mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-11-27 19:22:01 +03:00
Make Clock Persistant.
This commit is contained in:
parent
ee44b6ff49
commit
55f8908769
11
gcc_nrf52.ld
11
gcc_nrf52.ld
@ -3,14 +3,23 @@
|
|||||||
SEARCH_DIR(.)
|
SEARCH_DIR(.)
|
||||||
GROUP(-lgcc -lc -lnosys)
|
GROUP(-lgcc -lc -lnosys)
|
||||||
|
|
||||||
|
NO_INIT_SIZE = 0x100;
|
||||||
|
RAM_MAX = 64K;
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
FLASH (rx) : ORIGIN = 0x00000, LENGTH = 0x78000
|
FLASH (rx) : ORIGIN = 0x00000, LENGTH = 0x78000
|
||||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
|
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = RAM_MAX - NO_INIT_SIZE
|
||||||
|
NOINIT (rwx): ORIGIN = ORIGIN(RAM) + LENGTH(RAM), LENGTH = NO_INIT_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
noinit (NOLOAD):
|
||||||
|
{
|
||||||
|
PROVIDE(__start_noinit_data = .);
|
||||||
|
KEEP(*(.noinit))
|
||||||
|
PROVIDE(__stop_noinit_data = .);
|
||||||
|
} >NOINIT
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
|
|
||||||
using namespace Pinetime::Controllers;
|
using namespace Pinetime::Controllers;
|
||||||
|
|
||||||
|
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
|
||||||
|
this->currentDateTime = t;
|
||||||
|
}
|
||||||
|
|
||||||
void DateTime::SetTime(
|
void DateTime::SetTime(
|
||||||
uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) {
|
uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) {
|
||||||
std::tm tm = {
|
std::tm tm = {
|
||||||
@ -67,11 +71,12 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
|
|||||||
// Notify new day to SystemTask
|
// Notify new day to SystemTask
|
||||||
if (hour == 0 and not isMidnightAlreadyNotified) {
|
if (hour == 0 and not isMidnightAlreadyNotified) {
|
||||||
isMidnightAlreadyNotified = true;
|
isMidnightAlreadyNotified = true;
|
||||||
if(systemTask != nullptr)
|
if (systemTask != nullptr)
|
||||||
systemTask->PushMessage(System::Messages::OnNewDay);
|
systemTask->PushMessage(System::Messages::OnNewDay);
|
||||||
} else if (hour != 0) {
|
} else if (hour != 0) {
|
||||||
isMidnightAlreadyNotified = false;
|
isMidnightAlreadyNotified = false;
|
||||||
}
|
}
|
||||||
|
BackUpTime = currentDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* DateTime::MonthShortToString() {
|
const char* DateTime::MonthShortToString() {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> BackUpTime;
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace System {
|
namespace System {
|
||||||
@ -74,6 +75,7 @@ namespace Pinetime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Register(System::SystemTask* systemTask);
|
void Register(System::SystemTask* systemTask);
|
||||||
|
void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t year = 0;
|
uint16_t year = 0;
|
||||||
|
11
src/main.cpp
11
src/main.cpp
@ -124,7 +124,6 @@ Pinetime::Controllers::FS fs {spiNorFlash};
|
|||||||
Pinetime::Controllers::Settings settingsController {fs};
|
Pinetime::Controllers::Settings settingsController {fs};
|
||||||
Pinetime::Controllers::MotorController motorController {settingsController};
|
Pinetime::Controllers::MotorController motorController {settingsController};
|
||||||
|
|
||||||
|
|
||||||
Pinetime::Applications::DisplayApp displayApp(lcd,
|
Pinetime::Applications::DisplayApp displayApp(lcd,
|
||||||
lvgl,
|
lvgl,
|
||||||
touchPanel,
|
touchPanel,
|
||||||
@ -161,6 +160,9 @@ Pinetime::System::SystemTask systemTask(spi,
|
|||||||
heartRateApp,
|
heartRateApp,
|
||||||
fs);
|
fs);
|
||||||
|
|
||||||
|
uint32_t MAGIC_RAM __attribute__((section(".noinit")));
|
||||||
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> BackUpTime __attribute__((section(".noinit")));
|
||||||
|
|
||||||
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
||||||
if (pin == pinTouchIrq) {
|
if (pin == pinTouchIrq) {
|
||||||
systemTask.OnTouchEvent();
|
systemTask.OnTouchEvent();
|
||||||
@ -321,6 +323,13 @@ int main(void) {
|
|||||||
// retrieve version stored by bootloader
|
// retrieve version stored by bootloader
|
||||||
Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]);
|
Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]);
|
||||||
|
|
||||||
|
// Check Magic Ram and reset lost variables
|
||||||
|
if (MAGIC_RAM == 0xDEADBEEF) {
|
||||||
|
dateTimeController.SetCurrentTime(BackUpTime);
|
||||||
|
} else {
|
||||||
|
MAGIC_RAM = 0xDEADBEEF;
|
||||||
|
}
|
||||||
|
|
||||||
lvgl.Init();
|
lvgl.Init();
|
||||||
|
|
||||||
systemTask.Start();
|
systemTask.Start();
|
||||||
|
Loading…
Reference in New Issue
Block a user