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
11#define FLASH_NUMBER_OF_FLASH_DEVICES 8 // TODO: update to 8, or 10 with FRAM maybe
12
13// Total size of a singular Memory Module in bytes
14#define FLASH_CHIP_SIZE_BYTES 134217728 // 128MiB // TODO: update
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// Each page is divided into a 2048-byte data storage region, and a 128 bytes spare area (2176 bytes total).
21#define FLASH_CHIP_PAGE_SIZE_BYTES 2048
22
23#define FLASH_CHIP_BLOCK_SIZE_BYTES (FLASH_CHIP_PAGE_SIZE_BYTES * FLASH_CHIP_PAGES_PER_BLOCK)
24
25/*----------------------------- FLASH DATA TYPES -----------------------------*/
26
27/*
28A 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.
29- row_address: address to the start of a page in pages (NOT bytes).
30- 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.
31*/
32typedef struct {
33 uint32_t row_address;
34 uint32_t col_address;
36
37
38
39/*-------------------------------FLASH FEATURES-------------------------------*/
40// Features that can be accessed using Get Feature command
41typedef enum {
42 FLASH_FEAT_BLOCK_LOCK = 0xA0, // Block Lock
43 FLASH_FEAT_CONFIG = 0xB0, // Configuration Register
44 FLASH_FEAT_STATUS = 0xC0, // Status Register
45 FLASH_FEAT_DIE_SELECT = 0xD0, // Die Select
47
52
53
54// ------------------- Status Register 1 - Byte Masks -------------------
55// Source: Table 5
56static const uint8_t FLASH_OP_IN_PROGRESS_MASK = (1 << 0);
57static const uint8_t FLASH_SR1_WRITE_ENABLE_LATCH_MASK = (1 << 1);
58static const uint8_t FLASH_SR1_PROGRAMMING_ERROR_MASK = (1 << 3);
59static const uint8_t FLASH_SR1_ERASE_ERROR_MASK = (1 << 2);
60
61
62/*-----------------------------DRIVER FUNCTIONS-----------------------------*/
63FLASH_error_enum_t FLASH_init(uint8_t chip_number);
64FLASH_error_enum_t FLASH_read_status_register(uint8_t chip_number, uint8_t *response);
65
67FLASH_error_enum_t FLASH_program_page(uint8_t chip_number, FLASH_Physical_Address_t address, uint8_t *data, uint32_t data_len);
69 uint8_t chip_number, FLASH_Physical_Address_t address, uint8_t *rx_buffer, uint32_t rx_buffer_size
70);
71
72
73FLASH_error_enum_t FLASH_is_reachable(uint8_t chip_number);
74FLASH_error_enum_t FLASH_reset(uint8_t chip_number);
75void FLASH_enable_then_disable_chip_select(uint8_t chip_number);
76
77
78#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:57
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:41
@ FLASH_FEAT_DIE_SELECT
Definition flash_driver.h:45
@ FLASH_FEAT_CONFIG
Definition flash_driver.h:43
@ FLASH_FEAT_BLOCK_LOCK
Definition flash_driver.h:42
@ FLASH_FEAT_STATUS
Definition flash_driver.h:44
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:56
FLASH_Feat_State_Enum_t
Definition flash_driver.h:48
@ FLASH_FEAT_STATE_ENABLED
Definition flash_driver.h:49
@ FLASH_FEAT_STATE_DISABLED
Definition flash_driver.h:50
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:58
static const uint8_t FLASH_SR1_ERASE_ERROR_MASK
Definition flash_driver.h:59
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:32
uint32_t row_address
Definition flash_driver.h:33
uint32_t col_address
Definition flash_driver.h:34
static uint8_t rx_buffer[5120]
Definition uart_telelecommand_defs.c:22