#ifndef __BSP_AT32_H__
#define __BSP_AT32_H__
#if defined AT32F413RCT7
#include "at32f413.h"
#endif
#define BIT(x)        ((uint32_t)((uint32_t)0x01U<<(x)))

#define SYSTEM_CLOCK (200000000u) //system clk 200M Hz
#define TIM_CLOCK (SYSTEM_CLOCK) /*SystemClock_Config��TIM1��clk��sys PLL �������̶�2����PLLƵ��*/
#define TIM_CLOCK_MHz (200u)
#define ADC_CLOCK (25000000u)
#define ADC_CLOCK_MHz (30u)
#define NS_PER_TCLK (5u) /* (1/120000000 * 1000000000) */
#define NS_2_TCLK(ns) (((ns)/NS_PER_TCLK) + 1u) //ns תΪpwmʹ�õ��Ǹ�TIM��clk count
#define FOC_PWM_FS (16000u)
#define FOC_PWM_period (TIM_CLOCK/FOC_PWM_FS)
#define FOC_PWM_Half_Period (FOC_PWM_period/2)

#define FOC_CTRL_US (1.0f/(float)FOC_PWM_FS)

#define ADC_TRIG_CONV_LATENCY_CYCLES 12.5f
#define ADC_SAMPLING_CYCLES 13.5f

#if defined (MC100_HW_V1)
#include "bsp/at32/board_mc100_v1.h"
#define CONFIG_BOARD_MCXXX
#define CONFIG_BOARD_NAME "MC100AT"
#define CONFIG_HW_VERSION 2
#elif defined (MC105_HW_V3)
#include "bsp/at32/board_at_mc105_v3.h"
#define CONFIG_BOARD_MCXXX
#define CONFIG_BOARD_NAME "MC105AT"
#define CONFIG_HW_VERSION 3
#endif
#endif /* __BSP_AT32_H__ */
