app.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 %f\n", s->Ia, s->Ib, s->Ic, s->max_Ia);
  27. //sys_debug("phase offset %d %d %d\n", s->adc_offset_a, s->adc_offset_b, s->adc_offset_c);
  28. s->max_Ia = 0.0f;
  29. }
  30. extern void hall_debug_log(void);
  31. static void _app_low_task(void *args) {
  32. sys_debug("reset src: 0x%x\n", gd32_get_reset_source());
  33. while(1) {
  34. wdog_reload();
  35. _can_report_info();
  36. ///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);
  37. //sys_debug("hall exec time %d, intval %d\n", g_meas_hall.exec_time, g_meas_hall.intval_time);
  38. //sys_debug("vbus voltage: %f\n", foc_get_vbus_voltage());
  39. //hall_debug_log();
  40. co_task_delay(1000);
  41. }
  42. }