Contiki 3.x
Files | Macros | Functions
SensorTag/LaunchPad External Flash

Files

file  ext-flash.c
 Driver for the LaunchPad Flash and the Sensortag WinBond W25X20CL/W25X40CL.
 
file  ext-flash.h
 Header file for the Sensortag/LaunchPad External Flash Driver.
 

Macros

#define BLS_CODE_PROGRAM   0x02
 Page Program.
 
#define BLS_CODE_READ   0x03
 Read Data.
 
#define BLS_CODE_READ_STATUS   0x05
 Read Status Register.
 
#define BLS_CODE_WRITE_ENABLE   0x06
 Write Enable.
 
#define BLS_CODE_SECTOR_ERASE   0x20
 Sector Erase.
 
#define BLS_CODE_MDID   0x90
 Manufacturer Device ID.
 
#define BLS_CODE_PD   0xB9
 Power down.
 
#define BLS_CODE_RPD   0xAB
 Release Power-Down.
 
#define BLS_CODE_ERASE_4K   0x20
 Sector Erase.
 
#define BLS_CODE_ERASE_ALL   0xC7
 Mass Erase.
 
#define BLS_STATUS_BIT_BUSY   0x01
 Busy bit of the status register.
 

Functions

static void select_on_bus (void)
 Clear external flash CSN line.
 
static void deselect (void)
 Set external flash CSN line.
 
static bool wait_ready (void)
 Wait till previous erase/program operation completes. More...
 
static uint8_t verify_part (void)
 Verify the flash part. More...
 
static void power_down (void)
 Put the device in power save mode. More...
 
static bool power_standby (void)
 Take device out of power save mode and prepare it for normal operation. More...
 
static bool write_enable (void)
 Enable write. More...
 
bool ext_flash_open (void)
 Initialize storage driver. More...
 
void ext_flash_close (void)
 Close the storage driver. More...
 
bool ext_flash_read (size_t offset, size_t length, uint8_t *buf)
 Read storage content. More...
 
bool ext_flash_write (size_t offset, size_t length, const uint8_t *buf)
 Write to storage sectors. More...
 
bool ext_flash_erase (size_t offset, size_t length)
 Erase storage sectors corresponding to the range. More...
 
bool ext_flash_test (void)
 Test the flash (power on self-test) More...
 
void ext_flash_init (void)
 Initialise the external flash. More...
 

Detailed Description

Function Documentation

void ext_flash_close ( void  )

Close the storage driver.

This call will put the device in its lower power mode (power down).

Definition at line 288 of file ext-flash.c.

References board_spi_close(), and power_down().

Referenced by ext_flash_init(), and ext_flash_test().

bool ext_flash_erase ( size_t  offset,
size_t  length 
)

Erase storage sectors corresponding to the range.

Parameters
offsetAddress to start erasing
lengthNumber of bytes to erase
Returns
True when successful.

The erase operation will be sector-wise, therefore a call to this function will generally start the erase procedure at an address lower than offset

Definition at line 389 of file ext-flash.c.

References BLS_CODE_SECTOR_ERASE, board_spi_write(), deselect(), select_on_bus(), wait_ready(), and write_enable().

void ext_flash_init ( void  )

Initialise the external flash.

This function will explicitly put the part in its lowest power mode (power-down).

In order to perform any operation, the caller must first wake the device up by calling ext_flash_open()

Definition at line 449 of file ext-flash.c.

References ext_flash_close(), and ext_flash_open().

Referenced by board_init().

bool ext_flash_open ( void  )

Initialize storage driver.

Returns
True when successful.

Definition at line 271 of file ext-flash.c.

References board_spi_open(), deselect(), power_standby(), and verify_part().

Referenced by ext_flash_init(), and ext_flash_test().

bool ext_flash_read ( size_t  offset,
size_t  length,
uint8_t *  buf 
)

Read storage content.

Parameters
offsetAddress to read from
lengthNumber of bytes to read
bufBuffer where to store the read bytes
Returns
True when successful.

buf must be allocated by the caller

Definition at line 297 of file ext-flash.c.

References BLS_CODE_READ, board_spi_read(), board_spi_write(), deselect(), select_on_bus(), and wait_ready().

bool ext_flash_test ( void  )

Test the flash (power on self-test)

Returns
True when successful.

Definition at line 438 of file ext-flash.c.

References ext_flash_close(), and ext_flash_open().

bool ext_flash_write ( size_t  offset,
size_t  length,
const uint8_t *  buf 
)

Write to storage sectors.

Parameters
offsetAddress to write to
lengthNumber of bytes to write
bufBuffer holding the bytes to be written
Returns
True when successful.

Definition at line 332 of file ext-flash.c.

References BLS_CODE_PROGRAM, board_spi_write(), deselect(), select_on_bus(), wait_ready(), and write_enable().

static void power_down ( void  )
static

Put the device in power save mode.

No access to data; only the status register is accessible.

Definition at line 198 of file ext-flash.c.

References BLS_CODE_PD, board_spi_write(), deselect(), select_on_bus(), verify_part(), and wait_ready().

Referenced by ext_flash_close().

static bool power_standby ( void  )
static

Take device out of power save mode and prepare it for normal operation.

Returns
True if the command was written successfully

Definition at line 232 of file ext-flash.c.

References BLS_CODE_RPD, board_spi_write(), deselect(), select_on_bus(), and wait_ready().

Referenced by ext_flash_open().

static uint8_t verify_part ( void  )
static

Verify the flash part.

Return values
VERIFY_PART_OKThe part was identified successfully
VERIFY_PART_ERRORThere was an error communicating with the part
VERIFY_PART_POWERED_DOWNCommunication was successful, but the part was powered down

Definition at line 162 of file ext-flash.c.

References BLS_CODE_MDID, board_spi_read(), board_spi_write(), deselect(), and select_on_bus().

Referenced by ext_flash_open(), and power_down().

static bool wait_ready ( void  )
static

Wait till previous erase/program operation completes.

Returns
True when successful.

Definition at line 114 of file ext-flash.c.

References BLS_CODE_READ_STATUS, BLS_STATUS_BIT_BUSY, board_spi_flush(), board_spi_read(), board_spi_write(), deselect(), and select_on_bus().

Referenced by ext_flash_erase(), ext_flash_read(), ext_flash_write(), power_down(), and power_standby().

static bool write_enable ( void  )
static

Enable write.

Returns
True when successful.

Definition at line 255 of file ext-flash.c.

References BLS_CODE_WRITE_ENABLE, board_spi_write(), deselect(), and select_on_bus().

Referenced by ext_flash_erase(), and ext_flash_write().