Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Marlin/src/HAL/persistent_store_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program 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.
*
* This program 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "../inc/MarlinConfigPre.h"

#if ENABLED(EEPROM_SETTINGS)

#include "persistent_store_api.h"
PersistentStore persistentStore;

#endif
26 changes: 22 additions & 4 deletions Marlin/src/HAL/persistent_store_api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
#ifndef _PERSISTENT_STORE_H_
#define _PERSISTENT_STORE_H_
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program 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.
*
* This program 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once

#include <stddef.h>
#include <stdint.h>
Expand All @@ -16,5 +36,3 @@ class PersistentStore {
};

extern PersistentStore persistentStore;

#endif // _PERSISTENT_STORE_H_
10 changes: 7 additions & 3 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ubl.h"

#include "../../../Marlin.h"
#include "../../../HAL/persistent_store_api.h"
#include "../../../libs/hex_print_routines.h"
#include "../../../module/configuration_store.h"
#include "../../../lcd/ultralcd.h"
Expand Down Expand Up @@ -1167,24 +1168,27 @@
* right now, it is good to have the extra information. Soon... we prune this.
*/
void unified_bed_leveling::g29_eeprom_dump() {
unsigned char cccc;
unsigned int kkkk; // Needs to be of unspecfied size to compile clean on all platforms
uint8_t cccc;
int kkkk;
uint16_t crc = 0;

SERIAL_ECHO_START();
SERIAL_ECHOLNPGM("EEPROM Dump:");
persistentStore.access_start();
for (uint16_t i = 0; i < persistentStore.capacity(); i += 16) {
if (!(i & 0x3)) idle();
print_hex_word(i);
SERIAL_ECHOPGM(": ");
for (uint16_t j = 0; j < 16; j++) {
kkkk = i + j;
eeprom_read_block(&cccc, (const void *)kkkk, sizeof(unsigned char));
persistentStore.read_data(kkkk, &cccc, sizeof(uint8_t), &crc);
print_hex_byte(cccc);
SERIAL_ECHO(' ');
}
SERIAL_EOL();
}
SERIAL_EOL();
persistentStore.access_finish();
}

/**
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/module/configuration_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ void MarlinSettings::postprocess() {

#if ENABLED(EEPROM_SETTINGS)
#include "../HAL/persistent_store_api.h"
PersistentStore persistentStore;

#define DUMMY_PID_VALUE 3000.0f
#define EEPROM_START() int eeprom_index = EEPROM_OFFSET; persistentStore.access_start()
Expand Down
32 changes: 24 additions & 8 deletions Marlin/src/module/printcounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Stopwatch print_job_timer; // Global Print Job Timer instance

#include "printcounter.h"
#include "../Marlin.h"
#include "../HAL/persistent_store_api.h"

PrintCounter print_job_timer; // Global Print Job Timer instance

Expand Down Expand Up @@ -73,19 +74,31 @@ void PrintCounter::initStats() {
data = { 0, 0, 0, 0, 0.0 };

saveStats();
eeprom_write_byte((uint8_t*)address, 0x16);

uint16_t crc = 0;
int a = address;
persistentStore.access_start();
persistentStore.write_data(a, (uint8_t*)0x16, sizeof(uint8_t), &crc);
persistentStore.access_finish();
}

void PrintCounter::loadStats() {
#if ENABLED(DEBUG_PRINTCOUNTER)
debug(PSTR("loadStats"));
#endif

// Checks if the EEPROM block is initialized
if (eeprom_read_byte((uint8_t*)address) != 0x16) initStats();
else eeprom_read_block(&data,
(void*)(address + sizeof(uint8_t)), sizeof(printStatistics));

// Check if the EEPROM block is initialized
uint16_t crc = 0;
int a = address;
uint8_t value;
persistentStore.access_start();
persistentStore.read_data(a, &value, sizeof(uint8_t), &crc);
if (value != 0x16) initStats();
else {
a = address + sizeof(uint8_t);
persistentStore.read_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
}
persistentStore.access_finish();
loaded = true;
}

Expand All @@ -98,8 +111,11 @@ void PrintCounter::saveStats() {
if (!isLoaded()) return;

// Saves the struct to EEPROM
eeprom_update_block(&data,
(void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
uint16_t crc = 0;
int a = (address + sizeof(uint8_t));
persistentStore.access_start();
persistentStore.write_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
persistentStore.access_finish();
}

void PrintCounter::showStats() {
Expand Down