main.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #if 0
  8. #include <stdio.h>
  9. #include "board.h"
  10. #include "test.h"
  11. #ifdef TEST_EN
  12. #include "bsp_V8M_YY_led.h"
  13. #include "bsp_V8M_YY_pwm.h"
  14. #include "bsp_V8M_YY_adc.h"
  15. #include "hard_system.h"
  16. #include "hard_system_time.h"
  17. #include "hard_system_delay.h"
  18. #include "hard_system_timer.h"
  19. #include "hard_imu_uart3.h"
  20. #include "hard_rc_sbus.h"
  21. #include "hard_can.h"
  22. #include "hard_sbus_out.h"
  23. #include "hard_flash_gd25q16.h"
  24. #include "drv_usart.h"
  25. #include "soft_sdcard.h"
  26. #include "bsp_V8M_flash.h"
  27. #include "soft_voltage.h"
  28. #include "main.h"
  29. #include "hpm_math.h"
  30. #endif
  31. /*
  32. 1 手册:中断源优先级,有效值为 0 到 7。
  33. 2 注意:内存缓存问题 catch
  34. 如果DMA要访问​ → 必须用非缓存宏
  35. 如果多核要共享​ → 必须用非缓存宏
  36. 如果频繁被中断更新​ → 建议用非缓存宏
  37. 其他情况​ → 不用修饰,让编译器优化
  38. 3 注意配置顺序 IO-时钟-外设
  39. 4 XDMA,作为主设备连接到 AXI 系统总线 HDMA,作为主设备连接到 AHB 外设总线
  40. 当 XDMA 的 destination 为 DRAM 时,如果 burst 大于等于 16,那 destsize 必须为 64bit。
  41. DMAMUX 的输出 0∼7 连接到外设总线 DMA 控制器 HDMA,DMAMUX 的输出 8∼15 连接到系统总线 DMA 控制器 XDMA
  42. 它们都连接在统一的 DMAMUX(DMA 多路复用器)
  43. DMAMUX将所有外设的 DMA 请求(Request)统一管理,然后根据你的配置分配给 HDMA 或 XDMA 的任意空闲通道
  44. 5 注意cfg文件和一些前置的工程配置文件,可能导致编译出错 运行出错 仿真不了 重点:链接文件、yaml、板级cfg文件
  45. */
  46. uint64_t delta_time;
  47. #define PI (3.1415926f)
  48. void start_time(void)
  49. {
  50. delta_time = hpm_csr_get_core_mcycle();
  51. }
  52. uint32_t get_end_time(void)
  53. {
  54. delta_time = hpm_csr_get_core_mcycle() - delta_time;
  55. return delta_time;
  56. }
  57. float theta ;
  58. float sin_theta;
  59. #ifdef TEST_EN
  60. static void test_hard(void)
  61. {
  62. // v8m_yy_led_test();
  63. // v8m_yy_motor_pwm_test();
  64. // v8m_yy_adc_test();
  65. // timer0_test();
  66. // cpu_delay_test();
  67. // timer1_test();
  68. can2_test();
  69. // imu_uart3_test();
  70. // uart2_sbus_test();
  71. // system_test();
  72. // sbus_uart2_out_test();
  73. // test_gd25q16_quick();
  74. // sd_test_demo();
  75. // run_flash_tests();
  76. // run_time_test();
  77. // run_system_test_with_reset(100);
  78. // soft_vol_test();
  79. while(1)
  80. {
  81. theta += PI*0.1;
  82. sin_theta = hpm_dsp_sin_f32(theta);
  83. //uart_test_main(0);
  84. board_delay_ms(200);
  85. //printf("sin theta is %f\r\n", sin_theta);
  86. }
  87. }
  88. #endif
  89. int main(void)
  90. {
  91. board_init();
  92. float i = 9.8f;
  93. sin_theta = hpm_dsp_sin_f32(theta);
  94. //printf("hello world %f\n", i);
  95. //printf("sin theta is %f\r\n", sin_theta);
  96. #ifdef TEST_EN
  97. test_hard();
  98. #endif
  99. return 0;
  100. }
  101. // DMA 最大4k
  102. #endif
  103. #if 1
  104. #include "main.h"
  105. #include "auto_pilot.h"
  106. #include "data_save.h"
  107. #include "params.h"
  108. #include "pilot_init.h"
  109. #include "soft_can.h"
  110. #include "soft_flash.h"
  111. #include "soft_gs.h"
  112. #include "soft_imu.h"
  113. #include "soft_port_uart4.h"
  114. #include "soft_rc_input.h"
  115. #include "soft_time.h"
  116. #include "soft_timer.h"
  117. #include "ver_config.h"
  118. // while 正常循环不带写FLASH需要
  119. int main(void)
  120. {
  121. // 自驾仪初始化,耗时2.8s
  122. auto_pilot_init();
  123. while (1)
  124. {
  125. // 解析导航数据
  126. get_right_ins_data();
  127. // 主要控制循环
  128. pilot_main_loop();
  129. // 控制参数写入flash
  130. write_par_to_flash();
  131. // 数据传向地面站
  132. gs_receive_msg_poll(&gcs_link);
  133. // 解析地面站的消息
  134. gs_send_msg_poll(&gcs_link);
  135. // 解析can总线的消息
  136. CanTxRxServicePoll();
  137. // 解析载荷串口的消息数据
  138. // 发送数据给IMU
  139. send_msg_to_imu();
  140. #ifdef REC_DATA_POS
  141. data_record_service();
  142. #endif
  143. // 串口 4 服务函数
  144. Port4_Service();
  145. } // while
  146. } // main
  147. #endif
  148. //------------------End of File----------------------------