pwm.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. //*****************************************************************************
  2. //
  3. // pwm.h - API function protoypes for Pulse Width Modulation (PWM) ports
  4. //
  5. // Copyright (c) 2005-2011 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 8264 of the Stellaris Peripheral Driver Library.
  22. //
  23. //*****************************************************************************
  24. #ifndef __PWM_H__
  25. #define __PWM_H__
  26. //*****************************************************************************
  27. //
  28. // If building with a C++ compiler, make all of the definitions in this header
  29. // have a C binding.
  30. //
  31. //*****************************************************************************
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. //*****************************************************************************
  37. //
  38. // The following defines are passed to PWMGenConfigure() as the ulConfig
  39. // parameter and specify the configuration of the PWM generator.
  40. //
  41. //*****************************************************************************
  42. #define PWM_GEN_MODE_DOWN 0x00000000 // Down count mode
  43. #define PWM_GEN_MODE_UP_DOWN 0x00000002 // Up/Down count mode
  44. #define PWM_GEN_MODE_SYNC 0x00000038 // Synchronous updates
  45. #define PWM_GEN_MODE_NO_SYNC 0x00000000 // Immediate updates
  46. #define PWM_GEN_MODE_DBG_RUN 0x00000004 // Continue running in debug mode
  47. #define PWM_GEN_MODE_DBG_STOP 0x00000000 // Stop running in debug mode
  48. #define PWM_GEN_MODE_FAULT_LATCHED \
  49. 0x00040000 // Fault is latched
  50. #define PWM_GEN_MODE_FAULT_UNLATCHED \
  51. 0x00000000 // Fault is not latched
  52. #define PWM_GEN_MODE_FAULT_MINPER \
  53. 0x00020000 // Enable min fault period
  54. #define PWM_GEN_MODE_FAULT_NO_MINPER \
  55. 0x00000000 // Disable min fault period
  56. #define PWM_GEN_MODE_FAULT_EXT 0x00010000 // Enable extended fault support
  57. #define PWM_GEN_MODE_FAULT_LEGACY \
  58. 0x00000000 // Disable extended fault support
  59. #define PWM_GEN_MODE_DB_NO_SYNC 0x00000000 // Deadband updates occur
  60. // immediately
  61. #define PWM_GEN_MODE_DB_SYNC_LOCAL \
  62. 0x0000A800 // Deadband updates locally
  63. // synchronized
  64. #define PWM_GEN_MODE_DB_SYNC_GLOBAL \
  65. 0x0000FC00 // Deadband updates globally
  66. // synchronized
  67. #define PWM_GEN_MODE_GEN_NO_SYNC \
  68. 0x00000000 // Generator mode updates occur
  69. // immediately
  70. #define PWM_GEN_MODE_GEN_SYNC_LOCAL \
  71. 0x00000280 // Generator mode updates locally
  72. // synchronized
  73. #define PWM_GEN_MODE_GEN_SYNC_GLOBAL \
  74. 0x000003C0 // Generator mode updates globally
  75. // synchronized
  76. //*****************************************************************************
  77. //
  78. // Defines for enabling, disabling, and clearing PWM generator interrupts and
  79. // triggers.
  80. //
  81. //*****************************************************************************
  82. #define PWM_INT_CNT_ZERO 0x00000001 // Int if COUNT = 0
  83. #define PWM_INT_CNT_LOAD 0x00000002 // Int if COUNT = LOAD
  84. #define PWM_INT_CNT_AU 0x00000004 // Int if COUNT = CMPA U
  85. #define PWM_INT_CNT_AD 0x00000008 // Int if COUNT = CMPA D
  86. #define PWM_INT_CNT_BU 0x00000010 // Int if COUNT = CMPA U
  87. #define PWM_INT_CNT_BD 0x00000020 // Int if COUNT = CMPA D
  88. #define PWM_TR_CNT_ZERO 0x00000100 // Trig if COUNT = 0
  89. #define PWM_TR_CNT_LOAD 0x00000200 // Trig if COUNT = LOAD
  90. #define PWM_TR_CNT_AU 0x00000400 // Trig if COUNT = CMPA U
  91. #define PWM_TR_CNT_AD 0x00000800 // Trig if COUNT = CMPA D
  92. #define PWM_TR_CNT_BU 0x00001000 // Trig if COUNT = CMPA U
  93. #define PWM_TR_CNT_BD 0x00002000 // Trig if COUNT = CMPA D
  94. //*****************************************************************************
  95. //
  96. // Defines for enabling, disabling, and clearing PWM interrupts.
  97. //
  98. //*****************************************************************************
  99. #define PWM_INT_GEN_0 0x00000001 // Generator 0 interrupt
  100. #define PWM_INT_GEN_1 0x00000002 // Generator 1 interrupt
  101. #define PWM_INT_GEN_2 0x00000004 // Generator 2 interrupt
  102. #define PWM_INT_GEN_3 0x00000008 // Generator 3 interrupt
  103. #ifndef DEPRECATED
  104. #define PWM_INT_FAULT 0x00010000 // Fault interrupt
  105. #endif
  106. #define PWM_INT_FAULT0 0x00010000 // Fault0 interrupt
  107. #define PWM_INT_FAULT1 0x00020000 // Fault1 interrupt
  108. #define PWM_INT_FAULT2 0x00040000 // Fault2 interrupt
  109. #define PWM_INT_FAULT3 0x00080000 // Fault3 interrupt
  110. #define PWM_INT_FAULT_M 0x000F0000 // Fault interrupt source mask
  111. //*****************************************************************************
  112. //
  113. // Defines to identify the generators within a module.
  114. //
  115. //*****************************************************************************
  116. #define PWM_GEN_0 0x00000040 // Offset address of Gen0
  117. #define PWM_GEN_1 0x00000080 // Offset address of Gen1
  118. #define PWM_GEN_2 0x000000C0 // Offset address of Gen2
  119. #define PWM_GEN_3 0x00000100 // Offset address of Gen3
  120. #define PWM_GEN_0_BIT 0x00000001 // Bit-wise ID for Gen0
  121. #define PWM_GEN_1_BIT 0x00000002 // Bit-wise ID for Gen1
  122. #define PWM_GEN_2_BIT 0x00000004 // Bit-wise ID for Gen2
  123. #define PWM_GEN_3_BIT 0x00000008 // Bit-wise ID for Gen3
  124. #define PWM_GEN_EXT_0 0x00000800 // Offset of Gen0 ext address range
  125. #define PWM_GEN_EXT_1 0x00000880 // Offset of Gen1 ext address range
  126. #define PWM_GEN_EXT_2 0x00000900 // Offset of Gen2 ext address range
  127. #define PWM_GEN_EXT_3 0x00000980 // Offset of Gen3 ext address range
  128. //*****************************************************************************
  129. //
  130. // Defines to identify the outputs within a module.
  131. //
  132. //*****************************************************************************
  133. #define PWM_OUT_0 0x00000040 // Encoded offset address of PWM0
  134. #define PWM_OUT_1 0x00000041 // Encoded offset address of PWM1
  135. #define PWM_OUT_2 0x00000082 // Encoded offset address of PWM2
  136. #define PWM_OUT_3 0x00000083 // Encoded offset address of PWM3
  137. #define PWM_OUT_4 0x000000C4 // Encoded offset address of PWM4
  138. #define PWM_OUT_5 0x000000C5 // Encoded offset address of PWM5
  139. #define PWM_OUT_6 0x00000106 // Encoded offset address of PWM6
  140. #define PWM_OUT_7 0x00000107 // Encoded offset address of PWM7
  141. #define PWM_OUT_0_BIT 0x00000001 // Bit-wise ID for PWM0
  142. #define PWM_OUT_1_BIT 0x00000002 // Bit-wise ID for PWM1
  143. #define PWM_OUT_2_BIT 0x00000004 // Bit-wise ID for PWM2
  144. #define PWM_OUT_3_BIT 0x00000008 // Bit-wise ID for PWM3
  145. #define PWM_OUT_4_BIT 0x00000010 // Bit-wise ID for PWM4
  146. #define PWM_OUT_5_BIT 0x00000020 // Bit-wise ID for PWM5
  147. #define PWM_OUT_6_BIT 0x00000040 // Bit-wise ID for PWM6
  148. #define PWM_OUT_7_BIT 0x00000080 // Bit-wise ID for PWM7
  149. //*****************************************************************************
  150. //
  151. // Defines to identify each of the possible fault trigger conditions in
  152. // PWM_FAULT_GROUP_0.
  153. //
  154. //*****************************************************************************
  155. #define PWM_FAULT_GROUP_0 0
  156. #define PWM_FAULT_FAULT0 0x00000001
  157. #define PWM_FAULT_FAULT1 0x00000002
  158. #define PWM_FAULT_FAULT2 0x00000004
  159. #define PWM_FAULT_FAULT3 0x00000008
  160. #define PWM_FAULT_ACMP0 0x00010000
  161. #define PWM_FAULT_ACMP1 0x00020000
  162. #define PWM_FAULT_ACMP2 0x00040000
  163. //*****************************************************************************
  164. //
  165. // Defines to identify each of the possible fault trigger conditions in
  166. // PWM_FAULT_GROUP_1.
  167. //
  168. //*****************************************************************************
  169. #define PWM_FAULT_GROUP_1 1
  170. #define PWM_FAULT_DCMP0 0x00000001
  171. #define PWM_FAULT_DCMP1 0x00000002
  172. #define PWM_FAULT_DCMP2 0x00000004
  173. #define PWM_FAULT_DCMP3 0x00000008
  174. #define PWM_FAULT_DCMP4 0x00000010
  175. #define PWM_FAULT_DCMP5 0x00000020
  176. #define PWM_FAULT_DCMP6 0x00000040
  177. #define PWM_FAULT_DCMP7 0x00000080
  178. //*****************************************************************************
  179. //
  180. // Defines to identify the sense of each of the external FAULTn signals
  181. //
  182. //*****************************************************************************
  183. #define PWM_FAULT0_SENSE_HIGH 0x00000000
  184. #define PWM_FAULT0_SENSE_LOW 0x00000001
  185. #define PWM_FAULT1_SENSE_HIGH 0x00000000
  186. #define PWM_FAULT1_SENSE_LOW 0x00000002
  187. #define PWM_FAULT2_SENSE_HIGH 0x00000000
  188. #define PWM_FAULT2_SENSE_LOW 0x00000004
  189. #define PWM_FAULT3_SENSE_HIGH 0x00000000
  190. #define PWM_FAULT3_SENSE_LOW 0x00000008
  191. //*****************************************************************************
  192. //
  193. // API Function prototypes
  194. //
  195. //*****************************************************************************
  196. extern void PWMGenConfigure(unsigned long ulBase, unsigned long ulGen,
  197. unsigned long ulConfig);
  198. extern void PWMGenPeriodSet(unsigned long ulBase, unsigned long ulGen,
  199. unsigned long ulPeriod);
  200. extern unsigned long PWMGenPeriodGet(unsigned long ulBase,
  201. unsigned long ulGen);
  202. extern void PWMGenEnable(unsigned long ulBase, unsigned long ulGen);
  203. extern void PWMGenDisable(unsigned long ulBase, unsigned long ulGen);
  204. extern void PWMPulseWidthSet(unsigned long ulBase, unsigned long ulPWMOut,
  205. unsigned long ulWidth);
  206. extern unsigned long PWMPulseWidthGet(unsigned long ulBase,
  207. unsigned long ulPWMOut);
  208. extern void PWMDeadBandEnable(unsigned long ulBase, unsigned long ulGen,
  209. unsigned short usRise, unsigned short usFall);
  210. extern void PWMDeadBandDisable(unsigned long ulBase, unsigned long ulGen);
  211. extern void PWMSyncUpdate(unsigned long ulBase, unsigned long ulGenBits);
  212. extern void PWMSyncTimeBase(unsigned long ulBase, unsigned long ulGenBits);
  213. extern void PWMOutputState(unsigned long ulBase, unsigned long ulPWMOutBits,
  214. tBoolean bEnable);
  215. extern void PWMOutputInvert(unsigned long ulBase, unsigned long ulPWMOutBits,
  216. tBoolean bInvert);
  217. extern void PWMOutputFaultLevel(unsigned long ulBase,
  218. unsigned long ulPWMOutBits,
  219. tBoolean bDriveHigh);
  220. extern void PWMOutputFault(unsigned long ulBase, unsigned long ulPWMOutBits,
  221. tBoolean bFaultSuppress);
  222. extern void PWMGenIntRegister(unsigned long ulBase, unsigned long ulGen,
  223. void (*pfnIntHandler)(void));
  224. extern void PWMGenIntUnregister(unsigned long ulBase, unsigned long ulGen);
  225. extern void PWMFaultIntRegister(unsigned long ulBase,
  226. void (*pfnIntHandler)(void));
  227. extern void PWMFaultIntUnregister(unsigned long ulBase);
  228. extern void PWMGenIntTrigEnable(unsigned long ulBase, unsigned long ulGen,
  229. unsigned long ulIntTrig);
  230. extern void PWMGenIntTrigDisable(unsigned long ulBase, unsigned long ulGen,
  231. unsigned long ulIntTrig);
  232. extern unsigned long PWMGenIntStatus(unsigned long ulBase, unsigned long ulGen,
  233. tBoolean bMasked);
  234. extern void PWMGenIntClear(unsigned long ulBase, unsigned long ulGen,
  235. unsigned long ulInts);
  236. extern void PWMIntEnable(unsigned long ulBase, unsigned long ulGenFault);
  237. extern void PWMIntDisable(unsigned long ulBase, unsigned long ulGenFault);
  238. extern void PWMFaultIntClear(unsigned long ulBase);
  239. extern unsigned long PWMIntStatus(unsigned long ulBase, tBoolean bMasked);
  240. extern void PWMFaultIntClearExt(unsigned long ulBase,
  241. unsigned long ulFaultInts);
  242. extern void PWMGenFaultConfigure(unsigned long ulBase, unsigned long ulGen,
  243. unsigned long ulMinFaultPeriod,
  244. unsigned long ulFaultSenses);
  245. extern void PWMGenFaultTriggerSet(unsigned long ulBase, unsigned long ulGen,
  246. unsigned long ulGroup,
  247. unsigned long ulFaultTriggers);
  248. extern unsigned long PWMGenFaultTriggerGet(unsigned long ulBase,
  249. unsigned long ulGen,
  250. unsigned long ulGroup);
  251. extern unsigned long PWMGenFaultStatus(unsigned long ulBase,
  252. unsigned long ulGen,
  253. unsigned long ulGroup);
  254. extern void PWMGenFaultClear(unsigned long ulBase, unsigned long ulGen,
  255. unsigned long ulGroup,
  256. unsigned long ulFaultTriggers);
  257. //*****************************************************************************
  258. //
  259. // Mark the end of the C bindings section for C++ compilers.
  260. //
  261. //*****************************************************************************
  262. #ifdef __cplusplus
  263. }
  264. #endif
  265. #endif // __PWM_H__