grblHAL core  20241107
nvs.h
Go to the documentation of this file.
1 /*
2  nvs.h - non-volative storage data structures
3 
4  Part of grblHAL
5 
6  Copyright (c) 2017-2023 Terje Io
7  Copyright (c) 2009-2011 Simen Svale Skogsrud
8 
9  Grbl is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  Grbl is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with Grbl. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef _NVS_H_
24 #define _NVS_H_
25 
26 #ifndef NVS_SIZE
30 #define NVS_SIZE 2048
31 #endif
32 
36 #if N_AXIS > 6
37 #define GRBL_NVS_END 1151
38 #else
39 #define GRBL_NVS_END 1023
40 #endif
41 
43 #define NVS_CRC_BYTES 1
44 
52 #define NVS_ADDR_GLOBAL 1U
53 #define NVS_ADDR_PARAMETERS 512U
54 #define NVS_ADDR_BUILD_INFO (GRBL_NVS_END - 81U)
55 #define NVS_ADDR_STARTUP_BLOCK (NVS_ADDR_BUILD_INFO - 1 - N_STARTUP_LINE * (sizeof(stored_line_t) + NVS_CRC_BYTES))
56 #if N_TOOLS
57 #define NVS_ADDR_TOOL_TABLE (GRBL_NVS_END + 1)
58 #define GRBL_NVS_SIZE (GRBL_NVS_END + 1 + N_TOOLS * (sizeof(tool_data_t) + NVS_CRC_BYTES))
59 #else
60 #define GRBL_NVS_SIZE (GRBL_NVS_END + 1)
61 #endif
63 
64 typedef enum {
65  NVS_None = 0,
71 
73 typedef struct {
74  uint8_t *mem_address;
75  uint16_t address;
76  uint16_t size;
78 
79 typedef enum {
84 
89 typedef uint8_t (*get_byte_ptr)(uint32_t addr);
90 
95 typedef void (*put_byte_ptr)(uint32_t addr, uint8_t new_value);
96 
104 typedef nvs_transfer_result_t (*memcpy_from_nvs_ptr)(uint8_t *dest, uint32_t source, uint32_t size, bool with_checksum);
105 
113 typedef nvs_transfer_result_t (*memcpy_to_nvs_ptr)(uint32_t dest, uint8_t *source, uint32_t size, bool with_checksum);
114 
119 typedef bool (*memcpy_from_flash_ptr)(uint8_t *dest);
120 
125 typedef bool (*memcpy_to_flash_ptr)(uint8_t *source);
126 
128 typedef struct {
130  uint32_t size;
131  uint32_t size_max;
134 
140 
145 } nvs_io_t;
146 
147 #endif
nvs_transfer_result_t(* memcpy_to_nvs_ptr)(uint32_t dest, uint8_t *source, uint32_t size, bool with_checksum)
Pointer to function for writing a block of data to NVS storage.
Definition: nvs.h:113
uint8_t(* get_byte_ptr)(uint32_t addr)
Pointer to function for getting a byte from NVS storage.
Definition: nvs.h:89
bool(* memcpy_from_flash_ptr)(uint8_t *dest)
Pointer to function for reading a block of data from flash based NVS storage.
Definition: nvs.h:119
nvs_type
Definition: nvs.h:64
@ NVS_Emulated
4 - used by the core for buffered read and write
Definition: nvs.h:69
@ NVS_EEPROM
1
Definition: nvs.h:66
@ NVS_FRAM
2
Definition: nvs.h:67
@ NVS_None
0
Definition: nvs.h:65
@ NVS_Flash
3
Definition: nvs.h:68
nvs_transfer_result_t
Definition: nvs.h:79
@ NVS_TransferResult_Busy
1
Definition: nvs.h:81
@ NVS_TransferResult_OK
2
Definition: nvs.h:82
@ NVS_TransferResult_Failed
0
Definition: nvs.h:80
nvs_transfer_result_t(* memcpy_from_nvs_ptr)(uint8_t *dest, uint32_t source, uint32_t size, bool with_checksum)
Pointer to function for reading a block of data from NVS storage.
Definition: nvs.h:104
bool(* memcpy_to_flash_ptr)(uint8_t *source)
Pointer to function for reading a block of data from flash based NVS storage.
Definition: nvs.h:125
void(* put_byte_ptr)(uint32_t addr, uint8_t new_value)
Pointer to function for putting a byte into NVS storage.
Definition: nvs.h:95
Structure for keeping track of NVS area used by driver and/or plugin code.
Definition: nvs.h:73
uint16_t address
Index based address into the storage area where the driver area starts.
Definition: nvs.h:75
uint16_t size
Actual size of driver area in bytes.
Definition: nvs.h:76
uint8_t * mem_address
Pointer to location in RAM where driver area is located.
Definition: nvs.h:74
Handler functions and variables for NVS storage of settings and data.
Definition: nvs.h:128
uint32_t size_max
Physical size of non-volatile storage area in bytes.
Definition: nvs.h:131
memcpy_from_flash_ptr memcpy_from_flash
Handler for reading a block of data from flash.
Definition: nvs.h:142
memcpy_from_nvs_ptr memcpy_from_nvs
Handler for writing a block of data to EEPROM or FRAM.
Definition: nvs.h:138
nvs_type type
Type of NVS storage.
Definition: nvs.h:129
nvs_driver_area_t driver_area
Definition: nvs.h:132
put_byte_ptr put_byte
Handler for writing a byte to EEPROM or FRAM.
Definition: nvs.h:136
get_byte_ptr get_byte
Handler for reading a byte from EEPROM or FRAM.
Definition: nvs.h:135
uint32_t size
Actual size of non-volatile storage area in bytes.
Definition: nvs.h:130
memcpy_to_nvs_ptr memcpy_to_nvs
Handler for reading a block of data from EEPROM or FRAM.
Definition: nvs.h:137
memcpy_to_flash_ptr memcpy_to_flash
Handler for writing a block of data to flash.
Definition: nvs.h:143