X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Farm.git;a=blobdiff_plain;f=betty%2Ffwbc.c;h=e8fea0da70495e3ff944fa98820a5ad0bc51cd93;hp=6a8f187c55b80db709a2e8c1de7737e0ce3d6805;hb=67e8acdb6e63a64f34120318e44238869891deff;hpb=90fa4f3eca580f497dd24e9b3afd818d3b1f7054 diff --git a/betty/fwbc.c b/betty/fwbc.c index 6a8f187..e8fea0d 100644 --- a/betty/fwbc.c +++ b/betty/fwbc.c @@ -6,23 +6,141 @@ * */ -void uart0_init(void) { +/* + * include files + */ + +#include "lpc2xxx.h" + +/* + * defines + */ + +/* misc */ +#define OSC_CLOCK 10000000 +#define BAUDRATE 9600 +#define P_DIV 4 +#define P_CLOCK (OSC_CLOCK/P_DIV) + +/* memory mapping */ +#define MMAP_BL 0x00 +#define MMAP_RAM 0x02 +#define MMAP_EXT 0x03 + +/* band 0/2 addr */ +#define BANK0 0x80000000 +#define BANK2 0x82000000 + +/* + * type definitions + */ + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; + +/* + * function prototypes + */ + +void mmap_init(u8 memtype); +void uart0_init(void); +void uart0_send_string(char *txbuf); +void uart0_send_char(char send); + +/* + * main function + */ + +int main(void) { - PINSEL0|=((1<<0)|(1<<2)); /* pin select: tx, rx */ + /* variables */ + u16 *flash; + u32 i; + u8 start; + + /* memory mapping of interrupt vectors to static ram */ + + //mmap_init(MMAP_RAM); + + /* uart initialization */ + + //uart0_init(); + + PINSEL0=0x05; // pin select -> tx, rx + UART0_FCR=0x07; // enable fifo + UART0_LCR=0x83; // set dlab + word length + UART0_DLL=0x10; // br: 9600 @ 10/4 mhz + UART0_DLM=0x00; + UART0_LCR=0x03; // unset dlab + + /* external memory init */ + + BCFG0=0x1000FBEF; // no boot[1:0] influence? (thnx colibri) + // BCFG2 should be fine as is + flash=(u16 *)BANK0; + + /* wait for fwdump to send transmit start character */ + start=0; + while(start!=0x23) { + while(!(UART0_LSR&(1<<0))) + continue; + start=UART0_RBR; + } + + /* transmit 1 mb of data */ + for(i=0;i<524288;i++) { + while(!(UART0_LSR&(1<<5))) + continue; + UART0_THR=(*flash&0xff); // care for endianness + while(!(UART0_LSR&(1<<5))) + continue; + UART0_THR=((*flash&0xff00)>>8); + flash++; + } + + return 0; +} + +/* + * functions + */ + +void mmap_init(u8 memtype) { + + MEMMAP=memtype; } -void arm_init(void) { +void uart0_init(void) { + + PINSEL0=0x05; // pin select -> tx, rx + UART0_FCR=0x07; // enable fifo + UART0_LCR=0x83; // set dlab + word length + UART0_DLL=0x10; // br: 9600 @ 10/4 mhz + UART0_DLM=0x00; + UART0_LCR=0x03; // unset dlab +} + +void uart0_send_string(char *txbuf) { + + int i; + + i=0; - /* pin selection */ - uart0_init(); + while(txbuf[i]) + UART0_THR=txbuf[i++]; + UART0_THR='\n'; + UART0_THR='\r'; + while(!(UART0_LSR&(1<<6))) {} } -void main(void) { +void uart0_send_char(char send) { - /* initialization */ - arm_init(); + while(!(UART0_LSR&(1<<5))) + continue; + UART0_THR=send; }