a625716b4123a9b4c6d3f0d4108663a29b87c888
[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 #include "lpc2xxx.h"
10
11 #define OSC_CLOCK               10000000
12 #define BAUDRATE                9600
13 #define P_DIV                   4
14 #define P_CLOCK                 (OSC_CLOCK/P_DIV)
15
16 typedef unsigned char u8;
17 typedef unsigned int u32;
18
19
20 /* memory mapping */
21
22 #define MMAP_BL         0x00
23 #define MMAP_RAM        0x02
24 #define MMAP_EXT        0x03
25
26 void mmap_init(u8 memtype) {
27
28         MEMMAP=memtype;
29 }
30
31 void uart0_init(void) {
32
33         /* pin select -> tx rx */
34         PINSEL0=0x05;
35
36         /* enable fifo */
37         UART0_FCR=0x07;
38
39         /* set dlab + word length */
40         UART0_LCR=0x83;
41
42         /* set baud rate to 9600 @ 10/4 mhz */
43         UART0_DLL=0x10;
44         UART0_DLM=0x00;
45
46         /* unset dlab */
47         UART0_LCR=0x03;
48 }
49
50 void uart_send(char *txbuf) {
51
52         int i;
53
54         i=0;
55
56         while(txbuf[i])
57                 UART0_THR=txbuf[i++];
58         UART0_THR='\n';
59         UART0_THR='\r';
60
61         while(!(UART0_LSR&(1<<6))) {}
62 }
63
64 int main(void) {
65
66         char txbuf[]="uart0 working";
67
68         /* memory mapping of interrupt vectors to static ram */
69         mmap_init(MMAP_RAM);
70
71         /* initialization */
72         uart0_init();
73
74         while(1) {
75                 uart_send(txbuf);
76         }
77
78         return 0;
79 }
80