soft_system.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "hard_system.h"
  2. #include "soft_system.h"
  3. #include "test.h"
  4. void system_reset(void)
  5. {
  6. sys_reset();
  7. }
  8. void close_imu_dma(void)
  9. {
  10. u3_dma_disable(); // 实际dma通道未使用 使用串口fifo中断替代了 实在要用dma 需要触发io物理接在串口接收io 消耗定时器的2路通道 软件模拟空闲中断
  11. }
  12. #ifdef SOFT_SYSTEM_TEST
  13. //============================================================================
  14. // 测试函数
  15. //============================================================================
  16. /**
  17. * @brief 测试系统复位功能
  18. * @note 此函数会触发系统复位,执行后程序会重启
  19. */
  20. void test_system_reset(void)
  21. {
  22. printf("\n=== Test: System Reset ===\n");
  23. printf("System will reset in 3 seconds...\n");
  24. printf("Press any key to cancel, or wait for reset\n");
  25. // 延时等待,让用户有机会看到消息
  26. for (int i = 3; i > 0; i--) {
  27. printf(" %d...\n", i);
  28. for (volatile int j = 0; j < 1000000; j++); // 简单延时
  29. }
  30. printf("Resetting system now...\n");
  31. system_reset();
  32. // 正常情况下不会执行到这里
  33. printf("[FAIL] System reset failed\n");
  34. }
  35. /**
  36. * @brief 测试关闭IMU DMA功能
  37. */
  38. void test_close_imu_dma(void)
  39. {
  40. printf("\n=== Test: Close IMU DMA ===\n");
  41. printf("Calling close_imu_dma()...\n");
  42. close_imu_dma();
  43. printf("IMU DMA disabled\n");
  44. printf("[PASS] Close IMU DMA test\n");
  45. }
  46. /**
  47. * @brief 模拟测试(不实际复位,只打印信息)
  48. */
  49. void test_system_reset_simulate(void)
  50. {
  51. printf("\n=== Test: System Reset Simulation ===\n");
  52. printf("Simulating system reset (no actual reset)\n");
  53. printf(" - Saving system state...\n");
  54. printf(" - Flushing caches...\n");
  55. printf(" - Resetting peripherals...\n");
  56. printf(" - Restarting system...\n");
  57. printf("[PASS] Reset simulation (no actual reset)\n");
  58. }
  59. //============================================================================
  60. // 主测试函数
  61. //============================================================================
  62. /**
  63. * @brief 运行所有系统接口测试(不包含实际复位)
  64. */
  65. void run_system_test(void)
  66. {
  67. printf("\n");
  68. printf("========================================\n");
  69. printf(" System Interface Test Suite\n");
  70. printf("========================================\n");
  71. // 测试关闭DMA(不会影响系统运行)
  72. test_close_imu_dma();
  73. // 模拟复位测试(不实际复位)
  74. test_system_reset_simulate();
  75. printf("\n========================================\n");
  76. printf(" All tests completed\n");
  77. printf("========================================\n");
  78. }
  79. /**
  80. * @brief 运行包含实际复位的测试(谨慎使用)
  81. * @param delay_seconds 复位前延时秒数
  82. */
  83. void run_system_test_with_reset(uint32_t delay_seconds)
  84. {
  85. printf("\n");
  86. printf("========================================\n");
  87. printf(" System Interface Test (with Reset)\n");
  88. printf("========================================\n");
  89. test_close_imu_dma();
  90. printf("\n");
  91. printf("!!! WARNING: System will reset !!!\n");
  92. printf("Delay: %u seconds\n", delay_seconds);
  93. if (delay_seconds > 0) {
  94. for (uint32_t i = delay_seconds; i > 0; i--) {
  95. printf(" %u...\n", i);
  96. for (volatile uint32_t j = 0; j < 1000000; j++);
  97. }
  98. }
  99. test_system_reset();
  100. }
  101. //============================================================================
  102. // 菜单测试
  103. //============================================================================
  104. /**
  105. * @brief 交互式测试菜单
  106. */
  107. void run_system_test_menu(void)
  108. {
  109. printf("\n");
  110. printf("========================================\n");
  111. printf(" System Test Menu\n");
  112. printf("========================================\n");
  113. printf("1 - Test close_imu_dma()\n");
  114. printf("2 - Test system_reset() simulate (no reset)\n");
  115. printf("3 - Test system_reset() with 3s delay (actual reset)\n");
  116. printf("4 - Run all safe tests\n");
  117. printf("q - Exit\n");
  118. printf("========================================\n");
  119. // 这里需要用户输入,如果没有输入处理,可以只打印菜单
  120. printf("Please select an option in your main loop\n");
  121. }
  122. //============================================================================
  123. // 快速测试
  124. //============================================================================
  125. /**
  126. * @brief 快速测试(仅测试安全接口)
  127. */
  128. void run_system_quick_test(void)
  129. {
  130. printf("\n=== Quick System Test ===\n");
  131. printf("Testing close_imu_dma()...\n");
  132. close_imu_dma();
  133. printf(" - IMU DMA closed\n");
  134. printf("\nSystem interfaces available:\n");
  135. printf(" - system_reset() : Reset the system\n");
  136. printf(" - close_imu_dma() : Disable IMU DMA\n");
  137. printf("\nQuick test completed\n");
  138. }
  139. #endif