no-OS
no_os_pwm.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef _NO_OS_PWM_H_
34 #define _NO_OS_PWM_H_
35 
36 /******************************************************************************/
37 /***************************** Include Files **********************************/
38 /******************************************************************************/
39 #include <stdint.h>
40 #include <stdbool.h>
41 
42 /******************************************************************************/
43 /********************** Macros and Constants Definitions **********************/
44 /******************************************************************************/
45 
46 #define PWM_MAX_NUMBER 4
47 
48 /******************************************************************************/
49 /*************************** Types Declarations *******************************/
50 /******************************************************************************/
60 };
61 
68  uint32_t id;
70  uint32_t period_ns;
72  uint32_t duty_cycle_ns;
74  uint32_t phase_ns;
79  /* IRQ ID */
80  uint32_t irq_id;
82  void (*pwm_callback)(void *arg);
86  void *extra;
87 };
88 
95  void *mutex;
97  uint32_t id;
99  uint32_t period_ns;
101  uint32_t duty_cycle_ns;
103  uint32_t phase_ns;
107  bool enabled;
110  /* IRQ ID */
111  uint32_t irq_id;
113  void (*pwm_callback)(void* arg);
117  void *extra;
118 };
119 
127  int32_t (*pwm_ops_init)(struct no_os_pwm_desc **,
128  const struct no_os_pwm_init_param *);
130  int32_t (*pwm_ops_enable)(struct no_os_pwm_desc *);
132  int32_t (*pwm_ops_disable)(struct no_os_pwm_desc *);
134  int32_t (*pwm_ops_set_period)(struct no_os_pwm_desc *, uint32_t);
136  int32_t (*pwm_ops_get_period)(struct no_os_pwm_desc *, uint32_t *);
138  int32_t (*pwm_ops_set_duty_cycle)(struct no_os_pwm_desc *, uint32_t);
140  int32_t (*pwm_ops_get_duty_cycle)(struct no_os_pwm_desc *, uint32_t *);
142  int32_t (*pwm_ops_set_phase)(struct no_os_pwm_desc *, uint32_t);
144  int32_t (*pwm_ops_get_phase)(struct no_os_pwm_desc *, uint32_t *);
147  enum no_os_pwm_polarity);
150  enum no_os_pwm_polarity *);
152  int32_t(*pwm_ops_remove)(struct no_os_pwm_desc *);
153 };
154 
155 /******************************************************************************/
156 /************************ Functions Declarations ******************************/
157 /******************************************************************************/
158 /* Initialize the PWM generator device */
159 int32_t no_os_pwm_init(struct no_os_pwm_desc **desc,
160  const struct no_os_pwm_init_param *param);
161 
162 /* Free the resources used by the PWM generator device */
163 int32_t no_os_pwm_remove(struct no_os_pwm_desc *desc);
164 
165 /* Enable PWM generator device */
166 int32_t no_os_pwm_enable(struct no_os_pwm_desc *desc);
167 
168 /* Disable PWM generator device */
169 int32_t no_os_pwm_disable(struct no_os_pwm_desc *desc);
170 
171 /* Set period of PWM generator device */
172 int32_t no_os_pwm_set_period(struct no_os_pwm_desc *desc,
173  uint32_t period_ns);
174 
175 /* Get period of PWM generator device */
176 int32_t no_os_pwm_get_period(struct no_os_pwm_desc *desc,
177  uint32_t *period_ns);
178 
179 /* Set duty cycle of PWM generator device */
180 int32_t no_os_pwm_set_duty_cycle(struct no_os_pwm_desc *desc,
181  uint32_t duty_cycle_ns);
182 
183 /* Get period of PWM generator device */
184 int32_t no_os_pwm_get_duty_cycle(struct no_os_pwm_desc *desc,
185  uint32_t *duty_cycle_ns);
186 
187 /* Set the phase of PWM generator channel */
188 int32_t no_os_pwm_set_phase(struct no_os_pwm_desc *desc,
189  uint32_t phase_ns);
190 
191 /* Get the phase of PWM generator channel */
192 int32_t no_os_pwm_get_phase(struct no_os_pwm_desc *desc,
193  uint32_t *phase_ns);
194 
195 /* Set polarity of PWM generator device */
196 int32_t no_os_pwm_set_polarity(struct no_os_pwm_desc *desc,
198 
199 /* Set polarity of PWM generator device */
200 int32_t no_os_pwm_get_polarity(struct no_os_pwm_desc *desc,
202 
203 #endif // _NO_OS_PWM_H_
no_os_pwm_desc::mutex
void * mutex
Definition: no_os_pwm.h:95
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
no_os_pwm_desc::duty_cycle_ns
uint32_t duty_cycle_ns
Definition: no_os_pwm.h:101
no_os_pwm_init_param
Structure containing the init parameters needed by the PWM generator.
Definition: no_os_pwm.h:66
no_os_pwm_platform_ops::pwm_ops_get_period
int32_t(* pwm_ops_get_period)(struct no_os_pwm_desc *, uint32_t *)
Definition: no_os_pwm.h:136
no_os_pwm_remove
int32_t no_os_pwm_remove(struct no_os_pwm_desc *desc)
Free the resources allocated by no_os_pwm_init().
Definition: no_os_pwm.c:79
no_os_pwm_desc::id
uint32_t id
Definition: no_os_pwm.h:97
no_os_pwm_platform_ops::pwm_ops_set_phase
int32_t(* pwm_ops_set_phase)(struct no_os_pwm_desc *, uint32_t)
Definition: no_os_pwm.h:142
no_os_pwm_platform_ops::pwm_ops_get_polarity
int32_t(* pwm_ops_get_polarity)(struct no_os_pwm_desc *, enum no_os_pwm_polarity *)
Definition: no_os_pwm.h:149
no_os_pwm_init_param::period_ns
uint32_t period_ns
Definition: no_os_pwm.h:70
no_os_pwm_set_polarity
int32_t no_os_pwm_set_polarity(struct no_os_pwm_desc *desc, enum no_os_pwm_polarity polarity)
Set the PWM polarity.
Definition: no_os_pwm.c:243
no_os_pwm_desc::phase_ns
uint32_t phase_ns
Definition: no_os_pwm.h:103
no_os_pwm_init_param::id
uint32_t id
Definition: no_os_pwm.h:68
no_os_pwm_polarity
no_os_pwm_polarity
Possible polarities of the PWM signal.
Definition: no_os_pwm.h:55
no_os_pwm_platform_ops::pwm_ops_get_phase
int32_t(* pwm_ops_get_phase)(struct no_os_pwm_desc *, uint32_t *)
Definition: no_os_pwm.h:144
no_os_pwm_set_period
int32_t no_os_pwm_set_period(struct no_os_pwm_desc *desc, uint32_t period_ns)
Set the PWM period value.
Definition: no_os_pwm.c:133
no_os_pwm_desc::period_ns
uint32_t period_ns
Definition: no_os_pwm.h:99
no_os_pwm_platform_ops::pwm_ops_remove
int32_t(* pwm_ops_remove)(struct no_os_pwm_desc *)
Definition: no_os_pwm.h:152
no_os_pwm_get_phase
int32_t no_os_pwm_get_phase(struct no_os_pwm_desc *desc, uint32_t *phase_ns)
Get the PWM phase value.
Definition: no_os_pwm.c:223
no_os_pwm_platform_ops::pwm_ops_get_duty_cycle
int32_t(* pwm_ops_get_duty_cycle)(struct no_os_pwm_desc *, uint32_t *)
Definition: no_os_pwm.h:140
no_os_pwm_get_period
int32_t no_os_pwm_get_period(struct no_os_pwm_desc *desc, uint32_t *period_ns)
Get the PWM period value.
Definition: no_os_pwm.c:151
no_os_pwm_desc::pwm_gpio
struct no_os_gpio_desc * pwm_gpio
Definition: no_os_pwm.h:109
no_os_pwm_enable
int32_t no_os_pwm_enable(struct no_os_pwm_desc *desc)
Enable PWM signal generation.
Definition: no_os_pwm.c:98
no_os_pwm_init_param::irq_id
uint32_t irq_id
Definition: no_os_pwm.h:80
no_os_pwm_init_param::polarity
enum no_os_pwm_polarity polarity
Definition: no_os_pwm.h:76
no_os_pwm_disable
int32_t no_os_pwm_disable(struct no_os_pwm_desc *desc)
Disable PWM signal generation.
Definition: no_os_pwm.c:115
no_os_pwm_set_phase
int32_t no_os_pwm_set_phase(struct no_os_pwm_desc *desc, uint32_t phase_ns)
Set the PWM phase value.
Definition: no_os_pwm.c:205
no_os_pwm_platform_ops::pwm_ops_init
int32_t(* pwm_ops_init)(struct no_os_pwm_desc **, const struct no_os_pwm_init_param *)
Definition: no_os_pwm.h:127
no_os_pwm_platform_ops::pwm_ops_set_polarity
int32_t(* pwm_ops_set_polarity)(struct no_os_pwm_desc *, enum no_os_pwm_polarity)
Definition: no_os_pwm.h:146
no_os_pwm_desc::polarity
enum no_os_pwm_polarity polarity
Definition: no_os_pwm.h:105
no_os_pwm_desc::irq_id
uint32_t irq_id
Definition: no_os_pwm.h:111
no_os_pwm_platform_ops::pwm_ops_set_period
int32_t(* pwm_ops_set_period)(struct no_os_pwm_desc *, uint32_t)
Definition: no_os_pwm.h:134
no_os_pwm_desc::enabled
bool enabled
Definition: no_os_pwm.h:107
no_os_pwm_init_param::extra
void * extra
Definition: no_os_pwm.h:86
no_os_pwm_get_polarity
int32_t no_os_pwm_get_polarity(struct no_os_pwm_desc *desc, enum no_os_pwm_polarity *polarity)
Get the PWM polarity.
Definition: no_os_pwm.c:263
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
NO_OS_PWM_POLARITY_HIGH
@ NO_OS_PWM_POLARITY_HIGH
Definition: no_os_pwm.h:57
no_os_pwm_init_param::pwm_callback
void(* pwm_callback)(void *arg)
Definition: no_os_pwm.h:82
no_os_pwm_set_duty_cycle
int32_t no_os_pwm_set_duty_cycle(struct no_os_pwm_desc *desc, uint32_t duty_cycle_ns)
Set the PWM duty cycle.
Definition: no_os_pwm.c:169
no_os_pwm_desc
Structure representing an PWM generator device.
Definition: no_os_pwm.h:93
no_os_pwm_init_param::duty_cycle_ns
uint32_t duty_cycle_ns
Definition: no_os_pwm.h:72
no_os_pwm_init
int32_t no_os_pwm_init(struct no_os_pwm_desc **desc, const struct no_os_pwm_init_param *param)
Initialize the PWM peripheral.
Definition: no_os_pwm.c:51
no_os_pwm_platform_ops
Structure holding PWM function pointers that point to the platform specific function.
Definition: no_os_pwm.h:125
no_os_pwm_desc::extra
void * extra
Definition: no_os_pwm.h:117
no_os_pwm_desc::pwm_callback
void(* pwm_callback)(void *arg)
Definition: no_os_pwm.h:113
no_os_pwm_init_param::pwm_gpio
struct no_os_gpio_init_param * pwm_gpio
Definition: no_os_pwm.h:78
no_os_pwm_platform_ops::pwm_ops_enable
int32_t(* pwm_ops_enable)(struct no_os_pwm_desc *)
Definition: no_os_pwm.h:130
no_os_pwm_platform_ops::pwm_ops_disable
int32_t(* pwm_ops_disable)(struct no_os_pwm_desc *)
Definition: no_os_pwm.h:132
no_os_pwm_platform_ops::pwm_ops_set_duty_cycle
int32_t(* pwm_ops_set_duty_cycle)(struct no_os_pwm_desc *, uint32_t)
Definition: no_os_pwm.h:138
no_os_pwm_get_duty_cycle
int32_t no_os_pwm_get_duty_cycle(struct no_os_pwm_desc *desc, uint32_t *duty_cycle_ns)
Get the PWM duty cycle.
Definition: no_os_pwm.c:187
no_os_pwm_init_param::phase_ns
uint32_t phase_ns
Definition: no_os_pwm.h:74
no_os_pwm_init_param::platform_ops
const struct no_os_pwm_platform_ops * platform_ops
Definition: no_os_pwm.h:84
NO_OS_PWM_POLARITY_LOW
@ NO_OS_PWM_POLARITY_LOW
Definition: no_os_pwm.h:59
no_os_pwm_desc::platform_ops
const struct no_os_pwm_platform_ops * platform_ops
Definition: no_os_pwm.h:115