app.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. void fetch_jtag_cmd(void) {
  21. foc_cmd_body_t foc_cmd;
  22. u8 cmd_data[32];
  23. if (jtag_cmd == 1 || jtag_cmd == 2) {
  24. foc_cmd.cmd = Foc_Start_Motor;
  25. foc_cmd.data = cmd_data;
  26. cmd_data[0] = jtag_cmd;
  27. foc_send_command(&foc_cmd);
  28. jtag_cmd = 0;
  29. }
  30. }
  31. #else
  32. void fetch_jtag_cmd(void){
  33. }
  34. #endif
  35. static void mc_exec_log(void) {
  36. 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);
  37. sys_debug("timeup intval = %d, err = %d\n\n", g_meas_timeup.intval_time, g_meas_timeup.intval_time_error);
  38. PMSM_FOC_LogDebug();
  39. }
  40. void app_start(void){
  41. set_log_level(MOD_SYSTEM, L_debug);
  42. can_message_init();
  43. restore_config();
  44. mc_init();
  45. shark_task_create(_app_low_task, NULL);
  46. sys_debug("mc start\n");
  47. shark_task_run();
  48. }
  49. static void _can_report_info(void) {
  50. //can_report_speed(0x45, PMSM_FOC_GetSpeed());
  51. }
  52. static u32 _app_low_task(void *args) {
  53. wdog_reload();
  54. _can_report_info();
  55. mc_exec_log();
  56. fetch_jtag_cmd();
  57. return 1000;
  58. }