1
|
/* AT91SAM7 debug function implementation for OpenPCD
|
2
|
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
3
|
*
|
4
|
* This program is free software; you can redistribute it and/or modify
|
5
|
* it under the terms of the GNU General Public License as published by
|
6
|
* the Free Software Foundation; either version 2 of the License, or
|
7
|
* (at your option) any later version.
|
8
|
*
|
9
|
* This program is distributed in the hope that it will be useful,
|
10
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
* GNU General Public License for more details.
|
13
|
*
|
14
|
* You should have received a copy of the GNU General Public License
|
15
|
* along with this program; if not, write to the Free Software
|
16
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
*
|
18
|
*/
|
19
|
|
20
|
#include <lib_AT91SAM7.h>
|
21
|
#include <board.h>
|
22
|
#include <dfu/dbgu.h>
|
23
|
#include <stdarg.h>
|
24
|
#include <stdio.h>
|
25
|
#include <string.h>
|
26
|
|
27
|
#define USART_SYS_LEVEL 4
|
28
|
void AT91F_DBGU_Ready(void)
|
29
|
{
|
30
|
while (!(AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY)) ;
|
31
|
}
|
32
|
|
33
|
static void DBGU_irq_handler(void)
|
34
|
{
|
35
|
static char value;
|
36
|
|
37
|
AT91F_DBGU_Get(&value);
|
38
|
switch (value) {
|
39
|
case '9':
|
40
|
AT91F_DBGU_Printk("Resetting SAM7\n\r");
|
41
|
AT91F_RSTSoftReset(AT91C_BASE_RSTC, AT91C_RSTC_PROCRST|
|
42
|
AT91C_RSTC_PERRST|AT91C_RSTC_EXTRST);
|
43
|
break;
|
44
|
default:
|
45
|
AT91F_DBGU_Printk("\n\r");
|
46
|
}
|
47
|
}
|
48
|
|
49
|
void AT91F_DBGU_Init(void)
|
50
|
{
|
51
|
/* Open PIO for DBGU */
|
52
|
AT91F_DBGU_CfgPIO();
|
53
|
/* Enable Transmitter & receivier */
|
54
|
((AT91PS_USART) AT91C_BASE_DBGU)->US_CR =
|
55
|
AT91C_US_RSTTX | AT91C_US_RSTRX;
|
56
|
|
57
|
/* Configure DBGU */
|
58
|
AT91F_US_Configure(AT91C_BASE_DBGU,
|
59
|
MCK, AT91C_US_ASYNC_MODE,
|
60
|
AT91C_DBGU_BAUD, 0);
|
61
|
|
62
|
/* Enable Transmitter & receivier */
|
63
|
((AT91PS_USART) AT91C_BASE_DBGU)->US_CR =
|
64
|
AT91C_US_RXEN | AT91C_US_TXEN;
|
65
|
|
66
|
/* Enable USART IT error and AT91C_US_ENDRX */
|
67
|
AT91F_US_EnableIt((AT91PS_USART) AT91C_BASE_DBGU, AT91C_US_RXRDY);
|
68
|
|
69
|
/* open interrupt */
|
70
|
|
71
|
AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_SYS, USART_SYS_LEVEL,
|
72
|
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
|
73
|
DBGU_irq_handler);
|
74
|
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SYS);
|
75
|
|
76
|
}
|
77
|
|
78
|
void AT91F_DBGU_Printk(char *buffer)
|
79
|
{
|
80
|
while (*buffer != '\0') {
|
81
|
while (!AT91F_US_TxReady((AT91PS_USART) AT91C_BASE_DBGU)) ;
|
82
|
AT91F_US_PutChar((AT91PS_USART) AT91C_BASE_DBGU, *buffer++);
|
83
|
}
|
84
|
}
|
85
|
|
86
|
int AT91F_DBGU_Get(char *val)
|
87
|
{
|
88
|
if ((AT91F_US_RxReady((AT91PS_USART) AT91C_BASE_DBGU)) == 0)
|
89
|
return (0);
|
90
|
else {
|
91
|
*val = AT91F_US_GetChar((AT91PS_USART) AT91C_BASE_DBGU);
|
92
|
return (-1);
|
93
|
}
|
94
|
}
|
95
|
|
96
|
#ifdef DEBUG
|
97
|
|
98
|
void AT91F_DBGU_Frame(char *buffer)
|
99
|
{
|
100
|
unsigned char len;
|
101
|
|
102
|
for (len = 0; buffer[len] != '\0'; len++) { }
|
103
|
|
104
|
AT91F_US_SendFrame((AT91PS_USART) AT91C_BASE_DBGU,
|
105
|
(unsigned char *)buffer, len, 0, 0);
|
106
|
}
|
107
|
|
108
|
|
109
|
const char *
|
110
|
hexdump(const void *data, unsigned int len)
|
111
|
{
|
112
|
static char string[256];
|
113
|
unsigned char *d = (unsigned char *) data;
|
114
|
unsigned int i, left;
|
115
|
|
116
|
string[0] = '\0';
|
117
|
left = sizeof(string);
|
118
|
for (i = 0; len--; i += 3) {
|
119
|
if (i >= sizeof(string) -4)
|
120
|
break;
|
121
|
snprintf(string+i, 4, " %02x", *d++);
|
122
|
}
|
123
|
return string;
|
124
|
}
|
125
|
|
126
|
static char dbg_buf[2048];
|
127
|
void debugp(const char *format, ...)
|
128
|
{
|
129
|
va_list ap;
|
130
|
|
131
|
va_start(ap, format);
|
132
|
vsnprintf(dbg_buf, sizeof(dbg_buf)-1, format, ap);
|
133
|
va_end(ap);
|
134
|
|
135
|
dbg_buf[sizeof(dbg_buf)-1] = '\0';
|
136
|
//AT91F_DBGU_Frame(dbg_buf);
|
137
|
AT91F_DBGU_Printk(dbg_buf);
|
138
|
}
|
139
|
|
140
|
#endif
|