fwbc transmitting 0x23 now, though it's still curious. Makefile updates.
[my-code/arm.git] / betty / fwbc.c
index 46a342c..9682ee8 100644 (file)
  *
  */
 
+/*
+ * include files
+ */
+
 #include "lpc2xxx.h"
 
+/*
+ * defines
+ */
+
+/* misc */
 #define OSC_CLOCK              10000000
 #define BAUDRATE               9600
-#define P_DIV                  1
+#define P_DIV                  4
 #define P_CLOCK                        (OSC_CLOCK/P_DIV)
 
-typedef unsigned char u8;
+/* memory mapping */
+#define        MMAP_BL                 0x00
+#define MMAP_RAM               0x02
+#define MMAP_EXT               0x03
 
-void uart0_init(int br) {
+/*
+ * type definitions
+ */
 
-       PINSEL0&=~((0x03<<0)|(0x03<<2));        // clear bits 0-3
-       PINSEL0|=((1<<0)|(1<<2));               // pin select: tx, rx
+typedef unsigned char u8;
+typedef unsigned int u32;
 
-       UART0_LCR|=(1<<7);                      // enable access to divisor
-       UART0_DLL=(P_CLOCK/(br*16))&0xff;       // set divisor
-       UART0_DLL=((P_CLOCK/(br*16))&0xff00)>>8;
-       UART0_LCR&=~(1<<7);                     // disable access to divisor
+/*
+ * function prototypes
+ */
 
-       UART0_LCR&=~(0x03<<2);                  // 1 stop bit, no parity
-       UART0_LCR|=0x03;                        // 8 data bits
+void mmap_init(u8 memtype);
+void uart0_init(void);
+void uart0_send_string(char *txbuf);
+void uart0_send_char(char send);
 
-       UART0_FCR=0x01;                         // activate fifo
-}
+/*
+ * main function
+ */
+
+int main(void) {
 
-void uart_send(u8 byte) {
+       /* memory mapping of interrupt vectors to static ram */
 
-       /* wait for empty transmit buffer */
-       while(!(UART0_LSR&(1<<5)))
-               continue;
+       //mmap_init(MMAP_RAM);
 
-       UART0_THR=byte;
-}
+       /* uart initialization */
 
-int main(void) {
+#ifdef USE_FUNCTIONS
+       //uart0_init();
+#else
+       PINSEL0=0x05;                   // pin select -> tx, rx
+       UART0_FCR=0x07;                 // enable fifo
+       UART0_LCR=0x83;                 // set dlab + word length
+       UART0_DLL=0x10;                 // br: 9600 @ 10/4 mhz
+       UART0_DLM=0x00;
+       UART0_LCR=0x03;                 // unset dlab
+#endif
 
-       /* initialization */
-       uart0_init(9600);
+       /* external memory init */
 
        while(1) {
-               uart_send(0x23);
+               while(!(UART0_LSR&(1<<5)))
+                       continue;
+               UART0_THR=0x23;
        }
 
        return 0;
 }
 
+/*
+ * functions
+ */
+
+void mmap_init(u8 memtype) {
+
+       MEMMAP=memtype;
+}
+
+void uart0_init(void) {
+
+       PINSEL0=0x05;                   // pin select -> tx, rx
+       UART0_FCR=0x07;                 // enable fifo
+       UART0_LCR=0x83;                 // set dlab + word length
+       UART0_DLL=0x10;                 // br: 9600 @ 10/4 mhz
+       UART0_DLM=0x00;
+       UART0_LCR=0x03;                 // unset dlab
+}
+
+void uart0_send_string(char *txbuf) {
+
+       int i;
+
+       i=0;
+
+       while(txbuf[i])
+               UART0_THR=txbuf[i++];
+       UART0_THR='\n';
+       UART0_THR='\r';
+
+       while(!(UART0_LSR&(1<<6))) {}
+}
+
+void uart0_send_char(char send) {
+
+       while(!(UART0_LSR&(1<<5)))
+               continue;
+
+       UART0_THR=send;
+}
+