@@ -24,28 +24,38 @@ SOFTWARE.
24
24
25
25
26
26
#include " TLE9012.h"
27
+ #include " TLE9012_Makros.h"
27
28
28
29
HardwareSerial* hisoUART;
29
30
30
-
31
+ /*
32
+ Constructor for TLE9012 class. Unused for now
33
+ */
31
34
TLE9012::TLE9012 () // Constructor
32
35
{
33
36
34
37
}
35
38
36
-
39
+ /*
40
+ Destructor for TLE9012 class. Unused for now
41
+ */
37
42
TLE9012::~TLE9012 () // Destructor
38
43
{
39
44
40
45
}
41
46
42
47
48
+ /*
49
+
50
+ */
43
51
44
-
45
- void TLE9012::init (HardwareSerial* serial, uint32_t baudrate=1000000 )// Driver init
52
+ void TLE9012::init (HardwareSerial* serial, uint32_t baudrate=1000000 ,uint8_t rxpin=0 ,uint8_t txpin=0 )// Driver init
46
53
{
47
54
hisoUART = serial;
48
- hisoUART->begin (baudrate,SERIAL_8N1,16 ,17 );
55
+ if ((rxpin != 0 ) && (txpin != 0 ))
56
+ hisoUART->begin (baudrate,SERIAL_8N1,rxpin,txpin);
57
+ else
58
+ hisoUART->begin (baudrate,SERIAL_8N1);
49
59
}
50
60
51
61
void TLE9012::wakeUp ()
@@ -73,6 +83,170 @@ void TLE9012::wakeUp()
73
83
}
74
84
}
75
85
}
86
+
87
+ // High Level Routines
88
+
89
+ // Measurement related functions
90
+ void TLE9012::readCellVoltages (uint8_t nodeID)
91
+ {
92
+
93
+ }
94
+
95
+ void TLE9012::readTemperatures (uint8_t nodeID)
96
+ {
97
+
98
+ }
99
+
100
+ void TLE9012::setNumberofCells (uint8_t nodeID, uint8_t n_cells)
101
+ {
102
+
103
+ }
104
+
105
+ void TLE9012::setNumberofTempSensors (uint8_t nodeID, uint8_t n_temp_sensors)
106
+ {
107
+
108
+ }
109
+
110
+ // Watchdog and Power state handling
111
+ void TLE9012::activateSleep ()
112
+ {
113
+ (void ) writeRegisterBroadcast (OP_MODE,0x0001 ); // Return is ignored for now
114
+ }
115
+
116
+ void TLE9012::resetWatchdog ()
117
+ {
118
+ (void ) writeRegisterBroadcast (WDOG_CNT,0x007F );
119
+ }
120
+
121
+ void TLE9012::setExtendedWatchdog (uint8_t nodeID)
122
+ {
123
+ uint16_t op_mode_reg = 0 ;
124
+ (void ) readRegisterSingle (nodeID, OP_MODE, &op_mode_reg);
125
+ op_mode_reg |= 0x0002 ;
126
+ (void ) writeRegisterSingle (nodeID, OP_MODE, op_mode_reg);
127
+ }
128
+
129
+ void TLE9012::clearExtendedWatchdog (uint8_t nodeID)
130
+ {
131
+ uint16_t op_mode_reg = 0 ;
132
+ (void ) readRegisterSingle (nodeID, OP_MODE, &op_mode_reg);
133
+ op_mode_reg &= 0xFFFD ;
134
+ (void ) writeRegisterSingle (nodeID, OP_MODE, op_mode_reg);
135
+ }
136
+
137
+ // Miscallanious stuff
138
+ uint16_t TLE9012::readICVersionandManufacturerID (uint8_t nodeID)
139
+ {
140
+ uint16_t id = 0 ;
141
+ (void ) readRegisterSingle (nodeID, ICVID, &id);
142
+ return id;
143
+ }
144
+
145
+ void TLE9012::setNodeID (uint8_t oldID, uint8_t newID, uint8_t finalNode)
146
+ {
147
+ uint16_t cfg;
148
+ (void ) readRegisterSingle (oldID,CONFIG,&cfg);
149
+ cfg &= 0x07C0 ;
150
+ cfg |= newID & 0x3F ;
151
+ cfg |= finalNode<<11 ;
152
+ (void ) writeRegisterSingle (oldID,CONFIG,cfg);
153
+ }
154
+
155
+ void TLE9012::writeMailboxRegister (uint8_t nodeID, uint16_t value)
156
+ {
157
+ (void ) writeRegisterSingle (nodeID,MAILBOX,value);
158
+ }
159
+
160
+ void TLE9012::readMailboxRegister (uint8_t nodeID)
161
+ {
162
+ uint16_t id = 0 ;
163
+ (void ) readRegisterSingle (nodeID, MAILBOX, &id);
164
+ return id;
165
+ }
166
+
167
+
168
+ // Error checking and handling
169
+ void TLE9012::checkDiagnoseResistor (uint8_t nodeID)
170
+ {
171
+
172
+ }
173
+
174
+ void TLE9012::attachErrorHandler (tle9012_error_t errortype, void (*errorhandler)(uint8_t , uint16_t ))
175
+ {
176
+
177
+ }
178
+
179
+ void TLE9012::checkErrors (uint8_t nodeID)
180
+ {
181
+
182
+ }
183
+
184
+ // Round Robin Functions
185
+
186
+ void TLE9012::setRoundRobinErrorHandling (uint8_t nodeID, uint16_t rr_sleep_interval, uint8_t rr_temp_measurement_interval, uint8_t n_errors)
187
+ {
188
+
189
+ }
190
+
191
+ void TLE9012::setRoundRobinConfig (uint8_t nodeID, uint8_t rr_counter, rr_error_mask_t errormask)
192
+ {
193
+
194
+ }
195
+
196
+ // Cell Balancing Functions
197
+
198
+ void TLE9012::setBalancingPWM (uint8_t nodeID, tle9012_balancing_pwm_t pwm_duty_cycle)
199
+ {
200
+
201
+ }
202
+
203
+ void TLE9012::setBalancingCounter (uint8_t nodeID, uint8_t cell, uint8_t value)
204
+ {
205
+
206
+ }
207
+
208
+ void TLE9012::startBalancing (uint8_t nodeID, uint16_t balancing_mask)
209
+ {
210
+
211
+ }
212
+
213
+ // Threshold set functions
214
+ void TLE9012::setOvervoltageThreshold (uint8_t nodeID, uint16_t fault_threshold)
215
+ {
216
+
217
+ }
218
+
219
+ void TLE9012::setUndervoltageThreshold (uint8_t nodeID, uint16_t fault_threshold)
220
+ {
221
+
222
+ }
223
+
224
+ void TLE9012::setOpenLoadThresholdMax (uint8_t nodeID, uint8_t open_load_threshold)
225
+ {
226
+
227
+ }
228
+
229
+ void TLE9012::setOpenLoadThresholdMin (uint8_t nodeID, uint8_t open_load_threshold)
230
+ {
231
+
232
+ }
233
+
234
+ void TLE9012::setExternalTemperatureThreshold (uint8_t nodeID, uint16_t external_overtemperature_threshold)
235
+ {
236
+
237
+ }
238
+
239
+ void TLE9012::setInternalTemperatureThreshold (uint8_t nodeID, uint16_t internal_overtemperature_threshold)
240
+ {
241
+
242
+ }
243
+
244
+ void TLE9012::setBalancingCurrentThreshold (uint8_t nodeID, uint8_t overcurrent_threshold, uint8_t undercurrent_threshold)
245
+ {
246
+
247
+ }
248
+
249
+
76
250
77
251
// Low Level Routines for direct register Access
78
252
iso_uart_status_t TLE9012::readRegisterSingle (uint8_t nodeID, uint16_t regaddress, uint16_t * result)
@@ -144,6 +318,14 @@ iso_uart_status_t TLE9012::writeRegisterSingle(uint8_t nodeID, uint16_t regaddre
144
318
return status;
145
319
}
146
320
321
+ // Check if reply frame was received correctly
322
+ msb_first_converter (&response_buffer[6 ],1 );
323
+ if (!crc3 (response_buffer[6 ]))
324
+ {
325
+ status = isoUART_CRC_ERROR;
326
+ return status;
327
+ }
328
+
147
329
return status;
148
330
}
149
331
@@ -217,20 +399,55 @@ iso_uart_status_t TLE9012::writeRegisterBroadcast(uint16_t regaddress, uint16_t
217
399
return status;
218
400
}
219
401
402
+ // Check if reply frame was received correctly
403
+ msb_first_converter (&response_buffer[6 ],1 );
404
+ if (!crc3 (response_buffer[6 ]))
405
+ {
406
+ status = isoUART_CRC_ERROR;
407
+ return status;
408
+ }
409
+
220
410
return status;
221
411
}
222
412
223
413
iso_uart_status_t TLE9012::configureMultiread (multiread_cfg_t cfg) // Write a multiread configuration to all devices in the daisy chain
224
414
{
225
-
415
+ return 0 ; // Multiread is unsuported for the moment
226
416
}
227
417
228
418
iso_uart_status_t TLE9012::multiRead (multread_result_t * databuffer) // Multiread command from all devices in the chain
229
419
{
230
-
420
+ return 0 ; // Multiread is unsuported for the moment
231
421
}
232
422
233
423
// Private Functions start here
424
+
425
+ /*
426
+ Calculate the CRC-3 of the reply Frame
427
+ returns 1 if crc is correct and 0 if crc is false
428
+ */
429
+ uint8_t TLE9012::crc3 (uint8_t replyframe)
430
+ {
431
+ uint8_t polynomial = 0xB0 ;
432
+ uint8_t crc = replyframe;
433
+
434
+ for (uint8_t n = 0 ; n < 5 ; n++)
435
+ {
436
+ if (crc & 0x80 )
437
+ {
438
+ crc = crc^polynomial;
439
+ crc = crc << 1 ;
440
+ }
441
+ else
442
+ crc = crc << 1 ;
443
+ }
444
+
445
+ if (crc == 0 )
446
+ return 1 ;
447
+ else
448
+ return 0 ;
449
+ }
450
+
234
451
uint8_t TLE9012::crc8 (uint8_t * buffer, uint16_t len)
235
452
{
236
453
const uint8_t polynomial = 0x1D ;
0 commit comments