| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #include "hard_system.h"
- #include "soft_system.h"
- #include "test.h"
- void system_reset(void)
- {
- sys_reset();
- }
- void close_imu_dma(void)
- {
- u3_dma_disable(); // 实际dma通道未使用 使用串口fifo中断替代了 实在要用dma 需要触发io物理接在串口接收io 消耗定时器的2路通道 软件模拟空闲中断
- }
- #ifdef SOFT_SYSTEM_TEST
- //============================================================================
- // 测试函数
- //============================================================================
- /**
- * @brief 测试系统复位功能
- * @note 此函数会触发系统复位,执行后程序会重启
- */
- void test_system_reset(void)
- {
- printf("\n=== Test: System Reset ===\n");
- printf("System will reset in 3 seconds...\n");
- printf("Press any key to cancel, or wait for reset\n");
-
- // 延时等待,让用户有机会看到消息
- for (int i = 3; i > 0; i--) {
- printf(" %d...\n", i);
- for (volatile int j = 0; j < 1000000; j++); // 简单延时
- }
-
- printf("Resetting system now...\n");
- system_reset();
-
- // 正常情况下不会执行到这里
- printf("[FAIL] System reset failed\n");
- }
- /**
- * @brief 测试关闭IMU DMA功能
- */
- void test_close_imu_dma(void)
- {
- printf("\n=== Test: Close IMU DMA ===\n");
-
- printf("Calling close_imu_dma()...\n");
- close_imu_dma();
- printf("IMU DMA disabled\n");
-
- printf("[PASS] Close IMU DMA test\n");
- }
- /**
- * @brief 模拟测试(不实际复位,只打印信息)
- */
- void test_system_reset_simulate(void)
- {
- printf("\n=== Test: System Reset Simulation ===\n");
- printf("Simulating system reset (no actual reset)\n");
- printf(" - Saving system state...\n");
- printf(" - Flushing caches...\n");
- printf(" - Resetting peripherals...\n");
- printf(" - Restarting system...\n");
-
- printf("[PASS] Reset simulation (no actual reset)\n");
- }
- //============================================================================
- // 主测试函数
- //============================================================================
- /**
- * @brief 运行所有系统接口测试(不包含实际复位)
- */
- void run_system_test(void)
- {
- printf("\n");
- printf("========================================\n");
- printf(" System Interface Test Suite\n");
- printf("========================================\n");
-
- // 测试关闭DMA(不会影响系统运行)
- test_close_imu_dma();
-
- // 模拟复位测试(不实际复位)
- test_system_reset_simulate();
-
- printf("\n========================================\n");
- printf(" All tests completed\n");
- printf("========================================\n");
- }
- /**
- * @brief 运行包含实际复位的测试(谨慎使用)
- * @param delay_seconds 复位前延时秒数
- */
- void run_system_test_with_reset(uint32_t delay_seconds)
- {
- printf("\n");
- printf("========================================\n");
- printf(" System Interface Test (with Reset)\n");
- printf("========================================\n");
-
- test_close_imu_dma();
-
- printf("\n");
- printf("!!! WARNING: System will reset !!!\n");
- printf("Delay: %u seconds\n", delay_seconds);
-
- if (delay_seconds > 0) {
- for (uint32_t i = delay_seconds; i > 0; i--) {
- printf(" %u...\n", i);
- for (volatile uint32_t j = 0; j < 1000000; j++);
- }
- }
-
- test_system_reset();
- }
- //============================================================================
- // 菜单测试
- //============================================================================
- /**
- * @brief 交互式测试菜单
- */
- void run_system_test_menu(void)
- {
- printf("\n");
- printf("========================================\n");
- printf(" System Test Menu\n");
- printf("========================================\n");
- printf("1 - Test close_imu_dma()\n");
- printf("2 - Test system_reset() simulate (no reset)\n");
- printf("3 - Test system_reset() with 3s delay (actual reset)\n");
- printf("4 - Run all safe tests\n");
- printf("q - Exit\n");
- printf("========================================\n");
-
- // 这里需要用户输入,如果没有输入处理,可以只打印菜单
- printf("Please select an option in your main loop\n");
- }
- //============================================================================
- // 快速测试
- //============================================================================
- /**
- * @brief 快速测试(仅测试安全接口)
- */
- void run_system_quick_test(void)
- {
- printf("\n=== Quick System Test ===\n");
-
- printf("Testing close_imu_dma()...\n");
- close_imu_dma();
- printf(" - IMU DMA closed\n");
-
- printf("\nSystem interfaces available:\n");
- printf(" - system_reset() : Reset the system\n");
- printf(" - close_imu_dma() : Disable IMU DMA\n");
-
- printf("\nQuick test completed\n");
- }
- #endif
|