api-hal-version.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <api-hal-version.h>
  2. #include <stm32wbxx.h>
  3. #include <stm32wbxx_ll_rtc.h>
  4. typedef struct {
  5. uint8_t version;
  6. uint8_t target;
  7. uint8_t body;
  8. uint8_t connect;
  9. uint32_t timestamp;
  10. char name[8];
  11. } ApiHalVersionOTP;
  12. bool api_hal_version_do_i_belong_here() {
  13. return api_hal_version_get_hw_target() == 5;
  14. }
  15. const uint8_t api_hal_version_get_hw_version() {
  16. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->version;
  17. }
  18. const uint8_t api_hal_version_get_hw_target() {
  19. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->target;
  20. }
  21. const uint8_t api_hal_version_get_hw_body() {
  22. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->body;
  23. }
  24. const uint8_t api_hal_version_get_hw_connect() {
  25. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->connect;
  26. }
  27. const uint32_t api_hal_version_get_hw_timestamp() {
  28. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
  29. }
  30. const char * api_hal_version_get_name_ptr() {
  31. char * name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
  32. return *name == 0xFFU ? NULL : name;
  33. }
  34. const struct Version* api_hal_version_get_fw_version(void) {
  35. return version_get();
  36. }
  37. const struct Version* api_hal_version_get_boot_version(void) {
  38. #ifdef NO_BOOTLOADER
  39. return 0;
  40. #else
  41. /* Backup register which points to structure in flash memory */
  42. return (const struct Version*) LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
  43. #endif
  44. }