rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
backup_ram.h File Reference

Detailed Description

Non-volatile backup-RAM registers support.

Date
Dec 19, 2017

Definition in file backup_ram.h.

Data Structures

struct  BackupSramData
 

Enumerations

enum class  backup_ram_e { StepperPosition , IgnCounter , BACKUP_RAM_NUM }
 

Functions

uint32_t backupRamLoad (backup_ram_e idx)
 
void backupRamSave (backup_ram_e idx, uint32_t value)
 
void backupRamFlush (void)
 
BackupSramDatagetBackupSram ()
 

Enumeration Type Documentation

◆ backup_ram_e

enum class backup_ram_e
strong
Enumerator
StepperPosition 

IAC Stepper motor position, 16-bit (stored in BKP0R 0..15) Used in stepper.cpp

IgnCounter 

Ignition switch counter, 8-bit (stored in BKP0R 16..23) The counter stores the number of times the ignition switch is turned on. Used for prime injection pulse. We need a protection against 'fake' ignition switch on and off (i.e. no engine started), to avoid repeated prime pulses. So we check and update the ignition switch counter in non-volatile backup-RAM. See startPrimeInjectionPulse() in controllers/trigger/main_trigger_callback.cpp

BACKUP_RAM_NUM 

Definition at line 14 of file backup_ram.h.

14 {
15 /**
16 * IAC Stepper motor position, 16-bit (stored in BKP0R 0..15)
17 * Used in stepper.cpp
18 */
20 /**
21 * Ignition switch counter, 8-bit (stored in BKP0R 16..23)
22 * The counter stores the number of times the ignition switch is turned on. Used for prime injection pulse.
23 * We need a protection against 'fake' ignition switch on and off (i.e. no engine started), to avoid repeated prime pulses.
24 * So we check and update the ignition switch counter in non-volatile backup-RAM.
25 * See startPrimeInjectionPulse() in controllers/trigger/main_trigger_callback.cpp
26 */
28
29 /* The number of stored backup variables */
31};

Function Documentation

◆ backupRamFlush()

void backupRamFlush ( void  )

Definition at line 61 of file backup_ram.cpp.

61 {
62
63 // todo: implement an incremental "append-to-the-end" algorithm to minimize sector erasings?
64
65 // Enter the critical zone
66 syssts_t sts = chSysGetStatusAndLockX();
67
68 // rewrite the whole sector
69 intFlashErase((flashaddr_t)BACKUP_FLASH_ADDR, BACKUP_FLASH_SIZE);
70 // mark the data as valid & saved
71 backupRam[(int)backupStateOffset] = BACKUP_SAVED;
72 // save the data to the flash
73 intFlashWrite((flashaddr_t)BACKUP_FLASH_ADDR, (char *)backupRam, backupSize);
74
75 // Leaving the critical zone
76 chSysRestoreStatusX(sts);
77
78 // there should not be any backup-RAM activity after this call
79 // but if there is, at least try to reinitialize...
80 wasLoaded = false;
81}
static const int backupStateOffset
const size_t backupSize
static volatile uint32_t backupRam[(int) LAST_BACKUP_RAM_ENUM+1]
static bool wasLoaded
int intFlashErase(flashaddr_t address, size_t size)
Erase the sectors containing the span of size bytes starting at address.
uintptr_t flashaddr_t
Address in the flash memory.
Definition flash_int.h:86
int intFlashWrite(flashaddr_t address, const char *buffer, size_t size)
Copy data from a buffer to the flash memory.
Here is the call graph for this function:

◆ backupRamLoad()

uint32_t backupRamLoad ( backup_ram_e  idx)

Definition at line 43 of file backup_ram.cpp.

43 {
44 // this is executed only once during the firmware init
45 if (!wasLoaded) {
46 backupInit();
47 }
48
49 return backupRam[(int)idx + backupDataOffset];
50}
static const int backupDataOffset
static void backupInit()

Referenced by PrimeController::getKeyCycleCounter(), and StepperMotorBase::loadStepperPos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ backupRamSave()

void backupRamSave ( backup_ram_e  idx,
uint32_t  value 
)

Definition at line 52 of file backup_ram.cpp.

52 {
53 // this is executed only once during the firmware init
54 if (!wasLoaded) {
55 backupInit();
56 }
57
58 backupRam[(int)idx + backupDataOffset] = value;
59}

Referenced by PrimeController::onSlowCallback(), StepperMotorBase::saveStepperPos(), and PrimeController::setKeyCycleCounter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBackupSram()

BackupSramData * getBackupSram ( )

Definition at line 52 of file backup_ram.cpp.

52 {
53 return &backupSramData;
54}
static BKUP_RAM_NOINIT BackupSramData backupSramData

Referenced by chDbgPanic3(), errorHandlerInit(), firmwareErrorV(), and logHardFault().

Here is the caller graph for this function:

Go to the source code of this file.