X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=betty%2Fbetty.c;h=859860a03e4ce8e9347afe3c69fb26c95c36bac8;hb=94909b5b893d5c60bc44bbafec8de1b3c86d9595;hp=81b4687e2f18566f931a4e397e0a5b9ccddc3915;hpb=def8902c1681a94ccb70d90cc855aedbc6a9e918;p=my-code%2Farm.git diff --git a/betty/betty.c b/betty/betty.c index 81b4687..859860a 100644 --- a/betty/betty.c +++ b/betty/betty.c @@ -5,304 +5,70 @@ * */ -/* - * includes - */ - -#include "lpc2xxx.h" +/* includes */ +#include "betty.h" /* - * defines + * functions */ -/* bank 0/2 and boootloader addr/size */ -#define BANK0 0x80000000 -#define BANK1 0x81000000 -#define BANK2 0x82000000 -#define BANK_SIZE 0x00100000 -#define BOOTLOADER 0x7fffe000 -#define BL_SIZE 0x00002000 - -/* flash cmd addresses - flash[0-18] <--> arm[1-19]*/ -#define B0F555 (*((volatile unsigned short *)(BANK0|0xaaa))) // 0x555 -#define B0F2AA (*((volatile unsigned short *)(BANK0|0x554))) // 0x2aa -#define B0F (*((volatile unsigned short *)(BANK0))) -#define B2F555 (*((volatile unsigned short *)(BANK2|0xaaa))) // 0x555 -#define B2F2AA (*((volatile unsigned short *)(BANK2|0x554))) // 0x2aa -#define B2F (*((volatile unsigned short *)(BANK2))) - -/* lcd command and data addresses */ -#define LCD_CMD (*((volatile unsigned char *)(BANK1))) -#define LCD_DATA (*((volatile unsigned char *)(BANK1+1))) +#define cc1100_init spi1_init(8,SPI_MASTER,8) /* - * type definitions + * main function */ -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; - - /* - * functions - */ - -void mmap_init(u8 memtype) { - - MEMMAP=memtype; -} +int main() { -void pll_init(void) { + char announce[]="betty - live from flash at 0x80000000! ;)\r\n"; + t_button button; + u32 addr; - /* 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; -} + /* system init */ + pll_init(); -void ext_mem_bank_init(void) { + /* uart init */ + uart0_init(); - BCFG0=0x10000420; // flash 1 - BCFG1=0x00000c42; // lcd - BCFG2=0x10000420; // flash 2 -} + /* display init */ + display_bl_init(); + /* button init */ + button_init(&button); + button_set_retries(&button,100); -void pin_select_init() { + /* flash init */ + flash_init(); /* - * a[19:2] -> address lines + * start it ... */ - PINSEL2=0x0d6041d4; -} - -void uart0_init(void) { - - PINSEL0=0x05; // pin select -> tx, rx - 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>8)&0xff; - } -} - -void uart0_send_buf32(u32 *buf,int len) { - - int i; - - i=0; - - for(i=0;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; -} - -/* - * spi0 stuff (+ cc1100) - */ - -#define SLAVE 0 -#define MASTER 1 - -void spi1_init(u8 width,u8 type,u8 div) { - - if((width<8)|(width>16)) - width=8; - if(width==16) - width=0; - - div&=0xfe; - if(div<8) - div=8; - - S1SPCR=(1<<2)|(width<<8)|(type<<5); - S1SPCCR=div; -} - -#define cc1100_init spi1_init(8,MASTER,8) - -void spi1_send(u16 data) { - - S1SPDR=data; - - while(!(S1SPSR&(1<<7))) - continue; -} - -void bl_init(void) { - - IODIR0|=(1<<4); -} - -void bl_toggle(void) { - - if(IOPIN0&(1<<4)) - IOCLR0=(1<<4); - else - IOSET0=(1<<4); -} - -void bl_on(void) { - - IOCLR0=(1<<4); -} - -void bl_off(void) { - - IOSET0=(1<<4); -} - -/* - * main function - */ - -int main() { + /* pause - seems to not work if running from flash! (?) */ + pause(0xffffff); - char buf[]="betty - live from the flash at 0x80000000! ;)\r\n"; + /* announce */ + uart0_send_string(announce); - pll_init(); - uart0_init(); - ext_mem_bank_init(); - pin_select_init(); - init_lcd(0); - bl_init(); + /* toggle backlight */ + display_bl_toggle(); - pause(0xffffff); + //addr=0x82000000; + flash_sector_erase(BANK2,0); + addr=FLASH_BANK2; while(1) { - uart0_send_string(buf); - bl_toggle(); - pause(0x9ffff); + pause(0x0fffff); + + /* button test! */ + if(button_get_event(&button)) { + uart0_send_string(announce); + if(button.key[0]==BUTTON_POWER) { + display_bl_toggle(); + flash_write_buf(addr,(u16 *)announce,42); + addr+=64; + } + } } return 0;