[Tinyos-2-commits] CVS: tinyos-2.x/tos/platforms/intelmote2/chips/pxa271 BlockStorageC.nc, NONE, 1.1.2.1 Flash.nc, NONE, 1.1.2.1 FlashC.nc, NONE, 1.1.2.1 HalP30P.nc, NONE, 1.1.2.1 Storage_chip.h, NONE, 1.1.2.1

Philip Buonadonna philipb at users.sourceforge.net
Thu Jun 1 11:34:16 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/tos/platforms/intelmote2/chips/pxa271
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30885

Added Files:
      Tag: tinyos-2_0_devel-BRANCH
	BlockStorageC.nc Flash.nc FlashC.nc HalP30P.nc Storage_chip.h 
Log Message:
Added addditional storage files.

--- NEW FILE: BlockStorageC.nc ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the
 *   distribution.
 * - Neither the name of the Arched Rock Corporation nor the names of
 *   its contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE
 */

/**
 * Implementation of the block storage abstraction for the pxa271
 * embedded flash.
 *
 * @author Philip Buonadonna
 * @version $Revision: 1.1.2.1 $ $Date: 2006/06/01 18:34:14 $
 */

generic configuration BlockStorageC( volume_id_t volume_id ) {

  provides interface BlockRead;
  provides interface BlockWrite;
}

implementation {

  enum {
    BLOCK_ID = unique( "pxa271p30.Block" ),
    VOLUME_ID = unique( "pxa27xp30.Volume" ),
  };

}

--- NEW FILE: Flash.nc ---
/**
 * Interface for writing and erasing in flash memory
 *
 * Author:		Josh Herbach
 * Revision:	1.0
 * Date:		09/02/2005
 */

interface Flash
{
  /**
   * Writes numBytes of the buffer data to the address in flash specified
   * by addr. This function will only set bits low for the bytes it is 
   * supposed to write to.If addr connot be written to for any reason returns
   * FAIL, otherwise returns SUCCESS.
   *
   * @returns SUCCESS or FAIL.
   */
  command error_t write(uint32_t addr, uint8_t* data, uint32_t numBytes);

  /**
   * Erases the block of flash that contains addr, setting all bits to 1.
   * If this function fails for any reason it will return FAIL, otherwise 
   * SUCCESS.
   *
   * @returns SUCCESS or FAIL.
   */
  command error_t erase(uint32_t addr);
}




--- NEW FILE: FlashC.nc ---
/* 
 * Author:		Josh Herbach
 * Revision:	1.0
 * Date:		09/02/2005
 */

configuration FlashC {
  provides interface Flash;
}
implementation {
  components 
    Main,
    FlashM;

  Main.StdControl -> FlashM;
  Flash = FlashM;
}

--- NEW FILE: HalP30P.nc ---
/* 
 * Author:		Josh Herbach
 * Revision:	1.0
 * Date:		09/02/2005
 */
module HalP30P {
  provides interface Init;
  provides interface Flash; //does not allow writing into FLASH_PROTECTED_REGION
  uses interface HplP30;
}
implementation {
  
#include <P30.h>
#define FLASH_PARTITION_COUNT 16
#define FLASH_PARTITION_SIZE 0x200000
#define FLASH_PROTECTED_REGION 0x00200000
#define FLASH_PROGRAM_BUFFER_SIZE 32
  //#define FLASH_NOT_SUPPORTED 0x100
  enum {
    FLASH_STATE_READ_INACTIVE, 
    FLASH_STATE_PROGRAM,
    FLASH_STATE_ERASE,
    FLASH_STATE_READ_ACTIVE
  };

  uint8_t FlashPartitionState[FLASH_PARTITION_COUNT];
  uint8_t init = 0, programBufferSupported = 2, currBlock = 0;
  
  command error_t Init.init() {
    int i = 0;
    if(init != 0)
      return SUCCESS;
    init = 1;
    for(i = 0; i < FLASH_PARTITION_COUNT; i++) 
      FlashPartitionState[i] = FLASH_STATE_READ_INACTIVE;
    
    return SUCCESS;
  }
  
  uint16_t writeHelper(uint32_t addr, uint8_t* data, uint32_t numBytes,
		       uint8_t prebyte, uint8_t postbyte){
    uint32_t i = 0, j = 0, k = 0;
    error_t status;
    uint16_t buffer[FLASH_PROGRAM_BUFFER_SIZE];
    
    if(numBytes == 0)
      return FAIL;
    
    if(addr % 2 == 1){
      status = call HplP30.progWord(addr - 1, prebyte | (data[i] << 8));
      i++;
      if(status != SUCCESS)
	return FAIL;
    }
    
    if(addr % 2 == numBytes % 2){
      if(programBufferSupported == 1)
	for(; i < numBytes; i = k){
	  for(j = 0, k = i; k < numBytes && 
		j < FLASH_PROGRAM_BUFFER_SIZE; j++, k+=2)
	    buffer[j] = data[k] | (data[k + 1] << 8);
	  status = call HplP30.progBuffer(addr + i, buffer, j);
	  if(status != SUCCESS)
	    return FAIL;
	}
      else
	for(; i < numBytes; i+=2){
	  status = call HplP30.progWord(addr + i, (data[i + 1] << 8) | data[i]);
	  if(status != SUCCESS)
	    return FAIL;
	}
    }
    else{
      if(programBufferSupported == 1)
	for(; i < numBytes - 1; i = k){
	  for(j = 0, k = i; k < numBytes - 1 && 
		j < FLASH_PROGRAM_BUFFER_SIZE; j++, k+=2)
	    buffer[j] = data[k] | (data[k + 1] << 8);
	  status = call HplP30.progBuffer(addr + i, buffer, j);
	  if(status != SUCCESS)
	    return FAIL;
	}
      else
	for(; i < numBytes - 1; i+=2){
	  status = call HplP30.progWord(addr + i, (data[i + 1] << 8) | data[i]);
	  if(status != SUCCESS)
	    return FAIL;
	}
      status = call HplP30.progWord(addr + i, data[i] | (postbyte << 8));
      if(status != SUCCESS)
	return FAIL;
    }
    return SUCCESS;
  }
  
  void writeExitHelper(uint32_t addr, uint32_t numBytes){
    uint32_t i = 0;
    for(i = addr / FLASH_PARTITION_SIZE;
	i < (numBytes + addr) / FLASH_PARTITION_SIZE;
	i++)
      FlashPartitionState[i] = FLASH_STATE_READ_INACTIVE;
  }
  
  command error_t Flash.write(uint32_t addr, uint8_t* data, uint32_t numBytes) {
    uint32_t i;
    uint16_t status;
    uint8_t blocklen;
    uint32_t blockAddr = (addr / P30_BLOCK_SIZE) * P30_BLOCK_SIZE;
    
    if(addr + numBytes > 0x02000000) //not in the flash memory space
      return FAIL;
    if(addr < FLASH_PROTECTED_REGION)
      return FAIL;
    
    
    for(i = 0; i < FLASH_PARTITION_COUNT; i++)
      if(i != addr / FLASH_PARTITION_SIZE &&
	 FlashPartitionState[i] != FLASH_STATE_READ_INACTIVE &&
	 FlashPartitionState[i] != FLASH_STATE_READ_ACTIVE)
	return FAIL;
    
    
    for(i = addr / FLASH_PARTITION_SIZE;
	i < (numBytes + addr) / FLASH_PARTITION_SIZE;
	i++)
      if(FlashPartitionState[i] != FLASH_STATE_READ_INACTIVE)
	return FAIL;
    
    for(i = addr / FLASH_PARTITION_SIZE;
	i < (numBytes + addr) / FLASH_PARTITION_SIZE;
	i++)
      FlashPartitionState[i] = FLASH_STATE_PROGRAM;

    atomic{
      for(blocklen = 0, i = blockAddr;
	  i < addr + numBytes;
	  i += P30_BLOCK_SIZE, blocklen++)
	call HplP30.blkUnlock(i); //unlock(i);
      
      if(programBufferSupported == 2){
	uint16_t testBuf[1];
	
	if(addr % 2 == 0){
	  testBuf[0] = data[0] | ((*((uint8_t *)(addr + 1))) << 8);
	  status = call HplP30.progBuffer(addr, testBuf, 1);
	}
	else{
	  testBuf[0] = *((uint8_t *)(addr - 1)) | (data[0] << 8);
	  status = call HplP30.progBuffer(addr - 1, testBuf, 1);
	}      
	if(status != SUCCESS)
	  programBufferSupported = 0;
	else 
	  programBufferSupported = 1;
      }
    }
    if(blocklen == 1){
      atomic status = writeHelper(addr,data,numBytes,0xFF,0xFF);
      if(status == FAIL){
	writeExitHelper(addr, numBytes);
	return FAIL;
      }
    }
    else{
      uint32_t bytesLeft = numBytes;
      atomic status = writeHelper(addr,data, blockAddr + P30_BLOCK_SIZE - addr,0xFF,0xFF);
      if(status == FAIL){
	writeExitHelper(addr, numBytes);
	return FAIL;
      }
      bytesLeft = numBytes - (P30_BLOCK_SIZE - (addr - blockAddr));
      for(i = 1; i < blocklen - 1; i++){
	atomic status = writeHelper(blockAddr + i * P30_BLOCK_SIZE, (uint8_t *)(data + numBytes - bytesLeft),
				    P30_BLOCK_SIZE,0xFF,0xFF);
	bytesLeft -= P30_BLOCK_SIZE;
	if(status == FAIL){
	  writeExitHelper(addr, numBytes);
	  return FAIL;
	}
      }
      atomic status = writeHelper(blockAddr + i * P30_BLOCK_SIZE, data + (numBytes - bytesLeft), bytesLeft, 0xFF,0xFF);
      if(status == FAIL){
	writeExitHelper(addr, numBytes);
	return FAIL;
      }
    }
    
    writeExitHelper(addr, numBytes);
    return SUCCESS;
  }
  
  command error_t Flash.erase(uint32_t addr){
    uint16_t status, i;
    uint32_t j;
    
    if(addr > 0x02000000) //not in the flash memory space
      return FAIL;
    if(addr < FLASH_PROTECTED_REGION)
      return FAIL;
    
    addr = (addr / P30_BLOCK_SIZE) * P30_BLOCK_SIZE;
    
    for(i = 0; i < FLASH_PARTITION_COUNT; i++)
      if(i != addr / FLASH_PARTITION_SIZE &&
	 FlashPartitionState[i] != FLASH_STATE_READ_INACTIVE &&
	 FlashPartitionState[i] != FLASH_STATE_READ_ACTIVE)
	return FAIL;
    
    if(FlashPartitionState[addr / FLASH_PARTITION_SIZE] != FLASH_STATE_READ_INACTIVE)
      return FAIL;
    
    FlashPartitionState[addr / FLASH_PARTITION_SIZE] = FLASH_STATE_ERASE;
    
    for(j = 0; j < P30_BLOCK_SIZE; j++){
      uint32_t tempCheck = *(uint32_t *)(addr + j);
      if(tempCheck != 0xFFFFFFFF)
	break;
      if(j == P30_BLOCK_SIZE - 1){
	FlashPartitionState[addr / FLASH_PARTITION_SIZE] = FLASH_STATE_READ_INACTIVE;
	return SUCCESS;
      }
    }
    atomic{
      call HplP30.blkUnlock(addr);
      //      status = eraseFlash(addr);
      status = call HplP30.blkErase(addr);
    }
    FlashPartitionState[addr / FLASH_PARTITION_SIZE] = FLASH_STATE_READ_INACTIVE;
    if(status != SUCCESS)
      return FAIL;
    
    return SUCCESS;
  }
  
}

--- NEW FILE: Storage_chip.h ---
/**
 * Copyright (c) 2005-2006 Arched Rock Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the
 *   distribution.
 * - Neither the name of the Arched Rock Corporation nor the names of
 *   its contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 * ARCHED ROCK OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE
 *
 * @author Phil Buonadonna
 * @version $Revision: 1.1.2.1 $ $Date: 2006/06/01 18:34:14 $
 */

#ifndef __STORAGE_CHIP_H__
#define __STORAGE_CHIP_H__

typedef uint8_t storage_volume_t;
typedef uint8_t storage_block_t;
typedef uint8_t storage_log_t;
typedef storage_addr_t storage_cookie_t;

#endif



More information about the Tinyos-2-commits mailing list