grblHAL core  20250104
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  grblHAL 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  grblHAL 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 grblHAL. 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 
34 #ifndef NVS_CRC_BYTES
35 #define NVS_CRC_BYTES 2
36 #endif
37 
38 #define NVS_SIZE_PARAMETERS ((sizeof(coord_data_t) + NVS_CRC_BYTES) * N_CoordinateSystems)
39 #define NVS_SIZE_BUILD_INFO (sizeof(stored_line_t) + NVS_CRC_BYTES)
40 #define NVS_SIZE_STARTUP_BLOCK (N_STARTUP_LINE * (sizeof(stored_line_t) + NVS_CRC_BYTES))
41 
45 #if N_AXIS > 5
46 #define GRBL_NVS_END (NVS_ADDR_GLOBAL + ((sizeof(settings_t) + NVS_CRC_BYTES + 4) & 0xFFFC) + NVS_SIZE_PARAMETERS + NVS_SIZE_BUILD_INFO + NVS_SIZE_STARTUP_BLOCK + 1)
47 #else
48 #define GRBL_NVS_END 1023
49 #endif
50 
51 #if NVS_CRC_BYTES > 1
52 #define calc_checksum(data, length) modbus_crc16x(data, length)
53 #else
54 #define calc_checksum(data, length) grbl_crc8(data, length)
55 #endif
56 
64 #define NVS_ADDR_GLOBAL 1U
65 #if N_AXIS > 5
66 #define NVS_ADDR_PARAMETERS ((sizeof(settings_t) + NVS_CRC_BYTES + 4) & 0xFFFC) // align to word boundary
67 #else
68 #define NVS_ADDR_PARAMETERS 512U
69 #endif
70 #define NVS_ADDR_BUILD_INFO (GRBL_NVS_END - NVS_SIZE_BUILD_INFO)
71 #define NVS_ADDR_STARTUP_BLOCK (NVS_ADDR_BUILD_INFO - NVS_SIZE_STARTUP_BLOCK - 1)
72 #if N_TOOLS
73 #define NVS_ADDR_TOOL_TABLE (GRBL_NVS_END + 1)
74 #define GRBL_NVS_SIZE (GRBL_NVS_END + 1 + N_TOOLS * (sizeof(tool_data_t) + NVS_CRC_BYTES))
75 #else
76 #define GRBL_NVS_SIZE (GRBL_NVS_END + 1)
77 #endif
79 
80 typedef enum {
81  NVS_None = 0,
87 
89 typedef struct {
90  uint8_t *mem_address;
91  uint16_t address;
92  uint16_t size;
94 
95 typedef enum {
100 
105 typedef uint8_t (*get_byte_ptr)(uint32_t addr);
106 
111 typedef void (*put_byte_ptr)(uint32_t addr, uint8_t new_value);
112 
120 typedef nvs_transfer_result_t (*memcpy_from_nvs_ptr)(uint8_t *dest, uint32_t source, uint32_t size, bool with_checksum);
121 
129 typedef nvs_transfer_result_t (*memcpy_to_nvs_ptr)(uint32_t dest, uint8_t *source, uint32_t size, bool with_checksum);
130 
135 typedef bool (*memcpy_from_flash_ptr)(uint8_t *dest);
136 
141 typedef bool (*memcpy_to_flash_ptr)(uint8_t *source);
142 
144 typedef struct {
146  uint32_t size;
147  uint32_t size_max;
150 
156 
161 } nvs_io_t;
162 
163 #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:129
uint8_t(* get_byte_ptr)(uint32_t addr)
Pointer to function for getting a byte from NVS storage.
Definition: nvs.h:105
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:135
nvs_type
Definition: nvs.h:80
@ NVS_Emulated
4 - used by the core for buffered read and write
Definition: nvs.h:85
@ NVS_EEPROM
1
Definition: nvs.h:82
@ NVS_FRAM
2
Definition: nvs.h:83
@ NVS_None
0
Definition: nvs.h:81
@ NVS_Flash
3
Definition: nvs.h:84
nvs_transfer_result_t
Definition: nvs.h:95
@ NVS_TransferResult_Busy
1
Definition: nvs.h:97
@ NVS_TransferResult_OK
2
Definition: nvs.h:98
@ NVS_TransferResult_Failed
0
Definition: nvs.h:96
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:120
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:141
void(* put_byte_ptr)(uint32_t addr, uint8_t new_value)
Pointer to function for putting a byte into NVS storage.
Definition: nvs.h:111
Structure for keeping track of NVS area used by driver and/or plugin code.
Definition: nvs.h:89
uint16_t address
Index based address into the storage area where the driver area starts.
Definition: nvs.h:91
uint16_t size
Actual size of driver area in bytes.
Definition: nvs.h:92
uint8_t * mem_address
Pointer to location in RAM where driver area is located.
Definition: nvs.h:90
Handler functions and variables for NVS storage of settings and data.
Definition: nvs.h:144
uint32_t size_max
Physical size of non-volatile storage area in bytes.
Definition: nvs.h:147
memcpy_from_flash_ptr memcpy_from_flash
Handler for reading a block of data from flash.
Definition: nvs.h:158
memcpy_from_nvs_ptr memcpy_from_nvs
Handler for writing a block of data to EEPROM or FRAM.
Definition: nvs.h:154
nvs_type type
Type of NVS storage.
Definition: nvs.h:145
nvs_driver_area_t driver_area
Definition: nvs.h:148
put_byte_ptr put_byte
Handler for writing a byte to EEPROM or FRAM.
Definition: nvs.h:152
get_byte_ptr get_byte
Handler for reading a byte from EEPROM or FRAM.
Definition: nvs.h:151
uint32_t size
Actual size of non-volatile storage area in bytes.
Definition: nvs.h:146
memcpy_to_nvs_ptr memcpy_to_nvs
Handler for reading a block of data from EEPROM or FRAM.
Definition: nvs.h:153
memcpy_to_flash_ptr memcpy_to_flash
Handler for writing a block of data to flash.
Definition: nvs.h:159