You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.5 KiB

2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. //
  4. #include "base_service/base_service.h"
  5. #include "base_service/fpga_if.h"
  6. #include "base_service/light_ctrl_service.h"
  7. #include "service/device_info.hpp"
  8. #include "service/extern_if_service.h"
  9. #include "service/network_service.h"
  10. #include "service/reg_manager.h"
  11. //
  12. #define TAG "main"
  13. using namespace std;
  14. extern void umain();
  15. extern "C" {
  16. extern void MX_LWIP_Init(void);
  17. void StartDefaultTask(void const* argument) { umain(); }
  18. }
  19. /*******************************************************************************
  20. * MAIN *
  21. *******************************************************************************/
  22. /**
  23. * @brief
  24. * | extern_if_service |
  25. * ========================================
  26. * | reg_manager | device_info |
  27. * ========================================
  28. * | fpage_if |
  29. * =========================
  30. *
  31. */
  32. zaf_gpio_t m_debug_led;
  33. zaf_gpio_t m_factory_reset_key;
  34. extern "C" {
  35. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {}
  36. }
  37. void debug_light_ctrl() {
  38. static uint32_t lastcall = 0;
  39. static bool light_status = false;
  40. if (zaf_has_passedms(lastcall) > 100) {
  41. light_status = !light_status;
  42. zaf_gpio_write(&m_debug_led, light_status);
  43. lastcall = zaf_get_ticket();
  44. }
  45. }
  46. void factory_reset_key_detect() {
  47. static uint32_t reset_key_trigger_tp = 0;
  48. static bool reset_key_triggered = false;
  49. if (!reset_key_triggered) {
  50. if (zaf_gpio_read(&m_factory_reset_key)) {
  51. reset_key_trigger_tp = zaf_get_ticket();
  52. reset_key_triggered = true;
  53. }
  54. }
  55. if (reset_key_triggered) {
  56. if (!zaf_gpio_read(&m_factory_reset_key)) {
  57. reset_key_triggered = false;
  58. } else {
  59. if (zaf_has_passedms(reset_key_trigger_tp) > 3000) {
  60. ZLOGI(TAG, "factory reset key triggered");
  61. config_factory_reset();
  62. // m_power_led
  63. while (zaf_gpio_read(&m_factory_reset_key)) {
  64. LightCtrlService_GreenLight_setState(false);
  65. osDelay(100);
  66. LightCtrlService_GreenLight_setState(true);
  67. osDelay(100);
  68. }
  69. ZLOGI(TAG, "system reset");
  70. NVIC_SystemReset();
  71. }
  72. }
  73. //
  74. }
  75. }
  76. void umain() {
  77. /**
  78. * @brief device_info init
  79. */
  80. sn_t sn;
  81. device_info_init();
  82. device_info_get_sn(&sn);
  83. ZLOGI(TAG, "%s:%d", PC_PROJECT_NAME, PC_VERSION);
  84. ZLOGI(TAG, "sn: %x:%x:%x", sn.sn0, sn.sn1, sn.sn2);
  85. /**
  86. * @brief
  87. * 1. ʼָʾ
  88. * 2. ʼԴָʾ
  89. * 3. ʼλ
  90. */
  91. zaf_gpio_init_as_output(&m_debug_led, PC_DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
  92. if (FACTORY_RESET_KEY != PinNull) {
  93. zaf_gpio_init_as_input(&m_factory_reset_key, FACTORY_RESET_KEY, kxs_gpio_nopull, kxs_gpio_no_irq, true);
  94. }
  95. // m_power_led
  96. /**
  97. * @brief óʼ
  98. */
  99. config_init();
  100. /**
  101. * @brief ʼ
  102. */
  103. network_service_init();
  104. /**
  105. * @brief fpga_interface init
  106. */
  107. fpga_if_init();
  108. /**
  109. * @brief reg_manager init
  110. */
  111. reg_manager_init();
  112. /**
  113. * @brief extern_if_service init
  114. *
  115. * ⲿָ
  116. */
  117. osDelay(1000);
  118. extern_if_service_init();
  119. ZLOGI(TAG, "system init done");
  120. int32_t count = 0;
  121. while (true) {
  122. osDelay(10);
  123. debug_light_ctrl();
  124. if (FACTORY_RESET_KEY != PinNull) {
  125. factory_reset_key_detect();
  126. }
  127. }
  128. }