bsp.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef __BSP_H__
  2. #define __BSP_H__
  3. #if defined (GD32F30X_HD) || defined (GD32F30X_XD) || defined (GD32F30X_CL)
  4. #include "gd32f30x.h"
  5. #elif defined GD32E10x
  6. #include "gd32e10x.h"
  7. #endif
  8. #include "bsp/gpio.h"
  9. #include "bsp/gd32_bkp.h"
  10. #include "bsp/gd32_rtc.h"
  11. #include "bsp/can.h"
  12. #include "bsp/i2c.h"
  13. #include "bsp/fmc_flash.h"
  14. #include "bsp/can.h"
  15. //#define GD32_DEMO
  16. #define USER_ITMER_BRAKE 0
  17. #define SYSTEM_CLOCK (120000000u) //system clk 120M Hz
  18. #define TIM_CLOCK (SYSTEM_CLOCK) /*SystemClock_Config��TIM1��clk��sys PLL �������̶�2����PLLƵ��*/
  19. #define TIM_CLOCK_MHz (120u)
  20. #define ADC_CLOCK (30000000u)
  21. #define ADC_CLOCK_MHz (30u)
  22. #define NS_PER_TCLK (8u) /* (1/120000000 * 1000000000) */
  23. #define NS_2_TCLK(ns) (((ns)/NS_PER_TCLK) + 1u) //ns תΪpwmʹ�õ��Ǹ�TIM��clk count
  24. #define FOC_PWM_FS (16000u)
  25. #define FOC_PWM_period (TIM_CLOCK/FOC_PWM_FS)
  26. #define FOC_PWM_Half_Period (FOC_PWM_period/2)
  27. #define ADC_TRIG_CONV_LATENCY_CYCLES 12.5f
  28. #define ADC_SAMPLING_CYCLES 7.5f
  29. #ifdef GD32_DEMO
  30. #define TIMER_DT_NS 400U
  31. #define MOSDRV_DT_NS 400U
  32. #define HW_DEAD_TIME_NS (TIMER_DT_NS+MOSDRV_DT_NS)
  33. #define HW_RISE_TIME_NS 500u
  34. #define HW_NOISE_TIME_NS 500u
  35. #else
  36. #define HW_DEAD_TIME_NS 1200u
  37. #define HW_RISE_TIME_NS 500u
  38. #define HW_NOISE_TIME_NS 500u
  39. #endif
  40. #define TDead NS_2_TCLK(HW_DEAD_TIME_NS)/* ����ʱ�� */
  41. #define TRise NS_2_TCLK(HW_RISE_TIME_NS)/* MOS ����ʱ��*/
  42. #define TNoise NS_2_TCLK(HW_NOISE_TIME_NS)/* MOS��������Ŀ�������ʱ�� */
  43. #define TADC ((uint16_t)((ADC_TRIG_CONV_LATENCY_CYCLES + ADC_SAMPLING_CYCLES) * TIM_CLOCK_MHz) / ADC_CLOCK_MHz + 1u)/* ADC ����ʱ�� */
  44. #define TSampleMIN (TADC + TDead*2 + TRise) //采样需要的总时间
  45. #define TSampleBefore (TDead + TRise) //采样开始前需要等待的时间
  46. #define START_RAMP_DURATION (2000)//ms
  47. #define SPEED_SAMPLE_INVAL (100) //ת�Ѳɼ��ļ��,ms
  48. #define SPEED_RAMP_DURATION SPEED_SAMPLE_INVAL //�����ٶȵ�б��ʱ�䣬�ٶ�ƽ���������½�
  49. #define MAX_VBUS_VOLTAGE (54)
  50. #define ADC_REFERENCE_VOLTAGE (3.3F)
  51. #define MAX_CURRENT 50.0F
  52. #define pwm_timer TIMER0
  53. #define adc_timer TIMER1
  54. #define aux_timer TIMER2
  55. #define TIMER_UP_IRQ_PRIORITY 0
  56. #define ADC_IRQ_PRIORITY 1
  57. #define HALL_IRQ_PRIORITY 2
  58. #define THREE_SHUNTS_SAMPLE 1
  59. #define ONE_SHUNT_SAMPLE 2
  60. #define SHUNT_NUM THREE_SHUNTS_SAMPLE
  61. #define ENABLE_AUX_TIMER 1
  62. #define THROTTLE_LOW_VALUE 0.2f
  63. #define THROTTLE_MAX_VALUE 4.9f
  64. #define THROTTLE_MIN_RPM 10
  65. void bsp_init(void);
  66. void wdog_reload(void);
  67. void system_reboot(void);
  68. int wdog_set_timeout(int wdog_time);
  69. void systick_open(void);
  70. #endif /* __BSP_H__ */