9682ee8292fb4396fb98f16f29aaf2560844e0a6
[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 /*
31  * type definitions
32  */
33
34 typedef unsigned char u8;
35 typedef unsigned int u32;
36
37 /*
38  * function prototypes
39  */
40
41 void mmap_init(u8 memtype);
42 void uart0_init(void);
43 void uart0_send_string(char *txbuf);
44 void uart0_send_char(char send);
45
46 /*
47  * main function
48  */
49
50 int main(void) {
51
52         /* memory mapping of interrupt vectors to static ram */
53
54         //mmap_init(MMAP_RAM);
55
56         /* uart initialization */
57
58 #ifdef USE_FUNCTIONS
59         //uart0_init();
60 #else
61         PINSEL0=0x05;                   // pin select -> tx, rx
62         UART0_FCR=0x07;                 // enable fifo
63         UART0_LCR=0x83;                 // set dlab + word length
64         UART0_DLL=0x10;                 // br: 9600 @ 10/4 mhz
65         UART0_DLM=0x00;
66         UART0_LCR=0x03;                 // unset dlab
67 #endif
68
69         /* external memory init */
70
71         while(1) {
72                 while(!(UART0_LSR&(1<<5)))
73                         continue;
74                 UART0_THR=0x23;
75         }
76
77         return 0;
78 }
79
80 /*
81  * functions
82  */
83
84 void mmap_init(u8 memtype) {
85
86         MEMMAP=memtype;
87 }
88
89 void uart0_init(void) {
90
91         PINSEL0=0x05;                   // pin select -> tx, rx
92         UART0_FCR=0x07;                 // enable fifo
93         UART0_LCR=0x83;                 // set dlab + word length
94         UART0_DLL=0x10;                 // br: 9600 @ 10/4 mhz
95         UART0_DLM=0x00;
96         UART0_LCR=0x03;                 // unset dlab
97 }
98
99 void uart0_send_string(char *txbuf) {
100
101         int i;
102
103         i=0;
104
105         while(txbuf[i])
106                 UART0_THR=txbuf[i++];
107         UART0_THR='\n';
108         UART0_THR='\r';
109
110         while(!(UART0_LSR&(1<<6))) {}
111 }
112
113 void uart0_send_char(char send) {
114
115         while(!(UART0_LSR&(1<<5)))
116                 continue;
117
118         UART0_THR=send;
119 }
120