rusEFI
The most advanced open source ECU
backup_ram.h
Go to the documentation of this file.
1 /**
2  * @file backup_ram.h
3  * @brief Non-volatile backup-RAM registers support
4  *
5  * @date Dec 19, 2017
6  */
7 
8 #pragma once
9 
10 #include "efi_gpio.h"
11 
12 #include "error_handling.h"
13 
14 enum class backup_ram_e {
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  */
27  IgnCounter,
28 
29  /* The number of stored backup variables */
31 };
32 
33 #define LAST_BACKUP_RAM_ENUM backup_ram_e::BACKUP_RAM_NUM
34 
35 
36 // load data from backup-power RTC registers (non-volatile memory)
37 uint32_t backupRamLoad(backup_ram_e idx);
38 // use backup-power RTC registers (non-volatile memory) to store the data
39 void backupRamSave(backup_ram_e idx, uint32_t value);
40 // make sure that all changes are saved before we shutdown the MCU
41 void backupRamFlush(void);
42 
43 // These use very specific values to avoid interpreting random garbage memory as a real value
44 enum class ErrorCookie : uint32_t {
45  None = 0,
46  FirmwareError = 0xcafebabe,
47  HardFault = 0xdeadbeef,
48 };
49 
50 #if EFI_PROD_CODE
52 
53  // Error handling/recovery/reporting information
54  struct {
56 
59  int hardLine;
60  int check;
62  port_extctx FaultCtx;
63  uint32_t FaultType;
64  uint32_t FaultAddress;
65  uint32_t Csfr;
66 
67  uint32_t BootCount;
68  uint32_t BootCountCookie;
69  } Err;
70 
71 };
72 
74 #endif // EFI_PROD_CODE
backup_ram_e
Definition: backup_ram.h:14
uint32_t backupRamLoad(backup_ram_e idx)
Definition: backup_ram.cpp:43
void backupRamSave(backup_ram_e idx, uint32_t value)
Definition: backup_ram.cpp:52
void backupRamFlush(void)
Definition: backup_ram.cpp:61
BackupSramData * getBackupSram()
Definition: backup_ram.cpp:52
ErrorCookie
Definition: backup_ram.h:44
EFI-related GPIO code.
char[CRITICAL_BUFFER_SIZE] critical_msg_t
uint32_t BootCountCookie
Definition: backup_ram.h:68
struct BackupSramData::@29 Err
critical_msg_t ErrorString
Definition: backup_ram.h:57
uint32_t FaultAddress
Definition: backup_ram.h:64
port_extctx FaultCtx
Definition: backup_ram.h:62
uint32_t BootCount
Definition: backup_ram.h:67
uint32_t Csfr
Definition: backup_ram.h:65
ErrorCookie Cookie
Definition: backup_ram.h:55
critical_msg_t rawMsg
Definition: backup_ram.h:61
uint32_t FaultType
Definition: backup_ram.h:63
critical_msg_t hardFile
Definition: backup_ram.h:58