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
133#ifndef VSF_PWM_CFG_REIMPLEMENT_TYPE_CTRL
134# define VSF_PWM_CFG_REIMPLEMENT_TYPE_CTRL DISABLED
135#endif
136
137/*============================ MACROFIED FUNCTIONS ===========================*/
138
148#define VSF_PWM_APIS(__prefix_name) \
149 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, pwm, init, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr) \
150 __VSF_HAL_TEMPLATE_API(__prefix_name, void, pwm, fini, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
151 __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) \
152 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, pwm, enable, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
153 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, pwm, disable, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
154 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_pwm_capability_t, pwm, capability, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
155 __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)\
156 __VSF_HAL_TEMPLATE_API(__prefix_name, uint32_t, pwm, get_freq, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr) \
157 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, pwm, ctrl, VSF_MCONNECT(__prefix_name, _t) *pwm_ptr, vsf_pwm_ctrl_t ctrl, void* param)
158
159/*============================ TYPES =========================================*/
160
161#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
170typedef struct vsf_pwm_cfg_t {
171 union {
181
191 };
193#endif
194
195#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
204typedef struct vsf_pwm_capability_t {
205#if VSF_PWM_CFG_INHERIT_HAL_CAPABILITY == ENABLED
207#endif
208
217 uint32_t max_freq;
218
229#endif
230
231#if VSF_PWM_CFG_REIMPLEMENT_TYPE_CTRL == DISABLED
240typedef enum vsf_pwm_ctrl_t {
260#endif
261
262typedef struct vsf_pwm_t vsf_pwm_t;
263
264typedef struct vsf_pwm_op_t {
266#undef __VSF_HAL_TEMPLATE_API
267#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
269
270 VSF_PWM_APIS(vsf_pwm)
272
273#if VSF_PWM_CFG_MULTI_CLASS == ENABLED
274struct vsf_pwm_t {
276};
277#endif
278
279/*============================ PROTOTYPES ====================================*/
280
300extern vsf_err_t vsf_pwm_init(vsf_pwm_t *pwm_ptr, vsf_pwm_cfg_t *cfg_ptr);
301
313extern void vsf_pwm_fini(vsf_pwm_t *pwm_ptr);
314
335
347extern fsm_rt_t vsf_pwm_enable(vsf_pwm_t *pwm_ptr);
348
360extern fsm_rt_t vsf_pwm_disable(vsf_pwm_t *pwm_ptr);
361
374
392extern vsf_err_t vsf_pwm_set(vsf_pwm_t *pwm_ptr, uint8_t channel,
393 uint32_t period, uint32_t pulse);
394
406extern uint32_t vsf_pwm_get_freq(vsf_pwm_t *pwm_ptr);
407
423extern vsf_err_t vsf_pwm_ctrl(vsf_pwm_t *pwm_ptr, vsf_pwm_ctrl_t ctrl, void * param);
424
442extern vsf_err_t vsf_pwm_set_ms(vsf_pwm_t *pwm_ptr,
443 uint8_t channel,
444 uint32_t period,
445 uint32_t pulse);
446
464extern vsf_err_t vsf_pwm_set_us(vsf_pwm_t *pwm_ptr,
465 uint8_t channel,
466 uint32_t period,
467 uint32_t pulse);
468
486extern vsf_err_t vsf_pwm_set_ns(vsf_pwm_t *pwm_ptr,
487 uint8_t channel,
488 uint32_t period,
489 uint32_t pulse);
490
491/*============================ MACROFIED FUNCTIONS ===========================*/
492
494#if VSF_PWM_CFG_FUNCTION_RENAME == ENABLED
495# define __vsf_pwm_t VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_t)
496# define vsf_pwm_init(__PM, ...) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_init) ((__vsf_pwm_t *)(__PM), ##__VA_ARGS__)
497# define vsf_pwm_fini(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_fini) ((__vsf_pwm_t *)(__PM))
498# define vsf_pwm_get_configuration(__PM, ...) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_get_configuration) ((__vsf_pwm_t *)(__PM), ##__VA_ARGS__)
499# define vsf_pwm_enable(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_enable) ((__vsf_pwm_t *)(__PM))
500# define vsf_pwm_disable(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_disable) ((__vsf_pwm_t *)(__PM))
501# define vsf_pwm_capability(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_capability) ((__vsf_pwm_t *)(__PM))
502# define vsf_pwm_set(__PM, ...) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_set) ((__vsf_pwm_t *)(__PM), ##__VA_ARGS__)
503# define vsf_pwm_get_freq(__PM) VSF_MCONNECT(VSF_PWM_CFG_PREFIX, _pwm_get_freq) ((__vsf_pwm_t *)(__PM))
504#endif
506
507#ifdef __cplusplus
508}
509#endif
510
511#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:204
PWM capability structure. Describes the capabilities and limitations of the PWM hardware.
Definition vsf_template_pwm.h:204
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:227
PWM configuration structure. Used to configure the PWM generator's frequency settings.
Definition vsf_template_pwm.h:170
uint32_t freq
The PWM clock frequency in Hz. Determines the base time period for the PWM generator.
Definition vsf_template_pwm.h:180
uint32_t min_freq
The minimum allowed PWM clock frequency in Hz. Used when configuring adaptive frequency ranges.
Definition vsf_template_pwm.h:190
Definition vsf_template_pwm.h:264
Definition vsf_template_pwm.h:274
const vsf_pwm_op_t * op
Definition vsf_template_pwm.h:275
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:123
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:132
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:141
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
vsf_err_t vsf_pwm_ctrl(vsf_pwm_t *pwm_ptr, vsf_pwm_ctrl_t ctrl, void *param)
Calls the specified PWM command.
Definition pwm_common.c:111
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:148
vsf_pwm_ctrl_t
PWM control commands for hardware-specific operations.
Definition vsf_template_pwm.h:240
@ __VSF_PWM_CTRL_DUMMY
Dummy value for compilation, required when no actual control commands are defined.
Definition vsf_template_pwm.h:258
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@b2e9e8a