/*---------------------------------------------------------------------------- * ATMEL Microcontroller Software Support - ROUSSET - *---------------------------------------------------------------------------- * The software is delivered "AS IS" without warranty or condition of any * kind, either express, implied or statutory. This includes without * limitation any warranty or condition with respect to merchantability or * fitness for any particular purpose, or against the infringements of * intellectual property rights of others. *---------------------------------------------------------------------------- * File Name : com.c * Object : * Creation : HIi 03/27/2003 * *---------------------------------------------------------------------------- */ #include "AT91RM9200.h" #include "lib_AT91RM9200.h" #include "config.h" #include "com.h" #include "stdio.h" static char erase_seq[] = "\b \b"; /* erase sequence */ #define MAX_UARTS 1 //unsigned int usa[2] = {(unsigned int)AT91C_BASE_DBGU, (unsigned int)AT91C_ALTERNATE_USART}; unsigned int usa[1] = {(unsigned int)AT91C_BASE_DBGU}; unsigned int us; int port_detected; void at91_init_uarts(void) { int i; port_detected = 0; AT91F_DBGU_CfgPIO(); AT91F_US0_CfgPIO(); AT91F_US0_CfgPMC(); for(i=0; i 16) return 0; c = (type & ZEROPAD) ? '0' : ' '; sign = 0; if(type & SIGN && num < 0) { sign = '-'; num = -num; size--; } i = 0; if(num == 0) tmp[i++] = digits[0]; else while(num != 0) tmp[i++] = digits[do_div(num, base)]; if(i > precision) precision = i; size -= precision; if(!(type&(ZEROPAD+LEFT))) while(size-->0) putc(' '); if(sign) putc(sign); if (!(type & LEFT)) while (size-- > 0) putc(c); while (i < precision--) putc('0'); while (i-- > 0) putc(tmp[i]); while (size-- > 0) putc(' ');; return 1; } int hvfprintf(const char *fmt, va_list va) { char *s; do { if(*fmt == '%') { bool done = false; int type = 0; int precision = 0; do { fmt++; switch(*fmt) { case '0' : if(!precision) type |= ZEROPAD; case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' : precision = precision * 10 + (*fmt - '0'); break; case '.' : break; case 's' : s = va_arg(va, char *); if(!s) puts(""); else puts(s); done = true; break; case 'c' : putc(va_arg(va, int)); done = true; break; case 'd' : number(va_arg(va, int), 10, 0, precision, type); done = true; break; case 'x' : case 'X' : number(va_arg(va, int), 16, 0, precision, type); done = true; break; case '%' : putc(*fmt); done = true; default: putc('%'); putc(*fmt); done = true; break; } } while(!done); } else if(*fmt == '\\') { fmt++; if(*fmt == 'r') { putc('\r'); } else if(*fmt == 'n') { putc('\n'); } } else { putc(*fmt); } fmt++; } while(*fmt != 0); return 0; } int printf(const char *fmt, ...) { va_list ap; int i; va_start(ap, fmt); i = hvfprintf(fmt, ap); va_end(ap); return i; }