1
0
Fork 0

boards: Add pseudo-NVRAM support

Currently the pseudo-NVRAM is used only to measure the time spent in the
bootloader (which keeps the watch time stable when we reset the device).

At this stage the legacy mechanisms to pass messages via the SRAM have
not been modified.
pull/1/head
Daniel Thompson 2020-05-09 14:17:42 +01:00
parent 7786926950
commit d8d7d76b17
2 changed files with 56 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "nrf_wdt.h"
#include "app_scheduler.h"
#include "app_timer.h"
#include "pnvram.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
@ -151,6 +152,7 @@ static uint32_t _long_press_count = 0;
void SysTick_Handler(void)
{
_systick_count++;
pnvram_add_ms(pnvram, 1);
#if LEDS_NUMBER > 0
led_tick();
#endif

54
src/pnvram.h 100644
View File

@ -0,0 +1,54 @@
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* Copyright (C) 2020 Daniel Thompson
*/
#ifndef NPVRAM_H_
#define NPVRAM_H_
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
/*! \brief Pseudo Non-Voltatile RAM
*
* This is a data structure that can be placed in the first available
* RAM location. It survives reset but not power down. It can be used
* to share information between the bootloader and the main
* application.
*/
struct pnvram {
uint32_t header; //!< Validation word - 0x1abe11ed
uint32_t offset; //!< Number of seconds since the epoch
uint32_t uptime; //!< Device uptime in milliseconds
uint32_t reserved[4];
uint32_t footer; //!< Validation word - 0x10adab1e
};
#define PNVRAM_HEADER 0x1abe11ed
#define PNVRAM_FOOTER 0x10adab1e
#ifdef NRF52832_XXAA
static volatile struct pnvram * const pnvram = (void *) 0x200039c0;
#endif
static inline void pnvram_init(struct pnvram *p)
{
memset(p, 1, sizeof(*p));
p->header = PNVRAM_HEADER;
p->footer = PNVRAM_FOOTER;
}
static inline bool pnvram_is_valid(volatile struct pnvram * const p)
{
return p->header == PNVRAM_HEADER && p->footer == PNVRAM_FOOTER;
}
static inline void pnvram_add_ms(volatile struct pnvram * const p, uint32_t ms)
{
if (pnvram_is_valid(p))
p->uptime += ms;
}
#endif /* NPVRAM_H_ */