e8fea0da70495e3ff944fa98820a5ad0bc51cd93
[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 addr */
31 #define BANK0                   0x80000000
32 #define BANK2                   0x82000000
33
34 /*
35  * type definitions
36  */
37
38 typedef unsigned char u8;
39 typedef unsigned short u16;
40 typedef unsigned int u32;
41
42 /*
43  * function prototypes
44  */
45
46 void mmap_init(u8 memtype);
47 void uart0_init(void);
48 void uart0_send_string(char *txbuf);
49 void uart0_send_char(char send);
50
51 /*
52  * main function
53  */
54
55 int main(void) {
56
57         /* variables */
58
59         u16 *flash;
60         u32 i;
61         u8 start;
62
63         /* memory mapping of interrupt vectors to static ram */
64
65         //mmap_init(MMAP_RAM);
66
67         /* uart initialization */
68
69         //uart0_init();
70
71         PINSEL0=0x05;                   // pin select -> tx, rx
72         UART0_FCR=0x07;                 // enable fifo
73         UART0_LCR=0x83;                 // set dlab + word length
74         UART0_DLL=0x10;                 // br: 9600 @ 10/4 mhz
75         UART0_DLM=0x00;
76         UART0_LCR=0x03;                 // unset dlab
77
78         /* external memory init */
79
80         BCFG0=0x1000FBEF;               // no boot[1:0] influence? (thnx colibri)
81                                         // BCFG2 should be fine as is
82         flash=(u16 *)BANK0;
83
84         /* wait for fwdump to send transmit start character */
85         start=0;
86         while(start!=0x23) {
87                 while(!(UART0_LSR&(1<<0)))
88                         continue;
89                 start=UART0_RBR;
90         }
91
92         /* transmit 1 mb of data */
93         for(i=0;i<524288;i++) {
94                 while(!(UART0_LSR&(1<<5)))
95                         continue;
96                 UART0_THR=(*flash&0xff);                // care for endianness
97                 while(!(UART0_LSR&(1<<5)))
98                         continue;
99                 UART0_THR=((*flash&0xff00)>>8);
100                 flash++;
101         }
102
103         return 0;
104 }
105
106 /*
107  * functions
108  */
109
110 void mmap_init(u8 memtype) {
111
112         MEMMAP=memtype;
113 }
114
115 void uart0_init(void) {
116
117         PINSEL0=0x05;                   // pin select -> tx, rx
118         UART0_FCR=0x07;                 // enable fifo
119         UART0_LCR=0x83;                 // set dlab + word length
120         UART0_DLL=0x10;                 // br: 9600 @ 10/4 mhz
121         UART0_DLM=0x00;
122         UART0_LCR=0x03;                 // unset dlab
123 }
124
125 void uart0_send_string(char *txbuf) {
126
127         int i;
128
129         i=0;
130
131         while(txbuf[i])
132                 UART0_THR=txbuf[i++];
133         UART0_THR='\n';
134         UART0_THR='\r';
135
136         while(!(UART0_LSR&(1<<6))) {}
137 }
138
139 void uart0_send_char(char send) {
140
141         while(!(UART0_LSR&(1<<5)))
142                 continue;
143
144         UART0_THR=send;
145 }
146