SEcube
SEcube Open Source Library - Device
Data Structures | Macros | Typedefs | Enumerations | Functions
se3_flash.h File Reference

Flash management. More...

#include "se3c0.h"
#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"

Go to the source code of this file.

Data Structures

struct  se3_flash_it_
 Flash node iterator structure. More...
 

Macros

#define SE3_FLASH_S0   (FLASH_SECTOR_10)
 
#define SE3_FLASH_S1   (FLASH_SECTOR_11)
 
#define SE3_FLASH_S0_ADDR   ((uint32_t)0x080C0000)
 
#define SE3_FLASH_S1_ADDR   ((uint32_t)0x080E0000)
 
#define SE3_FLASH_SECTOR_SIZE   (128*1024)
 

Typedefs

typedef struct se3_flash_it_ se3_flash_it
 Flash node iterator structure.
 

Enumerations

enum  { SE3_FLASH_TYPE_INVALID = 0, SE3_FLASH_TYPE_SERIAL = 1, SE3_FLASH_TYPE_CONT = 0xFE, SE3_FLASH_TYPE_EMPTY = 0xFF }
 
enum  {
  SE3_FLASH_MAGIC_SIZE = 32, SE3_FLASH_INDEX_SIZE = 2016, SE3_FLASH_BLOCK_SIZE = 64, SE3_FLASH_NODE_MAX = (4 * 1024),
  SE3_FLASH_NODE_DATA_MAX = (SE3_FLASH_NODE_MAX - 2)
}
 

Functions

bool se3_flash_init ()
 Initialize flash. 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...
 
bool se3_flash_it_new (se3_flash_it *it, uint8_t type, uint16_t size)
 Allocate new node. 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...
 
bool se3_flash_it_delete (se3_flash_it *it)
 Delete flash node. More...
 
bool se3_flash_pos_delete (size_t pos)
 Delete flash node by index. More...
 
size_t se3_flash_unused ()
 Get unused space. More...
 
bool se3_flash_canfit (size_t size)
 Check if enough space for new node. More...
 
void se3_flash_info_setup (uint32_t sector, const uint8_t *base)
 Initialize flash structures. More...
 

Detailed Description

Flash management.

Author
Nicola Ferri

Enumeration Type Documentation

anonymous enum

Flash nodes' default and reserved types

Enumerator
SE3_FLASH_TYPE_INVALID 

Invalid node.

SE3_FLASH_TYPE_SERIAL 

Device's serial number.

SE3_FLASH_TYPE_CONT 

Continuation of previous node.

SE3_FLASH_TYPE_EMPTY 

Not written yet.

anonymous enum

Flash fields sizes

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