make: check if git is available before calculate version
[pyfrprog.git] / pkernel / flash.c
index c72b4633eb3dfd991932f455f644158d3bb1ae69..8379d1c9d9ae5dc97c6a5670221496d717a1bf8f 100644 (file)
@@ -1,18 +1,6 @@
-/*****************************************************************************/
-/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
-/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
-/* ELIGIBILITY FOR ANY PURPOSES.                                             */
-/*                 (C) Fujitsu Microelectronics Europe GmbH                  */
-/*****************************************************************************/
-
 #include "flash.h"
 #include "mb91465k.h"
 
-static unsigned int IFlag;
-
-#pragma section CODE=IRAM,attr=CODE
-       
-
 void FLASH_PrepareWriteHalfWordMode()
 {
        /*      Set FLASH Access Mode via BootROM Routine       */
@@ -63,123 +51,50 @@ void FLASH_PrepareReadMode()
        FMWT_WTC = 4;
 }              
                
-       
-unsigned char FLASH_SectorErase(unsigned int secadr)
+unsigned char FLASH_ChipErase(void)
 {
        unsigned char flag = 0;
-       volatile unsigned int value = 0;
-       
-       /*      Disable Interrupts if necessary */
-       IFlag = FLASH_SaveDisableInterruptFlag();
 
-       /*      Set FLASH access mode to 16Bit Write Mode       */
+       /*Set FLASH access mode to 16Bit Write Mode*/
        FLASH_PrepareWriteHalfWordMode();
-                                       
-       secadr |= 0x0003;
-       
-       /*      Start FLASH Sector Erase Sequence       */
+
+       /*Start FLASH Sector Erase Sequence*/
        *hseq_1 = 0x00AA;
        *hseq_2 = 0x0055;
        *hseq_1 = 0x0080;
        *hseq_1 = 0x00AA;
        *hseq_2 = 0x0055;
-       *(unsigned  short int *)secadr = 0x0030;
-
-       /*      Wait for the Auto Algorithm to start    */
-       while( !( *(unsigned  short int *)secadr & SETIMR ) )
-       {
-               /*      Feed the Hardware Watchdog      */
-               HWWD_CL = 0;
-               
-               /*      Check for Pending Interrupts    */
-               if( FLASH_CheckPendingInterrupt() )
-               {               
-                       /*      Wait for Sector Erase Suspend   */
-                       FLASH_SuspendSectorErase(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();
-                                               
-                       /*      Sector Erase Resume     */
-                       FLASH_ResumeSectorErase(secadr);
-               }               
-       }
+       *hseq_1 = 0x0010;
 
-       /*      Wait for the Auto Algorithm to finish   */
-       while( flag == 0 )
-       {
+       /*Wait for the Auto Algorithm to finish*/
+       while( flag == 0 ) {
                /* Feed Hardware Watchdog */
                HWWD_CL = 0;
 
-               /*      Check for Pending Interrupts    */
-               if( FLASH_CheckPendingInterrupt() )
-               {               
-                       /*      Sector Erase Suspend    */
-                       FLASH_SuspendSectorErase(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();
-                                               
-                       /*      Sector Erase Resume     */
-                       FLASH_ResumeSectorErase(secadr);
-               }               
-               
-                       
-               /*      Check the Hardware Sequence Flags       */                              
-               if( ( *(unsigned short int *)secadr /* value */ & DPOLL ) )
-               {
+               if(*hseq_1 & DPOLL) {
                        flag = 1;
                }
-               if( ( *(unsigned short int *)secadr /* value */ & TLOVER ) )
-               {
-                       if( ( *(unsigned short int *)secadr /* value */ & DPOLL ) )
-                       {
+               if(*hseq_1 & TLOVER) {
+                       if(*hseq_1 & DPOLL) {
                                flag = 1;
                        }
-                       else
-                       {
-                               /*      Reset FLASH     */
-                               FLASH_ReadReset();
-                               
+                       else {
+                               /*Reset FLASH (keep in mind 16Bit access to FLASH)*/
+                               *hseq_1 = 0x00F0; // Keep in Mind (16Bit access)
+
                                flag = 2;
                        }
                }
        }
-       
 
-       /*      Restore the original Interrupt Flag     */
-       FLASH_RestoreInterruptFlag(IFlag);
-       
-       /*      Set FLASH access mode to 32Bit Read Mode        */
+       /*Set FLASH access mode to 32Bit Read Mode*/
        FLASH_PrepareReadMode();
-               
+
        return flag;
 }
 
+//maybe implement this check too!
+#if 0
 unsigned char FLASH_SectorBlankCheck(unsigned int secaddr, unsigned int size)
 {
        unsigned int count;
@@ -207,14 +122,12 @@ unsigned char FLASH_SectorBlankCheck(unsigned int secaddr, unsigned int size)
        
        return 1;
 }
+#endif
 
 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();
        
@@ -253,13 +166,9 @@ 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;
 }
 
-
 unsigned char FLASH_ReadReset()
 {
        *hseq_1 = 0x00F0;
@@ -267,57 +176,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)
-{              
-       /* Write Sector Erase Suspend Command   */
-       *(volatile unsigned short int *)secaddr = 0x00B0;
-
-       /*      Wait for the FLASH macro to suspend sector erase        */              
-       while(!(*(unsigned short int *)secaddr /* value */ & DPOLL) && (*(unsigned short int *)secaddr /* value */ & SETIMR))
-       {
-               HWWD_CL=0;
-       }
-       
-       return 1;
-}
-
-unsigned char FLASH_ResumeSectorErase(unsigned int secaddr)
-{
-       /*      Write the Sector Erase Resume Command   */
-       *(volatile unsigned short int *)secaddr = 0x0030;
-       
-       /*      Wait for the FLASH Macro to resume sector erase */              
-       while((*(unsigned short int *)secaddr /*value */ & DPOLL) && !(*(unsigned short int *)secaddr /*value */ & SETIMR))
-       {
-               HWWD_CL=0;
-       }
-       
-       return 1;               
-}
-
 unsigned char FLASH_CheckPendingInterrupt()
 {
        /*      Poll for Pending Interrupts which are needed here       */
@@ -326,3 +184,4 @@ unsigned char FLASH_CheckPendingInterrupt()
        /*      and return 1 when an Interrupt is pending       */
        return 0;
 }
+