Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
BQ76905_mock.h
Go to the documentation of this file.
1
5#ifndef BQ76905_MOCK_H
6#define BQ76905_MOCK_H
7
8#include "i_ic.h"
9
10// use depend of real component (to have the registers)
11#include "src/system/hal/i2c.h"
13
14// hardwaree influencer simulator
16
17#include "src/system/hal/gpio.h"
18
20
21#include <cstdint>
22#include <map>
23#include <memory>
24
25namespace simulator {
26
28{
29public:
31 {
32 // fill register map
33 _registerMap[bq76905::SAFETY_ALERT_A_ADDR] = std::make_unique<Register>();
34 _registerMap[bq76905::SAFETY_ALERT_B_ADDR] = std::make_unique<Register>();
35
36 _registerMap[bq76905::BATTERY_STATUS_ADDR] = std::make_unique<Register>();
37
38 _registerMap[bq76905::ALARM_STATUS_ADDR] = std::make_unique<AlarmStatusRegister>();
39 _registerMap[bq76905::ALARM_RAW_STATUS_ADDR] = std::make_unique<Register>();
40 _registerMap[bq76905::ALARM_ENABLE_ADDR] = std::make_unique<Register>();
41
42 _registerMap[bq76905::FET_CONTROL_ADDR] = std::make_unique<Register>();
43 _registerMap[bq76905::REGOUT_CONTROL_ADDR] = std::make_unique<Register>();
44
45 _registerMap[bq76905::DSG_FET_DRIVER_PWM_CONTROL_ADDR] = std::make_unique<Register>();
46 _registerMap[bq76905::CHG_FET_DRIVER_PWM_CONTROL_ADDR] = std::make_unique<Register>();
47
48 _registerMap[bq76905::CELL_1_VOLTAGE_ADDR] = std::make_unique<StandardCellVoltage_Register>();
49 _registerMap[bq76905::CELL_2_VOLTAGE_ADDR] = std::make_unique<StandardCellVoltage_Register>();
50 _registerMap[bq76905::CELL_3_VOLTAGE_ADDR] = std::make_unique<StandardCellVoltage_Register>();
51 _registerMap[bq76905::CELL_4_VOLTAGE_ADDR] = std::make_unique<InvalidCellVoltage_Register>();
52 _registerMap[bq76905::CELL_5_VOLTAGE_ADDR] = std::make_unique<InvalidCellVoltage_Register>();
53
54 _registerMap[bq76905::REG_18_VOLTAGE_ADDR] = std::make_unique<Register>();
55 _registerMap[bq76905::VSS_VOLTAGE_ADDR] = std::make_unique<Register>();
56 _registerMap[bq76905::STACK_VOLTAGE_ADDR] = std::make_unique<StackVoltage_Register>();
57
58 _registerMap[bq76905::INT_TEMPERATURE_ADDR] = std::make_unique<InternalTemp_Register>();
59 _registerMap[bq76905::TS_MEASURMENT_ADDR] = std::make_unique<Register>();
60
61 // subcommands
62
63 // Main read place
64 _registerMap[bq76905::SUBCOMMAND_ADDR] = std::make_unique<Subcommand_Register>(); // enter a subcommand
65 _registerMap[bq76905::SUBCOMMAND_DATA_ADDR] =
66 std::make_unique<SubcommandData_Register>(); // read/write the subcommand data
67 _registerMap[bq76905::SUBCOMMAND_DATA_CHECKSUM_ADDR] = std::make_unique<Register>(); // check read/write validity
68 }
69
70 void run_electrical_update() override {}
71
72 uint8_t get_i2c_address() const override { return bq76905::BQ76905::BQ76905addr; }
73
74protected:
77 {
78 uint32_t read() override
79 {
80 uint8_t val0 = 0;
81 val0 |= 1 << 0x07; // FULLSCAN
82 val0 |= 0 << 0x06; // ADSCAN
83 val0 |= 0 << 0x05; // WAKE
84 val0 |= 0 << 0x04; // SLEEP
85 val0 |= 0 << 0x03; // TIMER_ALARM
86 val0 |= 0 << 0x02; // INITCOMP
87 val0 |= 0 << 0x01; // CDTOGGLE
88 val0 |= 0 << 0x0; // POR
89
90 uint8_t val1 = 0;
91 val1 |= 0 << 0x06; // SSB
92 val1 |= 0 << 0x05; // SAA
93 val1 |= 0 << 0x04; // SAB
94 val1 |= 0 << 0x03; // XCHG
95 val1 |= 0 << 0x02; // XDSG
96 val1 |= 0 << 0x01; // SHUTV
97 val1 |= 1 << 0x0; // CB
98
99 uint32_t bitList = val0 | val1 << 8;
100 return bitList;
101 }
102 };
103
106 {
107 uint32_t read() override { return mock_registers::cpuTemperature; }
108 };
109
112 {
113 uint32_t read() override { return mock_battery::voltage * 1000.0; }
114 };
115
118 {
119 uint32_t read() override { return mock_battery::voltage * 1000.0 / 3; }
120 };
122 {
123 uint32_t read() override { return 0; }
124 };
125
128 {
129 int write(uint32_t data) override
130 {
131 if (data > UINT16_MAX)
132 return 1;
133
134 BQ76905Mock::isInSubcommandState = true;
135 BQ76905Mock::subcommandAddress = data;
136 return 0;
137 }
138 };
139
142 {
143 uint32_t read() override
144 {
145 // check subcommand address, set data accordingly
146 uint32_t answer = 0;
147 if (not BQ76905Mock::isInSubcommandState)
148 return 0;
149
150 switch (BQ76905Mock::subcommandAddress)
151 {
152 case bq76905::SUBCOMMAND_DEVICE_NUMBER_ADDR:
153 // big endian answer for device version
154 answer = bq76905::DEVICE_NUMBER;
155 break;
156 case bq76905::SUBCOMMAND_FW_VERSION_ADDR:
157 break;
158 case bq76905::SUBCOMMAND_HW_VERSION_ADDR:
159 break;
160 case bq76905::SUBCOMMAND_PASSQ_ADDR:
161 break;
162 case bq76905::SUBCOMMAND_RESET_PASSQ_ADDR:
163 break;
164 case bq76905::SUBCOMMAND_EXIT_DEEPSLEEP_ADDR:
165 break;
166 case bq76905::SUBCOMMAND_DEEPSLEEP_ADDR:
167 break;
168 case bq76905::SUBCOMMAND_RESET_ADDR:
169 break;
170 case bq76905::SUBCOMMAND_FET_ENABLE_ADDR:
171 break;
172 case bq76905::SUBCOMMAND_SEAL_ADDR:
173 break;
174 case bq76905::SUBCOMMAND_SECURITY_KEYS_ADDR:
175 break;
176 case bq76905::SUBCOMMAND_CB_ACTIVE_CELLS_ADDR:
177 break;
178 case bq76905::SUBCOMMAND_SET_CFGUPDATE_ADDR:
179 break;
180 case bq76905::SUBCOMMAND_EXIT_CFGUPDATE_ADDR:
181 break;
182 case bq76905::SUBCOMMAND_PROG_TIMER_ADDR:
183 break;
184 case bq76905::SUBCOMMAND_SLEEP_ENABLE_ADDR:
185 break;
186 case bq76905::SUBCOMMAND_SLEEP_DISABLE_ADDR:
187 break;
188 case bq76905::SUBCOMMAND_PROT_RECOVERY_ADDR:
189 break;
190 case bq76905::SUBCOMMAND_CONFIGURATION_DA_ADDR:
191 break;
192 case bq76905::SUBCOMMAND_CONFIGURATION_VCELL_MODE_ADDR:
193 break;
194 case bq76905::SUBCOMMAND_CONFIGURATION_TS_OFFSET_ADDR:
195 break;
196 }
197 BQ76905Mock::isInSubcommandState = false;
198 return answer;
199 }
200 };
201
202private:
203 // Create instance of registers data structure
204 inline static bq76905::BQ76905::Regt IcRegisters;
205
206 inline static bool isInSubcommandState = false;
207 inline static uint16_t subcommandAddress = 0;
208};
209
210} // namespace simulator
211
212#endif
Definition: BQ76905_mock.h:28
Interface for the platform specific GeneralPurposeInputOutputs.
Handle the physical simulation paremeters of a real lamp.
Interface for the platform specific i2c protocols.
Electrical simulation interface with the electrical simulator.
Simulator dedicated namespace.
Definition: BQ25713_mock.h:23
Definition: BQ76905.h:336
Bit list register.
Definition: BQ76905_mock.h:77
Temperature.
Definition: BQ76905_mock.h:106
Stack voltage.
Definition: BQ76905_mock.h:112
return the voltage on Cell 1
Definition: BQ76905_mock.h:118
Subcommand data read.
Definition: BQ76905_mock.h:142
Subcommand register.
Definition: BQ76905_mock.h:128
Convertion header to use the text out functions from C code.