gio.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /** @file gio.c
  2. * @brief GIO Driver Implementation File
  3. * @date 29.May.2013
  4. * @version 03.05.02
  5. *
  6. */
  7. /* (c) Texas Instruments 2009-2013, All rights reserved. */
  8. /* USER CODE BEGIN (0) */
  9. /* USER CODE END */
  10. #include "gio.h"
  11. /* USER CODE BEGIN (1) */
  12. /* USER CODE END */
  13. /** @fn void gioInit(void)
  14. * @brief Initializes the GIO Driver
  15. *
  16. * This function initializes the GIO module and set the GIO ports
  17. * to the initial values.
  18. */
  19. /* SourceId : GIO_SourceId_001 */
  20. /* Requirements : HL_SR115, HL_SR116, HL_SR117, HL_SR118, HL_SR119, HL_SR120, HL_SR121, HL_SR122 */
  21. void gioInit(void)
  22. {
  23. /* USER CODE BEGIN (2) */
  24. /* USER CODE END */
  25. /** bring GIO module out of reset */
  26. gioREG->GCR0 = 1U;
  27. gioREG->INTENACLR = 0xFFU;
  28. gioREG->LVLCLR = 0xFFU;
  29. /** @b initialize @b Port @b A */
  30. /** - Port A output values */
  31. gioPORTA->DOUT = 0U /* Bit 0 */
  32. | (0U << 1U) /* Bit 1 */
  33. | (0U << 2U) /* Bit 2 */
  34. | (0U << 3U) /* Bit 3 */
  35. | (0U << 4U) /* Bit 4 */
  36. | (0U << 5U) /* Bit 5 */
  37. | (0U << 6U) /* Bit 6 */
  38. | (0U << 7U); /* Bit 7 */
  39. /** - Port A direction */
  40. gioPORTA->DIR = 0U /* Bit 0 */
  41. | (0U << 1U) /* Bit 1 */
  42. | (0U << 2U) /* Bit 2 */
  43. | (0U << 3U) /* Bit 3 */
  44. | (0U << 4U) /* Bit 4 */
  45. | (0U << 5U) /* Bit 5 */
  46. | (0U << 6U) /* Bit 6 */
  47. | (0U << 7U); /* Bit 7 */
  48. /** - Port A open drain enable */
  49. gioPORTA->PDR = 0U /* Bit 0 */
  50. | (0U << 1U) /* Bit 1 */
  51. | (0U << 2U) /* Bit 2 */
  52. | (0U << 3U) /* Bit 3 */
  53. | (0U << 4U) /* Bit 4 */
  54. | (0U << 5U) /* Bit 5 */
  55. | (0U << 6U) /* Bit 6 */
  56. | (0U << 7U); /* Bit 7 */
  57. /** - Port A pullup / pulldown selection */
  58. gioPORTA->PSL = 0U /* Bit 0 */
  59. | (0U << 1U) /* Bit 1 */
  60. | (0U << 2U) /* Bit 2 */
  61. | (0U << 3U) /* Bit 3 */
  62. | (0U << 4U) /* Bit 4 */
  63. | (0U << 5U) /* Bit 5 */
  64. | (0U << 6U) /* Bit 6 */
  65. | (0U << 7U); /* Bit 7 */
  66. /** - Port A pullup / pulldown enable*/
  67. gioPORTA->PULDIS = 0U /* Bit 0 */
  68. | (0U << 1U) /* Bit 1 */
  69. | (0U << 2U) /* Bit 2 */
  70. | (0U << 3U) /* Bit 3 */
  71. | (0U << 4U) /* Bit 4 */
  72. | (0U << 5U) /* Bit 5 */
  73. | (0U << 6U) /* Bit 6 */
  74. | (0U << 7U); /* Bit 7 */
  75. /** @b initialize @b Port @b B */
  76. /** - Port B output values */
  77. gioPORTB->DOUT = 0U /* Bit 0 */
  78. | (0U << 1U) /* Bit 1 */
  79. | (0U << 2U) /* Bit 2 */
  80. | (0U << 3U) /* Bit 3 */
  81. | (0U << 4U) /* Bit 4 */
  82. | (0U << 5U) /* Bit 5 */
  83. | (0U << 6U) /* Bit 6 */
  84. | (0U << 7U); /* Bit 7 */
  85. /** - Port B direction */
  86. gioPORTB->DIR = 0U /* Bit 0 */
  87. | (0U << 1U) /* Bit 1 */
  88. | (0U << 2U) /* Bit 2 */
  89. | (0U << 3U) /* Bit 3 */
  90. | (0U << 4U) /* Bit 4 */
  91. | (0U << 5U) /* Bit 5 */
  92. | (0U << 6U) /* Bit 6 */
  93. | (0U << 7U); /* Bit 7 */
  94. /** - Port B open drain enable */
  95. gioPORTB->PDR = 0U /* Bit 0 */
  96. | (0U << 1U) /* Bit 1 */
  97. | (0U << 2U) /* Bit 2 */
  98. | (0U << 3U) /* Bit 3 */
  99. | (0U << 4U) /* Bit 4 */
  100. | (0U << 5U) /* Bit 5 */
  101. | (0U << 6U) /* Bit 6 */
  102. | (0U << 7U); /* Bit 7 */
  103. /** - Port B pullup / pulldown selection */
  104. gioPORTB->PSL = 0U /* Bit 0 */
  105. | (0U << 1U) /* Bit 1 */
  106. | (0U << 2U) /* Bit 2 */
  107. | (0U << 3U) /* Bit 3 */
  108. | (0U << 4U) /* Bit 4 */
  109. | (0U << 5U) /* Bit 5 */
  110. | (0U << 6U) /* Bit 6 */
  111. | (0U << 7U); /* Bit 7 */
  112. /** - Port B pullup / pulldown enable*/
  113. gioPORTB->PULDIS = 0U /* Bit 0 */
  114. | (0U << 1U) /* Bit 1 */
  115. | (0U << 2U) /* Bit 2 */
  116. | (0U << 3U) /* Bit 3 */
  117. | (0U << 4U) /* Bit 4 */
  118. | (0U << 5U) /* Bit 5 */
  119. | (0U << 6U) /* Bit 6 */
  120. | (0U << 7U); /* Bit 7 */
  121. /* USER CODE BEGIN (3) */
  122. /* USER CODE END */
  123. /** @b initialize @b interrupts */
  124. /** - interrupt polarity */
  125. gioREG->POL = 0U /* Bit 0 */
  126. | (0U << 1U) /* Bit 1 */
  127. | (0U << 2U) /* Bit 2 */
  128. | (0U << 3U) /* Bit 3 */
  129. | (0U << 4U) /* Bit 4 */
  130. | (0U << 5U) /* Bit 5 */
  131. | (0U << 6U) /* Bit 6 */
  132. | (0U << 7U) /* Bit 7 */
  133. | (0U << 8U) /* Bit 8 */
  134. | (0U << 9U) /* Bit 9 */
  135. | (0U << 10U) /* Bit 10 */
  136. | (0U << 11U) /* Bit 11 */
  137. | (0U << 12U) /* Bit 12 */
  138. | (0U << 13U) /* Bit 13 */
  139. | (0U << 14U) /* Bit 14 */
  140. | (0U << 15U);/* Bit 15 */
  141. /** - interrupt level */
  142. gioREG->LVLSET = 0U /* Bit 0 */
  143. | (0U << 1U) /* Bit 1 */
  144. | (0U << 2U) /* Bit 2 */
  145. | (0U << 3U) /* Bit 3 */
  146. | (0U << 4U) /* Bit 4 */
  147. | (0U << 5U) /* Bit 5 */
  148. | (0U << 6U) /* Bit 6 */
  149. | (0U << 7U) /* Bit 7 */
  150. | (0U << 8U) /* Bit 8 */
  151. | (0U << 9U) /* Bit 9 */
  152. | (0U << 10U) /* Bit 10 */
  153. | (0U << 11U) /* Bit 11 */
  154. | (0U << 12U) /* Bit 12 */
  155. | (0U << 13U) /* Bit 13 */
  156. | (0U << 14U) /* Bit 14 */
  157. | (0U << 15U);/* Bit 15 */
  158. /** - clear all pending interrupts */
  159. gioREG->FLG = 0xFFU;
  160. /** - enable interrupts */
  161. gioREG->INTENASET = 0U /* Bit 0 */
  162. | (0U << 1U) /* Bit 1 */
  163. | (0U << 2U) /* Bit 2 */
  164. | (0U << 3U) /* Bit 3 */
  165. | (0U << 4U) /* Bit 4 */
  166. | (0U << 5U) /* Bit 5 */
  167. | (0U << 6U) /* Bit 6 */
  168. | (0U << 7U) /* Bit 7 */
  169. | (0U << 8U) /* Bit 8 */
  170. | (0U << 9U) /* Bit 9 */
  171. | (0U << 10U) /* Bit 10 */
  172. | (0U << 11U) /* Bit 11 */
  173. | (0U << 12U) /* Bit 12 */
  174. | (0U << 13U) /* Bit 13 */
  175. | (0U << 14U) /* Bit 14 */
  176. | (0U << 15U);/* Bit 15 */
  177. /* USER CODE BEGIN (4) */
  178. /* USER CODE END */
  179. }
  180. /** @fn void gioSetDirection(gioPORT_t *port, uint32 dir)
  181. * @brief Set Port Direction
  182. * @param[in] port pointer to GIO port:
  183. * - gioPORTA: PortA pointer
  184. * - gioPORTB: PortB pointer
  185. * @param[in] dir value to write to DIR register
  186. *
  187. * Set the direction of GIO pins at runtime.
  188. */
  189. /* SourceId : GIO_SourceId_002 */
  190. /* Requirements : HL_SR123 */
  191. void gioSetDirection(gioPORT_t *port, uint32 dir)
  192. {
  193. port->DIR = dir;
  194. }
  195. /** @fn void gioSetBit(gioPORT_t *port, uint32 bit, uint32 value)
  196. * @brief Write Bit
  197. * @param[in] port pointer to GIO port:
  198. * - gioPORTA: PortA pointer
  199. * - gioPORTB: PortB pointer
  200. * @param[in] bit number 0-7 that specifies the bit to be written to.
  201. * - 0: LSB
  202. * - 7: MSB
  203. * @param[in] value binary value to write to bit
  204. *
  205. * Writes a value to the specified pin of the given GIO port
  206. */
  207. /* SourceId : GIO_SourceId_003 */
  208. /* Requirements : HL_SR126 */
  209. void gioSetBit(gioPORT_t *port, uint32 bit, uint32 value)
  210. {
  211. /* USER CODE BEGIN (5) */
  212. /* USER CODE END */
  213. if (value != 0U)
  214. {
  215. port->DSET = 1U << bit;
  216. }
  217. else
  218. {
  219. port->DCLR = 1U << bit;
  220. }
  221. }
  222. /** @fn void gioSetPort(gioPORT_t *port, uint32 value)
  223. * @brief Write Port Value
  224. * @param[in] port pointer to GIO port:
  225. * - gioPORTA: PortA pointer
  226. * - gioPORTB: PortB pointer
  227. * @param[in] value value to write to port
  228. *
  229. * Writes a value to all pin of a given GIO port
  230. */
  231. /* SourceId : GIO_SourceId_004 */
  232. /* Requirements : HL_SR127 */
  233. void gioSetPort(gioPORT_t *port, uint32 value)
  234. {
  235. /* USER CODE BEGIN (6) */
  236. /* USER CODE END */
  237. port->DOUT = value;
  238. /* USER CODE BEGIN (7) */
  239. /* USER CODE END */
  240. }
  241. /** @fn uint32 gioGetBit(gioPORT_t *port, uint32 bit)
  242. * @brief Read Bit
  243. * @param[in] port pointer to GIO port:
  244. * - gioPORTA: PortA pointer
  245. * - gioPORTB: PortB pointer
  246. * @param[in] bit number 0-7 that specifies the bit to be written to.
  247. * - 0: LSB
  248. * - 7: MSB
  249. *
  250. * Reads a the current value from the specified pin of the given GIO port
  251. */
  252. /* SourceId : GIO_SourceId_005 */
  253. /* Requirements : HL_SR124 */
  254. uint32 gioGetBit(gioPORT_t *port, uint32 bit)
  255. {
  256. /* USER CODE BEGIN (8) */
  257. /* USER CODE END */
  258. return (port->DIN >> bit) & 1U;
  259. }
  260. /** @fn uint32 gioGetPort(gioPORT_t *port)
  261. * @brief Read Port Value
  262. * @param[in] port pointer to GIO port:
  263. * - gioPORTA: PortA pointer
  264. * - gioPORTB: PortB pointer
  265. *
  266. * Reads a the current value of a given GIO port
  267. */
  268. /* SourceId : GIO_SourceId_006 */
  269. /* Requirements : HL_SR125 */
  270. uint32 gioGetPort(gioPORT_t *port)
  271. {
  272. /* USER CODE BEGIN (9) */
  273. /* USER CODE END */
  274. return port->DIN;
  275. }
  276. /** @fn void gioToggleBit(gioPORT_t *port, uint32 bit)
  277. * @brief Write Bit
  278. * @param[in] port pointer to GIO port:
  279. * - gioPORTA: PortA pointer
  280. * - gioPORTB: PortB pointer
  281. * @param[in] bit number 0-7 that specifies the bit to be written to.
  282. * - 0: LSB
  283. * - 7: MSB
  284. *
  285. * Toggle a value to the specified pin of the given GIO port
  286. */
  287. /* SourceId : GIO_SourceId_007 */
  288. /* Requirements : */
  289. void gioToggleBit(gioPORT_t *port, uint32 bit)
  290. {
  291. /* USER CODE BEGIN (10) */
  292. /* USER CODE END */
  293. if ((port->DIN & (1U << bit)) != 0U)
  294. {
  295. port->DCLR = 1U << bit;
  296. }
  297. else
  298. {
  299. port->DSET = 1U << bit;
  300. }
  301. }
  302. /** @fn void gioEnableNotification(uint32 bit)
  303. * @brief Enable Interrupt
  304. * @param[in] port pointer to GIO port:
  305. * - gioPORTA: PortA pointer
  306. * - gioPORTB: PortB pointer
  307. * @param[in] bit interrupt pin to enable
  308. * - 0: LSB
  309. * - 7: MSB
  310. *
  311. * Enables an interrupt pin of selected port
  312. */
  313. /* SourceId : GIO_SourceId_008 */
  314. /* Requirements : HL_SR128 */
  315. void gioEnableNotification(gioPORT_t *port, uint32 bit)
  316. {
  317. /* USER CODE BEGIN (11) */
  318. /* USER CODE END */
  319. if (port == gioPORTA)
  320. {
  321. gioREG->INTENASET = 1U << bit;
  322. }
  323. else if (port == gioPORTB)
  324. {
  325. gioREG->INTENASET = 1U << (bit + 8);
  326. }
  327. else
  328. {
  329. /* Empty */
  330. }
  331. }
  332. /** @fn void gioDisableNotification(uint32 bit)
  333. * @brief Disable Interrupt
  334. * @param[in] port pointer to GIO port:
  335. * - gioPORTA: PortA pointer
  336. * - gioPORTB: PortB pointer
  337. * @param[in] bit interrupt pin to enable
  338. * - 0: LSB
  339. * - 7: MSB
  340. *
  341. * Disables an interrupt pin of selected port
  342. */
  343. /* SourceId : GIO_SourceId_009 */
  344. /* Requirements : HL_SR129 */
  345. void gioDisableNotification(gioPORT_t *port, uint32 bit)
  346. {
  347. /* USER CODE BEGIN (12) */
  348. /* USER CODE END */
  349. if (port == gioPORTA)
  350. {
  351. gioREG->INTENACLR = 1U << bit;
  352. }
  353. else if (port == gioPORTB)
  354. {
  355. gioREG->INTENACLR = 1U << (bit + 8);
  356. }
  357. else
  358. {
  359. /* Empty */
  360. }
  361. }
  362. /* USER CODE BEGIN (19) */
  363. /* USER CODE END */