pwm.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162
  1. //*****************************************************************************
  2. //
  3. // pwm.c - API for the PWM modules
  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 pwm_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_pwm.h"
  50. #include "inc/hw_sysctl.h"
  51. #include "inc/hw_types.h"
  52. #include "driverlib/debug.h"
  53. #include "driverlib/interrupt.h"
  54. #include "driverlib/pwm.h"
  55. //*****************************************************************************
  56. //
  57. // Misc macros for manipulating the encoded generator and output defines used
  58. // by the API.
  59. //
  60. //*****************************************************************************
  61. #define PWM_GEN_BADDR(_mod_, _gen_) \
  62. ((_mod_) + (_gen_))
  63. #define PWM_GEN_EXT_BADDR(_mod_, _gen_) \
  64. ((_mod_) + PWM_GEN_EXT_0 + \
  65. ((_gen_) - PWM_GEN_0) * 2)
  66. #define PWM_OUT_BADDR(_mod_, _out_) \
  67. ((_mod_) + ((_out_) & 0xFFFFFFC0))
  68. #define PWM_IS_OUTPUT_ODD(_out_) \
  69. ((_out_) & 0x00000001)
  70. //*****************************************************************************
  71. //
  72. //! \internal
  73. //! Checks a PWM generator number.
  74. //!
  75. //! \param ui32Gen is the generator number.
  76. //!
  77. //! This function determines if a PWM generator number is valid.
  78. //!
  79. //! \return Returnes \b true if the generator number is valid and \b false
  80. //! otherwise.
  81. //
  82. //*****************************************************************************
  83. #ifdef DEBUG
  84. static bool
  85. _PWMGenValid(uint32_t ui32Gen)
  86. {
  87. return((ui32Gen == PWM_GEN_0) || (ui32Gen == PWM_GEN_1) ||
  88. (ui32Gen == PWM_GEN_2) || (ui32Gen == PWM_GEN_3));
  89. }
  90. #endif
  91. //*****************************************************************************
  92. //
  93. //! \internal
  94. //! Checks a PWM output number.
  95. //!
  96. //! \param ui32PWMOut is the output number.
  97. //!
  98. //! This function determines if a PWM output number is valid.
  99. //!
  100. //! \return Returns \b true if the output number is valid and \b false
  101. //! otherwise.
  102. //
  103. //*****************************************************************************
  104. #ifdef DEBUG
  105. static bool
  106. _PWMOutValid(uint32_t ui32PWMOut)
  107. {
  108. return((ui32PWMOut == PWM_OUT_0) || (ui32PWMOut == PWM_OUT_1) ||
  109. (ui32PWMOut == PWM_OUT_2) || (ui32PWMOut == PWM_OUT_3) ||
  110. (ui32PWMOut == PWM_OUT_4) || (ui32PWMOut == PWM_OUT_5) ||
  111. (ui32PWMOut == PWM_OUT_6) || (ui32PWMOut == PWM_OUT_7));
  112. }
  113. #endif
  114. //*****************************************************************************
  115. //
  116. //! Configures a PWM generator.
  117. //!
  118. //! \param ui32Base is the base address of the PWM module.
  119. //! \param ui32Gen is the PWM generator to configure. This parameter must be
  120. //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  121. //! \param ui32Config is the configuration for the PWM generator.
  122. //!
  123. //! This function is used to set the mode of operation for a PWM generator.
  124. //! The counting mode, synchronization mode, and debug behavior are all
  125. //! configured. After configuration, the generator is left in the disabled
  126. //! state.
  127. //!
  128. //! A PWM generator can count in two different modes: count down mode or count
  129. //! up/down mode. In count down mode, it counts from a value down to zero,
  130. //! and then resets to the preset value, producing left-aligned PWM
  131. //! signals (that is, the rising edge of the two PWM signals produced by the
  132. //! generator occur at the same time). In count up/down mode, it counts up
  133. //! from zero to the preset value, counts back down to zero, and then repeats
  134. //! the process, producing center-aligned PWM signals (that is,
  135. //! the middle of the high/low period of the PWM signals produced by the
  136. //! generator occurs at the same time).
  137. //!
  138. //! When the PWM generator parameters (period and pulse width) are modified,
  139. //! their effect on the output PWM signals can be delayed. In synchronous
  140. //! mode, the parameter updates are not applied until a synchronization event
  141. //! occurs. This mode allows multiple parameters to be modified and take
  142. //! effect simultaneously, instead of one at a time. Additionally, parameters
  143. //! to multiple PWM generators in synchronous mode can be updated
  144. //! simultaneously, allowing them to be treated as if they were a unified
  145. //! generator. In non-synchronous mode, the parameter updates are not delayed
  146. //! until a synchronization event. In either mode, the parameter updates only
  147. //! occur when the counter is at zero to help prevent oddly formed PWM signals
  148. //! during the update (that is, a PWM pulse that is too short or too long).
  149. //!
  150. //! The PWM generator can either pause or continue running when the processor
  151. //! is stopped via the debugger. If configured to pause, it continues to
  152. //! count until it reaches zero, at which point it pauses until the
  153. //! processor is restarted. If configured to continue running, it keeps
  154. //! counting as if nothing had happened.
  155. //!
  156. //! The \e ui32Config parameter contains the desired configuration. It is the
  157. //! logical OR of the following:
  158. //!
  159. //! - \b PWM_GEN_MODE_DOWN or \b PWM_GEN_MODE_UP_DOWN to specify the counting
  160. //! mode
  161. //! - \b PWM_GEN_MODE_SYNC or \b PWM_GEN_MODE_NO_SYNC to specify the counter
  162. //! load and comparator update synchronization mode
  163. //! - \b PWM_GEN_MODE_DBG_RUN or \b PWM_GEN_MODE_DBG_STOP to specify the debug
  164. //! behavior
  165. //! - \b PWM_GEN_MODE_GEN_NO_SYNC, \b PWM_GEN_MODE_GEN_SYNC_LOCAL, or
  166. //! \b PWM_GEN_MODE_GEN_SYNC_GLOBAL to specify the update synchronization
  167. //! mode for generator counting mode changes
  168. //! - \b PWM_GEN_MODE_DB_NO_SYNC, \b PWM_GEN_MODE_DB_SYNC_LOCAL, or
  169. //! \b PWM_GEN_MODE_DB_SYNC_GLOBAL to specify the deadband parameter
  170. //! synchronization mode
  171. //! - \b PWM_GEN_MODE_FAULT_LATCHED or \b PWM_GEN_MODE_FAULT_UNLATCHED to
  172. //! specify whether fault conditions are latched or not
  173. //! - \b PWM_GEN_MODE_FAULT_MINPER or \b PWM_GEN_MODE_FAULT_NO_MINPER to
  174. //! specify whether minimum fault period support is required
  175. //! - \b PWM_GEN_MODE_FAULT_EXT or \b PWM_GEN_MODE_FAULT_LEGACY to specify
  176. //! whether extended fault source selection support is enabled or not
  177. //!
  178. //! Setting \b PWM_GEN_MODE_FAULT_MINPER allows an application to set the
  179. //! minimum duration of a PWM fault signal. Faults are signaled for at
  180. //! least this time even if the external fault pin deasserts earlier. Care
  181. //! should be taken when using this mode because during the fault signal
  182. //! period, the fault interrupt from the PWM generator remains asserted. The
  183. //! fault interrupt handler may, therefore, reenter immediately if it exits
  184. //! prior to expiration of the fault timer.
  185. //!
  186. //! \note Changes to the counter mode affect the period of the PWM signals
  187. //! produced. PWMGenPeriodSet() and PWMPulseWidthSet() should be called after
  188. //! any changes to the counter mode of a generator.
  189. //!
  190. //! \return None.
  191. //
  192. //*****************************************************************************
  193. void
  194. PWMGenConfigure(uint32_t ui32Base, uint32_t ui32Gen,
  195. uint32_t ui32Config)
  196. {
  197. //
  198. // Check the arguments.
  199. //
  200. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  201. ASSERT(_PWMGenValid(ui32Gen));
  202. //
  203. // Compute the generator's base address.
  204. //
  205. ui32Gen = PWM_GEN_BADDR(ui32Base, ui32Gen);
  206. //
  207. // Change the global configuration of the generator.
  208. //
  209. HWREG(ui32Gen + PWM_O_X_CTL) = ((HWREG(ui32Gen + PWM_O_X_CTL) &
  210. ~(PWM_X_CTL_MODE | PWM_X_CTL_DEBUG |
  211. PWM_X_CTL_LATCH | PWM_X_CTL_MINFLTPER |
  212. PWM_X_CTL_FLTSRC |
  213. PWM_X_CTL_DBFALLUPD_M |
  214. PWM_X_CTL_DBRISEUPD_M |
  215. PWM_X_CTL_DBCTLUPD_M |
  216. PWM_X_CTL_GENBUPD_M |
  217. PWM_X_CTL_GENAUPD_M |
  218. PWM_X_CTL_LOADUPD | PWM_X_CTL_CMPAUPD |
  219. PWM_X_CTL_CMPBUPD)) | ui32Config);
  220. //
  221. // Set the individual PWM generator controls.
  222. //
  223. if(ui32Config & PWM_X_CTL_MODE)
  224. {
  225. //
  226. // In up/down count mode, set the signal high on up count comparison
  227. // and low on down count comparison (that is, center align the
  228. // signals).
  229. //
  230. HWREG(ui32Gen + PWM_O_X_GENA) = (PWM_X_GENA_ACTCMPAU_ONE |
  231. PWM_X_GENA_ACTCMPAD_ZERO);
  232. HWREG(ui32Gen + PWM_O_X_GENB) = (PWM_X_GENB_ACTCMPBU_ONE |
  233. PWM_X_GENB_ACTCMPBD_ZERO);
  234. }
  235. else
  236. {
  237. //
  238. // In down count mode, set the signal high on load and low on count
  239. // comparison (that is, left align the signals).
  240. //
  241. HWREG(ui32Gen + PWM_O_X_GENA) = (PWM_X_GENA_ACTLOAD_ONE |
  242. PWM_X_GENA_ACTCMPAD_ZERO);
  243. HWREG(ui32Gen + PWM_O_X_GENB) = (PWM_X_GENB_ACTLOAD_ONE |
  244. PWM_X_GENB_ACTCMPBD_ZERO);
  245. }
  246. }
  247. //*****************************************************************************
  248. //
  249. //! Sets the period of a PWM generator.
  250. //!
  251. //! \param ui32Base is the base address of the PWM module.
  252. //! \param ui32Gen is the PWM generator to be modified. This parameter must be
  253. //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  254. //! \param ui32Period specifies the period of PWM generator output, measured
  255. //! in clock ticks.
  256. //!
  257. //! This function sets the period of the specified PWM generator block, where
  258. //! the period of the generator block is defined as the number of PWM clock
  259. //! ticks between pulses on the generator block zero signal.
  260. //!
  261. //! \note Any subsequent calls made to this function before an update occurs
  262. //! cause the previous values to be overwritten.
  263. //!
  264. //! \return None.
  265. //
  266. //*****************************************************************************
  267. void
  268. PWMGenPeriodSet(uint32_t ui32Base, uint32_t ui32Gen,
  269. uint32_t ui32Period)
  270. {
  271. //
  272. // Check the arguments.
  273. //
  274. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  275. ASSERT(_PWMGenValid(ui32Gen));
  276. //
  277. // Compute the generator's base address.
  278. //
  279. ui32Gen = PWM_GEN_BADDR(ui32Base, ui32Gen);
  280. //
  281. // Set the reload register based on the mode.
  282. //
  283. if(HWREG(ui32Gen + PWM_O_X_CTL) & PWM_X_CTL_MODE)
  284. {
  285. //
  286. // In up/down count mode, set the reload register to half the requested
  287. // period.
  288. //
  289. ASSERT((ui32Period / 2) < 65536);
  290. HWREG(ui32Gen + PWM_O_X_LOAD) = ui32Period / 2;
  291. }
  292. else
  293. {
  294. //
  295. // In down count mode, set the reload register to the requested period
  296. // minus one.
  297. //
  298. ASSERT((ui32Period <= 65536) && (ui32Period != 0));
  299. HWREG(ui32Gen + PWM_O_X_LOAD) = ui32Period - 1;
  300. }
  301. }
  302. //*****************************************************************************
  303. //
  304. //! Gets the period of a PWM generator block.
  305. //!
  306. //! \param ui32Base is the base address of the PWM module.
  307. //! \param ui32Gen is the PWM generator to query. This parameter must be one
  308. //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  309. //!
  310. //! This function gets the period of the specified PWM generator block. The
  311. //! period of the generator block is defined as the number of PWM clock ticks
  312. //! between pulses on the generator block zero signal.
  313. //!
  314. //! If the update of the counter for the specified PWM generator has yet
  315. //! to be completed, the value returned may not be the active period. The
  316. //! value returned is the programmed period, measured in PWM clock ticks.
  317. //!
  318. //! \return Returns the programmed period of the specified generator block
  319. //! in PWM clock ticks.
  320. //
  321. //*****************************************************************************
  322. uint32_t
  323. PWMGenPeriodGet(uint32_t ui32Base, uint32_t ui32Gen)
  324. {
  325. //
  326. // Check the arguments.
  327. //
  328. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  329. ASSERT(_PWMGenValid(ui32Gen));
  330. //
  331. // Compute the generator's base address.
  332. //
  333. ui32Gen = PWM_GEN_BADDR(ui32Base, ui32Gen);
  334. //
  335. // Figure out the counter mode.
  336. //
  337. if(HWREG(ui32Gen + PWM_O_X_CTL) & PWM_X_CTL_MODE)
  338. {
  339. //
  340. // The period is twice the reload register value.
  341. //
  342. return(HWREG(ui32Gen + PWM_O_X_LOAD) * 2);
  343. }
  344. else
  345. {
  346. //
  347. // The period is the reload register value plus one.
  348. //
  349. return(HWREG(ui32Gen + PWM_O_X_LOAD) + 1);
  350. }
  351. }
  352. //*****************************************************************************
  353. //
  354. //! Enables the timer/counter for a PWM generator block.
  355. //!
  356. //! \param ui32Base is the base address of the PWM module.
  357. //! \param ui32Gen is the PWM generator to be enabled. This parameter must be
  358. //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  359. //!
  360. //! This function allows the PWM clock to drive the timer/counter for the
  361. //! specified generator block.
  362. //!
  363. //! \return None.
  364. //
  365. //*****************************************************************************
  366. void
  367. PWMGenEnable(uint32_t ui32Base, uint32_t ui32Gen)
  368. {
  369. //
  370. // Check the arguments.
  371. //
  372. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  373. ASSERT(_PWMGenValid(ui32Gen));
  374. //
  375. // Enable the PWM generator.
  376. //
  377. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_CTL) |= PWM_X_CTL_ENABLE;
  378. }
  379. //*****************************************************************************
  380. //
  381. //! Disables the timer/counter for a PWM generator block.
  382. //!
  383. //! \param ui32Base is the base address of the PWM module.
  384. //! \param ui32Gen is the PWM generator to be disabled. This parameter must be
  385. //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  386. //!
  387. //! This function blocks the PWM clock from driving the timer/counter for the
  388. //! specified generator block.
  389. //!
  390. //! \return None.
  391. //
  392. //*****************************************************************************
  393. void
  394. PWMGenDisable(uint32_t ui32Base, uint32_t ui32Gen)
  395. {
  396. //
  397. // Check the arguments.
  398. //
  399. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  400. ASSERT(_PWMGenValid(ui32Gen));
  401. //
  402. // Disable the PWM generator.
  403. //
  404. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_CTL) &=
  405. ~(PWM_X_CTL_ENABLE);
  406. }
  407. //*****************************************************************************
  408. //
  409. //! Sets the pulse width for the specified PWM output.
  410. //!
  411. //! \param ui32Base is the base address of the PWM module.
  412. //! \param ui32PWMOut is the PWM output to modify. This parameter must be one
  413. //! of \b PWM_OUT_0, \b PWM_OUT_1, \b PWM_OUT_2, \b PWM_OUT_3, \b PWM_OUT_4,
  414. //! \b PWM_OUT_5, \b PWM_OUT_6, or \b PWM_OUT_7.
  415. //! \param ui32Width specifies the width of the positive portion of the pulse.
  416. //!
  417. //! This function sets the pulse width for the specified PWM output, where the
  418. //! pulse width is defined as the number of PWM clock ticks.
  419. //!
  420. //! \note Any subsequent calls made to this function before an update occurs
  421. //! cause the previous values to be overwritten.
  422. //!
  423. //! \return None.
  424. //
  425. //*****************************************************************************
  426. void
  427. PWMPulseWidthSet(uint32_t ui32Base, uint32_t ui32PWMOut,
  428. uint32_t ui32Width)
  429. {
  430. uint32_t ui32GenBase, ui32Reg;
  431. //
  432. // Check the arguments.
  433. //
  434. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  435. ASSERT(_PWMOutValid(ui32PWMOut));
  436. //
  437. // Compute the generator's base address.
  438. //
  439. ui32GenBase = PWM_OUT_BADDR(ui32Base, ui32PWMOut);
  440. //
  441. // If the counter is in up/down count mode, divide the width by two.
  442. //
  443. if(HWREG(ui32GenBase + PWM_O_X_CTL) & PWM_X_CTL_MODE)
  444. {
  445. ui32Width /= 2;
  446. }
  447. //
  448. // Get the period.
  449. //
  450. ui32Reg = HWREG(ui32GenBase + PWM_O_X_LOAD);
  451. //
  452. // Make sure the width is not too large.
  453. //
  454. ASSERT(ui32Width < ui32Reg);
  455. //
  456. // Compute the compare value.
  457. //
  458. ui32Reg = ui32Reg - ui32Width;
  459. //
  460. // Write to the appropriate registers.
  461. //
  462. if(PWM_IS_OUTPUT_ODD(ui32PWMOut))
  463. {
  464. HWREG(ui32GenBase + PWM_O_X_CMPB) = ui32Reg;
  465. }
  466. else
  467. {
  468. HWREG(ui32GenBase + PWM_O_X_CMPA) = ui32Reg;
  469. }
  470. }
  471. //*****************************************************************************
  472. //
  473. //! Gets the pulse width of a PWM output.
  474. //!
  475. //! \param ui32Base is the base address of the PWM module.
  476. //! \param ui32PWMOut is the PWM output to query. This parameter must be one
  477. //! of \b PWM_OUT_0, \b PWM_OUT_1, \b PWM_OUT_2, \b PWM_OUT_3, \b PWM_OUT_4,
  478. //! \b PWM_OUT_5, \b PWM_OUT_6, or \b PWM_OUT_7.
  479. //!
  480. //! This function gets the currently programmed pulse width for the specified
  481. //! PWM output. If the update of the comparator for the specified output has
  482. //! yet to be completed, the value returned may not be the active pulse width.
  483. //! The value returned is the programmed pulse width, measured in PWM clock
  484. //! ticks.
  485. //!
  486. //! \return Returns the width of the pulse in PWM clock ticks.
  487. //
  488. //*****************************************************************************
  489. uint32_t
  490. PWMPulseWidthGet(uint32_t ui32Base, uint32_t ui32PWMOut)
  491. {
  492. uint32_t ui32GenBase, ui32Reg, ui32Load;
  493. //
  494. // Check the arguments.
  495. //
  496. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  497. ASSERT(_PWMOutValid(ui32PWMOut));
  498. //
  499. // Compute the generator's base address.
  500. //
  501. ui32GenBase = PWM_OUT_BADDR(ui32Base, ui32PWMOut);
  502. //
  503. // Then compute the pulse width. If mode is UpDown, set
  504. // width = (load - compare) * 2. Otherwise, set width = load - compare.
  505. //
  506. ui32Load = HWREG(ui32GenBase + PWM_O_X_LOAD);
  507. if(PWM_IS_OUTPUT_ODD(ui32PWMOut))
  508. {
  509. ui32Reg = HWREG(ui32GenBase + PWM_O_X_CMPB);
  510. }
  511. else
  512. {
  513. ui32Reg = HWREG(ui32GenBase + PWM_O_X_CMPA);
  514. }
  515. ui32Reg = ui32Load - ui32Reg;
  516. //
  517. // If in up/down count mode, double the pulse width.
  518. //
  519. if(HWREG(ui32GenBase + PWM_O_X_CTL) & PWM_X_CTL_MODE)
  520. {
  521. ui32Reg = ui32Reg * 2;
  522. }
  523. //
  524. // Return the pulse width.
  525. //
  526. return(ui32Reg);
  527. }
  528. //*****************************************************************************
  529. //
  530. //! Enables the PWM dead band output and sets the dead band delays.
  531. //!
  532. //! \param ui32Base is the base address of the PWM module.
  533. //! \param ui32Gen is the PWM generator to modify. This parameter must be one
  534. //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  535. //! \param ui16Rise specifies the width of delay from the rising edge.
  536. //! \param ui16Fall specifies the width of delay from the falling edge.
  537. //!
  538. //! This function sets the dead bands for the specified PWM generator, where
  539. //! the dead bands are defined as the number of \b PWM clock ticks from the
  540. //! rising or falling edge of the generator's \b OutA signal. Note that this
  541. //! function causes the coupling of \b OutB to \b OutA.
  542. //!
  543. //! \return None.
  544. //
  545. //*****************************************************************************
  546. void
  547. PWMDeadBandEnable(uint32_t ui32Base, uint32_t ui32Gen,
  548. uint16_t ui16Rise, uint16_t ui16Fall)
  549. {
  550. //
  551. // Check the arguments.
  552. //
  553. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  554. ASSERT(_PWMGenValid(ui32Gen));
  555. ASSERT(ui16Rise < 4096);
  556. ASSERT(ui16Fall < 4096);
  557. //
  558. // Compute the generator's base address.
  559. //
  560. ui32Gen = PWM_GEN_BADDR(ui32Base, ui32Gen);
  561. //
  562. // Write the dead band delay values.
  563. //
  564. HWREG(ui32Gen + PWM_O_X_DBRISE) = ui16Rise;
  565. HWREG(ui32Gen + PWM_O_X_DBFALL) = ui16Fall;
  566. //
  567. // Enable the deadband functionality.
  568. //
  569. HWREG(ui32Gen + PWM_O_X_DBCTL) |= PWM_X_DBCTL_ENABLE;
  570. }
  571. //*****************************************************************************
  572. //
  573. //! Disables the PWM dead band output.
  574. //!
  575. //! \param ui32Base is the base address of the PWM module.
  576. //! \param ui32Gen is the PWM generator to modify. This parameter must be one
  577. //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  578. //!
  579. //! This function disables the dead band mode for the specified PWM generator.
  580. //! Doing so decouples the \b OutA and \b OutB signals.
  581. //!
  582. //! \return None.
  583. //
  584. //*****************************************************************************
  585. void
  586. PWMDeadBandDisable(uint32_t ui32Base, uint32_t ui32Gen)
  587. {
  588. //
  589. // Check the arguments.
  590. //
  591. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  592. ASSERT(_PWMGenValid(ui32Gen));
  593. //
  594. // Disable the deadband functionality.
  595. //
  596. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_DBCTL) &=
  597. ~(PWM_X_DBCTL_ENABLE);
  598. }
  599. //*****************************************************************************
  600. //
  601. //! Synchronizes all pending updates.
  602. //!
  603. //! \param ui32Base is the base address of the PWM module.
  604. //! \param ui32GenBits are the PWM generator blocks to be updated. This
  605. //! parameter must be the logical OR of any of \b PWM_GEN_0_BIT,
  606. //! \b PWM_GEN_1_BIT, \b PWM_GEN_2_BIT, or \b PWM_GEN_3_BIT.
  607. //!
  608. //! For the selected PWM generators, this function causes all queued updates to
  609. //! the period or pulse width to be applied the next time the corresponding
  610. //! counter becomes zero.
  611. //!
  612. //! \return None.
  613. //
  614. //*****************************************************************************
  615. void
  616. PWMSyncUpdate(uint32_t ui32Base, uint32_t ui32GenBits)
  617. {
  618. //
  619. // Check the arguments.
  620. //
  621. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  622. ASSERT(!(ui32GenBits & ~(PWM_GEN_0_BIT | PWM_GEN_1_BIT | PWM_GEN_2_BIT |
  623. PWM_GEN_3_BIT)));
  624. //
  625. // Synchronize pending PWM register changes.
  626. //
  627. HWREG(ui32Base + PWM_O_CTL) = ui32GenBits;
  628. }
  629. //*****************************************************************************
  630. //
  631. //! Synchronizes the counters in one or multiple PWM generator blocks.
  632. //!
  633. //! \param ui32Base is the base address of the PWM module.
  634. //! \param ui32GenBits are the PWM generator blocks to be synchronized. This
  635. //! parameter must be the logical OR of any of \b PWM_GEN_0_BIT,
  636. //! \b PWM_GEN_1_BIT, \b PWM_GEN_2_BIT, or \b PWM_GEN_3_BIT.
  637. //!
  638. //! For the selected PWM module, this function synchronizes the time base of
  639. //! the generator blocks by causing the specified generator counters to be
  640. //! reset to zero.
  641. //!
  642. //! \return None.
  643. //
  644. //*****************************************************************************
  645. void
  646. PWMSyncTimeBase(uint32_t ui32Base, uint32_t ui32GenBits)
  647. {
  648. //
  649. // Check the arguments.
  650. //
  651. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  652. ASSERT(!(ui32GenBits & ~(PWM_GEN_0_BIT | PWM_GEN_1_BIT | PWM_GEN_2_BIT |
  653. PWM_GEN_3_BIT)));
  654. //
  655. // Synchronize the counters in the specified generators by writing to the
  656. // module's synchronization register.
  657. //
  658. HWREG(ui32Base + PWM_O_SYNC) = ui32GenBits;
  659. }
  660. //*****************************************************************************
  661. //
  662. //! Enables or disables PWM outputs.
  663. //!
  664. //! \param ui32Base is the base address of the PWM module.
  665. //! \param ui32PWMOutBits are the PWM outputs to be modified. This parameter
  666. //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
  667. //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
  668. //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
  669. //! \param bEnable determines if the signal is enabled or disabled.
  670. //!
  671. //! This function enables or disables the selected PWM outputs. The outputs
  672. //! are selected using the parameter \e ui32PWMOutBits. The parameter \e
  673. //! bEnable determines the state of the selected outputs. If \e bEnable is
  674. //! \b true, then the selected PWM outputs are enabled, or placed in the active
  675. //! state. If \e bEnable is \b false, then the selected outputs are disabled
  676. //! or placed in the inactive state.
  677. //!
  678. //! \return None.
  679. //
  680. //*****************************************************************************
  681. void
  682. PWMOutputState(uint32_t ui32Base, uint32_t ui32PWMOutBits,
  683. bool bEnable)
  684. {
  685. //
  686. // Check the arguments.
  687. //
  688. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  689. ASSERT(!(ui32PWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  690. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  691. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  692. //
  693. // Read the module's ENABLE output control register and set or clear the
  694. // requested bits.
  695. //
  696. if(bEnable == true)
  697. {
  698. HWREG(ui32Base + PWM_O_ENABLE) |= ui32PWMOutBits;
  699. }
  700. else
  701. {
  702. HWREG(ui32Base + PWM_O_ENABLE) &= ~(ui32PWMOutBits);
  703. }
  704. }
  705. //*****************************************************************************
  706. //
  707. //! Selects the inversion mode for PWM outputs.
  708. //!
  709. //! \param ui32Base is the base address of the PWM module.
  710. //! \param ui32PWMOutBits are the PWM outputs to be modified. This parameter
  711. //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
  712. //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
  713. //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
  714. //! \param bInvert determines if the signal is inverted or passed through.
  715. //!
  716. //! This function is used to select the inversion mode for the selected PWM
  717. //! outputs. The outputs are selected using the parameter \e ui32PWMOutBits.
  718. //! The parameter \e bInvert determines the inversion mode for the selected
  719. //! outputs. If \e bInvert is \b true, this function causes the specified
  720. //! PWM output signals to be inverted or made active low. If \e bInvert is
  721. //! \b false, the specified outputs are passed through as is or made active
  722. //! high.
  723. //!
  724. //! \return None.
  725. //
  726. //*****************************************************************************
  727. void
  728. PWMOutputInvert(uint32_t ui32Base, uint32_t ui32PWMOutBits,
  729. bool bInvert)
  730. {
  731. //
  732. // Check the arguments.
  733. //
  734. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  735. ASSERT(!(ui32PWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  736. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  737. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  738. //
  739. // Read the module's INVERT output control register and set or clear the
  740. // requested bits.
  741. //
  742. if(bInvert == true)
  743. {
  744. HWREG(ui32Base + PWM_O_INVERT) |= ui32PWMOutBits;
  745. }
  746. else
  747. {
  748. HWREG(ui32Base + PWM_O_INVERT) &= ~(ui32PWMOutBits);
  749. }
  750. }
  751. //*****************************************************************************
  752. //
  753. //! Specifies the level of PWM outputs suppressed in response to a fault
  754. //! condition.
  755. //!
  756. //! \param ui32Base is the base address of the PWM module.
  757. //! \param ui32PWMOutBits are the PWM outputs to be modified. This parameter
  758. //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
  759. //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
  760. //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
  761. //! \param bDriveHigh determines if the signal is driven high or low during an
  762. //! active fault condition.
  763. //!
  764. //! This function determines whether a PWM output pin that is suppressed in
  765. //! response to a fault condition is driven high or low. The affected outputs
  766. //! are selected using the parameter \e ui32PWMOutBits. The parameter
  767. //! \e bDriveHigh determines the output level for the pins identified by
  768. //! \e ui32PWMOutBits. If \e bDriveHigh is \b true then the selected outputs
  769. //! are driven high when a fault is detected. If it is \e false, the pins are
  770. //! driven low.
  771. //!
  772. //! In a fault condition, pins which have not been configured to be suppressed
  773. //! via a call to PWMOutputFault() are unaffected by this function.
  774. //!
  775. //! \note This function is available only on devices which support extended
  776. //! PWM fault handling.
  777. //!
  778. //! \return None.
  779. //
  780. //*****************************************************************************
  781. void
  782. PWMOutputFaultLevel(uint32_t ui32Base, uint32_t ui32PWMOutBits,
  783. bool bDriveHigh)
  784. {
  785. //
  786. // Check the arguments.
  787. //
  788. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  789. ASSERT(!(ui32PWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  790. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  791. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  792. //
  793. // Read the module's FAULT output control register and set or clear the
  794. // requested bits.
  795. //
  796. if(bDriveHigh == true)
  797. {
  798. HWREG(ui32Base + PWM_O_FAULTVAL) |= ui32PWMOutBits;
  799. }
  800. else
  801. {
  802. HWREG(ui32Base + PWM_O_FAULTVAL) &= ~(ui32PWMOutBits);
  803. }
  804. }
  805. //*****************************************************************************
  806. //
  807. //! Specifies the state of PWM outputs in response to a fault condition.
  808. //!
  809. //! \param ui32Base is the base address of the PWM module.
  810. //! \param ui32PWMOutBits are the PWM outputs to be modified. This parameter
  811. //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
  812. //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
  813. //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
  814. //! \param bFaultSuppress determines if the signal is suppressed or passed
  815. //! through during an active fault condition.
  816. //!
  817. //! This function sets the fault handling characteristics of the selected PWM
  818. //! outputs. The outputs are selected using the parameter \e ui32PWMOutBits.
  819. //! The parameter \e bFaultSuppress determines the fault handling
  820. //! characteristics for the selected outputs. If \e bFaultSuppress is \b true,
  821. //! then the selected outputs are made inactive. If \e bFaultSuppress is
  822. //! \b false, then the selected outputs are unaffected by the detected fault.
  823. //!
  824. //! On devices supporting extended PWM fault handling, the state the affected
  825. //! output pins are driven to can be configured with PWMOutputFaultLevel(). If
  826. //! not configured, or if the device does not support extended PWM fault
  827. //! handling, affected outputs are driven low on a fault condition.
  828. //!
  829. //! \return None.
  830. //
  831. //*****************************************************************************
  832. void
  833. PWMOutputFault(uint32_t ui32Base, uint32_t ui32PWMOutBits,
  834. bool bFaultSuppress)
  835. {
  836. //
  837. // Check the arguments.
  838. //
  839. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  840. ASSERT(!(ui32PWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  841. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  842. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  843. //
  844. // Read the module's FAULT output control register and set or clear the
  845. // requested bits.
  846. //
  847. if(bFaultSuppress == true)
  848. {
  849. HWREG(ui32Base + PWM_O_FAULT) |= ui32PWMOutBits;
  850. }
  851. else
  852. {
  853. HWREG(ui32Base + PWM_O_FAULT) &= ~(ui32PWMOutBits);
  854. }
  855. }
  856. //*****************************************************************************
  857. //
  858. //! Gets the PWM generator interrupt number.
  859. //!
  860. //! \param ui32Base is the base address of the PWM module.
  861. //! \param ui32Gen is the PWM generator in question. This parameter must be
  862. //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  863. //!
  864. //! This function returns the interrupt number of the corresponding PWM
  865. //! generator.
  866. //!
  867. //! \return Returns the interrupt number.
  868. //
  869. //*****************************************************************************
  870. static uint32_t
  871. _PWMGenIntNumberGet(uint32_t ui32Base, uint32_t ui32Gen)
  872. {
  873. //
  874. // Determine the generator and PWM module in question.
  875. //
  876. switch(ui32Base + ui32Gen)
  877. {
  878. //
  879. // The first PWM generator in the first PWM module.
  880. //
  881. case PWM0_BASE + PWM_GEN_0:
  882. {
  883. if(CLASS_IS_TM4C123)
  884. {
  885. return(INT_PWM0_0_TM4C123);
  886. }
  887. else if(CLASS_IS_TM4C129)
  888. {
  889. return(INT_PWM0_0_TM4C129);
  890. }
  891. else
  892. {
  893. return(0);
  894. }
  895. }
  896. //
  897. // The second PWM generator in the first PWM module.
  898. //
  899. case PWM0_BASE + PWM_GEN_1:
  900. {
  901. if(CLASS_IS_TM4C129)
  902. {
  903. return(INT_PWM0_1_TM4C129);
  904. }
  905. else
  906. {
  907. return(0);
  908. }
  909. }
  910. //
  911. // The third PWM generator in the first PWM module.
  912. //
  913. case PWM0_BASE + PWM_GEN_2:
  914. {
  915. if(CLASS_IS_TM4C129)
  916. {
  917. return(INT_PWM0_2_TM4C129);
  918. }
  919. else
  920. {
  921. return(0);
  922. }
  923. }
  924. //
  925. // The fourth PWM generator in the first PWM module.
  926. //
  927. case PWM0_BASE + PWM_GEN_3:
  928. {
  929. if(CLASS_IS_TM4C129)
  930. {
  931. return(INT_PWM0_3_TM4C129);
  932. }
  933. else
  934. {
  935. return(0);
  936. }
  937. }
  938. //
  939. // The first PWM generator in the second PWM module.
  940. //
  941. case PWM1_BASE + PWM_GEN_0:
  942. {
  943. if(CLASS_IS_TM4C123)
  944. {
  945. return(INT_PWM1_0_TM4C123);
  946. }
  947. else
  948. {
  949. return(0);
  950. }
  951. }
  952. //
  953. // The first PWM generator in the second PWM module.
  954. //
  955. case PWM1_BASE + PWM_GEN_1:
  956. {
  957. if(CLASS_IS_TM4C123)
  958. {
  959. return(INT_PWM1_1_TM4C123);
  960. }
  961. else
  962. {
  963. return(0);
  964. }
  965. }
  966. //
  967. // The first PWM generator in the second PWM module.
  968. //
  969. case PWM1_BASE + PWM_GEN_2:
  970. {
  971. if(CLASS_IS_TM4C123)
  972. {
  973. return(INT_PWM1_2_TM4C123);
  974. }
  975. else
  976. {
  977. return(0);
  978. }
  979. }
  980. //
  981. // The first PWM generator in the second PWM module.
  982. //
  983. case PWM1_BASE + PWM_GEN_3:
  984. {
  985. if(CLASS_IS_TM4C123)
  986. {
  987. return(INT_PWM1_3_TM4C123);
  988. }
  989. else
  990. {
  991. return(0);
  992. }
  993. }
  994. //
  995. // An unknown PWM module/generator was specified.
  996. //
  997. default:
  998. {
  999. return(0);
  1000. }
  1001. }
  1002. }
  1003. //*****************************************************************************
  1004. //
  1005. //! Registers an interrupt handler for the specified PWM generator block.
  1006. //!
  1007. //! \param ui32Base is the base address of the PWM module.
  1008. //! \param ui32Gen is the PWM generator in question. This parameter must be
  1009. //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1010. //! \param pfnIntHandler is a pointer to the function to be called when the PWM
  1011. //! generator interrupt occurs.
  1012. //!
  1013. //! This function ensures that the interrupt handler specified by
  1014. //! \e pfnIntHandler is called when an interrupt is detected for the specified
  1015. //! PWM generator block. This function also enables the corresponding
  1016. //! PWM generator interrupt in the interrupt controller; individual generator
  1017. //! interrupts and interrupt sources must be enabled with PWMIntEnable() and
  1018. //! PWMGenIntTrigEnable().
  1019. //!
  1020. //! \sa IntRegister() for important information about registering interrupt
  1021. //! handlers.
  1022. //!
  1023. //! \return None.
  1024. //
  1025. //*****************************************************************************
  1026. void
  1027. PWMGenIntRegister(uint32_t ui32Base, uint32_t ui32Gen,
  1028. void (*pfnIntHandler)(void))
  1029. {
  1030. uint32_t ui32Int;
  1031. //
  1032. // Check the arguments.
  1033. //
  1034. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1035. ASSERT(_PWMGenValid(ui32Gen));
  1036. //
  1037. // Get the interrupt number associated with the specified generator.
  1038. //
  1039. ui32Int = _PWMGenIntNumberGet(ui32Base, ui32Gen);
  1040. ASSERT(ui32Int != 0);
  1041. //
  1042. // Register the interrupt handler.
  1043. //
  1044. IntRegister(ui32Int, pfnIntHandler);
  1045. //
  1046. // Enable the PWMx interrupt.
  1047. //
  1048. IntEnable(ui32Int);
  1049. }
  1050. //*****************************************************************************
  1051. //
  1052. //! Removes an interrupt handler for the specified PWM generator block.
  1053. //!
  1054. //! \param ui32Base is the base address of the PWM module.
  1055. //! \param ui32Gen is the PWM generator in question. This parameter must be
  1056. //! one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1057. //!
  1058. //! This function unregisters the interrupt handler for the specified
  1059. //! PWM generator block. This function also disables the corresponding
  1060. //! PWM generator interrupt in the interrupt controller; individual generator
  1061. //! interrupts and interrupt sources must be disabled with PWMIntDisable() and
  1062. //! PWMGenIntTrigDisable().
  1063. //!
  1064. //! \sa IntRegister() for important information about registering interrupt
  1065. //! handlers.
  1066. //!
  1067. //! \return None.
  1068. //
  1069. //*****************************************************************************
  1070. void
  1071. PWMGenIntUnregister(uint32_t ui32Base, uint32_t ui32Gen)
  1072. {
  1073. uint32_t ui32Int;
  1074. //
  1075. // Check the arguments.
  1076. //
  1077. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1078. ASSERT(_PWMGenValid(ui32Gen));
  1079. //
  1080. // Get the interrupt number associated with the specified generator.
  1081. //
  1082. ui32Int = _PWMGenIntNumberGet(ui32Base, ui32Gen);
  1083. ASSERT(ui32Int != 0);
  1084. //
  1085. // Disable the PWMx interrupt.
  1086. //
  1087. IntDisable(ui32Int);
  1088. //
  1089. // Unregister the interrupt handler.
  1090. //
  1091. IntUnregister(ui32Int);
  1092. }
  1093. //*****************************************************************************
  1094. //
  1095. //! Gets the PWM fault interrupt number.
  1096. //!
  1097. //! \param ui32Base is the base address of the PWM module.
  1098. //!
  1099. //! This function returns the fault interrupt number of the corresponding
  1100. //! PWM module.
  1101. //!
  1102. //! \return Returns the interrupt number.
  1103. //
  1104. //*****************************************************************************
  1105. static uint32_t
  1106. _PWMFaultIntNumberGet(uint32_t ui32Base)
  1107. {
  1108. //
  1109. // Return the fault interrupt number.
  1110. //
  1111. if(CLASS_IS_TM4C123)
  1112. {
  1113. return((ui32Base == PWM0_BASE) ? INT_PWM0_FAULT_TM4C123 :
  1114. INT_PWM1_FAULT_TM4C123);
  1115. }
  1116. else if(CLASS_IS_TM4C129)
  1117. {
  1118. return((ui32Base == PWM0_BASE) ? INT_PWM0_FAULT_TM4C129 : 0);
  1119. }
  1120. else
  1121. {
  1122. return(0);
  1123. }
  1124. }
  1125. //*****************************************************************************
  1126. //
  1127. //! Registers an interrupt handler for a fault condition detected in a PWM
  1128. //! module.
  1129. //!
  1130. //! \param ui32Base is the base address of the PWM module.
  1131. //! \param pfnIntHandler is a pointer to the function to be called when the PWM
  1132. //! fault interrupt occurs.
  1133. //!
  1134. //! This function ensures that the interrupt handler specified by
  1135. //! \e pfnIntHandler is called when a fault interrupt is detected for the
  1136. //! selected PWM module. This function also enables the PWM fault
  1137. //! interrupt in the NVIC; the PWM fault interrupt must also be enabled at the
  1138. //! module level using PWMIntEnable().
  1139. //!
  1140. //! \sa IntRegister() for important information about registering interrupt
  1141. //! handlers.
  1142. //!
  1143. //! \return None.
  1144. //
  1145. //*****************************************************************************
  1146. void
  1147. PWMFaultIntRegister(uint32_t ui32Base, void (*pfnIntHandler)(void))
  1148. {
  1149. uint32_t ui32Int;
  1150. //
  1151. // Check the arguments.
  1152. //
  1153. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1154. //
  1155. // Get the interrupt number associated with the specified module.
  1156. //
  1157. ui32Int = _PWMFaultIntNumberGet(ui32Base);
  1158. ASSERT(ui32Int != 0);
  1159. //
  1160. // Register the interrupt handler, returning an error if one occurs.
  1161. //
  1162. IntRegister(ui32Int, pfnIntHandler);
  1163. //
  1164. // Enable the PWM fault interrupt.
  1165. //
  1166. IntEnable(ui32Int);
  1167. }
  1168. //*****************************************************************************
  1169. //
  1170. //! Removes the PWM fault condition interrupt handler.
  1171. //!
  1172. //! \param ui32Base is the base address of the PWM module.
  1173. //!
  1174. //! This function removes the interrupt handler for a PWM fault interrupt
  1175. //! from the selected PWM module. This function also disables the PWM
  1176. //! fault interrupt in the NVIC; the PWM fault interrupt must also be disabled
  1177. //! at the module level using PWMIntDisable().
  1178. //!
  1179. //! \sa IntRegister() for important information about registering interrupt
  1180. //! handlers.
  1181. //!
  1182. //! \return None.
  1183. //
  1184. //*****************************************************************************
  1185. void
  1186. PWMFaultIntUnregister(uint32_t ui32Base)
  1187. {
  1188. uint32_t ui32Int;
  1189. //
  1190. // Check the arguments.
  1191. //
  1192. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1193. //
  1194. // Get the interrupt number associated with the specified module.
  1195. //
  1196. ui32Int = _PWMFaultIntNumberGet(ui32Base);
  1197. ASSERT(ui32Int != 0);
  1198. //
  1199. // Disable the PWM fault interrupt.
  1200. //
  1201. IntDisable(ui32Int);
  1202. //
  1203. // Unregister the interrupt handler, returning an error if one occurs.
  1204. //
  1205. IntUnregister(ui32Int);
  1206. }
  1207. //*****************************************************************************
  1208. //
  1209. //! Enables interrupts and triggers for the specified PWM generator block.
  1210. //!
  1211. //! \param ui32Base is the base address of the PWM module.
  1212. //! \param ui32Gen is the PWM generator to have interrupts and triggers
  1213. //! enabled. This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1,
  1214. //! \b PWM_GEN_2, or \b PWM_GEN_3.
  1215. //! \param ui32IntTrig specifies the interrupts and triggers to be enabled.
  1216. //!
  1217. //! This function unmasks the specified interrupt(s) and trigger(s) by setting
  1218. //! the specified bits of the interrupt/trigger enable register for the
  1219. //! specified PWM generator. The \e ui32IntTrig parameter is the logical OR of
  1220. //! \b PWM_INT_CNT_ZERO, \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU,
  1221. //! \b PWM_INT_CNT_AD, \b PWM_INT_CNT_BU, \b PWM_INT_CNT_BD,
  1222. //! \b PWM_TR_CNT_ZERO, \b PWM_TR_CNT_LOAD, \b PWM_TR_CNT_AU, \b PWM_TR_CNT_AD,
  1223. //! \b PWM_TR_CNT_BU, or \b PWM_TR_CNT_BD.
  1224. //!
  1225. //! \return None.
  1226. //
  1227. //*****************************************************************************
  1228. void
  1229. PWMGenIntTrigEnable(uint32_t ui32Base, uint32_t ui32Gen,
  1230. uint32_t ui32IntTrig)
  1231. {
  1232. //
  1233. // Check the arguments.
  1234. //
  1235. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1236. ASSERT(_PWMGenValid(ui32Gen));
  1237. ASSERT((ui32IntTrig & ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD |
  1238. PWM_INT_CNT_AU | PWM_INT_CNT_AD | PWM_INT_CNT_BU |
  1239. PWM_INT_CNT_BD | PWM_TR_CNT_ZERO |
  1240. PWM_TR_CNT_LOAD | PWM_TR_CNT_AU | PWM_TR_CNT_AD |
  1241. PWM_TR_CNT_BU | PWM_TR_CNT_BD)) == 0);
  1242. //
  1243. // Enable the specified interrupts/triggers.
  1244. //
  1245. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_INTEN) |= ui32IntTrig;
  1246. }
  1247. //*****************************************************************************
  1248. //
  1249. //! Disables interrupts for the specified PWM generator block.
  1250. //!
  1251. //! \param ui32Base is the base address of the PWM module.
  1252. //! \param ui32Gen is the PWM generator to have interrupts and triggers
  1253. //! disabled. This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1,
  1254. //! \b PWM_GEN_2, or \b PWM_GEN_3.
  1255. //! \param ui32IntTrig specifies the interrupts and triggers to be disabled.
  1256. //!
  1257. //! This function masks the specified interrupt(s) and trigger(s) by clearing
  1258. //! the specified bits of the interrupt/trigger enable register for the
  1259. //! specified PWM generator. The \e ui32IntTrig parameter is the logical OR of
  1260. //! \b PWM_INT_CNT_ZERO, \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU,
  1261. //! \b PWM_INT_CNT_AD, \b PWM_INT_CNT_BU, \b PWM_INT_CNT_BD,
  1262. //! \b PWM_TR_CNT_ZERO, \b PWM_TR_CNT_LOAD, \b PWM_TR_CNT_AU, \b PWM_TR_CNT_AD,
  1263. //! \b PWM_TR_CNT_BU, or \b PWM_TR_CNT_BD.
  1264. //!
  1265. //! \return None.
  1266. //
  1267. //*****************************************************************************
  1268. void
  1269. PWMGenIntTrigDisable(uint32_t ui32Base, uint32_t ui32Gen,
  1270. uint32_t ui32IntTrig)
  1271. {
  1272. //
  1273. // Check the arguments.
  1274. //
  1275. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1276. ASSERT(_PWMGenValid(ui32Gen));
  1277. ASSERT((ui32IntTrig & ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD |
  1278. PWM_INT_CNT_AU | PWM_INT_CNT_AD | PWM_INT_CNT_BU |
  1279. PWM_INT_CNT_BD | PWM_TR_CNT_ZERO |
  1280. PWM_TR_CNT_LOAD | PWM_TR_CNT_AU | PWM_TR_CNT_AD |
  1281. PWM_TR_CNT_BU | PWM_TR_CNT_BD)) == 0);
  1282. //
  1283. // Disable the specified interrupts/triggers.
  1284. //
  1285. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_INTEN) &= ~(ui32IntTrig);
  1286. }
  1287. //*****************************************************************************
  1288. //
  1289. //! Gets interrupt status for the specified PWM generator block.
  1290. //!
  1291. //! \param ui32Base is the base address of the PWM module.
  1292. //! \param ui32Gen is the PWM generator to query. This parameter must be one
  1293. //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1294. //! \param bMasked specifies whether masked or raw interrupt status is
  1295. //! returned.
  1296. //!
  1297. //! If \e bMasked is set as \b true, then the masked interrupt status is
  1298. //! returned; otherwise, the raw interrupt status is returned.
  1299. //!
  1300. //! \return Returns the contents of the interrupt status register or the
  1301. //! contents of the raw interrupt status register for the specified
  1302. //! PWM generator.
  1303. //
  1304. //*****************************************************************************
  1305. uint32_t
  1306. PWMGenIntStatus(uint32_t ui32Base, uint32_t ui32Gen, bool bMasked)
  1307. {
  1308. //
  1309. // Check the arguments.
  1310. //
  1311. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1312. ASSERT(_PWMGenValid(ui32Gen));
  1313. //
  1314. // Compute the generator's base address.
  1315. //
  1316. ui32Gen = PWM_GEN_BADDR(ui32Base, ui32Gen);
  1317. //
  1318. // Read and return the specified generator's raw or enabled interrupt
  1319. // status.
  1320. //
  1321. if(bMasked == true)
  1322. {
  1323. return(HWREG(ui32Gen + PWM_O_X_ISC));
  1324. }
  1325. else
  1326. {
  1327. return(HWREG(ui32Gen + PWM_O_X_RIS));
  1328. }
  1329. }
  1330. //*****************************************************************************
  1331. //
  1332. //! Clears the specified interrupt(s) for the specified PWM generator block.
  1333. //!
  1334. //! \param ui32Base is the base address of the PWM module.
  1335. //! \param ui32Gen is the PWM generator to query. This parameter must be one
  1336. //! of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1337. //! \param ui32Ints specifies the interrupts to be cleared.
  1338. //!
  1339. //! This function clears the specified interrupt(s) by writing a 1 to the
  1340. //! specified bits of the interrupt status register for the specified PWM
  1341. //! generator. The \e ui32Ints parameter is the logical OR of
  1342. //! \b PWM_INT_CNT_ZERO, \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU,
  1343. //! \b PWM_INT_CNT_AD, \b PWM_INT_CNT_BU, or \b PWM_INT_CNT_BD.
  1344. //!
  1345. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1346. //! take several clock cycles before the interrupt source is actually cleared.
  1347. //! Therefore, it is recommended that the interrupt source be cleared early in
  1348. //! the interrupt handler (as opposed to the very last action) to avoid
  1349. //! returning from the interrupt handler before the interrupt source is
  1350. //! actually cleared. Failure to do so may result in the interrupt handler
  1351. //! being immediately reentered (because the interrupt controller still sees
  1352. //! the interrupt source asserted).
  1353. //!
  1354. //! \return None.
  1355. //
  1356. //*****************************************************************************
  1357. void
  1358. PWMGenIntClear(uint32_t ui32Base, uint32_t ui32Gen, uint32_t ui32Ints)
  1359. {
  1360. //
  1361. // Check the arguments.
  1362. //
  1363. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1364. ASSERT(_PWMGenValid(ui32Gen));
  1365. ASSERT((ui32Ints &
  1366. ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD | PWM_INT_CNT_AU |
  1367. PWM_INT_CNT_AD | PWM_INT_CNT_BU | PWM_INT_CNT_BD)) == 0);
  1368. //
  1369. // Clear the requested interrupts by writing ones to the specified bit
  1370. // of the module's interrupt enable register.
  1371. //
  1372. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_ISC) = ui32Ints;
  1373. }
  1374. //*****************************************************************************
  1375. //
  1376. //! Enables generator and fault interrupts for a PWM module.
  1377. //!
  1378. //! \param ui32Base is the base address of the PWM module.
  1379. //! \param ui32GenFault contains the interrupts to be enabled. This parameter
  1380. //! must be a logical OR of any of \b PWM_INT_GEN_0, \b PWM_INT_GEN_1,
  1381. //! \b PWM_INT_GEN_2, \b PWM_INT_GEN_3, \b PWM_INT_FAULT0, \b PWM_INT_FAULT1,
  1382. //! \b PWM_INT_FAULT2, or \b PWM_INT_FAULT3.
  1383. //!
  1384. //! This function unmasks the specified interrupt(s) by setting the specified
  1385. //! bits of the interrupt enable register for the selected PWM module.
  1386. //!
  1387. //! \return None.
  1388. //
  1389. //*****************************************************************************
  1390. void
  1391. PWMIntEnable(uint32_t ui32Base, uint32_t ui32GenFault)
  1392. {
  1393. //
  1394. // Check the arguments.
  1395. //
  1396. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1397. ASSERT((ui32GenFault & ~(PWM_INT_GEN_0 | PWM_INT_GEN_1 | PWM_INT_GEN_2 |
  1398. PWM_INT_GEN_3 | PWM_INT_FAULT0 | PWM_INT_FAULT1 |
  1399. PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
  1400. //
  1401. // Read the module's interrupt enable register and enable interrupts
  1402. // for the specified PWM generators.
  1403. //
  1404. HWREG(ui32Base + PWM_O_INTEN) |= ui32GenFault;
  1405. }
  1406. //*****************************************************************************
  1407. //
  1408. //! Disables generator and fault interrupts for a PWM module.
  1409. //!
  1410. //! \param ui32Base is the base address of the PWM module.
  1411. //! \param ui32GenFault contains the interrupts to be disabled. This parameter
  1412. //! must be a logical OR of any of \b PWM_INT_GEN_0, \b PWM_INT_GEN_1,
  1413. //! \b PWM_INT_GEN_2, \b PWM_INT_GEN_3, \b PWM_INT_FAULT0, \b PWM_INT_FAULT1,
  1414. //! \b PWM_INT_FAULT2, or \b PWM_INT_FAULT3.
  1415. //!
  1416. //! This function masks the specified interrupt(s) by clearing the specified
  1417. //! bits of the interrupt enable register for the selected PWM module.
  1418. //!
  1419. //! \return None.
  1420. //
  1421. //*****************************************************************************
  1422. void
  1423. PWMIntDisable(uint32_t ui32Base, uint32_t ui32GenFault)
  1424. {
  1425. //
  1426. // Check the arguments.
  1427. //
  1428. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1429. ASSERT((ui32GenFault & ~(PWM_INT_GEN_0 | PWM_INT_GEN_1 | PWM_INT_GEN_2 |
  1430. PWM_INT_GEN_3 | PWM_INT_FAULT0 | PWM_INT_FAULT1 |
  1431. PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
  1432. //
  1433. // Read the module's interrupt enable register and disable interrupts
  1434. // for the specified PWM generators.
  1435. //
  1436. HWREG(ui32Base + PWM_O_INTEN) &= ~(ui32GenFault);
  1437. }
  1438. //*****************************************************************************
  1439. //
  1440. //! Clears the fault interrupt for a PWM module.
  1441. //!
  1442. //! \param ui32Base is the base address of the PWM module.
  1443. //!
  1444. //! This function clears the fault interrupt by writing to the appropriate bit
  1445. //! of the interrupt status register for the selected PWM module.
  1446. //!
  1447. //! This function clears only the FAULT0 interrupt and is retained for
  1448. //! backwards compatibility. It is recommended that PWMFaultIntClearExt() be
  1449. //! used instead because it supports all fault interrupts supported on devices
  1450. //! with and without extended PWM fault handling support.
  1451. //!
  1452. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1453. //! take several clock cycles before the interrupt source is actually cleared.
  1454. //! Therefore, it is recommended that the interrupt source be cleared early in
  1455. //! the interrupt handler (as opposed to the very last action) to avoid
  1456. //! returning from the interrupt handler before the interrupt source is
  1457. //! actually cleared. Failure to do so may result in the interrupt handler
  1458. //! being immediately reentered (because the interrupt controller still sees
  1459. //! the interrupt source asserted).
  1460. //!
  1461. //! \return None.
  1462. //
  1463. //*****************************************************************************
  1464. void
  1465. PWMFaultIntClear(uint32_t ui32Base)
  1466. {
  1467. //
  1468. // Check the arguments.
  1469. //
  1470. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1471. //
  1472. // Write the only writeable bit in the module's interrupt register.
  1473. //
  1474. HWREG(ui32Base + PWM_O_ISC) = PWM_ISC_INTFAULT0;
  1475. }
  1476. //*****************************************************************************
  1477. //
  1478. //! Gets the interrupt status for a PWM module.
  1479. //!
  1480. //! \param ui32Base is the base address of the PWM module.
  1481. //! \param bMasked specifies whether masked or raw interrupt status is
  1482. //! returned.
  1483. //!
  1484. //! If \e bMasked is set as \b true, then the masked interrupt status is
  1485. //! returned; otherwise, the raw interrupt status is returned.
  1486. //!
  1487. //! \return The current interrupt status, enumerated as a bit field of
  1488. //! \b PWM_INT_GEN_0, \b PWM_INT_GEN_1, \b PWM_INT_GEN_2, \b PWM_INT_GEN_3,
  1489. //! \b PWM_INT_FAULT0, \b PWM_INT_FAULT1, \b PWM_INT_FAULT2, and
  1490. //! \b PWM_INT_FAULT3.
  1491. //!
  1492. //*****************************************************************************
  1493. uint32_t
  1494. PWMIntStatus(uint32_t ui32Base, bool bMasked)
  1495. {
  1496. //
  1497. // Check the arguments.
  1498. //
  1499. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1500. //
  1501. // Read and return either the module's raw or enabled interrupt status.
  1502. //
  1503. if(bMasked == true)
  1504. {
  1505. return(HWREG(ui32Base + PWM_O_ISC));
  1506. }
  1507. else
  1508. {
  1509. return(HWREG(ui32Base + PWM_O_RIS));
  1510. }
  1511. }
  1512. //*****************************************************************************
  1513. //
  1514. //! Clears the fault interrupt for a PWM module.
  1515. //!
  1516. //! \param ui32Base is the base address of the PWM module.
  1517. //! \param ui32FaultInts specifies the fault interrupts to clear.
  1518. //!
  1519. //! This function clears one or more fault interrupts by writing to the
  1520. //! appropriate bit of the PWM interrupt status register. The parameter
  1521. //! \e ui32FaultInts must be the logical OR of any of \b PWM_INT_FAULT0,
  1522. //! \b PWM_INT_FAULT1, \b PWM_INT_FAULT2, or \b PWM_INT_FAULT3.
  1523. //!
  1524. //! The fault interrupts are derived by performing a logical OR of each of the
  1525. //! configured fault trigger signals for a given generator. Therefore, these
  1526. //! interrupts are not directly related to the four possible FAULTn inputs to
  1527. //! the device but indicate that a fault has been signaled to one of the four
  1528. //! possible PWM generators.
  1529. //!
  1530. //! \note Because there is a write buffer in the Cortex-M processor, it may
  1531. //! take several clock cycles before the interrupt source is actually cleared.
  1532. //! Therefore, it is recommended that the interrupt source be cleared early in
  1533. //! the interrupt handler (as opposed to the very last action) to avoid
  1534. //! returning from the interrupt handler before the interrupt source is
  1535. //! actually cleared. Failure to do so may result in the interrupt handler
  1536. //! being immediately reentered (because the interrupt controller still sees
  1537. //! the interrupt source asserted).
  1538. //!
  1539. //! \return None.
  1540. //
  1541. //*****************************************************************************
  1542. void
  1543. PWMFaultIntClearExt(uint32_t ui32Base, uint32_t ui32FaultInts)
  1544. {
  1545. //
  1546. // Check the arguments.
  1547. //
  1548. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1549. ASSERT((ui32FaultInts & ~(PWM_INT_FAULT0 | PWM_INT_FAULT1 |
  1550. PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
  1551. //
  1552. // Clear the supplied fault bits.
  1553. //
  1554. HWREG(ui32Base + PWM_O_ISC) = ui32FaultInts;
  1555. }
  1556. //*****************************************************************************
  1557. //
  1558. //! Configures the minimum fault period and fault pin senses for a given
  1559. //! PWM generator.
  1560. //!
  1561. //! \param ui32Base is the base address of the PWM module.
  1562. //! \param ui32Gen is the PWM generator for which fault configuration is being
  1563. //! set. This function must be one of \b PWM_GEN_0, \b PWM_GEN_1,
  1564. //! \b PWM_GEN_2, or \b PWM_GEN_3.
  1565. //! \param ui32MinFaultPeriod is the minimum fault active period expressed in
  1566. //! PWM clock cycles.
  1567. //! \param ui32FaultSenses indicates which sense of each FAULT input should be
  1568. //! considered the ``asserted'' state. Valid values are logical OR
  1569. //! combinations of \b PWM_FAULTn_SENSE_HIGH and \b PWM_FAULTn_SENSE_LOW.
  1570. //!
  1571. //! This function configures the minimum fault period for a given generator
  1572. //! along with the sense of each of the 4 possible fault inputs. The minimum
  1573. //! fault period is expressed in PWM clock cycles and takes effect only if
  1574. //! PWMGenConfigure() is called with flag \b PWM_GEN_MODE_FAULT_PER set in the
  1575. //! \e ui32Config parameter. When a fault input is asserted, the minimum fault
  1576. //! period timer ensures that it remains asserted for at least the number of
  1577. //! clock cycles specified.
  1578. //!
  1579. //! \note This function is only available on devices supporting extended PWM
  1580. //! fault handling.
  1581. //!
  1582. //! \return None.
  1583. //
  1584. //*****************************************************************************
  1585. void
  1586. PWMGenFaultConfigure(uint32_t ui32Base, uint32_t ui32Gen,
  1587. uint32_t ui32MinFaultPeriod,
  1588. uint32_t ui32FaultSenses)
  1589. {
  1590. //
  1591. // Check the arguments.
  1592. //
  1593. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1594. ASSERT(_PWMGenValid(ui32Gen));
  1595. ASSERT(ui32MinFaultPeriod < PWM_X_MINFLTPER_M);
  1596. ASSERT((ui32FaultSenses & ~(PWM_FAULT0_SENSE_HIGH | PWM_FAULT0_SENSE_LOW |
  1597. PWM_FAULT1_SENSE_HIGH | PWM_FAULT1_SENSE_LOW |
  1598. PWM_FAULT2_SENSE_HIGH | PWM_FAULT2_SENSE_LOW |
  1599. PWM_FAULT3_SENSE_HIGH |
  1600. PWM_FAULT3_SENSE_LOW)) == 0);
  1601. //
  1602. // Write the minimum fault period.
  1603. //
  1604. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_MINFLTPER) =
  1605. ui32MinFaultPeriod;
  1606. //
  1607. // Write the fault senses.
  1608. //
  1609. HWREG(PWM_GEN_EXT_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSEN) =
  1610. ui32FaultSenses;
  1611. }
  1612. //*****************************************************************************
  1613. //
  1614. //! Configures the set of fault triggers for a given PWM generator.
  1615. //!
  1616. //! \param ui32Base is the base address of the PWM module.
  1617. //! \param ui32Gen is the PWM generator for which fault triggers are being set.
  1618. //! This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or
  1619. //! \b PWM_GEN_3.
  1620. //! \param ui32Group indicates the subset of possible faults that are to be
  1621. //! configured. This parameter must be \b PWM_FAULT_GROUP_0 or
  1622. //! \b PWM_FAULT_GROUP_1.
  1623. //! \param ui32FaultTriggers defines the set of inputs that are to contribute
  1624. //! towards generation of the fault signal to the given PWM generator. For
  1625. //! \b PWM_FAULT_GROUP_0, this is the logical OR of \b PWM_FAULT_FAULT0,
  1626. //! \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or \b PWM_FAULT_FAULT3. For
  1627. //! \b PWM_FAULT_GROUP_1, this is the logical OR of \b PWM_FAULT_DCMP0,
  1628. //! \b PWM_FAULT_DCMP1, \b PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3,
  1629. //! \b PWM_FAULT_DCMP4, \b PWM_FAULT_DCMP5, \b PWM_FAULT_DCMP6, or
  1630. //! \b PWM_FAULT_DCMP7.
  1631. //!
  1632. //! This function allows selection of the set of fault inputs that is combined
  1633. //! to generate a fault condition to a given PWM generator. By default, all
  1634. //! generators use only FAULT0 (for backwards compatibility) but if
  1635. //! PWMGenConfigure() is called with flag \b PWM_GEN_MODE_FAULT_SRC in the
  1636. //! \e ui32Config parameter, extended fault handling is enabled and this
  1637. //! function must be called to configure the fault triggers.
  1638. //!
  1639. //! The fault signal to the PWM generator is generated by ORing together each
  1640. //! of the signals specified in the \e ui32FaultTriggers parameter after having
  1641. //! adjusted the sense of each FAULTn input based on the configuration
  1642. //! previously set using a call to PWMGenFaultConfigure().
  1643. //!
  1644. //! \note This function is only available on devices supporting extended PWM
  1645. //! fault handling.
  1646. //!
  1647. //! \return None.
  1648. //
  1649. //*****************************************************************************
  1650. void
  1651. PWMGenFaultTriggerSet(uint32_t ui32Base, uint32_t ui32Gen,
  1652. uint32_t ui32Group, uint32_t ui32FaultTriggers)
  1653. {
  1654. //
  1655. // Check for valid parameters.
  1656. //
  1657. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1658. ASSERT(_PWMGenValid(ui32Gen));
  1659. ASSERT((ui32Group == PWM_FAULT_GROUP_0) ||
  1660. (ui32Group == PWM_FAULT_GROUP_1));
  1661. ASSERT((ui32Group == PWM_FAULT_GROUP_0) &&
  1662. ((ui32FaultTriggers & ~(PWM_FAULT_FAULT0 | PWM_FAULT_FAULT1 |
  1663. PWM_FAULT_FAULT2 | PWM_FAULT_FAULT3)) ==
  1664. 0));
  1665. ASSERT((ui32Group == PWM_FAULT_GROUP_1) &&
  1666. ((ui32FaultTriggers & ~(PWM_FAULT_DCMP0 | PWM_FAULT_DCMP1 |
  1667. PWM_FAULT_DCMP2 | PWM_FAULT_DCMP3 |
  1668. PWM_FAULT_DCMP4 | PWM_FAULT_DCMP5 |
  1669. PWM_FAULT_DCMP6 | PWM_FAULT_DCMP7)) == 0));
  1670. //
  1671. // Write the fault triggers to the appropriate register.
  1672. //
  1673. if(ui32Group == PWM_FAULT_GROUP_0)
  1674. {
  1675. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSRC0) =
  1676. ui32FaultTriggers;
  1677. }
  1678. else
  1679. {
  1680. HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSRC1) =
  1681. ui32FaultTriggers;
  1682. }
  1683. }
  1684. //*****************************************************************************
  1685. //
  1686. //! Returns the set of fault triggers currently configured for a given PWM
  1687. //! generator.
  1688. //!
  1689. //! \param ui32Base is the base address of the PWM module.
  1690. //! \param ui32Gen is the PWM generator for which fault triggers are being
  1691. //! queried. This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1,
  1692. //! \b PWM_GEN_2, or \b PWM_GEN_3.
  1693. //! \param ui32Group indicates the subset of faults that are being queried.
  1694. //! This parameter must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
  1695. //!
  1696. //! This function allows an application to query the current set of inputs that
  1697. //! contribute to the generation of a fault condition to a given PWM generator.
  1698. //!
  1699. //! \note This function is only available on devices supporting extended PWM
  1700. //! fault handling.
  1701. //!
  1702. //! \return Returns the current fault triggers configured for the fault group
  1703. //! provided. For \b PWM_FAULT_GROUP_0, the returned value is a logical OR of
  1704. //! \b PWM_FAULT_FAULT0, \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or
  1705. //! \b PWM_FAULT_FAULT3. For \b PWM_FAULT_GROUP_1, the return value is the
  1706. //! logical OR of \b PWM_FAULT_DCMP0, \b PWM_FAULT_DCMP1,
  1707. //! \b PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3, \b PWM_FAULT_DCMP4,
  1708. //! \b PWM_FAULT_DCMP5, \b PWM_FAULT_DCMP6, or \b PWM_FAULT_DCMP7.
  1709. //
  1710. //*****************************************************************************
  1711. uint32_t
  1712. PWMGenFaultTriggerGet(uint32_t ui32Base, uint32_t ui32Gen,
  1713. uint32_t ui32Group)
  1714. {
  1715. //
  1716. // Check for valid parameters.
  1717. //
  1718. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1719. ASSERT(_PWMGenValid(ui32Gen));
  1720. ASSERT((ui32Group == PWM_FAULT_GROUP_0) ||
  1721. (ui32Group == PWM_FAULT_GROUP_1));
  1722. //
  1723. // Return the current fault triggers.
  1724. //
  1725. if(ui32Group == PWM_FAULT_GROUP_0)
  1726. {
  1727. return(HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSRC0));
  1728. }
  1729. else
  1730. {
  1731. return(HWREG(PWM_GEN_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSRC1));
  1732. }
  1733. }
  1734. //*****************************************************************************
  1735. //
  1736. //! Returns the current state of the fault triggers for a given PWM generator.
  1737. //!
  1738. //! \param ui32Base is the base address of the PWM module.
  1739. //! \param ui32Gen is the PWM generator for which fault trigger states are
  1740. //! being queried. This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1,
  1741. //! \b PWM_GEN_2, or \b PWM_GEN_3.
  1742. //! \param ui32Group indicates the subset of faults that are being queried.
  1743. //! This parameter must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
  1744. //!
  1745. //! This function allows an application to query the current state of each of
  1746. //! the fault trigger inputs to a given PWM generator. The current state of
  1747. //! each fault trigger input is returned unless PWMGenConfigure() has
  1748. //! previously been called with flag \b PWM_GEN_MODE_FAULT_LATCHED in the
  1749. //! \e ui32Config parameter, in which case the returned status is the latched
  1750. //! fault trigger status.
  1751. //!
  1752. //! If latched faults are configured, the application must call
  1753. //! PWMGenFaultClear() to clear each trigger.
  1754. //!
  1755. //! \note This function is only available on devices supporting extended PWM
  1756. //! fault handling.
  1757. //!
  1758. //! \return Returns the current state of the fault triggers for the given PWM
  1759. //! generator. A set bit indicates that the associated trigger is active.
  1760. //! For \b PWM_FAULT_GROUP_0, the returned value is a logical OR of
  1761. //! \b PWM_FAULT_FAULT0, \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or
  1762. //! \b PWM_FAULT_FAULT3. For \b PWM_FAULT_GROUP_1, the return value is the
  1763. //! logical OR of \b PWM_FAULT_DCMP0, \b PWM_FAULT_DCMP1,
  1764. //! \b PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3, \b PWM_FAULT_DCMP4,
  1765. //! \b PWM_FAULT_DCMP5, \b PWM_FAULT_DCMP6, or \b PWM_FAULT_DCMP7.
  1766. //
  1767. //*****************************************************************************
  1768. uint32_t
  1769. PWMGenFaultStatus(uint32_t ui32Base, uint32_t ui32Gen,
  1770. uint32_t ui32Group)
  1771. {
  1772. //
  1773. // Check for valid parameters.
  1774. //
  1775. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1776. ASSERT(_PWMGenValid(ui32Gen));
  1777. ASSERT((ui32Group == PWM_FAULT_GROUP_0) ||
  1778. (ui32Group == PWM_FAULT_GROUP_1));
  1779. //
  1780. // Return the current fault status.
  1781. //
  1782. if(ui32Group == PWM_FAULT_GROUP_0)
  1783. {
  1784. return(HWREG(PWM_GEN_EXT_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSTAT0));
  1785. }
  1786. else
  1787. {
  1788. return(HWREG(PWM_GEN_EXT_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSTAT1));
  1789. }
  1790. }
  1791. //*****************************************************************************
  1792. //
  1793. //! Clears one or more latched fault triggers for a given PWM generator.
  1794. //!
  1795. //! \param ui32Base is the base address of the PWM module.
  1796. //! \param ui32Gen is the PWM generator for which fault trigger states are
  1797. //! being queried. This parameter must be one of \b PWM_GEN_0, \b PWM_GEN_1,
  1798. //! \b PWM_GEN_2, or \b PWM_GEN_3.
  1799. //! \param ui32Group indicates the subset of faults that are being queried.
  1800. //! This parameter must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
  1801. //! \param ui32FaultTriggers is the set of fault triggers which are to be
  1802. //! cleared.
  1803. //!
  1804. //! This function allows an application to clear the fault triggers for a
  1805. //! given PWM generator. This function is only required if PWMGenConfigure()
  1806. //! has previously been called with flag \b PWM_GEN_MODE_FAULT_LATCHED in
  1807. //! parameter \e ui32Config.
  1808. //!
  1809. //! \note This function is only available on devices supporting extended PWM
  1810. //! fault handling.
  1811. //!
  1812. //! \return None.
  1813. //
  1814. //*****************************************************************************
  1815. void
  1816. PWMGenFaultClear(uint32_t ui32Base, uint32_t ui32Gen,
  1817. uint32_t ui32Group, uint32_t ui32FaultTriggers)
  1818. {
  1819. //
  1820. // Check for valid parameters.
  1821. //
  1822. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1823. ASSERT(_PWMGenValid(ui32Gen));
  1824. ASSERT((ui32Group == PWM_FAULT_GROUP_0) ||
  1825. (ui32Group == PWM_FAULT_GROUP_1));
  1826. ASSERT((ui32Group == PWM_FAULT_GROUP_0) &&
  1827. ((ui32FaultTriggers & ~(PWM_FAULT_FAULT0 | PWM_FAULT_FAULT1 |
  1828. PWM_FAULT_FAULT2 | PWM_FAULT_FAULT3)) ==
  1829. 0));
  1830. ASSERT((ui32Group == PWM_FAULT_GROUP_1) &&
  1831. ((ui32FaultTriggers & ~(PWM_FAULT_DCMP0 | PWM_FAULT_DCMP1 |
  1832. PWM_FAULT_DCMP2 | PWM_FAULT_DCMP3 |
  1833. PWM_FAULT_DCMP4 | PWM_FAULT_DCMP5 |
  1834. PWM_FAULT_DCMP6 | PWM_FAULT_DCMP7)) == 0));
  1835. //
  1836. // Clear the given faults.
  1837. //
  1838. if(ui32Group == PWM_FAULT_GROUP_0)
  1839. {
  1840. HWREG(PWM_GEN_EXT_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSTAT0) =
  1841. ui32FaultTriggers;
  1842. }
  1843. else
  1844. {
  1845. HWREG(PWM_GEN_EXT_BADDR(ui32Base, ui32Gen) + PWM_O_X_FLTSTAT1) =
  1846. ui32FaultTriggers;
  1847. }
  1848. }
  1849. //*****************************************************************************
  1850. ///
  1851. //! Sets the PWM clock configuration.
  1852. //!
  1853. //! \param ui32Base is the base address of the PWM module.
  1854. //! \param ui32Config is the configuration for the PWM clock; it must be one of
  1855. //! \b PWM_SYSCLK_DIV_1, \b PWM_SYSCLK_DIV_2, \b PWM_SYSCLK_DIV_4,
  1856. //! \b PWM_SYSCLK_DIV_8, \b PWM_SYSCLK_DIV_16, \b PWM_SYSCLK_DIV_32, or
  1857. //! \b PWM_SYSCLK_DIV_64.
  1858. //!
  1859. //! This function sets the PWM clock divider as the PWM clock source. It also
  1860. //! configures the clock frequency to the PWM module as a division of the
  1861. //! system clock. This clock is used by the PWM module to generate PWM
  1862. //! signals; its rate forms the basis for all PWM signals.
  1863. //!
  1864. //! \note This function should not be used with TM4C123 devices. For
  1865. //! TM4C123 devices, the SysCtlPWMClockGet() function should be used.
  1866. //!
  1867. //! \note The clocking of the PWM is dependent upon the system clock rate as
  1868. //! configured by SysCtlClockFreqSet().
  1869. //!
  1870. //! \return None.
  1871. //
  1872. //*****************************************************************************
  1873. void
  1874. PWMClockSet(uint32_t ui32Base, uint32_t ui32Config)
  1875. {
  1876. //
  1877. // Check the arguments.
  1878. //
  1879. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1880. ASSERT((ui32Config == PWM_SYSCLK_DIV_2) ||
  1881. (ui32Config == PWM_SYSCLK_DIV_4) ||
  1882. (ui32Config == PWM_SYSCLK_DIV_8) ||
  1883. (ui32Config == PWM_SYSCLK_DIV_16) ||
  1884. (ui32Config == PWM_SYSCLK_DIV_32) ||
  1885. (ui32Config == PWM_SYSCLK_DIV_64));
  1886. //
  1887. // Set the PWM clock configuration into the PWM clock configuration
  1888. // register.
  1889. //
  1890. HWREG(ui32Base + PWM_O_CC) = ((HWREG(ui32Base + PWM_O_CC) &
  1891. ~(PWM_CC_USEPWM | PWM_CC_PWMDIV_M)) |
  1892. ui32Config);
  1893. }
  1894. //*****************************************************************************
  1895. //
  1896. //! Gets the current PWM clock configuration.
  1897. //!
  1898. //! \param ui32Base is the base address of the PWM module.
  1899. //!
  1900. //! This function returns the current PWM clock configuration.
  1901. //!
  1902. //! \note This function should not be used with TM4C123 devices. For
  1903. //! TM4C123 devices, the SysCtlPWMClockGet() function should be used.
  1904. //!
  1905. //! \return Returns the current PWM clock configuration; is one of
  1906. //! \b PWM_SYSCLK_DIV_1, \b PWM_SYSCLK_DIV_2, \b PWM_SYSCLK_DIV_4,
  1907. //! \b PWM_SYSCLK_DIV_8, \b PWM_SYSCLK_DIV_16, \b PWM_SYSCLK_DIV_32,
  1908. //! or \b PWM_SYSCLK_DIV_64.
  1909. //
  1910. //*****************************************************************************
  1911. uint32_t
  1912. PWMClockGet(uint32_t ui32Base)
  1913. {
  1914. //
  1915. // Check the arguments.
  1916. //
  1917. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1918. //
  1919. // Return the current PWM clock configuration. Make sure that
  1920. // PWM_SYSCLK_DIV_1 is returned in all cases where the divider is disabled.
  1921. //
  1922. if(!(HWREG(ui32Base + PWM_O_CC) & PWM_CC_USEPWM))
  1923. {
  1924. //
  1925. // The divider is not active so reflect this in the value we return.
  1926. //
  1927. return(PWM_SYSCLK_DIV_1);
  1928. }
  1929. else
  1930. {
  1931. //
  1932. // The divider is active so directly return the masked register value.
  1933. //
  1934. return(HWREG(ui32Base + PWM_O_CC) & (PWM_CC_USEPWM | PWM_CC_PWMDIV_M));
  1935. }
  1936. }
  1937. //*****************************************************************************
  1938. //
  1939. //! Sets the update mode or synchronization mode to the PWM outputs.
  1940. //!
  1941. //! \param ui32Base is the base address of the PWM module.
  1942. //! \param ui32PWMOutBits are the PWM outputs to be modified. This parameter
  1943. //! must be the logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT,
  1944. //! \b PWM_OUT_2_BIT, \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT,
  1945. //! \b PWM_OUT_6_BIT, or \b PWM_OUT_7_BIT.
  1946. //! \param ui32Mode specifies the enable update mode to use when enabling or
  1947. //! disabling PWM outputs.
  1948. //!
  1949. //! This function sets one of three possible update modes to enable or disable
  1950. //! the requested PWM outputs. The \e ui32Mode parameter controls when changes
  1951. //! made via calls to PWMOutputState() take effect. Possible values are:
  1952. //!
  1953. //! - \b PWM_OUTPUT_MODE_NO_SYNC, which enables/disables changes to take effect
  1954. //! immediately.
  1955. //! - \b PWM_OUTPUT_MODE_SYNC_LOCAL, which causes changes to take effect when
  1956. //! the local PWM generator's count next reaches 0.
  1957. //! - \b PWM_OUTPUT_MODE_SYNC_GLOBAL, which causes changes to take effect when
  1958. //! the local PWM generator's count next reaches 0 following a call to
  1959. //! PWMSyncUpdate() which specifies the same generator in its \e ui32GenBits
  1960. //! parameter.
  1961. //!
  1962. //! \note This function is only available on Snowflake class devices.
  1963. //!
  1964. //! \return None.
  1965. //
  1966. //*****************************************************************************
  1967. void
  1968. PWMOutputUpdateMode(uint32_t ui32Base, uint32_t ui32PWMOutBits,
  1969. uint32_t ui32Mode)
  1970. {
  1971. uint_fast8_t ui8Index;
  1972. uint32_t ui32PWMOutputMask;
  1973. uint32_t ui32UpdateValueMask;
  1974. uint32_t ui32UpdateValue;
  1975. uint32_t ui32Temp;
  1976. //
  1977. // Check the arguments.
  1978. //
  1979. ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
  1980. ASSERT(!(ui32PWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  1981. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  1982. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  1983. ASSERT((ui32Mode == PWM_OUTPUT_MODE_NO_SYNC) ||
  1984. (ui32Mode == PWM_OUTPUT_MODE_SYNC_LOCAL) ||
  1985. (ui32Mode == PWM_OUTPUT_MODE_SYNC_GLOBAL));
  1986. //
  1987. // Initialize the local variables
  1988. //
  1989. ui8Index = 0;
  1990. ui32PWMOutputMask = 1;
  1991. ui32UpdateValue = 0;
  1992. ui32UpdateValueMask = 0;
  1993. //
  1994. // Loop to find out which PWM outputs are to be modified.
  1995. //
  1996. while(ui8Index < 8)
  1997. {
  1998. //
  1999. // Check if this PWM output is to be modified.
  2000. //
  2001. if(ui32PWMOutputMask & ui32PWMOutBits)
  2002. {
  2003. //
  2004. // Set the update mode value for the requested PWM output by
  2005. // writing to the appropriate field.
  2006. //
  2007. ui32UpdateValue |= ui32Mode << (ui8Index * 2);
  2008. //
  2009. // Compute the mask for the bits to be updated.
  2010. //
  2011. ui32UpdateValueMask |= 3 << (ui8Index * 2);
  2012. }
  2013. //
  2014. // Update the PWM output to be checked and the index.
  2015. //
  2016. ui32PWMOutputMask = ui32PWMOutputMask << 1;
  2017. ui8Index++;
  2018. }
  2019. //
  2020. // Read the Enable Update register and mask the bits that are to be
  2021. // updated.
  2022. //
  2023. ui32Temp = ~ui32UpdateValueMask & HWREG(ui32Base + PWM_O_ENUPD);
  2024. //
  2025. // Write the updated values to Enable Update register.
  2026. //
  2027. HWREG(ui32Base + PWM_O_ENUPD) = ui32Temp | ui32UpdateValue;
  2028. }
  2029. //*****************************************************************************
  2030. //
  2031. // Close the Doxygen group.
  2032. //! @}
  2033. //
  2034. //*****************************************************************************