-void mmap_init(u8 memtype) {
-
- MEMMAP=memtype;
-}
-
-void pll_init(void) {
-
- /* configuration */
- PLLCFG=0x42; // multiplier = 3 (for cclk), dividor = 4 (for f_cco)
- PLLCON=0x03; // enable and set as clk source for the lpc
- /* feed sequence */
- PLLFEED=0xaa;
- PLLFEED=0x55;
- /* wait for lock */
- while(!(PLLSTAT&(1<<10)))
- continue;
-}
-
-void ext_mem_bank_init(void) {
-
- BCFG0=0x10000420; // flash 1
- BCFG1=0x00000c42; // lcd
- BCFG2=0x10000420; // flash 2
-}
-
-
-void pin_select_init() {
-
- /*
- * a[19:2] -> address lines
- */
-
- PINSEL2=0x0d6041d4;
-}
-
-void uart0_init(void) {
-
- /* select pins 0.0 and 0.1 as tx and rx */
- PINSEL0=(PINSEL0&~(0xf))|0x05; // pin select -> tx, rx
-
- /* configure uart0 */
- UART0_FCR=0x07; // enable fifo
- UART0_LCR=0x83; // set dlab + word length
- UART0_DLL=0x04; // br: 38400 @ 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++];
- /* flush if tx buffer maximum reached */
- if(!(i%16))
- while(!(UART0_LSR&(1<<6)))
- continue;
- }
-
- /* flush if \n and \r do not fit in the tx buffer */
- if(i>14)
- while(!(UART0_LSR&(1<<6)))
- continue;
-
- UART0_THR='\n';
- UART0_THR='\r';
-
- /* flush uart0 anyways */
- while(!(UART0_LSR&(1<<6)))
- continue;
-}
-
-void uart0_send_buf16(u16 *buf,int len) {
-
- int i;
-
- i=0;
-
- for(i=0;i<len/2;i++) {
- if(!(i%8))
- while(!(UART0_LSR&(1<<6)))
- continue;
- UART0_THR=buf[i]&0xff;
- UART0_THR=(buf[i]>>8)&0xff;
- }
-}
-
-void uart0_send_buf32(u32 *buf,int len) {
-
- int i;
-
- i=0;
-
- for(i=0;i<len/4;i++) {
- if(!(i%4))
- while(!(UART0_LSR&(1<<6)))
- continue;
- UART0_THR=buf[i]&0xff;
- UART0_THR=(buf[i]>>8)&0xff;
- UART0_THR=(buf[i]>>16)&0xff;
- UART0_THR=(buf[i]>>24)&0xff;
- }
-}
-
-void uart0_send_byte(u8 send) {
-
- while(!(UART0_LSR&(1<<5)))
- continue;
-
- UART0_THR=send;
-}
-
-u8 uart0_get_byte(void) {
-
- u8 rx;
-
- while(!(UART0_LSR&(1<<0)))
- continue;
-
- rx=UART0_RBR;
-
- return rx;
-}
-
-void pause(int cnt) {
-
- while(cnt--)
- asm volatile ("nop");
-}
-
-void init_lcd(u8 s) {
-
- LCD_CMD=0xe1; // ?
- LCD_CMD=0xe2;
- pause(48000);
- LCD_CMD=0xab;
- LCD_CMD=0x27;
- LCD_CMD=0x81;
- LCD_CMD=0x3f;
- LCD_CMD=0x65;
- LCD_CMD=0x60;
- LCD_CMD=0x1c;
- LCD_CMD=0x61;
- LCD_CMD=0x0a;
- LCD_CMD=0x62;
- LCD_CMD=0x75;
- LCD_CMD=0x63;
- LCD_CMD=0x81;
- LCD_CMD=0x90;
- LCD_CMD=0x88;
- LCD_CMD=0x00;
- LCD_CMD=0x89;
- LCD_CMD=0x00;
- LCD_CMD=0x8a;
- LCD_CMD=0x33;
- LCD_CMD=0x8b;
- LCD_CMD=0x33;
- LCD_CMD=0x8c;
- LCD_CMD=0x66;
- LCD_CMD=0x8d;
- LCD_CMD=0x66;
- LCD_CMD=0x8e;
- LCD_CMD=0x99;
- LCD_CMD=0x8f;
- LCD_CMD=0x99;
- if(s) {
- LCD_CMD=0xa1;
- LCD_CMD=0xc0;
- }
- else {
- LCD_CMD=0xa0;
- LCD_CMD=0xc8;
- }
- LCD_CMD=0x2e;
- pause(48000);
- LCD_CMD=0x2f;
- LCD_CMD=0xa4;
- LCD_CMD=0xa6;
-}