Merge branch 'master' of wien.tomnetworks.com:pyfrprog
authorBernhard Urban <lewurm@gmx.net>
Mon, 14 Dec 2009 08:47:29 +0000 (09:47 +0100)
committerBernhard Urban <lewurm@gmx.net>
Mon, 14 Dec 2009 08:47:29 +0000 (09:47 +0100)
pkernel/flash.c
pkernel/kernel.py
pkernel/main.c

index e7049f3d133c9fa1297d798c1716119170f32376..cd1b20c26c108ea286c2625fdc7b7da2ca0800df 100644 (file)
@@ -8,8 +8,6 @@
 #include "flash.h"
 #include "mb91465k.h"
 
-static unsigned int IFlag;
-
 void FLASH_PrepareWriteHalfWordMode()
 {
        /*      Set FLASH Access Mode via BootROM Routine       */
@@ -64,9 +62,6 @@ unsigned char FLASH_ChipErase(void)
 {
        unsigned char flag = 0;
 
-       /*Disable Interrupts if necessary*/
-       IFlag = FLASH_SaveDisableInterruptFlag();
-
        /*Set FLASH access mode to 16Bit Write Mode*/
        FLASH_PrepareWriteHalfWordMode();
 
@@ -102,9 +97,6 @@ unsigned char FLASH_ChipErase(void)
        /*Set FLASH access mode to 32Bit Read Mode*/
        FLASH_PrepareReadMode();
 
-       /*Restore the original Interrupt Flag*/
-       FLASH_RestoreInterruptFlag(IFlag);
-
        return flag;
 }
        
@@ -113,9 +105,6 @@ unsigned char FLASH_SectorErase(unsigned int secadr)
        unsigned char flag = 0;
        volatile unsigned int value = 0;
        
-       /*      Disable Interrupts if necessary */
-       IFlag = FLASH_SaveDisableInterruptFlag();
-
        /*      Set FLASH access mode to 16Bit Write Mode       */
        FLASH_PrepareWriteHalfWordMode();
                                        
@@ -144,15 +133,9 @@ unsigned char FLASH_SectorErase(unsigned int secadr)
                /*      Set FLASH access mode to 32Bit Read Mode        */
                FLASH_PrepareReadMode();
                        
-                       /*      Restore the original Interrupt Flag     */
-                       FLASH_RestoreInterruptFlag(IFlag);
-                                               
                        /*      Keep on checking for pending Interrupts */
                        while( FLASH_CheckPendingInterrupt() ) HWWD_CL = 0;
                        
-                       /*      Disable Interrupts if necessary */
-                       IFlag = FLASH_SaveDisableInterruptFlag();
-                       
                        /*      Set FLASH access mode to 16Bit Write Mode       */
                FLASH_PrepareWriteHalfWordMode();
                                                
@@ -176,14 +159,8 @@ unsigned char FLASH_SectorErase(unsigned int secadr)
                /*      Set FLASH access mode to 32Bit Read Mode        */
                FLASH_PrepareReadMode();
                                        
-                       /*      Restore the original Interrupt Flag     */
-                       FLASH_RestoreInterruptFlag(IFlag);
-                                                                       
                        /*      Keep on checking for pending Interrupts */
                        while( FLASH_CheckPendingInterrupt() ) HWWD_CL = 0;
-
-                       /*      Disable Interrupts if necessary */
-                       IFlag = FLASH_SaveDisableInterruptFlag();
                        
                        /*      Set FLASH access mode to 16Bit Write Mode       */
                FLASH_PrepareWriteHalfWordMode();
@@ -213,11 +190,6 @@ unsigned char FLASH_SectorErase(unsigned int secadr)
                        }
                }
        }
-       
-
-       /*      Restore the original Interrupt Flag     */
-       FLASH_RestoreInterruptFlag(IFlag);
-       
        /*      Set FLASH access mode to 32Bit Read Mode        */
        FLASH_PrepareReadMode();
                
@@ -256,9 +228,6 @@ unsigned char FLASH_WriteHalfWord(unsigned int adr, unsigned short int data)
 {
        unsigned char flag = 0;
 
-       /*      Disable Interrupts if necessary */
-       IFlag = FLASH_SaveDisableInterruptFlag();
-                       
        /*      Set FLASH access mode to 16Bit Write Mode       */
        FLASH_PrepareWriteHalfWordMode();
        
@@ -297,9 +266,6 @@ unsigned char FLASH_WriteHalfWord(unsigned int adr, unsigned short int data)
        /*      Set FLASH access mode to 32Bit Read Mode        */
        FLASH_PrepareReadMode();
        
-       /*      Restore the original Interrupt Flag     */
-       FLASH_RestoreInterruptFlag(IFlag);
-       
        return flag;
 }
 
@@ -311,28 +277,6 @@ unsigned char FLASH_ReadReset()
        return 1;
 }
 
-#pragma asm
-_FLASH_SaveDisableInterruptFlag:
-       STM0 (R0)
-       MOV PS,R4
-       LDI     #0x00000010,R0  
-       AND R0,R4                       ; Store Original Flag
-       ANDCCR #0xFFFFFFEF      ; Clear Interrupt Flag
-       LDM0 (R0)       
-       RET
-#pragma endasm
-
-
-#pragma asm
-_FLASH_RestoreInterruptFlag:
-       STM0 (R0)
-       MOV PS,R0                       ; Get current PS
-       OR R4,R0                        ; Set Flag as saved
-       MOV R0,PS                       ; Write back PS
-       LDM0 (R0)
-       RET
-#pragma endasm
-
 
 unsigned char FLASH_SuspendSectorErase(unsigned int secaddr)
 {              
index e495a86b693f10d2a9557d15a57f1052898e5ca4..afadfcd4662e95c9a81625ed1cb75479b20ccbb5 100755 (executable)
@@ -11,6 +11,22 @@ def recvByte():
        i = tty.read()
        return ord(i)
 
+def recvByteTO(b): #with timeout
+       j = 0
+       i = tty.read()
+       while len(i)==0 and j < 400:
+               time.sleep(0.03)
+               i = tty.read()
+               j = j + 1
+       if j == 400:
+               print "ack it!"
+               sendByte(0x23)
+               if(recvByte() != 0xaa):
+                       raise Exception #ok, something really failed
+       else:
+               if(ord(i) != b):
+                       raise Exception
+
 def sendByte(byte):
        time.sleep(0.005) # just to get sure, wait 5ms
        tty.write(chr(byte))
@@ -50,28 +66,16 @@ def pkernWRITE(address, size, data):
        print "address:", hex(address), "size:", size
        # send WRITE command
        sendByte(0x13)
-       if (recvByte() != 0x37):
-               raise Exception
+       recvByteTO(0x37)
+
        # tell desired address and size
        sendDWord(address)
        sendWord(size)
 
-       if (recvByte() != 0x04):
-               raise Exception
-       print "Received Metadata."
-
        # write binary stream of data
        for i in range(0, size):
                sendByte(data[i])
 
-       if (recvByte() != 0x08):
-               raise Exception
-       print "Received Data."
-
-       if (recvByte() != 0x28):
-               raise Exception
-       print "Flashing done."
-
 
 class FlashSequence(object):
        def __init__(self, address, data):
@@ -144,6 +148,8 @@ for seq in flashseqs:
        print "Flashing", len(seq.data), "bytes at address", hex(seq.address)
        pkernWRITE(seq.address, len(seq.data), seq.data)
 
-sendByte(0x99);
+#sendByte(0x99); #exit and wait
+#print "Reset your board now to run code from Flash"
+
 
-print "Reset your board now to run code from Flash"
+sendByte(0x97); #exit and restart
index c40924f4b3c9c3c39e484a486734bba55491b5bb..ac9c20b9cfdc98eac7c531d4061d731700cde817 100644 (file)
@@ -1,13 +1,12 @@
 #include "mb91465k.h"
 #include "flash.h"
 
-#define BUFSIZE 0x20
+#define BUFSIZE 0x10
 #define cleardata() memset(data,0,BUFSIZE)
 
 static void increaseled(void)
 {
        PDR14 = ~(((~PDR14)+1)%256);
-       HWWD_CL = 0;
 }
 
 static unsigned char recvbyte(void)
@@ -68,6 +67,7 @@ void main(void)
        while(running) {
                cleardata();
                increaseled();
+
                switch(recvbyte()) {
                        case 0x15: //chip erase
                                Putch4(0x45);
@@ -106,13 +106,11 @@ void main(void)
                                size = recvword();
                                increaseled();
 
-                               Putch4(0x04); //Received Metadata.
                                PDR14 = 0xff;
                                for(i=0; i<size; i++) { /* get data */
                                        increaseled();
                                        data[i] = recvbyte();
                                }
-                               Putch4(0x08); //Received Data.
 
                                PDR14 = 0xff;
                                for(i=0; i<size; i+=2) { /* flash the data */
@@ -122,9 +120,17 @@ void main(void)
                                                panic();
                                        }
                                }
-                               Putch4(0x28); //Flashing done.
                                break;
 
+                       case 0x23: //ack it
+                               Putch4(0xaa);
+                               break;
+
+                       case 0x97: /* exit and restart (let do this by the watchdog)! */
+                               while(1) {
+                                       increaseled();
+                               }
+
                        case 0x99: /* exit */
                                running = 0;
                                break;