SimpleLink MCU SDK Driver APIs  tidrivers_msp43x_3_01_01_03
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  */
216 #ifndef ti_drivers_PWM__include
217 #define ti_drivers_PWM__include
218 
219 #ifdef __cplusplus
220 extern "C" {
221 #endif
222 
223 #include <stdint.h>
224 
229 #define PWM_DUTY_FRACTION_MAX ((uint32_t) ~0)
230 
242 #define PWM_CMD_RESERVED (32)
243 
256 #define PWM_STATUS_RESERVED (-32)
257 
265 #define PWM_STATUS_SUCCESS (0)
266 
273 #define PWM_STATUS_ERROR (-1)
274 
282 #define PWM_STATUS_UNDEFINEDCMD (-2)
283 
290 #define PWM_STATUS_INVALID_PERIOD (-3)
291 
298 #define PWM_STATUS_INVALID_DUTY (-4)
299 
304 typedef enum PWM_Period_Units_ {
305  PWM_PERIOD_US, /* Period in microseconds */
306  PWM_PERIOD_HZ, /* Period in (reciprocal) Hertz
307  (for example 2MHz = 0.5us period) */
308  PWM_PERIOD_COUNTS /* Period in timer counts */
310 
315 typedef enum PWM_Duty_Units_ {
316  PWM_DUTY_US, /* Duty cycle in microseconds */
317  PWM_DUTY_FRACTION, /* Duty as a fractional part of PWM_DUTY_FRACTION_MAX */
318  PWM_DUTY_COUNTS /* Duty in timer counts */
320 
324 typedef enum PWM_IdleLevel_ {
327 } PWM_IdleLevel;
328 
337 typedef struct PWM_Params_ {
339  uint32_t periodValue;
341  uint32_t dutyValue;
343  void *custom;
345 } PWM_Params;
346 
350 typedef struct PWM_Config_ *PWM_Handle;
351 
356 typedef void (*PWM_CloseFxn) (PWM_Handle handle);
357 
362 typedef int_fast16_t (*PWM_ControlFxn) (PWM_Handle handle, uint_fast16_t cmd,
363  void *arg);
368 typedef void (*PWM_InitFxn) (PWM_Handle handle);
369 
374 typedef PWM_Handle (*PWM_OpenFxn) (PWM_Handle handle, PWM_Params *params);
375 
380 typedef int_fast16_t (*PWM_SetDutyFxn) (PWM_Handle handle,
381  uint32_t duty);
382 
387 typedef int_fast16_t (*PWM_SetPeriodFxn) (PWM_Handle handle,
388  uint32_t period);
389 
394 typedef void (*PWM_StartFxn) (PWM_Handle handle);
395 
400 typedef void (*PWM_StopFxn) (PWM_Handle handle);
401 
407 typedef struct PWM_FxnTable_ {
424 } PWM_FxnTable;
425 
433 typedef struct PWM_Config_ {
437  void *object;
439  void const *hwAttrs;
440 } PWM_Config;
441 
454 extern void PWM_close(PWM_Handle handle);
455 
475 extern int_fast16_t PWM_control(PWM_Handle handle, uint_fast16_t cmd,
476  void *arg);
477 
486 extern void PWM_init(void);
487 
504 extern PWM_Handle PWM_open(uint_least8_t index, PWM_Params *params);
505 
518 extern void PWM_Params_init(PWM_Params *params);
519 
540 extern int_fast16_t PWM_setDuty(PWM_Handle handle, uint32_t duty);
541 
561 extern int_fast16_t PWM_setPeriod(PWM_Handle handle, uint32_t period);
562 
573 extern void PWM_start(PWM_Handle handle);
574 
586 extern void PWM_stop(PWM_Handle handle);
587 
588 #ifdef __cplusplus
589 }
590 #endif
591 #endif /* ti_drivers_PWM__include */
struct PWM_Params_ PWM_Params
PWM Parameters.
PWM_InitFxn initFxn
Definition: PWM.h:413
Definition: PWM.h:318
int_fast16_t PWM_control(PWM_Handle handle, uint_fast16_t cmd, void *arg)
Function performs implementation specific features on a given PWM_Handle.
uint32_t dutyValue
Definition: PWM.h:341
void PWM_close(PWM_Handle handle)
Function to close a PWM instance specified by the PWM handle.
struct PWM_Config_ * PWM_Handle
A handle that is returned from a PWM_open() call.
Definition: PWM.h:350
PWM_Duty_Units dutyUnits
Definition: PWM.h:340
PWM_IdleLevel_
Idle output level when PWM is not running (stopped / not started).
Definition: PWM.h:324
PWM_Handle PWM_open(uint_least8_t index, PWM_Params *params)
This function opens a given PWM instance and sets the period, duty and idle level to those specified ...
uint32_t periodValue
Definition: PWM.h:339
PWM_SetDutyFxn setDutyFxn
Definition: PWM.h:417
PWM_Duty_Units_
PWM duty cycle unit definitions. Refer to device specific implementation if using PWM_DUTY_COUNTS (ra...
Definition: PWM.h:315
PWM Global configuration.
Definition: PWM.h:433
PWM_Period_Units_
PWM period unit definitions. Refer to device specific implementation if using PWM_PERIOD_COUNTS (raw ...
Definition: PWM.h:304
Definition: PWM.h:317
Definition: PWM.h:326
void PWM_init(void)
This function initializes the PWM module.
Definition: PWM.h:316
Definition: PWM.h:305
The definition of a PWM function table that contains the required set of functions to control a speci...
Definition: PWM.h:407
int_fast16_t(* PWM_ControlFxn)(PWM_Handle handle, uint_fast16_t cmd, void *arg)
A function pointer to a driver specific implementation of PWM_control().
Definition: PWM.h:362
void(* PWM_CloseFxn)(PWM_Handle handle)
A function pointer to a driver specific implementation of PWM_close().
Definition: PWM.h:356
PWM_Period_Units periodUnits
Definition: PWM.h:338
PWM_StartFxn startFxn
Definition: PWM.h:421
void(* PWM_StopFxn)(PWM_Handle handle)
A function pointer to a driver specific implementation of PWM_stop().
Definition: PWM.h:400
Definition: PWM.h:306
PWM_IdleLevel idleLevel
Definition: PWM.h:342
int_fast16_t(* PWM_SetDutyFxn)(PWM_Handle handle, uint32_t duty)
A function pointer to a driver specific implementation of PWM_setDuty().
Definition: PWM.h:380
PWM Parameters.
Definition: PWM.h:337
enum PWM_Period_Units_ PWM_Period_Units
PWM period unit definitions. Refer to device specific implementation if using PWM_PERIOD_COUNTS (raw ...
void * object
Definition: PWM.h:437
void const * hwAttrs
Definition: PWM.h:439
PWM_StopFxn stopFxn
Definition: PWM.h:423
void(* PWM_StartFxn)(PWM_Handle handle)
A function pointer to a driver specific implementation of PWM_start().
Definition: PWM.h:394
PWM_FxnTable const * fxnTablePtr
Definition: PWM.h:435
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:374
PWM_ControlFxn controlFxn
Definition: PWM.h:411
Definition: PWM.h:325
Definition: PWM.h:308
int_fast16_t 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...
void(* PWM_InitFxn)(PWM_Handle handle)
A function pointer to a driver specific implementation of PWM_init().
Definition: PWM.h:368
struct PWM_Config_ PWM_Config
PWM Global configuration.
enum PWM_IdleLevel_ PWM_IdleLevel
Idle output level when PWM is not running (stopped / not started).
PWM_SetPeriodFxn setPeriodFxn
Definition: PWM.h:419
int_fast16_t 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...
int_fast16_t(* PWM_SetPeriodFxn)(PWM_Handle handle, uint32_t period)
A function pointer to a driver specific implementation of PWM_setPeriod().
Definition: PWM.h:387
void * custom
Definition: PWM.h:343
PWM_CloseFxn closeFxn
Definition: PWM.h:409
struct PWM_FxnTable_ PWM_FxnTable
The definition of a PWM function table that contains the required set of functions to control a speci...
PWM_OpenFxn openFxn
Definition: PWM.h:415
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...
void PWM_start(PWM_Handle handle)
Function to start the specified PWM handle with current settings.
enum PWM_Duty_Units_ PWM_Duty_Units
PWM duty cycle unit definitions. Refer to device specific implementation if using PWM_DUTY_COUNTS (ra...
Copyright 2016, Texas Instruments Incorporated