mirror of
https://github.com/grblHAL/core.git
synced 2026-03-23 11:32:44 +08:00
Revised core setting structures, changed from 8-bit to 16-bit CRC checksums for improved detection of corruption/version mismatches.
Added option to homing enable setting ($22) for per axis homing feedrates. !! Backup and restore settings over an update is recommended since all settings will be reset to default. Any odometer data will also be lost.
This commit is contained in:
39
nvs_buffer.c
39
nvs_buffer.c
@@ -7,18 +7,18 @@
|
||||
Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC
|
||||
Copyright (c) 2009-2011 Simen Svale Skogsrud
|
||||
|
||||
Grbl is free software: you can redistribute it and/or modify
|
||||
grblHAL is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Grbl is distributed in the hope that it will be useful,
|
||||
grblHAL is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License.
|
||||
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
|
||||
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "protocol.h"
|
||||
#include "settings.h"
|
||||
#include "gcode.h"
|
||||
#include "crc.h"
|
||||
#include "nvs.h"
|
||||
|
||||
static uint8_t *nvsbuffer = NULL;
|
||||
@@ -141,15 +142,19 @@ static nvs_transfer_result_t memcpy_to_ram (uint32_t destination, uint8_t *sourc
|
||||
return physical_nvs.memcpy_to_nvs(destination, source, size, with_checksum);
|
||||
|
||||
uint32_t dest = destination;
|
||||
uint8_t checksum = with_checksum ? calc_checksum(source, size) : 0;
|
||||
uint16_t checksum = with_checksum ? calc_checksum(source, size) : 0;
|
||||
|
||||
dirty = false;
|
||||
|
||||
for(; size > 0; size--)
|
||||
ram_put_byte(dest++, *(source++));
|
||||
|
||||
if(with_checksum)
|
||||
ram_put_byte(dest, checksum);
|
||||
if(with_checksum) {
|
||||
ram_put_byte(dest, checksum & 0xFF);
|
||||
#if NVS_CRC_BYTES > 1
|
||||
ram_put_byte(++dest, checksum >> 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
if(settings_dirty.version || source == hal.nvs.driver_area.mem_address)
|
||||
dirty = true;
|
||||
@@ -203,12 +208,16 @@ static nvs_transfer_result_t memcpy_from_ram (uint8_t *destination, uint32_t sou
|
||||
if(hal.nvs.driver_area.address && source > hal.nvs.driver_area.address + hal.nvs.driver_area.size)
|
||||
return physical_nvs.memcpy_from_nvs(destination, source, size, with_checksum);
|
||||
|
||||
uint8_t checksum = with_checksum ? calc_checksum(&nvsbuffer[source], size) : 0;
|
||||
uint16_t checksum = with_checksum ? calc_checksum(&nvsbuffer[source], size) : 0;
|
||||
|
||||
for(; size > 0; size--)
|
||||
*(destination++) = ram_get_byte(source++);
|
||||
|
||||
#if NVS_CRC_BYTES == 1
|
||||
return with_checksum ? (checksum == ram_get_byte(source) ? NVS_TransferResult_OK : NVS_TransferResult_Failed) : NVS_TransferResult_OK;
|
||||
#else
|
||||
return with_checksum ? (checksum == (ram_get_byte(source) | (ram_get_byte(source + 1) << 8)) ? NVS_TransferResult_OK : NVS_TransferResult_Failed) : NVS_TransferResult_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Try to allocate RAM from heap for buffer/emulation.
|
||||
@@ -403,30 +412,38 @@ void nvs_memmap (void)
|
||||
{
|
||||
char buf[30];
|
||||
|
||||
report_message("NVS Area: addr size", Message_Plain);
|
||||
report_message("NVS Area: addr size end", Message_Plain);
|
||||
|
||||
strcpy(buf, "Global: ");
|
||||
strcat(buf, uitoa(NVS_ADDR_GLOBAL));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(sizeof(settings_t) + NVS_CRC_BYTES));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(NVS_ADDR_GLOBAL + sizeof(settings_t) + NVS_CRC_BYTES));
|
||||
report_message(buf, Message_Plain);
|
||||
|
||||
strcpy(buf, "Parameters: ");
|
||||
strcat(buf, uitoa(NVS_ADDR_PARAMETERS));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(N_CoordinateSystems * (sizeof(coord_data_t) + NVS_CRC_BYTES)));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(NVS_ADDR_PARAMETERS + N_CoordinateSystems * (sizeof(coord_data_t) + NVS_CRC_BYTES)));
|
||||
report_message(buf, Message_Plain);
|
||||
|
||||
strcpy(buf, "Startup block: ");
|
||||
strcat(buf, uitoa(NVS_ADDR_STARTUP_BLOCK));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(N_STARTUP_LINE * (sizeof(stored_line_t) + NVS_CRC_BYTES)));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(NVS_ADDR_STARTUP_BLOCK + N_STARTUP_LINE * (sizeof(stored_line_t) + NVS_CRC_BYTES)));
|
||||
report_message(buf, Message_Plain);
|
||||
|
||||
strcpy(buf, "Build info: ");
|
||||
strcat(buf, uitoa(NVS_ADDR_BUILD_INFO));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(sizeof(stored_line_t) + NVS_CRC_BYTES));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(NVS_ADDR_BUILD_INFO + sizeof(stored_line_t) + NVS_CRC_BYTES));
|
||||
report_message(buf, Message_Plain);
|
||||
|
||||
#if N_TOOLS
|
||||
@@ -434,6 +451,8 @@ void nvs_memmap (void)
|
||||
strcat(buf, uitoa(NVS_ADDR_TOOL_TABLE));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(N_TOOLS * (sizeof(tool_data_t) + NVS_CRC_BYTES)));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(NVS_ADDR_TOOL_TABLE + N_TOOLS * (sizeof(tool_data_t) + NVS_CRC_BYTES)));
|
||||
report_message(buf, Message_Plain);
|
||||
#endif
|
||||
|
||||
@@ -441,6 +460,8 @@ void nvs_memmap (void)
|
||||
strcat(buf, uitoa(hal.nvs.driver_area.address));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(hal.nvs.driver_area.size));
|
||||
strcat(buf, " ");
|
||||
strcat(buf, uitoa(hal.nvs.driver_area.address + hal.nvs.driver_area.size));
|
||||
report_message(buf, Message_Plain);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user