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.

186 lines
4.7 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
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
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
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year 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. zaf_gpio_t m_fan0_power;
  35. zaf_gpio_t m_fan1_power;
  36. zaf_gpio_t m_fan0_state;
  37. zaf_gpio_t m_fan1_state;
  38. static uint32_t m_fan0_cnt;
  39. static uint32_t m_fan1_cnt;
  40. extern "C" {
  41. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
  42. if (GPIO_Pin == m_fan0_state.pin) {
  43. m_fan0_cnt++;
  44. }
  45. else if (GPIO_Pin == m_fan1_state.pin) {
  46. m_fan1_cnt++;
  47. }
  48. }
  49. }
  50. void debug_light_ctrl() {
  51. static uint32_t lastcall = 0;
  52. static bool light_status = false;
  53. if (zaf_has_passedms(lastcall) > 100) {
  54. light_status = !light_status;
  55. zaf_gpio_write(&m_debug_led, light_status);
  56. lastcall = zaf_get_ticket();
  57. }
  58. }
  59. void factory_reset_key_detect() {
  60. static uint32_t reset_key_trigger_tp = 0;
  61. static bool reset_key_triggered = false;
  62. if (!reset_key_triggered) {
  63. if (zaf_gpio_read(&m_factory_reset_key)) {
  64. reset_key_trigger_tp = zaf_get_ticket();
  65. reset_key_triggered = true;
  66. }
  67. }
  68. if (reset_key_triggered) {
  69. if (!zaf_gpio_read(&m_factory_reset_key)) {
  70. reset_key_triggered = false;
  71. } else {
  72. if (zaf_has_passedms(reset_key_trigger_tp) > 3000) {
  73. ZLOGI(TAG, "factory reset key triggered");
  74. config_factory_reset();
  75. // m_power_led
  76. while (zaf_gpio_read(&m_factory_reset_key)) {
  77. LightCtrlService_GreenLight_setState(false);
  78. osDelay(100);
  79. LightCtrlService_GreenLight_setState(true);
  80. osDelay(100);
  81. }
  82. ZLOGI(TAG, "system reset");
  83. NVIC_SystemReset();
  84. }
  85. }
  86. //
  87. }
  88. }
  89. void umain() {
  90. /**
  91. * @brief device_info init
  92. */
  93. sn_t sn;
  94. device_info_init();
  95. device_info_get_sn(&sn);
  96. ZLOGI(TAG, "%s:%d", PC_PROJECT_NAME, PC_VERSION);
  97. ZLOGI(TAG, "sn: %x:%x:%x", sn.sn0, sn.sn1, sn.sn2);
  98. LightCtrlService_init();
  99. LightCtrlService_GreenLight_setState(true);
  100. /**
  101. * @brief
  102. * 1. ʼָʾ
  103. * 2. ʼԴָʾ
  104. * 3. ʼλ
  105. */
  106. zaf_gpio_init_as_output(&m_debug_led, PC_DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
  107. if (FACTORY_RESET_KEY != PinNull) {
  108. zaf_gpio_init_as_input(&m_factory_reset_key, FACTORY_RESET_KEY, kxs_gpio_nopull, kxs_gpio_no_irq, true);
  109. }
  110. // m_power_led
  111. /**
  112. * @brief óʼ
  113. */
  114. config_init();
  115. /**
  116. * @brief ʼ
  117. */
  118. network_service_init();
  119. /**
  120. * @brief fpga_interface init
  121. */
  122. fpga_if_init();
  123. /**
  124. * @brief reg_manager init
  125. */
  126. reg_manager_init();
  127. /**
  128. * @brief extern_if_service init
  129. *
  130. * ⲿָ
  131. */
  132. osDelay(10);
  133. config_t* config = config_get();
  134. for (uint32_t i = 0; i < ZARRAY_SIZE(config->reg_config_storage); i++) {
  135. if (config->reg_config_storage[i].add == 0) {
  136. break;
  137. }
  138. ZLOGI(TAG, "init reg [0x%x] [0x%x]", config->reg_config_storage[i].add, config->reg_config_storage[i].val);
  139. fpga_if_spi_write_data(config->reg_config_storage[i].add, config->reg_config_storage[i].val, NULL);
  140. }
  141. extern_if_service_init();
  142. zaf_gpio_init_as_output(&m_fan0_power, PD0, kxs_gpio_pullup, false, true);
  143. zaf_gpio_init_as_output(&m_fan1_power, PD1, kxs_gpio_pullup, false, true);
  144. zaf_gpio_init_as_input(&m_fan0_state, PD5, kxs_gpio_pullup, kxs_gpio_rising_irq, false);
  145. zaf_gpio_init_as_input(&m_fan1_state, PD6, kxs_gpio_pullup, kxs_gpio_rising_irq, false);
  146. ZLOGI(TAG, "system init done");
  147. int32_t count = 0;
  148. while (true) {
  149. osDelay(10);
  150. count++;
  151. debug_light_ctrl();
  152. if (FACTORY_RESET_KEY != PinNull) {
  153. factory_reset_key_detect();
  154. }
  155. if (count % 100 == 0) {
  156. ZLOGI(TAG, "fan0:%d, fan1:%d", m_fan0_cnt, m_fan1_cnt);
  157. }
  158. }
  159. }