pwm_pal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 NXP
3  * All rights reserved.
4  *
5  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
6  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
9  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
11  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
12  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
13  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
14  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
15  * THE POSSIBILITY OF SUCH DAMAGE.
16  */
17 
18 #ifndef PWM_PAL_H
19 #define PWM_PAL_H
20 
21 #include "status.h"
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include "callbacks.h"
25 #include "pwm_pal_mapping.h"
26 #include "pwm_pal_cfg.h"
27 /* Include PD files */
28 /* Include PD files for FTM. */
29 #if (defined (PWM_OVER_FTM))
30  #include "ftm_pwm_driver.h"
31  #include "ftm_common.h"
32 #endif
33 
34 /* Include PD files for EMIOS. */
35 #if (defined (PWM_OVER_EMIOS))
36  #include "emios_common.h"
37  #include "emios_mc_driver.h"
38  #include "emios_pwm_driver.h"
39  #include "emios_hw_access.h"
40 #endif
41 
42 /* Include PD files for ETIMER. */
43 #if (defined (PWM_OVER_ETIMER))
44  #include "etimer_driver.h"
45  #include "etimer_hw_access.h"
46 #endif
47 
56 /*******************************************************************************
57  * Definitions
58  ******************************************************************************/
59 
64 typedef enum
65 {
69 
74 typedef enum
75 {
79 
84 typedef enum
85 {
89 
90 #if defined PWM_OVER_FTM
91 
96 typedef struct
97 {
98  ftm_clock_source_t sourceClock;
99  ftm_clock_ps_t prescaler;
100  ftm_deadtime_ps_t deadtimePrescaler;
101 } pwm_ftm_timebase_t;
102 #endif
103 
104 #if defined PWM_OVER_EMIOS
105 
109 typedef enum
110 {
111  BUS_B = 0U,
112  BUS_C = 8U,
113  BUS_D = 16U,
114  BUS_F = 22U,
115  BUS_A = 23U,
116  BUS_E = 24U
117 } pwm_emios_timebase_name_t;
118 
124 typedef struct
125 {
126  pwm_emios_timebase_name_t name;
127  emios_clock_internal_ps_t internalPrescaler;
128 } pwm_emios_timebase_t;
129 #endif
130 
131 #if (defined (PWM_OVER_ETIMER))
132 
138 typedef struct
139 {
140  bool halfClkPeriod;
141  etimer_input_config_t pwmClkSrc;
142  bool enableOutSig;
143 } pwm_etimer_timebase_t;
144 
145 #endif
146 
151 typedef struct
152 {
153  uint8_t channel;
155  uint32_t period;
156  uint32_t duty;
159  uint8_t deadtime;
162  void* timebase;
164 } pwm_channel_t;
165 
170 typedef struct
171 {
175 
176 /*******************************************************************************
177  * API
178  ******************************************************************************/
179 
180 #if defined(__cplusplus)
181 extern "C" {
182 #endif
183 
191  status_t PWM_Init(const pwm_instance_t * const instance, const pwm_global_config_t* config);
192 
201  status_t PWM_UpdateDuty(const pwm_instance_t * const instance, uint8_t channel, uint32_t duty);
202 
212  status_t PWM_UpdatePeriod(const pwm_instance_t * const instance, uint8_t channel, uint32_t period);
213 
225  status_t PWM_OverwriteOutputChannels(const pwm_instance_t * const instance, uint32_t channelsMask, uint32_t channelsValues);
226 
233  status_t PWM_Deinit(const pwm_instance_t * const instance);
234 
235 #if defined(__cplusplus)
236 }
237 #endif
238 
240 #endif /* PWM_PAL_H */
241 
242 
243 /*******************************************************************************
244  * EOF
245  ******************************************************************************/
246 
247 
248 
249 
250 
251 
252 
uint8_t channel
Definition: pwm_pal.h:153
This structure includes the configuration for each channel Implements : pwm_channel_t_Class.
Definition: pwm_pal.h:151
pwm_polarity_t polarity
Definition: pwm_pal.h:157
status_t PWM_UpdatePeriod(const pwm_instance_t *const instance, uint8_t channel, uint32_t period)
Update period for specific a specific channel. This function changes period for all channels which sh...
Definition: pwm_pal.c:583
This structure is the configuration for initialization of PWM channels. Implements : pwm_global_confi...
Definition: pwm_pal.h:170
status_t PWM_Init(const pwm_instance_t *const instance, const pwm_global_config_t *config)
Initialize PWM channels based on config parameter.
Definition: pwm_pal.c:134
pwm_polarity_t
Defines the polarity of pwm channels Implements : pwm_polarity_t_Class.
Definition: pwm_pal.h:74
uint8_t numberOfPwmChannels
Definition: pwm_pal.h:173
uint32_t period
Definition: pwm_pal.h:155
uint32_t duty
Definition: pwm_pal.h:156
status_t PWM_Deinit(const pwm_instance_t *const instance)
Uninitialised PWM instance.
Definition: pwm_pal.c:723
ftm_clock_ps_t
FlexTimer pre-scaler factor selection for the clock source. In quadrature decoder mode set FTM_CLOCK_...
Definition: ftm_common.h:252
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
bool enableComplementaryChannel
Definition: pwm_pal.h:160
ftm_clock_source_t
FlexTimer clock source selection.
Definition: ftm_common.h:238
pwm_complementarty_mode_t complementaryChannelPolarity
Definition: pwm_pal.h:161
pwm_complementarty_mode_t
Defines the polarity of complementary pwm channels relative to main channel Implements : pwm_compleme...
Definition: pwm_pal.h:84
uint8_t deadtime
Definition: pwm_pal.h:159
ftm_deadtime_ps_t
FlexTimer pre-scaler factor for the dead-time insertion.
Definition: ftm_common.h:334
pwm_channel_type_t channelType
Definition: pwm_pal.h:154
pwm_channel_t * pwmChannels
Definition: pwm_pal.h:172
pwm_channel_type_t
Defines the channel types Implements : pwm_channel_type_t_Class.
Definition: pwm_pal.h:64
bool insertDeadtime
Definition: pwm_pal.h:158
status_t PWM_UpdateDuty(const pwm_instance_t *const instance, uint8_t channel, uint32_t duty)
Update duty cycle. The measurement unit for duty is clock ticks.
Definition: pwm_pal.c:516
status_t PWM_OverwriteOutputChannels(const pwm_instance_t *const instance, uint32_t channelsMask, uint32_t channelsValues)
This function change the output value for some channels. channelsMask select which channels will be o...
Definition: pwm_pal.c:679
Structure storing PAL instance information.
void * timebase
Definition: pwm_pal.h:162