[Tinyos-commits] CVS: tinyos-1.x/tos/platform/msp430 InternalFlashC.nc, 1.8, 1.9

Jonathan Hui jwhui at users.sourceforge.net
Mon Jun 13 22:42:14 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/tos/platform/msp430
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27219

Modified Files:
	InternalFlashC.nc 
Log Message:
- Fixed critical bug that would cause InternalFlash to misbehave after
128 writes. Wasn't casting a variable to int8_t before testing its
sign.

- Made version -1 be an invalid version number so that an erased but
not yet written flash segment will not be mistaken as a valid segment.



Index: InternalFlashC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tos/platform/msp430/InternalFlashC.nc,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** InternalFlashC.nc	21 Apr 2005 17:25:52 -0000	1.8
--- InternalFlashC.nc	14 Jun 2005 05:42:11 -0000	1.9
***************
*** 54,57 ****
--- 54,58 ----
      IFLASH_SEG0_VNUM_ADDR = 0x107f,
      IFLASH_SEG1_VNUM_ADDR = 0x10ff,
+     IFLASH_INVALID_VNUM = -1;
    };
  
***************
*** 59,70 ****
      int8_t vnum0 = *(int8_t*)IFLASH_SEG0_VNUM_ADDR;
      int8_t vnum1 = *(int8_t*)IFLASH_SEG1_VNUM_ADDR;
!     return !( (vnum0 - vnum1) > 0 );
    }
  
    command result_t InternalFlash.write(void* addr, void* buf, uint16_t size) {
  
!     volatile uint8_t *newPtr;
!     uint8_t *oldPtr;
!     uint8_t *bufPtr = (uint8_t*)buf;
      uint16_t i;
  
--- 60,76 ----
      int8_t vnum0 = *(int8_t*)IFLASH_SEG0_VNUM_ADDR;
      int8_t vnum1 = *(int8_t*)IFLASH_SEG1_VNUM_ADDR;
!     if (vnum0 == IFLASH_INVALID_VNUM)
!       return 1;
!     else if (vnum1 == IFLASH_INVALID_VNUM)
!       return 0;
!     return ( (int8_t)(vnum0 - vnum1) < 0 );
    }
  
    command result_t InternalFlash.write(void* addr, void* buf, uint16_t size) {
  
!     volatile int8_t *newPtr;
!     int8_t *oldPtr;
!     int8_t *bufPtr = (int8_t*)buf;
!     int8_t version;
      uint16_t i;
  
***************
*** 73,77 ****
  
      addr += IFLASH_OFFSET;
!     newPtr = oldPtr = (uint8_t*)IFLASH_OFFSET;
      if (chooseSegment()) {
        oldPtr += IFLASH_SIZE;
--- 79,83 ----
  
      addr += IFLASH_OFFSET;
!     newPtr = oldPtr = (int8_t*)IFLASH_OFFSET;
      if (chooseSegment()) {
        oldPtr += IFLASH_SIZE;
***************
*** 95,99 ****
  	  *newPtr = *bufPtr++;
        }
!       *newPtr = *oldPtr+1;
  
        FCTL1 = FWKEY;
--- 101,108 ----
  	  *newPtr = *bufPtr++;
        }
!       version = *oldPtr + 1;
!       if (version == IFLASH_INVALID_VNUM)
! 	version++;
!       *newPtr = version;
  
        FCTL1 = FWKEY;



More information about the Tinyos-commits mailing list