compilation errors fixed, debug now!
[my-code/arm.git] / betty / fwbc.c
1 /*
2  * fwbc.c - broadcast the betty tv original firmware via uart0
3  *          use fwdump to write it onto your computers harddisk
4  *
5  * author: hackbard@hackdaworld.org
6  *
7  */
8
9 /*
10  * include files
11  */
12
13 #include "lpc2xxx.h"
14
15 /*
16  * defines
17  */
18
19 /* misc */
20 #define OSC_CLOCK               10000000
21 #define BAUDRATE                9600
22 #define P_DIV                   4
23 #define P_CLOCK                 (OSC_CLOCK/P_DIV)
24
25 /* memory mapping */
26 #define MMAP_BL                 0x00
27 #define MMAP_RAM                0x02
28 #define MMAP_EXT                0x03
29
30 /* band 0/2 & bootloader addr */
31 #define BANK0                   0x80000000
32 #define BANK2                   0x82000000
33 #define BOOTLOADER              0x7fffe000
34
35 /*
36  * type definitions
37  */
38
39 typedef unsigned char u8;
40 typedef unsigned short u16;
41 typedef unsigned int u32;
42
43 /*
44  * function prototypes
45  */
46
47 void mmap_init(u8 memtype);
48 void uart0_init(void);
49 void uart0_send_string(char *txbuf);
50 void uart0_send_char(char send);
51
52 /*
53  * main function
54  */
55
56 int main(void) {
57
58         /* variables */
59
60         u16 *mem=0;
61         u32 *bl=0;
62         u32 i,len;
63         u8 start;
64
65         /* memory mapping of interrupt vectors to static ram */
66
67         //mmap_init(MMAP_RAM);
68
69         /* uart initialization */
70
71         //uart0_init();
72
73         PINSEL0=0x05;                   // pin select -> tx, rx
74         UART0_FCR=0x07;                 // enable fifo
75         UART0_LCR=0x83;                 // set dlab + word length
76         UART0_DLL=0x10;                 // br: 9600 @ 10/4 mhz
77         UART0_DLM=0x00;
78         UART0_LCR=0x03;                 // unset dlab
79
80         /* external memory init */
81
82         BCFG0=0x1000FBEF;               // no boot[1:0] influence? (thnx colibri)
83                                         // BCFG2 should be fine as is
84
85         while(1) {
86
87         /* wait for fwdump to send transmit start character */
88         start=0x23;
89         while(1) {
90                 while(!(UART0_LSR&(1<<0)))
91                         continue;
92                 start=UART0_RBR;
93                 if(start=='0') {
94                         mem=(u16 *)BANK0;
95                         len=0x80000;
96                         break;
97                 }
98                 if(start=='2') {
99                         mem=(u16 *)BANK2;
100                         len=0x80000;
101                         break;
102                 }
103                 if(start=='b') {
104                         BCFG0=0x1000FBEF;       // 32 bit width
105                         bl=(u32 *)BOOTLOADER;
106                         len=0x800;
107                         break;
108                 }
109         }
110
111         /* transmit 1 mb of data */
112         for(i=0;i<len;i++) {                    // care for endianness
113
114                 while(!(UART0_LSR&(1<<5)))
115                         continue;
116                 if(start=='b')
117                         UART0_THR=(*bl&0xff);
118                 else
119                         UART0_THR=(*mem&0xff);
120
121                 while(!(UART0_LSR&(1<<5)))
122                         continue;
123                 if(start=='b')
124                         UART0_THR=((*bl&0xff00)>>8);
125                 else {
126                         UART0_THR=((*mem&0xff00)>>8);
127                         mem++;
128                 }
129
130                 if(start=='b') {
131                         while(!(UART0_LSR&(1<<5)))
132                                 continue;
133                         UART0_THR=((*bl&0xff0000)>>16);
134                         while(!(UART0_LSR&(1<<5)))
135                                 continue;
136                         UART0_THR=((*bl&0xff000000)>>24);
137                         bl++;
138                 }
139         }
140
141         }
142
143         return 0;
144 }
145
146 /*
147  * functions
148  */
149
150 void mmap_init(u8 memtype) {
151
152         MEMMAP=memtype;
153 }
154
155 void uart0_init(void) {
156
157         PINSEL0=0x05;                   // pin select -> tx, rx
158         UART0_FCR=0x07;                 // enable fifo
159         UART0_LCR=0x83;                 // set dlab + word length
160         UART0_DLL=0x10;                 // br: 9600 @ 10/4 mhz
161         UART0_DLM=0x00;
162         UART0_LCR=0x03;                 // unset dlab
163 }
164
165 void uart0_send_string(char *txbuf) {
166
167         int i;
168
169         i=0;
170
171         while(txbuf[i])
172                 UART0_THR=txbuf[i++];
173         UART0_THR='\n';
174         UART0_THR='\r';
175
176         while(!(UART0_LSR&(1<<6))) {}
177 }
178
179 void uart0_send_char(char send) {
180
181         while(!(UART0_LSR&(1<<5)))
182                 continue;
183
184         UART0_THR=send;
185 }
186