Merge branch 'master' of hackdaworld.org:/chroot/git/my-code/arm
authorhackbard <hackbard@staubsauger.localdomain>
Wed, 8 Aug 2007 01:40:00 +0000 (03:40 +0200)
committerhackbard <hackbard@staubsauger.localdomain>
Wed, 8 Aug 2007 01:40:00 +0000 (03:40 +0200)
betty/fwbc.c
betty/lpc2xxx.h
betty/lpcload.c

index fecb753..a625716 100644 (file)
 
 #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;
 typedef unsigned int u32;
 
-void uart0_init(u32 br) {
+
+/* memory mapping */
+
+#define        MMAP_BL         0x00
+#define MMAP_RAM       0x02
+#define MMAP_EXT       0x03
+
+void mmap_init(u8 memtype) {
+
+       MEMMAP=memtype;
+}
+
+void uart0_init(void) {
 
        /* pin select -> tx rx */
-       PINSEL0&=~((1<<0)|(1<<1)|(1<<2)|(1<<3));
-       PINSEL0|=((1<<0)|(1<<2));
+       PINSEL0=0x05;
 
-       /* divisor */
-       UART0_LCR|=(1<<7);
-       //UART0_DLL=((OSC_CLOCK/(16*br)))&0xff;
-       //UART0_DLM=(((OSC_CLOCK/(16*br)))&0xff00)>>8;
-       UART0_DLL=65;
-       UART0_DLM=0;
+       /* enable fifo */
+       UART0_FCR=0x07;
 
-       /* 8 bit data */
-       UART0_LCR=((1<<0)|(1<<1));
+       /* set dlab + word length */
+       UART0_LCR=0x83;
 
-       /* activate rx tx fifo */
-       UART0_FCR|=((1<<0)|(1<<1)|(1<<2));
+       /* set baud rate to 9600 @ 10/4 mhz */
+       UART0_DLL=0x10;
+       UART0_DLM=0x00;
+
+       /* unset dlab */
+       UART0_LCR=0x03;
 }
 
-void uart_send(u8 byte) {
+void uart_send(char *txbuf) {
+
+       int i;
+
+       i=0;
 
-       /* wait for empty transmit buffer */
-       while(!(UART0_LSR&(1<<5)))
-               continue;
+       while(txbuf[i])
+               UART0_THR=txbuf[i++];
+       UART0_THR='\n';
+       UART0_THR='\r';
 
-       UART0_THR=byte;
+       while(!(UART0_LSR&(1<<6))) {}
 }
 
 int main(void) {
 
+       char txbuf[]="uart0 working";
+
+       /* memory mapping of interrupt vectors to static ram */
+       mmap_init(MMAP_RAM);
+
        /* initialization */
-       uart0_init(9600);
+       uart0_init();
 
        while(1) {
-               uart_send(0x23);
+               uart_send(txbuf);
        }
 
        return 0;
index e7d5c49..4dd46ad 100644 (file)
 /* Memory Accelerator Module (MAM) */\r
 #define MAMCR          (*((volatile unsigned long *) 0xE01FC000))\r
 #define MAMTIM         (*((volatile unsigned long *) 0xE01FC004))\r
-#define MAMMAP         (*((volatile unsigned long *) 0xE01FC040))\r
+\r
+/* Memory Mapping control register */\r
+#define MEMMAP         (*((volatile unsigned long *) 0xE01FC040))\r
 \r
 /* Phase Locked Loop (PLL) */\r
 #define PLLCON         (*((volatile unsigned long *) 0xE01FC080))\r
index 0d2f9c8..80af804 100644 (file)
@@ -112,11 +112,15 @@ int open_serial_device(t_lpc *lpc) {
        //term.c_iflag&=~(IXON|IXOFF|IXANY|INLCR|ICRNL);
        term.c_iflag&=~(INLCR|ICRNL|IXANY);
        term.c_iflag|=(IXON|IXOFF);
+       
+       // output options
+
+       term.c_oflag=0;
 
        // more control options -> timeout / flow control
        
        term.c_cc[VMIN]=0;
-       term.c_cc[VTIME]=10;    // 1 second timeout
+       term.c_cc[VTIME]=40;    // 4 second timeout
        term.c_cc[VSTART]=0x11;
        term.c_cc[VSTOP]=0x13;
 
@@ -471,12 +475,15 @@ int firmware_to_ram(t_lpc *lpc) {
                }
                /* act according to type */
                switch(type) {
-                       case 0x03:
-                               /* get cs and ip */
-                               break;
+                       //case 0x03:
+                       //      /* get cs and ip */
+                       //      break;
                        case 0x00:
                                write_to_ram(lpc,buf,addr,len);
                                break;
+                       case 0x01:
+                               write_to_ram(lpc,buf,addr,len);
+                               break;
                        default:
                                printf("fw to ram: unknown type %02x\n",type);
                                return -1;
@@ -490,6 +497,8 @@ int main(int argc,char **argv) {
 
        t_lpc lpc;
        int i;
+       u8 buf[BUFSIZE];
+       int ret;
 
        /*
         * initial ... 
@@ -533,15 +542,21 @@ int main(int argc,char **argv) {
        if(open_serial_device(&lpc)<0)
                goto end;
 
-       /* open firmware file */
-       if(open_firmware(&lpc)<0)
-               goto end;
-
        /* boot loader init */
        printf("boot loader init ...\n");
        if(bl_init(&lpc)<0)
                return -1;
 
+       /* quit if there is no hex file to process */
+       if(!(lpc.info&FIRMWARE)) {
+               printf("no firmware -> aborting\n");
+               goto end;
+       }
+
+       /* open firmware file */
+       if(open_firmware(&lpc)<0)
+               goto end;
+
        /* parse intel hex file and write to ram */
        printf("write firmware to ram ...\n");
        firmware_to_ram(&lpc);
@@ -552,9 +567,31 @@ int main(int argc,char **argv) {
 
        /* go! */
        printf("go ...\n");
-       go(&lpc);
+       ret=go(&lpc);
+
+       /* tell the user that the error might be due to the jump */
+       printf("\n\n");
+       if(ret<0)
+               printf("the above error might be due to the jump!\n\n");
+
+       /* query user for serial port listening */
+       printf("continue listening on serial port? (ctrl+c to quit) [y|n]: ");
+       buf[0]=getchar();
        printf("\n");
 
+       if(buf[0]!='y')
+               goto end;
+
+       /* continue lsitening on serial port */
+       ret=1;
+       while(ret) {
+               ret=read(lpc.sfd,buf,BUFSIZE);
+               printf("\rread %d bytes: ",ret);
+               for(i=0;i<ret;i++)
+                       printf("%02x ",buf[i]);
+               printf("\n");
+       }
+
 end:
        close(lpc.sfd);
        close(lpc.fwfd);