eeprom.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright Jordy Sipkema, 2016.
  3. *
  4. * Project : 20152016-TI2.3a6-Internet Radio
  5. * Module : Eeprom
  6. * File name : Eeprom.h
  7. * Revision : 2.0
  8. * Creation Date : 2016/03/04
  9. *
  10. * Description : This module stores the non-volatile settings
  11. * for the radio in the atmega128's internal eeprom
  12. */
  13. #include "eeprom.h"
  14. void EepromRead(int addr, void* settings, size_t size){
  15. }
  16. void EepromWrite(int addr, void* settings, size_t size){
  17. }
  18. bool EepromGetAll(TSettings *settings){
  19. NutNvMemLoad(EEPROM_BASE, settings, sizeof(*settings));
  20. if (settings->Checksum != sizeof(*settings)){
  21. // Size mismatch: There is no valid configuration present.
  22. puts("EepromGetAll(): Size mismatch");
  23. return false;
  24. }
  25. return true;
  26. }
  27. void EepromSetAll(TSettings *settings){
  28. int success = NutNvMemSave(EEPROM_BASE, settings, sizeof(*settings));
  29. if (success == 0){ puts("EepromSetAll: SettingsSetAll successful."); }
  30. else { puts("EepromSetAll: SettingsSetAll successful."); }
  31. NutDelay(100);
  32. }
  33. void EepromWriteDefaults(void){
  34. puts("EepromWriteDefaults()");
  35. // Declare TSettings:
  36. TSettings settings;
  37. settings.Checksum = sizeof(settings);
  38. settings.Cache = (const struct TCache){ 0 };
  39. settings.System = (const struct TSettingsSystem){ 0 };
  40. EepromSetAll(&settings);
  41. }
  42. //bool EepromGetSystemSettings(TSettingsSystem *SystemSettings){
  43. //
  44. //}
  45. //
  46. bool EepromGetCache(TCache *cache){
  47. TSettings *settings;
  48. if (EepromGetAll(settings) == false){
  49. return false;
  50. }
  51. *cache = settings->Cache;
  52. return true;
  53. }
  54. void EepromSetCache(TCache *cache){
  55. TSettings settings;
  56. settings.Checksum = sizeof(settings);
  57. settings.System = (const struct TSettingsSystem){ 0 };
  58. settings.Cache = *cache;
  59. EepromSetAll(&settings);
  60. }