2 * betty.c - alternative firmware for the betty tv ;)
4 * author: hackbard@hackdaworld.org
18 /* bank 0/2 and boootloader addr/size */
19 #define BANK0 0x80000000
20 #define BANK1 0x81000000
21 #define BANK2 0x82000000
22 #define BANK_SIZE 0x00100000
23 #define BOOTLOADER 0x7fffe000
24 #define BL_SIZE 0x00002000
26 /* flash cmd addresses - flash[0-18] <--> arm[1-19]*/
27 #define B0F555 (*((volatile unsigned short *)(BANK0|0xaaa))) // 0x555
28 #define B0F2AA (*((volatile unsigned short *)(BANK0|0x554))) // 0x2aa
29 #define B0F (*((volatile unsigned short *)(BANK0)))
30 #define B2F555 (*((volatile unsigned short *)(BANK2|0xaaa))) // 0x555
31 #define B2F2AA (*((volatile unsigned short *)(BANK2|0x554))) // 0x2aa
32 #define B2F (*((volatile unsigned short *)(BANK2)))
34 /* lcd command and data addresses */
35 #define LCD_CMD (*((volatile unsigned char *)(BANK1)))
36 #define LCD_DATA (*((volatile unsigned char *)(BANK1+1)))
42 typedef unsigned char u8;
43 typedef unsigned short u16;
44 typedef unsigned int u32;
50 void mmap_init(u8 memtype) {
58 PLLCFG=0x42; // multiplier = 3 (for cclk), dividor = 4 (for f_cco)
59 PLLCON=0x03; // enable and set as clk source for the lpc
64 while(!(PLLSTAT&(1<<10)))
68 void ext_mem_bank_init(void) {
70 BCFG0=0x10000420; // flash 1
71 BCFG1=0x00000c42; // lcd
72 BCFG2=0x10000420; // flash 2
76 void pin_select_init() {
79 * a[19:2] -> address lines
85 void uart0_init(void) {
87 PINSEL0=0x05; // pin select -> tx, rx
88 UART0_FCR=0x07; // enable fifo
89 UART0_LCR=0x83; // set dlab + word length
90 UART0_DLL=0x04; // br: 38400 @ 10/4 mhz
92 UART0_LCR=0x03; // unset dlab
95 void uart0_send_string(char *txbuf) {
102 UART0_THR=txbuf[i++];
103 /* flush if tx buffer maximum reached */
105 while(!(UART0_LSR&(1<<6)))
109 /* flush if \n and \r do not fit in the tx buffer */
111 while(!(UART0_LSR&(1<<6)))
117 /* flush uart0 anyways */
118 while(!(UART0_LSR&(1<<6)))
122 void uart0_send_buf16(u16 *buf,int len) {
128 for(i=0;i<len/2;i++) {
130 while(!(UART0_LSR&(1<<6)))
132 UART0_THR=buf[i]&0xff;
133 UART0_THR=(buf[i]>>8)&0xff;
137 void uart0_send_buf32(u32 *buf,int len) {
143 for(i=0;i<len/4;i++) {
145 while(!(UART0_LSR&(1<<6)))
147 UART0_THR=buf[i]&0xff;
148 UART0_THR=(buf[i]>>8)&0xff;
149 UART0_THR=(buf[i]>>16)&0xff;
150 UART0_THR=(buf[i]>>24)&0xff;
154 void uart0_send_byte(u8 send) {
156 while(!(UART0_LSR&(1<<5)))
162 u8 uart0_get_byte(void) {
166 while(!(UART0_LSR&(1<<0)))
174 void pause(int cnt) {
177 asm volatile ("nop");
180 void init_lcd(u8 s) {
231 * spi0 stuff (+ cc1100)
237 void spi1_init(u8 width,u8 type,u8 div) {
239 if((width<8)|(width>16))
248 S1SPCR=(1<<2)|(width<<8)|(type<<5);
252 #define cc1100_init spi1_init(8,MASTER,8)
254 void spi1_send(u16 data) {
258 while(!(S1SPSR&(1<<7)))
267 void bl_toggle(void) {
291 char buf[]="betty - live from the flash at 0x80000000! ;)\r\n";
303 uart0_send_string(buf);