app.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. log_start_task();
  19. co_task_create(_app_low_task, NULL, 512);
  20. co_task_schedule();
  21. }
  22. static void _can_report_info(void) {
  23. can_report_speed(0x45, foc_get_speed());
  24. current_samp_t *s = foc_get_current_sample();
  25. can_report_phase_current(0x45, F2I(s->Ia * 1000), F2I(s->Ib * 1000), F2I(s->Ic * 1000));
  26. //sys_debug("phase current %f %f %f\n", s->Ia, s->Ib, s->Ic);
  27. sys_debug("phase offset %d %d %d\n", s->adc_offset_a, s->adc_offset_b, s->adc_offset_c);
  28. }
  29. extern void hall_debug_log(void);
  30. static void _app_low_task(void *args) {
  31. while(1) {
  32. wdog_reload();
  33. _can_report_info();
  34. 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);
  35. //sys_debug("hall exec time %d, intval %d\n", g_meas_hall.exec_time, g_meas_hall.intval_time);
  36. //sys_debug("vbus voltage: %f\n", foc_get_vbus_voltage());
  37. //hall_debug_log();
  38. co_task_delay(1000);
  39. }
  40. }