app.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "app/app.h"
  2. #include "bsp/bsp.h"
  3. #include "os/timer.h"
  4. #include "os/co_task.h"
  5. #include "libs/logger.h"
  6. #include "libs/utils.h"
  7. #include "prot/can_foc_msg.h"
  8. #include "prot/can_message.h"
  9. #include "foc/foc_api.h"
  10. #include "bsp/timer_count32.h"
  11. static void _app_low_task(void *args);
  12. extern measure_time_t g_meas_hall;
  13. extern measure_time_t g_meas_foc;
  14. void app_start(void){
  15. set_log_level(MOD_SYSTEM, L_debug);
  16. can_message_init();
  17. foc_init();
  18. co_task_create(_app_low_task, NULL, 512);
  19. co_task_schedule();
  20. }
  21. static void _can_report_info(void) {
  22. can_report_speed(0x45, foc_get_speed());
  23. current_samp_t *s = foc_get_current_sample();
  24. can_report_phase_current(0x45, F2I(s->Ia * 1000), F2I(s->Ib * 1000), F2I(s->Ic * 1000));
  25. }
  26. static void _app_low_task(void *args) {
  27. while(1) {
  28. wdog_reload();
  29. _can_report_info();
  30. sys_debug("foc exec time %d, intval %d, max %d, error %d\n", g_meas_foc.exec_time, g_meas_foc.intval_time, g_meas_foc.exec_max_error_time, g_meas_foc.intval_time_error);
  31. //sys_debug("hall exec time %d, intval %d\n", g_meas_hall.exec_time, g_meas_hall.intval_time);
  32. co_task_delay(500);
  33. }
  34. }