pulled put out of lib

still need set __putc as a fuction pointer to the uart_putc
This commit is contained in:
Mariano Alvira 2010-03-03 08:09:19 -05:00
parent 4b22b25e38
commit 00224dd7eb
7 changed files with 66 additions and 19 deletions

View file

@ -1,6 +1,8 @@
#ifndef UART1_H
#define UART1_H
#include <types.h>
#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)

View file

@ -37,7 +37,7 @@
#include <mc1322x.h>
#include <types.h>
#define __putc(x) putchr(x)
#define __putc(x) uart1_putc(x)
/**
* Structure to hold data to be passed to print function with format.

6
lib/uart1.c Normal file
View file

@ -0,0 +1,6 @@
#include <uart1.h>
void uart1_putc(char c) {
while(*UT1CON == 31); /* wait for there to be room in the buffer */
*UART1_DATA = c;
}

View file

@ -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 \

36
tests/put.c Normal file
View file

@ -0,0 +1,36 @@
#include <mc1322x.h>
#include <board.h>
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);
}

10
tests/put.h Normal file
View file

@ -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

View file

@ -1,4 +1,6 @@
#include <mc1322x.h>
#include <stdio.h>
#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);
}