From 00224dd7ebf77b2a490046ee529d38bbd06db53e Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Wed, 3 Mar 2010 08:09:19 -0500 Subject: [PATCH] pulled put out of lib still need set __putc as a fuction pointer to the uart_putc --- lib/include/uart1.h | 4 +++- lib/printf.c | 2 +- lib/uart1.c | 6 ++++++ tests/Makefile | 2 +- tests/put.c | 36 ++++++++++++++++++++++++++++++++++++ tests/put.h | 10 ++++++++++ tests/tests.c | 25 +++++++++---------------- 7 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 lib/uart1.c create mode 100644 tests/put.c create mode 100644 tests/put.h diff --git a/lib/include/uart1.h b/lib/include/uart1.h index 4967ceb5f..ee8337ef6 100644 --- a/lib/include/uart1.h +++ b/lib/include/uart1.h @@ -1,6 +1,8 @@ #ifndef UART1_H #define UART1_H +#include + #define UART1_CON ((volatile uint32_t *) 0x80005000) #define UART1_STAT ((volatile uint32_t *) 0x80005004) #define UART1_DATA ((volatile uint32_t *) 0x80005008) @@ -9,7 +11,7 @@ #define UART1_CTS ((volatile uint32_t *) 0x80005014) #define UART1_BR ((volatile uint32_t *) 0x80005018) -int uart1_putchar(int c); +void uart1_putc(char c); #define uart1_can_get() (*UR1CON > 0) diff --git a/lib/printf.c b/lib/printf.c index 74b388fb2..46cae36f2 100644 --- a/lib/printf.c +++ b/lib/printf.c @@ -37,7 +37,7 @@ #include #include -#define __putc(x) putchr(x) +#define __putc(x) uart1_putc(x) /** * Structure to hold data to be passed to print function with format. diff --git a/lib/uart1.c b/lib/uart1.c new file mode 100644 index 000000000..3d821b3cd --- /dev/null +++ b/lib/uart1.c @@ -0,0 +1,6 @@ +#include + +void uart1_putc(char c) { + while(*UT1CON == 31); /* wait for there to be room in the buffer */ + *UART1_DATA = c; +} diff --git a/tests/Makefile b/tests/Makefile index a7a79c989..3bb939f1c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -3,7 +3,7 @@ MC1322X := .. # all off the common objects for each target # a COBJ is made for EACH board and goes the obj_$(BOARD)_board directory # board specific code is OK in these files -COBJS := tests.o +COBJS := tests.o put.o # all of the target programs to build TARGETS := blink-red blink-green blink-blue blink-white blink-allio \ diff --git a/tests/put.c b/tests/put.c new file mode 100644 index 000000000..348da13f0 --- /dev/null +++ b/tests/put.c @@ -0,0 +1,36 @@ +#include +#include + +const uint8_t hex[16]={'0','1','2','3','4','5','6','7', + '8','9','a','b','c','d','e','f'}; + +void putchr(char c) { + while(*UT1CON == 31); /* wait for there to be room in the buffer */ + *UART1_DATA = c; +} + +void putstr(char *s) { + while(s && *s!=0) { + putchr(*s++); + } +} + +void put_hex(uint8_t x) +{ + putchr(hex[x >> 4]); + putchr(hex[x & 15]); +} + +void put_hex16(uint16_t x) +{ + put_hex((x >> 8) & 0xFF); + put_hex((x) & 0xFF); +} + +void put_hex32(uint32_t x) +{ + put_hex((x >> 24) & 0xFF); + put_hex((x >> 16) & 0xFF); + put_hex((x >> 8) & 0xFF); + put_hex((x) & 0xFF); +} diff --git a/tests/put.h b/tests/put.h new file mode 100644 index 000000000..f8826f622 --- /dev/null +++ b/tests/put.h @@ -0,0 +1,10 @@ +#ifndef PUT_H +#define PUT_H + +void putchr(char c); +void putstr(char *s); +void put_hex(uint8_t x); +void put_hex16(uint16_t x); +void put_hex32(uint32_t x); + +#endif diff --git a/tests/tests.c b/tests/tests.c index e1da61cd4..770d67997 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -1,4 +1,6 @@ #include +#include + #include "put.h" #include "tests.h" @@ -21,30 +23,21 @@ void uart1_init(uint16_t inc, uint16_t mod) { } void print_welcome(char* testname) { - putstr("mc1322x-test: "); - putstr(testname); - putstr("\n\r"); - putstr("board: "); -#if (BOARD == redbee-dev) - putstr("redbee-dev"); -#elif (BOARD == redbee-r1) - putstr("redbee-dev"); -#endif - putstr("\n\r"); + printf("mc1322x-test: %s\n\r",testname); + printf("board: %s\n\r", "fix print welcom"); } void dump_regs(uint32_t base, uint32_t len) { volatile uint32_t i; - putstr("base +0 +4 +8 +c +10 +14 +18 +1c \n\r"); + printf("base +0 +4 +8 +c +10 +14 +18 +1c \n\r"); for (i = 0; i < len; i ++) { if ((i & 7) == 0) { - put_hex16(4 * i); + printf("%02x",4 * i); } - putstr(" "); - put_hex32(*mem32(base+(4*i))); + printf(" %08x",*mem32(base+(4*i))); if ((i & 7) == 7) - putstr(NL); + printf(NL); } - putstr(NL); + printf(NL); }