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#ifndef VSF_PWM_CFG_REIMPLEMENT_TYPE_CFG
96# define VSF_PWM_CFG_REIMPLEMENT_TYPE_CFG DISABLED
97#endif
98
106#ifndef VSF_PWM_CFG_REIMPLEMENT_TYPE_CAPABILITY
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, _t) *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr) \
136 __VSF_HAL_TEMPLATE_API(__prefix_name, void, pwm, fini, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
137 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, pwm, get_configuration, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr) \
138 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, pwm, enable, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
139 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, pwm, disable, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
140 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_pwm_capability_t, pwm, capability, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
141 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, pwm, set, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr, uint8_t channel, uint32_t period, uint32_t pulse)\
142 __VSF_HAL_TEMPLATE_API(__prefix_name, uint32_t, pwm, get_freq, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr)
143
144/*============================ TYPES =========================================*/
145
146#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
155typedef struct vsf_pwm_cfg_t {
156 union {
166
176 };
178#endif
179
180#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
189typedef struct vsf_pwm_capability_t {
190#if VSF_PWM_CFG_INHERIT_HAL_CAPABILITY == ENABLED
192#endif
193
202 uint32_t max_freq;
203
214#endif
215
216typedef struct vsf_pwm_t vsf_pwm_t;
217
218typedef struct vsf_pwm_op_t {
220#undef __VSF_HAL_TEMPLATE_API
221#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
223
224 VSF_PWM_APIS(vsf_pwm)
226
227#if VSF_PWM_CFG_MULTI_CLASS == ENABLED
228struct vsf_pwm_t {
230};
231#endif
232
233/*============================ PROTOTYPES ====================================*/
234
254extern vsf_err_t vsf_pwm_init(vsf_pwm_t *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr);
255
267extern void vsf_pwm_fini(vsf_pwm_t *pwm_ptr);
268
289
301extern fsm_rt_t vsf_pwm_enable(vsf_pwm_t *pwm_ptr);
302
314extern fsm_rt_t vsf_pwm_disable(vsf_pwm_t *pwm_ptr);
315
328
346extern vsf_err_t vsf_pwm_set(vsf_pwm_t *pwm_ptr, uint8_t channel,
347 uint32_t period, uint32_t pulse);
348
360extern uint32_t vsf_pwm_get_freq(vsf_pwm_t *pwm_ptr);
361
379extern vsf_err_t vsf_pwm_set_ms(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_us(vsf_pwm_t *pwm_ptr,
402 uint8_t channel,
403 uint32_t period,
404 uint32_t pulse);
405
423extern vsf_err_t vsf_pwm_set_ns(vsf_pwm_t *pwm_ptr,
424 uint8_t channel,
425 uint32_t period,
426 uint32_t pulse);
427
428/*============================ MACROFIED FUNCTIONS ===========================*/
429
431#if VSF_PWM_CFG_FUNCTION_RENAME == ENABLED
432# define __vsf_pwm_t VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_t)
433# define vsf_pwm_init(__PM, ...) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_init) ((__vsf_pwm_t *)(__PM), ##__VA_ARGS__)
434# define vsf_pwm_fini(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_fini) ((__vsf_pwm_t *)(__PM))
435# define vsf_pwm_get_configuration(__PM, ...) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_get_configuration) ((__vsf_pwm_t *)(__PM), ##__VA_ARGS__)
436# define vsf_pwm_enable(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_enable) ((__vsf_pwm_t *)(__PM))
437# define vsf_pwm_disable(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_disable) ((__vsf_pwm_t *)(__PM))
438# define vsf_pwm_capability(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_capability) ((__vsf_pwm_t *)(__PM))
439# define vsf_pwm_set(__PM, ...) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_set) ((__vsf_pwm_t *)(__PM), ##__VA_ARGS__)
440# define vsf_pwm_get_freq(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_get_freq) ((__vsf_pwm_t *)(__PM))
441#endif
443
444#ifdef __cplusplus
445}
446#endif
447
448#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:189
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:212
PWM configuration structure. Used to configure the PWM generator's frequency settings.
Definition vsf_template_pwm.h:155
uint32_t freq
The PWM clock frequency in Hz. Determines the base time period for the PWM generator.
Definition vsf_template_pwm.h:165
uint32_t min_freq
The minimum allowed PWM clock frequency in Hz. Used when configuring adaptive frequency ranges.
Definition vsf_template_pwm.h:175
Definition vsf_template_pwm.h:218
Definition vsf_template_pwm.h:228
const vsf_pwm_op_t * op
Definition vsf_template_pwm.h:229
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:114
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:123
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:132
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
vsf_err_t vsf_pwm_get_configuration(vsf_pwm_t *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr)
Get the current configuration of a PWM instance.
Definition pwm_common.c:101
#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@74aa6ce