-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash_io.h
145 lines (126 loc) · 6.25 KB
/
flash_io.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* flash_io.h
*
* Created: 4/16/2018 3:10:50 PM
* Author: kmcarrin
*/
#ifndef FLASH_IO_H_
#define FLASH_IO_H_
#include "NAND_Flash.h"
#include "seal_RTOS.h"
/* Struct containing page data buffer, page size, and a count for the number of buffer bytes to use.
* Instantiate only a single descriptor in the main driving program. */
typedef struct
{
uint8_t buf_0[PAGE_SIZE_EXTRA]; /* Buffer for holding a page worth of data. */
int buffer_index; /* Current read/write index of active buffer. */
int PAGE_SIZE; /* Size of page that user will see (should not include extra space bits). */
}FLASH_DESCRIPTOR;
/* THIS STRUCT IS FOR INTERNAL PROCESSING ONLY - DO NOT INSTANTIATE ANYWHERE ELSE. */
typedef struct
{
uint32_t currentAddress; /* Address currently being written or read to/from. Updated after operation. */
uint32_t nextAddress; /* Address that should be used next. Updated before operation. */
uint8_t currentChipInUse; /* Which chip is currently in use. [0, numChips-1]. Will be initialized to 0. */
uint32_t totalPagesWritten; /* Total number of pages written during deployment. */
} FLASH_ADDRESS_DESCRIPTOR;
/*************************************************************
* FUNCTION: flash_io_init()
* -----------------------------------------------------------
* This function initializes the flash descriptor. This
* function initializes the active buffer, buffer index, and
* flash page size.
*************************************************************/
void flash_io_init(FLASH_DESCRIPTOR *fd, int page_size);
/*************************************************************
* FUNCTION: flash_io_read()
* -----------------------------------------------------------
* This function reads a number of bytes specified by "count".
* If the value of count exceeds a page, only a full page of
* data will be returned through the buffer. The number of
* bytes actually read is returned from this function.
*************************************************************/
uint32_t flash_io_read(FLASH_DESCRIPTOR *fd, uint8_t *buf, size_t count);
/*************************************************************
* FUNCTION: flash_io_write()
* -----------------------------------------------------------
* This function writes a specific number of bytes to the
* flash device's write buffer. The number of bytes to write
* is specified by "count".
*************************************************************/
uint32_t flash_io_write(FLASH_DESCRIPTOR *fd, uint8_t *buf, size_t count);
/*************************************************************
* FUNCTION: flash_io_is_busy()
* -----------------------------------------------------------
* This function returns true if the flash device is currently
* busy. It returns false if the device is currently not busy.
*************************************************************/
bool flash_io_is_busy();
/*************************************************************
* FUNCTION: flash_io_flush()
* -----------------------------------------------------------
* This function flushes the write buffer. All data currently
* in the buffer will be written out to the flash device.
*************************************************************/
void flash_io_flush(FLASH_DESCRIPTOR *fd);
/*************************************************************
* FUNCTION: flash_io_reset_addr()
* -----------------------------------------------------------
* This function resets the address pointer back to the
* beginning of the flash device. The pointer goes back to
* block one of the device, which is the first addressable
* block by the user.
*************************************************************/
void flash_io_reset_addr();
/*************************************************************
* FUNCTION: update_next_address()
* -----------------------------------------------------------
* This function goes to the next address that should be
* written to or read from.
*************************************************************/
uint32_t update_next_address();
/*************************************************************
* FUNCTION: update_current_address()
* -----------------------------------------------------------
* This function goes to the next address that should be
* written to or read from.
*************************************************************/
uint32_t update_current_address();
/*************************************************************
* FUNCTION: get_current_address()
* -----------------------------------------------------------
* This function returns the value currently stored in the
* address descriptor's current address value.
*************************************************************/
uint32_t get_current_address();
/*************************************************************
* FUNCTION: get_next_address()
* -----------------------------------------------------------
* This function returns the value currently stored in the
* address descriptor's current address value.
*************************************************************/
uint32_t get_next_address();
/*************************************************************
* FUNCTION: reset_address_info()
* -----------------------------------------------------------
* This function reinitializes the address pointer back to the
* beginning of the device. It points back to block one of the
* device.
*************************************************************/
void reset_address_info();
/*************************************************************
* FUNCTION: switch_flash_chips()
* -----------------------------------------------------------
* This function switches to the next available flash chip and
* sets the address pointer to the first user-addressable
* space.
*************************************************************/
void switch_flash_chips();
/*************************************************************
* FUNCTION: num_pages_written()
* -----------------------------------------------------------
* This function returns the total number of pages currently
* written to flash.
*************************************************************/
uint32_t num_pages_written();
#endif /* FLASH_IO_H_ */