Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

109 rindas
3.3 KiB

  1. #ifndef PLSR_PERSISTENCE_H
  2. #define PLSR_PERSISTENCE_H
  3. #include "plsr_address_map.h"
  4. #include <stdint.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /* HSD 检查点元数据位(随 HSD 记录一起掉电保存)。 */
  9. #define PLSR_HSD_META_POSITION_VALID (1UL << 0U)
  10. #define PLSR_HSD_META_LAST_BUSY (1UL << 1U)
  11. #define PLSR_HSD_META_REASON_MASK (0x0000003CUL)
  12. typedef struct
  13. {
  14. uint32_t metadata;
  15. uint16_t runtime[PLSR_HSD_RUNTIME_COUNT];
  16. uint16_t config[PLSR_HSD_CONFIG_COUNT];
  17. } PLSR_HSD_DATA;
  18. typedef struct
  19. {
  20. uint16_t config[PLSR_SFD_CONFIG_COUNT];
  21. } PLSR_SFD_DATA;
  22. typedef enum
  23. {
  24. PLSR_PERSISTENCE_OK = 0,
  25. PLSR_PERSISTENCE_DEFAULTED,
  26. PLSR_PERSISTENCE_INVALID_ARGUMENT,
  27. PLSR_PERSISTENCE_VERIFY_FAILED,
  28. PLSR_PERSISTENCE_NOT_IMPLEMENTED,
  29. PLSR_PERSISTENCE_ERASE_FAILED,
  30. PLSR_PERSISTENCE_PROGRAM_FAILED
  31. } PLSR_PERSISTENCE_RESULT;
  32. /* Cached persistence health snapshot. Slot CRCs are evaluated only by
  33. * load/save/erase/diagnostic operations; reading this structure never scans
  34. * Backup SRAM or Flash and is therefore safe in the 1 ms Modbus poll path. */
  35. typedef struct
  36. {
  37. uint8_t hsdValidMask;
  38. uint8_t sfdValidMask;
  39. uint8_t hsdNewestMask;
  40. uint8_t sfdNewestMask;
  41. uint8_t destructiveDiagnosticEnabled;
  42. PLSR_PERSISTENCE_RESULT lastHsdLoadResult;
  43. PLSR_PERSISTENCE_RESULT lastSfdLoadResult;
  44. PLSR_PERSISTENCE_RESULT lastHsdSaveResult;
  45. PLSR_PERSISTENCE_RESULT lastSfdSaveResult;
  46. PLSR_PERSISTENCE_RESULT lastSfdEraseResult;
  47. uint32_t hsdGeneration[2];
  48. uint32_t sfdGeneration[2];
  49. uint32_t hsdSaveCount;
  50. uint32_t sfdSaveCount;
  51. uint32_t selectedHsdCrc32;
  52. uint32_t selectedSfdCrc32;
  53. } PLSR_PERSISTENCE_DIAGNOSTICS;
  54. typedef enum
  55. {
  56. PLSR_PERSISTENCE_DIAG_TARGET_HSD = 1,
  57. PLSR_PERSISTENCE_DIAG_TARGET_SFD = 2
  58. } PLSR_PERSISTENCE_DIAG_TARGET;
  59. PLSR_PERSISTENCE_RESULT PlsrPersistenceLoadHsd(PLSR_HSD_DATA *data);
  60. PLSR_PERSISTENCE_RESULT PlsrPersistenceSaveHsd(const PLSR_HSD_DATA *data);
  61. void PlsrPersistenceResetHsd(void);
  62. PLSR_PERSISTENCE_RESULT PlsrPersistenceLoadSfd(PLSR_SFD_DATA *data);
  63. PLSR_PERSISTENCE_RESULT PlsrPersistenceSaveSfd(const PLSR_SFD_DATA *data);
  64. PLSR_PERSISTENCE_RESULT PlsrPersistenceEraseSfd(void);
  65. void PlsrPersistenceGetDiagnostics(PLSR_PERSISTENCE_DIAGNOSTICS *diagnostics);
  66. /* Deliberately unavailable in normal builds. A validation build may enable
  67. * it with PLSR_ENABLE_DESTRUCTIVE_PERSISTENCE_DIAG=1; the Modbus control layer
  68. * additionally requires a double-magic, sequence/inverse handshake and all
  69. * motion axes idle. This function only invalidates the newest committed slot
  70. * and never accepts a memory address. */
  71. PLSR_PERSISTENCE_RESULT PlsrPersistenceDiagnosticInvalidateNewest(
  72. PLSR_PERSISTENCE_DIAG_TARGET target);
  73. #ifdef PLSR_HOST_TEST
  74. typedef enum
  75. {
  76. PLSR_TEST_SFD_FAULT_NONE = 0,
  77. PLSR_TEST_SFD_FAULT_ERASE,
  78. PLSR_TEST_SFD_FAULT_PROGRAM,
  79. PLSR_TEST_SFD_FAULT_VERIFY,
  80. PLSR_TEST_SFD_FAULT_BEFORE_COMMIT
  81. } PLSR_TEST_SFD_FAULT;
  82. void PlsrPersistenceTestResetStorage(void);
  83. void PlsrPersistenceTestCorruptNewestHsd(void);
  84. void PlsrPersistenceTestCorruptNewestSfd(void);
  85. void PlsrPersistenceTestSetSfdFault(PLSR_TEST_SFD_FAULT fault);
  86. uint32_t PlsrPersistenceTestGetHsdSaveCount(void);
  87. uint32_t PlsrPersistenceTestCrc32(const uint8_t *data, uint32_t length);
  88. #endif
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* PLSR_PERSISTENCE_H */