SEcube
SEcube Open Source Library - Device
Functions
se3_flash.c File Reference

Flash management. More...

#include "se3_flash.h"

Functions

static bool flash_fill (uint32_t addr, uint8_t val, size_t size)
 
static bool flash_zero (uint32_t addr, size_t size)
 
static bool flash_program (uint32_t addr, const uint8_t *data, size_t size)
 
static bool flash_erase (uint32_t sector)
 
static bool flash_swap ()
 
void se3_flash_info_setup (uint32_t sector, const uint8_t *base)
 Initialize flash structures. More...
 
bool se3_flash_canfit (size_t size)
 Check if enough space for new node. More...
 
bool se3_flash_init ()
 Initialize flash. More...
 
bool se3_flash_it_write (se3_flash_it *it, uint16_t off, const uint8_t *data, uint16_t size)
 Write to flash node. More...
 
void se3_flash_it_init (se3_flash_it *it)
 Initialize flash iterator. More...
 
bool se3_flash_it_next (se3_flash_it *it)
 Increment flash iterator. More...
 
size_t se3_flash_unused ()
 Get unused space. More...
 
bool se3_flash_it_new (se3_flash_it *it, uint8_t type, uint16_t size)
 Allocate new node. More...
 
bool se3_flash_pos_delete (size_t pos)
 Delete flash node by index. More...
 
bool se3_flash_it_delete (se3_flash_it *it)
 Delete flash node. More...
 

Detailed Description

Flash management.

Author
Nicola Ferri

Function Documentation

bool se3_flash_canfit ( size_t  size)

Check if enough space for new node.

Check if there is enough space

Parameters
sizesize of the data to be stored inside the new node
Returns
true if the node will fit into the flash, else false
void se3_flash_info_setup ( uint32_t  sector,
const uint8_t *  base 
)

Initialize flash structures.

Initializes the structures for flash management, selecting a sector and its base address.

Parameters
sectoractive sector number
baseactive sector base address
bool se3_flash_init ( )

Initialize flash.

Selects the active flash sector or initializes one

bool se3_flash_it_delete ( se3_flash_it it)

Delete flash node.

Delete a flash node and its data

Remarks
if a flash operation fails, the hwerror flag (se3c0.hwerror) is set.
Parameters
itflash iterator structure
Returns
true on success, else false
void se3_flash_it_init ( se3_flash_it it)

Initialize flash iterator.

Parameters
itflash iterator structure
bool se3_flash_it_new ( se3_flash_it it,
uint8_t  type,
uint16_t  size 
)

Allocate new node.

Allocates a new node in the flash and points the iterator to the new node.

Remarks
if a flash operation fails, the hwerror flag (se3c0.hwerror) is set.
Parameters
itflash iterator structure
typetype of the new flash node
sizesize of the data in the new flash node
Returns
true if the function succedes, false if there is no more space, or a flash operation fails
bool se3_flash_it_next ( se3_flash_it it)

Increment flash iterator.

Increment iterator and read information of the next node in flash

Parameters
itflash iterator structure
Returns
false if end of iteration, else true
bool se3_flash_it_write ( se3_flash_it it,
uint16_t  off,
const uint8_t *  data,
uint16_t  size 
)

Write to flash node.

Write data to flash node.

Remarks
if a flash operation fails, the hwerror flag (se3c0.hwerror) is set.
Parameters
itflash iterator structure
offoffset of data
datapointer to data to be written
sizesize of data to be written
bool se3_flash_pos_delete ( size_t  pos)

Delete flash node by index.

Delete a flash node given its index

Remarks
if a flash operation fails, the hwerror flag (se3c0.hwerror) is set.
Parameters
posthe index of the node
Returns
true on success, else false
size_t se3_flash_unused ( )

Get unused space.

Get unused space in the flash memory, including the space marked as invalid. If space is available, it does not mean that flash sectors will not be swapped.

Returns
unused space in bytes