ble_glue.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef enum {
  8. BleGlueC2ModeUnknown = 0,
  9. BleGlueC2ModeFUS,
  10. BleGlueC2ModeStack,
  11. } BleGlueC2Mode;
  12. #define BLE_GLUE_MAX_VERSION_STRING_LEN 20
  13. typedef struct {
  14. BleGlueC2Mode mode;
  15. /**
  16. * Wireless Info
  17. */
  18. uint8_t VersionMajor;
  19. uint8_t VersionMinor;
  20. uint8_t VersionSub;
  21. uint8_t VersionBranch;
  22. uint8_t VersionReleaseType;
  23. uint8_t MemorySizeSram2B; /*< Multiple of 1K */
  24. uint8_t MemorySizeSram2A; /*< Multiple of 1K */
  25. uint8_t MemorySizeSram1; /*< Multiple of 1K */
  26. uint8_t MemorySizeFlash; /*< Multiple of 4K */
  27. uint8_t StackType;
  28. char StackTypeString[BLE_GLUE_MAX_VERSION_STRING_LEN];
  29. /**
  30. * Fus Info
  31. */
  32. uint8_t FusVersionMajor;
  33. uint8_t FusVersionMinor;
  34. uint8_t FusVersionSub;
  35. uint8_t FusMemorySizeSram2B; /*< Multiple of 1K */
  36. uint8_t FusMemorySizeSram2A; /*< Multiple of 1K */
  37. uint8_t FusMemorySizeFlash; /*< Multiple of 4K */
  38. } BleGlueC2Info;
  39. typedef enum {
  40. // Stage 1: core2 startup and FUS
  41. BleGlueStatusStartup,
  42. BleGlueStatusBroken,
  43. BleGlueStatusC2Started,
  44. // Stage 2: radio stack
  45. BleGlueStatusRadioStackRunning,
  46. BleGlueStatusRadioStackMissing
  47. } BleGlueStatus;
  48. typedef void (
  49. *BleGlueKeyStorageChangedCallback)(uint8_t* change_addr_start, uint16_t size, void* context);
  50. /** Initialize start core2 and initialize transport */
  51. void ble_glue_init();
  52. /** Start Core2 Radio stack
  53. *
  54. * @return true on success
  55. */
  56. bool ble_glue_start();
  57. /** Is core2 alive and at least FUS is running
  58. *
  59. * @return true if core2 is alive
  60. */
  61. bool ble_glue_is_alive();
  62. /** Waits for C2 to reports its mode to callback
  63. *
  64. * @return true if it reported before reaching timeout
  65. */
  66. bool ble_glue_wait_for_c2_start(int32_t timeout);
  67. BleGlueStatus ble_glue_get_c2_status();
  68. const BleGlueC2Info* ble_glue_get_c2_info();
  69. /** Is core2 radio stack present and ready
  70. *
  71. * @return true if present and ready
  72. */
  73. bool ble_glue_is_radio_stack_ready();
  74. /** Set callback for NVM in RAM changes
  75. *
  76. * @param[in] callback The callback to call on NVM change
  77. * @param context The context for callback
  78. */
  79. void ble_glue_set_key_storage_changed_callback(
  80. BleGlueKeyStorageChangedCallback callback,
  81. void* context);
  82. /** Stop SHCI thread */
  83. void ble_glue_thread_stop();
  84. bool ble_glue_reinit_c2();
  85. typedef enum {
  86. BleGlueCommandResultUnknown,
  87. BleGlueCommandResultOK,
  88. BleGlueCommandResultError,
  89. BleGlueCommandResultRestartPending,
  90. BleGlueCommandResultOperationOngoing,
  91. } BleGlueCommandResult;
  92. /** Restart MCU to launch radio stack firmware if necessary
  93. *
  94. * @return true on radio stack start command
  95. */
  96. BleGlueCommandResult ble_glue_force_c2_mode(BleGlueC2Mode mode);
  97. BleGlueCommandResult ble_glue_fus_stack_delete();
  98. BleGlueCommandResult ble_glue_fus_stack_install(uint32_t src_addr, uint32_t dst_addr);
  99. BleGlueCommandResult ble_glue_fus_get_status();
  100. BleGlueCommandResult ble_glue_fus_wait_operation();
  101. #ifdef __cplusplus
  102. }
  103. #endif