jcontrol.io
Class Flash

java.lang.Object
  extended by jcontrol.io.Flash

public class Flash
extends Object

Raw access to JControls flash memory. The methods are designed to access sectors of memory, not single bytes. Whenever single bytes are to be changed, the sector must be read, changed and rewritten.

The organisation of the flash memory used in the JControl device can be found out using the flash.format property, it is organized as <number of sectors>x<bytes per sector>x<number of banks> e.g. "512x128x2".

Author:
Andreas Wesseler, Marcus Timmermann
Available on JControl Devices:
all

Constructor Summary
Flash()
          Constructs a Flash-Object with access to the default bank (of the current application), is equivalent to Flash(-1).
Flash(int bank)
          Constructs a Flash-Object to a specific bank.
 
Method Summary
 int getBank()
          Returns the number of the bank used by this Flash.
 int getUsableSectors()
          Get the number of usable sectors.
 int read(byte[] data, int startindex, int length, int sector)
          Reads a byte array from the Flash.
 int write(byte[] data, int startindex, int length, int sector)
          Writes a byte array to the Flash.
 
Methods inherited from class java.lang.Object
clone, equals, notifyAll, wait
 

Constructor Detail

Flash

public Flash()
      throws IOException
Constructs a Flash-Object with access to the default bank (of the current application), is equivalent to Flash(-1).

Throws:
IOException

Flash

public Flash(int bank)
      throws IOException
Constructs a Flash-Object to a specific bank. Use the flash.format property to query the number of available banks. Range is 0 to n-1, use -1 to use the bank of the current application.

Parameters:
bank - to use, 0 ... n-1 or -1.
Throws:
IOException
See Also:
Management
Method Detail

getBank

public int getBank()
Returns the number of the bank used by this Flash.

Returns:
used bank

getUsableSectors

public int getUsableSectors()
Get the number of usable sectors. Depends on application space used on the Flash bank.

Returns:
the number of sectors

read

public int read(byte[] data,
                int startindex,
                int length,
                int sector)
         throws IOException
Reads a byte array from the Flash. Only data from the specified sector will be read even if the bytearray could hold the requested number of bytes. The byte array may be partially filled.

Parameters:
data - the byte array to fill with memory data
startindex - the index to start filling the array
length - number of bytes to read into the array; the array is filled from startindex to startindex+length-1, but not more bytes a sector contains
sector - the index of the flash memory sector to read
Returns:
the number of received bytes
Throws:
IOException

write

public int write(byte[] data,
                 int startindex,
                 int length,
                 int sector)
          throws IOException
Writes a byte array to the Flash. Only the specified sector will be written, even if the bytearray contains the number of requested bytes. Byte array may be partially written. The data is always written to the start of the sector and filled with 0xFF.

Parameters:
data - the byte array with data to write to memory
startindex - the index to start reading the array
length - number of bytes to read from the array; the array is read from startindex to startindex+length-1, but not more bytes a sector contains
sector - the index of the flash memory sector to write
Returns:
the number of bytes actually written
Throws:
IOException