TI-RTOS Drivers
tidrivers_tivac_2_16_01_13
|
PWM driver interface.
============================================================================
The PWM header file should be included in an application as follows:
The PWM driver in TI-RTOS facilitates the generation of Pulse Width Modulated signals via simple and portable APIs. A device's PWM peripheral pins must be configured before initializing the PWM driver. The application initializes the PWM driver by calling PWM_init(). PWM instances must be opened by calling PWM_open() while passing in a PWM index and a parameters data structure.
The driver APIs serve as an interface to a typical TI-RTOS application. The specific peripheral implementations are responsible of creating all SYS/BIOS specific primitives to allow for thread-safe operation.
When a PWM instance is opened, the period, units of the duty, and polarity can be set. The maximum period supported is device dependent; refer to the implementation specific documentation for values. A PWM instance can be configured to interpret the duty as one of three units: PWM_DUTY_COUNTS: The duty is in PWM timer ticks. PWM_DUTY_SCALAR: The duty is an integer scaled to the period where 0 corresponds to a duty of 0% and 65535 corresponds to 100% duty. PWM_DUTY_TIME: The duty is specified in microseconds. The driver calculates the appropriate amount of PWM timer ticks.
The polarity is used to set the output during the active duty portion of the period; it can be set to produce low output or a high output when active.
By default PWM output is set to a duty of 0. It is the applications responsability to set the duty for each PWM output used.
This module serves as the main interface for TI-RTOS applications. Its purpose is to redirect the module APIs to specific peripheral implementations specified by a pointer to a PWM_FxnTable.
The PWM driver interface module is joined (at link time) to a NULL-terminated array of PWM_Config data structures named PWM_config. PWM_config is implemented in the application with each entry being an instance of a PWM peripheral. Each entry in PWM_config contains a:
Function | Hwi | Swi | Task | Main |
---|---|---|---|---|
PWM_Params_init | Y | Y | Y | Y |
PWM_close | Y | Y | Y | Y |
PWM_control | Y | Y | Y | Y |
PWM_getPeriodCounts | Y | Y | Y | Y |
PWM_getPeriodMicroSecs | Y | Y | Y | Y |
PWM_init | Y | Y | Y | Y |
PWM_open | Y | Y | Y | Y |
PWM_setDuty | Y | Y | Y | Y |
|
The PWM driver interface produces log statements if instrumentation is enabled.
Diagnostics Mask | Log details |
---|---|
Diags_USER1 | basic operations performed |
Diags_USER2 | detailed operations performed |
#include <stdint.h>
#include <stddef.h>
Go to the source code of this file.
Data Structures | |
struct | PWM_Params |
PWM Parameters. More... | |
struct | PWM_FxnTable |
The definition of a PWM function table that contains the required set of functions to control a specific PWM driver implementation. More... | |
struct | PWM_Config |
PWM Global configuration. More... | |
Macros | |
#define | PWM_CMD_RESERVED 32 |
#define | PWM_STATUS_RESERVED -32 |
#define | PWM_STATUS_SUCCESS 0 |
Successful status code returned by PWM_control(). More... | |
#define | PWM_STATUS_ERROR -1 |
Generic error status code returned by PWM_control(). More... | |
#define | PWM_STATUS_UNDEFINEDCMD -2 |
An error status code returned by PWM_control() for undefined command codes. More... | |
Typedefs | |
typedef struct PWM_Config * | PWM_Handle |
A handle that is returned from a PWM_open() call. More... | |
typedef enum PWM_DutyMode | PWM_DutyMode |
Definitions for various units for specifying the PWM duty. More... | |
typedef enum PWM_Polarity | PWM_Polarity |
Definitions for various PWM output polarity. More... | |
typedef struct PWM_Params | PWM_Params |
PWM Parameters. More... | |
typedef void(* | PWM_CloseFxn) (PWM_Handle handle) |
A function pointer to a driver specific implementation of PWM_close(). More... | |
typedef int(* | PWM_ControlFxn) (PWM_Handle handle, unsigned int cmd, void *arg) |
A function pointer to a driver specific implementation of PWM_control(). More... | |
typedef unsigned int(* | PWM_GetPeriodCountsFxn) (PWM_Handle handle) |
A function pointer to a driver specific implementation of PWM_getPeriodCounts(). More... | |
typedef unsigned int(* | PWM_GetPeriodMicroSecsFxn) (PWM_Handle handle) |
A function pointer to a driver specific implementation of PWM_getPeriodMicroSecs(). More... | |
typedef void(* | PWM_InitFxn) (PWM_Handle handle) |
A function pointer to a driver specific implementation of PWM_init(). More... | |
typedef PWM_Handle(* | PWM_OpenFxn) (PWM_Handle handle, PWM_Params *params) |
A function pointer to a driver specific implementation of PWM_open(). More... | |
typedef void(* | PWM_SetDutyFxn) (PWM_Handle handle, uint32_t duty) |
A function pointer to a driver specific implementation of PWM_setDuty(). More... | |
typedef struct PWM_FxnTable | PWM_FxnTable |
The definition of a PWM function table that contains the required set of functions to control a specific PWM driver implementation. More... | |
typedef struct PWM_Config | PWM_Config |
PWM Global configuration. More... | |
Enumerations | |
enum | PWM_DutyMode { PWM_DUTY_COUNTS = 0, PWM_DUTY_SCALAR, PWM_DUTY_TIME } |
Definitions for various units for specifying the PWM duty. More... | |
enum | PWM_Polarity { PWM_POL_ACTIVE_HIGH = 0, PWM_POL_ACTIVE_LOW = 1 } |
Definitions for various PWM output polarity. More... | |
Functions | |
void | PWM_close (PWM_Handle handle) |
Function to close a PWM peripheral specified by the PWM handle. More... | |
int | PWM_control (PWM_Handle handle, unsigned int cmd, void *arg) |
Function performs implementation specific features on a given PWM_Handle. More... | |
unsigned int | PWM_getPeriodCounts (PWM_Handle handle) |
Get the PWM handle period in timer counts. More... | |
unsigned int | PWM_getPeriodMicroSecs (PWM_Handle handle) |
Get the PWM handle period in microseconds. More... | |
void | PWM_init (void) |
This function initializes the PWM module. More... | |
PWM_Handle | PWM_open (unsigned int index, PWM_Params *params) |
This function opens a given PWM peripheral. More... | |
void | PWM_Params_init (PWM_Params *params) |
Function to initialize the PWM_Params struct to its defaults. More... | |
void | PWM_setDuty (PWM_Handle handle, uint32_t duty) |
Function to set the duty cycle of the specified PWM handle. More... | |
typedef struct PWM_Config* PWM_Handle |
A handle that is returned from a PWM_open() call.
typedef enum PWM_DutyMode PWM_DutyMode |
Definitions for various units for specifying the PWM duty.
typedef enum PWM_Polarity PWM_Polarity |
Definitions for various PWM output polarity.
typedef struct PWM_Params PWM_Params |
PWM Parameters.
PWM Parameters are used to with the PWM_open() call. Default values for these parameters are set using PWM_Params_init().
typedef void(* PWM_CloseFxn) (PWM_Handle handle) |
A function pointer to a driver specific implementation of PWM_close().
typedef int(* PWM_ControlFxn) (PWM_Handle handle, unsigned int cmd, void *arg) |
A function pointer to a driver specific implementation of PWM_control().
typedef unsigned int(* PWM_GetPeriodCountsFxn) (PWM_Handle handle) |
A function pointer to a driver specific implementation of PWM_getPeriodCounts().
typedef unsigned int(* PWM_GetPeriodMicroSecsFxn) (PWM_Handle handle) |
A function pointer to a driver specific implementation of PWM_getPeriodMicroSecs().
typedef void(* PWM_InitFxn) (PWM_Handle handle) |
A function pointer to a driver specific implementation of PWM_init().
typedef PWM_Handle(* PWM_OpenFxn) (PWM_Handle handle, PWM_Params *params) |
A function pointer to a driver specific implementation of PWM_open().
typedef void(* PWM_SetDutyFxn) (PWM_Handle handle, uint32_t duty) |
A function pointer to a driver specific implementation of PWM_setDuty().
typedef struct PWM_FxnTable PWM_FxnTable |
The definition of a PWM function table that contains the required set of functions to control a specific PWM driver implementation.
typedef struct PWM_Config PWM_Config |
PWM Global configuration.
The PWM_Config structure contains a set of pointers used to characterize the PWM driver implementation.
This structure needs to be defined before calling PWM_init() and it must not be changed thereafter.
enum PWM_DutyMode |
enum PWM_Polarity |
void PWM_close | ( | PWM_Handle | handle | ) |
Function to close a PWM peripheral specified by the PWM handle.
handle | A PWM handle returned from PWM_open() |
int PWM_control | ( | PWM_Handle | handle, |
unsigned int | cmd, | ||
void * | arg | ||
) |
Function performs implementation specific features on a given PWM_Handle.
Commands for PWM_control can originate from PWM.h or from implementation specific PWM*.h (PWMCC32XX.h, PWMTiva.h, etc.. ) files. While commands from PWM.h are API portable across driver implementations, not all implementations may support all these commands. Conversely, commands from driver implementation specific PWM*.h files add unique driver capabilities but are not API portable across all PWM driver implementations.
Commands supported by PWM.h follow a PWM_CMD_<cmd> naming convention.
Commands supported by PWM*.h follow a PWM*_CMD_<cmd> naming convention.
Each control command defines arg differently. The types of arg are documented with each command.
See PWM_control command codes for command codes.
See PWM_control return status codes for status codes.
handle | A PWM handle returned from PWM_open() |
cmd | PWM.h or PWM*.h commands. |
arg | An optional R/W (read/write) command argument accompanied with cmd |
unsigned int PWM_getPeriodCounts | ( | PWM_Handle | handle | ) |
Get the PWM handle period in timer counts.
handle | A PWM_Handle |
unsigned int PWM_getPeriodMicroSecs | ( | PWM_Handle | handle | ) |
Get the PWM handle period in microseconds.
handle | A PWM_Handle |
void PWM_init | ( | void | ) |
This function initializes the PWM module.
PWM_Handle PWM_open | ( | unsigned int | index, |
PWM_Params * | params | ||
) |
This function opens a given PWM peripheral.
index | Logical peripheral number for the PWM indexed into the PWM_config table |
params | Pointer to an parameter block, if NULL it will use default values. All the fields in this structure are RO (read-only). |
void PWM_Params_init | ( | PWM_Params * | params | ) |
Function to initialize the PWM_Params struct to its defaults.
params | An pointer to PWM_Params structure for initialization |
Defaults values are: period = 10000 (microseconds) dutyMode = PWM_DUTY_TIME polarity = PWM_POL_ACTIVE_HIGH
void PWM_setDuty | ( | PWM_Handle | handle, |
uint32_t | duty | ||
) |
Function to set the duty cycle of the specified PWM handle.
handle | A PWM_Handle |
duty | PWM duty cycle. |