Added flash reads and writes to energest.

This commit is contained in:
nvt-se 2009-05-11 15:26:24 +00:00
parent 4855d0325c
commit 74e9bc8789
2 changed files with 15 additions and 2 deletions

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: energest.h,v 1.3 2008/10/14 12:46:39 nvt-se Exp $
* $Id: energest.h,v 1.4 2009/05/11 15:26:24 nvt-se Exp $
*/
/**
@ -58,6 +58,9 @@ enum energest_type {
ENERGEST_TYPE_TRANSMIT,
ENERGEST_TYPE_LISTEN,
ENERGEST_TYPE_FLASH_READ,
ENERGEST_TYPE_FLASH_WRITE,
ENERGEST_TYPE_SENSORS,
ENERGEST_TYPE_SERIAL,

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)$Id: xmem.c,v 1.7 2008/07/03 23:12:10 adamdunkels Exp $
* @(#)$Id: xmem.c,v 1.8 2009/05/11 15:26:24 nvt-se Exp $
*/
/**
@ -169,6 +169,8 @@ xmem_pread(void *_p, int size, unsigned long offset)
int s;
wait_ready();
ENERGEST_ON(ENERGEST_TYPE_FLASH_READ);
s = splhigh();
SPI_FLASH_ENABLE();
@ -186,6 +188,9 @@ xmem_pread(void *_p, int size, unsigned long offset)
SPI_FLASH_DISABLE();
splx(s);
ENERGEST_OFF(ENERGEST_TYPE_FLASH_READ);
return size;
}
/*---------------------------------------------------------------------------*/
@ -224,6 +229,8 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
const unsigned long end = addr + size;
unsigned long i, next_page;
ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE);
for(i = addr; i < end;) {
next_page = (i | 0xff) + 1;
if(next_page > end) {
@ -232,6 +239,9 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr)
p = program_page(i, p, next_page - i);
i = next_page;
}
ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE);
return size;
}
/*---------------------------------------------------------------------------*/