pwm.c 62 KB

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