1 /* AT91SAM7 debug function implementation for OpenPCD
2 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
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.
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.
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
20 #include <lib_AT91SAM7.h>
27 #define USART_SYS_LEVEL 4
28 void AT91F_DBGU_Ready(void)
30 while (!(AT91C_BASE_DBGU
->DBGU_CSR
& AT91C_US_TXEMPTY
)) ;
33 static void DBGU_irq_handler(void)
37 AT91F_DBGU_Get(&value
);
40 AT91F_DBGU_Printk("Resetting SAM7\n\r");
41 AT91F_RSTSoftReset(AT91C_BASE_RSTC
, AT91C_RSTC_PROCRST
|
42 AT91C_RSTC_PERRST
|AT91C_RSTC_EXTRST
);
45 AT91F_DBGU_Printk("\n\r");
49 void AT91F_DBGU_Init(void)
51 /* Open PIO for DBGU */
53 /* Enable Transmitter & receivier */
54 ((AT91PS_USART
) AT91C_BASE_DBGU
)->US_CR
=
55 AT91C_US_RSTTX
| AT91C_US_RSTRX
;
58 AT91F_US_Configure(AT91C_BASE_DBGU
,
59 MCK
, AT91C_US_ASYNC_MODE
,
62 /* Enable Transmitter & receivier */
63 ((AT91PS_USART
) AT91C_BASE_DBGU
)->US_CR
=
64 AT91C_US_RXEN
| AT91C_US_TXEN
;
66 /* Enable USART IT error and AT91C_US_ENDRX */
67 AT91F_US_EnableIt((AT91PS_USART
) AT91C_BASE_DBGU
, AT91C_US_RXRDY
);
71 AT91F_AIC_ConfigureIt(AT91C_BASE_AIC
, AT91C_ID_SYS
, USART_SYS_LEVEL
,
72 AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL
,
74 AT91F_AIC_EnableIt(AT91C_BASE_AIC
, AT91C_ID_SYS
);
78 void AT91F_DBGU_Printk(char *buffer
)
80 while (*buffer
!= '\0') {
81 while (!AT91F_US_TxReady((AT91PS_USART
) AT91C_BASE_DBGU
)) ;
82 AT91F_US_PutChar((AT91PS_USART
) AT91C_BASE_DBGU
, *buffer
++);
86 int AT91F_DBGU_Get(char *val
)
88 if ((AT91F_US_RxReady((AT91PS_USART
) AT91C_BASE_DBGU
)) == 0)
91 *val
= AT91F_US_GetChar((AT91PS_USART
) AT91C_BASE_DBGU
);
98 void AT91F_DBGU_Frame(char *buffer
)
102 for (len
= 0; buffer
[len
] != '\0'; len
++) { }
104 AT91F_US_SendFrame((AT91PS_USART
) AT91C_BASE_DBGU
,
105 (unsigned char *)buffer
, len
, 0, 0);
110 hexdump(const void *data
, unsigned int len
)
112 static char string
[256];
113 unsigned char *d
= (unsigned char *) data
;
114 unsigned int i
, left
;
117 left
= sizeof(string
);
118 for (i
= 0; len
--; i
+= 3) {
119 if (i
>= sizeof(string
) -4)
121 snprintf(string
+i
, 4, " %02x", *d
++);
126 static char dbg_buf
[2048];
127 void debugp(const char *format
, ...)
131 va_start(ap
, format
);
132 vsnprintf(dbg_buf
, sizeof(dbg_buf
)-1, format
, ap
);
135 dbg_buf
[sizeof(dbg_buf
)-1] = '\0';
136 //AT91F_DBGU_Frame(dbg_buf);
137 AT91F_DBGU_Printk(dbg_buf
);