Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jeff Gough
firmware
Commits
dbc3b8fb
Commit
dbc3b8fb
authored
5 years ago
by
Jeff Gough
Browse files
Options
Downloads
Patches
Plain Diff
Add timer to appDb persistant storage to group write operations together
parent
ea85141f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/ble/app/common/app_db.c
+30
-0
30 additions, 0 deletions
epicardium/ble/app/common/app_db.c
with
30 additions
and
0 deletions
epicardium/ble/app/common/app_db.c
+
30
−
0
View file @
dbc3b8fb
...
...
@@ -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(1000)
/*************************************************************************************************/
/*!
* \brief Initialize the device database.
...
...
@@ -107,13 +118,32 @@ void AppDbInit(void)
}
epic_file_close
(
fd
);
}
store_timer
=
xTimerCreateStatic
(
"appdb_store_timer"
,
STORE_DELAY
,
pdFALSE
,
NULL
,
store_callback
,
&
store_timer_buffer
);
}
static
void
store
(
void
)
{
LOG_DEBUG
(
"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
()
{
int
fd
=
epic_file_open
(
"pairings.bin"
,
"w"
);
if
(
fd
>=
0
)
{
if
(
epic_file_write
(
fd
,
&
appDb
,
sizeof
(
appDb
))
!=
sizeof
(
appDb
))
{
LOG_DEBUG
(
"appDb"
,
"STORE_DELAY passed, writing to persistent storage"
);
}
epic_file_close
(
fd
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment