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.

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