source: ecs_cellMon/firmware/src/eeprom.c @ 3

Last change on this file since 3 was 3, checked in by f.jahn, 20 months ago

fw hinzugfügt-->zed

File size: 20.3 KB
RevLine 
[3]1#include "eeprom.h"
2#include "stdio.h"
3#include "string.h"
4/********************************************************/
5
6// Eeprom state related defines
7
8/*****************EEPROM_EMULATOR************************/
9
10typedef struct
11{
12  // Schnittstellenparameter
13  uint32_t     baudrate;           
14  uint16_t     parityMode;                                 
15  uint16_t     stopBits;       
16  uint16_t     slaveAddress;
17
18  // Cell Parameter
19  uint16_t    ovpAlarm; 
20  uint16_t    lvpAlarm; 
21  uint16_t    ovpStart;
22  uint16_t    ovpStop;
23  uint16_t    lvpStart;
24  uint16_t    lvpStop;
25  uint16_t    vShutdownStart;
26  uint16_t    vShutdownStop; 
27  int16_t     otShutdownStart;
28  int16_t     otShutdownStop;
29  int16_t     utpChargeStart;
30  int16_t     utpChargeStop;       
31  int16_t     utpDischargeStart;
32  int16_t     utpDischargeStop;
33  uint16_t    lvpTime;
34  uint16_t    defaultBalVoltage;
35 
36  // tempco
37  int16_t     refTemp;
38  int16_t     ovpAlarmTempco;
39  int16_t     lvpAlarmTempco;
40  int16_t     ovpStartTempco;
41  int16_t     ovpStopTempco;
42  int16_t     lvpStartTempco;
43  int16_t     lvpStopTempco;     
44  int16_t     vShutdownStartTempco;
45  int16_t     vShutdownStopTempco; 
46  int16_t     balancerVoltageTempco;
47  uint16_t    lockKey;
48}eeprom_data_t;
49
50typedef struct 
51{
52  // Geräteinformation
53  uint32_t    SN;
54  uint8_t     deviceInfoWritten;
55  uint8_t     resv[3];
56}device_info_t;
57
58
59typedef struct
60{
61  // Eeprom Status Infos
62  uint32_t     writeCounter;
63  uint16_t     structureSize;
64  uint16_t     revisionInfo;
65   uint8_t     firstStartId;
66}eeprom_state_t;
67
68
69typedef struct
70{
71  // Eeprom Status Infos
72  uint16_t    cycleCounter;
73  uint16_t    minVoltage;
74  uint16_t    maxVoltage;
75  int16_t     minTemperature;
76  int16_t     maxTemperature;
77  uint16_t    criticalOverTempTime;
78  uint16_t    criticalUnderTempTime;
79  uint16_t    criticalOvervoltageTime;
80  uint16_t    criticalUndervoltageTime;
81
82}log_data_t;
83
84// fasse zu einer Struktur zusammen um nachher einfach darauf zugreifen zu können
85typedef struct
86{
87  eeprom_data_t changedData;
88  eeprom_state_t  eepromState;
89  device_info_t deviceInfo;
90  log_data_t logData;
91}eeprom_stored_data_t;
92
93// Flash related defines
94#define USER_FLASH_BASE_ADRESS                    FLASH_BASE
95
96#define USER_FLASH_SIZE                           FLASH_SIZE
97//#define USER_FLASH_END                            ((USER_FLASH_BASE_ADRESS + USER_FLASH_SIZE) - 1)
98#define USER_FLASH_END                            (USER_FLASH_BASE_ADRESS + USER_FLASH_SIZE)
99#define USER_FLASH_PAGE_SIZE                      (0x800)
100
101// Eeprom emulator related defines
102#define NUMBER_OF_PAGES                           (2)
103#define USER_EEPROM_BASE_ADRESS                   (USER_FLASH_END - (USER_FLASH_PAGE_SIZE * NUMBER_OF_PAGES))
104
105// Data to store reated defines
106#define SIZEOF_DEFAULT_EEPROM_DATA                (sizeof(eeprom_data_t))
107#define SIZEOF_CHANGED_EEPROM_DATA                (sizeof(eeprom_data_t))
108#define SIZEOF_DEVICE_INFO                        (sizeof(device_info_t))
109#define SIZEOF_EEPROM_STATE                       (sizeof(eeprom_state_t))
110
111#define SIZE_OF_DATA_TO_STORE                     (SIZEOF_CHANGED_EEPROM_DATA + SIZEOF_DEVICE_INFO + SIZEOF_EEPROM_STATE)
112
113// Adress related defines
114#define EEPROM_ADRESS_FIRST_START_ID              (USER_EEPROM_BASE_ADRESS - 1 + SIZE_OF_DATA_TO_STORE - 1 - SIZEOF_DEVICE_INFO - 1 - 1)
115#define FIRST_START_ID                            (1)
116
117
118static uint32_t GetPage(uint32_t Address);
119static HAL_StatusTypeDef getEEPROMData(uint32_t address, uint8_t * data, uint32_t len);
120
121// muss modulo 8 noch hinzufügen wg 8 byte alignement
122static uint64_t eepromData[(SIZE_OF_DATA_TO_STORE / 8) + 1];
123static uint64_t eepromLogData[(sizeof(log_data_t) / 8) + 1];
124static FLASH_EraseInitTypeDef EraseInitStruct = {0};
125
126extern uint16_t savedLockKey;
127
128static const eeprom_data_t defaultEepromData =
129{
130  // Schnittstellenparameter
131  MB_BAUDRATE_DEFAULT,   
132  MB_PARITY_MODE_DEFAULT,
133  MB_STOPBIT_MODE_DEFAULT,        /*uint16_t     stopbitmode, reserviert;*/                           
134  MB_SLAVE_ADDRESS_DEFAULT,        /*uint16_t     slave_adress;*/ 
135  OVP_ALARM_VOLTAGE_DEFAULT,
136  LVP_ALARM_VOLTAGE_DEFAULT,
137  OVP_START_VOLTAGE_DEFAULT,
138  OVP_STOPP_VOLTAGE_DEFAULT,
139  LVP_START_VOLTAGE_DEFAULT,
140  LVP_STOPP_VOLTAGE_DEFAULT,
141  VOLTAGE_SHUTDOWN_START_VOLTAGE_DEFAULT,
142  VOLTAGE_SHUTDOWN_STOPP_VOLTAGE_DEFAULT,
143  OVERTEMPPROTECTION_START_DEFAULT,
144  OVERTEMPPROTECTION_STOP_DEFAULT,
145  UNDERTEMPPROTECTION_CHARGE_START_DEFAULT,
146  UNDERTEMPPROTECTION_CHARGE_STOP_DEFAULT,
147  UNDERTEMPPROTECTION_DISCHARGE_START_DEFAULT,
148  UNDERTEMPPROTECTION_DISCHARGE_STOP_DEFAULT,
149  LVP_TIME_DEFAULT,
150  BAL_VOLTAGE_DEFAULT,
151  BASIS_TEMP_DEFAULT,
152  OVP_ALARM_TEMPCO_DEFAULT,
153  LVP_ALARM_TEMPCO_DEFAULT,
154  OVP_START_TEMPCO_DEFAULT,
155  OVP_STOPP_TEMPCO_DEFAULT,
156  LVP_START_TEMPCO_DEFAULT,
157  LVP_STOPP_TEMPCO_DEFAULT,
158  V_SHUTDOWN_START_TEMPCO_DEFAULT,
159  V_SHUTDOWN_STOPP_TEMPCO_DEFAULT,
160  BAL_TEMPCO_DEFAULT,
161  0,                                  //Lockkey, Default keiner!
162};
163
164/**
165  * @brief  Gets the page of a given address
166  * @param  Addr: Address of the FLASH Memory
167  * @retval The page of a given address
168  */
169static uint32_t GetPage(uint32_t Addr)
170{
171  return (Addr - FLASH_BASE) / FLASH_PAGE_SIZE;
172}
173
174static HAL_StatusTypeDef getEEPROMData(uint32_t address, uint8_t * data, uint32_t len)
175{
176    uint32_t i = 0;
177    uint8_t daten;
178    if((address + len) > USER_FLASH_END)
179    {
180      return HAL_ERROR;
181    }
182    for(i = 0; i < len; i ++)
183    {
184      data[i] = *((uint8_t *) (address + i));
185    }
186    return HAL_OK;
187}
188
189bool EEPROM_isFirstStart()
190{
191
192  uint8_t firstStartCatcher;
193  if(getEEPROMData(EEPROM_ADRESS_FIRST_START_ID, (uint8_t *)&firstStartCatcher, 1) != HAL_OK) return HAL_ERROR;
194  if(firstStartCatcher != FIRST_START_ID)
195  {
196    printf ("First start detected\n");
197    return true;
198
199  }
200  else
201  {
202    printf ("previous config present\n");
203    return false;
204  }
205}
206
207HAL_StatusTypeDef EEPROM_fullRestore(sys_data_t * data, bool keepSN)
208{
209  eeprom_stored_data_t * dataToStore;
210  uint32_t PageError;
211  uint32_t Address;
212  uint32_t x;
213
214  printf("EEPROM FULL RESTORE!\n");
215
216  /****************LESE_DEFAULT_WERTE************************/
217
218  dataToStore = (eeprom_stored_data_t *) eepromData;
219 
220  memcpy( (void *) &dataToStore->changedData, (void*) &defaultEepromData, sizeof(dataToStore->changedData)) ;
221 
222 
223  // Eeprom Status Infos
224  dataToStore->eepromState.writeCounter ++;
225  dataToStore->eepromState.structureSize = sizeof(eeprom_stored_data_t);
226  dataToStore->eepromState.revisionInfo = 0;
227  dataToStore->eepromState.firstStartId = FIRST_START_ID;
228 
229  /****************PAGE_LÖSCHEN********************/   
230  HAL_FLASH_Unlock();
231   
232  // check for PG bit set if so clear bit
233  FLASH_WaitForLastOperation(1000);
234  if(READ_BIT(FLASH->CR, FLASH_CR_PG)) 
235  {
236    CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
237  }
238 
239  /* Fill EraseInit structure*/
240  //Speicherung in vorletzter page, deshalb diese löschen.
241  //Log Daten kommen in die letzte page
242  EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
243  EraseInitStruct.Page        = FLASH_PAGE_NB - 2; //GetPage(USER_EEPROM_BASE_ADRESS);
244  EraseInitStruct.NbPages     = 1;
245
246  /* erase Sektoren daten d+rfen nicht im instuction cache liegen  */
247  if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
248  {
249    while (1)
250    {
251      // ERROR HAL_FLASH_GetError() kann info geben
252    }
253  }
254
255  /****************IM_FLASH_SPEICHERN********************/
256
257  /* programmiere uint64_t */
258  Address = USER_EEPROM_BASE_ADRESS;
259  x = 0;
260  while (Address < (USER_EEPROM_BASE_ADRESS + SIZE_OF_DATA_TO_STORE))
261  {
262    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, eepromData[x]) == HAL_OK)
263    {
264      Address = Address + 8;
265      x ++;
266    }
267   else
268    {
269      /* Error occurred while writing data in Flash memory.
270         User can add here some code to deal with this error */
271      while (1)
272      {
273        // ERROR
274      }
275    }
276  }
277
278  /* Lock the Flash */
279  HAL_FLASH_Lock();
280
281  /****************AUSLESEN_UND_PRÜFEN********************/
282
283  return EEPROM_readConfig(data);
284
285
286}
287
288
289
290HAL_StatusTypeDef EEPROM_storeConfig(sys_data_t * data,bool withSN, bool saveNewKey)
291{
292  eeprom_stored_data_t * dataToStore;
293  uint32_t PageError;
294  uint32_t Address;
295  uint32_t x;
296  /****************LESE_WERTE_AUS_SYSDATA*********************/ 
297  printf("EEPROM STORE CONFIG!\n");
298  dataToStore = (eeprom_stored_data_t *) eepromData;
299 
300  // Schnittstellenparameter
301  dataToStore->changedData.baudrate = data->s.baudrate;           
302  dataToStore->changedData.parityMode = data->s.parityMode;                                     
303  dataToStore->changedData.stopBits = data->s.stopBits;
304  dataToStore->changedData.slaveAddress = data->s.slaveAddress; 
305
306    // Cell Parameter
307  dataToStore->changedData.ovpAlarm = data->s.ovpAlarm;
308  dataToStore->changedData.lvpAlarm = data->s.lvpAlarm;
309  dataToStore->changedData.ovpStart = data->s.ovpStart;
310  dataToStore->changedData.ovpStop  = data->s.ovpStop;
311  dataToStore->changedData.lvpStart = data->s.lvpStart;
312  dataToStore->changedData.lvpStop  = data->s.lvpStop;
313  dataToStore->changedData.vShutdownStart  = data->s.vShutdownStart;
314  dataToStore->changedData.vShutdownStop   = data->s.vShutdownStop;
315  dataToStore->changedData.otShutdownStart = data->s.otShutdownStart;
316  dataToStore->changedData.otShutdownStop  = data->s.otShutdownStop;
317  dataToStore->changedData.utpChargeStart  = data->s.utpChargeStart;
318  dataToStore->changedData.utpChargeStop   = data->s.utpChargeStop;
319  dataToStore->changedData.utpDischargeStart = data->s.utpDischargeStart;
320  dataToStore->changedData.utpDischargeStop  = data->s.utpDischargeStop;
321  dataToStore->changedData.lvpTime           = data->s.lvpTime;
322  dataToStore->changedData.defaultBalVoltage = data->s.defaultBalVoltage;
323
324   // tempco
325  dataToStore->changedData.refTemp = data->s.refTemp;
326  dataToStore->changedData.ovpAlarmTempco = data->s.ovpAlarmTempco;
327  dataToStore->changedData.lvpAlarmTempco = data->s.lvpAlarmTempco;
328  dataToStore->changedData.ovpStartTempco = data->s.ovpStartTempco;
329  dataToStore->changedData.ovpStopTempco  = data->s.ovpStopTempco;
330  dataToStore->changedData.lvpStartTempco = data->s.lvpStartTempco;
331  dataToStore->changedData.lvpStopTempco  = data->s.lvpStopTempco;
332  dataToStore->changedData.vShutdownStartTempco = data->s.vShutdownStartTempco;
333  dataToStore->changedData.vShutdownStopTempco = data->s.vShutdownStopTempco;
334  dataToStore->changedData.balancerVoltageTempco = data->s.balancerVoltageTempco;
335
336  if (saveNewKey)
337  {
338    dataToStore->changedData.lockKey = data->s.newLockKey;
339  }
340  else
341  {
342    dataToStore->changedData.lockKey = savedLockKey;
343  }
344 
345
346  // Eeprom Status Infos
347  dataToStore->eepromState.writeCounter ++ ;
348  dataToStore->eepromState.structureSize = sizeof(eeprom_stored_data_t);
349  dataToStore->eepromState.revisionInfo = 0;
350  dataToStore->eepromState.firstStartId = FIRST_START_ID;
351
352  if (withSN)
353  {
354    printf("Writing SN!\n");
355    dataToStore->deviceInfo.SN = data->s.deviceSn;
356  }
357
358  /****************PAGE_LÖSCHEN********************/ 
359  HAL_FLASH_Unlock();
360
361  // check for PG bit set if so clear bit
362  FLASH_WaitForLastOperation(1000);
363  if(READ_BIT(FLASH->CR, FLASH_CR_PG)) 
364  {
365    CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
366  }
367
368  /* Fill EraseInit structure*/
369  EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
370  EraseInitStruct.Page        = FLASH_PAGE_NB - 2; 
371  EraseInitStruct.NbPages     = 1;
372
373  /* erase Sektoren daten dürfen nicht im instuction cache liegen  */
374  if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
375  {
376    while (1)
377    {
378      // ERROR HAL_FLASH_GetError() kann info geben
379    }
380  }
381
382  /****************IM_FLASH_SPEICHERN********************/
383
384  /* programmiere uint64_t */
385  Address = USER_EEPROM_BASE_ADRESS;
386  x = 0;
387  while (Address < (USER_EEPROM_BASE_ADRESS + SIZE_OF_DATA_TO_STORE))
388  {
389    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, eepromData[x]) == HAL_OK)
390    {
391      Address = Address + 8;
392      x ++;
393    }
394   else
395    {
396      /* Error occurred while writing data in Flash memory.
397         User can add here some code to deal with this error */
398      while (1)
399      {
400        // ERROR
401      }
402    }
403  }
404
405  /* Lock the Flash */
406  HAL_FLASH_Lock();
407
408  /****************AUSLESEN_UND_PRÜFEN********************/
409
410  return EEPROM_readConfig(data);
411
412
413}
414
415HAL_StatusTypeDef EEPROM_storeLogData()
416{
417 
418  uint32_t PageError;
419  uint32_t Address;
420  uint32_t x;
421  log_data_t * logData;
422  /****************LESE_WERTE_AUS_SYSDATA*********************/ 
423  printf("EEPROM STORE LOG DATA!\n");
424
425  //Zeiger auf Resevierten Ram Speicher, der für das speichern der Daten zuständig ist
426  logData = (log_data_t *) eepromLogData;
427  logData->cycleCounter = sysData.s.cycleCounter;
428  logData->maxVoltage = sysData.s.maxVoltage;
429  logData->minVoltage = sysData.s.minVoltage;
430  logData->maxTemperature = sysData.s.maxTemperature;
431  logData->minTemperature = sysData.s.minTemperature;
432  logData->criticalOvervoltageTime = sysData.s.criticalOverVoltageTime;
433  logData->criticalUndervoltageTime = sysData.s.criticalUnderVoltageTime;
434  logData->criticalOverTempTime = sysData.s.criticalOverTempTime;
435  logData->criticalUnderTempTime = sysData.s.criticalUnderTempTime;
436 
437
438  /****************PAGE_LÖSCHEN********************/ 
439  HAL_FLASH_Unlock();
440
441  // check for PG bit set if so clear bit
442  FLASH_WaitForLastOperation(1000);
443  if(READ_BIT(FLASH->CR, FLASH_CR_PG)) 
444  {
445    CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
446  }
447
448  /* Fill EraseInit structure*/
449  EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
450  EraseInitStruct.Page        = FLASH_PAGE_NB - 1;  // Page löschen
451  EraseInitStruct.NbPages     = 1;
452
453  /* erase Sektoren daten dürfen nicht im instuction cache liegen  */
454  if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
455  {
456    printf("Error while deleting log data area in flash\n");
457    return HAL_ERROR;
458  }
459
460  /****************IM_FLASH_SPEICHERN********************/
461
462  /* programmiere uint64_t */
463  uint32_t startAdress =  USER_EEPROM_BASE_ADRESS + FLASH_PAGE_SIZE;
464  Address = startAdress;
465  x = 0;
466  while (Address < (startAdress + sizeof(log_data_t)))
467  {
468    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, eepromLogData[x]) == HAL_OK)
469    {
470      Address = Address + 8;
471      x ++;
472    }
473   else
474    {
475        printf("Error while saving data to flash\n");
476        return HAL_ERROR;
477    }
478  }
479
480  /* Lock the Flash */
481  HAL_FLASH_Lock();
482
483  return HAL_OK;
484}
485
486
487HAL_StatusTypeDef EEPROM_ResetLogData()
488{
489 
490  uint32_t PageError;
491  uint32_t Address;
492  uint32_t x;
493  log_data_t * logData;
494  /****************LESE_WERTE_AUS_SYSDATA*********************/ 
495  printf("EEPROM STORE LOG DATA!\n");
496
497  //Zeiger auf Resevierten Ram Speicher, der für das speichern der Daten zuständig ist
498  logData = (log_data_t *) eepromLogData;
499  logData->cycleCounter = 0;
500  logData->maxVoltage = 0;
501  logData->minVoltage = UINT16_MAX;
502  logData->maxTemperature = INT16_MIN;
503  logData->minTemperature = INT16_MAX;
504  logData->criticalOvervoltageTime = 0;
505  logData->criticalUndervoltageTime = 0;
506  logData->criticalOverTempTime = 0;
507  logData->criticalUnderTempTime = 0;
508 
509
510  /****************PAGE_LÖSCHEN********************/ 
511  HAL_FLASH_Unlock();
512
513  // check for PG bit set if so clear bit
514  FLASH_WaitForLastOperation(1000);
515  if(READ_BIT(FLASH->CR, FLASH_CR_PG)) 
516  {
517    CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
518  }
519
520  /* Fill EraseInit structure*/
521  EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
522  EraseInitStruct.Page        = FLASH_PAGE_NB - 1;  // Page löschen
523  EraseInitStruct.NbPages     = 1;
524
525  /* erase Sektoren daten dürfen nicht im instuction cache liegen  */
526  if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK)
527  {
528    printf("Error while deleting log data area in flash\n");
529    return HAL_ERROR;
530  }
531
532  /****************IM_FLASH_SPEICHERN********************/
533
534  /* programmiere uint64_t */
535  uint32_t startAdress =  USER_EEPROM_BASE_ADRESS + FLASH_PAGE_SIZE;
536  Address = startAdress;
537  x = 0;
538  while (Address < (startAdress + sizeof(log_data_t)))
539  {
540    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, eepromLogData[x]) == HAL_OK)
541    {
542      Address = Address + 8;
543      x ++;
544    }
545   else
546    {
547        printf("Error while saving data to flash\n");
548        return HAL_ERROR;
549    }
550  }
551
552  /* Lock the Flash */
553  HAL_FLASH_Lock();
554
555  return HAL_OK;
556}
557
558
559
560HAL_StatusTypeDef EEPROM_readConfig(sys_data_t * data)
561{
562  eeprom_stored_data_t * dataToStore;
563
564  /****************WERTE_AUS_FLASH_LESEN********************/
565 
566 
567  if(getEEPROMData(USER_EEPROM_BASE_ADRESS, (uint8_t *)eepromData, sizeof(eepromData)) != HAL_OK) return HAL_ERROR;
568
569  dataToStore = (eeprom_stored_data_t *) eepromData;
570 
571  // Schnittstellenparameter
572  data->s.baudrate = dataToStore->changedData.baudrate;           
573  data->s.parityMode = dataToStore->changedData.parityMode;     
574  data->s.stopBits = dataToStore->changedData.stopBits;     
575  data->s.slaveAddress = dataToStore->changedData.slaveAddress; 
576
577  //   // Cell Parameter
578  data->s.ovpAlarm = dataToStore ->changedData.ovpAlarm;
579  data->s.lvpAlarm = dataToStore ->changedData.lvpAlarm;
580  data->s.ovpStart = dataToStore ->changedData.ovpStart;
581  data->s.ovpStop  = dataToStore ->changedData.ovpStop;
582  data->s.lvpStart = dataToStore ->changedData.lvpStart;
583  data->s.lvpStop  = dataToStore ->changedData.lvpStop;
584  data->s.vShutdownStart    = dataToStore->changedData.vShutdownStart;
585  data->s.vShutdownStop     = dataToStore->changedData.vShutdownStop;
586  data->s.otShutdownStart   = dataToStore->changedData.otShutdownStart;
587  data->s.otShutdownStop    = dataToStore->changedData.otShutdownStop;
588  data->s.utpChargeStart    = dataToStore->changedData.utpChargeStart;
589  data->s.utpChargeStop     = dataToStore->changedData.utpChargeStop;
590  data->s.utpDischargeStart = dataToStore->changedData.utpDischargeStart;
591  data->s.utpDischargeStop  = dataToStore->changedData.utpDischargeStop; 
592  data->s.lvpTime           = dataToStore->changedData.lvpTime;
593  data->s.defaultBalVoltage = dataToStore->changedData.defaultBalVoltage;
594
595
596  // tempco
597  data->s.refTemp = dataToStore ->changedData.refTemp;
598  data->s.ovpAlarmTempco = dataToStore ->changedData.ovpAlarmTempco;
599  data->s.lvpAlarmTempco =  dataToStore ->changedData.lvpAlarmTempco;
600  data->s.ovpStartTempco = dataToStore ->changedData.ovpStartTempco;
601  data->s.ovpStopTempco = dataToStore->changedData.ovpStopTempco;
602  data->s.lvpStartTempco = dataToStore->changedData.lvpStartTempco;
603  data->s.lvpStopTempco = dataToStore->changedData.lvpStopTempco;
604  data->s.vShutdownStartTempco = dataToStore->changedData.vShutdownStartTempco;
605  data->s.vShutdownStopTempco = dataToStore->changedData.vShutdownStopTempco;
606  data->s.balancerVoltageTempco = dataToStore->changedData.balancerVoltageTempco;
607  savedLockKey =  dataToStore->changedData.lockKey;
608  if (savedLockKey != 0) sysData.s.writeLocked = 1 ;
609  //  Geräteinformation
610  data->s.deviceSn = dataToStore->deviceInfo.SN;
611 
612
613  // prüfe Eeprom Status Infos
614  if(dataToStore->eepromState.structureSize != sizeof(eeprom_stored_data_t)) return HAL_ERROR;
615  if(dataToStore->eepromState.revisionInfo != 0) return HAL_ERROR;
616  if(dataToStore->eepromState.firstStartId != FIRST_START_ID) return HAL_ERROR;
617
618  return HAL_OK;
619}
620
621
622
623HAL_StatusTypeDef EEPROM_readLogData()
624{
625  log_data_t * logData;
626
627  /****************WERTE_AUS_FLASH_LESEN********************/
628 
629 
630  if(getEEPROMData(USER_EEPROM_BASE_ADRESS + FLASH_PAGE_SIZE, (uint8_t *)eepromLogData, sizeof(eepromLogData)) != HAL_OK) return HAL_ERROR;
631
632  logData = (log_data_t *) eepromLogData; 
633  sysData.s.cycleCounter = logData->cycleCounter;
634  sysData.s.maxVoltage = logData->maxVoltage; 
635  sysData.s.minVoltage = logData->minVoltage;
636  sysData.s.maxTemperature = logData->maxVoltage;
637  sysData.s.minTemperature = logData->minTemperature;
638  sysData.s.criticalOverVoltageTime = logData->criticalOvervoltageTime;
639  sysData.s.criticalUnderVoltageTime = logData->criticalUndervoltageTime;
640  sysData.s.criticalOverTempTime = logData->criticalOverTempTime;
641  sysData.s.criticalUnderTempTime = logData->criticalUnderTempTime; 
642
643  return HAL_OK;
644}
Note: See TracBrowser for help on using the repository browser.