qei.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. //*****************************************************************************
  2. //
  3. // qei.c - Driver for the Quadrature Encoder with Index.
  4. //
  5. // Copyright (c) 2005-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. //*****************************************************************************
  40. //
  41. //! \addtogroup qei_api
  42. //! @{
  43. //
  44. //*****************************************************************************
  45. #include <stdbool.h>
  46. #include <stdint.h>
  47. #include "inc/hw_ints.h"
  48. #include "inc/hw_memmap.h"
  49. #include "inc/hw_qei.h"
  50. #include "inc/hw_types.h"
  51. #include "inc/hw_sysctl.h"
  52. #include "driverlib/debug.h"
  53. #include "driverlib/interrupt.h"
  54. #include "driverlib/qei.h"
  55. //*****************************************************************************
  56. //
  57. //! Enables the quadrature encoder.
  58. //!
  59. //! \param ui32Base is the base address of the quadrature encoder module.
  60. //!
  61. //! This function enables operation of the quadrature encoder module. The
  62. //! module must be configured before it is enabled.
  63. //!
  64. //! \sa QEIConfigure()
  65. //!
  66. //! \return None.
  67. //
  68. //*****************************************************************************
  69. void
  70. QEIEnable(uint32_t ui32Base)
  71. {
  72. //
  73. // Check the arguments.
  74. //
  75. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  76. //
  77. // Enable the QEI module.
  78. //
  79. HWREG(ui32Base + QEI_O_CTL) |= QEI_CTL_ENABLE;
  80. }
  81. //*****************************************************************************
  82. //
  83. //! Disables the quadrature encoder.
  84. //!
  85. //! \param ui32Base is the base address of the quadrature encoder module.
  86. //!
  87. //! This function disables operation of the quadrature encoder module.
  88. //!
  89. //! \return None.
  90. //
  91. //*****************************************************************************
  92. void
  93. QEIDisable(uint32_t ui32Base)
  94. {
  95. //
  96. // Check the arguments.
  97. //
  98. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  99. //
  100. // Disable the QEI module.
  101. //
  102. HWREG(ui32Base + QEI_O_CTL) &= ~(QEI_CTL_ENABLE);
  103. }
  104. //*****************************************************************************
  105. //
  106. //! Configures the quadrature encoder.
  107. //!
  108. //! \param ui32Base is the base address of the quadrature encoder module.
  109. //! \param ui32Config is the configuration for the quadrature encoder. See
  110. //! below for a description of this parameter.
  111. //! \param ui32MaxPosition specifies the maximum position value.
  112. //!
  113. //! This function configures the operation of the quadrature encoder. The
  114. //! \e ui32Config parameter provides the configuration of the encoder and is
  115. //! the logical OR of several values:
  116. //!
  117. //! - \b QEI_CONFIG_CAPTURE_A or \b QEI_CONFIG_CAPTURE_A_B specify if edges
  118. //! on channel A or on both channels A and B should be counted by the
  119. //! position integrator and velocity accumulator.
  120. //! - \b QEI_CONFIG_NO_RESET or \b QEI_CONFIG_RESET_IDX specify if the
  121. //! position integrator should be reset when the index pulse is detected.
  122. //! - \b QEI_CONFIG_QUADRATURE or \b QEI_CONFIG_CLOCK_DIR specify if
  123. //! quadrature signals are being provided on ChA and ChB, or if a direction
  124. //! signal and a clock are being provided instead.
  125. //! - \b QEI_CONFIG_NO_SWAP or \b QEI_CONFIG_SWAP to specify if the signals
  126. //! provided on ChA and ChB should be swapped before being processed.
  127. //!
  128. //! \e ui32MaxPosition is the maximum value of the position integrator and is
  129. //! the value used to reset the position capture when in index reset mode and
  130. //! moving in the reverse (negative) direction.
  131. //!
  132. //! \return None.
  133. //
  134. //*****************************************************************************
  135. void
  136. QEIConfigure(uint32_t ui32Base, uint32_t ui32Config,
  137. uint32_t ui32MaxPosition)
  138. {
  139. //
  140. // Check the arguments.
  141. //
  142. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  143. //
  144. // Write the new configuration to the hardware.
  145. //
  146. HWREG(ui32Base + QEI_O_CTL) = ((HWREG(ui32Base + QEI_O_CTL) &
  147. ~(QEI_CTL_CAPMODE | QEI_CTL_RESMODE |
  148. QEI_CTL_SIGMODE | QEI_CTL_SWAP)) |
  149. ui32Config);
  150. //
  151. // Set the maximum position.
  152. //
  153. HWREG(ui32Base + QEI_O_MAXPOS) = ui32MaxPosition;
  154. }
  155. //*****************************************************************************
  156. //
  157. //! Gets the current encoder position.
  158. //!
  159. //! \param ui32Base is the base address of the quadrature encoder module.
  160. //!
  161. //! This function returns the current position of the encoder. Depending upon
  162. //! the configuration of the encoder, and the incident of an index pulse, this
  163. //! value may or may not contain the expected data (that is, if in reset on
  164. //! index mode, if an index pulse has not been encountered, the position
  165. //! counter is not yet aligned with the index pulse).
  166. //!
  167. //! \return The current position of the encoder.
  168. //
  169. //*****************************************************************************
  170. uint32_t
  171. QEIPositionGet(uint32_t ui32Base)
  172. {
  173. //
  174. // Check the arguments.
  175. //
  176. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  177. //
  178. // Return the current position counter.
  179. //
  180. return(HWREG(ui32Base + QEI_O_POS));
  181. }
  182. //*****************************************************************************
  183. //
  184. //! Sets the current encoder position.
  185. //!
  186. //! \param ui32Base is the base address of the quadrature encoder module.
  187. //! \param ui32Position is the new position for the encoder.
  188. //!
  189. //! This function sets the current position of the encoder; the encoder
  190. //! position is then measured relative to this value.
  191. //!
  192. //! \return None.
  193. //
  194. //*****************************************************************************
  195. void
  196. QEIPositionSet(uint32_t ui32Base, uint32_t ui32Position)
  197. {
  198. //
  199. // Check the arguments.
  200. //
  201. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  202. //
  203. // Set the position counter.
  204. //
  205. HWREG(ui32Base + QEI_O_POS) = ui32Position;
  206. }
  207. //*****************************************************************************
  208. //
  209. //! Gets the current direction of rotation.
  210. //!
  211. //! \param ui32Base is the base address of the quadrature encoder module.
  212. //!
  213. //! This function returns the current direction of rotation. In this case,
  214. //! current means the most recently detected direction of the encoder; it may
  215. //! not be presently moving but this is the direction it last moved before it
  216. //! stopped.
  217. //!
  218. //! \return Returns 1 if moving in the forward direction or -1 if moving in the
  219. //! reverse direction.
  220. //
  221. //*****************************************************************************
  222. int32_t
  223. QEIDirectionGet(uint32_t ui32Base)
  224. {
  225. //
  226. // Check the arguments.
  227. //
  228. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  229. //
  230. // Return the direction of rotation.
  231. //
  232. return((HWREG(ui32Base + QEI_O_STAT) & QEI_STAT_DIRECTION) ? -1 : 1);
  233. }
  234. //*****************************************************************************
  235. //
  236. //! Gets the encoder error indicator.
  237. //!
  238. //! \param ui32Base is the base address of the quadrature encoder module.
  239. //!
  240. //! This function returns the error indicator for the quadrature encoder. It
  241. //! is an error for both of the signals of the quadrature input to change at
  242. //! the same time.
  243. //!
  244. //! \return Returns \b true if an error has occurred and \b false otherwise.
  245. //
  246. //*****************************************************************************
  247. bool
  248. QEIErrorGet(uint32_t ui32Base)
  249. {
  250. //
  251. // Check the arguments.
  252. //
  253. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  254. //
  255. // Return the error indicator.
  256. //
  257. return((HWREG(ui32Base + QEI_O_STAT) & QEI_STAT_ERROR) ? true : false);
  258. }
  259. //*****************************************************************************
  260. //
  261. //! Enables the velocity capture.
  262. //!
  263. //! \param ui32Base is the base address of the quadrature encoder module.
  264. //!
  265. //! This function enables operation of the velocity capture in the quadrature
  266. //! encoder module. The module must be configured before velocity capture is
  267. //! enabled.
  268. //!
  269. //! \sa QEIVelocityConfigure() and QEIEnable()
  270. //!
  271. //! \return None.
  272. //
  273. //*****************************************************************************
  274. void
  275. QEIVelocityEnable(uint32_t ui32Base)
  276. {
  277. //
  278. // Check the arguments.
  279. //
  280. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  281. //
  282. // Enable the velocity capture.
  283. //
  284. HWREG(ui32Base + QEI_O_CTL) |= QEI_CTL_VELEN;
  285. }
  286. //*****************************************************************************
  287. //
  288. //! Disables the velocity capture.
  289. //!
  290. //! \param ui32Base is the base address of the quadrature encoder module.
  291. //!
  292. //! This function disables operation of the velocity capture in the quadrature
  293. //! encoder module.
  294. //!
  295. //! \return None.
  296. //
  297. //*****************************************************************************
  298. void
  299. QEIVelocityDisable(uint32_t ui32Base)
  300. {
  301. //
  302. // Check the arguments.
  303. //
  304. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  305. //
  306. // Disable the velocity capture.
  307. //
  308. HWREG(ui32Base + QEI_O_CTL) &= ~(QEI_CTL_VELEN);
  309. }
  310. //*****************************************************************************
  311. //
  312. //! Configures the velocity capture.
  313. //!
  314. //! \param ui32Base is the base address of the quadrature encoder module.
  315. //! \param ui32PreDiv specifies the predivider applied to the input quadrature
  316. //! signal before it is counted; can be one of \b QEI_VELDIV_1,
  317. //! \b QEI_VELDIV_2, \b QEI_VELDIV_4, \b QEI_VELDIV_8, \b QEI_VELDIV_16,
  318. //! \b QEI_VELDIV_32, \b QEI_VELDIV_64, or \b QEI_VELDIV_128.
  319. //! \param ui32Period specifies the number of clock ticks over which to measure
  320. //! the velocity; must be non-zero.
  321. //!
  322. //! This function configures the operation of the velocity capture portion of
  323. //! the quadrature encoder. The position increment signal is predivided as
  324. //! specified by \e ui32PreDiv before being accumulated by the velocity
  325. //! capture. The divided signal is accumulated over \e ui32Period system clock
  326. //! before being saved and resetting the accumulator.
  327. //!
  328. //! \return None.
  329. //
  330. //*****************************************************************************
  331. void
  332. QEIVelocityConfigure(uint32_t ui32Base, uint32_t ui32PreDiv,
  333. uint32_t ui32Period)
  334. {
  335. //
  336. // Check the arguments.
  337. //
  338. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  339. ASSERT(!(ui32PreDiv & ~(QEI_CTL_VELDIV_M)));
  340. ASSERT(ui32Period != 0);
  341. //
  342. // Set the velocity predivider.
  343. //
  344. HWREG(ui32Base + QEI_O_CTL) = ((HWREG(ui32Base + QEI_O_CTL) &
  345. ~(QEI_CTL_VELDIV_M)) | ui32PreDiv);
  346. //
  347. // Set the timer period.
  348. //
  349. HWREG(ui32Base + QEI_O_LOAD) = ui32Period - 1;
  350. }
  351. //*****************************************************************************
  352. //
  353. //! Gets the current encoder speed.
  354. //!
  355. //! \param ui32Base is the base address of the quadrature encoder module.
  356. //!
  357. //! This function returns the current speed of the encoder. The value returned
  358. //! is the number of pulses detected in the specified time period; this number
  359. //! can be multiplied by the number of time periods per second and divided by
  360. //! the number of pulses per revolution to obtain the number of revolutions per
  361. //! second.
  362. //!
  363. //! \return Returns the number of pulses captured in the given time period.
  364. //
  365. //*****************************************************************************
  366. uint32_t
  367. QEIVelocityGet(uint32_t ui32Base)
  368. {
  369. //
  370. // Check the arguments.
  371. //
  372. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  373. //
  374. // Return the speed capture value.
  375. //
  376. return(HWREG(ui32Base + QEI_O_SPEED));
  377. }
  378. //*****************************************************************************
  379. //
  380. //! Returns the quadrature encoder interrupt number.
  381. //!
  382. //! \param ui32Base is the base address of the selected quadrature encoder
  383. //!
  384. //! This function returns the interrupt number for the quadrature encoder with
  385. //! the base address passed in the \e ui32Base parameter.
  386. //!
  387. //! \return Returns a quadrature encoder interrupt number or 0 if the interrupt
  388. //! does not exist.
  389. //
  390. //*****************************************************************************
  391. static uint32_t
  392. _QEIIntNumberGet(uint32_t ui32Base)
  393. {
  394. uint32_t ui32Int;
  395. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  396. //
  397. // Find the valid interrupt number for this quadrature encoder.
  398. //
  399. if(CLASS_IS_TM4C123)
  400. {
  401. if(ui32Base == QEI0_BASE)
  402. {
  403. ui32Int = INT_QEI0_TM4C123;
  404. }
  405. else
  406. {
  407. ui32Int = INT_QEI1_TM4C123;
  408. }
  409. }
  410. else if(CLASS_IS_TM4C129)
  411. {
  412. if(ui32Base == QEI0_BASE)
  413. {
  414. ui32Int = INT_QEI0_TM4C129;
  415. }
  416. else
  417. {
  418. ui32Int = 0;
  419. }
  420. }
  421. else
  422. {
  423. ui32Int = 0;
  424. }
  425. return(ui32Int);
  426. }
  427. //*****************************************************************************
  428. //
  429. //! Registers an interrupt handler for the quadrature encoder interrupt.
  430. //!
  431. //! \param ui32Base is the base address of the quadrature encoder module.
  432. //! \param pfnHandler is a pointer to the function to be called when the
  433. //! quadrature encoder interrupt occurs.
  434. //!
  435. //! This function registers the handler to be called when a quadrature encoder
  436. //! interrupt occurs. This function enables the global interrupt in the
  437. //! interrupt controller; specific quadrature encoder interrupts must be
  438. //! enabled via QEIIntEnable(). It is the interrupt handler's responsibility
  439. //! to clear the interrupt source via QEIIntClear().
  440. //!
  441. //! \sa IntRegister() for important information about registering interrupt
  442. //! handlers.
  443. //!
  444. //! \return None.
  445. //
  446. //*****************************************************************************
  447. void
  448. QEIIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
  449. {
  450. uint32_t ui32Int;
  451. //
  452. // Check the arguments.
  453. //
  454. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  455. //
  456. // Determine the interrupt number based on the QEI module.
  457. //
  458. ui32Int = _QEIIntNumberGet(ui32Base);
  459. ASSERT(ui32Int != 0);
  460. //
  461. // Register the interrupt handler, returning an error if an error occurs.
  462. //
  463. IntRegister(ui32Int, pfnHandler);
  464. //
  465. // Enable the quadrature encoder interrupt.
  466. //
  467. IntEnable(ui32Int);
  468. }
  469. //*****************************************************************************
  470. //
  471. //! Unregisters an interrupt handler for the quadrature encoder interrupt.
  472. //!
  473. //! \param ui32Base is the base address of the quadrature encoder module.
  474. //!
  475. //! This function unregisters the handler to be called when a quadrature
  476. //! encoder interrupt occurs. This function also masks off the interrupt in
  477. //! the interrupt controller so that the interrupt handler no longer is called.
  478. //!
  479. //! \sa IntRegister() for important information about registering interrupt
  480. //! handlers.
  481. //!
  482. //! \return None.
  483. //
  484. //*****************************************************************************
  485. void
  486. QEIIntUnregister(uint32_t ui32Base)
  487. {
  488. uint32_t ui32Int;
  489. //
  490. // Check the arguments.
  491. //
  492. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  493. //
  494. // Determine the interrupt number based on the QEI module.
  495. //
  496. ui32Int = _QEIIntNumberGet(ui32Base);
  497. ASSERT(ui32Int != 0);
  498. //
  499. // Disable the interrupt.
  500. //
  501. IntDisable(ui32Int);
  502. //
  503. // Unregister the interrupt handler.
  504. //
  505. IntUnregister(ui32Int);
  506. }
  507. //*****************************************************************************
  508. //
  509. //! Enables individual quadrature encoder interrupt sources.
  510. //!
  511. //! \param ui32Base is the base address of the quadrature encoder module.
  512. //! \param ui32IntFlags is a bit mask of the interrupt sources to be enabled.
  513. //! Can be any of the \b QEI_INTERROR, \b QEI_INTDIR, \b QEI_INTTIMER, or
  514. //! \b QEI_INTINDEX values.
  515. //!
  516. //! This function enables the indicated quadrature encoder interrupt sources.
  517. //! Only the sources that are enabled can be reflected to the processor
  518. //! interrupt; disabled sources have no effect on the processor.
  519. //!
  520. //! \return None.
  521. //
  522. //*****************************************************************************
  523. void
  524. QEIIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
  525. {
  526. //
  527. // Check the arguments.
  528. //
  529. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  530. //
  531. // Enable the specified interrupts.
  532. //
  533. HWREG(ui32Base + QEI_O_INTEN) |= ui32IntFlags;
  534. }
  535. //*****************************************************************************
  536. //
  537. //! Disables individual quadrature encoder interrupt sources.
  538. //!
  539. //! \param ui32Base is the base address of the quadrature encoder module.
  540. //! \param ui32IntFlags is a bit mask of the interrupt sources to be disabled.
  541. //! This parameter can be any of the \b QEI_INTERROR, \b QEI_INTDIR,
  542. //! \b QEI_INTTIMER, or \b QEI_INTINDEX values.
  543. //!
  544. //! This function disables the indicated quadrature encoder interrupt sources.
  545. //! Only the sources that are enabled can be reflected to the processor
  546. //! interrupt; disabled sources have no effect on the processor.
  547. //!
  548. //! \return None.
  549. //
  550. //*****************************************************************************
  551. void
  552. QEIIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
  553. {
  554. //
  555. // Check the arguments.
  556. //
  557. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  558. //
  559. // Disable the specified interrupts.
  560. //
  561. HWREG(ui32Base + QEI_O_INTEN) &= ~(ui32IntFlags);
  562. }
  563. //*****************************************************************************
  564. //
  565. //! Gets the current interrupt status.
  566. //!
  567. //! \param ui32Base is the base address of the quadrature encoder module.
  568. //! \param bMasked is false if the raw interrupt status is required and true if
  569. //! the masked interrupt status is required.
  570. //!
  571. //! This function returns the interrupt status for the quadrature encoder
  572. //! module. Either the raw interrupt status or the status of interrupts that
  573. //! are allowed to reflect to the processor can be returned.
  574. //!
  575. //! \return Returns the current interrupt status, enumerated as a bit field of
  576. //! \b QEI_INTERROR, \b QEI_INTDIR, \b QEI_INTTIMER, and \b QEI_INTINDEX.
  577. //
  578. //*****************************************************************************
  579. uint32_t
  580. QEIIntStatus(uint32_t ui32Base, bool bMasked)
  581. {
  582. //
  583. // Check the arguments.
  584. //
  585. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  586. //
  587. // Return either the interrupt status or the raw interrupt status as
  588. // requested.
  589. //
  590. if(bMasked)
  591. {
  592. return(HWREG(ui32Base + QEI_O_ISC));
  593. }
  594. else
  595. {
  596. return(HWREG(ui32Base + QEI_O_RIS));
  597. }
  598. }
  599. //*****************************************************************************
  600. //
  601. //! Clears quadrature encoder interrupt sources.
  602. //!
  603. //! \param ui32Base is the base address of the quadrature encoder module.
  604. //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
  605. //! This parameter can be any of the \b QEI_INTERROR, \b QEI_INTDIR,
  606. //! \b QEI_INTTIMER, or \b QEI_INTINDEX values.
  607. //!
  608. //! The specified quadrature encoder interrupt sources are cleared, so that
  609. //! they no longer assert. This function must be called in the interrupt
  610. //! handler to keep the interrupt from being triggered again immediately upon
  611. //! exit.
  612. //!
  613. //! \note Because there is a write buffer in the Cortex-M processor, it may
  614. //! take several clock cycles before the interrupt source is actually cleared.
  615. //! Therefore, it is recommended that the interrupt source be cleared early in
  616. //! the interrupt handler (as opposed to the very last action) to avoid
  617. //! returning from the interrupt handler before the interrupt source is
  618. //! actually cleared. Failure to do so may result in the interrupt handler
  619. //! being immediately reentered (because the interrupt controller still sees
  620. //! the interrupt source asserted).
  621. //!
  622. //! \return None.
  623. //
  624. //*****************************************************************************
  625. void
  626. QEIIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
  627. {
  628. //
  629. // Check the arguments.
  630. //
  631. ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));
  632. //
  633. // Clear the requested interrupt sources.
  634. //
  635. HWREG(ui32Base + QEI_O_ISC) = ui32IntFlags;
  636. }
  637. //*****************************************************************************
  638. //
  639. // Close the Doxygen group.
  640. //! @}
  641. //
  642. //*****************************************************************************