00001 #include "print_funcs.h"
00002
00003 void init_dbg_rs232( long cpu_hz )
00004 {
00005 struct usart_options_t usart_opt;
00006
00007 avr32_pio_t *pio = (void *) AVR32_PIOB_ADDRESS;
00008 avr32_usart_t *usart0 = (void *) AVR32_USART0_ADDRESS;
00009
00010
00011 pio->pdr = 0x00000300;
00012 pio->asr = 0x00000300;
00013
00014
00015 usart_opt.baudrate = 115200;
00016 usart_opt.charlength = 8;
00017 usart_opt.paritytype = USART_NO_PARITY;
00018 usart_opt.stopbits = USART_1_STOPBIT;
00019 usart_opt.channelmode = USART_NORMAL_CHMODE;
00020
00021
00022 usart_init_rs232(usart0, &usart_opt, cpu_hz);
00023 }
00024
00025 void print_dbg(char *str)
00026 {
00027 avr32_usart_t *usart0 = (void *) AVR32_USART0_ADDRESS;
00028 print(usart0, str);
00029 }
00030
00031 void print_dbg_ulong(unsigned long n)
00032 {
00033 avr32_usart_t *usart0 = (void *) AVR32_USART0_ADDRESS;
00034 print_ulong(usart0, n);
00035 }
00036
00037 void print_dbg_hex(unsigned long n)
00038 {
00039 avr32_usart_t *usart0 = (void *) AVR32_USART0_ADDRESS;
00040 print_hex(usart0, n);
00041 }
00042
00043 int print(volatile avr32_usart_t * usart, char *str)
00044 {
00045 while (*str != '\0')
00046 usart_putchar(usart, *str++);
00047 return 0;
00048 }
00049
00050 int print_char(volatile avr32_usart_t * usart, int c)
00051 {
00052 usart_putchar(usart, c);
00053 return 0;
00054 }
00055
00056
00057 void print_ulong(volatile avr32_usart_t * usart, unsigned long n)
00058 {
00059 char tmp[16];
00060 int i = sizeof(tmp) - 1;
00061
00062 tmp[i] = 0;
00063 do {
00064 tmp[--i] = (n % 10) + '0';
00065 n /= 10;
00066 } while (n);
00067
00068 print(usart, tmp + i);
00069 }
00070
00071 void print_hex(volatile avr32_usart_t * usart, unsigned long n)
00072 {
00073 char tmp[9];
00074 int i;
00075
00076 for (i = 0; i < 8; i++) {
00077 unsigned long nibble;
00078
00079 nibble = (n >> (28 - 4 * i)) & 0xf;
00080 if (nibble < 10)
00081 tmp[i] = nibble + '0';
00082 else
00083 tmp[i] = nibble - 10 + 'a';
00084 }
00085 tmp[8] = 0;
00086
00087 print(usart, tmp);
00088 }