Skip to content

Commit 5855906

Browse files
committed
Merge branch 'geekbozu-PersistantStorage' into develop
2 parents 7af7db7 + f556003 commit 5855906

9 files changed

Lines changed: 100 additions & 8 deletions

File tree

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ Testing/Temporary/
3838
**/.DS_Store
3939

4040
# Windows
41-
**/thumbs.db
41+
**/thumbs.db
42+
43+
#VSCODE
44+
.vscode/.cortex-debug.registers.state.json
45+
.vscode/.cortex-debug.peripherals.state.json

.vscode/settings.json

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,55 @@
55
"-DNRF5_SDK_PATH=${env:NRF5_SDK_PATH}",
66
],
77
"cmake.generator": "Unix Makefiles",
8-
"clang-tidy.buildPath": "build/compile_commands.json"
8+
"clang-tidy.buildPath": "build/compile_commands.json",
9+
"files.associations": {
10+
"array": "cpp",
11+
"atomic": "cpp",
12+
"bit": "cpp",
13+
"*.tcc": "cpp",
14+
"bitset": "cpp",
15+
"cctype": "cpp",
16+
"chrono": "cpp",
17+
"clocale": "cpp",
18+
"cmath": "cpp",
19+
"cstdarg": "cpp",
20+
"cstddef": "cpp",
21+
"cstdint": "cpp",
22+
"cstdio": "cpp",
23+
"cstdlib": "cpp",
24+
"ctime": "cpp",
25+
"cwchar": "cpp",
26+
"cwctype": "cpp",
27+
"deque": "cpp",
28+
"unordered_map": "cpp",
29+
"vector": "cpp",
30+
"exception": "cpp",
31+
"algorithm": "cpp",
32+
"functional": "cpp",
33+
"iterator": "cpp",
34+
"memory": "cpp",
35+
"memory_resource": "cpp",
36+
"numeric": "cpp",
37+
"optional": "cpp",
38+
"random": "cpp",
39+
"ratio": "cpp",
40+
"string": "cpp",
41+
"string_view": "cpp",
42+
"system_error": "cpp",
43+
"tuple": "cpp",
44+
"type_traits": "cpp",
45+
"utility": "cpp",
46+
"fstream": "cpp",
47+
"initializer_list": "cpp",
48+
"iosfwd": "cpp",
49+
"istream": "cpp",
50+
"limits": "cpp",
51+
"new": "cpp",
52+
"ostream": "cpp",
53+
"sstream": "cpp",
54+
"stdexcept": "cpp",
55+
"streambuf": "cpp",
56+
"cinttypes": "cpp",
57+
"typeinfo": "cpp"
58+
}
959
}

gcc_nrf52-mcuboot.ld

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ GROUP(-lgcc -lc -lnosys)
66
MEMORY
77
{
88
FLASH (rx) : ORIGIN = 0x08020, LENGTH = 0x78000
9-
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
9+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
1010
}
1111

1212
SECTIONS
1313
{
14-
}
14+
.noinit(NOLOAD):
15+
{
16+
PROVIDE(__start_noinit_data = .);
17+
*(.noinit)
18+
PROVIDE(__stop_noinit_data = .);
19+
} > RAM
20+
} INSERT AFTER .bss
1521

1622
SECTIONS
1723
{

gcc_nrf52.ld

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ GROUP(-lgcc -lc -lnosys)
66
MEMORY
77
{
88
FLASH (rx) : ORIGIN = 0x00000, LENGTH = 0x78000
9-
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
9+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
1010
}
1111

1212
SECTIONS
1313
{
14-
}
14+
.noinit(NOLOAD):
15+
{
16+
PROVIDE(__start_noinit_data = .);
17+
*(.noinit)
18+
PROVIDE(__stop_noinit_data = .);
19+
} > RAM
20+
} INSERT AFTER .bss
1521

1622
SECTIONS
1723
{
@@ -44,6 +50,7 @@ SECTIONS
4450
PROVIDE(__stop_log_filter_data = .);
4551
} > RAM
4652

53+
4754
} INSERT AFTER .data;
4855

4956
SECTIONS

src/components/datetime/DateTimeController.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
using namespace Pinetime::Controllers;
77

8+
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
9+
this->currentDateTime = t;
10+
}
11+
812
void DateTime::SetTime(
913
uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) {
1014
std::tm tm = {
@@ -67,7 +71,7 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
6771
// Notify new day to SystemTask
6872
if (hour == 0 and not isMidnightAlreadyNotified) {
6973
isMidnightAlreadyNotified = true;
70-
if(systemTask != nullptr)
74+
if (systemTask != nullptr)
7175
systemTask->PushMessage(System::Messages::OnNewDay);
7276
} else if (hour != 0) {
7377
isMidnightAlreadyNotified = false;

src/components/datetime/DateTimeController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace Pinetime {
7474
}
7575

7676
void Register(System::SystemTask* systemTask);
77+
void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
7778

7879
private:
7980
uint16_t year = 0;

src/main.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ Pinetime::Controllers::FS fs {spiNorFlash};
115115
Pinetime::Controllers::Settings settingsController {fs};
116116
Pinetime::Controllers::MotorController motorController {settingsController};
117117

118-
119118
Pinetime::Applications::DisplayApp displayApp(lcd,
120119
lvgl,
121120
touchPanel,
@@ -156,6 +155,16 @@ Pinetime::System::SystemTask systemTask(spi,
156155
fs,
157156
touchHandler);
158157

158+
/* Variable Declarations for variables in noinit SRAM
159+
Increment NoInit_MagicValue upon adding variables to this area
160+
*/
161+
extern uint32_t __start_noinit_data;
162+
extern uint32_t __stop_noinit_data;
163+
static constexpr uint32_t NoInit_MagicValue = 0xDEAD0000;
164+
uint32_t NoInit_MagicWord __attribute__((section(".noinit")));
165+
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime __attribute__((section(".noinit")));
166+
167+
159168
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
160169
if (pin == Pinetime::PinMap::Cst816sIrq) {
161170
systemTask.OnTouchEvent();
@@ -316,6 +325,15 @@ int main(void) {
316325
// retrieve version stored by bootloader
317326
Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]);
318327

328+
329+
if (NoInit_MagicWord == NoInit_MagicValue) {
330+
dateTimeController.SetCurrentTime(NoInit_BackUpTime);
331+
} else {
332+
//Clear Memory to known state
333+
memset(&__start_noinit_data,0,(uintptr_t)&__stop_noinit_data-(uintptr_t)&__start_noinit_data);
334+
NoInit_MagicWord = NoInit_MagicValue;
335+
}
336+
319337
lvgl.Init();
320338

321339
systemTask.Start();

src/systemtask/SystemTask.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ void SystemTask::Work() {
376376
monitor.Process();
377377
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
378378
dateTimeController.UpdateTime(systick_counter);
379+
NoInit_BackUpTime = dateTimeController.CurrentDateTime();
379380
if (!nrf_gpio_pin_read(PinMap::Button))
380381
watchdog.Kick();
381382
}

src/systemtask/SystemTask.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "drivers/Watchdog.h"
3434
#include "Messages.h"
3535

36+
extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime;
3637
namespace Pinetime {
3738
namespace Drivers {
3839
class Cst816S;

0 commit comments

Comments
 (0)