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.

146 lines
3.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
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. #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/device_info.hpp"
  7. #include "service/extern_if_service.h"
  8. #include "service/network_service.h"
  9. #include "service/reg_manager.h"
  10. #include "service/report_generator_service.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 |
  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) { report_generator_service_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) > 100) {
  44. light_status = !light_status;
  45. xs_gpio_write(&m_debug_led, light_status);
  46. lastcall = xs_get_ticket();
  47. }
  48. }
  49. void factory_reset_key_detect() {
  50. static uint32_t reset_key_trigger_tp = 0;
  51. static bool reset_key_triggered = false;
  52. if (!reset_key_triggered) {
  53. if (xs_gpio_read(&m_factory_reset_key)) {
  54. reset_key_trigger_tp = xs_get_ticket();
  55. reset_key_triggered = true;
  56. }
  57. }
  58. if (reset_key_triggered) {
  59. if (!xs_gpio_read(&m_factory_reset_key)) {
  60. reset_key_triggered = false;
  61. } else {
  62. if (xs_has_passedms(reset_key_trigger_tp) > 3000) {
  63. ZLOGI(TAG, "factory reset key triggered");
  64. config_factory_reset();
  65. // m_power_led
  66. while (xs_gpio_read(&m_factory_reset_key)) {
  67. xs_gpio_write(&m_power_led, false);
  68. osDelay(100);
  69. xs_gpio_write(&m_power_led, true);
  70. osDelay(100);
  71. }
  72. ZLOGI(TAG, "system reset");
  73. NVIC_SystemReset();
  74. }
  75. }
  76. //
  77. }
  78. }
  79. void umain() {
  80. /**
  81. * @brief device_info init
  82. */
  83. sn_t sn;
  84. device_info_init();
  85. device_info_get_sn(&sn);
  86. XS_LOGI(TAG, "%s:%d", PC_PROJECT_NAME, PC_VERSION);
  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_nopull, 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. report_generator_service_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. ZLOGI(TAG, "system init done");
  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. }
  133. }