tiva_timer.c 64 KB

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