SEcube
SEcube Open Source Library - Device
se3_flash.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "se3c0.h"
9 
10 #ifndef CUBESIM
11 #include "stm32f4xx.h"
12 #include "stm32f4xx_hal.h"
13 #define SE3_FLASH_S0 (FLASH_SECTOR_10)
14 #define SE3_FLASH_S1 (FLASH_SECTOR_11)
15 #define SE3_FLASH_S0_ADDR ((uint32_t)0x080C0000)
16 #define SE3_FLASH_S1_ADDR ((uint32_t)0x080E0000)
17 #define SE3_FLASH_SECTOR_SIZE (128*1024)
18 #endif
19 
20 /*
21 Structure of flash:
22  0:31 magic
23  32:2047 index
24  2048:131071 data
25 
26  The data section is divided into 2016 64-byte blocks.
27  Each byte of the index stores the type of the corresponding data block.
28  A special value (SE3_FLASH_TYPE_CONT) indicates that the block is the continuation of the
29  previous one.
30  if the block is invalid, its type is 0. If it has not been written yet, the type is 0xFF.
31 */
32 
34 typedef struct se3_flash_it_ {
35  const uint8_t* addr;
36  uint8_t type;
37  uint16_t size;
38  uint16_t blocks;
39  size_t pos;
40 } se3_flash_it;
41 
46 bool se3_flash_init();
47 
53 
61 
71 bool se3_flash_it_new(se3_flash_it* it, uint8_t type, uint16_t size);
72 
82 bool se3_flash_it_write(se3_flash_it* it, uint16_t off, const uint8_t* data, uint16_t size);
83 
92 
100 bool se3_flash_pos_delete(size_t pos);
101 
108 size_t se3_flash_unused();
109 
116 bool se3_flash_canfit(size_t size);
117 
124 void se3_flash_info_setup(uint32_t sector, const uint8_t* base);
125 
127 enum {
132 };
133 
135 enum {
136  SE3_FLASH_MAGIC_SIZE = 32,
137  SE3_FLASH_INDEX_SIZE = 2016,
138  SE3_FLASH_BLOCK_SIZE = 64,
139  SE3_FLASH_NODE_MAX = (4 * 1024),
140  SE3_FLASH_NODE_DATA_MAX = (SE3_FLASH_NODE_MAX - 2)
141 };
142 
143 
144 
bool se3_flash_it_delete(se3_flash_it *it)
Delete flash node.
Definition: se3_flash.c:372
bool se3_flash_it_write(se3_flash_it *it, uint16_t off, const uint8_t *data, uint16_t size)
Write to flash node.
Definition: se3_flash.c:256
Not written yet.
Definition: se3_flash.h:131
L0 structures and functions.
Flash node iterator structure.
Definition: se3_flash.h:34
bool se3_flash_pos_delete(size_t pos)
Delete flash node by index.
Definition: se3_flash.c:357
bool se3_flash_it_new(se3_flash_it *it, uint8_t type, uint16_t size)
Allocate new node.
Definition: se3_flash.c:306
struct se3_flash_it_ se3_flash_it
Flash node iterator structure.
size_t se3_flash_unused()
Get unused space.
Definition: se3_flash.c:301
void se3_flash_it_init(se3_flash_it *it)
Initialize flash iterator.
Definition: se3_flash.c:263
Continuation of previous node.
Definition: se3_flash.h:130
bool se3_flash_init()
Initialize flash.
Definition: se3_flash.c:195
Invalid node.
Definition: se3_flash.h:128
Device's serial number.
Definition: se3_flash.h:129
bool se3_flash_it_next(se3_flash_it *it)
Increment flash iterator.
Definition: se3_flash.c:268
void se3_flash_info_setup(uint32_t sector, const uint8_t *base)
Initialize flash structures.
Definition: se3_flash.c:179
bool se3_flash_canfit(size_t size)
Check if enough space for new node.
Definition: se3_flash.c:189