ecap.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**
  2. * \file ecap.h
  3. *
  4. * \brief This file contains the function prototypes for the device
  5. * abstraction layer for ECAP. It also contains some
  6. * related macro definitions and some files to be included.
  7. */
  8. /*
  9. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  10. */
  11. /*
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * Neither the name of Texas Instruments Incorporated nor the names of
  25. * its contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. */
  41. #ifndef _ECAP_H_
  42. #define _ECAP_H_
  43. #include "hw_ecap.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /****************************************************************************/
  48. /*
  49. ** Values that can be passed to ECAPOperatingModeSelect API as modeSelect
  50. ** to select type operating mode.
  51. */
  52. #define ECAP_CAPTURE_MODE 1
  53. #define ECAP_APWM_MODE 0
  54. /****************************************************************************/
  55. /*
  56. ** Values that can be passed to ECAPTimeStampRead API as capEvtFlag
  57. ** to determine for which capture event time-stamp has to be returned
  58. */
  59. #define ECAP_CAPTURE_EVENT_1 0x08
  60. #define ECAP_CAPTURE_EVENT_2 0x0c
  61. #define ECAP_CAPTURE_EVENT_3 0x10
  62. #define ECAP_CAPTURE_EVENT_4 0x14
  63. /****************************************************************************/
  64. /*
  65. ** Values that can be passed to ECAPOneShotModeConfig API as stopVal
  66. ** which determines number of captures allowed to occur before
  67. ** Capture register(1-4) frozen.\n
  68. */
  69. #define ECAP_CAPTURE_EVENT1_STOP (0x00 << ECAP_ECCTL2_STOP_WRAP_SHIFT)
  70. #define ECAP_CAPTURE_EVENT2_STOP (0x01 << ECAP_ECCTL2_STOP_WRAP_SHIFT)
  71. #define ECAP_CAPTURE_EVENT3_STOP (0x02 << ECAP_ECCTL2_STOP_WRAP_SHIFT)
  72. #define ECAP_CAPTURE_EVENT4_STOP (0x03 << ECAP_ECCTL2_STOP_WRAP_SHIFT)
  73. /****************************************************************************/
  74. /*
  75. ** Values that can be passed to ECAPAPWMPolarityConfig API as flag
  76. ** which determines the output polarity for APWM output
  77. */
  78. #define ECAP_APWM_ACTIVE_HIGH 0
  79. #define ECAP_APWM_ACTIVE_LOW 1
  80. /****************************************************************************/
  81. /*
  82. ** Values that can be passed to ECAPCounterControl API as flag
  83. ** which determines whether counter to be configured to stop
  84. ** or free running
  85. */
  86. #define ECAP_COUNTER_STOP 0
  87. #define ECAP_COUNTER_FREE_RUNNING 1
  88. /****************************************************************************/
  89. /*
  90. ** Values that can be passed to ECAPSyncInOutSelect API as syncIn
  91. ** to disable syncIn or to enable counter to be loaded from
  92. ** CNTPHS register upon a SYNCI signal
  93. */
  94. #define ECAP_SYNC_IN_DISABLE (0 << ECAP_ECCTL2_SYNCI_EN_SHIFT)
  95. #define ECAP_ENABLE_Counter (1 << ECAP_ECCTL2_SYNCI_EN_SHIFT)
  96. /****************************************************************************/
  97. /*
  98. ** Values that can be passed to ECAPSyncInOutSelect API as syncOut
  99. ** to select syncIn event to be the Sync-Out signal or select
  100. ** PRD_eq event to be Sync-Out signal or to disaqble syncOut
  101. ** signal
  102. */
  103. #define ECAP_SYNC_IN (00 << ECAP_ECCTL2_SYNCO_SEL_SHIFT)
  104. #define ECAP_PRD_EQ (01 << ECAP_ECCTL2_SYNCO_SEL_SHIFT)
  105. #define ECAP_SYNC_OUT_DISABLE (10 << ECAP_ECCTL2_SYNCO_SEL_SHIFT)
  106. /****************************************************************************/
  107. /*
  108. ** Values that can be passed to ECAPIntEnable/Disable API
  109. ** to enable or disable interrupt or it can be passed
  110. ** ECAPIntStatus to get the interrupt or it can be passed
  111. ** to ECAPIntStatusClear to clear the interrupt status
  112. */
  113. #define ECAP_CEVT1_INT ECAP_ECEINT_CEVT1
  114. #define ECAP_CEVT2_INT ECAP_ECEINT_CEVT2
  115. #define ECAP_CEVT3_INT ECAP_ECEINT_CEVT3
  116. #define ECAP_CEVT4_INT ECAP_ECEINT_CEVT4
  117. #define ECAP_CNTOVF_INT ECAP_ECEINT_CTROVF
  118. #define ECAP_PRDEQ_INT ECAP_ECEINT_CTR_PRD
  119. #define ECAP_CMPEQ_INT ECAP_ECEINT_CTR_CMP
  120. /* It can be passed to ECAPIntStatusClear to clear global interrupt flag */
  121. #define ECAP_GLOBAL_INT ECAP_ECFLG_INT
  122. /****************************************************************************/
  123. /*
  124. ** Values that can be passed to ECAPStandByModeConfig API
  125. ** to configure ECAP module in different stand by mode.
  126. **
  127. */
  128. #define ECAP_SMART_STAND_BY_WAKE_UP 3
  129. #define ECAP_FORCE_STAND_BY 0
  130. #define ECAP_SMART_STAND_BY 2
  131. #define ECAP_NO_STAND_BY 1
  132. /****************************************************************************/
  133. /*
  134. ** Values that can be passed to ECAPIdleModeConfig API
  135. ** to configure ECAP module in different Idle mode.
  136. **
  137. */
  138. #define ECAP_SMART_IDLE_WAKE_UP 3
  139. #define ECAP_SMART_IDLE_MODE 2
  140. #define ECAP_FORCE_IDLE_MODE 0
  141. #define ECAP_NO_IDLE_MODE 1
  142. /*
  143. ** Structure to save the ECAP context
  144. */
  145. typedef struct ecapContext {
  146. unsigned short ecctl2;
  147. unsigned short ecclr;
  148. unsigned short eceint;
  149. unsigned int pwm0ssclkconfig;
  150. unsigned int tsctr;
  151. unsigned int cap1;
  152. unsigned int cap2;
  153. }ECAPCONTEXT;
  154. void ECAPClockStop(unsigned int baseAdd);
  155. void ECAPClockEnable(unsigned int baseAdd);
  156. void ECAPOneShotREARM(unsigned int baseAdd);
  157. void ECAPGlobalIntEnable(unsigned int baseAdd);
  158. void ECAPContinousModeConfig(unsigned int baseAdd);
  159. void ECAPCaptureLoadingEnable(unsigned int baseAdd);
  160. void ECAPCaptureLoadingDisable(unsigned int baseAdd);
  161. unsigned int ECAPPeripheralIdGet(unsigned int baseAdd);
  162. unsigned int ECAPClockStopStatusGet(unsigned int baseAdd);
  163. unsigned int ECAPClockEnableStatusGet(unsigned int baseAdd);
  164. void ECAPIntEnable(unsigned int baseAdd, unsigned int flag);
  165. void ECAPIntDisable(unsigned int baseAdd, unsigned int flag);
  166. void ECAPIntStatusClear(unsigned int baseAdd, unsigned int flag);
  167. void ECAPCounterControl(unsigned int baseAdd, unsigned int flag);
  168. void ECAPCounterConfig(unsigned int baseAdd, unsigned int countVal);
  169. unsigned int ECAPIntStatus(unsigned int baseAdd, unsigned int flag);
  170. void ECAPAPWMPolarityConfig(unsigned int baseAdd, unsigned int flag);
  171. void ECAPSyncInOutSelect(unsigned int baseAdd, unsigned int syncIn,
  172. unsigned int syncOut);
  173. void ECAPPrescaleConfig(unsigned int baseAdd, unsigned int prescale);
  174. void ECAPOneShotModeConfig(unsigned int baseAdd, unsigned int stopVal);
  175. void ECAPAPWMCaptureConfig(unsigned int baseAdd, unsigned int compareVal,
  176. unsigned int periodVal);
  177. void ECAPAPWMShadowCaptureConfig(unsigned int baseAdd, unsigned int compareVal,
  178. unsigned int periodVal);
  179. void ECAPOperatingModeSelect(unsigned int baseAdd, unsigned int modeSelect);
  180. unsigned int ECAPTimeStampRead(unsigned int baseAdd, unsigned int capEvtFlag);
  181. void ECAPCounterPhaseValConfig(unsigned int baseAdd, unsigned int cntPhaseVal);
  182. void ECAPCapeEvtPolarityConfig(unsigned int baseAdd, unsigned int capEvt1pol,
  183. unsigned int capEvt2pol, unsigned int capEvt3pol,
  184. unsigned int capEvt4pol);
  185. void ECAPCaptureEvtCntrRstConfig(unsigned int baseAdd, unsigned int CounterRst1,
  186. unsigned int CounterRst2,unsigned int CounterRst3,
  187. unsigned int CounterRst4);
  188. void ECAPClockEnable(unsigned int baseAdd);
  189. void ECAPClockDisable(unsigned int baseAdd);
  190. unsigned int ECAPClockEnableStatusGet(unsigned int baseAdd);
  191. unsigned int ECAPClockDisableStatusGet(unsigned int baseAdd);
  192. extern void EcapContextSave(unsigned int ecapBase, unsigned int pwmssBase,
  193. ECAPCONTEXT *contextPtr);
  194. extern void EcapContextRestore(unsigned int ecapBase, unsigned int pwmssBase,
  195. ECAPCONTEXT *contextPtr);
  196. #endif