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.

194 lines
5.6 KiB

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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
11 months ago
9 months ago
11 months ago
9 months ago
11 months ago
9 months ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
9 months ago
2 years ago
9 months ago
9 months ago
2 years ago
9 months ago
9 months ago
2 years ago
11 months ago
2 years ago
11 months ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
11 months 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
9 months ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
11 months ago
1 year ago
2 years ago
2 years 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 "service/extern_if_service.h"
  7. #include "service/network_service.h"
  8. #include "service/reg_manager.h"
  9. #include "service/report_generator_service.h"
  10. //
  11. #include "iwdg.h"
  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 |
  27. * config_service ========================================
  28. * | report_generator | device_info |
  29. * =================== ==============
  30. * | fpage_if |
  31. * ========================================
  32. *
  33. */
  34. xs_gpio_t m_debug_led;
  35. xs_gpio_t m_factory_reset_key;
  36. xs_gpio_t m_power_led0;
  37. xs_gpio_t m_power_led1;
  38. xs_gpio_t m_power_led2;
  39. void power_light_init() {
  40. xs_gpio_init_as_output(&m_power_led0, PB6, kxs_gpio_nopull, true, false); // r
  41. xs_gpio_init_as_output(&m_power_led1, PB7, kxs_gpio_nopull, true, false); // g
  42. xs_gpio_init_as_output(&m_power_led2, PB8, kxs_gpio_nopull, true, false); // y
  43. }
  44. void power_light_ctrl(int green, int yellow) {
  45. xs_gpio_write(&m_power_led0, 0);
  46. xs_gpio_write(&m_power_led1, green);
  47. xs_gpio_write(&m_power_led2, yellow);
  48. }
  49. extern "C" {
  50. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { ReportGeneratorService_irq_trigger(GPIO_Pin); }
  51. }
  52. void debug_light_ctrl() {
  53. static uint32_t lastcall = 0;
  54. static bool light_status = false;
  55. if (xs_has_passedms(lastcall) > 200) {
  56. light_status = !light_status;
  57. xs_gpio_write(&m_debug_led, light_status);
  58. if (network_service_network_is_ready()) {
  59. power_light_ctrl(1,0);
  60. } else {
  61. power_light_ctrl(0,light_status);
  62. }
  63. lastcall = xs_get_ticket();
  64. }
  65. }
  66. void factory_reset_key_detect() {
  67. static uint32_t reset_key_trigger_tp = 0;
  68. static bool reset_key_triggered = false;
  69. if (!reset_key_triggered) {
  70. if (xs_gpio_read(&m_factory_reset_key)) {
  71. reset_key_trigger_tp = xs_get_ticket();
  72. reset_key_triggered = true;
  73. }
  74. }
  75. if (reset_key_triggered) {
  76. if (!xs_gpio_read(&m_factory_reset_key)) {
  77. reset_key_triggered = false;
  78. } else {
  79. if (xs_has_passedms(reset_key_trigger_tp) > 3000) {
  80. ZLOGI(TAG, "factory reset key triggered");
  81. config_factory_reset();
  82. // m_power_led
  83. while (xs_gpio_read(&m_factory_reset_key)) {
  84. power_light_ctrl(false,false);
  85. osDelay(1000);
  86. power_light_ctrl(true,false);
  87. osDelay(1000);
  88. }
  89. ZLOGI(TAG, "system reset");
  90. NVIC_SystemReset();
  91. }
  92. }
  93. //
  94. }
  95. }
  96. // PB6
  97. // PB7
  98. // PB8
  99. void umain() {
  100. XS_LOGI(TAG, "%s:%d-%d-%d", PC_PROJECT_NAME, VERSION_MAIN, VERSION_SUB, VERSION_FIX);
  101. XS_LOGI(TAG, "sn: %02d%02d%04d", xs_device_info_get()->year, xs_device_info_get()->weak, xs_device_info_get()->index);
  102. // XS_LOGI(TAG, "sn: %x:%x:%x", sn.sn0, sn.sn1, sn.sn2);
  103. /**
  104. * @brief
  105. * 1. ʼָʾ
  106. * 2. ʼԴָʾ
  107. * 3. ʼλ
  108. */
  109. xs_gpio_init_as_output(&m_debug_led, PC_DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
  110. // xs_gpio_init_as_output(&m_power_led, POWER_LED_PIN, kxs_gpio_nopull, false, true);
  111. power_light_init();
  112. xs_gpio_init_as_input(&m_factory_reset_key, FACTORY_RESET_KEY, kxs_gpio_pullup, kxs_gpio_no_irq, true);
  113. // m_power_led
  114. /**
  115. * @brief óʼ
  116. */
  117. config_init();
  118. /**
  119. * @brief ʼ
  120. */
  121. network_service_init();
  122. /**
  123. * @brief fpga_interface init
  124. */
  125. fpga_if_init();
  126. /**
  127. * @brief reg_manager init
  128. */
  129. reg_manager_init();
  130. /**
  131. * @brief extern_if_service init
  132. *
  133. * ⲿָ
  134. */
  135. osDelay(1000);
  136. extern_if_service_init();
  137. ReportGeneratorService_init(fpga_if_get_instance()->timecode_irq_pin, fpga_if_get_instance()->camera_sync_code_irq_pin);
  138. MX_IWDG_Init();
  139. ZLOGI(TAG, "system init done");
  140. int32_t count = 0;
  141. while (true) {
  142. // HAL_SPI_Transmit(&hspi1, (uint8_t*)"hello", 5, 1000);
  143. // HAL_SPI_Transmit(&hspi2, (uint8_t*)"hello", 5, 1000);
  144. osDelay(10);
  145. debug_light_ctrl();
  146. factory_reset_key_detect();
  147. network_service_schedule();
  148. HAL_IWDG_Refresh(&hiwdg);
  149. // uint32_t val;
  150. // fpga_if_spi_read_data_02(0x0020, &val);
  151. // ZLOGI(TAG, "fpga_if_spi_read_data_02 %x", val);
  152. // if (xs_has_passedms(0) >= * 60 * 60 * 1000) {
  153. // ���ƿͻ�ʹ��ʱ��
  154. // reset_pin_io
  155. // NVIC_SystemReset();
  156. // }
  157. // ZLOGI(TAG,"factory_reset_key_state %d",xs_gpio_read(&m_factory_reset_key));
  158. // osDelay(10);
  159. // fpga_if_spi_write_data_01(33, count, &rxdata);
  160. // osDelay(10);
  161. // fpga_if_spi_write_data_01(34, count, &rxdata);
  162. // osDelay(10);
  163. // fpga_if_spi_write_data_01(35, count, &rxdata);
  164. // osDelay(10);
  165. // fpga_if_spi_write_data_01(36, count, &rxdata);
  166. // osDelay(10);
  167. // if(count!=rxdata){
  168. // ZLOGI(TAG, "fpga_if_spi_write_data_01 error count: %d, rxdata: %d", count, rxdata);
  169. // }
  170. // count++;
  171. // ZLOGI(TAG, "fpga_if_init: %d", xs_gpio_read(&fpga_if_get_instance()->xsync_workstate_start_sig_irq_io));
  172. // ZLOGI(TAG, "rxdata: %x", rxdata);
  173. }
  174. }