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.

166 lines
4.8 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
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
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) > 100) {
  43. light_status = !light_status;
  44. xs_gpio_write(&m_debug_led, light_status);
  45. lastcall = xs_get_ticket();
  46. }
  47. }
  48. void factory_reset_key_detect() {
  49. static uint32_t reset_key_trigger_tp = 0;
  50. static bool reset_key_triggered = false;
  51. if (!reset_key_triggered) {
  52. if (xs_gpio_read(&m_factory_reset_key)) {
  53. reset_key_trigger_tp = xs_get_ticket();
  54. reset_key_triggered = true;
  55. }
  56. }
  57. if (reset_key_triggered) {
  58. if (!xs_gpio_read(&m_factory_reset_key)) {
  59. reset_key_triggered = false;
  60. } else {
  61. if (xs_has_passedms(reset_key_trigger_tp) > 3000) {
  62. ZLOGI(TAG, "factory reset key triggered");
  63. config_factory_reset();
  64. // m_power_led
  65. while (xs_gpio_read(&m_factory_reset_key)) {
  66. xs_gpio_write(&m_power_led, false);
  67. osDelay(100);
  68. xs_gpio_write(&m_power_led, true);
  69. osDelay(100);
  70. }
  71. ZLOGI(TAG, "system reset");
  72. NVIC_SystemReset();
  73. }
  74. }
  75. //
  76. }
  77. }
  78. void umain() {
  79. XS_LOGI(TAG, "%s:%d", PC_PROJECT_NAME, PC_VERSION);
  80. XS_LOGI(TAG, "sn: %02d%02d%04d", xs_device_info_get()->year, xs_device_info_get()->weak, xs_device_info_get()->index);
  81. // XS_LOGI(TAG, "sn: %x:%x:%x", sn.sn0, sn.sn1, sn.sn2);
  82. /**
  83. * @brief
  84. * 1. ʼָʾ
  85. * 2. ʼԴָʾ
  86. * 3. ʼλ
  87. */
  88. xs_gpio_init_as_output(&m_debug_led, PC_DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
  89. xs_gpio_init_as_output(&m_power_led, POWER_LED_PIN, kxs_gpio_nopull, false, true);
  90. xs_gpio_init_as_input(&m_factory_reset_key, FACTORY_RESET_KEY, kxs_gpio_nopull, kxs_gpio_no_irq, true);
  91. // m_power_led
  92. /**
  93. * @brief óʼ
  94. */
  95. config_init();
  96. /**
  97. * @brief ʼ
  98. */
  99. network_service_init();
  100. /**
  101. * @brief fpga_interface init
  102. */
  103. fpga_if_init();
  104. /**
  105. * @brief report_generator init
  106. */
  107. ReportGeneratorService_init(fpga_if_get_instance()->timecode_irq_pin, fpga_if_get_instance()->camera_sync_code_irq_pin);
  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. // HAL_SPI_Transmit(&hspi1, (uint8_t*)"hello", 5, 1000);
  123. // HAL_SPI_Transmit(&hspi2, (uint8_t*)"hello", 5, 1000);
  124. osDelay(10);
  125. debug_light_ctrl();
  126. factory_reset_key_detect();
  127. // if (xs_has_passedms(0) >= * 60 * 60 * 1000) {
  128. // ���ƿͻ�ʹ��ʱ��
  129. // reset_pin_io
  130. // NVIC_SystemReset();
  131. // }
  132. // ZLOGI(TAG,"factory_reset_key_state %d",xs_gpio_read(&m_factory_reset_key));
  133. // osDelay(10);
  134. // fpga_if_spi_write_data_01(33, count, &rxdata);
  135. // osDelay(10);
  136. // fpga_if_spi_write_data_01(34, count, &rxdata);
  137. // osDelay(10);
  138. // fpga_if_spi_write_data_01(35, count, &rxdata);
  139. // osDelay(10);
  140. // fpga_if_spi_write_data_01(36, count, &rxdata);
  141. // osDelay(10);
  142. // if(count!=rxdata){
  143. // ZLOGI(TAG, "fpga_if_spi_write_data_01 error count: %d, rxdata: %d", count, rxdata);
  144. // }
  145. // count++;
  146. // ZLOGI(TAG, "fpga_if_init: %d", xs_gpio_read(&fpga_if_get_instance()->xsync_workstate_start_sig_irq_io));
  147. // ZLOGI(TAG, "rxdata: %x", rxdata);
  148. }
  149. }