TI-RTOS Drivers  tidrivers_full_2_20_00_08
PWM.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
139 #ifndef ti_drivers_PWM__include
140 #define ti_drivers_PWM__include
141 
142 #ifdef __cplusplus
143 extern "C" {
144 #endif
145 
146 #include <stdint.h>
147 
152 #define PWM_DUTY_FRACTION_MAX ((uint32_t) ~0)
153 
165 #define PWM_CMD_RESERVED (32)
166 
179 #define PWM_STATUS_RESERVED (-32)
180 
188 #define PWM_STATUS_SUCCESS (0)
189 
196 #define PWM_STATUS_ERROR (-1)
197 
205 #define PWM_STATUS_UNDEFINEDCMD (-2)
206 
213 #define PWM_STATUS_INVALID_PERIOD (-3)
214 
221 #define PWM_STATUS_INVALID_DUTY (-4)
222 
227 typedef enum PWM_Period_Units {
228  PWM_PERIOD_US, /* Period in microseconds */
229  PWM_PERIOD_HZ, /* Period in Hertz (for example 2MHz = 0.5us period) */
230  PWM_PERIOD_COUNTS /* Period in timer counts */
232 
237 typedef enum PWM_Duty_Units {
238  PWM_DUTY_US, /* Duty cycle in microseconds */
239  PWM_DUTY_FRACTION, /* Duty as a fractional part of PWM_DUTY_FRACTION_MAX */
240  PWM_DUTY_COUNTS /* Duty in timer counts */
242 
246 typedef enum PWM_IdleLevel {
249 } PWM_IdleLevel;
250 
259 typedef struct PWM_Params {
261  uint32_t periodValue;
263  uint32_t dutyValue;
265  uintptr_t custom;
267 } PWM_Params;
268 
272 typedef struct PWM_Config *PWM_Handle;
273 
278 typedef void (*PWM_CloseFxn) (PWM_Handle handle);
279 
284 typedef int (*PWM_ControlFxn) (PWM_Handle handle,
285  unsigned int cmd,
286  void *arg);
291 typedef void (*PWM_InitFxn) (PWM_Handle handle);
292 
297 typedef PWM_Handle (*PWM_OpenFxn) (PWM_Handle handle,
298  PWM_Params *params);
299 
304 typedef int (*PWM_SetDutyFxn) (PWM_Handle handle,
305  uint32_t dutyValue);
306 
311 typedef int (*PWM_SetPeriodFxn) (PWM_Handle handle,
312  uint32_t periodValue);
313 
318 typedef void (*PWM_StartFxn) (PWM_Handle handle);
319 
324 typedef void (*PWM_StopFxn) (PWM_Handle handle);
325 
331 typedef struct PWM_FxnTable {
348 } PWM_FxnTable;
349 
357 typedef struct PWM_Config {
361  void *object;
363  void const *hwAttrs;
364 } PWM_Config;
365 
378 extern void PWM_close(PWM_Handle handle);
379 
399 extern int PWM_control(PWM_Handle handle, unsigned int cmd, void *arg);
400 
409 extern void PWM_init(void);
410 
427 extern PWM_Handle PWM_open(unsigned int index, PWM_Params *params);
428 
441 extern void PWM_Params_init(PWM_Params *params);
442 
463 extern int PWM_setDuty(PWM_Handle handle, uint32_t duty);
464 
484 extern int PWM_setPeriod(PWM_Handle handle, uint32_t period);
485 
496 extern void PWM_start(PWM_Handle handle);
497 
509 extern void PWM_stop(PWM_Handle handle);
510 
511 #ifdef __cplusplus
512 }
513 #endif
514 #endif /* ti_drivers_PWM__include */
PWM_Duty_Units dutyUnits
Definition: PWM.h:262
int PWM_setPeriod(PWM_Handle handle, uint32_t period)
Function to set the period of the specified PWM handle. This API can be called while the PWM is runni...
void PWM_close(PWM_Handle handle)
Function to close a PWM instance specified by the PWM handle.
PWM Global configuration.
Definition: PWM.h:357
PWM_OpenFxn openFxn
Definition: PWM.h:339
PWM_SetDutyFxn setDutyFxn
Definition: PWM.h:341
PWM_FxnTable const * fxnTablePtr
Definition: PWM.h:359
PWM_Duty_Units
PWM duty cycle unit definitions. Refer to device specific implementation if using PWM_DUTY_COUNTS (ra...
Definition: PWM.h:237
PWM_Handle PWM_open(unsigned int index, PWM_Params *params)
This function opens a given PWM instance and sets the period, duty and idle level to those specified ...
uintptr_t custom
Definition: PWM.h:265
int PWM_setDuty(PWM_Handle handle, uint32_t duty)
Function to set the duty cycle of the specified PWM handle. PWM instances run in active high output m...
uint32_t dutyValue
Definition: PWM.h:263
struct PWM_Config PWM_Config
PWM Global configuration.
PWM_CloseFxn closeFxn
Definition: PWM.h:333
void * object
Definition: PWM.h:361
void PWM_init(void)
This function initializes the PWM module.
Definition: PWM.h:240
PWM_Period_Units
PWM period unit definitions. Refer to device specific implementation if using PWM_PERIOD_COUNTS (raw ...
Definition: PWM.h:227
struct PWM_Params PWM_Params
PWM Parameters.
void(* PWM_CloseFxn)(PWM_Handle handle)
A function pointer to a driver specific implementation of PWM_close().
Definition: PWM.h:278
int PWM_control(PWM_Handle handle, unsigned int cmd, void *arg)
Function performs implementation specific features on a given PWM_Handle.
void(* PWM_StopFxn)(PWM_Handle handle)
A function pointer to a driver specific implementation of PWM_stop().
Definition: PWM.h:324
The definition of a PWM function table that contains the required set of functions to control a speci...
Definition: PWM.h:331
int(* PWM_SetPeriodFxn)(PWM_Handle handle, uint32_t periodValue)
A function pointer to a driver specific implementation of PWM_setPeriod().
Definition: PWM.h:311
struct PWM_Config * PWM_Handle
A handle that is returned from a PWM_open() call.
Definition: PWM.h:272
PWM_SetPeriodFxn setPeriodFxn
Definition: PWM.h:343
PWM_StopFxn stopFxn
Definition: PWM.h:347
void const * hwAttrs
Definition: PWM.h:363
Definition: PWM.h:230
Definition: PWM.h:248
void(* PWM_StartFxn)(PWM_Handle handle)
A function pointer to a driver specific implementation of PWM_start().
Definition: PWM.h:318
struct PWM_FxnTable PWM_FxnTable
The definition of a PWM function table that contains the required set of functions to control a speci...
void PWM_Params_init(PWM_Params *params)
Function to initialize the PWM_Params structure to default values.
PWM_Handle(* PWM_OpenFxn)(PWM_Handle handle, PWM_Params *params)
A function pointer to a driver specific implementation of PWM_open().
Definition: PWM.h:297
PWM Parameters.
Definition: PWM.h:259
PWM_Period_Units periodUnits
Definition: PWM.h:260
void(* PWM_InitFxn)(PWM_Handle handle)
A function pointer to a driver specific implementation of PWM_init().
Definition: PWM.h:291
int(* PWM_SetDutyFxn)(PWM_Handle handle, uint32_t dutyValue)
A function pointer to a driver specific implementation of PWM_setDuty().
Definition: PWM.h:304
Definition: PWM.h:228
int(* PWM_ControlFxn)(PWM_Handle handle, unsigned int cmd, void *arg)
A function pointer to a driver specific implementation of PWM_control().
Definition: PWM.h:284
PWM_ControlFxn controlFxn
Definition: PWM.h:335
Definition: PWM.h:238
Definition: PWM.h:239
uint32_t periodValue
Definition: PWM.h:261
Definition: PWM.h:247
PWM_IdleLevel
Idle output level when PWM is not running (stopped / not started).
Definition: PWM.h:246
PWM_InitFxn initFxn
Definition: PWM.h:337
PWM_StartFxn startFxn
Definition: PWM.h:345
void PWM_stop(PWM_Handle handle)
Function to stop the specified PWM handle. Output will set to the idle level specified by params in P...
Definition: PWM.h:229
void PWM_start(PWM_Handle handle)
Function to start the specified PWM handle with current settings.
PWM_IdleLevel idleLevel
Definition: PWM.h:264
Copyright 2016, Texas Instruments Incorporated