PWM
|
PWM.h
Go to the documentation of this file.
00001 00076 #ifndef PWM_H 00077 #define PWM_H 00078 00079 00080 /*********************************************************************************************************************** 00081 * HEADER FILES 00082 **********************************************************************************************************************/ 00083 #include <xmc_gpio.h> 00084 #include "pwm_conf.h" 00085 #include <DAVE_common.h> 00086 00087 /********************************************************************************************************************** 00088 * MACROS 00089 **********************************************************************************************************************/ 00090 #if (!((XMC_LIB_MAJOR_VERSION == 2U) && \ 00091 (XMC_LIB_MINOR_VERSION >= 0U) && \ 00092 (XMC_LIB_PATCH_VERSION >= 0U))) 00093 #error "PWM requires XMC Peripheral Library v2.0.0 or higher" 00094 #endif 00095 00096 #define PWM_MAX_TIMER_COUNT (65535U) 00098 /********************************************************************************************************************** 00099 * ENUMS 00100 **********************************************************************************************************************/ 00101 00108 typedef enum PWM_TIMER_SLICE 00109 { 00110 PWM_TIMER_SLICE_CCU4 = 0U, 00111 PWM_TIMER_SLICE_CCU8 00112 } PWM_TIMER_SLICE_t; 00113 00117 typedef enum PWM_TIMER_STATUS 00118 { 00119 PWM_TIMER_IDLE = 0U, 00120 PWM_TIMER_RUNNING 00121 } PWM_TIMER_STATUS_t; 00122 00126 typedef enum PWM_INTERRUPT 00127 { 00128 PWM_INTERRUPT_PERIODMATCH = 0U, 00129 PWM_INTERRUPT_COMPAREMATCH = 2U 00130 } PWM_INTERRUPT_t; 00131 00135 typedef enum PWM_OUTPUT_PASSIVE_LEVEL 00136 { 00137 PWM_OUTPUT_PASSIVE_LEVEL_LOW = 0, 00138 PWM_OUTPUT_PASSIVE_LEVEL_HIGH , 00139 PWM_OUTPUT_PASSIVE_LEVEL_MAX 00140 } PWM_OUTPUT_PASSIVE_LEVEL_t; 00141 00145 typedef enum PWM_STATUS 00146 { 00147 PWM_STATUS_SUCCESS = 0, 00148 PWM_STATUS_FAILURE, 00149 PWM_STATUS_UNINITIALIZED, 00150 PWM_STATUS_RUNNING, 00151 PWM_STATUS_STOPPED, 00152 } PWM_STATUS_t; 00153 00157 typedef enum PWM_ERROR_CODES 00158 { 00159 PWM_OPER_NOT_ALLOWED_ERROR = 1, 00160 PWM_INVALID_PARAM_ERROR 00161 } PWM_ERROR_CODES_t; 00162 00167 /********************************************************************************************************************** 00168 * DATA STRUCTURES 00169 **********************************************************************************************************************/ 00174 /*Anonymous structure/union guard start*/ 00175 #if defined(__CC_ARM) 00176 #pragma push 00177 #pragma anon_unions 00178 #elif defined(__TASKING__) 00179 #pragma warning 586 00180 #endif 00181 00184 typedef struct PWM_HandleType 00185 { 00186 union 00187 { 00188 #ifdef PWM_SLICE_USED_CCU4 00189 GLOBAL_CCU4_t *const global_ccu4_handle; 00190 #endif 00191 #ifdef PWM_SLICE_USED_CCU8 00192 GLOBAL_CCU8_t *const global_ccu8_handle; 00193 #endif 00194 }; 00195 00196 union 00197 { 00198 #ifdef PWM_SLICE_USED_CCU4 00199 XMC_CCU4_MODULE_t *const ccu4_kernel_ptr; 00200 #endif 00201 #ifdef PWM_SLICE_USED_CCU8 00202 XMC_CCU8_MODULE_t *const ccu8_kernel_ptr; 00203 #endif 00204 }; 00205 00206 union 00207 { 00208 #ifdef PWM_SLICE_USED_CCU4 00209 XMC_CCU4_SLICE_t *const ccu4_slice_ptr; 00210 #endif 00211 #ifdef PWM_SLICE_USED_CCU8 00212 XMC_CCU8_SLICE_t *const ccu8_slice_ptr; 00213 #endif 00214 }; 00215 00216 union 00217 { 00218 #ifdef PWM_SLICE_USED_CCU4 00219 const XMC_CCU4_SLICE_COMPARE_CONFIG_t *const ccu4_slice_config_ptr; 00220 #endif 00221 #ifdef PWM_SLICE_USED_CCU8 00222 const XMC_CCU8_SLICE_COMPARE_CONFIG_t *const ccu8_slice_config_ptr; 00223 #endif 00224 }; 00225 00226 XMC_GPIO_PORT_t *const gpio_out_port; 00228 const XMC_GPIO_CONFIG_t *const gpio_out_config; 00230 uint32_t compare_value; 00232 uint32_t period_value; 00234 uint32_t duty_cycle; 00236 uint32_t shadow_mask; 00238 const PWM_TIMER_SLICE_t timer_type; 00240 PWM_STATUS_t state; 00242 union 00243 { 00244 #ifdef PWM_SLICE_USED_CCU4 00245 const XMC_CCU4_SLICE_SR_ID_t ccu4_slice_period_match_node; 00246 #endif 00247 #ifdef PWM_SLICE_USED_CCU8 00248 const XMC_CCU8_SLICE_SR_ID_t ccu8_slice_period_match_node; 00249 #endif 00250 }; 00251 00252 union 00253 { 00254 #ifdef PWM_SLICE_USED_CCU4 00255 const XMC_CCU4_SLICE_SR_ID_t ccu4_slice_compare_match_node; 00256 #endif 00257 #ifdef PWM_SLICE_USED_CCU8 00258 const XMC_CCU8_SLICE_SR_ID_t ccu8_slice_compare_match_node; 00259 #endif 00260 }; 00261 00262 const uint8_t gpio_out_pin; 00264 const uint8_t kernel_number; 00266 const uint8_t slice_number; 00268 const bool start_control; 00270 const bool period_match_enable; 00272 const bool compare_match_enable; 00274 } PWM_t; 00275 00279 /*Anonymous structure/union guard end*/ 00280 #if defined(__CC_ARM) 00281 #pragma pop 00282 #elif defined(__TASKING__) 00283 #pragma warning restore 00284 #endif 00285 00289 #ifdef __cplusplus 00290 extern "C" { 00291 #endif 00292 /*********************************************************************************************************************** 00293 * API Prototypes 00294 **********************************************************************************************************************/ 00329 DAVE_APP_VERSION_t PWM_GetAppVersion(void); 00330 00354 PWM_STATUS_t PWM_Init(PWM_t *const handle_ptr); 00355 00383 void PWM_Start(PWM_t *const handle_ptr); 00384 00411 void PWM_Stop(PWM_t *const handle_ptr); 00412 00459 PWM_STATUS_t PWM_SetFreq(PWM_t *const handle_ptr, uint32_t pwm_freq_hz); 00460 00515 PWM_STATUS_t PWM_SetFreqAndDutyCycle(PWM_t *const handle_ptr, uint32_t pwm_freq_hz, uint32_t duty_cycle); 00516 00569 void PWM_ClearEvent(PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt); 00570 00609 bool PWM_GetInterruptStatus(PWM_t *const handle_ptr, PWM_INTERRUPT_t pwm_interrupt); 00610 00636 bool PWM_GetTimerStatus(PWM_t *const handle_ptr); 00637 00697 PWM_STATUS_t PWM_SetDutyCycle(PWM_t *const handle_ptr, uint32_t duty_cycle); 00698 00699 00734 void PWM_SetPassiveLevel(PWM_t *const handle_ptr, PWM_OUTPUT_PASSIVE_LEVEL_t pwm_output_passive_level); 00735 00771 PWM_STATUS_t PWM_SetPeriodMatchValue(PWM_t *const handle_ptr, uint32_t period_match_value); 00772 00773 #include "PWM_Extern.h" 00774 00778 #ifdef __cplusplus 00779 } 00780 #endif 00781 00782 #endif /* PWM_H_ */