X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Farm.git;a=blobdiff_plain;f=betty%2Ffwbc.c;h=187481916da4c8c127c5730dd7a883f08b319b18;hp=fecb7533ac3275da6700c2b5848b41de50b049ca;hb=HEAD;hpb=404060c864c2d8bd444246078590c6f71f22217f diff --git a/betty/fwbc.c b/betty/fwbc.c index fecb753..1874819 100644 --- a/betty/fwbc.c +++ b/betty/fwbc.c @@ -6,54 +6,181 @@ * */ +/* + * include files + */ + #include "lpc2xxx.h" +/* + * defines + */ + +/* misc */ #define OSC_CLOCK 10000000 #define BAUDRATE 9600 -#define P_DIV 1 +#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 & bootloader addr */ +#define BANK0 0x80000000 +#define BANK2 0x82000000 +#define BOOTLOADER 0x7fffe000 + +/* + * type definitions + */ + typedef unsigned char u8; +typedef unsigned short u16; typedef unsigned int u32; -void uart0_init(u32 br) { +/* + * function prototypes + */ + +void mmap_init(u8 memtype); +void uart0_init(void); +void uart0_send_string(char *txbuf); +void uart0_send_char(char send); - /* pin select -> tx rx */ - PINSEL0&=~((1<<0)|(1<<1)|(1<<2)|(1<<3)); - PINSEL0|=((1<<0)|(1<<2)); +/* + * main function + */ - /* divisor */ - UART0_LCR|=(1<<7); - //UART0_DLL=((OSC_CLOCK/(16*br)))&0xff; - //UART0_DLM=(((OSC_CLOCK/(16*br)))&0xff00)>>8; - UART0_DLL=65; - UART0_DLM=0; +int main(void) { - /* 8 bit data */ - UART0_LCR=((1<<0)|(1<<1)); + /* variables */ - /* activate rx tx fifo */ - UART0_FCR|=((1<<0)|(1<<1)|(1<<2)); -} + u16 *mem=0; + u32 *bl=0; + u32 i,len; + u8 start; -void uart_send(u8 byte) { + /* memory mapping of interrupt vectors to static ram */ - /* wait for empty transmit buffer */ - while(!(UART0_LSR&(1<<5))) - continue; + //mmap_init(MMAP_RAM); - UART0_THR=byte; -} + /* uart initialization */ -int main(void) { + //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 - /* initialization */ - uart0_init(9600); + /* external memory init */ + + BCFG0=0x1000FBEF; // no boot[1:0] influence? (thnx colibri) + // BCFG2 should be fine as is + + while(1) { + /* wait for fwdump to send transmit start character */ + start=0x23; while(1) { - uart_send(0x23); + while(!(UART0_LSR&(1<<0))) + continue; + start=UART0_RBR; + if(start=='0') { + mem=(u16 *)BANK0; + len=0x80000; + break; + } + if(start=='2') { + mem=(u16 *)BANK2; + len=0x80000; + break; + } + if(start=='b') { + BCFG0=0x1000FBEF; // 32 bit width + bl=(u32 *)BOOTLOADER; + len=0x800; + break; + } + } + + /* transmit 1 mb of data */ + for(i=0;i>8); + else { + UART0_THR=((*mem&0xff00)>>8); + mem++; + } + + if(start=='b') { + while(!(UART0_LSR&(1<<5))) + continue; + UART0_THR=((*bl&0xff0000)>>16); + while(!(UART0_LSR&(1<<5))) + continue; + UART0_THR=((*bl&0xff000000)>>24); + bl++; + } + } + } return 0; } +/* + * functions + */ + +void mmap_init(u8 memtype) { + + MEMMAP=memtype; +} + +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; + + while(txbuf[i]) + UART0_THR=txbuf[i++]; + UART0_THR='\n'; + UART0_THR='\r'; + + while(!(UART0_LSR&(1<<6))) {} +} + +void uart0_send_char(char send) { + + while(!(UART0_LSR&(1<<5))) + continue; + + UART0_THR=send; +} +