bt.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /*******************************************************************************
  2. * Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
  3. *
  4. * This software is owned and published by:
  5. * Huada Semiconductor Co.,Ltd ("HDSC").
  6. *
  7. * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
  8. * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
  9. *
  10. * This software contains source code for use with HDSC
  11. * components. This software is licensed by HDSC to be adapted only
  12. * for use in systems utilizing HDSC components. HDSC shall not be
  13. * responsible for misuse or illegal use of this software for devices not
  14. * supported herein. HDSC is providing this software "AS IS" and will
  15. * not be responsible for issues arising from incorrect user implementation
  16. * of the software.
  17. *
  18. * Disclaimer:
  19. * HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
  20. * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
  21. * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
  22. * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
  23. * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
  24. * WARRANTY OF NONINFRINGEMENT.
  25. * HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
  26. * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
  27. * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
  28. * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
  29. * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
  30. * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
  31. * SAVINGS OR PROFITS,
  32. * EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  33. * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
  34. * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
  35. * FROM, THE SOFTWARE.
  36. *
  37. * This software may be replicated in part or whole for the licensed use,
  38. * with the restriction that this Disclaimer and Copyright notice must be
  39. * included with each copy of this software, whether used in part or whole,
  40. * at all times.
  41. */
  42. /******************************************************************************/
  43. /** \file bt.h
  44. **
  45. ** 基本定时器数据结构及API声明
  46. ** @link BT Group Some description @endlink
  47. **
  48. ** History:
  49. ** - 2018-04-18 Husj First Version
  50. **
  51. *****************************************************************************/
  52. #ifndef __BT_H__
  53. #define __BT_H__
  54. /*****************************************************************************
  55. * Include files
  56. *****************************************************************************/
  57. #include "ddl.h"
  58. #include "interrupts_hc32l136.h"
  59. #ifdef __cplusplus
  60. extern "C"
  61. {
  62. #endif
  63. /**
  64. ******************************************************************************
  65. ** \defgroup BtGroup Base Timer (BT)
  66. **
  67. ******************************************************************************/
  68. //@{
  69. /******************************************************************************/
  70. /* Global pre-processor symbols/macros ('#define') */
  71. /******************************************************************************/
  72. /******************************************************************************
  73. * Global type definitions
  74. ******************************************************************************/
  75. /**
  76. ******************************************************************************
  77. ** \brief 定时器选择数据类型重定义
  78. *****************************************************************************/
  79. typedef enum en_bt_unit
  80. {
  81. TIM0 = 0u, ///< Timer 0
  82. TIM1 = 1u, ///< Timer 1
  83. TIM2 = 2u, ///< Timer 2
  84. }en_bt_unit_t;
  85. /**
  86. ******************************************************************************
  87. ** \brief 工作模式选择数据类型重定义 (MODE)(模式0/1/23)
  88. *****************************************************************************/
  89. typedef enum en_bt_work_mode
  90. {
  91. BtWorkMode0 = 0u, ///< 定时器模式
  92. BtWorkMode1 = 1u, ///< PWC模式
  93. BtWorkMode2 = 2u, ///< 锯齿波模式
  94. BtWorkMode3 = 3u, ///< 三角波模式
  95. }en_bt_work_mode_t;
  96. /**
  97. ******************************************************************************
  98. ** \brief 极性控制数据类型重定义 (GATE_P)(模式0)
  99. *****************************************************************************/
  100. typedef enum en_bt_m0_gatep
  101. {
  102. BtGatePositive = 0u, ///< 高电平有效
  103. BtGateOpposite = 1u, ///< 低电平有效
  104. }en_bt_m0_gatep_t;
  105. /**
  106. ******************************************************************************
  107. ** \brief TIM 预除频选择 (PRS)(模式0/1/23)
  108. *****************************************************************************/
  109. typedef enum en_bt_cr_timclkdiv
  110. {
  111. BtPCLKDiv1 = 0u, ///< Div 1
  112. BtPCLKDiv2 = 1u, ///< Div 2
  113. BtPCLKDiv4 = 2u, ///< Div 4
  114. BtPCLKDiv8 = 3u, ///< Div 8
  115. BtPCLKDiv16 = 4u, ///< Div 16
  116. BtPCLKDiv32 = 5u, ///< Div 32
  117. BtPCLKDiv64 = 6u, ///< Div 64
  118. BtPCLKDiv256 = 7u, ///< Div 256
  119. }en_bt_cr_timclkdiv_t;
  120. /**
  121. ******************************************************************************
  122. ** \brief 计数/定时器功能选择数据类型重定义 (CT)(模式0/1/23)
  123. *****************************************************************************/
  124. typedef enum en_bt_cr_ct
  125. {
  126. BtTimer = 0u, ///< 定时器功能,计数时钟为内部PCLK
  127. BtCounter = 1u, ///< 计数器功能,计数时钟为外部ETR
  128. }en_bt_cr_ct_t;
  129. /**
  130. ******************************************************************************
  131. ** \brief 定时器工作模式数据类型重定义 (MD)(模式0)
  132. *****************************************************************************/
  133. typedef enum en_bt_m0cr_md
  134. {
  135. Bt32bitFreeMode = 0u, ///< 32位计数器/定时器
  136. Bt16bitArrMode = 1u, ///< 自动重载16位计数器/定时器
  137. }en_bt_m0cr_md_t;
  138. /**
  139. ******************************************************************************
  140. ** \brief BT0/BT1/BT2中断类型数据类型重定义(模式0/1/23)
  141. *****************************************************************************/
  142. typedef enum en_bt_irq_type
  143. {
  144. BtUevIrq = 0u, ///< 溢出/事件更新中断
  145. BtCA0Irq = 2u, ///< 捕获/比较中断A(仅模式1/23存在)
  146. BtCB0Irq = 5u, ///< 捕获/比较中断B(仅模式23存在)
  147. BtCA0E = 8u, ///< CH0A捕获数据丢失标志(仅模式23存在),不是中断
  148. BtCB0E = 11u, ///< CH0B捕获数据丢失标志(仅模式23存在),不是中断
  149. BtBkIrq = 14u, ///< 刹车中断(仅模式23存在)
  150. BtTrigIrq = 15u, ///< 触发中断(仅模式23存在)
  151. }en_bt_irq_type_t;
  152. /**
  153. ******************************************************************************
  154. ** \brief 测量开始结束数据类型重定义 (Edg1stEdg2nd)(模式1)
  155. *****************************************************************************/
  156. typedef enum en_bt_m1cr_Edge
  157. {
  158. BtPwcRiseToRise = 0u, ///< 上升沿到上升沿(周期)
  159. BtPwcFallToRise = 1u, ///< 下降沿到上升沿(低电平)
  160. BtPwcRiseToFall = 2u, ///< 上升沿到下降沿(高电平)
  161. BtPwcFallToFall = 3u, ///< 下降沿到下降沿(周期)
  162. }en_bt_m1cr_Edge_t;
  163. /**
  164. ******************************************************************************
  165. ** \brief PWC测量测试模式选择数据类型重定义 (Oneshot)(模式1)
  166. *****************************************************************************/
  167. typedef enum en_bt_m1cr_oneshot
  168. {
  169. BtPwcCycleDetect = 0u, ///< PWC循环测量
  170. BtPwcOneShotDetect = 1u, ///< PWC单次测量
  171. }en_bt_m1cr_oneshot_t;
  172. /**
  173. ******************************************************************************
  174. ** \brief PWC IA0选择数据类型重定义 (IA0S)(模式1)
  175. *****************************************************************************/
  176. typedef enum en_bt_m1_mscr_ia0s
  177. {
  178. BtIA0Input = 0u, ///< IAO输入
  179. BtXORInput = 1u, ///< IA0 ETR GATE XOR(TIM0/1/2)/IA0 IA1 IA2 XOR(TIM3)
  180. }en_bt_m1_mscr_ia0s_t;
  181. /**
  182. ******************************************************************************
  183. ** \brief PWC IB0选择数据类型重定义 (IA0S)(模式1)
  184. *****************************************************************************/
  185. typedef enum en_bt_m1_mscr_ib0s
  186. {
  187. BtIB0Input = 0u, ///< IBO输入
  188. BtTsInput = 1u, ///< 内部触发TS选择信号
  189. }en_bt_m1_mscr_ib0s_t;
  190. /**
  191. ******************************************************************************
  192. ** \brief 输出极性、输入相位 数据类型重定义 (CCPA0/CCPB0/ETP/BKP)(模式1/23)
  193. *****************************************************************************/
  194. typedef enum en_bt_port_polarity
  195. {
  196. BtPortPositive = 0u, ///< 正常输入输出
  197. BtPortOpposite = 1u, ///< 反向输入输出
  198. }en_bt_port_polarity_t;
  199. /**
  200. ******************************************************************************
  201. ** \brief 滤波选择数据类型重定义 (FLTET/FLTA0/FLAB0)(模式1/23)
  202. *****************************************************************************/
  203. typedef enum en_bt_flt
  204. {
  205. BtFltNone = 0u, ///< 无滤波
  206. BtFltPCLKCnt3 = 4u, ///< PCLK 3个连续有效
  207. BtFltPCLKDiv4Cnt3 = 5u, ///< PCLK/4 3个连续有效
  208. BtFltPCLKDiv16Cnt3 = 6u, ///< PCLK/16 3个连续有效
  209. BtFltPCLKDiv64Cnt3 = 7u, ///< PCLK/64 3个连续有效
  210. }en_bt_flt_t;
  211. /**
  212. ******************************************************************************
  213. ** \brief 通道比较控制 数据类型重定义 (OCMA/OCMB)(模式23)
  214. *****************************************************************************/
  215. typedef enum en_bt_m23_fltr_ocm
  216. {
  217. BtForceLow = 0u, ///< 强制为0
  218. BtForceHigh = 1u, ///< 强制为1
  219. BtCMPForceLow = 2u, ///< 比较匹配时强制为0
  220. BtCMPForceHigh = 3u, ///< 比较匹配时强制为1
  221. BtCMPInverse = 4u, ///< 比较匹配时翻转电平
  222. BtCMPOnePrdHigh = 5u, ///< 比较匹配时输出一个计数周期的高电平
  223. BtPWMMode1 = 6u, ///< 通道控制为PWM mode 1
  224. BtPWMMode2 = 7u, ///< 通道控制为PWM mode 2
  225. }en_bt_m23_fltr_ocm_t;
  226. /**
  227. ******************************************************************************
  228. ** \brief 主从模式TS数据类型重定义 (TS)(模式1/23)
  229. *****************************************************************************/
  230. typedef enum en_bt_mscr_ts
  231. {
  232. BtTs0ETR = 0u, ///< ETR外部输入滤波后的相位选择信号
  233. BtTs1TIM0TRGO = 1u, ///< Timer0的TRGO输出信号
  234. BtTs2TIM1TRGO = 2u, ///< Timer1的TRGO输出信号
  235. BtTs3TIM2TRGO = 3u, ///< Timer2的TRGO输出信号
  236. BtTs4TIM3TRGO = 4u, ///< Timer3的TRGO输出信号
  237. //BtTs5IA0ED = 5u, ///< 无效
  238. BtTs6IAFP = 6u, ///< CH0A 外部输输入滤波后的相位选择信号
  239. BtTs7IBFP = 7u, ///< CH0B 外部输输入滤波后的相位选择信
  240. }en_bt_mscr_ts_t;
  241. /**
  242. ******************************************************************************
  243. ** \brief PWM输出模式选择数据类型重定义 (COMP)(模式23)
  244. *****************************************************************************/
  245. typedef enum en_bt_m23cr_comp
  246. {
  247. BtIndependentPWM = 0u, ///< 独立PWM输出
  248. BtComplementaryPWM = 1u, ///< 互补PWM输出
  249. }en_bt_m23cr_comp_t;
  250. /**
  251. ******************************************************************************
  252. ** \brief 计数方向选择数据类型重定义 (DIR)(模式23)
  253. *****************************************************************************/
  254. typedef enum en_bt_m23cr_dir
  255. {
  256. BtCntUp = 0u, ///< 向上计数
  257. BtCntDown = 1u, ///< 向下计数
  258. }en_bt_m23cr_dir_t;
  259. /**
  260. ******************************************************************************
  261. ** \brief 计数方向选择数据类型重定义 (PWM2S)(模式23)
  262. *****************************************************************************/
  263. typedef enum en_bt_m23cr_pwm2s
  264. {
  265. BtDoublePointCmp = 0u, ///< 双点比较使能,使用CCRA,CCRB比较控制OCREFA输出
  266. BtSinglePointCmp = 1u, ///< 单点比较使能,使用CCRA比较控制OCREFA输出
  267. }en_bt_m23cr_pwm2s_t;
  268. /**
  269. ******************************************************************************
  270. ** \brief GATE在PWM互补模式下捕获或比较功能 选择数据类型重定义 (CSG)(模式23)
  271. *****************************************************************************/
  272. typedef enum en_bt_m23cr_csg
  273. {
  274. BtPWMCompGateCmpOut = 0u, ///< 在PWM互补模式下,Gate作为比较输出
  275. BtPWMCompGateCapIn = 1u, ///< 在PWM互补模式下,Gate作为捕获输入
  276. }en_bt_m23cr_csg_t;
  277. /**
  278. ******************************************************************************
  279. ** \brief 比较捕获寄存器 数据类型重定义 (CCR0A,CCR0B)(模式23)
  280. *****************************************************************************/
  281. typedef enum en_bt_m23_ccrx
  282. {
  283. BtCCR0A = 0u, ///< CCR0A比较捕获寄存器
  284. BtCCR0B = 1u, ///< CCR0B比较捕获寄存器
  285. }en_bt_m23_ccrx_t;
  286. /**
  287. ******************************************************************************
  288. ** \brief OCREF清除源 选择数据类型重定义 (OCCS)(模式23)
  289. *****************************************************************************/
  290. typedef enum en_bt_m23ce_occs
  291. {
  292. BtOC_Ref_Clr = 0u, ///< 来自VC的OC_Ref_Clr
  293. BtETRf = 1u, ///< 外部ETRf
  294. }en_bt_m23ce_occs_t;
  295. /**
  296. ******************************************************************************
  297. ** \brief 比较匹配中断模式 选择数据类型重定义 (CIS/CISB)(模式23)
  298. *****************************************************************************/
  299. typedef enum en_bt_m23_cisa_cisb
  300. {
  301. BtCmpIntNone = 0u, ///< 无比较匹配中断
  302. BtCmpIntRise = 1u, ///< 比较匹配上升沿中断
  303. BtCmpIntFall = 2u, ///< 比较匹配下降沿中断
  304. BtCmpIntRiseFall = 3u, ///< 比较匹配上升沿下降沿中断
  305. }en_bt_m23_cisa_cisb_t;
  306. /**
  307. ******************************************************************************
  308. ** \brief BT端口控制 - 刹车时CHx输出状态控制(BKSA/BKSB)(模式23)
  309. **
  310. ** \note
  311. ******************************************************************************/
  312. typedef enum en_bt_m23_crch0_bks
  313. {
  314. BtCHxBksHiZ = 0u, ///< 刹车使能时,CHx端口输出高阻态
  315. BtCHxBksNorm = 1u, ///< 刹车使能时,CHx端口正常输出
  316. BtCHxBksLow = 2u, ///< 刹车使能时,CHx端口输出低电平
  317. BtCHxBksHigh = 3u, ///< 刹车使能时,CHx端口输出高电平
  318. }en_bt_m23_crch0_bks_t;
  319. /**
  320. ******************************************************************************
  321. ** \brief BT端口控制 - CHx上升沿下降沿捕获(CRx/CFx)(模式23)
  322. **
  323. ** \note
  324. ******************************************************************************/
  325. typedef enum en_bt_m23_crch0_cfx_crx
  326. {
  327. BtCHxCapNone = 0u, ///< CHx通道捕获禁止
  328. BtCHxCapRise = 1u, ///< CHx通道上升沿捕获使能
  329. BtCHxCapFall = 2u, ///< CHx通道下降沿捕获使能
  330. BtCHxCapFallRise = 3u, ///< CHx通道上升沿下降沿捕获都使能
  331. }en_bt_m23_crch0_cfx_crx_t;
  332. /**
  333. ******************************************************************************
  334. ** \brief BT端口控制 - CHx比较捕获模式(CSA/CSB)(模式23)
  335. **
  336. ** \note
  337. ******************************************************************************/
  338. typedef enum en_bt_m23_crch0_csa_csb
  339. {
  340. BtCHxCmpMode = 0u, ///< CHx通道设置为比较模式
  341. BtCHxCapMode = 1u, ///< CHx通道设置为捕获模式
  342. }en_bt_m23_crch0_csa_csb_t;
  343. /**
  344. ******************************************************************************
  345. ** \brief 比较模式下 DMA比较触发选择 数据类型重定义 (CCDS)(模式23)
  346. *****************************************************************************/
  347. typedef enum en_bt_m23_mscr_ccds
  348. {
  349. BtCmpTrigDMA = 0u, ///< 比较匹配触发DMA
  350. BtUEVTrigDMA = 1u, ///< 事件更新代替比较匹配触发DMA
  351. }en_bt_m23_mscr_ccds_t;
  352. /**
  353. ******************************************************************************
  354. ** \brief 主从模式选择 数据类型重定义 (MSM)(模式23)
  355. *****************************************************************************/
  356. typedef enum en_bt_m23_mscr_msm
  357. {
  358. BtSlaveMode = 0u, ///< 从模式
  359. BtMasterMode = 1u, ///< 主模式
  360. }en_bt_m23_mscr_msm_t;
  361. /**
  362. ******************************************************************************
  363. ** \brief 触发主模式输出源 数据类型重定义 (MMS)(模式23)
  364. *****************************************************************************/
  365. typedef enum en_bt_m23_mscr_mms
  366. {
  367. BtMasterUG = 0u, ///< UG(软件更新)源
  368. BtMasterCTEN = 1u, ///< CTEN源
  369. BtMasterUEV = 2u, ///< UEV更新源
  370. BtMasterCMPSO = 3u, ///< 比较匹配选择输出源
  371. BtMasterOCA0Ref = 4u, ///< OCA0_Ref源
  372. BtMasterOCB0Ref = 5u, ///< OCB0_Ref源
  373. //BtMasterOCB0Ref = 6u,
  374. //BtMasterOCB0Ref = 7u,
  375. }en_bt_m23_mscr_mms_t;
  376. /**
  377. ******************************************************************************
  378. ** \brief 触发从模式选择 数据类型重定义 (SMS)(模式23)
  379. *****************************************************************************/
  380. typedef enum en_bt_m23_mscr_sms
  381. {
  382. BtSlaveIClk = 0u, ///< 使用内部时钟
  383. BtSlaveResetTIM = 1u, ///< 复位功能
  384. BtSlaveTrigMode = 2u, ///< 触发模式
  385. BtSlaveEClk = 3u, ///< 外部时钟模式
  386. BtSlaveCodeCnt1 = 4u, ///< 正交编码计数模式1
  387. BtSlaveCodeCnt2 = 5u, ///< 正交编码计数模式2
  388. BtSlaveCodeCnt3 = 6u, ///< 正交编码计数模式3
  389. BtSlaveGateCtrl = 7u, ///< 门控功能
  390. }en_bt_m23_mscr_sms_t;
  391. /**
  392. ******************************************************************************
  393. ** \brief 定时器运行控制数据类型重定义 (CTEN)
  394. *****************************************************************************/
  395. typedef enum en_bt_start
  396. {
  397. BtCTENDisable = 0u, ///< 停止
  398. BtCTENEnable = 1u, ///< 运行
  399. }en_bt_start_t;
  400. /**
  401. ******************************************************************************
  402. ** \brief BaseTimer mode0 配置结构体定义(模式0)
  403. *****************************************************************************/
  404. typedef struct stc_bt_mode0_config
  405. {
  406. en_bt_work_mode_t enWorkMode; ///< 工作模式设置
  407. en_bt_m0_gatep_t enGateP; ///< 门控极性控制
  408. boolean_t bEnGate; ///< 门控使能
  409. en_bt_cr_timclkdiv_t enPRS; ///< 预除频配置
  410. boolean_t bEnTog; ///< 翻转输出使能
  411. en_bt_cr_ct_t enCT; ///< 定时/计数功能选择
  412. en_bt_m0cr_md_t enCntMode; ///< 计数模式配置
  413. func_ptr_t pfnTim0Cb; ///< Timer0中断服务回调函数[void function(void)]
  414. func_ptr_t pfnTim1Cb; ///< Timer1中断服务回调函数[void function(void)]
  415. func_ptr_t pfnTim2Cb; ///< Timer2中断服务回调函数[void function(void)]
  416. }stc_bt_mode0_config_t;
  417. /**
  418. ******************************************************************************
  419. ** \brief BaseTimer mode1 配置结构体定义(模式1)
  420. *****************************************************************************/
  421. typedef struct stc_bt_mode1_config
  422. {
  423. en_bt_work_mode_t enWorkMode; ///< 工作模式设置
  424. en_bt_cr_timclkdiv_t enPRS; ///< 预除频配置
  425. en_bt_cr_ct_t enCT; ///< 定时/计数功能选择
  426. en_bt_m1cr_oneshot_t enOneShot; ///< 单次测量/循环测量选择
  427. func_ptr_t pfnTim0Cb; ///< Timer0中断服务回调函数[void function(void)]
  428. func_ptr_t pfnTim1Cb; ///< Timer1中断服务回调函数[void function(void)]
  429. func_ptr_t pfnTim2Cb; ///< Timer2中断服务回调函数[void function(void)]
  430. }stc_bt_mode1_config_t;
  431. /**
  432. ******************************************************************************
  433. ** \brief PWC输入配置结构体定义(模式1)
  434. *****************************************************************************/
  435. typedef struct stc_bt_pwc_input_config
  436. {
  437. en_bt_mscr_ts_t enTsSel; ///< 触发输入源选择
  438. en_bt_m1_mscr_ia0s_t enIA0Sel; ///< CHA0输入选择
  439. en_bt_m1_mscr_ib0s_t enIB0Sel; ///< CHB0输入选择
  440. en_bt_port_polarity_t enETRPhase; ///< ETR相位选择
  441. en_bt_flt_t enFltETR; ///< ETR滤波设置
  442. en_bt_flt_t enFltIA0; ///< CHA0滤波设置
  443. en_bt_flt_t enFltIB0; ///< CHB0滤波设置
  444. }stc_bt_pwc_input_config_t;
  445. /**
  446. ******************************************************************************
  447. ** \brief BaseTimer mode23 配置结构体定义(模式23)
  448. *****************************************************************************/
  449. typedef struct stc_bt_mode23_config
  450. {
  451. en_bt_work_mode_t enWorkMode; ///< 工作模式设置
  452. en_bt_m23cr_dir_t enCntDir; ///< 计数方向
  453. en_bt_cr_timclkdiv_t enPRS; ///< 时钟预除频配置
  454. en_bt_cr_ct_t enCT; ///< 定时/计数功能选择
  455. en_bt_m23cr_comp_t enPWMTypeSel; ///< PWM模式选择(独立/互补)
  456. en_bt_m23cr_pwm2s_t enPWM2sSel; ///< OCREFA双点比较功能选择
  457. boolean_t bOneShot; ///< 单次触发模式使能/禁止
  458. boolean_t bURSSel; ///< 更新源选择
  459. func_ptr_t pfnTim0Cb; ///< Timer0中断服务回调函数[void function(void)]
  460. func_ptr_t pfnTim1Cb; ///< Timer1中断服务回调函数[void function(void)]
  461. func_ptr_t pfnTim2Cb; ///< Timer2中断服务回调函数[void function(void)]
  462. }stc_bt_mode23_config_t;
  463. /**
  464. ******************************************************************************
  465. ** \brief GATE在PWM互补模式下捕获或比较功能 配置结构体定义(模式23)
  466. *****************************************************************************/
  467. typedef struct stc_bt_m23_gate_config
  468. {
  469. en_bt_m23cr_csg_t enGateFuncSel; ///< Gate比较、捕获功能选择
  470. boolean_t bGateRiseCap; ///< GATE作为捕获功能时,上沿捕获有效控制
  471. boolean_t bGateFallCap; ///< GATE作为捕获功能时,下沿捕获有效控制
  472. }stc_bt_m23_gate_config_t;
  473. /**
  474. ******************************************************************************
  475. ** \brief CHA/CHB通道比较控制 配置结构体定义(模式23)
  476. *****************************************************************************/
  477. typedef struct stc_bt_m23_compare_config
  478. {
  479. en_bt_m23_crch0_csa_csb_t enCh0ACmpCap; ///< CH0A比较/捕获功能选择
  480. en_bt_m23_fltr_ocm_t enCH0ACmpCtrl; ///< CH0A通道比较控制
  481. en_bt_port_polarity_t enCH0APolarity; ///< CH0A输出极性控制
  482. boolean_t bCh0ACmpBufEn; ///< 比较A缓存功能 使能/禁止
  483. en_bt_m23_cisa_cisb_t enCh0ACmpIntSel; ///< CHA比较匹配中断选择
  484. en_bt_m23_crch0_csa_csb_t enCh0BCmpCap; ///< CH0B比较/捕获功能选择
  485. en_bt_m23_fltr_ocm_t enCH0BCmpCtrl; ///< CH0B通道比较控制
  486. en_bt_port_polarity_t enCH0BPolarity; ///< CH0B输出极性控制
  487. boolean_t bCH0BCmpBufEn; ///< 比较B缓存功能 使能/禁止
  488. en_bt_m23_cisa_cisb_t enCH0BCmpIntSel; ///< CHB0比较匹配中断选择
  489. }stc_bt_m23_compare_config_t;
  490. /**
  491. ******************************************************************************
  492. ** \brief CHA/CHB通道捕获控制 配置结构体定义(模式23)
  493. *****************************************************************************/
  494. typedef struct stc_bt_m23_input_config
  495. {
  496. en_bt_m23_crch0_csa_csb_t enCh0ACmpCap; ///< CH0A比较/捕获功能选择
  497. en_bt_m23_crch0_cfx_crx_t enCH0ACapSel; ///< CH0A捕获边沿选择
  498. en_bt_flt_t enCH0AInFlt; ///< CH0A通道捕获滤波控制
  499. en_bt_port_polarity_t enCH0APolarity; ///< CH0A输入相位
  500. en_bt_m23_crch0_csa_csb_t enCh0BCmpCap; ///< CH0B比较/捕获功能选择
  501. en_bt_m23_crch0_cfx_crx_t enCH0BCapSel; ///< HC0B捕获边沿选择
  502. en_bt_flt_t enCH0BInFlt; ///< CH0B通道捕获滤波控制
  503. en_bt_port_polarity_t enCH0BPolarity; ///< CH0B输入相位
  504. }stc_bt_m23_input_config_t;
  505. /**
  506. ******************************************************************************
  507. ** \brief ETR输入相位滤波配置结构体定义(模式23)
  508. *****************************************************************************/
  509. typedef struct stc_bt_m23_etr_input_config
  510. {
  511. en_bt_port_polarity_t enETRPolarity; ///< ETR输入极性设置
  512. en_bt_flt_t enETRFlt; ///< ETR滤波设置
  513. }stc_bt_m23_etr_input_config_t;
  514. /**
  515. ******************************************************************************
  516. ** \brief 刹车BK输入相位滤波配置结构体定义(模式23)
  517. *****************************************************************************/
  518. typedef struct stc_bt_m23_bk_input_config
  519. {
  520. boolean_t bEnBrake; ///< 刹车使能
  521. boolean_t bEnVC0Brake; ///< 使能VC0刹车
  522. boolean_t bEnVC1Brake; ///< 使能VC1刹车
  523. boolean_t bEnSafetyBk; ///< 使能safety刹车
  524. boolean_t bEnBKSync; ///< TIM0/TIM1/TIM2刹车同步使能
  525. en_bt_m23_crch0_bks_t enBkCH0AStat; ///< 刹车时CHA端口状态设置
  526. en_bt_m23_crch0_bks_t enBkCH0BStat; ///< 刹车时CHB端口状态设置
  527. en_bt_port_polarity_t enBrakePolarity; ///< 刹车BK输入极性设置
  528. en_bt_flt_t enBrakeFlt; ///< 刹车BK滤波设置
  529. }stc_bt_m23_bk_input_config_t;
  530. /**
  531. ******************************************************************************
  532. ** \brief 死区功能配置结构体定义(模式23)
  533. *****************************************************************************/
  534. typedef struct stc_bt_m23_dt_config
  535. {
  536. boolean_t bEnDeadTime; ///< 刹车时CHA端口状态设置
  537. uint8_t u8DeadTimeValue; ///< 刹车时CHA端口状态设置
  538. }stc_bt_m23_dt_config_t;
  539. /**
  540. ******************************************************************************
  541. ** \brief 触发ADC配置结构体定义(模式23)
  542. *****************************************************************************/
  543. typedef struct stc_bt_m23_adc_trig_config
  544. {
  545. boolean_t bEnTrigADC; ///< 触发ADC全局控制
  546. boolean_t bEnUevTrigADC; ///< 事件更新触发ADC
  547. boolean_t bEnCH0ACmpTrigADC; ///< CH0A比较匹配触发ADC
  548. boolean_t bEnCH0BCmpTrigADC; ///< CH0B比较匹配触发ADC
  549. }stc_bt_m23_adc_trig_config_t;
  550. /**
  551. ******************************************************************************
  552. ** \brief DMA触发 配置结构体定义(模式23)
  553. *****************************************************************************/
  554. typedef struct stc_bt_m23_trig_dma_config
  555. {
  556. boolean_t bUevTrigDMA; ///< 更新 触发DMA使能
  557. boolean_t bTITrigDMA; ///< Trig 触发DMA功能
  558. boolean_t bCmpATrigDMA; ///< A捕获比较触发DMA使能
  559. boolean_t bCmpBTrigDMA; ///< B捕获比较触发DMA使能
  560. en_bt_m23_mscr_ccds_t enCmpUevTrigDMA; ///< 比较模式下DMA比较触发选择
  561. }stc_bt_m23_trig_dma_config_t;
  562. /**
  563. ******************************************************************************
  564. ** \brief 主从模式 配置结构体定义(模式23)
  565. *****************************************************************************/
  566. typedef struct stc_bt_m23_master_slave_config
  567. {
  568. en_bt_m23_mscr_msm_t enMasterSlaveSel; ///< 主从模式选择
  569. en_bt_m23_mscr_mms_t enMasterSrc; ///< 主模式触发源选择
  570. en_bt_m23_mscr_sms_t enSlaveModeSel; ///< 从模式选择
  571. en_bt_mscr_ts_t enTsSel; ///< 触发输入源选择
  572. }stc_bt_m23_master_slave_config_t;
  573. /**
  574. ******************************************************************************
  575. ** \brief OCREF清除功能 配置结构体定义(模式23)
  576. *****************************************************************************/
  577. typedef struct stc_bt_m23_OCREF_Clr_config
  578. {
  579. en_bt_m23ce_occs_t enOCRefClrSrcSel; ///< OCREF清除源选择
  580. boolean_t bVCClrEn; ///< 是否使能来自VC的OCREF_Clr
  581. }stc_bt_m23_OCREF_Clr_config_t;
  582. /******************************************************************************
  583. * Global variable declarations ('extern', definition in C source)
  584. *****************************************************************************/
  585. /******************************************************************************
  586. * Global function prototypes (definition in C source)
  587. *****************************************************************************/
  588. //中断相关函数
  589. //中断标志获取
  590. boolean_t Bt_GetIntFlag(en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
  591. //中断标志清除
  592. en_result_t Bt_ClearIntFlag(en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
  593. //所有中断标志清除
  594. en_result_t Bt_ClearAllIntFlag(en_bt_unit_t enUnit);
  595. //模式0中断使能
  596. en_result_t Bt_Mode0_EnableIrq(en_bt_unit_t enUnit);
  597. //模式1中断使能
  598. en_result_t Bt_Mode1_EnableIrq (en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
  599. //模式2中断使能
  600. en_result_t Bt_Mode23_EnableIrq (en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
  601. //模式0中断禁止
  602. en_result_t Bt_Mode0_DisableIrq(en_bt_unit_t enUnit);
  603. //模式1中断禁止
  604. en_result_t Bt_Mode1_DisableIrq (en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
  605. //模式2中断禁止
  606. en_result_t Bt_Mode23_DisableIrq (en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
  607. //模式0初始化及相关功能操作
  608. //timer配置及初始化
  609. en_result_t Bt_Mode0_Init(en_bt_unit_t enUnit, stc_bt_mode0_config_t* pstcConfig);
  610. //timer 启动/停止
  611. en_result_t Bt_M0_Run(en_bt_unit_t enUnit);
  612. en_result_t Bt_M0_Stop(en_bt_unit_t enUnit);
  613. //重载值设置
  614. en_result_t Bt_M0_ARRSet(en_bt_unit_t enUnit, uint16_t u16Data);
  615. //16位计数值设置/获取
  616. en_result_t Bt_M0_Cnt16Set(en_bt_unit_t enUnit, uint16_t u16Data);
  617. uint16_t Bt_M0_Cnt16Get(en_bt_unit_t enUnit);
  618. //32位计数值设置/获取
  619. en_result_t Bt_M0_Cnt32Set(en_bt_unit_t enUnit, uint32_t u32Data);
  620. uint32_t Bt_M0_Cnt32Get(en_bt_unit_t enUnit);
  621. //翻转输出使能/禁止设定
  622. en_result_t Bt_M0_EnTOG_Output(en_bt_unit_t enUnit, boolean_t bEnOutput);
  623. //模式1初始化及相关功能操作
  624. //timer配置及初始化
  625. en_result_t Bt_Mode1_Init(en_bt_unit_t enUnit, stc_bt_mode1_config_t* pstcConfig);
  626. //PWC 输入配置
  627. en_result_t Bt_M1_Input_Config(en_bt_unit_t enUnit, stc_bt_pwc_input_config_t* pstcConfig);
  628. //PWC测量边沿起始结束选择
  629. en_result_t Bt_M1_PWC_Edge_Sel(en_bt_unit_t enUnit,en_bt_m1cr_Edge_t enEdgeSel);
  630. //timer 启动/停止
  631. en_result_t Bt_M1_Run(en_bt_unit_t enUnit);
  632. en_result_t Bt_M1_Stop(en_bt_unit_t enUnit);
  633. //16位计数值设置/获取
  634. en_result_t Bt_M1_Cnt16Set(en_bt_unit_t enUnit, uint16_t u16Data);
  635. uint16_t Bt_M1_Cnt16Get(en_bt_unit_t enUnit);
  636. //脉冲宽度测量结果数值获取
  637. uint16_t Bt_M1_PWC_CapValueGet(en_bt_unit_t enUnit);
  638. //模式23初始化及相关功能操作
  639. //timer配置及初始化
  640. en_result_t Bt_Mode23_Init(en_bt_unit_t enUnit, stc_bt_mode23_config_t* pstcConfig);
  641. //timer 启动/停止
  642. en_result_t Bt_M23_Run(en_bt_unit_t enUnit);
  643. en_result_t Bt_M23_Stop(en_bt_unit_t enUnit);
  644. //PWM输出使能
  645. en_result_t Bt_M23_EnPWM_Output(en_bt_unit_t enUnit, boolean_t bEnOutput, boolean_t bEnAutoOutput);
  646. //重载值设置
  647. en_result_t Bt_M23_ARRSet(en_bt_unit_t enUnit, uint16_t u16Data, boolean_t bArrBufEn);
  648. //16位计数值设置/获取
  649. en_result_t Bt_M23_Cnt16Set(en_bt_unit_t enUnit, uint16_t u16Data);
  650. uint16_t Bt_M23_Cnt16Get(en_bt_unit_t enUnit);
  651. //比较捕获寄存器CCR0A/CCR0B设置/读取
  652. en_result_t Bt_M23_CCR_Set(en_bt_unit_t enUnit, en_bt_m23_ccrx_t enCCRSel, uint16_t u16Data);
  653. uint16_t Bt_M23_CCR_Get(en_bt_unit_t enUnit, en_bt_m23_ccrx_t enCCRSel);
  654. //PWM互补输出模式下,GATE功能选择
  655. en_result_t Bt_M23_GateFuncSel(en_bt_unit_t enUnit,stc_bt_m23_gate_config_t* pstcConfig);
  656. //主从模式配置
  657. en_result_t Bt_M23_MasterSlave_Set(en_bt_unit_t enUnit, stc_bt_m23_master_slave_config_t* pstcConfig);
  658. //CH0A/CH0B比较通道控制
  659. en_result_t Bt_M23_PortOutput_Config(en_bt_unit_t enUnit, stc_bt_m23_compare_config_t* pstcConfig);
  660. //CH0A/CH0B输入控制
  661. en_result_t Bt_M23_PortInput_Config(en_bt_unit_t enUnit, stc_bt_m23_input_config_t* pstcConfig);
  662. //ERT输入控制
  663. en_result_t Bt_M23_ETRInput_Config(en_bt_unit_t enUnit, stc_bt_m23_etr_input_config_t* pstcConfig);
  664. //刹车BK输入控制
  665. en_result_t Bt_M23_BrakeInput_Config(en_bt_unit_t enUnit, stc_bt_m23_bk_input_config_t* pstcConfig);
  666. //触发ADC控制
  667. en_result_t Bt_M23_TrigADC_Config(en_bt_unit_t enUnit, stc_bt_m23_adc_trig_config_t* pstcConfig);
  668. //死区功能
  669. en_result_t Bt_M23_DT_Config(en_bt_unit_t enUnit, stc_bt_m23_dt_config_t* pstcConfig);
  670. //重复周期设置
  671. en_result_t Bt_M23_SetValidPeriod(en_bt_unit_t enUnit, uint8_t u8ValidPeriod);
  672. //OCREF清除功能
  673. en_result_t Bt_M23_OCRefClr(en_bt_unit_t enUnit, stc_bt_m23_OCREF_Clr_config_t* pstcConfig);
  674. //使能DMA传输
  675. en_result_t Bt_M23_EnDMA(en_bt_unit_t enUnit, stc_bt_m23_trig_dma_config_t* pstcConfig);
  676. //捕获比较A软件触发
  677. en_result_t Bt_M23_EnSwTrigCapCmpA(en_bt_unit_t enUnit);
  678. //捕获比较B软件触发
  679. en_result_t Bt_M23_EnSwTrigCapCmpB(en_bt_unit_t enUnit);
  680. //软件更新使能
  681. en_result_t Bt_M23_EnSwUev(en_bt_unit_t enUnit);
  682. //软件触发使能
  683. en_result_t Bt_M23_EnSwTrig(en_bt_unit_t enUnit);
  684. //软件刹车使能
  685. en_result_t Bt_M23_EnSwBk(en_bt_unit_t enUnit);
  686. //@} // BtGroup
  687. #ifdef __cplusplus
  688. #endif
  689. #endif /* __BT_H__ */
  690. /******************************************************************************
  691. * EOF (not truncated)
  692. *****************************************************************************/