pwm.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  1. //*****************************************************************************
  2. //
  3. // pwm.c - API for the PWM modules
  4. //
  5. // Copyright (c) 2005-2010 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 6459 of the Stellaris Peripheral Driver Library.
  22. //
  23. //*****************************************************************************
  24. //*****************************************************************************
  25. //
  26. //! \addtogroup pwm_api
  27. //! @{
  28. //
  29. //*****************************************************************************
  30. #include "inc/hw_ints.h"
  31. #include "inc/hw_memmap.h"
  32. #include "inc/hw_pwm.h"
  33. #include "inc/hw_sysctl.h"
  34. #include "inc/hw_types.h"
  35. #include "driverlib/debug.h"
  36. #include "driverlib/interrupt.h"
  37. #include "driverlib/pwm.h"
  38. //*****************************************************************************
  39. //
  40. // Misc macros for manipulating the encoded generator and output defines used
  41. // by the API.
  42. //
  43. //*****************************************************************************
  44. #define PWM_GEN_BADDR(_mod_, _gen_) \
  45. ((_mod_) + (_gen_))
  46. #define PWM_GEN_EXT_BADDR(_mod_, _gen_) \
  47. ((_mod_) + PWM_GEN_EXT_0 + \
  48. ((_gen_) - PWM_GEN_0) * 2)
  49. #define PWM_OUT_BADDR(_mod_, _out_) \
  50. ((_mod_) + ((_out_) & 0xFFFFFFC0))
  51. #define PWM_IS_OUTPUT_ODD(_out_) \
  52. ((_out_) & 0x00000001)
  53. //*****************************************************************************
  54. //
  55. //! \internal
  56. //! Checks a PWM generator number.
  57. //!
  58. //! \param ulGen is the generator number.
  59. //!
  60. //! This function determines if a PWM generator number is valid.
  61. //!
  62. //! \return Returnes \b true if the generator number is valid and \b false
  63. //! otherwise.
  64. //
  65. //*****************************************************************************
  66. #ifdef DEBUG
  67. static tBoolean
  68. PWMGenValid(unsigned long ulGen)
  69. {
  70. return((ulGen == PWM_GEN_0) || (ulGen == PWM_GEN_1) ||
  71. (ulGen == PWM_GEN_2) || (ulGen == PWM_GEN_3));
  72. }
  73. #endif
  74. //*****************************************************************************
  75. //
  76. //! \internal
  77. //! Checks a PWM output number.
  78. //!
  79. //! \param ulPWMOut is the output number.
  80. //!
  81. //! This function determines if a PWM output number is valid.
  82. //!
  83. //! \return Returns \b true if the output number is valid and \b false
  84. //! otherwise.
  85. //
  86. //*****************************************************************************
  87. #ifdef DEBUG
  88. static tBoolean
  89. PWMOutValid(unsigned long ulPWMOut)
  90. {
  91. return((ulPWMOut == PWM_OUT_0) || (ulPWMOut == PWM_OUT_1) ||
  92. (ulPWMOut == PWM_OUT_2) || (ulPWMOut == PWM_OUT_3) ||
  93. (ulPWMOut == PWM_OUT_4) || (ulPWMOut == PWM_OUT_5) ||
  94. (ulPWMOut == PWM_OUT_6) || (ulPWMOut == PWM_OUT_7));
  95. }
  96. #endif
  97. //*****************************************************************************
  98. //
  99. //! Configures a PWM generator.
  100. //!
  101. //! \param ulBase is the base address of the PWM module.
  102. //! \param ulGen is the PWM generator to configure. Must be one of
  103. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  104. //! \param ulConfig is the configuration for the PWM generator.
  105. //!
  106. //! This function is used to set the mode of operation for a PWM generator.
  107. //! The counting mode, synchronization mode, and debug behavior are all
  108. //! configured. After configuration, the generator is left in the disabled
  109. //! state.
  110. //!
  111. //! A PWM generator can count in two different modes: count down mode or count
  112. //! up/down mode. In count down mode, it will count from a value down to zero,
  113. //! and then reset to the preset value. This will produce left-aligned PWM
  114. //! signals (that is the rising edge of the two PWM signals produced by the
  115. //! generator will occur at the same time). In count up/down mode, it will
  116. //! count up from zero to the preset value, count back down to zero, and then
  117. //! repeat the process. This will produce center-aligned PWM signals (that is,
  118. //! the middle of the high/low period of the PWM signals produced by the
  119. //! generator will occur at the same time).
  120. //!
  121. //! When the PWM generator parameters (period and pulse width) are modified,
  122. //! their affect on the output PWM signals can be delayed. In synchronous
  123. //! mode, the parameter updates are not applied until a synchronization event
  124. //! occurs. This allows multiple parameters to be modified and take affect
  125. //! simultaneously, instead of one at a time. Additionally, parameters to
  126. //! multiple PWM generators in synchronous mode can be updated simultaneously,
  127. //! allowing them to be treated as if they were a unified generator. In
  128. //! non-synchronous mode, the parameter updates are not delayed until a
  129. //! synchronization event. In either mode, the parameter updates only occur
  130. //! when the counter is at zero to help prevent oddly formed PWM signals during
  131. //! the update (that is, a PWM pulse that is too short or too long).
  132. //!
  133. //! The PWM generator can either pause or continue running when the processor
  134. //! is stopped via the debugger. If configured to pause, it will continue to
  135. //! count until it reaches zero, at which point it will pause until the
  136. //! processor is restarted. If configured to continue running, it will keep
  137. //! counting as if nothing had happened.
  138. //!
  139. //! The \e ulConfig parameter contains the desired configuration. It is the
  140. //! logical OR of the following:
  141. //!
  142. //! - \b PWM_GEN_MODE_DOWN or \b PWM_GEN_MODE_UP_DOWN to specify the counting
  143. //! mode
  144. //! - \b PWM_GEN_MODE_SYNC or \b PWM_GEN_MODE_NO_SYNC to specify the counter
  145. //! load and comparator update synchronization mode
  146. //! - \b PWM_GEN_MODE_DBG_RUN or \b PWM_GEN_MODE_DBG_STOP to specify the debug
  147. //! behavior
  148. //! - \b PWM_GEN_MODE_GEN_NO_SYNC, \b PWM_GEN_MODE_GEN_SYNC_LOCAL, or
  149. //! \b PWM_GEN_MODE_GEN_SYNC_GLOBAL to specify the update synchronization
  150. //! mode for generator counting mode changes
  151. //! - \b PWM_GEN_MODE_DB_NO_SYNC, \b PWM_GEN_MODE_DB_SYNC_LOCAL, or
  152. //! \b PWM_GEN_MODE_DB_SYNC_GLOBAL to specify the deadband parameter
  153. //! synchronization mode
  154. //! - \b PWM_GEN_MODE_FAULT_LATCHED or \b PWM_GEN_MODE_FAULT_UNLATCHED to
  155. //! specify whether fault conditions are latched or not
  156. //! - \b PWM_GEN_MODE_FAULT_MINPER or \b PWM_GEN_MODE_FAULT_NO_MINPER to
  157. //! specify whether minimum fault period support is required
  158. //! - \b PWM_GEN_MODE_FAULT_EXT or \b PWM_GEN_MODE_FAULT_LEGACY to specify
  159. //! whether extended fault source selection support is enabled or not
  160. //!
  161. //! Setting \b PWM_GEN_MODE_FAULT_MINPER allows an application to set the
  162. //! minimum duration of a PWM fault signal. Fault will be signaled for at
  163. //! least this time even if the external fault pin deasserts earlier. Care
  164. //! should be taken when using this mode since during the fault signal period,
  165. //! the fault interrupt from the PWM generator will remain asserted. The fault
  166. //! interrupt handler may, therefore, reenter immediately if it exits prior to
  167. //! expiration of the fault timer.
  168. //!
  169. //! \note Changes to the counter mode will affect the period of the PWM signals
  170. //! produced. PWMGenPeriodSet() and PWMPulseWidthSet() should be called after
  171. //! any changes to the counter mode of a generator.
  172. //!
  173. //! \return None.
  174. //
  175. //*****************************************************************************
  176. void
  177. PWMGenConfigure(unsigned long ulBase, unsigned long ulGen,
  178. unsigned long ulConfig)
  179. {
  180. //
  181. // Check the arguments.
  182. //
  183. ASSERT(ulBase == PWM_BASE);
  184. ASSERT(PWMGenValid(ulGen));
  185. //
  186. // Compute the generator's base address.
  187. //
  188. ulGen = PWM_GEN_BADDR(ulBase, ulGen);
  189. //
  190. // Change the global configuration of the generator.
  191. //
  192. HWREG(ulGen + PWM_O_X_CTL) = ((HWREG(ulGen + PWM_O_X_CTL) &
  193. ~(PWM_X_CTL_MODE | PWM_X_CTL_DEBUG |
  194. PWM_X_CTL_LATCH | PWM_X_CTL_MINFLTPER |
  195. PWM_X_CTL_FLTSRC | PWM_X_CTL_DBFALLUPD_M |
  196. PWM_X_CTL_DBRISEUPD_M |
  197. PWM_X_CTL_DBCTLUPD_M |
  198. PWM_X_CTL_GENBUPD_M |
  199. PWM_X_CTL_GENAUPD_M |
  200. PWM_X_CTL_LOADUPD | PWM_X_CTL_CMPAUPD |
  201. PWM_X_CTL_CMPBUPD)) | ulConfig);
  202. //
  203. // Set the individual PWM generator controls.
  204. //
  205. if(ulConfig & PWM_X_CTL_MODE)
  206. {
  207. //
  208. // In up/down count mode, set the signal high on up count comparison
  209. // and low on down count comparison (that is, center align the
  210. // signals).
  211. //
  212. HWREG(ulGen + PWM_O_X_GENA) = (PWM_X_GENA_ACTCMPAU_ONE |
  213. PWM_X_GENA_ACTCMPAD_ZERO);
  214. HWREG(ulGen + PWM_O_X_GENB) = (PWM_X_GENB_ACTCMPBU_ONE |
  215. PWM_X_GENB_ACTCMPBD_ZERO);
  216. }
  217. else
  218. {
  219. //
  220. // In down count mode, set the signal high on load and low on count
  221. // comparison (that is, left align the signals).
  222. //
  223. HWREG(ulGen + PWM_O_X_GENA) = (PWM_X_GENA_ACTLOAD_ONE |
  224. PWM_X_GENA_ACTCMPAD_ZERO);
  225. HWREG(ulGen + PWM_O_X_GENB) = (PWM_X_GENB_ACTLOAD_ONE |
  226. PWM_X_GENB_ACTCMPBD_ZERO);
  227. }
  228. }
  229. //*****************************************************************************
  230. //
  231. //! Set the period of a PWM generator.
  232. //!
  233. //! \param ulBase is the base address of the PWM module.
  234. //! \param ulGen is the PWM generator to be modified. Must be one of
  235. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  236. //! \param ulPeriod specifies the period of PWM generator output, measured
  237. //! in clock ticks.
  238. //!
  239. //! This function sets the period of the specified PWM generator block, where
  240. //! the period of the generator block is defined as the number of PWM clock
  241. //! ticks between pulses on the generator block zero signal.
  242. //!
  243. //! \note Any subsequent calls made to this function before an update occurs
  244. //! will cause the previous values to be overwritten.
  245. //!
  246. //! \return None.
  247. //
  248. //*****************************************************************************
  249. void
  250. PWMGenPeriodSet(unsigned long ulBase, unsigned long ulGen,
  251. unsigned long ulPeriod)
  252. {
  253. //
  254. // Check the arguments.
  255. //
  256. ASSERT(ulBase == PWM_BASE);
  257. ASSERT(PWMGenValid(ulGen));
  258. //
  259. // Compute the generator's base address.
  260. //
  261. ulGen = PWM_GEN_BADDR(ulBase, ulGen);
  262. //
  263. // Set the reload register based on the mode.
  264. //
  265. if(HWREG(ulGen + PWM_O_X_CTL) & PWM_X_CTL_MODE)
  266. {
  267. //
  268. // In up/down count mode, set the reload register to half the requested
  269. // period.
  270. //
  271. ASSERT((ulPeriod / 2) < 65536);
  272. HWREG(ulGen + PWM_O_X_LOAD) = ulPeriod / 2;
  273. }
  274. else
  275. {
  276. //
  277. // In down count mode, set the reload register to the requested period
  278. // minus one.
  279. //
  280. ASSERT((ulPeriod <= 65536) && (ulPeriod != 0));
  281. HWREG(ulGen + PWM_O_X_LOAD) = ulPeriod - 1;
  282. }
  283. }
  284. //*****************************************************************************
  285. //
  286. //! Gets the period of a PWM generator block.
  287. //!
  288. //! \param ulBase is the base address of the PWM module.
  289. //! \param ulGen is the PWM generator to query. Must be one of
  290. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  291. //!
  292. //! This function gets the period of the specified PWM generator block. The
  293. //! period of the generator block is defined as the number of PWM clock ticks
  294. //! between pulses on the generator block zero signal.
  295. //!
  296. //! If the update of the counter for the specified PWM generator has yet
  297. //! to be completed, the value returned may not be the active period. The
  298. //! value returned is the programmed period, measured in PWM clock ticks.
  299. //!
  300. //! \return Returns the programmed period of the specified generator block
  301. //! in PWM clock ticks.
  302. //
  303. //*****************************************************************************
  304. unsigned long
  305. PWMGenPeriodGet(unsigned long ulBase, unsigned long ulGen)
  306. {
  307. //
  308. // Check the arguments.
  309. //
  310. ASSERT(ulBase == PWM_BASE);
  311. ASSERT(PWMGenValid(ulGen));
  312. //
  313. // Compute the generator's base address.
  314. //
  315. ulGen = PWM_GEN_BADDR(ulBase, ulGen);
  316. //
  317. // Figure out the counter mode.
  318. //
  319. if(HWREG(ulGen + PWM_O_X_CTL) & PWM_X_CTL_MODE)
  320. {
  321. //
  322. // The period is twice the reload register value.
  323. //
  324. return(HWREG(ulGen + PWM_O_X_LOAD) * 2);
  325. }
  326. else
  327. {
  328. //
  329. // The period is the reload register value plus one.
  330. //
  331. return(HWREG(ulGen + PWM_O_X_LOAD) + 1);
  332. }
  333. }
  334. //*****************************************************************************
  335. //
  336. //! Enables the timer/counter for a PWM generator block.
  337. //!
  338. //! \param ulBase is the base address of the PWM module.
  339. //! \param ulGen is the PWM generator to be enabled. Must be one of
  340. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  341. //!
  342. //! This function allows the PWM clock to drive the timer/counter for the
  343. //! specified generator block.
  344. //!
  345. //! \return None.
  346. //
  347. //*****************************************************************************
  348. void
  349. PWMGenEnable(unsigned long ulBase, unsigned long ulGen)
  350. {
  351. //
  352. // Check the arguments.
  353. //
  354. ASSERT(ulBase == PWM_BASE);
  355. ASSERT(PWMGenValid(ulGen));
  356. //
  357. // Enable the PWM generator.
  358. //
  359. HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_CTL) |= PWM_X_CTL_ENABLE;
  360. }
  361. //*****************************************************************************
  362. //
  363. //! Disables the timer/counter for a PWM generator block.
  364. //!
  365. //! \param ulBase is the base address of the PWM module.
  366. //! \param ulGen is the PWM generator to be disabled. Must be one of
  367. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  368. //!
  369. //! This function blocks the PWM clock from driving the timer/counter for the
  370. //! specified generator block.
  371. //!
  372. //! \return None.
  373. //
  374. //*****************************************************************************
  375. void
  376. PWMGenDisable(unsigned long ulBase, unsigned long ulGen)
  377. {
  378. //
  379. // Check the arguments.
  380. //
  381. ASSERT(ulBase == PWM_BASE);
  382. ASSERT(PWMGenValid(ulGen));
  383. //
  384. // Disable the PWM generator.
  385. //
  386. HWREG(PWM_GEN_BADDR(ulBase, + ulGen) + PWM_O_X_CTL) &= ~(PWM_X_CTL_ENABLE);
  387. }
  388. //*****************************************************************************
  389. //
  390. //! Sets the pulse width for the specified PWM output.
  391. //!
  392. //! \param ulBase is the base address of the PWM module.
  393. //! \param ulPWMOut is the PWM output to modify. Must be one of \b PWM_OUT_0,
  394. //! \b PWM_OUT_1, \b PWM_OUT_2, \b PWM_OUT_3, \b PWM_OUT_4, \b PWM_OUT_5,
  395. //! \b PWM_OUT_6, or \b PWM_OUT_7.
  396. //! \param ulWidth specifies the width of the positive portion of the pulse.
  397. //!
  398. //! This function sets the pulse width for the specified PWM output, where the
  399. //! pulse width is defined as the number of PWM clock ticks.
  400. //!
  401. //! \note Any subsequent calls made to this function before an update occurs
  402. //! will cause the previous values to be overwritten.
  403. //!
  404. //! \return None.
  405. //
  406. //*****************************************************************************
  407. void
  408. PWMPulseWidthSet(unsigned long ulBase, unsigned long ulPWMOut,
  409. unsigned long ulWidth)
  410. {
  411. unsigned long ulGenBase, ulReg;
  412. //
  413. // Check the arguments.
  414. //
  415. ASSERT(ulBase == PWM_BASE);
  416. ASSERT(PWMOutValid(ulPWMOut));
  417. //
  418. // Compute the generator's base address.
  419. //
  420. ulGenBase = PWM_OUT_BADDR(ulBase, ulPWMOut);
  421. //
  422. // If the counter is in up/down count mode, divide the width by two.
  423. //
  424. if(HWREG(ulGenBase + PWM_O_X_CTL) & PWM_X_CTL_MODE)
  425. {
  426. ulWidth /= 2;
  427. }
  428. //
  429. // Get the period.
  430. //
  431. ulReg = HWREG(ulGenBase + PWM_O_X_LOAD);
  432. //
  433. // Make sure the width is not too large.
  434. //
  435. ASSERT(ulWidth < ulReg);
  436. //
  437. // Compute the compare value.
  438. //
  439. ulReg = ulReg - ulWidth;
  440. //
  441. // Write to the appropriate registers.
  442. //
  443. if(PWM_IS_OUTPUT_ODD(ulPWMOut))
  444. {
  445. HWREG(ulGenBase + PWM_O_X_CMPB) = ulReg;
  446. }
  447. else
  448. {
  449. HWREG(ulGenBase + PWM_O_X_CMPA) = ulReg;
  450. }
  451. }
  452. //*****************************************************************************
  453. //
  454. //! Gets the pulse width of a PWM output.
  455. //!
  456. //! \param ulBase is the base address of the PWM module.
  457. //! \param ulPWMOut is the PWM output to query. Must be one of \b PWM_OUT_0,
  458. //! \b PWM_OUT_1, \b PWM_OUT_2, \b PWM_OUT_3, \b PWM_OUT_4, \b PWM_OUT_5,
  459. //! \b PWM_OUT_6, or \b PWM_OUT_7.
  460. //!
  461. //! This function gets the currently programmed pulse width for the specified
  462. //! PWM output. If the update of the comparator for the specified output has
  463. //! yet to be completed, the value returned may not be the active pulse width.
  464. //! The value returned is the programmed pulse width, measured in PWM clock
  465. //! ticks.
  466. //!
  467. //! \return Returns the width of the pulse in PWM clock ticks.
  468. //
  469. //*****************************************************************************
  470. unsigned long
  471. PWMPulseWidthGet(unsigned long ulBase, unsigned long ulPWMOut)
  472. {
  473. unsigned long ulGenBase, ulReg, ulLoad;
  474. //
  475. // Check the arguments.
  476. //
  477. ASSERT(ulBase == PWM_BASE);
  478. ASSERT(PWMOutValid(ulPWMOut));
  479. //
  480. // Compute the generator's base address.
  481. //
  482. ulGenBase = PWM_OUT_BADDR(ulBase, ulPWMOut);
  483. //
  484. // Then compute the pulse width. If mode is UpDown, set
  485. // width = (load - compare) * 2. Otherwise, set width = load - compare.
  486. //
  487. ulLoad = HWREG(ulGenBase + PWM_O_X_LOAD);
  488. if(PWM_IS_OUTPUT_ODD(ulPWMOut))
  489. {
  490. ulReg = HWREG(ulGenBase + PWM_O_X_CMPB);
  491. }
  492. else
  493. {
  494. ulReg = HWREG(ulGenBase + PWM_O_X_CMPA);
  495. }
  496. ulReg = ulLoad - ulReg;
  497. //
  498. // If in up/down count mode, double the pulse width.
  499. //
  500. if(HWREG(ulGenBase + PWM_O_X_CTL) & PWM_X_CTL_MODE)
  501. {
  502. ulReg = ulReg * 2;
  503. }
  504. //
  505. // Return the pulse width.
  506. //
  507. return(ulReg);
  508. }
  509. //*****************************************************************************
  510. //
  511. //! Enables the PWM dead band output, and sets the dead band delays.
  512. //!
  513. //! \param ulBase is the base address of the PWM module.
  514. //! \param ulGen is the PWM generator to modify. Must be one of
  515. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  516. //! \param usRise specifies the width of delay from the rising edge.
  517. //! \param usFall specifies the width of delay from the falling edge.
  518. //!
  519. //! This function sets the dead bands for the specified PWM generator,
  520. //! where the dead bands are defined as the number of \b PWM clock ticks
  521. //! from the rising or falling edge of the generator's \b OutA signal.
  522. //! Note that this function causes the coupling of \b OutB to \b OutA.
  523. //!
  524. //! \return None.
  525. //
  526. //*****************************************************************************
  527. void
  528. PWMDeadBandEnable(unsigned long ulBase, unsigned long ulGen,
  529. unsigned short usRise, unsigned short usFall)
  530. {
  531. //
  532. // Check the arguments.
  533. //
  534. ASSERT(ulBase == PWM_BASE);
  535. ASSERT(PWMGenValid(ulGen));
  536. ASSERT(usRise < 4096);
  537. ASSERT(usFall < 4096);
  538. //
  539. // Compute the generator's base address.
  540. //
  541. ulGen = PWM_GEN_BADDR(ulBase, ulGen);
  542. //
  543. // Write the dead band delay values.
  544. //
  545. HWREG(ulGen + PWM_O_X_DBRISE) = usRise;
  546. HWREG(ulGen + PWM_O_X_DBFALL) = usFall;
  547. //
  548. // Enable the deadband functionality.
  549. //
  550. HWREG(ulGen + PWM_O_X_DBCTL) |= PWM_X_DBCTL_ENABLE;
  551. }
  552. //*****************************************************************************
  553. //
  554. //! Disables the PWM dead band output.
  555. //!
  556. //! \param ulBase is the base address of the PWM module.
  557. //! \param ulGen is the PWM generator to modify. Must be one of
  558. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  559. //!
  560. //! This function disables the dead band mode for the specified PWM generator.
  561. //! Doing so decouples the \b OutA and \b OutB signals.
  562. //!
  563. //! \return None.
  564. //
  565. //*****************************************************************************
  566. void
  567. PWMDeadBandDisable(unsigned long ulBase, unsigned long ulGen)
  568. {
  569. //
  570. // Check the arguments.
  571. //
  572. ASSERT(ulBase == PWM_BASE);
  573. ASSERT(PWMGenValid(ulGen));
  574. //
  575. // Disable the deadband functionality.
  576. //
  577. HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_DBCTL) &=
  578. ~(PWM_X_DBCTL_ENABLE);
  579. }
  580. //*****************************************************************************
  581. //
  582. //! Synchronizes all pending updates.
  583. //!
  584. //! \param ulBase is the base address of the PWM module.
  585. //! \param ulGenBits are the PWM generator blocks to be updated. Must be the
  586. //! logical OR of any of \b PWM_GEN_0_BIT, \b PWM_GEN_1_BIT,
  587. //! \b PWM_GEN_2_BIT, or \b PWM_GEN_3_BIT.
  588. //!
  589. //! For the selected PWM generators, this function causes all queued updates to
  590. //! the period or pulse width to be applied the next time the corresponding
  591. //! counter becomes zero.
  592. //!
  593. //! \return None.
  594. //
  595. //*****************************************************************************
  596. void
  597. PWMSyncUpdate(unsigned long ulBase, unsigned long ulGenBits)
  598. {
  599. //
  600. // Check the arguments.
  601. //
  602. ASSERT(ulBase == PWM_BASE);
  603. ASSERT(!(ulGenBits & ~(PWM_GEN_0_BIT | PWM_GEN_1_BIT | PWM_GEN_2_BIT |
  604. PWM_GEN_3_BIT)));
  605. //
  606. // Synchronize pending PWM register changes.
  607. //
  608. HWREG(ulBase + PWM_O_CTL) = ulGenBits;
  609. }
  610. //*****************************************************************************
  611. //
  612. //! Synchronizes the counters in one or multiple PWM generator blocks.
  613. //!
  614. //! \param ulBase is the base address of the PWM module.
  615. //! \param ulGenBits are the PWM generator blocks to be synchronized. Must be
  616. //! the logical OR of any of \b PWM_GEN_0_BIT, \b PWM_GEN_1_BIT,
  617. //! \b PWM_GEN_2_BIT, or \b PWM_GEN_3_BIT.
  618. //!
  619. //! For the selected PWM module, this function synchronizes the time base
  620. //! of the generator blocks by causing the specified generator counters to be
  621. //! reset to zero.
  622. //!
  623. //! \return None.
  624. //
  625. //*****************************************************************************
  626. void
  627. PWMSyncTimeBase(unsigned long ulBase, unsigned long ulGenBits)
  628. {
  629. //
  630. // Check the arguments.
  631. //
  632. ASSERT(ulBase == PWM_BASE);
  633. ASSERT(!(ulGenBits & ~(PWM_GEN_0_BIT | PWM_GEN_1_BIT | PWM_GEN_2_BIT |
  634. PWM_GEN_3_BIT)));
  635. //
  636. // Synchronize the counters in the specified generators by writing to the
  637. // module's synchronization register.
  638. //
  639. HWREG(ulBase + PWM_O_SYNC) = ulGenBits;
  640. }
  641. //*****************************************************************************
  642. //
  643. //! Enables or disables PWM outputs.
  644. //!
  645. //! \param ulBase is the base address of the PWM module.
  646. //! \param ulPWMOutBits are the PWM outputs to be modified. Must be the
  647. //! logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT, \b PWM_OUT_2_BIT,
  648. //! \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT, \b PWM_OUT_6_BIT,
  649. //! or \b PWM_OUT_7_BIT.
  650. //! \param bEnable determines if the signal is enabled or disabled.
  651. //!
  652. //! This function is used to enable or disable the selected PWM outputs. The
  653. //! outputs are selected using the parameter \e ulPWMOutBits. The parameter
  654. //! \e bEnable determines the state of the selected outputs. If \e bEnable is
  655. //! \b true, then the selected PWM outputs are enabled, or placed in the active
  656. //! state. If \e bEnable is \b false, then the selected outputs are disabled,
  657. //! or placed in the inactive state.
  658. //!
  659. //! \return None.
  660. //
  661. //*****************************************************************************
  662. void
  663. PWMOutputState(unsigned long ulBase, unsigned long ulPWMOutBits,
  664. tBoolean bEnable)
  665. {
  666. //
  667. // Check the arguments.
  668. //
  669. ASSERT(ulBase == PWM_BASE);
  670. ASSERT(!(ulPWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  671. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  672. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  673. //
  674. // Read the module's ENABLE output control register, and set or clear the
  675. // requested bits.
  676. //
  677. if(bEnable == true)
  678. {
  679. HWREG(ulBase + PWM_O_ENABLE) |= ulPWMOutBits;
  680. }
  681. else
  682. {
  683. HWREG(ulBase + PWM_O_ENABLE) &= ~(ulPWMOutBits);
  684. }
  685. }
  686. //*****************************************************************************
  687. //
  688. //! Selects the inversion mode for PWM outputs.
  689. //!
  690. //! \param ulBase is the base address of the PWM module.
  691. //! \param ulPWMOutBits are the PWM outputs to be modified. Must be the
  692. //! logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT, \b PWM_OUT_2_BIT,
  693. //! \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT, \b PWM_OUT_6_BIT, or
  694. //! \b PWM_OUT_7_BIT.
  695. //! \param bInvert determines if the signal is inverted or passed through.
  696. //!
  697. //! This function is used to select the inversion mode for the selected PWM
  698. //! outputs. The outputs are selected using the parameter \e ulPWMOutBits.
  699. //! The parameter \e bInvert determines the inversion mode for the selected
  700. //! outputs. If \e bInvert is \b true, this function will cause the specified
  701. //! PWM output signals to be inverted, or made active low. If \e bInvert is
  702. //! \b false, the specified output will be passed through as is, or be made
  703. //! active high.
  704. //!
  705. //! \return None.
  706. //
  707. //*****************************************************************************
  708. void
  709. PWMOutputInvert(unsigned long ulBase, unsigned long ulPWMOutBits,
  710. tBoolean bInvert)
  711. {
  712. //
  713. // Check the arguments.
  714. //
  715. ASSERT(ulBase == PWM_BASE);
  716. ASSERT(!(ulPWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  717. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  718. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  719. //
  720. // Read the module's INVERT output control register, and set or clear the
  721. // requested bits.
  722. //
  723. if(bInvert == true)
  724. {
  725. HWREG(ulBase + PWM_O_INVERT) |= ulPWMOutBits;
  726. }
  727. else
  728. {
  729. HWREG(ulBase + PWM_O_INVERT) &= ~(ulPWMOutBits);
  730. }
  731. }
  732. //*****************************************************************************
  733. //
  734. //! Specifies the level of PWM outputs suppressed in response to a fault
  735. //! condition.
  736. //!
  737. //! \param ulBase is the base address of the PWM module.
  738. //! \param ulPWMOutBits are the PWM outputs to be modified. Must be the
  739. //! logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT, \b PWM_OUT_2_BIT,
  740. //! \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT, \b PWM_OUT_6_BIT, or
  741. //! \b PWM_OUT_7_BIT.
  742. //! \param bDriveHigh determines if the signal is driven high or low during an
  743. //! active fault condition.
  744. //!
  745. //! This function determines whether a PWM output pin that is suppressed in
  746. //! response to a fault condition will be driven high or low. The affected
  747. //! outputs are selected using the parameter \e ulPWMOutBits. The parameter
  748. //! \e bDriveHigh determines the output level for the pins identified by
  749. //! \e ulPWMOutBits. If \e bDriveHigh is \b true then the selected outputs
  750. //! will be driven high when a fault is detected. If it is \e false, the pins
  751. //! will be driven low.
  752. //!
  753. //! In a fault condition, pins which have not been configured to be suppressed
  754. //! via a call to PWMOutputFault() are unaffected by this function.
  755. //!
  756. //! \note This function is available only on devices which support extended
  757. //! PWM fault handling.
  758. //!
  759. //! \return None.
  760. //
  761. //*****************************************************************************
  762. void
  763. PWMOutputFaultLevel(unsigned long ulBase, unsigned long ulPWMOutBits,
  764. tBoolean bDriveHigh)
  765. {
  766. //
  767. // Check the arguments.
  768. //
  769. ASSERT(HWREG(SYSCTL_DC5) & SYSCTL_DC5_PWMEFLT);
  770. ASSERT(ulBase == PWM_BASE);
  771. ASSERT(!(ulPWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  772. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  773. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  774. //
  775. // Read the module's FAULT output control register, and set or clear the
  776. // requested bits.
  777. //
  778. if(bDriveHigh == true)
  779. {
  780. HWREG(ulBase + PWM_O_FAULTVAL) |= ulPWMOutBits;
  781. }
  782. else
  783. {
  784. HWREG(ulBase + PWM_O_FAULTVAL) &= ~(ulPWMOutBits);
  785. }
  786. }
  787. //*****************************************************************************
  788. //
  789. //! Specifies the state of PWM outputs in response to a fault condition.
  790. //!
  791. //! \param ulBase is the base address of the PWM module.
  792. //! \param ulPWMOutBits are the PWM outputs to be modified. Must be the
  793. //! logical OR of any of \b PWM_OUT_0_BIT, \b PWM_OUT_1_BIT, \b PWM_OUT_2_BIT,
  794. //! \b PWM_OUT_3_BIT, \b PWM_OUT_4_BIT, \b PWM_OUT_5_BIT, \b PWM_OUT_6_BIT, or
  795. //! \b PWM_OUT_7_BIT.
  796. //! \param bFaultSuppress determines if the signal is suppressed or passed
  797. //! through during an active fault condition.
  798. //!
  799. //! This function sets the fault handling characteristics of the selected PWM
  800. //! outputs. The outputs are selected using the parameter \e ulPWMOutBits.
  801. //! The parameter \e bFaultSuppress determines the fault handling
  802. //! characteristics for the selected outputs. If \e bFaultSuppress is \b true,
  803. //! then the selected outputs will be made inactive. If \e bFaultSuppress is
  804. //! \b false, then the selected outputs are unaffected by the detected fault.
  805. //!
  806. //! On devices supporting extended PWM fault handling, the state the affected
  807. //! output pins are driven to can be configured with PWMOutputFaultLevel(). If
  808. //! not configured, or if the device does not support extended PWM fault
  809. //! handling, affected outputs will be driven low on a fault condition.
  810. //!
  811. //! \return None.
  812. //
  813. //*****************************************************************************
  814. void
  815. PWMOutputFault(unsigned long ulBase, unsigned long ulPWMOutBits,
  816. tBoolean bFaultSuppress)
  817. {
  818. //
  819. // Check the arguments.
  820. //
  821. ASSERT(ulBase == PWM_BASE);
  822. ASSERT(!(ulPWMOutBits & ~(PWM_OUT_0_BIT | PWM_OUT_1_BIT | PWM_OUT_2_BIT |
  823. PWM_OUT_3_BIT | PWM_OUT_4_BIT | PWM_OUT_5_BIT |
  824. PWM_OUT_6_BIT | PWM_OUT_7_BIT)));
  825. //
  826. // Read the module's FAULT output control register, and set or clear the
  827. // requested bits.
  828. //
  829. if(bFaultSuppress == true)
  830. {
  831. HWREG(ulBase + PWM_O_FAULT) |= ulPWMOutBits;
  832. }
  833. else
  834. {
  835. HWREG(ulBase + PWM_O_FAULT) &= ~(ulPWMOutBits);
  836. }
  837. }
  838. //*****************************************************************************
  839. //
  840. //! Registers an interrupt handler for the specified PWM generator block.
  841. //!
  842. //! \param ulBase is the base address of the PWM module.
  843. //! \param ulGen is the PWM generator in question. Must be one of
  844. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  845. //! \param pfnIntHandler is a pointer to the function to be called when the PWM
  846. //! generator interrupt occurs.
  847. //!
  848. //! This function will ensure that the interrupt handler specified by
  849. //! \e pfnIntHandler is called when an interrupt is detected for the specified
  850. //! PWM generator block. This function will also enable the corresponding
  851. //! PWM generator interrupt in the interrupt controller; individual generator
  852. //! interrupts and interrupt sources must be enabled with PWMIntEnable() and
  853. //! PWMGenIntTrigEnable().
  854. //!
  855. //! \sa IntRegister() for important information about registering interrupt
  856. //! handlers.
  857. //!
  858. //! \return None.
  859. //
  860. //*****************************************************************************
  861. void
  862. PWMGenIntRegister(unsigned long ulBase, unsigned long ulGen,
  863. void (*pfnIntHandler)(void))
  864. {
  865. unsigned long ulInt;
  866. //
  867. // Check the arguments.
  868. //
  869. ASSERT(ulBase == PWM_BASE);
  870. ASSERT(PWMGenValid(ulGen));
  871. //
  872. // Get the interrupt number associated with the specified generator.
  873. //
  874. if(ulGen == PWM_GEN_3)
  875. {
  876. ulInt = INT_PWM3;
  877. }
  878. else
  879. {
  880. ulInt = INT_PWM0 + (ulGen >> 6) - 1;
  881. }
  882. //
  883. // Register the interrupt handler.
  884. //
  885. IntRegister(ulInt, pfnIntHandler);
  886. //
  887. // Enable the PWMx interrupt.
  888. //
  889. IntEnable(ulInt);
  890. }
  891. //*****************************************************************************
  892. //
  893. //! Removes an interrupt handler for the specified PWM generator block.
  894. //!
  895. //! \param ulBase is the base address of the PWM module.
  896. //! \param ulGen is the PWM generator in question. Must be one of
  897. //! \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  898. //!
  899. //! This function will unregister the interrupt handler for the specified
  900. //! PWM generator block. This function will also disable the corresponding
  901. //! PWM generator interrupt in the interrupt controller; individual generator
  902. //! interrupts and interrupt sources must be disabled with PWMIntDisable() and
  903. //! PWMGenIntTrigDisable().
  904. //!
  905. //! \sa IntRegister() for important information about registering interrupt
  906. //! handlers.
  907. //!
  908. //! \return None.
  909. //
  910. //*****************************************************************************
  911. void
  912. PWMGenIntUnregister(unsigned long ulBase, unsigned long ulGen)
  913. {
  914. unsigned long ulInt;
  915. //
  916. // Check the arguments.
  917. //
  918. ASSERT(ulBase == PWM_BASE);
  919. ASSERT(PWMGenValid(ulGen));
  920. //
  921. // Get the interrupt number associated with the specified generator.
  922. //
  923. if(ulGen == PWM_GEN_3)
  924. {
  925. ulInt = INT_PWM3;
  926. }
  927. else
  928. {
  929. ulInt = INT_PWM0 + (ulGen >> 6) - 1;
  930. }
  931. //
  932. // Disable the PWMx interrupt.
  933. //
  934. IntDisable(ulInt);
  935. //
  936. // Unregister the interrupt handler.
  937. //
  938. IntUnregister(ulInt);
  939. }
  940. //*****************************************************************************
  941. //
  942. //! Registers an interrupt handler for a fault condition detected in a PWM
  943. //! module.
  944. //!
  945. //! \param ulBase is the base address of the PWM module.
  946. //! \param pfnIntHandler is a pointer to the function to be called when the PWM
  947. //! fault interrupt occurs.
  948. //!
  949. //! This function will ensure that the interrupt handler specified by
  950. //! \e pfnIntHandler is called when a fault interrupt is detected for the
  951. //! selected PWM module. This function will also enable the PWM fault
  952. //! interrupt in the NVIC; the PWM fault interrupt must also be enabled at the
  953. //! module level using PWMIntEnable().
  954. //!
  955. //! \sa IntRegister() for important information about registering interrupt
  956. //! handlers.
  957. //!
  958. //! \return None.
  959. //
  960. //*****************************************************************************
  961. void
  962. PWMFaultIntRegister(unsigned long ulBase, void (*pfnIntHandler)(void))
  963. {
  964. //
  965. // Check the arguments.
  966. //
  967. ASSERT(ulBase == PWM_BASE);
  968. //
  969. // Register the interrupt handler, returning an error if one occurs.
  970. //
  971. IntRegister(INT_PWM_FAULT, pfnIntHandler);
  972. //
  973. // Enable the PWM fault interrupt.
  974. //
  975. IntEnable(INT_PWM_FAULT);
  976. }
  977. //*****************************************************************************
  978. //
  979. //! Removes the PWM fault condition interrupt handler.
  980. //!
  981. //! \param ulBase is the base address of the PWM module.
  982. //!
  983. //! This function will remove the interrupt handler for a PWM fault interrupt
  984. //! from the selected PWM module. This function will also disable the PWM
  985. //! fault interrupt in the NVIC; the PWM fault interrupt must also be disabled
  986. //! at the module level using PWMIntDisable().
  987. //!
  988. //! \sa IntRegister() for important information about registering interrupt
  989. //! handlers.
  990. //!
  991. //! \return None.
  992. //
  993. //*****************************************************************************
  994. void
  995. PWMFaultIntUnregister(unsigned long ulBase)
  996. {
  997. //
  998. // Check the arguments.
  999. //
  1000. ASSERT(ulBase == PWM_BASE);
  1001. //
  1002. // Disable the PWM fault interrupt.
  1003. //
  1004. IntDisable(INT_PWM_FAULT);
  1005. //
  1006. // Unregister the interrupt handler, returning an error if one occurs.
  1007. //
  1008. IntUnregister(INT_PWM_FAULT);
  1009. }
  1010. //*****************************************************************************
  1011. //
  1012. //! Enables interrupts and triggers for the specified PWM generator block.
  1013. //!
  1014. //! \param ulBase is the base address of the PWM module.
  1015. //! \param ulGen is the PWM generator to have interrupts and triggers enabled.
  1016. //! Must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1017. //! \param ulIntTrig specifies the interrupts and triggers to be enabled.
  1018. //!
  1019. //! Unmasks the specified interrupt(s) and trigger(s) by setting the
  1020. //! specified bits of the interrupt/trigger enable register for the specified
  1021. //! PWM generator. The \e ulIntTrig parameter is the logical OR of
  1022. //! \b PWM_INT_CNT_ZERO, \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU,
  1023. //! \b PWM_INT_CNT_AD, \b PWM_INT_CNT_BU, \b PWM_INT_CNT_BD,
  1024. //! \b PWM_TR_CNT_ZERO, \b PWM_TR_CNT_LOAD, \b PWM_TR_CNT_AU, \b PWM_TR_CNT_AD,
  1025. //! \b PWM_TR_CNT_BU, or \b PWM_TR_CNT_BD.
  1026. //!
  1027. //! \return None.
  1028. //
  1029. //*****************************************************************************
  1030. void
  1031. PWMGenIntTrigEnable(unsigned long ulBase, unsigned long ulGen,
  1032. unsigned long ulIntTrig)
  1033. {
  1034. //
  1035. // Check the arguments.
  1036. //
  1037. ASSERT(ulBase == PWM_BASE);
  1038. ASSERT(PWMGenValid(ulGen));
  1039. ASSERT((ulIntTrig & ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD |
  1040. PWM_INT_CNT_AU | PWM_INT_CNT_AD | PWM_INT_CNT_BU |
  1041. PWM_INT_CNT_BD | PWM_TR_CNT_ZERO | PWM_TR_CNT_LOAD |
  1042. PWM_TR_CNT_AU | PWM_TR_CNT_AD | PWM_TR_CNT_BU |
  1043. PWM_TR_CNT_BD)) == 0);
  1044. //
  1045. // Enable the specified interrupts/triggers.
  1046. //
  1047. HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_INTEN) |= ulIntTrig;
  1048. }
  1049. //*****************************************************************************
  1050. //
  1051. //! Disables interrupts for the specified PWM generator block.
  1052. //!
  1053. //! \param ulBase is the base address of the PWM module.
  1054. //! \param ulGen is the PWM generator to have interrupts and triggers disabled.
  1055. //! Must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1056. //! \param ulIntTrig specifies the interrupts and triggers to be disabled.
  1057. //!
  1058. //! Masks the specified interrupt(s) and trigger(s) by clearing the
  1059. //! specified bits of the interrupt/trigger enable register for the specified
  1060. //! PWM generator. The \e ulIntTrig parameter is the logical OR of
  1061. //! \b PWM_INT_CNT_ZERO, \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU,
  1062. //! \b PWM_INT_CNT_AD, \b PWM_INT_CNT_BU, \b PWM_INT_CNT_BD,
  1063. //! \b PWM_TR_CNT_ZERO, \b PWM_TR_CNT_LOAD, \b PWM_TR_CNT_AU, \b PWM_TR_CNT_AD,
  1064. //! \b PWM_TR_CNT_BU, or \b PWM_TR_CNT_BD.
  1065. //!
  1066. //! \return None.
  1067. //
  1068. //*****************************************************************************
  1069. void
  1070. PWMGenIntTrigDisable(unsigned long ulBase, unsigned long ulGen,
  1071. unsigned long ulIntTrig)
  1072. {
  1073. //
  1074. // Check the arguments.
  1075. //
  1076. ASSERT(ulBase == PWM_BASE);
  1077. ASSERT(PWMGenValid(ulGen));
  1078. ASSERT((ulIntTrig & ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD |
  1079. PWM_INT_CNT_AU | PWM_INT_CNT_AD | PWM_INT_CNT_BU |
  1080. PWM_INT_CNT_BD | PWM_TR_CNT_ZERO | PWM_TR_CNT_LOAD |
  1081. PWM_TR_CNT_AU | PWM_TR_CNT_AD | PWM_TR_CNT_BU |
  1082. PWM_TR_CNT_BD)) == 0);
  1083. //
  1084. // Disable the specified interrupts/triggers.
  1085. //
  1086. HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_INTEN) &= ~(ulIntTrig);
  1087. }
  1088. //*****************************************************************************
  1089. //
  1090. //! Gets interrupt status for the specified PWM generator block.
  1091. //!
  1092. //! \param ulBase is the base address of the PWM module.
  1093. //! \param ulGen is the PWM generator to query. Must be one of \b PWM_GEN_0,
  1094. //! \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1095. //! \param bMasked specifies whether masked or raw interrupt status is
  1096. //! returned.
  1097. //!
  1098. //! If \e bMasked is set as \b true, then the masked interrupt status is
  1099. //! returned; otherwise, the raw interrupt status will be returned.
  1100. //!
  1101. //! \return Returns the contents of the interrupt status register, or the
  1102. //! contents of the raw interrupt status register, for the specified
  1103. //! PWM generator.
  1104. //
  1105. //*****************************************************************************
  1106. unsigned long
  1107. PWMGenIntStatus(unsigned long ulBase, unsigned long ulGen, tBoolean bMasked)
  1108. {
  1109. //
  1110. // Check the arguments.
  1111. //
  1112. ASSERT(ulBase == PWM_BASE);
  1113. ASSERT(PWMGenValid(ulGen));
  1114. //
  1115. // Compute the generator's base address.
  1116. //
  1117. ulGen = PWM_GEN_BADDR(ulBase, ulGen);
  1118. //
  1119. // Read and return the specified generator's raw or enabled interrupt
  1120. // status.
  1121. //
  1122. if(bMasked == true)
  1123. {
  1124. return(HWREG(ulGen + PWM_O_X_ISC));
  1125. }
  1126. else
  1127. {
  1128. return(HWREG(ulGen + PWM_O_X_RIS));
  1129. }
  1130. }
  1131. //*****************************************************************************
  1132. //
  1133. //! Clears the specified interrupt(s) for the specified PWM generator block.
  1134. //!
  1135. //! \param ulBase is the base address of the PWM module.
  1136. //! \param ulGen is the PWM generator to query. Must be one of \b PWM_GEN_0,
  1137. //! \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1138. //! \param ulInts specifies the interrupts to be cleared.
  1139. //!
  1140. //! Clears the specified interrupt(s) by writing a 1 to the specified bits
  1141. //! of the interrupt status register for the specified PWM generator. The
  1142. //! \e ulInts parameter is the logical OR of \b PWM_INT_CNT_ZERO,
  1143. //! \b PWM_INT_CNT_LOAD, \b PWM_INT_CNT_AU, \b PWM_INT_CNT_AD,
  1144. //! \b PWM_INT_CNT_BU, or \b PWM_INT_CNT_BD.
  1145. //!
  1146. //! \note Since there is a write buffer in the Cortex-M3 processor, it may take
  1147. //! several clock cycles before the interrupt source is actually cleared.
  1148. //! Therefore, it is recommended that the interrupt source be cleared early in
  1149. //! the interrupt handler (as opposed to the very last action) to avoid
  1150. //! returning from the interrupt handler before the interrupt source is
  1151. //! actually cleared. Failure to do so may result in the interrupt handler
  1152. //! being immediately reentered (since NVIC still sees the interrupt source
  1153. //! asserted).
  1154. //!
  1155. //! \return None.
  1156. //
  1157. //*****************************************************************************
  1158. void
  1159. PWMGenIntClear(unsigned long ulBase, unsigned long ulGen, unsigned long ulInts)
  1160. {
  1161. //
  1162. // Check the arguments.
  1163. //
  1164. ASSERT(ulBase == PWM_BASE);
  1165. ASSERT(PWMGenValid(ulGen));
  1166. ASSERT((ulInts & ~(PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD | PWM_INT_CNT_AU |
  1167. PWM_INT_CNT_AD | PWM_INT_CNT_BU | PWM_INT_CNT_BD)) ==
  1168. 0);
  1169. //
  1170. // Clear the requested interrupts by writing ones to the specified bit
  1171. // of the module's interrupt enable register.
  1172. //
  1173. HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_ISC) = ulInts;
  1174. }
  1175. //*****************************************************************************
  1176. //
  1177. //! Enables generator and fault interrupts for a PWM module.
  1178. //!
  1179. //! \param ulBase is the base address of the PWM module.
  1180. //! \param ulGenFault contains the interrupts to be enabled. Must be a logical
  1181. //! OR of any of \b PWM_INT_GEN_0, \b PWM_INT_GEN_1, \b PWM_INT_GEN_2,
  1182. //! \b PWM_INT_GEN_3, \b PWM_INT_FAULT0, \b PWM_INT_FAULT1, \b PWM_INT_FAULT2,
  1183. //! or \b PWM_INT_FAULT3.
  1184. //!
  1185. //! Unmasks the specified interrupt(s) by setting the specified bits of
  1186. //! the interrupt enable register for the selected PWM module.
  1187. //!
  1188. //! \return None.
  1189. //
  1190. //*****************************************************************************
  1191. void
  1192. PWMIntEnable(unsigned long ulBase, unsigned long ulGenFault)
  1193. {
  1194. //
  1195. // Check the arguments.
  1196. //
  1197. ASSERT(ulBase == PWM_BASE);
  1198. ASSERT((ulGenFault & ~(PWM_INT_GEN_0 | PWM_INT_GEN_1 | PWM_INT_GEN_2 |
  1199. PWM_INT_GEN_3 | PWM_INT_FAULT0 | PWM_INT_FAULT1 |
  1200. PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
  1201. //
  1202. // Read the module's interrupt enable register, and enable interrupts
  1203. // for the specified PWM generators.
  1204. //
  1205. HWREG(ulBase + PWM_O_INTEN) |= ulGenFault;
  1206. }
  1207. //*****************************************************************************
  1208. //
  1209. //! Disables generator and fault interrupts for a PWM module.
  1210. //!
  1211. //! \param ulBase is the base address of the PWM module.
  1212. //! \param ulGenFault contains the interrupts to be disabled. Must be a
  1213. //! logical OR of any of \b PWM_INT_GEN_0, \b PWM_INT_GEN_1, \b PWM_INT_GEN_2,
  1214. //! \b PWM_INT_GEN_3, \b PWM_INT_FAULT0, \b PWM_INT_FAULT1, \b PWM_INT_FAULT2,
  1215. //! or \b PWM_INT_FAULT3.
  1216. //!
  1217. //! Masks the specified interrupt(s) by clearing the specified bits of
  1218. //! the interrupt enable register for the selected PWM module.
  1219. //!
  1220. //! \return None.
  1221. //
  1222. //*****************************************************************************
  1223. void
  1224. PWMIntDisable(unsigned long ulBase, unsigned long ulGenFault)
  1225. {
  1226. //
  1227. // Check the arguments.
  1228. //
  1229. ASSERT(ulBase == PWM_BASE);
  1230. ASSERT((ulGenFault & ~(PWM_INT_GEN_0 | PWM_INT_GEN_1 | PWM_INT_GEN_2 |
  1231. PWM_INT_GEN_3 | PWM_INT_FAULT0 | PWM_INT_FAULT1 |
  1232. PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
  1233. //
  1234. // Read the module's interrupt enable register, and disable interrupts
  1235. // for the specified PWM generators.
  1236. //
  1237. HWREG(ulBase + PWM_O_INTEN) &= ~(ulGenFault);
  1238. }
  1239. //*****************************************************************************
  1240. //
  1241. //! Clears the fault interrupt for a PWM module.
  1242. //!
  1243. //! \param ulBase is the base address of the PWM module.
  1244. //!
  1245. //! Clears the fault interrupt by writing to the appropriate bit of the
  1246. //! interrupt status register for the selected PWM module.
  1247. //!
  1248. //! This function clears only the FAULT0 interrupt and is retained for
  1249. //! backwards compatibility. It is recommended that PWMFaultIntClearExt() be
  1250. //! used instead since it supports all fault interrupts supported on devices
  1251. //! with and without extended PWM fault handling support.
  1252. //!
  1253. //! \note Since there is a write buffer in the Cortex-M3 processor, it may take
  1254. //! several clock cycles before the interrupt source is actually cleared.
  1255. //! Therefore, it is recommended that the interrupt source be cleared early in
  1256. //! the interrupt handler (as opposed to the very last action) to avoid
  1257. //! returning from the interrupt handler before the interrupt source is
  1258. //! actually cleared. Failure to do so may result in the interrupt handler
  1259. //! being immediately reentered (since NVIC still sees the interrupt source
  1260. //! asserted).
  1261. //!
  1262. //! \return None.
  1263. //
  1264. //*****************************************************************************
  1265. void
  1266. PWMFaultIntClear(unsigned long ulBase)
  1267. {
  1268. //
  1269. // Check the arguments.
  1270. //
  1271. ASSERT(ulBase == PWM_BASE);
  1272. //
  1273. // Write the only writeable bit in the module's interrupt register.
  1274. //
  1275. HWREG(ulBase + PWM_O_ISC) = PWM_ISC_INTFAULT0;
  1276. }
  1277. //*****************************************************************************
  1278. //
  1279. //! Gets the interrupt status for a PWM module.
  1280. //!
  1281. //! \param ulBase is the base address of the PWM module.
  1282. //! \param bMasked specifies whether masked or raw interrupt status is
  1283. //! returned.
  1284. //!
  1285. //! If \e bMasked is set as \b true, then the masked interrupt status is
  1286. //! returned; otherwise, the raw interrupt status will be returned.
  1287. //!
  1288. //! \return The current interrupt status, enumerated as a bit field of
  1289. //! \b PWM_INT_GEN_0, \b PWM_INT_GEN_1, \b PWM_INT_GEN_2, \b PWM_INT_GEN_3,
  1290. //! \b PWM_INT_FAULT0, \b PWM_INT_FAULT1, \b PWM_INT_FAULT2, and
  1291. //! \b PWM_INT_FAULT3.
  1292. //!
  1293. //*****************************************************************************
  1294. unsigned long
  1295. PWMIntStatus(unsigned long ulBase, tBoolean bMasked)
  1296. {
  1297. //
  1298. // Check the arguments.
  1299. //
  1300. ASSERT(ulBase == PWM_BASE);
  1301. //
  1302. // Read and return either the module's raw or enabled interrupt status.
  1303. //
  1304. if(bMasked == true)
  1305. {
  1306. return(HWREG(ulBase + PWM_O_ISC));
  1307. }
  1308. else
  1309. {
  1310. return(HWREG(ulBase + PWM_O_RIS));
  1311. }
  1312. }
  1313. //*****************************************************************************
  1314. //
  1315. //! Clears the fault interrupt for a PWM module.
  1316. //!
  1317. //! \param ulBase is the base address of the PWM module.
  1318. //! \param ulFaultInts specifies the fault interrupts to clear.
  1319. //!
  1320. //! Clears one or more fault interrupts by writing to the appropriate bit of
  1321. //! the PWM interrupt status register. The parameter \e ulFaultInts must be
  1322. //! the logical OR of any of \b PWM_INT_FAULT0, \b PWM_INT_FAULT1,
  1323. //! \b PWM_INT_FAULT2, or \b PWM_INT_FAULT3.
  1324. //!
  1325. //! When running on a device supporting extended PWM fault handling, the fault
  1326. //! interrupts are derived by performing a logical OR of each of the configured
  1327. //! fault trigger signals for a given generator. Therefore, these interrupts
  1328. //! are not directly related to the four possible FAULTn inputs to the device
  1329. //! but indicate that a fault has been signaled to one of the four possible PWM
  1330. //! generators. On a device without extended PWM fault handling, the interrupt
  1331. //! is directly related to the state of the single FAULT pin.
  1332. //!
  1333. //! \note Since there is a write buffer in the Cortex-M3 processor, it may take
  1334. //! several cycles before the interrupt source is actually cleared. Therefore,
  1335. //! it is recommended that the interrupt source be cleared early in the
  1336. //! interrupt handler (as opposed to the very last action) to avoid returning
  1337. //! from the interrupt handler before the interrupt source is actually cleared.
  1338. //! Failure to do so may result in the interrupt handler being immediately
  1339. //! reentered (since NVIC still sees the interrupt source asserted).
  1340. //!
  1341. //! \return None.
  1342. //
  1343. //*****************************************************************************
  1344. void
  1345. PWMFaultIntClearExt(unsigned long ulBase, unsigned long ulFaultInts)
  1346. {
  1347. //
  1348. // Check the arguments.
  1349. //
  1350. ASSERT(ulBase == PWM_BASE);
  1351. ASSERT((ulFaultInts & ~(PWM_INT_FAULT0 | PWM_INT_FAULT1 |
  1352. PWM_INT_FAULT2 | PWM_INT_FAULT3)) == 0);
  1353. //
  1354. // Clear the supplied fault bits.
  1355. //
  1356. HWREG(ulBase + PWM_O_ISC) = ulFaultInts;
  1357. }
  1358. //*****************************************************************************
  1359. //
  1360. //! Configures the minimum fault period and fault pin senses for a given
  1361. //! PWM generator.
  1362. //!
  1363. //! \param ulBase is the base address of the PWM module.
  1364. //! \param ulGen is the PWM generator whose fault configuration is being set.
  1365. //! Must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1366. //! \param ulMinFaultPeriod is the minimum fault active period expressed in
  1367. //! PWM clock cycles.
  1368. //! \param ulFaultSenses indicates which sense of each FAULT input should be
  1369. //! considered the ``asserted'' state. Valid values are logical OR
  1370. //! combinations of \b PWM_FAULTn_SENSE_HIGH and \b PWM_FAULTn_SENSE_LOW.
  1371. //!
  1372. //! This function sets the minimum fault period for a given generator along
  1373. //! with the sense of each of the 4 possible fault inputs. The minimum fault
  1374. //! period is expressed in PWM clock cycles and takes effect only if
  1375. //! PWMGenConfigure() is called with flag \b PWM_GEN_MODE_FAULT_PER set in the
  1376. //! \e ulConfig parameter. When a fault input is asserted, the minimum fault
  1377. //! period timer ensures that it remains asserted for at least the number of
  1378. //! clock cycles specified.
  1379. //!
  1380. //! \note This function is only available on devices supporting extended PWM
  1381. //! fault handling.
  1382. //!
  1383. //! \return None.
  1384. //
  1385. //*****************************************************************************
  1386. void
  1387. PWMGenFaultConfigure(unsigned long ulBase, unsigned long ulGen,
  1388. unsigned long ulMinFaultPeriod,
  1389. unsigned long ulFaultSenses)
  1390. {
  1391. //
  1392. // Check the arguments.
  1393. //
  1394. ASSERT(HWREG(SYSCTL_DC5) & SYSCTL_DC5_PWMEFLT);
  1395. ASSERT(ulBase == PWM_BASE);
  1396. ASSERT(PWMGenValid(ulGen));
  1397. ASSERT(ulMinFaultPeriod < PWM_X_MINFLTPER_M);
  1398. ASSERT((ulFaultSenses & ~(PWM_FAULT0_SENSE_HIGH | PWM_FAULT0_SENSE_LOW |
  1399. PWM_FAULT1_SENSE_HIGH | PWM_FAULT1_SENSE_LOW |
  1400. PWM_FAULT2_SENSE_HIGH | PWM_FAULT2_SENSE_LOW |
  1401. PWM_FAULT3_SENSE_HIGH | PWM_FAULT3_SENSE_LOW)) ==
  1402. 0);
  1403. //
  1404. // Write the minimum fault period.
  1405. //
  1406. HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_MINFLTPER) = ulMinFaultPeriod;
  1407. //
  1408. // Write the fault senses.
  1409. //
  1410. HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSEN) = ulFaultSenses;
  1411. }
  1412. //*****************************************************************************
  1413. //
  1414. //! Configures the set of fault triggers for a given PWM generator.
  1415. //!
  1416. //! \param ulBase is the base address of the PWM module.
  1417. //! \param ulGen is the PWM generator whose fault triggers are being set. Must
  1418. //! be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1419. //! \param ulGroup indicates the subset of possible faults that are to be
  1420. //! configured. This must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
  1421. //! \param ulFaultTriggers defines the set of inputs that are to contribute
  1422. //! towards generation of the fault signal to the given PWM generator. For
  1423. //! \b PWM_FAULT_GROUP_0, this will be the logical OR of \b PWM_FAULT_FAULT0,
  1424. //! \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or \b PWM_FAULT_FAULT3. For
  1425. //! \b PWM_FAULT_GROUP_1, this will be the logical OR of \b PWM_FAULT_DCMP0,
  1426. //! \b PWM_FAULT_DCMP1, \b PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3, \b
  1427. //! PWM_FAULT_DCMP4, \b PWM_FAULT_DCMP5, \b PWM_FAULT_DCMP6, or \b
  1428. //! PWM_FAULT_DCMP7.
  1429. //!
  1430. //! This function allows selection of the set of fault inputs that will be
  1431. //! combined to generate a fault condition to a given PWM generator. By
  1432. //! default, all generators use only FAULT0 (for backwards compatibility) but
  1433. //! if PWMGenConfigure() is called with flag \b PWM_GEN_MODE_FAULT_SRC in the
  1434. //! \e ulConfig parameter, extended fault handling is enabled and this function
  1435. //! must be called to configure the fault triggers.
  1436. //!
  1437. //! The fault signal to the PWM generator is generated by ORing together each
  1438. //! of the signals whose inputs are specified in the \e ulFaultTriggers
  1439. //! parameter after having adjusted the sense of each FAULTn input based on the
  1440. //! configuration previously set using a call to PWMGenFaultConfigure().
  1441. //!
  1442. //! \note This function is only available on devices supporting extended PWM
  1443. //! fault handling.
  1444. //!
  1445. //! \return None.
  1446. //
  1447. //*****************************************************************************
  1448. void
  1449. PWMGenFaultTriggerSet(unsigned long ulBase, unsigned long ulGen,
  1450. unsigned long ulGroup, unsigned long ulFaultTriggers)
  1451. {
  1452. //
  1453. // Check for valid parameters.
  1454. //
  1455. ASSERT(HWREG(SYSCTL_DC5) & SYSCTL_DC5_PWMEFLT);
  1456. ASSERT(ulBase == PWM_BASE);
  1457. ASSERT(PWMGenValid(ulGen));
  1458. ASSERT((ulGroup == PWM_FAULT_GROUP_0) || (ulGroup == PWM_FAULT_GROUP_1));
  1459. ASSERT((ulGroup == PWM_FAULT_GROUP_0) &&
  1460. ((ulFaultTriggers & ~(PWM_FAULT_FAULT0 | PWM_FAULT_FAULT1 |
  1461. PWM_FAULT_FAULT2 | PWM_FAULT_FAULT3)) == 0));
  1462. ASSERT((ulGroup == PWM_FAULT_GROUP_1) &&
  1463. ((ulFaultTriggers & ~(PWM_FAULT_DCMP0 | PWM_FAULT_DCMP1 |
  1464. PWM_FAULT_DCMP2 | PWM_FAULT_DCMP3 |
  1465. PWM_FAULT_DCMP4 | PWM_FAULT_DCMP5 |
  1466. PWM_FAULT_DCMP6 | PWM_FAULT_DCMP7)) == 0));
  1467. //
  1468. // Write the fault triggers to the appropriate register.
  1469. //
  1470. if(ulGroup == PWM_FAULT_GROUP_0)
  1471. {
  1472. HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_FLTSRC0) =
  1473. ulFaultTriggers;
  1474. }
  1475. else
  1476. {
  1477. HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_FLTSRC1) =
  1478. ulFaultTriggers;
  1479. }
  1480. }
  1481. //*****************************************************************************
  1482. //
  1483. //! Returns the set of fault triggers currently configured for a given PWM
  1484. //! generator.
  1485. //!
  1486. //! \param ulBase is the base address of the PWM module.
  1487. //! \param ulGen is the PWM generator whose fault triggers are being queried.
  1488. //! Must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or \b PWM_GEN_3.
  1489. //! \param ulGroup indicates the subset of faults that are being queried. This
  1490. //! must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
  1491. //!
  1492. //! This function allows an application to query the current set of inputs that
  1493. //! contribute towards the generation of a fault condition to a given PWM
  1494. //! generator.
  1495. //!
  1496. //! \note This function is only available on devices supporting extended PWM
  1497. //! fault handling.
  1498. //!
  1499. //! \return Returns the current fault triggers configured for the fault group
  1500. //! provided. For \b PWM_FAULT_GROUP_0, the returned value will be a logical
  1501. //! OR of \b PWM_FAULT_FAULT0, \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or
  1502. //! \b PWM_FAULT_FAULT3. For \b PWM_FAULT_GROUP_1, the return value will be
  1503. //! the logical OR of \b PWM_FAULT_DCMP0, \b PWM_FAULT_DCMP1, \b
  1504. //! PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3, \b PWM_FAULT_DCMP4, \b PWM_FAULT_DCMP5,
  1505. //! \b PWM_FAULT_DCMP6, or \b PWM_FAULT_DCMP7.
  1506. //
  1507. //*****************************************************************************
  1508. unsigned long
  1509. PWMGenFaultTriggerGet(unsigned long ulBase, unsigned long ulGen,
  1510. unsigned long ulGroup)
  1511. {
  1512. //
  1513. // Check for valid parameters.
  1514. //
  1515. ASSERT(HWREG(SYSCTL_DC5) & SYSCTL_DC5_PWMEFLT);
  1516. ASSERT(ulBase == PWM_BASE);
  1517. ASSERT(PWMGenValid(ulGen));
  1518. ASSERT((ulGroup == PWM_FAULT_GROUP_0) || (ulGroup == PWM_FAULT_GROUP_1));
  1519. //
  1520. // Return the current fault triggers.
  1521. //
  1522. if(ulGroup == PWM_FAULT_GROUP_0)
  1523. {
  1524. return(HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_FLTSRC0));
  1525. }
  1526. else
  1527. {
  1528. return(HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_FLTSRC1));
  1529. }
  1530. }
  1531. //*****************************************************************************
  1532. //
  1533. //! Returns the current state of the fault triggers for a given PWM generator.
  1534. //!
  1535. //! \param ulBase is the base address of the PWM module.
  1536. //! \param ulGen is the PWM generator whose fault trigger states are being
  1537. //! queried. Must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or
  1538. //! \b PWM_GEN_3.
  1539. //! \param ulGroup indicates the subset of faults that are being queried. This
  1540. //! must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
  1541. //!
  1542. //! This function allows an application to query the current state of each of
  1543. //! the fault trigger inputs to a given PWM generator. The current state of
  1544. //! each fault trigger input is returned unless PWMGenConfigure() has
  1545. //! previously been called with flag \b PWM_GEN_MODE_LATCH_FAULT in the
  1546. //! \e ulConfig parameter in which case the returned status is the latched
  1547. //! fault trigger status.
  1548. //!
  1549. //! If latched faults are configured, the application must call
  1550. //! PWMGenFaultClear() to clear each trigger.
  1551. //!
  1552. //! \note This function is only available on devices supporting extended PWM
  1553. //! fault handling.
  1554. //!
  1555. //! \return Returns the current state of the fault triggers for the given PWM
  1556. //! generator. A set bit indicates that the associated trigger is active. For
  1557. //! \b PWM_FAULT_GROUP_0, the returned value will be a logical OR of
  1558. //! \b PWM_FAULT_FAULT0, \b PWM_FAULT_FAULT1, \b PWM_FAULT_FAULT2, or
  1559. //! \b PWM_FAULT_FAULT3. For \b PWM_FAULT_GROUP_1, the return value will be
  1560. //! the logical OR of \b PWM_FAULT_DCMP0, \b PWM_FAULT_DCMP1, \b
  1561. //! PWM_FAULT_DCMP2, \b PWM_FAULT_DCMP3, \b PWM_FAULT_DCMP4, \b PWM_FAULT_DCMP5,
  1562. //! \b PWM_FAULT_DCMP6, or \b PWM_FAULT_DCMP7.
  1563. //
  1564. //*****************************************************************************
  1565. unsigned long
  1566. PWMGenFaultStatus(unsigned long ulBase, unsigned long ulGen,
  1567. unsigned long ulGroup)
  1568. {
  1569. //
  1570. // Check for valid parameters.
  1571. //
  1572. ASSERT(HWREG(SYSCTL_DC5) & SYSCTL_DC5_PWMEFLT);
  1573. ASSERT(ulBase == PWM_BASE);
  1574. ASSERT(PWMGenValid(ulGen));
  1575. ASSERT((ulGroup == PWM_FAULT_GROUP_0) || (ulGroup == PWM_FAULT_GROUP_1));
  1576. //
  1577. // Return the current fault status.
  1578. //
  1579. if(ulGroup == PWM_FAULT_GROUP_0)
  1580. {
  1581. return(HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSTAT0));
  1582. }
  1583. else
  1584. {
  1585. return(HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSTAT1));
  1586. }
  1587. }
  1588. //*****************************************************************************
  1589. //
  1590. //! Clears one or more latched fault triggers for a given PWM generator.
  1591. //!
  1592. //! \param ulBase is the base address of the PWM module.
  1593. //! \param ulGen is the PWM generator whose fault trigger states are being
  1594. //! queried. Must be one of \b PWM_GEN_0, \b PWM_GEN_1, \b PWM_GEN_2, or
  1595. //! \b PWM_GEN_3.
  1596. //! \param ulGroup indicates the subset of faults that are being queried. This
  1597. //! must be \b PWM_FAULT_GROUP_0 or \b PWM_FAULT_GROUP_1.
  1598. //! \param ulFaultTriggers is the set of fault triggers which are to be
  1599. //! cleared.
  1600. //!
  1601. //! This function allows an application to clear the fault triggers for a given
  1602. //! PWM generator. This is only required if PWMGenConfigure() has previously
  1603. //! been called with flag \b PWM_GEN_MODE_LATCH_FAULT in parameter \e ulConfig.
  1604. //!
  1605. //! \note This function is only available on devices supporting extended PWM
  1606. //! fault handling.
  1607. //!
  1608. //! \return None.
  1609. //
  1610. //*****************************************************************************
  1611. void
  1612. PWMGenFaultClear(unsigned long ulBase, unsigned long ulGen,
  1613. unsigned long ulGroup, unsigned long ulFaultTriggers)
  1614. {
  1615. //
  1616. // Check for valid parameters.
  1617. //
  1618. ASSERT(HWREG(SYSCTL_DC5) & SYSCTL_DC5_PWMEFLT);
  1619. ASSERT(ulBase == PWM_BASE);
  1620. ASSERT(PWMGenValid(ulGen));
  1621. ASSERT((ulGroup == PWM_FAULT_GROUP_0) || (ulGroup == PWM_FAULT_GROUP_1));
  1622. ASSERT((ulGroup == PWM_FAULT_GROUP_0) &&
  1623. ((ulFaultTriggers & ~(PWM_FAULT_FAULT0 | PWM_FAULT_FAULT1 |
  1624. PWM_FAULT_FAULT2 | PWM_FAULT_FAULT3)) == 0));
  1625. ASSERT((ulGroup == PWM_FAULT_GROUP_1) &&
  1626. ((ulFaultTriggers & ~(PWM_FAULT_DCMP0 | PWM_FAULT_DCMP1 |
  1627. PWM_FAULT_DCMP2 | PWM_FAULT_DCMP3 |
  1628. PWM_FAULT_DCMP4 | PWM_FAULT_DCMP5 |
  1629. PWM_FAULT_DCMP6 | PWM_FAULT_DCMP7)) == 0));
  1630. //
  1631. // Clear the given faults.
  1632. //
  1633. if(ulGroup == PWM_FAULT_GROUP_0)
  1634. {
  1635. HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSTAT0) =
  1636. ulFaultTriggers;
  1637. }
  1638. else
  1639. {
  1640. HWREG(PWM_GEN_EXT_BADDR(ulBase, ulGen) + PWM_O_X_FLTSTAT1) =
  1641. ulFaultTriggers;
  1642. }
  1643. }
  1644. //*****************************************************************************
  1645. //
  1646. // Close the Doxygen group.
  1647. //! @}
  1648. //
  1649. //*****************************************************************************