tiva_timer.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  1. //*****************************************************************************
  2. //
  3. // timer.c - Driver for the timer module.
  4. //
  5. // Copyright (c) 2005-2020 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup timer_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_ints.h"
  48. #include "inc/hw_memmap.h"
  49. #include "inc/hw_timer.h"
  50. #include "inc/hw_types.h"
  51. #include "inc/hw_sysctl.h"
  52. #include "driverlib/debug.h"
  53. #include "driverlib/interrupt.h"
  54. #include "driverlib/tiva_timer.h"
  55. //*****************************************************************************
  56. //
  57. // A macro used to determine whether the target part supports new
  58. // configuration and control options.
  59. //
  60. //*****************************************************************************
  61. #define NEW_TIMER_CONFIGURATION CLASS_IS_TM4C129
  62. //*****************************************************************************
  63. //
  64. // A mapping of timer base address to interrupt number.
  65. //
  66. //*****************************************************************************
  67. static const uint32_t g_ppui32TimerIntMap[][2] =
  68. {
  69. { TIMER0_BASE, INT_TIMER0A_TM4C123 },
  70. { TIMER1_BASE, INT_TIMER1A_TM4C123 },
  71. { TIMER2_BASE, INT_TIMER2A_TM4C123 },
  72. { TIMER3_BASE, INT_TIMER3A_TM4C123 },
  73. { TIMER4_BASE, INT_TIMER4A_TM4C123 },
  74. { TIMER5_BASE, INT_TIMER5A_TM4C123 },
  75. { WTIMER0_BASE, INT_WTIMER0A_TM4C123 },
  76. { WTIMER1_BASE, INT_WTIMER1A_TM4C123 },
  77. { WTIMER2_BASE, INT_WTIMER2A_TM4C123 },
  78. { WTIMER3_BASE, INT_WTIMER3A_TM4C123 },
  79. { WTIMER4_BASE, INT_WTIMER4A_TM4C123 },
  80. { WTIMER5_BASE, INT_WTIMER5A_TM4C123 },
  81. };
  82. static const uint_fast8_t g_ui8TimerIntMapRows =
  83. sizeof(g_ppui32TimerIntMap) / sizeof(g_ppui32TimerIntMap[0]);
  84. static const uint32_t g_ppui32TimerIntMapSnowflake[][2] =
  85. {
  86. { TIMER0_BASE, INT_TIMER0A_TM4C129 },
  87. { TIMER1_BASE, INT_TIMER1A_TM4C129 },
  88. { TIMER2_BASE, INT_TIMER2A_TM4C129 },
  89. { TIMER3_BASE, INT_TIMER3A_TM4C129 },
  90. { TIMER4_BASE, INT_TIMER4A_TM4C129 },
  91. { TIMER5_BASE, INT_TIMER5A_TM4C129 },
  92. { TIMER6_BASE, INT_TIMER6A_TM4C129 },
  93. { TIMER7_BASE, INT_TIMER7A_TM4C129 },
  94. };
  95. static const uint_fast8_t g_ui8TimerIntMapRowsSnowflake =
  96. sizeof(g_ppui32TimerIntMapSnowflake) /
  97. sizeof(g_ppui32TimerIntMapSnowflake[0]);
  98. //*****************************************************************************
  99. //
  100. //! \internal
  101. //! Checks a timer base address.
  102. //!
  103. //! \param ui32Base is the base address of the timer module.
  104. //!
  105. //! This function determines if a timer module base address is valid.
  106. //!
  107. //! \return Returns \b true if the base address is valid and \b false
  108. //! otherwise.
  109. //
  110. //*****************************************************************************
  111. #ifdef DEBUG
  112. static bool
  113. _TimerBaseValid(uint32_t ui32Base)
  114. {
  115. return((ui32Base == TIMER0_BASE) || (ui32Base == TIMER1_BASE) ||
  116. (ui32Base == TIMER2_BASE) || (ui32Base == TIMER3_BASE) ||
  117. (ui32Base == TIMER4_BASE) || (ui32Base == TIMER5_BASE) ||
  118. (ui32Base == TIMER6_BASE) || (ui32Base == TIMER7_BASE) ||
  119. (ui32Base == WTIMER0_BASE) || (ui32Base == WTIMER1_BASE) ||
  120. (ui32Base == WTIMER2_BASE) || (ui32Base == WTIMER3_BASE) ||
  121. (ui32Base == WTIMER4_BASE) || (ui32Base == WTIMER5_BASE));
  122. }
  123. #endif
  124. //*****************************************************************************
  125. //
  126. //! Returns a timer modules interrupt number.
  127. //!
  128. //! \param ui32Base is the base address of the selected timer.
  129. //! \param ui32Timer specifies the timer(s) to enable; must be one of
  130. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  131. //!
  132. //! This function returns the interrupt number for a given timer module
  133. //! specified by the \e ui32Base and \e ui32Timer parameter.
  134. //!
  135. //! \return Returns a timer module's interrupt number or 0 if the interrupt
  136. //! does not exist.
  137. //
  138. //*****************************************************************************
  139. static uint32_t
  140. _TimerIntNumberGet(uint32_t ui32Base, uint32_t ui32Timer)
  141. {
  142. uint32_t ui32Int;
  143. uint_fast8_t ui8Idx, ui8Rows;
  144. const uint32_t (*ppui32SSIIntMap)[2];
  145. //
  146. // Default interrupt map.
  147. //
  148. ppui32SSIIntMap = g_ppui32TimerIntMap;
  149. ui8Rows = g_ui8TimerIntMapRows;
  150. if(CLASS_IS_TM4C129)
  151. {
  152. ppui32SSIIntMap = g_ppui32TimerIntMapSnowflake;
  153. ui8Rows = g_ui8TimerIntMapRowsSnowflake;
  154. }
  155. //
  156. // Loop through the table that maps timer base addresses to interrupt
  157. // numbers.
  158. //
  159. for(ui8Idx = 0; ui8Idx < ui8Rows; ui8Idx++)
  160. {
  161. //
  162. // See if this base address matches.
  163. //
  164. if(ppui32SSIIntMap[ui8Idx][0] == ui32Base)
  165. {
  166. ui32Int = ppui32SSIIntMap[ui8Idx][1];
  167. if(ui32Timer == TIMER_B)
  168. {
  169. ui32Int += 1;
  170. }
  171. //
  172. // Return the corresponding interrupt number.
  173. //
  174. return(ui32Int);
  175. }
  176. }
  177. //
  178. // The base address could not be found, so return an error.
  179. //
  180. return(0);
  181. }
  182. //*****************************************************************************
  183. //
  184. //! Enables the timer(s).
  185. //!
  186. //! \param ui32Base is the base address of the timer module.
  187. //! \param ui32Timer specifies the timer(s) to enable; must be one of
  188. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  189. //!
  190. //! This function enables operation of the timer module. The timer must be
  191. //! configured before it is enabled.
  192. //!
  193. //! \return None.
  194. //
  195. //*****************************************************************************
  196. void
  197. TimerEnable(uint32_t ui32Base, uint32_t ui32Timer)
  198. {
  199. //
  200. // Check the arguments.
  201. //
  202. ASSERT(_TimerBaseValid(ui32Base));
  203. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  204. (ui32Timer == TIMER_BOTH));
  205. //
  206. // Enable the timer(s) module.
  207. //
  208. HWREG(ui32Base + TIMER_O_CTL) |= ui32Timer & (TIMER_CTL_TAEN |
  209. TIMER_CTL_TBEN);
  210. }
  211. //*****************************************************************************
  212. //
  213. //! Disables the timer(s).
  214. //!
  215. //! \param ui32Base is the base address of the timer module.
  216. //! \param ui32Timer specifies the timer(s) to disable; must be one of
  217. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  218. //!
  219. //! This function disables operation of the timer module.
  220. //!
  221. //! \return None.
  222. //
  223. //*****************************************************************************
  224. void
  225. TimerDisable(uint32_t ui32Base, uint32_t ui32Timer)
  226. {
  227. //
  228. // Check the arguments.
  229. //
  230. ASSERT(_TimerBaseValid(ui32Base));
  231. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  232. (ui32Timer == TIMER_BOTH));
  233. //
  234. // Disable the timer module.
  235. //
  236. HWREG(ui32Base + TIMER_O_CTL) &= ~(ui32Timer &
  237. (TIMER_CTL_TAEN | TIMER_CTL_TBEN));
  238. }
  239. //*****************************************************************************
  240. //
  241. //! Configures the timer(s).
  242. //!
  243. //! \param ui32Base is the base address of the timer module.
  244. //! \param ui32Config is the configuration for the timer.
  245. //!
  246. //! This function configures the operating mode of the timer(s). The timer
  247. //! module is disabled before being configured and is left in the disabled
  248. //! state. The timer can be configured to be a single full-width timer
  249. //! by using the \b TIMER_CFG_* values or a pair of half-width timers using the
  250. //! \b TIMER_CFG_A_* and \b TIMER_CFG_B_* values passed in the \e ui32Config
  251. //! parameter.
  252. //!
  253. //! The configuration is specified in \e ui32Config as one of the following
  254. //! values:
  255. //!
  256. //! - \b TIMER_CFG_ONE_SHOT - Full-width one-shot timer
  257. //! - \b TIMER_CFG_ONE_SHOT_UP - Full-width one-shot timer that counts up
  258. //! instead of down (not available on all parts)
  259. //! - \b TIMER_CFG_PERIODIC - Full-width periodic timer
  260. //! - \b TIMER_CFG_PERIODIC_UP - Full-width periodic timer that counts up
  261. //! instead of down (not available on all parts)
  262. //! - \b TIMER_CFG_RTC - Full-width real time clock timer
  263. //! - \b TIMER_CFG_SPLIT_PAIR - Two half-width timers
  264. //!
  265. //! When configured for a pair of half-width timers, each timer is separately
  266. //! configured. The first timer is configured by setting \e ui32Config to
  267. //! the result of a logical OR operation between one of the following values
  268. //! and \e ui32Config:
  269. //!
  270. //! - \b TIMER_CFG_A_ONE_SHOT - Half-width one-shot timer
  271. //! - \b TIMER_CFG_A_ONE_SHOT_UP - Half-width one-shot timer that counts up
  272. //! instead of down (not available on all parts)
  273. //! - \b TIMER_CFG_A_PERIODIC - Half-width periodic timer
  274. //! - \b TIMER_CFG_A_PERIODIC_UP - Half-width periodic timer that counts up
  275. //! instead of down (not available on all parts)
  276. //! - \b TIMER_CFG_A_CAP_COUNT - Half-width edge count capture
  277. //! - \b TIMER_CFG_A_CAP_COUNT_UP - Half-width edge count capture that counts
  278. //! up instead of down (not available on all parts)
  279. //! - \b TIMER_CFG_A_CAP_TIME - Half-width edge time capture
  280. //! - \b TIMER_CFG_A_CAP_TIME_UP - Half-width edge time capture that counts up
  281. //! instead of down (not available on all parts)
  282. //! - \b TIMER_CFG_A_ONE_SHOT_PWM - Half-width one shot PWM output
  283. //! - \b TIMER_CFG_A_PWM - Half-width PWM output
  284. //!
  285. //! Some Tiva devices also allow configuring an action when the timers
  286. //! reach their timeout. Please consult the data sheet for the part you are
  287. //! using to determine whether configuring actions on timers is available.
  288. //!
  289. //! One of the following can be combined with the \b TIMER_CFG_* values to
  290. //! enable an action on timer A:
  291. //!
  292. //! - \b TIMER_CFG_A_ACT_TOINTD - masks the timeout interrupt of timer A.
  293. //! - \b TIMER_CFG_A_ACT_NONE - no additional action on timeout of timer A.
  294. //! - \b TIMER_CFG_A_ACT_TOGGLE - toggle CCP on timeout of timer A.
  295. //! - \b TIMER_CFG_A_ACT_SETTO - set CCP on timeout of timer A.
  296. //! - \b TIMER_CFG_A_ACT_CLRTO - clear CCP on timeout of timer A.
  297. //! - \b TIMER_CFG_A_ACT_SETTOGTO - set CCP immediately and then toggle it on
  298. //! timeout of timer A.
  299. //! - \b TIMER_CFG_A_ACT_CLRTOGTO - clear CCP immediately and then toggle it on
  300. //! timeout of timer A.
  301. //! - \b TIMER_CFG_A_ACT_SETCLRTO - set CCP immediately and then clear it on
  302. //! timeout of timer A.
  303. //! - \b TIMER_CFG_A_ACT_CLRSETTO - clear CCP immediately and then set it on
  304. //! timeout of timer A.
  305. //!
  306. //! One of the following can be combined with the \b TIMER_CFG_* values to
  307. //! enable an action on timer B:
  308. //!
  309. //! - \b TIMER_CFG_B_ACT_TOINTD - masks the timeout interrupt of timer B.
  310. //! - \b TIMER_CFG_B_ACT_NONE - no additional action on timeout of timer B.
  311. //! - \b TIMER_CFG_B_ACT_TOGGLE - toggle CCP on timeout of timer B.
  312. //! - \b TIMER_CFG_B_ACT_SETTO - set CCP on timeout of timer B.
  313. //! - \b TIMER_CFG_B_ACT_CLRTO - clear CCP on timeout of timer B.
  314. //! - \b TIMER_CFG_B_ACT_SETTOGTO - set CCP immediately and then toggle it on
  315. //! timeout of timer B.
  316. //! - \b TIMER_CFG_B_ACT_CLRTOGTO - clear CCP immediately and then toggle it on
  317. //! timeout of timer B.
  318. //! - \b TIMER_CFG_B_ACT_SETCLRTO - set CCP immediately and then clear it on
  319. //! timeout of timer B.
  320. //! - \b TIMER_CFG_B_ACT_CLRSETTO - clear CCP immediately and then set it on
  321. //! timeout of timer B.
  322. //!
  323. //! Similarly, the second timer is configured by setting \e ui32Config to
  324. //! the result of a logical OR operation between one of the corresponding
  325. //! \b TIMER_CFG_B_* values and \e ui32Config.
  326. //!
  327. //! \return None.
  328. //
  329. //*****************************************************************************
  330. void
  331. TimerConfigure(uint32_t ui32Base, uint32_t ui32Config)
  332. {
  333. //
  334. // Check the arguments.
  335. //
  336. ASSERT(_TimerBaseValid(ui32Base));
  337. ASSERT(((ui32Config & 0xfff0ffff) == TIMER_CFG_ONE_SHOT) ||
  338. ((ui32Config & 0xfff0ffff) == TIMER_CFG_ONE_SHOT_UP) ||
  339. ((ui32Config & 0xfff0ffff) == TIMER_CFG_PERIODIC) ||
  340. ((ui32Config & 0xfff0ffff) == TIMER_CFG_PERIODIC_UP) ||
  341. ((ui32Config & 0xfff0ffff) == TIMER_CFG_RTC) ||
  342. ((ui32Config & 0xff000000) == TIMER_CFG_SPLIT_PAIR));
  343. ASSERT(((ui32Config & 0xff000000) != TIMER_CFG_SPLIT_PAIR) ||
  344. ((((ui32Config & 0x000000ff) == TIMER_CFG_A_ONE_SHOT) ||
  345. ((ui32Config & 0x000000ff) == TIMER_CFG_A_ONE_SHOT_UP) ||
  346. ((ui32Config & 0x000000ff) == TIMER_CFG_A_PERIODIC) ||
  347. ((ui32Config & 0x000000ff) == TIMER_CFG_A_PERIODIC_UP) ||
  348. ((ui32Config & 0x000000ff) == TIMER_CFG_A_CAP_COUNT) ||
  349. ((ui32Config & 0x000000ff) == TIMER_CFG_A_CAP_COUNT_UP) ||
  350. ((ui32Config & 0x000000ff) == TIMER_CFG_A_CAP_TIME) ||
  351. ((ui32Config & 0x000000ff) == TIMER_CFG_A_CAP_TIME_UP) ||
  352. ((ui32Config & 0x000000ff) == TIMER_CFG_A_ONE_SHOT_PWM) ||
  353. ((ui32Config & 0x000000ff) == TIMER_CFG_A_PWM)) &&
  354. (((ui32Config & 0x0000ff00) == TIMER_CFG_B_ONE_SHOT) ||
  355. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_ONE_SHOT_UP) ||
  356. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_PERIODIC) ||
  357. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_PERIODIC_UP) ||
  358. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_CAP_COUNT) ||
  359. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_CAP_COUNT_UP) ||
  360. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_CAP_TIME) ||
  361. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_CAP_TIME_UP) ||
  362. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_ONE_SHOT_PWM) ||
  363. ((ui32Config & 0x0000ff00) == TIMER_CFG_B_PWM))));
  364. //
  365. // Disable the timers.
  366. //
  367. HWREG(ui32Base + TIMER_O_CTL) &= ~(TIMER_CTL_TAEN | TIMER_CTL_TBEN);
  368. //
  369. // Set the global timer configuration.
  370. //
  371. HWREG(ui32Base + TIMER_O_CFG) = ui32Config >> 24;
  372. //
  373. // Set the configuration of the A and B timers and set the TxPWMIE bit.
  374. // Note that the B timer configuration is ignored by the hardware in 32-bit
  375. // modes.
  376. //
  377. if(NEW_TIMER_CONFIGURATION)
  378. {
  379. HWREG(ui32Base + TIMER_O_TAMR) = (((ui32Config & 0x000f0000) >> 4) |
  380. (ui32Config & 0xff) |
  381. TIMER_TAMR_TAPWMIE);
  382. HWREG(ui32Base + TIMER_O_TBMR) = (((ui32Config & 0x00f00000) >> 8) |
  383. ((ui32Config >> 8) & 0xff) |
  384. TIMER_TBMR_TBPWMIE);
  385. }
  386. else
  387. {
  388. HWREG(ui32Base + TIMER_O_TAMR) = ((ui32Config & 0xff) |
  389. TIMER_TAMR_TAPWMIE);
  390. HWREG(ui32Base + TIMER_O_TBMR) = (((ui32Config >> 8) & 0xff) |
  391. TIMER_TBMR_TBPWMIE);
  392. }
  393. }
  394. //*****************************************************************************
  395. //
  396. //! Controls the output level.
  397. //!
  398. //! \param ui32Base is the base address of the timer module.
  399. //! \param ui32Timer specifies the timer(s) to adjust; must be one of
  400. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  401. //! \param bInvert specifies the output level.
  402. //!
  403. //! This function configures the PWM output level for the specified timer. If
  404. //! the \e bInvert parameter is \b true, then the timer's output is made active
  405. //! low; otherwise, it is made active high.
  406. //!
  407. //! \return None.
  408. //
  409. //*****************************************************************************
  410. void
  411. TimerControlLevel(uint32_t ui32Base, uint32_t ui32Timer, bool bInvert)
  412. {
  413. //
  414. // Check the arguments.
  415. //
  416. ASSERT(_TimerBaseValid(ui32Base));
  417. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  418. (ui32Timer == TIMER_BOTH));
  419. //
  420. // Set the output levels as requested.
  421. //
  422. ui32Timer &= TIMER_CTL_TAPWML | TIMER_CTL_TBPWML;
  423. HWREG(ui32Base + TIMER_O_CTL) = (bInvert ?
  424. (HWREG(ui32Base + TIMER_O_CTL) |
  425. ui32Timer) :
  426. (HWREG(ui32Base + TIMER_O_CTL) &
  427. ~(ui32Timer)));
  428. }
  429. //*****************************************************************************
  430. //
  431. //! Enables or disables the ADC trigger output.
  432. //!
  433. //! \param ui32Base is the base address of the timer module.
  434. //! \param ui32Timer specifies the timer to adjust; must be one of \b TIMER_A,
  435. //! \b TIMER_B, or \b TIMER_BOTH.
  436. //! \param bEnable specifies the desired ADC trigger state.
  437. //!
  438. //! This function controls the ADC trigger output for the specified timer. If
  439. //! the \e bEnable parameter is \b true, then the timer's ADC output trigger is
  440. //! enabled; otherwise it is disabled.
  441. //!
  442. //! \return None.
  443. //
  444. //*****************************************************************************
  445. void
  446. TimerControlTrigger(uint32_t ui32Base, uint32_t ui32Timer,
  447. bool bEnable)
  448. {
  449. //
  450. // Check the arguments.
  451. //
  452. ASSERT(_TimerBaseValid(ui32Base));
  453. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  454. (ui32Timer == TIMER_BOTH));
  455. //
  456. // On newer devices the Timer time out ADC trigger enable must also
  457. // be set.
  458. //
  459. if(NEW_TIMER_CONFIGURATION)
  460. {
  461. uint32_t ui32Val;
  462. //
  463. // Determine which bits to set or clear in GPTMADCEV.
  464. //
  465. ui32Val = (TIMER_ADCEV_TATOADCEN | TIMER_ADCEV_TBTOADCEN);
  466. ui32Val &= ui32Timer;
  467. //
  468. // Write the GPTM ADC Event register to enable or disable the trigger
  469. // to the ADC.
  470. //
  471. HWREG(ui32Base + TIMER_O_ADCEV) = (bEnable ?
  472. (HWREG(ui32Base + TIMER_O_ADCEV) |
  473. ui32Val) :
  474. (HWREG(ui32Base + TIMER_O_ADCEV) &
  475. ~(ui32Val)));
  476. }
  477. //
  478. // Set the trigger output as requested.
  479. // Set the ADC trigger output as requested.
  480. //
  481. ui32Timer &= TIMER_CTL_TAOTE | TIMER_CTL_TBOTE;
  482. HWREG(ui32Base + TIMER_O_CTL) = (bEnable ?
  483. (HWREG(ui32Base + TIMER_O_CTL) |
  484. ui32Timer) :
  485. (HWREG(ui32Base + TIMER_O_CTL) &
  486. ~(ui32Timer)));
  487. }
  488. //*****************************************************************************
  489. //
  490. //! Controls the event type.
  491. //!
  492. //! \param ui32Base is the base address of the timer module.
  493. //! \param ui32Timer specifies the timer(s) to be adjusted; must be one of
  494. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  495. //! \param ui32Event specifies the type of event; must be one of
  496. //! \b TIMER_EVENT_POS_EDGE, \b TIMER_EVENT_NEG_EDGE, or
  497. //! \b TIMER_EVENT_BOTH_EDGES.
  498. //!
  499. //! This function configures the signal edge(s) that triggers the timer when
  500. //! in capture mode.
  501. //!
  502. //! \return None.
  503. //
  504. //*****************************************************************************
  505. void
  506. TimerControlEvent(uint32_t ui32Base, uint32_t ui32Timer,
  507. uint32_t ui32Event)
  508. {
  509. //
  510. // Check the arguments.
  511. //
  512. ASSERT(_TimerBaseValid(ui32Base));
  513. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  514. (ui32Timer == TIMER_BOTH));
  515. //
  516. // Set the event type.
  517. //
  518. ui32Timer &= TIMER_CTL_TAEVENT_M | TIMER_CTL_TBEVENT_M;
  519. HWREG(ui32Base + TIMER_O_CTL) = ((HWREG(ui32Base + TIMER_O_CTL) &
  520. ~ui32Timer) | (ui32Event & ui32Timer));
  521. }
  522. //*****************************************************************************
  523. //
  524. //! Controls the stall handling.
  525. //!
  526. //! \param ui32Base is the base address of the timer module.
  527. //! \param ui32Timer specifies the timer(s) to be adjusted; must be one of
  528. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  529. //! \param bStall specifies the response to a stall signal.
  530. //!
  531. //! This function controls the stall response for the specified timer. If the
  532. //! \e bStall parameter is \b true, then the timer stops counting if the
  533. //! processor enters debug mode; otherwise the timer keeps running while in
  534. //! debug mode.
  535. //!
  536. //! \return None.
  537. //
  538. //*****************************************************************************
  539. void
  540. TimerControlStall(uint32_t ui32Base, uint32_t ui32Timer,
  541. bool bStall)
  542. {
  543. //
  544. // Check the arguments.
  545. //
  546. ASSERT(_TimerBaseValid(ui32Base));
  547. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  548. (ui32Timer == TIMER_BOTH));
  549. //
  550. // Set the stall mode.
  551. //
  552. ui32Timer &= TIMER_CTL_TASTALL | TIMER_CTL_TBSTALL;
  553. HWREG(ui32Base + TIMER_O_CTL) = (bStall ?
  554. (HWREG(ui32Base + TIMER_O_CTL) |
  555. ui32Timer) :
  556. (HWREG(ui32Base + TIMER_O_CTL) &
  557. ~(ui32Timer)));
  558. }
  559. //*****************************************************************************
  560. //
  561. //! Controls the wait on trigger handling.
  562. //!
  563. //! \param ui32Base is the base address of the timer module.
  564. //! \param ui32Timer specifies the timer(s) to be adjusted; must be one of
  565. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  566. //! \param bWait specifies if the timer should wait for a trigger input.
  567. //!
  568. //! This function controls whether or not a timer waits for a trigger input to
  569. //! start counting. When enabled, the previous timer in the trigger chain must
  570. //! count to its timeout in order for this timer to start counting. Refer to
  571. //! the part's data sheet for a description of the trigger chain.
  572. //!
  573. //! \note This functionality is not available on all parts. This function
  574. //! should not be used for Timer 0A or Wide Timer 0A.
  575. //!
  576. //! \return None.
  577. //
  578. //*****************************************************************************
  579. void
  580. TimerControlWaitOnTrigger(uint32_t ui32Base, uint32_t ui32Timer,
  581. bool bWait)
  582. {
  583. //
  584. // Check the arguments.
  585. //
  586. ASSERT(_TimerBaseValid(ui32Base));
  587. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  588. (ui32Timer == TIMER_BOTH));
  589. //
  590. // Set the wait on trigger mode for timer A.
  591. //
  592. if((ui32Timer & TIMER_A) != 0)
  593. {
  594. if(bWait)
  595. {
  596. HWREG(ui32Base + TIMER_O_TAMR) |= TIMER_TAMR_TAWOT;
  597. }
  598. else
  599. {
  600. HWREG(ui32Base + TIMER_O_TAMR) &= ~(TIMER_TAMR_TAWOT);
  601. }
  602. }
  603. //
  604. // Set the wait on trigger mode for timer B.
  605. //
  606. if((ui32Timer & TIMER_B) != 0)
  607. {
  608. if(bWait)
  609. {
  610. HWREG(ui32Base + TIMER_O_TBMR) |= TIMER_TBMR_TBWOT;
  611. }
  612. else
  613. {
  614. HWREG(ui32Base + TIMER_O_TBMR) &= ~(TIMER_TBMR_TBWOT);
  615. }
  616. }
  617. }
  618. //*****************************************************************************
  619. //
  620. //! Enables RTC counting.
  621. //!
  622. //! \param ui32Base is the base address of the timer module.
  623. //!
  624. //! This function causes the timer to start counting when in RTC mode. If not
  625. //! configured for RTC mode, this function does nothing.
  626. //!
  627. //! \return None.
  628. //
  629. //*****************************************************************************
  630. void
  631. TimerRTCEnable(uint32_t ui32Base)
  632. {
  633. //
  634. // Check the arguments.
  635. //
  636. ASSERT(_TimerBaseValid(ui32Base));
  637. //
  638. // Enable RTC counting.
  639. //
  640. HWREG(ui32Base + TIMER_O_CTL) |= TIMER_CTL_RTCEN;
  641. }
  642. //*****************************************************************************
  643. //
  644. //! Disables RTC counting.
  645. //!
  646. //! \param ui32Base is the base address of the timer module.
  647. //!
  648. //! This function causes the timer to stop counting when in RTC mode.
  649. //!
  650. //! \return None.
  651. //
  652. //*****************************************************************************
  653. void
  654. TimerRTCDisable(uint32_t ui32Base)
  655. {
  656. //
  657. // Check the arguments.
  658. //
  659. ASSERT(_TimerBaseValid(ui32Base));
  660. //
  661. // Disable RTC counting.
  662. //
  663. HWREG(ui32Base + TIMER_O_CTL) &= ~(TIMER_CTL_RTCEN);
  664. }
  665. //*****************************************************************************
  666. //
  667. //! Sets the clock source for the specified timer module.
  668. //!
  669. //! \param ui32Base is the base address of the timer module.
  670. //! \param ui32Source is the clock source for the timer module.
  671. //!
  672. //! This function sets the clock source for both timer A and timer B for the
  673. //! given timer module. The possible clock sources are the system clock
  674. //! (\b TIMER_CLOCK_SYSTEM) or the precision internal oscillator
  675. //! (\b TIMER_CLOCK_PIOSC).
  676. //!
  677. //! \note The ability to specify the timer clock source varies with the
  678. //! Tiva part in use. Please consult the data sheet for the part you are
  679. //! using to determine whether this support is available.
  680. //!
  681. //! \return None.
  682. //
  683. //*****************************************************************************
  684. void
  685. TimerClockSourceSet(uint32_t ui32Base, uint32_t ui32Source)
  686. {
  687. //
  688. // Check the arguments.
  689. //
  690. ASSERT(_TimerBaseValid(ui32Base));
  691. ASSERT((ui32Source == TIMER_CLOCK_SYSTEM) ||
  692. (ui32Source == TIMER_CLOCK_PIOSC));
  693. //
  694. // Set the timer clock source.
  695. //
  696. HWREG(ui32Base + TIMER_O_CC) = ui32Source;
  697. }
  698. //*****************************************************************************
  699. //
  700. //! Returns the clock source for the specified timer module.
  701. //!
  702. //! \param ui32Base is the base address of the timer module.
  703. //!
  704. //! This function returns the clock source for the specified timer module. The
  705. //! possible clock sources are the system clock (\b TIMER_CLOCK_SYSTEM) or
  706. //! the precision internal oscillator (\b TIMER_CLOCK_PIOSC).
  707. //!
  708. //! \note The ability to specify the timer clock source varies with the
  709. //! Tiva part in use. Please consult the data sheet for the part you are
  710. //! using to determine whether this support is available.
  711. //!
  712. //! \return Returns either \b TIMER_CLOCK_SYSTEM or \b TIMER_CLOCK_PIOSC.
  713. //
  714. //*****************************************************************************
  715. uint32_t
  716. TimerClockSourceGet(uint32_t ui32Base)
  717. {
  718. //
  719. // Check the arguments.
  720. //
  721. ASSERT(_TimerBaseValid(ui32Base));
  722. //
  723. // Return the timer clock source.
  724. //
  725. return(HWREG(ui32Base + TIMER_O_CC));
  726. }
  727. //*****************************************************************************
  728. //
  729. //! Sets the timer prescale value.
  730. //!
  731. //! \param ui32Base is the base address of the timer module.
  732. //! \param ui32Timer specifies the timer(s) to adjust; must be one of
  733. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  734. //! \param ui32Value is the timer prescale value which must be between 0 and
  735. //! 255 (inclusive) for 16/32-bit timers and between 0 and 65535 (inclusive)
  736. //! for 32/64-bit timers.
  737. //!
  738. //! This function configures the value of the input clock prescaler. The
  739. //! prescaler is only operational when in half-width mode and is used to extend
  740. //! the range of the half-width timer modes. The prescaler provides the least
  741. //! significant bits when counting down in periodic and one-shot modes; in all
  742. //! other modes, the prescaler provides the most significant bits.
  743. //!
  744. //! \note The availability of the prescaler varies with the Tiva part and
  745. //! timer mode in use. Please consult the datasheet for the part you are using
  746. //! to determine whether this support is available.
  747. //!
  748. //! \return None.
  749. //
  750. //*****************************************************************************
  751. void
  752. TimerPrescaleSet(uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Value)
  753. {
  754. //
  755. // Check the arguments.
  756. //
  757. ASSERT(_TimerBaseValid(ui32Base));
  758. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  759. (ui32Timer == TIMER_BOTH));
  760. ASSERT(ui32Value < 256);
  761. //
  762. // Set the timer A prescaler if requested.
  763. //
  764. if(ui32Timer & TIMER_A)
  765. {
  766. HWREG(ui32Base + TIMER_O_TAPR) = ui32Value;
  767. }
  768. //
  769. // Set the timer B prescaler if requested.
  770. //
  771. if(ui32Timer & TIMER_B)
  772. {
  773. HWREG(ui32Base + TIMER_O_TBPR) = ui32Value;
  774. }
  775. }
  776. //*****************************************************************************
  777. //
  778. //! Gets the timer prescale value.
  779. //!
  780. //! \param ui32Base is the base address of the timer module.
  781. //! \param ui32Timer specifies the timer; must be one of \b TIMER_A or
  782. //! \b TIMER_B.
  783. //!
  784. //! This function gets the value of the input clock prescaler. The prescaler
  785. //! is only operational when in half-width mode and is used to extend the range
  786. //! of the half-width timer modes. The prescaler provides the least
  787. //! significant bits when counting down in periodic and one-shot modes; in all
  788. //! other modes, the prescaler provides the most significant bits.
  789. //!
  790. //! \note The availability of the prescaler varies with the Tiva part and
  791. //! timer mode in use. Please consult the datasheet for the part you are using
  792. //! to determine whether this support is available.
  793. //!
  794. //! \return The value of the timer prescaler.
  795. //
  796. //*****************************************************************************
  797. uint32_t
  798. TimerPrescaleGet(uint32_t ui32Base, uint32_t ui32Timer)
  799. {
  800. //
  801. // Check the arguments.
  802. //
  803. ASSERT(_TimerBaseValid(ui32Base));
  804. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  805. (ui32Timer == TIMER_BOTH));
  806. //
  807. // Return the appropriate prescale value.
  808. //
  809. return((ui32Timer == TIMER_A) ? HWREG(ui32Base + TIMER_O_TAPR) :
  810. HWREG(ui32Base + TIMER_O_TBPR));
  811. }
  812. //*****************************************************************************
  813. //
  814. //! Sets the timer prescale match value.
  815. //!
  816. //! \param ui32Base is the base address of the timer module.
  817. //! \param ui32Timer specifies the timer(s) to adjust; must be one of
  818. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH.
  819. //! \param ui32Value is the timer prescale match value which must be between 0
  820. //! and 255 (inclusive) for 16/32-bit timers and between 0 and 65535
  821. //! (inclusive) for 32/64-bit timers.
  822. //!
  823. //! This function configures the value of the input clock prescaler match
  824. //! value. When in a half-width mode that uses the counter match and the
  825. //! prescaler, the prescale match effectively extends the range of the match.
  826. //! The prescaler provides the least significant bits when counting down in
  827. //! periodic and one-shot modes; in all other modes, the prescaler provides the
  828. //! most significant bits.
  829. //!
  830. //! \note The availability of the prescaler match varies with the Tiva
  831. //! part and timer mode in use. Please consult the datasheet for the part you
  832. //! are using to determine whether this support is available.
  833. //!
  834. //! \return None.
  835. //
  836. //*****************************************************************************
  837. void
  838. TimerPrescaleMatchSet(uint32_t ui32Base, uint32_t ui32Timer,
  839. uint32_t ui32Value)
  840. {
  841. //
  842. // Check the arguments.
  843. //
  844. ASSERT(_TimerBaseValid(ui32Base));
  845. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  846. (ui32Timer == TIMER_BOTH));
  847. ASSERT(ui32Value < 256);
  848. //
  849. // Set the timer A prescale match if requested.
  850. //
  851. if(ui32Timer & TIMER_A)
  852. {
  853. HWREG(ui32Base + TIMER_O_TAPMR) = ui32Value;
  854. }
  855. //
  856. // Set the timer B prescale match if requested.
  857. //
  858. if(ui32Timer & TIMER_B)
  859. {
  860. HWREG(ui32Base + TIMER_O_TBPMR) = ui32Value;
  861. }
  862. }
  863. //*****************************************************************************
  864. //
  865. //! Gets the timer prescale match value.
  866. //!
  867. //! \param ui32Base is the base address of the timer module.
  868. //! \param ui32Timer specifies the timer; must be one of \b TIMER_A or
  869. //! \b TIMER_B.
  870. //!
  871. //! This function gets the value of the input clock prescaler match value.
  872. //! When in a half-width mode that uses the counter match and prescaler, the
  873. //! prescale match effectively extends the range of the match. The prescaler
  874. //! provides the least significant bits when counting down in periodic and
  875. //! one-shot modes; in all other modes, the prescaler provides the most
  876. //! significant bits.
  877. //!
  878. //! \note The availability of the prescaler match varies with the Tiva
  879. //! part and timer mode in use. Please consult the datasheet for the part you
  880. //! are using to determine whether this support is available.
  881. //!
  882. //! \return The value of the timer prescale match.
  883. //
  884. //*****************************************************************************
  885. uint32_t
  886. TimerPrescaleMatchGet(uint32_t ui32Base, uint32_t ui32Timer)
  887. {
  888. //
  889. // Check the arguments.
  890. //
  891. ASSERT(_TimerBaseValid(ui32Base));
  892. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  893. (ui32Timer == TIMER_BOTH));
  894. //
  895. // Return the appropriate prescale match value.
  896. //
  897. return((ui32Timer == TIMER_A) ? HWREG(ui32Base + TIMER_O_TAPMR) :
  898. HWREG(ui32Base + TIMER_O_TBPMR));
  899. }
  900. //*****************************************************************************
  901. //
  902. //! Sets the timer load value.
  903. //!
  904. //! \param ui32Base is the base address of the timer module.
  905. //! \param ui32Timer specifies the timer(s) to adjust; must be one of
  906. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH. Only \b TIMER_A should be used
  907. //! when the timer is configured for full-width operation.
  908. //! \param ui32Value is the load value.
  909. //!
  910. //! This function configures the timer load value; if the timer is running then
  911. //! the value is immediately loaded into the timer.
  912. //!
  913. //! \note This function can be used for both full- and half-width modes of
  914. //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
  915. //! TimerLoadSet64() for full-width modes of 32/64-bit timers.
  916. //!
  917. //! \return None.
  918. //
  919. //*****************************************************************************
  920. void
  921. TimerLoadSet(uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Value)
  922. {
  923. //
  924. // Check the arguments.
  925. //
  926. ASSERT(_TimerBaseValid(ui32Base));
  927. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  928. (ui32Timer == TIMER_BOTH));
  929. //
  930. // Set the timer A load value if requested.
  931. //
  932. if(ui32Timer & TIMER_A)
  933. {
  934. HWREG(ui32Base + TIMER_O_TAILR) = ui32Value;
  935. }
  936. //
  937. // Set the timer B load value if requested.
  938. //
  939. if(ui32Timer & TIMER_B)
  940. {
  941. HWREG(ui32Base + TIMER_O_TBILR) = ui32Value;
  942. }
  943. }
  944. //*****************************************************************************
  945. //
  946. //! Gets the timer load value.
  947. //!
  948. //! \param ui32Base is the base address of the timer module.
  949. //! \param ui32Timer specifies the timer; must be one of \b TIMER_A or
  950. //! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
  951. //! for full-width operation.
  952. //!
  953. //! This function gets the currently programmed interval load value for the
  954. //! specified timer.
  955. //!
  956. //! \note This function can be used for both full- and half-width modes of
  957. //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
  958. //! TimerLoadGet64() for full-width modes of 32/64-bit timers.
  959. //!
  960. //! \return Returns the load value for the timer.
  961. //
  962. //*****************************************************************************
  963. uint32_t
  964. TimerLoadGet(uint32_t ui32Base, uint32_t ui32Timer)
  965. {
  966. //
  967. // Check the arguments.
  968. //
  969. ASSERT(_TimerBaseValid(ui32Base));
  970. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B));
  971. //
  972. // Return the appropriate load value.
  973. //
  974. return((ui32Timer == TIMER_A) ? HWREG(ui32Base + TIMER_O_TAILR) :
  975. HWREG(ui32Base + TIMER_O_TBILR));
  976. }
  977. //*****************************************************************************
  978. //
  979. //! Sets the timer load value for a 64-bit timer.
  980. //!
  981. //! \param ui32Base is the base address of the timer module.
  982. //! \param ui64Value is the load value.
  983. //!
  984. //! This function configures the timer load value for a 64-bit timer; if the
  985. //! timer is running, then the value is immediately loaded into the timer.
  986. //!
  987. //! \return None.
  988. //
  989. //*****************************************************************************
  990. void
  991. TimerLoadSet64(uint32_t ui32Base, uint64_t ui64Value)
  992. {
  993. //
  994. // Check the arguments.
  995. //
  996. ASSERT(_TimerBaseValid(ui32Base));
  997. //
  998. // Set the timer load value. The upper 32-bits must be written before the
  999. // lower 32-bits in order to adhere to the hardware interlocks on the
  1000. // 64-bit value.
  1001. //
  1002. HWREG(ui32Base + TIMER_O_TBILR) = ui64Value >> 32;
  1003. HWREG(ui32Base + TIMER_O_TAILR) = ui64Value & 0xffffffff;
  1004. }
  1005. //*****************************************************************************
  1006. //
  1007. //! Gets the timer load value for a 64-bit timer.
  1008. //!
  1009. //! \param ui32Base is the base address of the timer module.
  1010. //!
  1011. //! This function gets the currently programmed interval load value for the
  1012. //! specified 64-bit timer.
  1013. //!
  1014. //! \return Returns the load value for the timer.
  1015. //
  1016. //*****************************************************************************
  1017. uint64_t
  1018. TimerLoadGet64(uint32_t ui32Base)
  1019. {
  1020. uint32_t ui32High1, ui32High2, ui32Low;
  1021. //
  1022. // Check the arguments.
  1023. //
  1024. ASSERT(_TimerBaseValid(ui32Base));
  1025. //
  1026. // Read the 64-bit load value. A read of the low 32-bits is performed
  1027. // between two reads of the upper 32-bits; if the upper 32-bit values match
  1028. // then the 64-bit value is consistent. If they do not match, then the
  1029. // read is performed again until they do match (it should never execute the
  1030. // loop body more than twice).
  1031. //
  1032. do
  1033. {
  1034. ui32High1 = HWREG(ui32Base + TIMER_O_TBILR);
  1035. ui32Low = HWREG(ui32Base + TIMER_O_TAILR);
  1036. ui32High2 = HWREG(ui32Base + TIMER_O_TBILR);
  1037. }
  1038. while(ui32High1 != ui32High2);
  1039. //
  1040. // Return the load value.
  1041. //
  1042. return(((uint64_t)ui32High1 << 32) | (uint64_t)ui32Low);
  1043. }
  1044. //*****************************************************************************
  1045. //
  1046. //! Gets the current timer value.
  1047. //!
  1048. //! \param ui32Base is the base address of the timer module.
  1049. //! \param ui32Timer specifies the timer; must be one of \b TIMER_A or
  1050. //! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
  1051. //! for full-width operation.
  1052. //!
  1053. //! This function reads the current value of the specified timer.
  1054. //!
  1055. //! \note This function can be used for both full- and half-width modes of
  1056. //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
  1057. //! TimerValueGet64() for full-width modes of 32/64-bit timers.
  1058. //!
  1059. //! \return Returns the current value of the timer.
  1060. //
  1061. //*****************************************************************************
  1062. uint32_t
  1063. TimerValueGet(uint32_t ui32Base, uint32_t ui32Timer)
  1064. {
  1065. //
  1066. // Check the arguments.
  1067. //
  1068. ASSERT(_TimerBaseValid(ui32Base));
  1069. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B));
  1070. //
  1071. // Return the appropriate timer value.
  1072. //
  1073. return((ui32Timer == TIMER_A) ? HWREG(ui32Base + TIMER_O_TAR) :
  1074. HWREG(ui32Base + TIMER_O_TBR));
  1075. }
  1076. //*****************************************************************************
  1077. //
  1078. //! Gets the current 64-bit timer value.
  1079. //!
  1080. //! \param ui32Base is the base address of the timer module.
  1081. //!
  1082. //! This function reads the current value of the specified timer.
  1083. //!
  1084. //! \return Returns the current value of the timer.
  1085. //
  1086. //*****************************************************************************
  1087. uint64_t
  1088. TimerValueGet64(uint32_t ui32Base)
  1089. {
  1090. uint32_t ui32High1, ui32High2, ui32Low;
  1091. //
  1092. // Check the arguments.
  1093. //
  1094. ASSERT(_TimerBaseValid(ui32Base));
  1095. //
  1096. // Read the 64-bit timer value. A read of the low 32-bits is performed
  1097. // between two reads of the upper 32-bits; if the upper 32-bit values match
  1098. // then the 64-bit value is consistent. If they do not match, then the
  1099. // read is performed again until they do match (it should never execute the
  1100. // loop body more than twice).
  1101. //
  1102. do
  1103. {
  1104. ui32High1 = HWREG(ui32Base + TIMER_O_TBR);
  1105. ui32Low = HWREG(ui32Base + TIMER_O_TAR);
  1106. ui32High2 = HWREG(ui32Base + TIMER_O_TBR);
  1107. }
  1108. while(ui32High1 != ui32High2);
  1109. //
  1110. // Return the timer value.
  1111. //
  1112. return(((uint64_t)ui32High1 << 32) | (uint64_t)ui32Low);
  1113. }
  1114. //*****************************************************************************
  1115. //
  1116. //! Sets the timer match value.
  1117. //!
  1118. //! \param ui32Base is the base address of the timer module.
  1119. //! \param ui32Timer specifies the timer(s) to adjust; must be one of
  1120. //! \b TIMER_A, \b TIMER_B, or \b TIMER_BOTH. Only \b TIMER_A should be used
  1121. //! when the timer is configured for full-width operation.
  1122. //! \param ui32Value is the match value.
  1123. //!
  1124. //! This function configures the match value for a timer. This value is used
  1125. //! in capture count mode to determine when to interrupt the processor and in
  1126. //! PWM mode to determine the duty cycle of the output signal. On some
  1127. //! Tiva devices, match interrupts can also be generated in periodic and
  1128. //! one-shot modes.
  1129. //!
  1130. //! \note This function can be used for both full- and half-width modes of
  1131. //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
  1132. //! TimerMatchSet64() for full-width modes of 32/64-bit timers.
  1133. //!
  1134. //! \return None.
  1135. //
  1136. //*****************************************************************************
  1137. void
  1138. TimerMatchSet(uint32_t ui32Base, uint32_t ui32Timer,
  1139. uint32_t ui32Value)
  1140. {
  1141. //
  1142. // Check the arguments.
  1143. //
  1144. ASSERT(_TimerBaseValid(ui32Base));
  1145. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  1146. (ui32Timer == TIMER_BOTH));
  1147. //
  1148. // Set the timer A match value if requested.
  1149. //
  1150. if(ui32Timer & TIMER_A)
  1151. {
  1152. HWREG(ui32Base + TIMER_O_TAMATCHR) = ui32Value;
  1153. }
  1154. //
  1155. // Set the timer B match value if requested.
  1156. //
  1157. if(ui32Timer & TIMER_B)
  1158. {
  1159. HWREG(ui32Base + TIMER_O_TBMATCHR) = ui32Value;
  1160. }
  1161. }
  1162. //*****************************************************************************
  1163. //
  1164. //! Gets the timer match value.
  1165. //!
  1166. //! \param ui32Base is the base address of the timer module.
  1167. //! \param ui32Timer specifies the timer; must be one of \b TIMER_A or
  1168. //! \b TIMER_B. Only \b TIMER_A should be used when the timer is configured
  1169. //! for full-width operation.
  1170. //!
  1171. //! This function gets the match value for the specified timer.
  1172. //!
  1173. //! \note This function can be used for both full- and half-width modes of
  1174. //! 16/32-bit timers and for half-width modes of 32/64-bit timers. Use
  1175. //! TimerMatchGet64() for full-width modes of 32/64-bit timers.
  1176. //!
  1177. //! \return Returns the match value for the timer.
  1178. //
  1179. //*****************************************************************************
  1180. uint32_t
  1181. TimerMatchGet(uint32_t ui32Base, uint32_t ui32Timer)
  1182. {
  1183. //
  1184. // Check the arguments.
  1185. //
  1186. ASSERT(_TimerBaseValid(ui32Base));
  1187. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B));
  1188. //
  1189. // Return the appropriate match value.
  1190. //
  1191. return((ui32Timer == TIMER_A) ? HWREG(ui32Base + TIMER_O_TAMATCHR) :
  1192. HWREG(ui32Base + TIMER_O_TBMATCHR));
  1193. }
  1194. //*****************************************************************************
  1195. //
  1196. //! Sets the timer match value for a 64-bit timer.
  1197. //!
  1198. //! \param ui32Base is the base address of the timer module.
  1199. //! \param ui64Value is the match value.
  1200. //!
  1201. //! This function configures the match value for a timer. This value is used
  1202. //! in capture count mode to determine when to interrupt the processor and in
  1203. //! PWM mode to determine the duty cycle of the output signal.
  1204. //!
  1205. //! \return None.
  1206. //
  1207. //*****************************************************************************
  1208. void
  1209. TimerMatchSet64(uint32_t ui32Base, uint64_t ui64Value)
  1210. {
  1211. //
  1212. // Check the arguments.
  1213. //
  1214. ASSERT(_TimerBaseValid(ui32Base));
  1215. //
  1216. // Set the timer match value. The upper 32-bits must be written before the
  1217. // lower 32-bits in order to adhere to the hardware interlocks on the
  1218. // 64-bit value.
  1219. //
  1220. HWREG(ui32Base + TIMER_O_TBMATCHR) = ui64Value >> 32;
  1221. HWREG(ui32Base + TIMER_O_TAMATCHR) = ui64Value & 0xffffffff;
  1222. }
  1223. //*****************************************************************************
  1224. //
  1225. //! Gets the timer match value for a 64-bit timer.
  1226. //!
  1227. //! \param ui32Base is the base address of the timer module.
  1228. //!
  1229. //! This function gets the match value for the specified timer.
  1230. //!
  1231. //! \return Returns the match value for the timer.
  1232. //
  1233. //*****************************************************************************
  1234. uint64_t
  1235. TimerMatchGet64(uint32_t ui32Base)
  1236. {
  1237. uint32_t ui32High1, ui32High2, ui32Low;
  1238. //
  1239. // Check the arguments.
  1240. //
  1241. ASSERT(_TimerBaseValid(ui32Base));
  1242. //
  1243. // Read the 64-bit match value. A read of the low 32-bits is performed
  1244. // between two reads of the upper 32-bits; if the upper 32-bit values match
  1245. // then the 64-bit value is consistent. If they do not match, then the
  1246. // read is performed again until they do match (it should never execute the
  1247. // loop body more than twice).
  1248. //
  1249. do
  1250. {
  1251. ui32High1 = HWREG(ui32Base + TIMER_O_TBMATCHR);
  1252. ui32Low = HWREG(ui32Base + TIMER_O_TAMATCHR);
  1253. ui32High2 = HWREG(ui32Base + TIMER_O_TBMATCHR);
  1254. }
  1255. while(ui32High1 != ui32High2);
  1256. //
  1257. // Return the match value.
  1258. //
  1259. return(((uint64_t)ui32High1 << 32) | (uint64_t)ui32Low);
  1260. }
  1261. //*****************************************************************************
  1262. //
  1263. //! Registers an interrupt handler for the timer interrupt.
  1264. //!
  1265. //! \param ui32Base is the base address of the timer module.
  1266. //! \param ui32Timer specifies the timer(s); must be one of \b TIMER_A,
  1267. //! \b TIMER_B, or \b TIMER_BOTH.
  1268. //! \param pfnHandler is a pointer to the function to be called when the timer
  1269. //! interrupt occurs.
  1270. //!
  1271. //! This function registers the handler to be called when a timer interrupt
  1272. //! occurs. In addition, this function enables the global interrupt in the
  1273. //! interrupt controller; specific timer interrupts must be enabled via
  1274. //! TimerIntEnable(). It is the interrupt handler's responsibility to clear
  1275. //! the interrupt source via TimerIntClear().
  1276. //!
  1277. //! \sa IntRegister() for important information about registering interrupt
  1278. //! handlers.
  1279. //!
  1280. //! \return None.
  1281. //
  1282. //*****************************************************************************
  1283. void
  1284. TimerIntRegister(uint32_t ui32Base, uint32_t ui32Timer,
  1285. void (*pfnHandler)(void))
  1286. {
  1287. uint32_t ui32Int;
  1288. //
  1289. // Check the arguments.
  1290. //
  1291. ASSERT(_TimerBaseValid(ui32Base));
  1292. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  1293. (ui32Timer == TIMER_BOTH));
  1294. //
  1295. // Get the interrupt number for this timer module.
  1296. //
  1297. ui32Int = _TimerIntNumberGet(ui32Base, ui32Timer);
  1298. ASSERT(ui32Int != 0);
  1299. //
  1300. // Register the interrupt handler.
  1301. //
  1302. IntRegister(ui32Int, pfnHandler);
  1303. //
  1304. // Enable the interrupt.
  1305. //
  1306. IntEnable(ui32Int);
  1307. }
  1308. //*****************************************************************************
  1309. //
  1310. //! Unregisters an interrupt handler for the timer interrupt.
  1311. //!
  1312. //! \param ui32Base is the base address of the timer module.
  1313. //! \param ui32Timer specifies the timer(s); must be one of \b TIMER_A,
  1314. //! \b TIMER_B, or \b TIMER_BOTH.
  1315. //!
  1316. //! This function unregisters the handler to be called when a timer interrupt
  1317. //! occurs. This function also masks off the interrupt in the interrupt
  1318. //! controller so that the interrupt handler is no longer called.
  1319. //!
  1320. //! \sa IntRegister() for important information about registering interrupt
  1321. //! handlers.
  1322. //!
  1323. //! \return None.
  1324. //
  1325. //*****************************************************************************
  1326. void
  1327. TimerIntUnregister(uint32_t ui32Base, uint32_t ui32Timer)
  1328. {
  1329. uint32_t ui32Int;
  1330. //
  1331. // Check the arguments.
  1332. //
  1333. ASSERT(_TimerBaseValid(ui32Base));
  1334. ASSERT((ui32Timer == TIMER_A) || (ui32Timer == TIMER_B) ||
  1335. (ui32Timer == TIMER_BOTH));
  1336. //
  1337. // Get the interrupt number for this timer module.
  1338. //
  1339. ui32Int = _TimerIntNumberGet(ui32Base, ui32Timer);
  1340. //
  1341. // Disable the interrupt.
  1342. //
  1343. IntDisable(ui32Int);
  1344. //
  1345. // Unregister the interrupt handler.
  1346. //
  1347. IntUnregister(ui32Int);
  1348. }
  1349. //*****************************************************************************
  1350. //
  1351. //! Enables individual timer interrupt sources.
  1352. //!
  1353. //! \param ui32Base is the base address of the timer module.
  1354. //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
  1355. //!
  1356. //! This function enables the indicated timer interrupt sources. Only the
  1357. //! sources that are enabled can be reflected to the processor interrupt;
  1358. //! disabled sources have no effect on the processor.
  1359. //!
  1360. //! The \e ui32IntFlags parameter must be the logical OR of any combination of
  1361. //! the following:
  1362. //!
  1363. //! - \b TIMER_TIMB_DMA - Timer B uDMA complete
  1364. //! - \b TIMER_TIMA_DMA - Timer A uDMA complete
  1365. //! - \b TIMER_CAPB_EVENT - Capture B event interrupt
  1366. //! - \b TIMER_CAPB_MATCH - Capture B match interrupt
  1367. //! - \b TIMER_TIMB_MATCH - Timer B match interrupt
  1368. //! - \b TIMER_TIMB_TIMEOUT - Timer B timeout interrupt
  1369. //! - \b TIMER_RTC_MATCH - RTC interrupt mask
  1370. //! - \b TIMER_CAPA_EVENT - Capture A event interrupt
  1371. //! - \b TIMER_CAPA_MATCH - Capture A match interrupt
  1372. //! - \b TIMER_TIMA_MATCH - Timer A match interrupt
  1373. //! - \b TIMER_TIMA_TIMEOUT - Timer A timeout interrupt
  1374. //!
  1375. //! \return None.
  1376. //
  1377. //*****************************************************************************
  1378. void
  1379. TimerIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
  1380. {
  1381. //
  1382. // Check the arguments.
  1383. //
  1384. ASSERT(_TimerBaseValid(ui32Base));
  1385. //
  1386. // Enable the specified interrupts.
  1387. //
  1388. HWREG(ui32Base + TIMER_O_IMR) |= ui32IntFlags;
  1389. }
  1390. //*****************************************************************************
  1391. //
  1392. //! Disables individual timer interrupt sources.
  1393. //!
  1394. //! \param ui32Base is the base address of the timer module.
  1395. //! \param ui32IntFlags is the bit mask of the interrupt sources to be
  1396. //! disabled.
  1397. //!
  1398. //! This function disables the indicated timer interrupt sources. Only the
  1399. //! sources that are enabled can be reflected to the processor interrupt;
  1400. //! disabled sources have no effect on the processor.
  1401. //!
  1402. //! The \e ui32IntFlags parameter has the same definition as the
  1403. //! \e ui32IntFlags parameter to TimerIntEnable().
  1404. //!
  1405. //! \return None.
  1406. //
  1407. //*****************************************************************************
  1408. void
  1409. TimerIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
  1410. {
  1411. //
  1412. // Check the arguments.
  1413. //
  1414. ASSERT(_TimerBaseValid(ui32Base));
  1415. //
  1416. // Disable the specified interrupts.
  1417. //
  1418. HWREG(ui32Base + TIMER_O_IMR) &= ~(ui32IntFlags);
  1419. }
  1420. //*****************************************************************************
  1421. //
  1422. //! Gets the current interrupt status.
  1423. //!
  1424. //! \param ui32Base is the base address of the timer module.
  1425. //! \param bMasked is false if the raw interrupt status is required and true if
  1426. //! the masked interrupt status is required.
  1427. //!
  1428. //! This function returns the interrupt status for the timer module. Either
  1429. //! the raw interrupt status or the status of interrupts that are allowed to
  1430. //! reflect to the processor can be returned.
  1431. //!
  1432. //! \return The current interrupt status, enumerated as a bit field of
  1433. //! values described in TimerIntEnable().
  1434. //
  1435. //*****************************************************************************
  1436. uint32_t
  1437. TimerIntStatus(uint32_t ui32Base, bool bMasked)
  1438. {
  1439. //
  1440. // Check the arguments.
  1441. //
  1442. ASSERT(_TimerBaseValid(ui32Base));
  1443. //
  1444. // Return either the interrupt status or the raw interrupt status as
  1445. // requested.
  1446. //
  1447. return(bMasked ? HWREG(ui32Base + TIMER_O_MIS) :
  1448. HWREG(ui32Base + TIMER_O_RIS));
  1449. }
  1450. //*****************************************************************************
  1451. //
  1452. //! Clears timer interrupt sources.
  1453. //!
  1454. //! \param ui32Base is the base address of the timer module.
  1455. //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
  1456. //!
  1457. //! The specified timer interrupt sources are cleared, so that they no longer
  1458. //! assert. This function must be called in the interrupt handler to keep the
  1459. //! interrupt from being triggered again immediately upon exit.
  1460. //!
  1461. //! The \e ui32IntFlags parameter has the same definition as the
  1462. //! \e ui32IntFlags parameter to TimerIntEnable().
  1463. //!
  1464. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1465. //! take several clock cycles before the interrupt source is actually cleared.
  1466. //! Therefore, it is recommended that the interrupt source be cleared early in
  1467. //! the interrupt handler (as opposed to the very last action) to avoid
  1468. //! returning from the interrupt handler before the interrupt source is
  1469. //! actually cleared. Failure to do so may result in the interrupt handler
  1470. //! being immediately reentered (because the interrupt controller still sees
  1471. //! the interrupt source asserted).
  1472. //!
  1473. //! \return None.
  1474. //
  1475. //*****************************************************************************
  1476. void
  1477. TimerIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
  1478. {
  1479. //
  1480. // Check the arguments.
  1481. //
  1482. ASSERT(_TimerBaseValid(ui32Base));
  1483. //
  1484. // Clear the requested interrupt sources.
  1485. //
  1486. HWREG(ui32Base + TIMER_O_ICR) = ui32IntFlags;
  1487. }
  1488. //*****************************************************************************
  1489. //
  1490. //! Synchronizes the counters in a set of timers.
  1491. //!
  1492. //! \param ui32Base is the base address of the timer module. This parameter
  1493. //! must be the base address of Timer0 (in other words, \b TIMER0_BASE).
  1494. //! \param ui32Timers is the set of timers to synchronize.
  1495. //!
  1496. //! This function synchronizes the counters in a specified set of timers.
  1497. //! When a timer is running in half-width mode, each half can be included or
  1498. //! excluded in the synchronization event. When a timer is running in
  1499. //! full-width mode, only the A timer can be synchronized (specifying the B
  1500. //! timer has no effect).
  1501. //!
  1502. //! The \e ui32Timers parameter is the logical OR of any of the following
  1503. //! defines:
  1504. //!
  1505. //! - \b TIMER_0A_SYNC
  1506. //! - \b TIMER_0B_SYNC
  1507. //! - \b TIMER_1A_SYNC
  1508. //! - \b TIMER_1B_SYNC
  1509. //! - \b TIMER_2A_SYNC
  1510. //! - \b TIMER_2B_SYNC
  1511. //! - \b TIMER_3A_SYNC
  1512. //! - \b TIMER_3B_SYNC
  1513. //! - \b TIMER_4A_SYNC
  1514. //! - \b TIMER_4B_SYNC
  1515. //! - \b TIMER_5A_SYNC
  1516. //! - \b TIMER_5B_SYNC
  1517. //! - \b WTIMER_0A_SYNC
  1518. //! - \b WTIMER_0B_SYNC
  1519. //! - \b WTIMER_1A_SYNC
  1520. //! - \b WTIMER_1B_SYNC
  1521. //! - \b WTIMER_2A_SYNC
  1522. //! - \b WTIMER_2B_SYNC
  1523. //! - \b WTIMER_3A_SYNC
  1524. //! - \b WTIMER_3B_SYNC
  1525. //! - \b WTIMER_4A_SYNC
  1526. //! - \b WTIMER_4B_SYNC
  1527. //! - \b WTIMER_5A_SYNC
  1528. //! - \b WTIMER_5B_SYNC
  1529. //!
  1530. //! \note This functionality is not available on all parts.
  1531. //!
  1532. //! \return None.
  1533. //
  1534. //*****************************************************************************
  1535. void
  1536. TimerSynchronize(uint32_t ui32Base, uint32_t ui32Timers)
  1537. {
  1538. //
  1539. // Check the arguments.
  1540. //
  1541. ASSERT(ui32Base == TIMER0_BASE);
  1542. //
  1543. // Synchronize the specified timers.
  1544. //
  1545. HWREG(ui32Base + TIMER_O_SYNC) = ui32Timers;
  1546. }
  1547. //*****************************************************************************
  1548. //
  1549. //! Enables the events that can cause an ADC trigger event.
  1550. //!
  1551. //! \param ui32Base is the base address of the timer module.
  1552. //! \param ui32ADCEvent is a bit mask of the events that can cause an ADC
  1553. //! trigger event.
  1554. //!
  1555. //! This function enables the timer events that can cause an ADC trigger event.
  1556. //! The ADC trigger events are specified in the \e ui32ADCEvent parameter by
  1557. //! passing in the logical OR of any of the following values:
  1558. //!
  1559. //! - \b TIMER_ADC_MODEMATCH_B - Enables the mode match ADC trigger for timer
  1560. //! B.
  1561. //! - \b TIMER_ADC_CAPEVENT_B - Enables the capture event ADC trigger for
  1562. //! timer B.
  1563. //! - \b TIMER_ADC_CAPMATCH_B - Enables the capture match ADC trigger for
  1564. //! timer B.
  1565. //! - \b TIMER_ADC_TIMEOUT_B - Enables the timeout ADC trigger for timer B.
  1566. //! - \b TIMER_ADC_MODEMATCH_A - Enables the mode match ADC trigger for timer
  1567. //! A.
  1568. //! - \b TIMER_ADC_RTC_A - Enables the RTC ADC trigger for timer A.
  1569. //! - \b TIMER_ADC_CAPEVENT_A - Enables the capture event ADC trigger for
  1570. //! timer A.
  1571. //! - \b TIMER_ADC_CAPMATCH_A - Enables the capture match ADC trigger for
  1572. //! timer A.
  1573. //! - \b TIMER_ADC_TIMEOUT_A - Enables the timeout ADC trigger for timer A.
  1574. //!
  1575. //! \note The ability to specify ADC event triggers varies with the Tiva
  1576. //! part in use. Please consult the data sheet for the part you are
  1577. //! using to determine whether this support is available.
  1578. //!
  1579. //! \return None.
  1580. //
  1581. //*****************************************************************************
  1582. void
  1583. TimerADCEventSet(uint32_t ui32Base, uint32_t ui32ADCEvent)
  1584. {
  1585. //
  1586. // Check the arguments.
  1587. //
  1588. ASSERT(_TimerBaseValid(ui32Base));
  1589. //
  1590. // Set the ADC triggers.
  1591. //
  1592. HWREG(ui32Base + TIMER_O_ADCEV) = ui32ADCEvent;
  1593. }
  1594. //*****************************************************************************
  1595. //
  1596. //! Returns the events that can cause an ADC trigger event.
  1597. //!
  1598. //! \param ui32Base is the base address of the timer module.
  1599. //!
  1600. //! This function returns the timer events that can cause an ADC trigger event.
  1601. //! The ADC trigger events are the logical OR of any of the following values:
  1602. //!
  1603. //! - \b TIMER_ADC_MODEMATCH_B - The mode match ADC trigger for timer B is
  1604. //! enabled.
  1605. //! - \b TIMER_ADC_CAPEVENT_B - The capture event ADC trigger for timer B is
  1606. //! enabled.
  1607. //! - \b TIMER_ADC_CAPMATCH_B - The capture match ADC trigger for timer B is
  1608. //! enabled.
  1609. //! - \b TIMER_ADC_TIMEOUT_B - The timeout ADC trigger for timer B is enabled.
  1610. //! - \b TIMER_ADC_MODEMATCH_A - The mode match ADC trigger for timer A is
  1611. //! enabled.
  1612. //! - \b TIMER_ADC_RTC_A - The RTC ADC trigger for timer A is enabled.
  1613. //! - \b TIMER_ADC_CAPEVENT_A - The capture event ADC trigger for timer A is
  1614. //! enabled.
  1615. //! - \b TIMER_ADC_CAPMATCH_A - The capture match ADC trigger for timer A is
  1616. //! enabled.
  1617. //! - \b TIMER_ADC_TIMEOUT_A - The timeout ADC trigger for timer A is enabled.
  1618. //!
  1619. //! \note The ability to specify ADC event triggers varies with the Tiva
  1620. //! part in use. Please consult the data sheet for the part you are
  1621. //! using to determine whether this support is available.
  1622. //!
  1623. //! \return The timer events that trigger the ADC.
  1624. //
  1625. //*****************************************************************************
  1626. uint32_t
  1627. TimerADCEventGet(uint32_t ui32Base)
  1628. {
  1629. //
  1630. // Check the arguments.
  1631. //
  1632. ASSERT(_TimerBaseValid(ui32Base));
  1633. //
  1634. // Return the current ADC triggers.
  1635. //
  1636. return(HWREG(ui32Base + TIMER_O_ADCEV));
  1637. }
  1638. //*****************************************************************************
  1639. //
  1640. //! Enables the events that can trigger a uDMA request.
  1641. //!
  1642. //! \param ui32Base is the base address of the timer module.
  1643. //! \param ui32DMAEvent is a bit mask of the events that can trigger uDMA.
  1644. //!
  1645. //! This function enables the timer events that can trigger the start of a uDMA
  1646. //! sequence. The uDMA trigger events are specified in the \e ui32DMAEvent
  1647. //! parameter by passing in the logical OR of the following values:
  1648. //!
  1649. //! - \b TIMER_DMA_MODEMATCH_B - The mode match uDMA trigger for timer B is
  1650. //! enabled.
  1651. //! - \b TIMER_DMA_CAPEVENT_B - The capture event uDMA trigger for timer B is
  1652. //! enabled.
  1653. //! - \b TIMER_DMA_CAPMATCH_B - The capture match uDMA trigger for timer B is
  1654. //! enabled.
  1655. //! - \b TIMER_DMA_TIMEOUT_B - The timeout uDMA trigger for timer B is enabled.
  1656. //! - \b TIMER_DMA_MODEMATCH_A - The mode match uDMA trigger for timer A is
  1657. //! enabled.
  1658. //! - \b TIMER_DMA_RTC_A - The RTC uDMA trigger for timer A is enabled.
  1659. //! - \b TIMER_DMA_CAPEVENT_A - The capture event uDMA trigger for timer A is
  1660. //! enabled.
  1661. //! - \b TIMER_DMA_CAPMATCH_A - The capture match uDMA trigger for timer A is
  1662. //! enabled.
  1663. //! - \b TIMER_DMA_TIMEOUT_A - The timeout uDMA trigger for timer A is enabled.
  1664. //!
  1665. //! \note The ability to specify uDMA event triggers varies with the Tiva
  1666. //! part in use. Please consult the data sheet for the part you are
  1667. //! using to determine whether this support is available.
  1668. //!
  1669. //! \return None.
  1670. //
  1671. //*****************************************************************************
  1672. void
  1673. TimerDMAEventSet(uint32_t ui32Base, uint32_t ui32DMAEvent)
  1674. {
  1675. //
  1676. // Check the arguments.
  1677. //
  1678. ASSERT(_TimerBaseValid(ui32Base));
  1679. //
  1680. // Set the uDMA triggers.
  1681. //
  1682. HWREG(ui32Base + TIMER_O_DMAEV) = ui32DMAEvent;
  1683. }
  1684. //*****************************************************************************
  1685. //
  1686. //! Returns the events that can trigger a uDMA request.
  1687. //!
  1688. //! \param ui32Base is the base address of the timer module.
  1689. //!
  1690. //! This function returns the timer events that can trigger the start of a uDMA
  1691. //! sequence. The uDMA trigger events are the logical OR of the following
  1692. //! values:
  1693. //!
  1694. //! - \b TIMER_DMA_MODEMATCH_B - Enables the mode match uDMA trigger for timer
  1695. //! B.
  1696. //! - \b TIMER_DMA_CAPEVENT_B - Enables the capture event uDMA trigger for
  1697. //! timer B.
  1698. //! - \b TIMER_DMA_CAPMATCH_B - Enables the capture match uDMA trigger for
  1699. //! timer B.
  1700. //! - \b TIMER_DMA_TIMEOUT_B - Enables the timeout uDMA trigger for timer B.
  1701. //! - \b TIMER_DMA_MODEMATCH_A - Enables the mode match uDMA trigger for timer
  1702. //! A.
  1703. //! - \b TIMER_DMA_RTC_A - Enables the RTC uDMA trigger for timer A.
  1704. //! - \b TIMER_DMA_CAPEVENT_A - Enables the capture event uDMA trigger for
  1705. //! timer A.
  1706. //! - \b TIMER_DMA_CAPMATCH_A - Enables the capture match uDMA trigger for
  1707. //! timer A.
  1708. //! - \b TIMER_DMA_TIMEOUT_A - Enables the timeout uDMA trigger for timer A.
  1709. //!
  1710. //! \note The ability to specify uDMA event triggers varies with the Tiva
  1711. //! part in use. Please consult the data sheet for the part you are
  1712. //! using to determine whether this support is available.
  1713. //!
  1714. //! \return The timer events that trigger the uDMA.
  1715. //
  1716. //*****************************************************************************
  1717. uint32_t
  1718. TimerDMAEventGet(uint32_t ui32Base)
  1719. {
  1720. //
  1721. // Check the arguments.
  1722. //
  1723. ASSERT(_TimerBaseValid(ui32Base));
  1724. //
  1725. // Return the current uDMA triggers.
  1726. //
  1727. return(HWREG(ui32Base + TIMER_O_DMAEV));
  1728. }
  1729. //*****************************************************************************
  1730. //
  1731. //! This function configures the update of timer load and match settings.
  1732. //!
  1733. //! \param ui32Base is the base address of the timer module.
  1734. //! \param ui32Timer specifies the timer(s); must be one of \b TIMER_A,
  1735. //! \b TIMER_B, or \b TIMER_BOTH.
  1736. //! \param ui32Config is a combination of the updates methods for the timers
  1737. //! specified in the \e ui32Timer parameter.
  1738. //!
  1739. //! This function configures how the timer updates the timer load and match
  1740. //! values for the timers. The \e ui32Timer values can be \b TIMER_A,
  1741. //! \b TIMER_B, or \b TIMER_BOTH to apply the settings in \e ui32Config to
  1742. //! either timer or both timers. If the timer is not split then the \b TIMER_A
  1743. //! should be used. The \e ui32Config values affects when the TimerLoadSet()
  1744. //! and TimerLoadSet64() values take effect.
  1745. //!
  1746. //! - \b TIMER_UP_LOAD_IMMEDIATE is the default mode that causes the
  1747. //! TimerLoadSet() or TimerLoadSet64() to update the timer counter immediately.
  1748. //! - \b TIMER_UP_LOAD_TIMEOUT causes the TimerLoadSet() or TimerLoadSet64() to
  1749. //! update the timer when it counts down to zero.
  1750. //!
  1751. //! Similarly the \e ui32Config value affects when the TimerMatchSet() and
  1752. //! TimerMatchSet64() values take effect.
  1753. //!
  1754. //! - \b TIMER_UP_MATCH_IMMEDIATE is the default mode that causes the
  1755. //! TimerMatchSet() or TimerMatchSet64() to update the timer match value
  1756. //! immediately.
  1757. //! - \b TIMER_UP_MATCH_TIMEOUT causes the TimerMatchSet() or TimerMatchSet64()
  1758. //! to update the timer match value when it counts down to zero.
  1759. //!
  1760. //! \note These settings have no effect if the timer is not in count down mode
  1761. //! and are mostly useful when operating in PWM mode to allow for synchronous
  1762. //! update of timer match and load values.
  1763. //!
  1764. //! \return None.
  1765. //
  1766. //*****************************************************************************
  1767. void
  1768. TimerUpdateMode(uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Config)
  1769. {
  1770. uint32_t ui32Value;
  1771. if((ui32Timer & TIMER_A) == TIMER_A)
  1772. {
  1773. ui32Value = HWREG(ui32Base + TIMER_O_TAMR) & ~(0x00000500);
  1774. ui32Value |= ui32Config;
  1775. HWREG(ui32Base + TIMER_O_TAMR) = ui32Value;
  1776. }
  1777. if((ui32Timer & TIMER_B) == TIMER_B)
  1778. {
  1779. ui32Value = HWREG(ui32Base + TIMER_O_TBMR) & ~(0x00000500);
  1780. ui32Value |= ui32Config;
  1781. HWREG(ui32Base + TIMER_O_TBMR) = ui32Value;
  1782. }
  1783. }
  1784. //*****************************************************************************
  1785. //
  1786. // Close the Doxygen group.
  1787. //! @}
  1788. //
  1789. //*****************************************************************************