[Tinyos-commits] CVS: tinyos-1.x/tos/platform/pc HPLSTM25P.h, NONE,
1.1 HPLSTM25PC.nc, NONE, 1.1
Jonathan Hui
jwhui at users.sourceforge.net
Mon Jul 11 20:03:30 PDT 2005
Update of /cvsroot/tinyos/tinyos-1.x/tos/platform/pc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11935
Added Files:
HPLSTM25P.h HPLSTM25PC.nc
Log Message:
- Support for STM25P storage stack on pc platform.
--- NEW FILE: HPLSTM25P.h ---
// $Id: HPLSTM25P.h,v 1.1 2005/07/12 03:03:28 jwhui Exp $
/* tab:2
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* @author: Jonathan Hui <jwhui at cs.berkeley.edu>
*/
#ifndef __HPLSTM25P_H__
#define __HPLSTM25P_H__
enum {
STM25P_FLASH_SIZE = 16L*65536L,
};
enum {
STM25P_CMD_WREN = 0x06,
STM25P_CMD_WRDI = 0x04,
STM25P_CMD_RDSR = 0x05,
STM25P_CMD_WRSR = 0x01,
STM25P_CMD_READ = 0x03,
STM25P_CMD_FAST_READ = 0x0b,
STM25P_CMD_PP = 0x02,
STM25P_CMD_SE = 0xd8,
STM25P_CMD_BE = 0xc7,
STM25P_CMD_DP = 0xb9,
STM25P_CMD_RES = 0xab,
};
enum {
WIP = 0,
WEL = 1 << 1,
BP = 1 << 2,
SRWP = 1 << 7,
};
#endif
--- NEW FILE: HPLSTM25PC.nc ---
// $Id: HPLSTM25PC.nc,v 1.1 2005/07/12 03:03:28 jwhui Exp $
/* tab:2
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* @author: Jonathan Hui <jwhui at cs.berkeley.edu>
*/
includes HPLSTM25P;
module HPLSTM25PC {
provides {
interface StdControl;
interface HPLSTM25P;
}
}
implementation {
enum {
S_POWEROFF = 0xfe,
S_POWERON = 0xff,
};
enum {
WRITE_DELAY = 6000, // 1.5ms
};
norace uint8_t state;
norace uint8_t status;
norace uint8_t addressBytesLoaded;
norace uint32_t curAddr;
norace uint8_t eraseBuf[256];
norace event_t flash_event;
void event_flash_create(event_t* fevent, int mote, long long ftime);
command result_t StdControl.init() {
state = S_POWERON;
status = 0;
addressBytesLoaded = 0;
curAddr = 0;
event_flash_create(&flash_event, tos_state.current_node, 0);
memset(eraseBuf, 0xff, 256);
dbg(DBG_USR1, "STM25P Initialized.\n");
return SUCCESS;
}
command result_t StdControl.start() { return SUCCESS; }
command result_t StdControl.stop() { return SUCCESS; }
async command result_t HPLSTM25P.getBus() { return SUCCESS; }
async command result_t HPLSTM25P.releaseBus() { return SUCCESS; }
async command result_t HPLSTM25P.beginCmd() { return SUCCESS; }
async command result_t HPLSTM25P.endCmd() {
if ( state == STM25P_WRSR || state == STM25P_PP
|| state == STM25P_SE || state == STM25P_BE ) {
status += WIP;
flash_event.time = tos_state.tos_time + WRITE_DELAY;
queue_insert_event(&(tos_state.queue), &flash_event);
}
state = S_POWERON;
addressBytesLoaded = 0;
curAddr = 0;
return SUCCESS;
}
async command result_t HPLSTM25P.hold() { return SUCCESS; }
async command result_t HPLSTM25P.unhold() { return SUCCESS; }
async command result_t HPLSTM25P.txBuf(void* buf, stm25p_addr_t len) {
uint8_t* bufByte = (uint8_t*)buf;
uint32_t i;
if (state == S_POWERON) {
state = *bufByte++;
len--;
}
switch(state) {
case STM25P_CMD_WREN:
status |= WEL;
break;
case STM25P_CMD_WRDI:
status &= ~WEL;
break;
case STM25P_CMD_RDSR:
break;
case STM25P_CMD_WRSR:
status = (status & WIP) | (*bufByte++ & ~WIP);
break;
case STM25P_CMD_READ:
for ( ; addressBytesLoaded < 3 && len; addressBytesLoaded++, len-- )
curAddr |= (*bufByte++ & 0xff) << (2-addressBytesLoaded)*8;
break;
case STM25P_CMD_FAST_READ:
break;
case STM25P_CMD_PP:
for ( ; addressBytesLoaded < 3 && len; addressBytesLoaded++, len-- )
curAddr |= (*bufByte++ & 0xff) << (2-addressBytesLoaded)*8;
if ( status & WEL ) {
for ( i = 0; i < len; i++, curAddr++ ) {
uint8_t tmpBufByte;
readEEPROM(&tmpBufByte, tos_state.current_node, curAddr, 1);
tmpBufByte &= *bufByte++;
writeEEPROM(&tmpBufByte, tos_state.current_node, curAddr, 1);
}
}
break;
case STM25P_CMD_SE:
for ( ; addressBytesLoaded < 3 && len; addressBytesLoaded++, len-- )
curAddr |= (*bufByte++ & 0xff) << (2-addressBytesLoaded)*8;
curAddr &= 0xff0000;
if ( status & WEL ) {
if ( addressBytesLoaded == 3 ) {
for ( i = 0; i < STM25P_SECTOR_SIZE; i += 256, curAddr += 256 )
writeEEPROM(eraseBuf, tos_state.current_node, curAddr, 256);
}
}
break;
case STM25P_CMD_BE:
if ( status & WEL ) {
for ( i = 0; i < STM25P_FLASH_SIZE; i += 256 )
writeEEPROM(eraseBuf, tos_state.current_node, i, 256);
}
break;
case STM25P_CMD_DP:
break;
case STM25P_CMD_RES:
break;
}
return SUCCESS;
}
async command result_t HPLSTM25P.rxBuf(void* buf, stm25p_addr_t len, uint16_t* crcResult) {
uint16_t crc = *crcResult;
uint8_t* bufByte = (uint8_t*)buf;
uint8_t tmp;
uint32_t i;
switch(state) {
case STM25P_CMD_RDSR:
*bufByte++ = status;
break;
case STM25P_CMD_READ:
for ( i = 0; i < len; i++, curAddr++ ) {
readEEPROM(&tmp, tos_state.current_node, curAddr, 1);
crc = crcByte(crc, tmp);
if (buf != NULL)
*bufByte++ = tmp;
}
break;
case STM25P_CMD_FAST_READ:
break;
case STM25P_CMD_RES:
break;
default:
dbg(DBG_USR1, "rxBuf : unexpected command %d\n", state);
}
*crcResult = crc;
return SUCCESS;
}
void event_flash_handle(event_t* fevent, struct TOS_state* fstate) {
status &= ~WIP;
}
void event_flash_cleanup(event_t* fevent) {
// Since logger events are statically allocated,
// we shouldn't deallocate anything; since this function
// should never be called, we set the fields so they
// will cause a SEGV if used as is.
fevent->time = -1;
fevent->handle = 0;
fevent->cleanup = 0;
fevent->mote = 0xffffffff;
}
void event_flash_create(event_t* fevent, int mote, long long ftime) {
fevent->mote = mote;
fevent->time = ftime;
fevent->data = NULL;
fevent->handle = event_flash_handle;
fevent->cleanup = event_flash_cleanup;
fevent->pause = 0;
}
}
More information about the Tinyos-commits
mailing list