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.

172 lines
4.9 KiB

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