3131#include " configstore.h"
3232
3333#include " hardware.h"
34- #include " softwaretimers.h"
3534
3635#include " debug.h"
3736
3837namespace global {
3938extern int32_t *gp_nUtcOffset;
4039} // namespace global
4140
42- void configstore_commit () {
43- while (ConfigStore::Get ()->Commit ())
44- ;
45- }
46-
47- static TimerHandle_t s_nTimerId = TIMER_ID_NONE;
48- static void timer_stop ();
49-
50- static void timer ([[maybe_unused]] TimerHandle_t nHandle) {
51- if (!ConfigStore::Get ()->Commit ()) {
52- timer_stop ();
53- }
54- }
55-
56- static void timer_start () {
57- assert (s_nTimerId == TIMER_ID_NONE);
58- s_nTimerId = SoftwareTimerAdd (100 , timer);
59- }
60-
61- static void timer_stop () {
62- assert (s_nTimerId != TIMER_ID_NONE);
63- SoftwareTimerDelete (s_nTimerId);
64- }
65-
6641using namespace configstore ;
6742
6843static constexpr uint8_t s_aSignature[] = {' A' , ' v' , ' V' , 0x01 };
@@ -113,7 +88,6 @@ ConfigStore::ConfigStore() {
11388 DEBUG_PUTS (" No signature" );
11489 memset (&s_ConfigStoreData[StoreConfiguration::SIGNATURE_SIZE], 0 , StoreConfiguration::SIZE - StoreConfiguration::SIGNATURE_SIZE);
11590 s_State = State::CHANGED;
116- timer_start ();
11791 }
11892
11993 s_nStoresSize = StoreConfiguration::OFFSET_STORES;
@@ -169,7 +143,6 @@ void ConfigStore::ResetSetList(Store store) {
169143 *pbSetList = 0x00 ;
170144
171145 s_State = State::CHANGED;
172- timer_start ();
173146}
174147
175148void ConfigStore::Update (Store store, uint32_t nOffset, const void *pData, uint32_t nDataLength, uint32_t nSetList, uint32_t nOffsetSetList) {
@@ -204,7 +177,6 @@ void ConfigStore::Update(Store store, uint32_t nOffset, const void *pData, uint3
204177
205178 if (bIsChanged) {
206179 s_State = State::CHANGED;
207- timer_start ();
208180 }
209181
210182 debug_dump (&s_ConfigStoreData[GetStoreOffset (store)] + nOffsetSetList, 8 );
@@ -251,22 +223,26 @@ void ConfigStore::Delay() {
251223}
252224
253225bool ConfigStore::Flash () {
254- DEBUG_PRINTF (" s_State=%u" , static_cast <unsigned int >(s_State));
255226 if (__builtin_expect ((s_State == State::IDLE), 1 )) {
256227 return false ;
257228 }
258229
259230 switch (s_State) {
260231 case State::CHANGED:
232+ s_nWaitMillis = Hardware::Get ()->Millis ();
261233 s_State = State::CHANGED_WAITING;
262234 return true ;
263235 case State::CHANGED_WAITING:
236+ if ((Hardware::Get ()->Millis () - s_nWaitMillis) < 100 ) {
237+ return true ;
238+ }
264239 s_State = State::ERASING;
265240 return true ;
266241 break ;
267242 case State::ERASING: {
268243 storedevice::result result;
269244 if (StoreDevice::Erase (s_nStartAddress, StoreConfiguration::SIZE, result)) {
245+ s_nWaitMillis = Hardware::Get ()->Millis ();
270246 s_State = State::ERASED_WAITING;
271247 }
272248 assert (result == storedevice::result::OK);
@@ -275,6 +251,9 @@ bool ConfigStore::Flash() {
275251 }
276252 break ;
277253 case State::ERASED_WAITING:
254+ if ((Hardware::Get ()->Millis () - s_nWaitMillis) < 100 ) {
255+ return true ;
256+ }
278257 s_State = State::ERASED;
279258 return true ;
280259 break ;
0 commit comments