Skip to content
Snippets Groups Projects
Commit 05b94cac authored by schneider's avatar schneider
Browse files

Merge branch 'appDb-store-timing' into 'master'

Timer to group calls to appDb store() method

See merge request !207
parents 330f8713 7dd77fe8
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,11 @@
#include "app_cfg.h"
#include "epicardium.h"
#include "modules/log.h"
#include "FreeRTOS.h"
#include "timers.h"
#include "mxc_sys.h"
#include "wdt.h"
#include <string.h>
#include <stdio.h>
......@@ -90,6 +95,12 @@ static appDb_t appDb;
/*! When all records are allocated use this index to determine which to overwrite */
static appDbRec_t *pAppDbNewRec = appDb.rec;
/* Timer to delay writing to persistent storage until a burst of store() calls has finished */
static TimerHandle_t store_timer;
static StaticTimer_t store_timer_buffer;
static void store_callback();
#define STORE_DELAY pdMS_TO_TICKS(5000)
/*************************************************************************************************/
/*!
* \brief Initialize the device database.
......@@ -107,10 +118,32 @@ void AppDbInit(void)
}
epic_file_close(fd);
}
store_timer = xTimerCreateStatic(
"appdb_store_timer",
STORE_DELAY,
pdFALSE,
NULL,
store_callback,
&store_timer_buffer
);
}
/* TODO this should actually put tasks into a queue. On the other end of the queue */
/* a worker task can read tasks off the queue and execute them */
static void store(void)
{
LOG_INFO("appDb", "store() called, resetting timer");
if (xTimerReset(store_timer, 10) != pdPASS) { /* (Re)start the timer */
/* Store timer could not be reset, write to persistent storage anyway */
store_callback();
}
}
static void store_callback()
{
LOG_INFO("appDb", "STORE_DELAY passed, writing to persistent storage");
int fd = epic_file_open("pairings.bin", "w");
if(fd >= 0) {
if(epic_file_write(fd, &appDb, sizeof(appDb)) != sizeof(appDb)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment