Sun SPOT API
Green Release  


com.sun.spot.peripheral.external
Class M25P05

java.lang.Object
  extended by com.sun.spot.peripheral.external.M25P05
All Implemented Interfaces:
IFlashMemoryDevice

public class M25P05
extends Object
implements IFlashMemoryDevice

Driver for the M25P05 flash memory chip as fitted to Sun SPOT external boards


Constructor Summary
M25P05(ISPI spi)
           
 
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 startAddress, int length)
          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 addr)
          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
 boolean isWriteProtected()
          Check whether the device is write protected
 void read(int address, int numOfBytes, byte[] buffer)
          Read data from the M25P05 flash memory.
 boolean sectorErased(int address)
          Check whether a sector is erased.
 void setWriteProtection(boolean b)
          Set or clear the write protection
 boolean verify(int address, int numOfBytes, byte[] buffer)
          Verify data in the M25P05 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 M25P05 flash memory.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

M25P05

public M25P05(ISPI spi)
Method Detail

read

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

Specified by:
read in interface IFlashMemoryDevice
Parameters:
address - address in memory to start reading, in range 0 to 0xFFFF
numOfBytes - number of bytes to read, in range 0 to (0x10000-address)
buffer - the hold the data

write

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

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

write

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

Specified by:
write in interface IFlashMemoryDevice
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

verify

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

Specified by:
verify in interface IFlashMemoryDevice
Parameters:
address - address in memory to start verifying, in range 0 to 0xFF00 but 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

public void eraseSectorAtAddress(int address)
Erase a sector

Specified by:
eraseSectorAtAddress in interface IFlashMemoryDevice
Parameters:
address - an address within sector to erase

sectorErased

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

Specified by:
sectorErased in interface IFlashMemoryDevice
Parameters:
address - an address within sector to check
Returns:
true if sector is erased

eraseChip

public void eraseChip()
Erase all data in the chip

Specified by:
eraseChip in interface IFlashMemoryDevice

getPageSize

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

Specified by:
getPageSize in interface IFlashMemoryDevice
Returns:
The page size in bytes

getSectorMap

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

Specified by:
getSectorMap in interface IFlashMemoryDevice
Returns:
The map as an array of addresses where the array index is the sector number.

setWriteProtection

public void setWriteProtection(boolean b)
Set or clear the write protection

Parameters:
b - If b is true the device becomes write protected; if b is false the device becomes writable.

isWriteProtected

public boolean isWriteProtected()
Check whether the device is write protected

Returns:
true if it is write protected

getInputStream

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

Specified by:
getInputStream in interface IFlashMemoryDevice
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

public 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.

Specified by:
getOutputStream in interface IFlashMemoryDevice
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

public int getSize()
Get the capacity of the device

Specified by:
getSize in interface IFlashMemoryDevice
Returns:
The size of the memory in bytes

getSectorSize

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

Specified by:
getSectorSize in interface IFlashMemoryDevice
Parameters:
sectorNum - The sector whose size is to be returned
Returns:
The size of a sector in bytes

getFirstAvailableSector

public int getFirstAvailableSector()
Description copied from interface: IFlashMemoryDevice
Get the sector number of the first sector that can be used with the input and output streams.

Specified by:
getFirstAvailableSector in interface IFlashMemoryDevice
Returns:
Sector number

getNumberOfSectors

public int getNumberOfSectors()
Description copied from interface: IFlashMemoryDevice
Get the number of sectors in the device.

Specified by:
getNumberOfSectors in interface IFlashMemoryDevice
Returns:
Number of sectors.

getSectorContainingAddress

public int getSectorContainingAddress(int addr)
Description copied from interface: IFlashMemoryDevice
Find the sector associated with a given address in the flash.

Specified by:
getSectorContainingAddress in interface IFlashMemoryDevice
Parameters:
addr - The address.
Returns:
The sector number.

getNumberOfSectorsInRegion

public int getNumberOfSectorsInRegion(int startAddress,
                                      int length)
Description copied from interface: IFlashMemoryDevice
Find the number of sectors in a region of the flash memory.

Specified by:
getNumberOfSectorsInRegion in interface IFlashMemoryDevice
Parameters:
startAddress - The start of the region.
length - The size of the region.
Returns:
The number of sectors.

Sun SPOT API
Green Release  


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