CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
flash_driver.h
Go to the documentation of this file.
1#ifndef INCLUDE_GUARD__FLASH_DRIVER_H__
2#define INCLUDE_GUARD__FLASH_DRIVER_H__
3
4/*-----------------------------INCLUDES-----------------------------*/
5#include <stdint.h>
6
8
9/*----------------------------- CONFIG VARIABLES ----------------------------- */
10// Number of CS pins available. 8 FLASH + 2 optional FRAM, if used. FRAM not used.
11#define FLASH_NUMBER_OF_FLASH_DEVICES 8
12
13// Total size of a singular Memory Module in bytes
14#define FLASH_CHIP_SIZE_BYTES 134217728 // 128MiB
15
16// Number of pages contained within a single block of memory module
17#define FLASH_CHIP_PAGES_PER_BLOCK 64
18
19// NAND Flash Memory Datasheet https://www.farnell.com/datasheets/3151163.pdf
20// Page Size: 2048 bytes (+ error correction)
21// Block Size: 64 pages
22// Plane (entire chip) Size: 128 MiB = 134217728 bytes = 1024 blocks
23// Chip Size = 2048 bytes per page * 64 pages per block * 1024 blocks per plane
24// You can write one PAGE at a time, but you have to erase a whole BLOCK at a time.
25
26// Each page is divided into a 2048-byte data storage region, and a 128 bytes spare area (2176 bytes total).
27#define FLASH_CHIP_PAGE_SIZE_BYTES 2048
28
29#define FLASH_CHIP_BLOCK_SIZE_BYTES (FLASH_CHIP_PAGE_SIZE_BYTES * FLASH_CHIP_PAGES_PER_BLOCK)
30
31/*----------------------------- FLASH DATA TYPES -----------------------------*/
32
33/*
34A struct representing the the location of a block, page and byte within that page. More compact representations are available (uint64_t) but this is easier to use.
35- row_address: address to the start of a page in pages (NOT bytes).
36- col_address: address to a specific byte in the page (in bytes, between [0, 2047]). If you are writing a full page, this should be 0.
37*/
38typedef struct {
39 uint32_t row_address;
40 uint32_t col_address;
42
43
44
45/*-------------------------------FLASH FEATURES-------------------------------*/
46// Features that can be accessed using Get Feature command
47typedef enum {
48 FLASH_FEAT_BLOCK_LOCK = 0xA0, // Block Lock
49 FLASH_FEAT_CONFIG = 0xB0, // Configuration Register
50 FLASH_FEAT_STATUS = 0xC0, // Status Register
51 FLASH_FEAT_DIE_SELECT = 0xD0, // Die Select
53
58
59
60// ------------------- Status Register 1 - Byte Masks -------------------
61// Source: Table 5
62static const uint8_t FLASH_OP_IN_PROGRESS_MASK = (1 << 0);
63static const uint8_t FLASH_SR1_WRITE_ENABLE_LATCH_MASK = (1 << 1);
64static const uint8_t FLASH_SR1_PROGRAMMING_ERROR_MASK = (1 << 3);
65static const uint8_t FLASH_SR1_ERASE_ERROR_MASK = (1 << 2);
66
67
68/*-----------------------------DRIVER FUNCTIONS-----------------------------*/
69FLASH_error_enum_t FLASH_init(uint8_t chip_number);
70FLASH_error_enum_t FLASH_read_status_register(uint8_t chip_number, uint8_t *response);
71
73FLASH_error_enum_t FLASH_program_page(uint8_t chip_number, FLASH_Physical_Address_t address, uint8_t *data, uint32_t data_len);
75 uint8_t chip_number, FLASH_Physical_Address_t address, uint8_t *rx_buffer, uint32_t rx_buffer_size
76);
77
78
79FLASH_error_enum_t FLASH_is_reachable(uint8_t chip_number);
80FLASH_error_enum_t FLASH_reset(uint8_t chip_number);
81void FLASH_enable_then_disable_chip_select(uint8_t chip_number);
82
83
84#endif /* INCLUDE_GUARD__FLASH_DRIVER_H__ */
FLASH_error_enum_t FLASH_program_page(uint8_t chip_number, FLASH_Physical_Address_t address, uint8_t *data, uint32_t data_len)
Definition flash_driver.c:39
FLASH_error_enum_t FLASH_read_page(uint8_t chip_number, FLASH_Physical_Address_t address, uint8_t *rx_buffer, uint32_t rx_buffer_size)
Definition flash_driver.c:79
static const uint8_t FLASH_SR1_WRITE_ENABLE_LATCH_MASK
Definition flash_driver.h:63
FLASH_error_enum_t FLASH_init(uint8_t chip_number)
Definition flash_driver.c:10
FLASH_error_enum_t FLASH_read_status_register(uint8_t chip_number, uint8_t *response)
Definition flash_driver.c:148
FLASH_FEATURE_REGISTER_ADDR
Definition flash_driver.h:47
@ FLASH_FEAT_DIE_SELECT
Definition flash_driver.h:51
@ FLASH_FEAT_CONFIG
Definition flash_driver.h:49
@ FLASH_FEAT_BLOCK_LOCK
Definition flash_driver.h:48
@ FLASH_FEAT_STATUS
Definition flash_driver.h:50
FLASH_error_enum_t FLASH_erase_block(uint8_t chip_number, FLASH_Physical_Address_t address)
Definition flash_driver.c:15
static const uint8_t FLASH_OP_IN_PROGRESS_MASK
Definition flash_driver.h:62
FLASH_Feat_State_Enum_t
Definition flash_driver.h:54
@ FLASH_FEAT_STATE_ENABLED
Definition flash_driver.h:55
@ FLASH_FEAT_STATE_DISABLED
Definition flash_driver.h:56
FLASH_error_enum_t FLASH_is_reachable(uint8_t chip_number)
Definition flash_driver.c:115
FLASH_error_enum_t FLASH_reset(uint8_t chip_number)
Definition flash_driver.c:137
static const uint8_t FLASH_SR1_PROGRAMMING_ERROR_MASK
Definition flash_driver.h:64
static const uint8_t FLASH_SR1_ERASE_ERROR_MASK
Definition flash_driver.h:65
void FLASH_enable_then_disable_chip_select(uint8_t chip_number)
Here for testing purposes.
Definition flash_driver.c:161
FLASH_error_enum_t
Definition flash_internal_spi.h:7
Definition flash_driver.h:38
uint32_t row_address
Definition flash_driver.h:39
uint32_t col_address
Definition flash_driver.h:40
static uint8_t rx_buffer[5120]
Definition uart_telelecommand_defs.c:25