Sun SPOT API
Green Release  


com.sun.spot.peripheral
Interface IFlashMemoryDevice

All Known Implementing Classes:
M25P05

public interface IFlashMemoryDevice

Interface to flash memory devices on the main Spot board and sensor board.

Author:
Syntropy

Method Summary
 void eraseChip()
          Erase all data in the chip
 void eraseSectorAtAddress(int address)
          Erase a sector
 int getFirstAvailableSector()
          Get the sector number of the first sector that can be used with the input and output streams.
 InputStream getInputStream(int startSectorNum, int numOfSectors)
          Create an input stream over a logical device formed of selected sectors of the physical device.
 int getNumberOfSectors()
          Get the number of sectors in the device.
 int getNumberOfSectorsInRegion(int addrToFlash, int dataSize)
          Find the number of sectors in a region of the flash memory.
 OutputStream getOutputStream(int startSectorNum, int numOfSectors)
          Create an output stream over a logical device formed of selected sectors of the physical device.
 int getPageSize()
          Get the page size for writing.
 int getSectorContainingAddress(int addrToFlash)
          Find the sector associated with a given address in the flash.
 int[] getSectorMap()
          Get a map of sector numbers to sector addresses
 int getSectorSize(int sectorNum)
          Get the size of a device sector
 int getSize()
          Get the capacity of the device
 void read(int address, int numOfBytes, byte[] buffer)
          Read data from the flash memory.
 boolean sectorErased(int address)
          Check whether a sector is erased.
 boolean verify(int address, int numOfBytes, byte[] buffer)
          Verify data in the flash memory.
 void write(int address, byte[] data, int index)
          Write a 16-bit value into flash.
 void write(int address, int numOfBytes, byte[] buffer)
          Write data into the flash memory.
 

Method Detail

read

void read(int address,
          int numOfBytes,
          byte[] buffer)
Read data from the flash memory.

Parameters:
address - address in memory to start reading
numOfBytes - number of bytes to read
buffer - the hold the data

write

void write(int address,
           byte[] data,
           int index)
Write a 16-bit value into flash. If the address co-incides with the start of a sector, the sector is erased.

Parameters:
address - The address to write at - must be even and in range
data - The byte at data[index] is written to the address, the byte at data[index+1] to address+1
index - The offset into data at which to get the data to write

write

void write(int address,
           int numOfBytes,
           byte[] buffer)
Write data into the flash memory.

Parameters:
address - address in memory to start writing, must be page-aligned
numOfBytes - number of bytes to write, in range 0 to PAGE_SIZE
buffer - the data to write

verify

boolean verify(int address,
               int numOfBytes,
               byte[] buffer)
Verify data in the flash memory.

Parameters:
address - address in memory to start verifying, must be page-aligned
numOfBytes - number of bytes to write, in range 0 to PAGE_SIZE
buffer - the data to verify against
Returns:
true if data matches

eraseSectorAtAddress

void eraseSectorAtAddress(int address)
Erase a sector

Parameters:
address - an address within sector to erase - must be even and in range

sectorErased

boolean sectorErased(int address)
Check whether a sector is erased.

Parameters:
address - an address within sector to check
Returns:
true if sector is erased

eraseChip

void eraseChip()
Erase all data in the chip


getPageSize

int getPageSize()
Get the page size for writing. Each call to write can write no more than one page.

Returns:
The page size in bytes

getSectorMap

int[] getSectorMap()
Get a map of sector numbers to sector addresses

Returns:
The map as an array of addresses where the array index is the sector number.

getInputStream

InputStream getInputStream(int startSectorNum,
                           int numOfSectors)
Create an input stream over a logical device formed of selected sectors of the physical device.

Parameters:
startSectorNum - The number of the sector at the base of the logical device
numOfSectors - The number of sectors that form the logical device
Returns:
An input stream over the logical device

getOutputStream

OutputStream getOutputStream(int startSectorNum,
                             int numOfSectors)
                             throws IOException
Create an output stream over a logical device formed of selected sectors of the physical device. NOTE that the sectors forming the logical device are erased by this operation.

Parameters:
startSectorNum - The number of the sector at the base of the logical device
numOfSectors - The number of sectors that form the logical device
Returns:
An output stream over the logical device
Throws:
IOException - If the sectors in the logical device cannot be erased.

getSize

int getSize()
Get the capacity of the device

Returns:
The size of the memory in bytes

getSectorSize

int getSectorSize(int sectorNum)
Get the size of a device sector

Parameters:
sectorNum - The sector whose size is to be returned
Returns:
The size of the sector in bytes

getFirstAvailableSector

int getFirstAvailableSector()
Get the sector number of the first sector that can be used with the input and output streams.

Returns:
Sector number

getNumberOfSectors

int getNumberOfSectors()
Get the number of sectors in the device.

Returns:
Number of sectors.

getSectorContainingAddress

int getSectorContainingAddress(int addrToFlash)
Find the sector associated with a given address in the flash.

Parameters:
addrToFlash - The address.
Returns:
The sector number.

getNumberOfSectorsInRegion

int getNumberOfSectorsInRegion(int addrToFlash,
                               int dataSize)
Find the number of sectors in a region of the flash memory.

Parameters:
addrToFlash - The start of the region.
dataSize - The size of the region.
Returns:
The number of sectors.

Sun SPOT API
Green Release  


Copyright © 2006 Sun Microsystems, Inc. All Rights Reserved.