[Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/imote2 FlashM.nc, 1.3, 1.4

Josh jsherbach at users.sourceforge.net
Wed Aug 24 16:53:43 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/platform/imote2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14552

Modified Files:
	FlashM.nc 
Log Message:
change to allow erasing / writing of flash in any partition

Index: FlashM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/imote2/FlashM.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FlashM.nc	18 Aug 2005 22:08:35 -0000	1.3
--- FlashM.nc	24 Aug 2005 23:53:41 -0000	1.4
***************
*** 23,28 ****
    
    uint8_t FlashPartitionState[FLASH_PARTITION_COUNT];
-   uint8_t FlashBlockState[FLASH_BLOCK_COUNT];
    uint8_t init = 0, programBufferSupported = 2, currBlock = 0;
    
    command result_t StdControl.init() {
--- 23,31 ----
    
    uint8_t FlashPartitionState[FLASH_PARTITION_COUNT];
    uint8_t init = 0, programBufferSupported = 2, currBlock = 0;
+ 
+   extern void __Flash_Erase() __attribute__ ((C,spontaneous));
+   extern void __Flash_Program_Word() __attribute__ ((C,spontaneous));
+   extern void __Flash_Program_Buffer() __attribute__ ((C,spontaneous));
    
    command result_t StdControl.init() {
***************
*** 33,44 ****
      for(i = 0; i < FLASH_PARTITION_COUNT; i++)
        FlashPartitionState[i] = FLASH_STATE_READ_INACTIVE;
-     FlashPartitionState[0] = FLASH_STATE_READ_ACTIVE;//program
-     
-     for(i = 0; i < FLASH_BLOCK_COUNT; i++)
-       if(i < FLASH_PARTITION_SIZE / FLASH_BLOCK_SIZE)
- 	FlashBlockState[i] = FLASH_BLOCK_USED;//saying first partition is used
-       else
- 	FlashBlockState[i] = FLASH_BLOCK_CLEAN;
-     FlashBlockState[i - 1] = FLASH_BLOCK_USED; //UID block is not touched
      
      asm volatile(
--- 36,39 ----
***************
*** 354,399 ****
    uint16_t programBuffer(uint32_t addr, uint16_t data[], uint8_t datalen)   __attribute__((noinline)){
      uint16_t status;
!     //addr <<= 1;
      
      datalen -= 1;
      asm volatile(
! 		 "ldr r1,=FLASH_PROGRAMBUFFER;    \
! 		 ldr r2,=FLASH_READARRAY;	  \
! 		 ldr r3,=0x0;			  \
! 		 ldr r4,=FLASH_CLEARSTATUS;	  \
!                  ldr r5,=FLASH_PROGRAMBUFFERCONF; \
!                  strh r4,[r3];			  \
! 		 strh r1,[%1];			  \
! 		 ldrh r1,[%1];			  \
!                  and r1,r1,#0x80;		  \
!                  cmp r1,#0x0;			  \
!                  beq _goProgramBufferNS;	  \
!                  strh %3, [%1];			  \
!                  _goProgramBufferLoop:		  \
!                  mov r4,r3,LSL #1;		  \
! 		 ldrh r6, [%2,r4];		  \
!                  strh r6, [%1,r4];		  \
!                  add r3,r3,#1;			  \
!                  cmp r3, %3;			  \
!                  ble _goProgramBufferLoop;	  \
!                  mov r4,r3,LSL #1;		  \
!                  strh r5,[%1,r4];		  \
!                  _goProgramBufferSpin:		  \
! 		 ldrh r1,[%1];			  \
!                  and r1,r1,#0x80;		  \
!                  cmp r1,#0x0;			  \
!                  beq _goProgramBufferSpin;	  \
!                  ldrh r1,[%1];			  \
!                  strh r2,[%1];			  \
!                  ldrh r2,[%1];			  \
!                  mov %0, r1;			  \
! 		 b _goProgramBufferEnd;		  \
!                  _goProgramBufferNS:		  \
!                  ldrh %0,=FLASH_OP_NOT_SUPPORTED; \
!                  mov %0,%0,LSL #1;		  \
!                  _goProgramBufferEnd:"
  		 :"=r"(status)
! 		 :"r"(addr), "r"(data), "r"(datalen)
! 		 : "r1", "r2", "r3", "r4", "r5", "r6", "memory");
      return status;
    }
--- 349,372 ----
    uint16_t programBuffer(uint32_t addr, uint16_t data[], uint8_t datalen)   __attribute__((noinline)){
      uint16_t status;
!     uint32_t programBufferCommands[100];/* even though there are only 33 lines
! 					 * of assembly by my count it seems
! 					 * to work better if I allocate / allow
! 					 * for more lines...no clue but this
! 					 * is an issue*/
! 
!     memcpy(programBufferCommands,__Flash_Program_Buffer,100 * 4);
      
      datalen -= 1;
      asm volatile(
! 		 "mov r1, %1;           	\
!                  mov r2, %2;			\
!                  mov r3, %3;			\		 
! 		 mov r14, PC;			\
! 		 mov PC, %4;			\
! 		 mov %0, r0;"
  		 :"=r"(status)
! 		 :"r"(addr), "r"(data),"r"(datalen),"r"(programBufferCommands)
! 		 : "r0", "r1", "r2", "r3", "r14", "memory");
! 
      return status;
    }
***************
*** 401,435 ****
    uint16_t programWord(uint32_t addr, uint16_t data)  __attribute__((noinline)){
      uint16_t status;
!     //addr <<= 1;
!     
      asm volatile(
! 		 "ldr r1,=FLASH_PROGRAMWORD;    \
! 		 ldr r2,=FLASH_READARRAY;	\
! 		 ldr r3,=0x0;			\
! 		 ldr r4,=FLASH_CLEARSTATUS;	\
! 		 b _goProgramWordCacheLine;	\
! 		 .align 5;			\
! 		 _goProgramWordCacheLine:	\
!                  strh r4,[r3];			\
! 		 strh r1,[%1];			\
! 		 strh %2,[%1];			\
! 		 nop;				\
! 		 nop;				\
! 		 nop;				\
! 		 nop;				\
! 		 nop;				\
!                  _goProgramWordSpin:		\
! 		 ldrh r1,[%1];			\
!                  and r1,r1,#0x80;		\
!                  cmp r1,#0x0;			\
!                  beq _goProgramWordSpin;	\
!                  ldrh r1,[%1];			\
!                  strh r2,[%1];			\
!                  ldrh r2,[%1];			\
!                  mov %0, r1;"
  		 :"=r"(status)
! 		 :"r"(addr), "r"(data)
! 		 : "r1", "r2", "r3", "r4", "memory");
!     
      return status;
    }
--- 374,390 ----
    uint16_t programWord(uint32_t addr, uint16_t data)  __attribute__((noinline)){
      uint16_t status;
!     uint32_t programWordCommands[16];
! 
!     memcpy(programWordCommands,__Flash_Program_Word,16 * 4);
! 
      asm volatile(
! 		 "mov r1, %1;                   \
!                  mov r2, %2;			\
!                  mov r14, PC;			\
! 		 mov PC, %3;			\
! 		 mov %0, r0;"		 
  		 :"=r"(status)
! 		 :"r"(addr), "r"(data),"r"(programWordCommands)
! 		 : "r0", "r1", "r2", "memory");
      return status;
    }
***************
*** 437,470 ****
    uint16_t eraseFlash(uint32_t addr)  __attribute__((noinline)){
      uint16_t status;
!     //addr <<= 1;
      asm volatile(
! 		 "ldr r1,=FLASH_ERASEBLOCK;     \
! 		 ldr r2,=FLASH_READARRAY;	\
! 		 ldr r3,=0x0;			\
! 		 ldr r4,=FLASH_ERASECONF;	\
! 		 ldr r5,=FLASH_CLEARSTATUS;	\
! 		 b _goEraseFlashCacheLine;	\
! 		 .align 5;			\
! 		 _goEraseFlashCacheLine:	\
! 		 strh r5,[r3];			\
! 		 strh r1,[%1];			\
! 		 strh r4,[%1];			\
! 		 nop;				\
! 		 nop;				\
! 		 nop;				\
! 		 nop;				\
! 		 nop;				\
!                  _goEraseFlashSpin:		\
! 		 ldrh r1,[%1];			\
!                  and r1,r1,#0x80;		\
!                  cmp r1,#0x0;			\
!                  beq _goEraseFlashSpin;         \
!                  ldrh r1,[%1];			\
!                  strh r2,[%1];			\
!                  ldrh r2,[%1];			\
!                  mov  %0, r1;"
  		 :"=r"(status)
! 		 :"r"(addr)
! 		 : "r1", "r2", "r3", "r4", "r5", "memory");
      return status;
    }
--- 392,406 ----
    uint16_t eraseFlash(uint32_t addr)  __attribute__((noinline)){
      uint16_t status;
!     uint32_t eraseFlashCommands[17];
! 
!     memcpy(eraseFlashCommands,__Flash_Erase,17 * 4);
      asm volatile(
! 		 "mov r1, %1;                   \
!                  mov r14, PC;			\
! 		 mov PC, %2;			\
! 		 mov %0, r0;"		 
  		 :"=r"(status)
! 		 :"r"(addr), "r"(eraseFlashCommands)
! 		 : "r0", "r1", "memory");
      return status;
    }



More information about the Tinyos-beta-commits mailing list