app.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "app/app.h"
  2. #include "bsp/bsp.h"
  3. #include "os/os_task.h"
  4. #include "libs/logger.h"
  5. #include "libs/utils.h"
  6. #include "foc/motor/motor.h"
  7. #include "foc/samples.h"
  8. #include "prot/can_foc_msg.h"
  9. #include "prot/can_message.h"
  10. #include "libs/time_measure.h"
  11. #include "app/nv_storage.h"
  12. #include "foc/commands.h"
  13. static u32 _app_low_task(void *args);
  14. extern void PMSM_FOC_LogDebug(void);
  15. extern measure_time_t g_meas_hall;
  16. extern measure_time_t g_meas_foc;
  17. extern measure_time_t g_meas_timeup;
  18. #ifdef JTAG_DEBUG
  19. int jtag_cmd = 0;
  20. int jtag_data = 0;
  21. void fetch_jtag_cmd(void) {
  22. foc_cmd_body_t foc_cmd;
  23. u8 cmd_data[32];
  24. if (jtag_cmd == 1 || jtag_cmd == 2) {
  25. foc_cmd.cmd = Foc_Start_Motor;
  26. foc_cmd.data = cmd_data;
  27. cmd_data[0] = jtag_cmd;
  28. foc_send_command(&foc_cmd);
  29. jtag_cmd = 0;
  30. }else if (jtag_cmd == 3) {
  31. PMSM_FOC_SetOpenVdq(0, S16Q5(jtag_data));
  32. jtag_cmd = 0;
  33. }else if (jtag_cmd == 4) {
  34. foc_cmd.cmd = Foc_Cali_Hall_Phase;
  35. foc_cmd.data = cmd_data;
  36. encode_s16(cmd_data, jtag_data);
  37. foc_send_command(&foc_cmd);
  38. jtag_cmd = 0;
  39. }
  40. }
  41. #else
  42. void fetch_jtag_cmd(void){
  43. }
  44. #endif
  45. static void mc_exec_log(void) {
  46. sys_debug("intval = %d, exec = %d, err = %d, %d, %d, count = %d\n", g_meas_foc.intval_time, g_meas_foc.exec_time, g_meas_foc.intval_time_error, g_meas_foc.intval_low_err, g_meas_foc.intval_hi_err, g_meas_foc.exec_count);
  47. sys_debug("timeup intval = %d, err = %d\n\n", g_meas_timeup.intval_time, g_meas_timeup.intval_time_error);
  48. PMSM_FOC_LogDebug();
  49. }
  50. void app_start(void){
  51. set_log_level(MOD_SYSTEM, L_debug);
  52. can_message_init();
  53. restore_config();
  54. mc_init();
  55. gpio_led1_enable(true);
  56. shark_task_create(_app_low_task, NULL);
  57. sys_debug("mc start\n");
  58. shark_task_run();
  59. }
  60. static void _can_report_info(void) {
  61. //can_report_speed(0x45, PMSM_FOC_GetSpeed());
  62. }
  63. static u32 _app_low_task(void *args) {
  64. wdog_reload();
  65. _can_report_info();
  66. mc_exec_log();
  67. fetch_jtag_cmd();
  68. return 1000;
  69. }