gd32f3x0_tsi.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /*!
  2. \file gd32f3x0_tsi.c
  3. \brief TSI driver
  4. \version 2017-06-06, V1.0.0, firmware for GD32F3x0
  5. \version 2019-06-01, V2.0.0, firmware for GD32F3x0
  6. */
  7. /*
  8. Copyright (c) 2019, GigaDevice Semiconductor Inc.
  9. Redistribution and use in source and binary forms, with or without modification,
  10. are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice, this
  12. list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. 3. Neither the name of the copyright holder nor the names of its contributors
  17. may be used to endorse or promote products derived from this software without
  18. specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  28. OF SUCH DAMAGE.
  29. */
  30. #include "gd32f3x0_tsi.h"
  31. /*!
  32. \brief reset TSI peripheral
  33. \param[in] none
  34. \param[out] none
  35. \retval none
  36. */
  37. void tsi_deinit(void)
  38. {
  39. rcu_periph_reset_enable(RCU_TSIRST);
  40. rcu_periph_reset_disable(RCU_TSIRST);
  41. }
  42. /*!
  43. \brief initialize TSI plus prescaler,charge plus,transfer plus,max cycle number
  44. \param[in] prescaler: CTCLK clock division factor
  45. only one parameter can be selected which is shown as below:
  46. \arg TSI_CTCDIV_DIV1: fCTCLK = fHCLK
  47. \arg TSI_CTCDIV_DIV2: fCTCLK = fHCLK/2
  48. \arg TSI_CTCDIV_DIV4: fCTCLK = fHCLK/4
  49. \arg TSI_CTCDIV_DIV8: fCTCLK = fHCLK/8
  50. \arg TSI_CTCDIV_DIV16: fCTCLK = fHCLK/16
  51. \arg TSI_CTCDIV_DIV32: fCTCLK = fHCLK/32
  52. \arg TSI_CTCDIV_DIV64: fCTCLK = fHCLK/64
  53. \arg TSI_CTCDIV_DIV128: fCTCLK = fHCLK/128
  54. \arg TSI_CTCDIV_DIV256: fCTCLK = fHCLK/256
  55. \arg TSI_CTCDIV_DIV512: fCTCLK = fHCLK/512
  56. \arg TSI_CTCDIV_DIV1024: fCTCLK = fHCLK/1024
  57. \arg TSI_CTCDIV_DIV2048: fCTCLK = fHCLK/2048
  58. \arg TSI_CTCDIV_DIV4096: fCTCLK = fHCLK/4096
  59. \arg TSI_CTCDIV_DIV8192: fCTCLK = fHCLK/8192
  60. \arg TSI_CTCDIV_DIV16384: fCTCLK = fHCLK/16384
  61. \arg TSI_CTCDIV_DIV32768: fCTCLK = fHCLK/32768
  62. \param[in] charge_duration: charge state duration time
  63. only one parameter can be selected which is shown as below:
  64. \arg TSI_CHARGE_1CTCLK(x=1..16): the duration time of charge state is x CTCLK
  65. \param[in] transfer_duration: charge transfer state duration time
  66. only one parameter can be selected which is shown as below:
  67. \arg TSI_TRANSFER_xCTCLK(x=1..16): the duration time of transfer state is x CTCLK
  68. \param[in] max_number: max cycle number
  69. only one parameter can be selected which is shown as below:
  70. \arg TSI_MAXNUM255: the max cycle number of a sequence is 255
  71. \arg TSI_MAXNUM511: the max cycle number of a sequence is 511
  72. \arg TSI_MAXNUM1023: the max cycle number of a sequence is 1023
  73. \arg TSI_MAXNUM2047: the max cycle number of a sequence is 2047
  74. \arg TSI_MAXNUM4095: the max cycle number of a sequence is 4095
  75. \arg TSI_MAXNUM8191: the max cycle number of a sequence is 8191
  76. \arg TSI_MAXNUM16383: the max cycle number of a sequence is 16383
  77. \param[out] none
  78. \retval none
  79. */
  80. void tsi_init(uint32_t prescaler,uint32_t charge_duration,uint32_t transfer_duration,uint32_t max_number)
  81. {
  82. uint32_t ctl0,ctl1;
  83. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  84. if(TSI_CTCDIV_DIV256 > prescaler){
  85. /* config TSI_CTL0 */
  86. ctl0 = TSI_CTL0;
  87. /*configure TSI clock division factor,charge state duration time,charge transfer state duration time */
  88. ctl0 &= ~(TSI_CTL0_CTCDIV|TSI_CTL0_CTDT|TSI_CTL0_CDT|TSI_CTL0_MCN);
  89. ctl0 |= ((prescaler<<12U)|charge_duration|transfer_duration|max_number);
  90. TSI_CTL0 = ctl0;
  91. /* config TSI_CTL1 */
  92. ctl1 = TSI_CTL1;
  93. ctl1 &= ~TSI_CTL1_CTCDIV;
  94. TSI_CTL1 = ctl1;
  95. }else{
  96. /* config TSI_CTL0 */
  97. ctl0 = TSI_CTL0;
  98. prescaler &= ~0x08U;
  99. /*configure TSI clock division factor,charge state duration time,charge transfer state duration time */
  100. ctl0 &= ~(TSI_CTL0_CTCDIV|TSI_CTL0_CTDT|TSI_CTL0_CDT|TSI_CTL0_MCN);
  101. ctl0 |= ((prescaler<<12U)|charge_duration|transfer_duration|max_number);
  102. TSI_CTL0 = ctl0;
  103. /* config TSI_CTL1 */
  104. ctl1 = TSI_CTL1;
  105. ctl1 |= TSI_CTL1_CTCDIV;
  106. TSI_CTL1 = ctl1;
  107. }
  108. }
  109. }
  110. /*!
  111. \brief enable TSI module
  112. \param[in] none
  113. \param[out] none
  114. \retval none
  115. */
  116. void tsi_enable(void)
  117. {
  118. TSI_CTL0 |= TSI_CTL0_TSIEN;
  119. }
  120. /*!
  121. \brief disable TSI module
  122. \param[in] none
  123. \param[out] none
  124. \retval none
  125. */
  126. void tsi_disable(void)
  127. {
  128. TSI_CTL0 &= ~TSI_CTL0_TSIEN;
  129. }
  130. /*!
  131. \brief enable sample pin
  132. \param[in] sample: sample pin
  133. one or more parameters can be selected which are shown as below:
  134. \arg TSI_SAMPCFG_GxPy( x=0..5,y=0..3):pin y of group x is sample pin
  135. \param[out] none
  136. \retval none
  137. */
  138. void tsi_sample_pin_enable(uint32_t sample)
  139. {
  140. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  141. TSI_SAMPCFG |= sample;
  142. }
  143. }
  144. /*!
  145. \brief disable sample pin
  146. \param[in] sample: sample pin
  147. one or more parameters can be selected which are shown as below:
  148. \arg TSI_SAMPCFG_GxPy( x=0..5,y=0..3): pin y of group x is sample pin
  149. \param[out] none
  150. \retval none
  151. */
  152. void tsi_sample_pin_disable(uint32_t sample)
  153. {
  154. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  155. TSI_SAMPCFG &= ~sample;
  156. }
  157. }
  158. /*!
  159. \brief enable channel pin
  160. \param[in] channel: channel pin
  161. one or more parameters can be selected which are shown as below:
  162. \arg TSI_CHCFG_GxPy( x=0..5,y=0..3): pin y of group x
  163. \param[out] none
  164. \retval none
  165. */
  166. void tsi_channel_pin_enable(uint32_t channel)
  167. {
  168. TSI_CHCFG |= channel;
  169. }
  170. /*!
  171. \brief disable channel pin
  172. \param[in] channel: channel pin
  173. one or more parameters can be selected which are shown as below:
  174. \arg TSI_CHCFG_GxPy( x=0..5,y=0..3): pin y of group x
  175. \param[out] none
  176. \retval none
  177. */
  178. void tsi_channel_pin_disable(uint32_t channel)
  179. {
  180. TSI_CHCFG &= ~channel;
  181. }
  182. /*!
  183. \brief configure TSI triggering by software
  184. \param[in] none
  185. \param[out] none
  186. \retval none
  187. */
  188. void tsi_sofeware_mode_config(void)
  189. {
  190. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  191. TSI_CTL0 &= ~TSI_CTL0_TRGMOD;
  192. }
  193. }
  194. /*!
  195. \brief start a charge-transfer sequence when TSI is in software trigger mode
  196. \param[in] none
  197. \param[out] none
  198. \retval none
  199. */
  200. void tsi_software_start(void)
  201. {
  202. TSI_CTL0 |= TSI_CTL0_TSIS;
  203. }
  204. /*!
  205. \brief stop a charge-transfer sequence when TSI is in software trigger mode
  206. \param[in] none
  207. \param[out] none
  208. \retval none
  209. */
  210. void tsi_software_stop(void)
  211. {
  212. TSI_CTL0 &= ~TSI_CTL0_TSIS;
  213. }
  214. /*!
  215. \brief configure TSI triggering by hardware
  216. \param[in] trigger_edge: the edge type in hardware trigger mode
  217. only one parameter can be selected which is shown as below:
  218. \arg TSI_FALLING_TRIGGER: falling edge trigger TSI charge transfer sequence
  219. \arg TSI_RISING_TRIGGER: rising edge trigger TSI charge transfer sequence
  220. \param[out] none
  221. \retval none
  222. */
  223. void tsi_hardware_mode_config(uint8_t trigger_edge)
  224. {
  225. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  226. /*enable hardware mode*/
  227. TSI_CTL0 |= TSI_CTL0_TRGMOD;
  228. /*configure the edge type in hardware trigger mode*/
  229. if(TSI_FALLING_TRIGGER == trigger_edge){
  230. TSI_CTL0 &= ~TSI_CTL0_EGSEL;
  231. }else{
  232. TSI_CTL0 |= TSI_CTL0_EGSEL;
  233. }
  234. }
  235. }
  236. /*!
  237. \brief configure TSI pin mode when charge-transfer sequence is IDLE
  238. \param[in] pin_mode: pin mode when charge-transfer sequence is IDLE
  239. only one parameter can be selected which is shown as below:
  240. \arg TSI_OUTPUT_LOW: TSI pin will output low when IDLE
  241. \arg TSI_INPUT_FLOATING: TSI pin will keep input_floating when IDLE
  242. \param[out] none
  243. \retval none
  244. */
  245. void tsi_pin_mode_config(uint8_t pin_mode)
  246. {
  247. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  248. if(TSI_OUTPUT_LOW == pin_mode){
  249. TSI_CTL0 &= ~TSI_CTL0_PINMOD;
  250. }else{
  251. TSI_CTL0 |= TSI_CTL0_PINMOD;
  252. }
  253. }
  254. }
  255. /*!
  256. \brief configure extend charge state
  257. \param[in] extend: enable or disable extend charge state
  258. only one parameter can be selected which is shown as below:
  259. \arg ENABLE: enable extend charge state
  260. \arg DISABLE: disable extend charge state
  261. \param[in] prescaler: ECCLK clock division factor
  262. only one parameter can be selected which is shown as below:
  263. \arg TSI_EXTEND_DIV1: fECCLK = fHCLK
  264. \arg TSI_EXTEND_DIV2: fECCLK = fHCLK/2
  265. \arg TSI_EXTEND_DIV3: fECCLK = fHCLK/3
  266. \arg TSI_EXTEND_DIV4: fECCLK = fHCLK/4
  267. \arg TSI_EXTEND_DIV5: fECCLK = fHCLK/5
  268. \arg TSI_EXTEND_DIV6: fECCLK = fHCLK/6
  269. \arg TSI_EXTEND_DIV7: fECCLK = fHCLK/7
  270. \arg TSI_EXTEND_DIV8: fECCLK = fHCLK/8
  271. \param[in] max_duration: value range 1...128,extend charge state maximum duration time is 1*tECCLK~128*tECCLK
  272. \param[out] none
  273. \retval none
  274. */
  275. void tsi_extend_charge_config(ControlStatus extend,uint8_t prescaler,uint32_t max_duration)
  276. {
  277. uint32_t ctl0,ctl1;
  278. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  279. if(DISABLE == extend){
  280. /*disable extend charge state*/
  281. TSI_CTL0 &= ~TSI_CTL0_ECEN;
  282. }else{
  283. if(TSI_EXTEND_DIV3 > prescaler){
  284. /*configure extend charge state maximum duration time*/
  285. ctl0 = TSI_CTL0;
  286. ctl0 &= ~TSI_CTL0_ECDT;
  287. ctl0 |= TSI_EXTENDMAX((max_duration-1U));
  288. TSI_CTL0 = ctl0;
  289. /*configure ECCLK clock division factor*/
  290. ctl0 = TSI_CTL0;
  291. ctl0 &= ~TSI_CTL0_ECDIV;
  292. ctl0 |= (uint32_t)prescaler<<15U;
  293. TSI_CTL0 = ctl0;
  294. /*enable extend charge state*/
  295. TSI_CTL0 |= TSI_CTL0_ECEN;
  296. }else{
  297. /*configure extend charge state maximum duration time*/
  298. ctl0 = TSI_CTL0;
  299. ctl0 &= ~TSI_CTL0_ECDT;
  300. ctl0 |= TSI_EXTENDMAX((max_duration-1U));
  301. TSI_CTL0 = ctl0;
  302. /*configure ECCLK clock division factor*/
  303. ctl0 = TSI_CTL0;
  304. ctl0 &= ~TSI_CTL0_ECDIV;
  305. ctl0 |= (prescaler & 0x01U)<<15U;
  306. TSI_CTL0 = ctl0;
  307. ctl1 = TSI_CTL1;
  308. ctl1 &= ~TSI_CTL1_ECDIV;
  309. ctl1 |= (prescaler & 0x06U)<<28U;
  310. TSI_CTL1 = ctl1;
  311. /*enable extend charge state*/
  312. TSI_CTL0 |= TSI_CTL0_ECEN;
  313. }
  314. }
  315. }
  316. }
  317. /*!
  318. \brief configure charge plus and transfer plus
  319. \param[in] prescaler: CTCLK clock division factor
  320. only one parameter can be selected which is shown as below:
  321. \arg TSI_CTCDIV_DIV1: fCTCLK = fHCLK
  322. \arg TSI_CTCDIV_DIV2: fCTCLK = fHCLK/2
  323. \arg TSI_CTCDIV_DIV4: fCTCLK = fHCLK/4
  324. \arg TSI_CTCDIV_DIV8: fCTCLK = fHCLK/8
  325. \arg TSI_CTCDIV_DIV16: fCTCLK = fHCLK/16
  326. \arg TSI_CTCDIV_DIV32: fCTCLK = fHCLK/32
  327. \arg TSI_CTCDIV_DIV64: fCTCLK = fHCLK/64
  328. \arg TSI_CTCDIV_DIV128: fCTCLK = fHCLK/128
  329. \arg TSI_CTCDIV_DIV256: fCTCLK = fHCLK/256
  330. \arg TSI_CTCDIV_DIV512: fCTCLK = fHCLK/512
  331. \arg TSI_CTCDIV_DIV1024: fCTCLK = fHCLK/1024
  332. \arg TSI_CTCDIV_DIV2048: fCTCLK = fHCLK/2048
  333. \arg TSI_CTCDIV_DIV4096: fCTCLK = fHCLK/4096
  334. \arg TSI_CTCDIV_DIV8192: fCTCLK = fHCLK/8192
  335. \arg TSI_CTCDIV_DIV16384: fCTCLK = fHCLK/16384
  336. \arg TSI_CTCDIV_DIV32768: fCTCLK = fHCLK/32768
  337. \param[in] charge_duration: charge state duration time
  338. only one parameter can be selected which is shown as below:
  339. \arg TSI_CHARGE_xCTCLK(x=1..16): the duration time of charge state is x CTCLK
  340. \param[in] transfer_duration: charge transfer state duration time
  341. only one parameter can be selected which is shown as below:
  342. \arg TSI_TRANSFER_xCTCLK(x=1..16): the duration time of transfer state is x CTCLK
  343. \param[out] none
  344. \retval none
  345. */
  346. void tsi_plus_config(uint32_t prescaler,uint32_t charge_duration,uint32_t transfer_duration)
  347. {
  348. uint32_t ctl0,ctl1;
  349. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  350. if(TSI_CTCDIV_DIV256 > prescaler){
  351. /* config TSI_CTL0 */
  352. ctl0 = TSI_CTL0;
  353. /*configure TSI clock division factor,charge state duration time,charge transfer state duration time */
  354. ctl0 &= ~(TSI_CTL0_CTCDIV|TSI_CTL0_CTDT|TSI_CTL0_CDT);
  355. ctl0 |= ((prescaler<<12U)|charge_duration|transfer_duration);
  356. TSI_CTL0 = ctl0;
  357. /* config TSI_CTL1 */
  358. ctl1 = TSI_CTL1;
  359. ctl1 &= ~TSI_CTL1_CTCDIV;
  360. TSI_CTL1 = ctl1;
  361. }else{
  362. /* config TSI_CTL */
  363. ctl0 = TSI_CTL0;
  364. prescaler &= ~0x08U;
  365. /*configure TSI clock division factor,charge state duration time,charge transfer state duration time */
  366. ctl0 &= ~(TSI_CTL0_CTCDIV|TSI_CTL0_CTDT|TSI_CTL0_CDT);
  367. ctl0 |= ((prescaler<<12U)|charge_duration|transfer_duration);
  368. TSI_CTL0 = ctl0;
  369. /* config TSI_CTL2 */
  370. ctl1 = TSI_CTL1;
  371. ctl1 |= TSI_CTL1_CTCDIV;
  372. TSI_CTL1 = ctl1;
  373. }
  374. }
  375. }
  376. /*!
  377. \brief configure the max cycle number of a charge-transfer sequence
  378. \param[in] max_number: max cycle number
  379. only one parameter can be selected which is shown as below:
  380. \arg TSI_MAXNUM255: the max cycle number of a sequence is 255
  381. \arg TSI_MAXNUM511: the max cycle number of a sequence is 511
  382. \arg TSI_MAXNUM1023: the max cycle number of a sequence is 1023
  383. \arg TSI_MAXNUM2047: the max cycle number of a sequence is 2047
  384. \arg TSI_MAXNUM4095: the max cycle number of a sequence is 4095
  385. \arg TSI_MAXNUM8191: the max cycle number of a sequence is 8191
  386. \arg TSI_MAXNUM16383: the max cycle number of a sequence is 16383
  387. \param[out] none
  388. \retval none
  389. */
  390. void tsi_max_number_config(uint32_t max_number)
  391. {
  392. if(RESET == (TSI_CTL0 & TSI_CTL0_TSIS)){
  393. uint32_t maxnum;
  394. maxnum = TSI_CTL0;
  395. /*configure the max cycle number of a charge-transfer sequence*/
  396. maxnum &= ~TSI_CTL0_MCN;
  397. maxnum |= max_number;
  398. TSI_CTL0 = maxnum;
  399. }
  400. }
  401. /*!
  402. \brief switch on hysteresis pin
  403. \param[in] group_pin: select pin which will be switched on hysteresis
  404. one or more parameters can be selected which are shown as below:
  405. \arg TSI_PHM_GxPy(x=0..5,y=0..3): pin y of group x switch on hysteresis
  406. \param[out] none
  407. \retval none
  408. */
  409. void tsi_hysteresis_on(uint32_t group_pin)
  410. {
  411. TSI_PHM |= group_pin;
  412. }
  413. /*!
  414. \brief switch off hysteresis pin
  415. \param[in] group_pin: select pin which will be switched off hysteresis
  416. one or more parameters can be selected which are shown as below:
  417. \arg TSI_PHM_GxPy(x=0..5,y=0..3): pin y of group x switch off hysteresis
  418. \param[out] none
  419. \retval none
  420. */
  421. void tsi_hysteresis_off(uint32_t group_pin)
  422. {
  423. TSI_PHM &= ~group_pin;
  424. }
  425. /*!
  426. \brief switch on analog pin
  427. \param[in] group_pin: select pin which will be switched on analog
  428. one or more parameters can be selected which are shown as below:
  429. \arg TSI_ASW_GxPy(x=0..5,y=0..3):pin y of group x switch on analog
  430. \param[out] none
  431. \retval none
  432. */
  433. void tsi_analog_on(uint32_t group_pin)
  434. {
  435. TSI_ASW |= group_pin;
  436. }
  437. /*!
  438. \brief switch off analog pin
  439. \param[in] group_pin: select pin which will be switched off analog
  440. one or more parameters can be selected which are shown as below:
  441. \arg TSI_ASW_GxPy(x=0..5,y=0..3):pin y of group x switch off analog
  442. \param[out] none
  443. \retval none
  444. */
  445. void tsi_analog_off(uint32_t group_pin)
  446. {
  447. TSI_ASW &= ~group_pin;
  448. }
  449. /*!
  450. \brief enable TSI interrupt
  451. \param[in] source: select interrupt which will be enabled
  452. only one parameter can be selected which is shown as below:
  453. \arg TSI_INT_CCTCF: charge-transfer complete flag interrupt enable
  454. \arg TSI_INT_MNERR: max cycle number error interrupt enable
  455. \param[out] none
  456. \retval none
  457. */
  458. void tsi_interrupt_enable(uint32_t source)
  459. {
  460. TSI_INTEN |= source;
  461. }
  462. /*!
  463. \brief disable TSI interrupt
  464. \param[in] source: select interrupt which will be disabled
  465. only one parameter can be selected which is shown as below:
  466. \arg TSI_INT_CCTCF: charge-transfer complete flag interrupt disable
  467. \arg TSI_INT_MNERR: max cycle number error interrupt disable
  468. \param[out] none
  469. \retval none
  470. */
  471. void tsi_interrupt_disable(uint32_t source)
  472. {
  473. TSI_INTEN &= ~source;
  474. }
  475. /*!
  476. \brief clear TSI interrupt flag
  477. \param[in] flag: select flag which will be cleared
  478. only one parameter can be selected which is shown as below:
  479. \arg TSI_INT_FLAG_CTCF_CLR: clear charge-transfer complete flag
  480. \arg TSI_INT_FLAG_MNERR_CLR: clear max cycle number error
  481. \param[out] none
  482. \retval none
  483. */
  484. void tsi_interrupt_flag_clear(uint32_t flag)
  485. {
  486. TSI_INTC |= flag;
  487. }
  488. /*!
  489. \brief get TSI interrupt flag
  490. \param[in] flag:
  491. only one parameter can be selected which is shown as below:
  492. \arg TSI_INT_FLAG_CTCF: charge-transfer complete flag
  493. \arg TSI_INT_FLAG_MNERR: max Cycle Number Error
  494. \param[out] none
  495. \retval FlagStatus:SET or RESET
  496. */
  497. FlagStatus tsi_interrupt_flag_get(uint32_t flag)
  498. {
  499. uint32_t interrupt_enable = 0U,interrupt_flag = 0U;
  500. interrupt_flag = (TSI_INTF & flag);
  501. interrupt_enable = (TSI_INTEN & flag);
  502. if(interrupt_flag && interrupt_enable){
  503. return SET;
  504. }else{
  505. return RESET;
  506. }
  507. }
  508. /*!
  509. \brief clear flag
  510. \param[in] flag: select flag which will be cleared
  511. only one parameter can be selected which is shown as below:
  512. \arg TSI_FLAG_CTCF_CLR: clear charge-transfer complete flag
  513. \arg TSI_FLAG_MNERR_CLR: clear max cycle number error
  514. \param[out] none
  515. \retval none
  516. */
  517. void tsi_flag_clear(uint32_t flag)
  518. {
  519. TSI_INTC |= flag;
  520. }
  521. /*!
  522. \brief get flag
  523. \param[in] flag:
  524. only one parameter can be selected which is shown as below:
  525. \arg TSI_FLAG_CTCF: charge-transfer complete flag
  526. \arg TSI_FLAG_MNERR: max Cycle Number Error
  527. \param[out] none
  528. \retval FlagStatus:SET or RESET
  529. */
  530. FlagStatus tsi_flag_get(uint32_t flag)
  531. {
  532. FlagStatus flag_status;
  533. if(TSI_INTF & flag){
  534. flag_status = SET;
  535. }else{
  536. flag_status = RESET;
  537. }
  538. return flag_status;
  539. }
  540. /*!
  541. \brief enbale group
  542. \param[in] group: select group to be enabled
  543. one or more parameters can be selected which are shown as below:
  544. \arg TSI_GCTL_GEx(x=0..5): the x group will be enabled
  545. \param[out] none
  546. \retval none
  547. */
  548. void tsi_group_enable(uint32_t group)
  549. {
  550. TSI_GCTL |= group;
  551. }
  552. /*!
  553. \brief disbale group
  554. \param[in] group: select group to be disabled
  555. one or more parameters can be selected which are shown as below:
  556. \arg TSI_GCTL_GEx(x=0..5):the x group will be disabled
  557. \param[out] none
  558. \retval none
  559. */
  560. void tsi_group_disable(uint32_t group)
  561. {
  562. TSI_GCTL &= ~group;
  563. }
  564. /*!
  565. \brief get group complete status
  566. \param[in] group: select group
  567. one or more parameters can be selected which are shown as below:
  568. \arg TSI_GCTL_GCx(x=0..5): get the complete status of group x
  569. \param[out] none
  570. \retval FlagStatus: group complete status,SET or RESET
  571. */
  572. FlagStatus tsi_group_status_get(uint32_t group)
  573. {
  574. FlagStatus flag_status;
  575. if(TSI_GCTL & group){
  576. flag_status = SET;
  577. }else{
  578. flag_status = RESET;
  579. }
  580. return flag_status;
  581. }
  582. /*!
  583. \brief get the cycle number for group0 as soon as a charge-transfer sequence completes
  584. \param[in] none
  585. \param[out] none
  586. \retval group0 cycle number
  587. */
  588. uint16_t tsi_group0_cycle_get(void)
  589. {
  590. return (uint16_t)TSI_G0CYCN;
  591. }
  592. /*!
  593. \brief get the cycle number for group1 as soon as a charge-transfer sequence completes
  594. \param[in] none
  595. \param[out] none
  596. \retval group1 cycle number
  597. */
  598. uint16_t tsi_group1_cycle_get(void)
  599. {
  600. return (uint16_t)TSI_G1CYCN;
  601. }
  602. /*!
  603. \brief get the cycle number for group2 as soon as a charge-transfer sequence completes
  604. \param[in] none
  605. \param[out] none
  606. \retval group2 cycle number
  607. */
  608. uint16_t tsi_group2_cycle_get(void)
  609. {
  610. return (uint16_t)TSI_G2CYCN;
  611. }
  612. /*!
  613. \brief get the cycle number for group3 as soon as a charge-transfer sequence completes
  614. \param[in] none
  615. \param[out] none
  616. \retval group3 cycle number
  617. */
  618. uint16_t tsi_group3_cycle_get(void)
  619. {
  620. return (uint16_t)TSI_G3CYCN;
  621. }
  622. /*!
  623. \brief get the cycle number for group4 as soon as a charge-transfer sequence completes
  624. \param[in] none
  625. \param[out] none
  626. \retval group4 cycle number
  627. */
  628. uint16_t tsi_group4_cycle_get(void)
  629. {
  630. return (uint16_t)TSI_G4CYCN;
  631. }
  632. /*!
  633. \brief get the cycle number for group5 as soon as a charge-transfer sequence completes
  634. \param[in] none
  635. \param[out] none
  636. \retval group5 cycle number
  637. */
  638. uint16_t tsi_group5_cycle_get(void)
  639. {
  640. return (uint16_t)TSI_G5CYCN;
  641. }