tiva_timer.c 64 KB

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