VSF Documented
vsf_template_pwm.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_TEMPLATE_PWM_H__
19#define __VSF_TEMPLATE_PWM_H__
20
21/*============================ INCLUDES ======================================*/
22
24#include "hal/arch/vsf_arch.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*============================ MACROS ========================================*/
31
38#ifndef VSF_PWM_CFG_MULTI_CLASS
39# define VSF_PWM_CFG_MULTI_CLASS ENABLED
40#endif
41
48#if defined(VSF_HW_PWM_COUNT) && !defined(VSF_HW_PWM_MASK)
49# define VSF_HW_PWM_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_PWM_COUNT)
50#endif
51
58#if defined(VSF_HW_PWM_MASK) && !defined(VSF_HW_PWM_COUNT)
59# define VSF_HW_PWM_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_PWM_MASK)
60#endif
61
70#ifndef VSF_PWM_CFG_PREFIX
71# if VSF_PWM_CFG_MULTI_CLASS == ENABLED
72# define VSF_PWM_CFG_PREFIX vsf
73# elif defined(VSF_HW_PWM_COUNT) && (VSF_HW_PWM_COUNT != 0)
74# define VSF_PWM_CFG_PREFIX vsf_hw
75# else
76# define VSF_PWM_CFG_PREFIX vsf
77# endif
78#endif
79
80#ifndef VSF_PWM_CFG_FUNCTION_RENAME
81# define VSF_PWM_CFG_FUNCTION_RENAME ENABLED
82#endif
83
95#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
96# define VSF_PWM_CFG_REIMPLEMENT_TYPE_CFG DISABLED
97#endif
98
106#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
107# define VSF_PWM_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
108#endif
109
119#ifndef VSF_PWM_CFG_INHERIT_HAL_CAPABILITY
120# define VSF_PWM_CFG_INHERIT_HAL_CAPABILITY ENABLED
121#endif
122
123/*============================ MACROFIED FUNCTIONS ===========================*/
124
134#define VSF_PWM_APIS(__prefix_name) \
135 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, pwm, init, VSF_MCONNECT(__prefix_name, _pwm_t) *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr) \
136 __VSF_HAL_TEMPLATE_API(__prefix_name, void, pwm, fini, VSF_MCONNECT(__prefix_name, _pwm_t) *pwm_ptr) \
137 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, pwm, enable, VSF_MCONNECT(__prefix_name, _pwm_t) *pwm_ptr) \
138 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, pwm, disable, VSF_MCONNECT(__prefix_name, _pwm_t) *pwm_ptr) \
139 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_pwm_capability_t, pwm, capability, VSF_MCONNECT(__prefix_name, _pwm_t) *pwm_ptr) \
140 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, pwm, set, VSF_MCONNECT(__prefix_name, _pwm_t) *pwm_ptr, uint8_t channel, uint32_t period, uint32_t pulse)\
141 __VSF_HAL_TEMPLATE_API(__prefix_name, uint32_t, pwm, get_freq, VSF_MCONNECT(__prefix_name, _pwm_t) *pwm_ptr)
142
143/*============================ TYPES =========================================*/
144
145#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
154typedef struct vsf_pwm_cfg_t {
155 union {
165
175 };
177#endif
178
179#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
188typedef struct vsf_pwm_capability_t {
189#if VSF_PWM_CFG_INHERIT_HAL_CAPABILITY == ENABLED
191#endif
192
201 uint32_t max_freq;
202
213#endif
214
215typedef struct vsf_pwm_t vsf_pwm_t;
216
217typedef struct vsf_pwm_op_t {
219#undef __VSF_HAL_TEMPLATE_API
220#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
222
223 VSF_PWM_APIS(vsf)
225
226#if VSF_PWM_CFG_MULTI_CLASS == ENABLED
227struct vsf_pwm_t {
229};
230#endif
231
232/*============================ PROTOTYPES ====================================*/
233
253extern vsf_err_t vsf_pwm_init(vsf_pwm_t *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr);
254
266extern void vsf_pwm_fini(vsf_pwm_t *pwm_ptr);
267
279extern fsm_rt_t vsf_pwm_enable(vsf_pwm_t *pwm_ptr);
280
292extern fsm_rt_t vsf_pwm_disable(vsf_pwm_t *pwm_ptr);
293
306
324extern vsf_err_t vsf_pwm_set(vsf_pwm_t *pwm_ptr, uint8_t channel,
325 uint32_t period, uint32_t pulse);
326
338extern uint32_t vsf_pwm_get_freq(vsf_pwm_t *pwm_ptr);
339
357extern vsf_err_t vsf_pwm_set_ms(vsf_pwm_t *pwm_ptr,
358 uint8_t channel,
359 uint32_t period,
360 uint32_t pulse);
361
379extern vsf_err_t vsf_pwm_set_us(vsf_pwm_t *pwm_ptr,
380 uint8_t channel,
381 uint32_t period,
382 uint32_t pulse);
383
401extern vsf_err_t vsf_pwm_set_ns(vsf_pwm_t *pwm_ptr,
402 uint8_t channel,
403 uint32_t period,
404 uint32_t pulse);
405
406/*============================ MACROFIED FUNCTIONS ===========================*/
407
409#if VSF_PWM_CFG_FUNCTION_RENAME == ENABLED
410# define __vsf_pwm_t VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_t)
411# define vsf_pwm_init(__PM, ...) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_init) ((__vsf_pwm_t *)(__PM), ##__VA_ARGS__)
412# define vsf_pwm_fini(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_fini) ((__vsf_pwm_t *)(__PM))
413# define vsf_pwm_enable(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_enable) ((__vsf_pwm_t *)(__PM))
414# define vsf_pwm_disable(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_disable) ((__vsf_pwm_t *)(__PM))
415# define vsf_pwm_capability(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_capability) ((__vsf_pwm_t *)(__PM))
416# define vsf_pwm_set(__PM, ...) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_set) ((__vsf_pwm_t *)(__PM), ##__VA_ARGS__)
417# define vsf_pwm_get_freq(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_get_freq) ((__vsf_pwm_t *)(__PM))
418#endif
420
421#ifdef __cplusplus
422}
423#endif
424
425#endif /*__VSF_TEMPLATE_PWM_H__ */
vsf_err_t
Definition __type.h:42
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_template_hal_driver.h:203
PWM capability structure. Describes the capabilities and limitations of the PWM hardware.
Definition vsf_template_pwm.h:188
inherit(vsf_peripheral_capability_t) uint32_t max_freq
Maximum supported PWM frequency in Hz. The upper limit of the PWM generator's frequency range.
uint32_t min_freq
Minimum supported PWM frequency in Hz. The lower limit of the PWM generator's frequency range.
Definition vsf_template_pwm.h:211
PWM configuration structure. Used to configure the PWM generator's frequency settings.
Definition vsf_template_pwm.h:154
uint32_t freq
The PWM clock frequency in Hz. Determines the base time period for the PWM generator.
Definition vsf_template_pwm.h:164
uint32_t min_freq
The minimum allowed PWM clock frequency in Hz. Used when configuring adaptive frequency ranges.
Definition vsf_template_pwm.h:174
Definition vsf_template_pwm.h:217
Definition vsf_template_pwm.h:227
const vsf_pwm_op_t * op
Definition vsf_template_pwm.h:228
fsm_rt_t
Definition vsf_fsm.h:315
vsf_err_t vsf_pwm_init(vsf_pwm_t *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr)
Initialize a PWM instance.
Definition pwm_common.c:38
vsf_err_t vsf_pwm_set_ns(vsf_pwm_t *pwm_ptr, uint8_t channel, uint32_t period, uint32_t pulse)
Set PWM period in nanoseconds.
Definition pwm_common.c:104
vsf_err_t vsf_pwm_set_us(vsf_pwm_t *pwm_ptr, uint8_t channel, uint32_t period, uint32_t pulse)
Set PWM period in microseconds.
Definition pwm_common.c:113
struct vsf_pwm_capability_t vsf_pwm_capability_t
PWM capability structure. Describes the capabilities and limitations of the PWM hardware.
vsf_err_t vsf_pwm_set(vsf_pwm_t *pwm_ptr, uint8_t channel, uint32_t period, uint32_t pulse)
PWM set the period width and pulse width for a channel.
Definition pwm_common.c:83
vsf_err_t vsf_pwm_set_ms(vsf_pwm_t *pwm_ptr, uint8_t channel, uint32_t period, uint32_t pulse)
Set PWM period in milliseconds.
Definition pwm_common.c:122
struct vsf_pwm_cfg_t vsf_pwm_cfg_t
PWM configuration structure. Used to configure the PWM generator's frequency settings.
fsm_rt_t vsf_pwm_disable(vsf_pwm_t *pwm_ptr)
Disable a PWM instance.
Definition pwm_common.c:65
void vsf_pwm_fini(vsf_pwm_t *pwm_ptr)
Finalize a PWM instance.
Definition pwm_common.c:47
uint32_t vsf_pwm_get_freq(vsf_pwm_t *pwm_ptr)
PWM get clock frequency.
Definition pwm_common.c:92
fsm_rt_t vsf_pwm_enable(vsf_pwm_t *pwm_ptr)
Enable PWM instance.
Definition pwm_common.c:56
#define VSF_PWM_APIS(__prefix_name)
PWM API template, used to generate PWM type, specific prefix function declarations,...
Definition vsf_template_pwm.h:134
vsf_pwm_capability_t vsf_pwm_capability(vsf_pwm_t *pwm_ptr)
Get the capability of PWM instance.
Definition pwm_common.c:74
Generated from commit: vsfteam/vsf@2b286be