VSF Documented
timer_to_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 __HAL_DRIVER_COMMON_PWM_TIMER_TO_PWM_H__
19#define __HAL_DRIVER_COMMON_PWM_TIMER_TO_PWM_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_PWM == ENABLED && VSF_HAL_USE_TIMER == ENABLED
26
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/*============================ MACROS ========================================*/
36
37/*
38 * Default MULTI_CLASS follows VSF_PWM_CFG_MULTI_CLASS.
39 * When ENABLED, vsf_hw_pwm_t inherits vsf_pwm_t so it can be accessed through
40 * the class dispatcher; when DISABLED, callers must use vsf_hw_pwm_* directly.
41 */
42#ifndef VSF_HW_PWM_CFG_MULTI_CLASS
43# define VSF_HW_PWM_CFG_MULTI_CLASS VSF_PWM_CFG_MULTI_CLASS
44#endif
45
46/*
47 * Capability defaults (Hz). Can be overridden by the hw driver before
48 * including timer_to_pwm.inc.
49 */
50#ifndef VSF_HW_PWM_CFG_CAPABILITY_MIN_FREQ
51# define VSF_HW_PWM_CFG_CAPABILITY_MIN_FREQ (1ul * 1000)
52#endif
53#ifndef VSF_HW_PWM_CFG_CAPABILITY_MAX_FREQ
54# define VSF_HW_PWM_CFG_CAPABILITY_MAX_FREQ (100ul * 1000 * 1000)
55#endif
56
57/*============================ TYPES =========================================*/
58
59/*
60 * Generic hw PWM instance that maps every call onto a vsf_timer_t.
61 *
62 * One vsf_hw_pwm_t corresponds to ONE underlying timer (i.e. one PWM
63 * controller). Per-channel operations are driven by the `channel` argument
64 * of vsf_pwm_set(); this struct does NOT bind itself to a single channel.
65 *
66 * .timer: pointer to the underlying timer class instance (cast from
67 * the concrete vsf_hw_timer_t* on init-time). Uses
68 * vsf_timer_t so the glue stays chip-agnostic and goes
69 * through the dispatcher.
70 * REQUIRES VSF_TIMER_CFG_MULTI_CLASS == ENABLED.
71 * .cfg: cached user config (for get_configuration).
72 * .period: period currently programmed on the timer (in timer ticks).
73 * 0 = not locked yet by any pwm_set(). Timer hardware has
74 * a single period register shared by all channels, so all
75 * active channels on this instance must share this value.
76 * .configured_mask: bitmask of channels that have been configured by a
77 * previous pwm_set(). Used by pwm_enable()/pwm_disable()
78 * to iterate, and by pwm_set() to detect frequency
79 * conflicts across channels.
80 * .enabled: latched state of pwm_enable()/pwm_disable(). A pwm_set()
81 * on a new channel will auto-start it when .enabled is true.
82 */
83typedef struct vsf_hw_pwm_t {
84#if VSF_HW_PWM_CFG_MULTI_CLASS == ENABLED
86#endif
91 bool enabled;
93
94/*============================ MACROFIED FUNCTIONS ===========================*/
95
96/*
97 * Default per-instance initializer used by timer_to_pwm.inc when the caller
98 * does not override VSF_PWM_CFG_IMP_LV0. Assumes "PWMx <-> TIMx" one-to-one
99 * mapping. Channel is not bound at compile time; it is supplied by the
100 * caller via vsf_pwm_set()'s channel argument. Override
101 * VSF_PWM_CFG_IMP_LV0 before including timer_to_pwm.inc if a different
102 * mapping is needed.
103 */
104#ifndef VSF_TIMER_TO_PWM_DEFAULT_TIMER
105# define VSF_TIMER_TO_PWM_DEFAULT_TIMER(__IDX) \
106 (vsf_timer_t *)&VSF_MCONNECT(vsf_hw_timer, __IDX)
107#endif
108
109#ifdef __cplusplus
110}
111#endif
112
113#endif /* VSF_HAL_USE_PWM && VSF_HAL_USE_TIMER */
114#endif /* __HAL_DRIVER_COMMON_PWM_TIMER_TO_PWM_H__ */
115/* EOF */
unsigned uint32_t
Definition stdint.h:9
Definition pwm.c:41
uint32_t configured_mask
Definition timer_to_pwm.h:90
vsf_pwm_cfg_t cfg
Definition timer_to_pwm.h:88
vsf_pwm_t vsf_pwm
Definition pwm.c:43
vsf_timer_t * timer
Definition timer_to_pwm.h:87
bool enabled
Definition timer_to_pwm.h:91
uint32_t period
Definition timer_to_pwm.h:89
PWM configuration structure. Used to configure the PWM generator's frequency settings.
Definition vsf_template_pwm.h:170
Definition vsf_template_pwm.h:274
Definition vsf_template_timer.h:780
Generated from commit: vsfteam/vsf@c3767bf