rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
PWM

Functions

static void pwm_lld_serve_interrupt (PWMDriver *pwmp)
 
 OSAL_IRQ_HANDLER (KINETIS_FTM0_IRQ_VECTOR)
 FTM0 interrupt handler.
 
 OSAL_IRQ_HANDLER (KINETIS_FTM1_IRQ_VECTOR)
 FTM1 interrupt handler.
 
 OSAL_IRQ_HANDLER (KINETIS_FTM2_IRQ_VECTOR)
 FTM2 interrupt handler.
 
 OSAL_IRQ_HANDLER (KINETIS_FTM3_IRQ_VECTOR)
 FTM3 interrupt handler.
 
void pwm_lld_init (void)
 Low level PWM driver initialization.
 
void pwm_lld_start (PWMDriver *pwmp)
 Configures and activates the PWM peripheral.
 
void pwm_lld_stop (PWMDriver *pwmp)
 Deactivates the PWM peripheral.
 
void pwm_lld_enable_channel (PWMDriver *pwmp, pwmchannel_t channel, pwmcnt_t width)
 Enables a PWM channel.
 
void pwm_lld_disable_channel (PWMDriver *pwmp, pwmchannel_t channel)
 Disables a PWM channel and its notification.
 
void pwm_lld_enable_periodic_notification (PWMDriver *pwmp)
 Enables the periodic activation edge notification.
 
void pwm_lld_disable_periodic_notification (PWMDriver *pwmp)
 Disables the periodic activation edge notification.
 
void pwm_lld_enable_channel_notification (PWMDriver *pwmp, pwmchannel_t channel)
 Enables a channel de-activation edge notification.
 
void pwm_lld_disable_channel_notification (PWMDriver *pwmp, pwmchannel_t channel)
 Disables a channel de-activation edge notification.
 

Variables

PWMDriver PWMD1
 PWMD1 driver identifier.
 
PWMDriver PWMD2
 PWMD2 driver identifier.
 
PWMDriver PWMD3
 PWMD3 driver identifier.
 
PWMDriver PWMD4
 PWMD4 driver identifier.
 

Detailed Description

Function Documentation

◆ OSAL_IRQ_HANDLER() [1/4]

OSAL_IRQ_HANDLER ( KINETIS_FTM0_IRQ_VECTOR  )

FTM0 interrupt handler.

@isr

Definition at line 118 of file hal_pwm_lld.c.

118 {
119 OSAL_IRQ_PROLOGUE();
121 OSAL_IRQ_EPILOGUE();
122}
static void pwm_lld_serve_interrupt(PWMDriver *pwmp)
Definition hal_pwm_lld.c:84
PWMDriver PWMD1
PWMD1 driver identifier.
Definition hal_pwm_lld.c:49
Here is the call graph for this function:

◆ OSAL_IRQ_HANDLER() [2/4]

OSAL_IRQ_HANDLER ( KINETIS_FTM1_IRQ_VECTOR  )

FTM1 interrupt handler.

@isr

Definition at line 131 of file hal_pwm_lld.c.

131 {
132
133 OSAL_IRQ_PROLOGUE();
135 OSAL_IRQ_EPILOGUE();
136}
PWMDriver PWMD2
PWMD2 driver identifier.
Definition hal_pwm_lld.c:57
Here is the call graph for this function:

◆ OSAL_IRQ_HANDLER() [3/4]

OSAL_IRQ_HANDLER ( KINETIS_FTM2_IRQ_VECTOR  )

FTM2 interrupt handler.

@isr

Definition at line 145 of file hal_pwm_lld.c.

145 {
146
147 OSAL_IRQ_PROLOGUE();
149 OSAL_IRQ_EPILOGUE();
150}
PWMDriver PWMD3
PWMD3 driver identifier.
Definition hal_pwm_lld.c:65
Here is the call graph for this function:

◆ OSAL_IRQ_HANDLER() [4/4]

OSAL_IRQ_HANDLER ( KINETIS_FTM3_IRQ_VECTOR  )

FTM3 interrupt handler.

@isr

Definition at line 159 of file hal_pwm_lld.c.

159 {
160
161 OSAL_IRQ_PROLOGUE();
163 OSAL_IRQ_EPILOGUE();
164}
PWMDriver PWMD4
PWMD4 driver identifier.
Definition hal_pwm_lld.c:73
Here is the call graph for this function:

◆ pwm_lld_disable_channel()

void pwm_lld_disable_channel ( PWMDriver pwmp,
pwmchannel_t  channel 
)

Disables a PWM channel and its notification.

Precondition
The PWM unit must have been activated using pwmStart().
Postcondition
The channel is disabled and its output line returned to the idle state.
Note
The function has effect at the next cycle start.
Parameters
[in]pwmppointer to a PWMDriver object
[in]channelPWM channel identifier (0...channels-1)

@notapi

Definition at line 404 of file hal_pwm_lld.c.

404 {
405
406 pwmp->ftm->CHANNEL[channel].CnSC = 0;
407 pwmp->ftm->CHANNEL[channel].CnV = 0;
408}
uint16_t channel
Definition adc_inputs.h:104
PWM_DRIVER_EXT_FIELDS FTM_TypeDef * ftm
Pointer to the FTM registers block.

◆ pwm_lld_disable_channel_notification()

void pwm_lld_disable_channel_notification ( PWMDriver pwmp,
pwmchannel_t  channel 
)

Disables a channel de-activation edge notification.

Precondition
The PWM unit must have been activated using pwmStart().
The channel must have been activated using pwmEnableChannel().
Note
If the notification is already disabled then the call has no effect.
Parameters
[in]pwmppointer to a PWMDriver object
[in]channelPWM channel identifier (0...channels-1)

@notapi

Definition at line 463 of file hal_pwm_lld.c.

464 {
465 pwmp->ftm->CHANNEL[channel].CnSC &= ~FTM_CnSC_CHIEx;
466}

◆ pwm_lld_disable_periodic_notification()

void pwm_lld_disable_periodic_notification ( PWMDriver pwmp)

Disables the periodic activation edge notification.

Precondition
The PWM unit must have been activated using pwmStart().
Note
If the notification is already disabled then the call has no effect.
Parameters
[in]pwmppointer to a PWMDriver object

@notapi

Definition at line 432 of file hal_pwm_lld.c.

432 {
433 pwmp->ftm->SC &= ~FTM_SC_TOIEx;
434}

◆ pwm_lld_enable_channel()

void pwm_lld_enable_channel ( PWMDriver pwmp,
pwmchannel_t  channel,
pwmcnt_t  width 
)

Enables a PWM channel.

Precondition
The PWM unit must have been activated using pwmStart().
Postcondition
The channel is active using the specified configuration.
Note
The function has effect at the next cycle start.
Channel notification is not enabled.
Parameters
[in]pwmppointer to a PWMDriver object
[in]channelPWM channel identifier (0...channels-1)
[in]widthPWM pulse width as clock pulses number

@notapi

Definition at line 370 of file hal_pwm_lld.c.

372 {
373 uint32_t mode = FTM_CnSC_MSBx; /* Edge-aligned PWM mode.*/
374
375 switch (pwmp->config->channels[channel].mode & PWM_OUTPUT_MASK) {
376 case PWM_OUTPUT_ACTIVE_HIGH:
377 mode |= FTM_CnSC_ELSBx;
378 break;
379 case PWM_OUTPUT_ACTIVE_LOW:
380 mode |= FTM_CnSC_ELSAx;
381 break;
382 }
383
384 if (pwmp->ftm->CHANNEL[channel].CnSC & FTM_CnSC_CHIEx)
385 mode |= FTM_CnSC_CHIEx;
386
387 pwmp->ftm->CHANNEL[channel].CnSC = mode;
388 pwmp->ftm->CHANNEL[channel].CnV = width;
389 pwmp->ftm->PWMLOAD = FTM_PWMLOAD_LDOK_MASK;
390}
pwmmode_t mode
Channel active logic level.
PWMChannelConfig channels[PWM_CHANNELS]
Channels configurations.
const PWMConfig * config
Current driver configuration data.

Referenced by portSetHardwareSchedulerTimer().

Here is the caller graph for this function:

◆ pwm_lld_enable_channel_notification()

void pwm_lld_enable_channel_notification ( PWMDriver pwmp,
pwmchannel_t  channel 
)

Enables a channel de-activation edge notification.

Precondition
The PWM unit must have been activated using pwmStart().
The channel must have been activated using pwmEnableChannel().
Note
If the notification is already enabled then the call has no effect.
Parameters
[in]pwmppointer to a PWMDriver object
[in]channelPWM channel identifier (0...channels-1)

@notapi

Definition at line 447 of file hal_pwm_lld.c.

448 {
449 pwmp->ftm->CHANNEL[channel].CnSC |= FTM_CnSC_CHIEx;
450}

◆ pwm_lld_enable_periodic_notification()

void pwm_lld_enable_periodic_notification ( PWMDriver pwmp)

Enables the periodic activation edge notification.

Precondition
The PWM unit must have been activated using pwmStart().
Note
If the notification is already enabled then the call has no effect.
Parameters
[in]pwmppointer to a PWMDriver object

@notapi

Definition at line 419 of file hal_pwm_lld.c.

419 {
420 pwmp->ftm->SC |= FTM_SC_TOIEx;
421}

◆ pwm_lld_init()

void pwm_lld_init ( void  )

Low level PWM driver initialization.

@notapi

Definition at line 176 of file hal_pwm_lld.c.

176 {
177
178#if KINETIS_PWM_USE_FTM0
179 pwmObjectInit(&PWMD1);
180 PWMD1.channels = KINETIS_FTM0_CHANNELS;
181 PWMD1.ftm = FTM0;
182#endif
183
184#if KINETIS_PWM_USE_FTM1
185 pwmObjectInit(&PWMD2);
186 PWMD2.channels = KINETIS_FTM1_CHANNELS;
187 PWMD2.ftm = FTM1;
188#endif
189
190#if KINETIS_PWM_USE_FTM2
191 pwmObjectInit(&PWMD3);
192 PWMD3.channels = KINETIS_FTM2_CHANNELS;
193 PWMD3.ftm = FTM2;
194#endif
195
196#if KINETIS_PWM_USE_FTM3
197 pwmObjectInit(&PWMD4);
198 PWMD4.channels = KINETIS_FTM3_CHANNELS;
199 PWMD4.ftm = FTM3;
200#endif
201}
pwmchannel_t channels
Number of channels in this instance.

◆ pwm_lld_serve_interrupt()

static void pwm_lld_serve_interrupt ( PWMDriver pwmp)
static

Definition at line 84 of file hal_pwm_lld.c.

84 {
85 uint32_t sr;
86
87 sr = pwmp->ftm->SC;
88 pwmp->ftm->SC = sr&(~FTM_SC_TOFx);
89
90 if (((sr & FTM_SC_TOFx) != 0) && /* Timer Overflow */
91 ((sr & FTM_SC_TOIEx) != 0) &&
92 (pwmp->config->callback != NULL)) {
93 pwmp->config->callback(pwmp);
94 }
95
96 uint8_t n=0;
97 for(n=0;n<pwmp->channels;n++) {
98 sr = pwmp->ftm->CHANNEL[n].CnSC;
99 pwmp->ftm->CHANNEL[n].CnSC = sr&(~FTM_CnSC_CHFx);
100 if (((sr & FTM_CnSC_CHFx) != 0) &&
101 ((sr & FTM_CnSC_CHIEx) != 0) &&
102 (pwmp->config->channels[n].callback != NULL)) {
103 pwmp->config->channels[n].callback(pwmp);
104 }
105 }
106}
pwmcallback_t callback
Channel callback pointer.
pwmcallback_t callback
Periodic callback pointer.

Referenced by OSAL_IRQ_HANDLER(), OSAL_IRQ_HANDLER(), OSAL_IRQ_HANDLER(), and OSAL_IRQ_HANDLER().

Here is the caller graph for this function:

◆ pwm_lld_start()

void pwm_lld_start ( PWMDriver pwmp)

Configures and activates the PWM peripheral.

Note
Starting a driver that is already in the PWM_READY state disables all the active channels.
Parameters
[in]pwmppointer to a PWMDriver object

@notapi

Definition at line 212 of file hal_pwm_lld.c.

212 {
213 uint16_t psc;
214 uint8_t i=0;
215
216 if (pwmp->state == PWM_STOP) {
217 /* Clock activation and timer reset.*/
218#if KINETIS_PWM_USE_FTM0
219 if (&PWMD1 == pwmp) {
220#ifdef KE1xF
222#else
223 SIM->SCGC6 |= SIM_SCGC6_FTM0;
224#endif
225 nvicEnableVector(FTM0_IRQn, KINETIS_PWM_FTM0_PRIORITY);
226 }
227#endif
228
229#if KINETIS_PWM_USE_FTM1
230 if (&PWMD2 == pwmp) {
231#ifdef KE1xF
233#else
234 SIM->SCGC6 |= SIM_SCGC6_FTM1;
235#endif
236 nvicEnableVector(FTM1_IRQn, KINETIS_PWM_FTM1_PRIORITY);
237 }
238#endif
239
240#if KINETIS_PWM_USE_FTM2
241 if (&PWMD3 == pwmp) {
242#ifdef KE1xF
244#else
245 SIM->SCGC3 |= SIM_SCGC3_FTM2;
246#endif
247 nvicEnableVector(FTM2_IRQn, KINETIS_PWM_FTM2_PRIORITY);
248 }
249#endif
250
251#if KINETIS_PWM_USE_FTM3
252 if (&PWMD4 == pwmp) {
253#ifdef KE1xF
255#else
256 SIM->SCGC3 |= SIM_SCGC3_FTM3;
257#endif
258 nvicEnableVector(FTM3_IRQn, KINETIS_PWM_FTM3_PRIORITY);
259 }
260#endif
261 }
262 pwmp->ftm->MODE = FTM_MODE_FTMEN_MASK|FTM_MODE_PWMSYNC_MASK;
263 pwmp->ftm->SYNC = FTM_SYNC_CNTMIN_MASK|FTM_SYNC_CNTMAX_MASK
264 |FTM_SYNC_SWSYNC_MASK;
265 pwmp->ftm->COMBINE = FTM_COMBINE_SYNCEN3_MASK | FTM_COMBINE_SYNCEN2_MASK
266 | FTM_COMBINE_SYNCEN1_MASK | FTM_COMBINE_SYNCEN0_MASK;
267 pwmp->ftm->SYNCONF = FTM_SYNCONF_SYNCMODE_MASK;
268
269 pwmp->ftm->CNTIN = 0x0000;
270 //~ pwmp->ftm->SC = 0; /* Disable FTM counter.*/
271 pwmp->ftm->CNT = 0x0000; /* Clear count register.*/
272
273 /* Prescaler value calculation.*/
274 psc = (KINETIS_FTM_FREQUENCY / pwmp->config->frequency);
275 //~ /* Prescaler must be power of two between 1 and 128.*/
276 osalDbgAssert(psc <= 128 && !(psc & (psc - 1)), "invalid frequency");
277 //~ /* Prescaler register value determination.
278 //~ Prescaler register value conveniently corresponds to bit position,
279 //~ i.e., register value for prescaler CLK/64 is 6 ((1 << 6) == 64).*/
280 for (i = 0; i < 8; i++) {
281 if (psc == (unsigned)(1 << i)) {
282 break;
283 }
284 }
285
286 /* Set prescaler and clock mode.
287 This also sets the following:
288 CPWMS up-counting mode
289 Timer overflow interrupt disabled
290 DMA disabled.*/
291 pwmp->ftm->SC = FTM_SC_CLKS(1) | FTM_SC_PS(i);
292 /* Configure period */
293 pwmp->ftm->MOD = pwmp->period-1;
294 pwmp->ftm->PWMLOAD = FTM_PWMLOAD_LDOK_MASK;
295}
static void CLOCK_EnableClock(clock_ip_name_t name)
Enable the clock for specific IP.
Definition fsl_clock.h:641
@ kCLOCK_Ftm3
Definition fsl_clock.h:277
@ kCLOCK_Ftm1
Definition fsl_clock.h:287
@ kCLOCK_Ftm2
Definition fsl_clock.h:288
@ kCLOCK_Ftm0
Definition fsl_clock.h:286
uint32_t frequency
Timer clock in Hz.
pwmcnt_t period
Current PWM period in ticks.
pwmstate_t state
Driver state.
Here is the call graph for this function:

◆ pwm_lld_stop()

void pwm_lld_stop ( PWMDriver pwmp)

Deactivates the PWM peripheral.

Parameters
[in]pwmppointer to a PWMDriver object

@notapi

Definition at line 304 of file hal_pwm_lld.c.

304 {
305
306 /* If in ready state then disables the PWM clock.*/
307 if (pwmp->state == PWM_READY) {
308#if KINETIS_PWM_USE_FTM0
309 if (&PWMD1 == pwmp) {
310#ifdef KE1xF
311 PCC->CLKCFG[PCC_FLEXTMR0_INDEX] &= ~PCC_CLKCFG_CGC(1);
312#else
313 SIM->SCGC6 &= ~SIM_SCGC6_FTM0;
314#endif
315 nvicDisableVector(FTM0_IRQn);
316 }
317#endif
318
319#if KINETIS_PWM_USE_FTM1
320 if (&PWMD2 == pwmp) {
321#ifdef KE1xF
322 PCC->CLKCFG[PCC_FLEXTMR1_INDEX] &= ~PCC_CLKCFG_CGC(1);
323#else
324 SIM->SCGC6 &= ~SIM_SCGC6_FTM1;
325#endif
326 nvicDisableVector(FTM1_IRQn);
327 }
328#endif
329
330#if KINETIS_PWM_USE_FTM2
331 if (&PWMD3 == pwmp) {
332#ifdef KE1xF
333 PCC->CLKCFG[PCC_FLEXTMR2_INDEX] &= ~PCC_CLKCFG_CGC(1);
334#else
335 SIM->SCGC3 &= ~SIM_SCGC3_FTM2;
336#endif
337 nvicDisableVector(FTM2_IRQn);
338 }
339#endif
340
341#if KINETIS_PWM_USE_FTM3
342 if (&PWMD4 == pwmp) {
343#ifdef KE1xF
344 PCC->CLKCFG[PCC_FLEXTMR3_INDEX] &= ~PCC_CLKCFG_CGC(1);
345#else
346 SIM->SCGC3 &= ~SIM_SCGC3_FTM3;
347#endif
348 nvicDisableVector(FTM3_IRQn);
349 }
350#endif
351 /* Disable FTM counter.*/
352 pwmp->ftm->SC = 0;
353 pwmp->ftm->MOD = 0;
354 }
355}

Variable Documentation

◆ PWMD1

PWMDriver PWMD1

PWMD1 driver identifier.

Note
The driver PWMD1 allocates the timer FTM0 when enabled.

Definition at line 49 of file hal_pwm_lld.c.

Referenced by getConfigForPin(), initWS2812(), OSAL_IRQ_HANDLER(), pwm_lld_init(), pwm_lld_start(), and pwm_lld_stop().

◆ PWMD2

PWMDriver PWMD2

PWMD2 driver identifier.

Note
The driver PWMD2 allocates the timer FTM1 when enabled.

Definition at line 57 of file hal_pwm_lld.c.

Referenced by getConfigForPin(), OSAL_IRQ_HANDLER(), pwm_lld_init(), pwm_lld_start(), and pwm_lld_stop().

◆ PWMD3

PWMDriver PWMD3

PWMD3 driver identifier.

Note
The driver PWMD3 allocates the timer FTM2 when enabled.

Definition at line 65 of file hal_pwm_lld.c.

Referenced by getConfigForPin(), OSAL_IRQ_HANDLER(), pwm_lld_init(), pwm_lld_start(), and pwm_lld_stop().

◆ PWMD4

PWMDriver PWMD4

PWMD4 driver identifier.

Note
The driver PWMD4 allocates the timer FTM3 when enabled.

Definition at line 73 of file hal_pwm_lld.c.

Referenced by getConfigForPin(), OSAL_IRQ_HANDLER(), pwm_lld_init(), pwm_lld_start(), and pwm_lld_stop().