Capture.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019, 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  */
32 /*!*****************************************************************************
33  * @file Capture.h
34  * @brief Capture Driver
35  *
36  * @anchor ti_drivers_Capture_Overview
37  * # Overview
38  *
39  * The capture driver is used to detect and time edge triggered events on a
40  * GPIO pin.
41  *
42  * The capture driver serves as the main interface for a typical RTOS
43  * application. Its purpose is to redirect the capture APIs to device specific
44  * implementations which are specified using a pointer to a #Capture_FxnTable.
45  * The device specific implementations are responsible for creating all the
46  * RTOS specific primitives to allow for thead-safe operation. The capture
47  * driver utilizes the general purpose timer hardware.
48  *
49  * The capture driver internally handles the general purpose timer resource
50  * allocation. For each capture driver instance, Capture_open() occupies the
51  * specified timer, and Capture_close() releases the occupied timer resource.
52  *
53  * <hr>
54  * @anchor ti_drivers_Capture_Usage
55  * # Usage
56  *
57  * This documentation provides a basic @ref ti_drivers_Capture_Synopsis
58  * "usage summary" and a set of @ref ti_drivers_Capture_Examples "examples"
59  * in the form of commented code fragments. Detailed descriptions of the
60  * APIs are provided in subsequent sections.
61  *
62  * @anchor ti_drivers_Capture_Synopsis
63  * ## Synopsis
64  * @anchor ti_drivers_Capture_Synopsis_Code
65  * @code
66  * // Import Capture Driver definitions
67  * #include <ti/drivers/Capture.h>
68  *
69  * Capture_Handle handle;
70  * Capture_Params params;
71  *
72  * Capture_Params_init(&params);
73  * params.mode = Capture_FALLING_EDGE;
74  * params.callbackFxn = someCaptureCallbackFunction;
75  * params.periodUnit = Capture_PERIOD_US;
76  *
77  * handle = Capture_open(CONFIG_CAPTURE0, &params);
78  *
79  * if (handle == NULL) {
80  * //Capture_open() failed
81  * while(1);
82  * }
83  *
84  * status = Capture_start(handle);
85  *
86  * if (status == Capture_STATUS_ERROR) {
87  * //Capture_start() failed
88  * while(1);
89  * }
90  *
91  * sleep(10000);
92  *
93  * Capture_stop(handle);
94  * @endcode
95  *
96  * <hr>
97  * @anchor ti_drivers_Capture_Examples
98  * # Examples
99  *
100  * @li @ref ti_drivers_Capture_Examples_open "Opening a Capture instance"
101  *
102  * @anchor ti_drivers_Capture_Examples_open
103  * ## Opening a Capture instance
104  *
105  * @code
106  * Capture_Handle handle;
107  * Capture_Params params;
108  *
109  * Capture_Params_init(&params);
110  * params.mode = Capture_FALLING_EDGE;
111  * params.callbackFxn = someCaptureCallbackFunction;
112  * params.periodUnit = Capture_PERIOD_US;
113  *
114  * handle = Capture_open(CONFIG_CAPTURE0, &params);
115  *
116  * if (handle == NULL) {
117  * //Capture_open() failed
118  * while(1);
119  * }
120  * @endcode
121  *
122  * <hr>
123  * @anchor ti_drivers_Capture_Configuration
124  * # Configuration
125  *
126  * Refer to the @ref driver_configuration "Driver's Configuration" section
127  * for driver configuration information.
128  * <hr>
129  *******************************************************************************
130  */
131 
132 #ifndef ti_drivers_Capture__include
133 #define ti_drivers_Capture__include
134 
135 #include <stdint.h>
136 
137 #ifdef __cplusplus
138 extern "C"
139 {
140 #endif
141 
153 #define Capture_CMD_RESERVED (32)
154 
166 #define Capture_STATUS_RESERVED (-32)
167 
171 #define Capture_STATUS_SUCCESS (0)
172 
176 #define Capture_STATUS_ERROR (-1)
177 
185 #define Capture_STATUS_UNDEFINEDCMD (-2)
186 
191 
192 
202 typedef enum {
213 } Capture_Mode;
214 
221 typedef enum {
229 
230 
243 typedef void (*Capture_CallBackFxn)(Capture_Handle handle, uint32_t interval);
244 
252 typedef struct {
254  Capture_Mode mode;
255 
258 
260  Capture_PeriodUnits periodUnit;
262 
267 typedef void (*Capture_CloseFxn)(Capture_Handle handle);
268 
273 typedef int_fast16_t (*Capture_ControlFxn)(Capture_Handle handle,
274  uint_fast16_t cmd, void *arg);
275 
280 typedef void (*Capture_InitFxn)(Capture_Handle handle);
281 
286 typedef Capture_Handle (*Capture_OpenFxn)(Capture_Handle handle,
287  Capture_Params *params);
288 
293 typedef int32_t (*Capture_StartFxn)(Capture_Handle handle);
294 
299 typedef void (*Capture_StopFxn)(Capture_Handle handle);
300 
306 typedef struct {
309 
312 
315 
318 
321 
325 
337 typedef struct Capture_Config_ {
341 
343  void *object;
344 
346  void const *hwAttrs;
348 
359 extern void Capture_close(Capture_Handle handle);
360 
380 extern int_fast16_t Capture_control(Capture_Handle handle, uint_fast16_t cmd,
381  void *arg);
382 
394 extern void Capture_init(void);
395 
416 extern Capture_Handle Capture_open(uint_least8_t index, Capture_Params *params);
417 
429 extern void Capture_Params_init(Capture_Params *params);
430 
444 extern int32_t Capture_start(Capture_Handle handle);
445 
456 extern void Capture_stop(Capture_Handle handle);
457 
458 #ifdef __cplusplus
459 }
460 #endif
461 
462 #endif /* ti_drivers_Capture__include */
Definition: Capture.h:210
Definition: Capture.h:227
void Capture_stop(Capture_Handle handle)
Function to stop a capture instance. If the capture instance is already stopped, this function has no...
Capture_Mode
Capture mode settings.
Definition: Capture.h:202
Capture Global configuration.
Definition: Capture.h:337
Capture_StopFxn stopFxn
Definition: Capture.h:323
Capture_Handle(* Capture_OpenFxn)(Capture_Handle handle, Capture_Params *params)
A function pointer to a driver specific implementation of Capture_open().
Definition: Capture.h:286
void(* Capture_CloseFxn)(Capture_Handle handle)
A function pointer to a driver specific implementation of Capture_close().
Definition: Capture.h:267
Definition: Capture.h:207
Capture_Handle Capture_open(uint_least8_t index, Capture_Params *params)
Function to open a given capture instance specified by the index argument. The Capture_Params specifi...
struct Capture_Config_ Capture_Config
Capture Global configuration.
int32_t Capture_start(Capture_Handle handle)
Function to start the capture instance.
void Capture_init(void)
Function to initialize the capture driver. This function will go through all available hardware resou...
void * object
Definition: Capture.h:343
Capture_OpenFxn openFxn
Definition: Capture.h:317
void Capture_Params_init(Capture_Params *params)
Function to initialize the Capture_Params struct to its defaults.
Capture_CallBackFxn callbackFxn
Definition: Capture.h:257
Capture_PeriodUnits
Capture period unit enum.
Definition: Capture.h:221
Definition: Capture.h:203
void const * hwAttrs
Definition: Capture.h:346
int_fast16_t Capture_control(Capture_Handle handle, uint_fast16_t cmd, void *arg)
Function performs implementation specific features on a given Capture_Handle.
Definition: Capture.h:222
struct Capture_Config_ * Capture_Handle
A handle that is returned from a Capture_open() call.
Definition: Capture.h:190
Definition: Capture.h:223
Definition: Capture.h:205
void(* Capture_InitFxn)(Capture_Handle handle)
A function pointer to a driver specific implementation of Capture_init().
Definition: Capture.h:280
Definition: Capture.h:204
Capture_Mode mode
Definition: Capture.h:254
int_fast16_t(* Capture_ControlFxn)(Capture_Handle handle, uint_fast16_t cmd, void *arg)
A function pointer to a driver specific implementation of Capture_control().
Definition: Capture.h:273
void(* Capture_CallBackFxn)(Capture_Handle handle, uint32_t interval)
Capture callback function.
Definition: Capture.h:243
Capture_PeriodUnits periodUnit
Definition: Capture.h:260
Capture_FxnTable const * fxnTablePtr
Definition: Capture.h:340
Capture_StartFxn startFxn
Definition: Capture.h:320
void(* Capture_StopFxn)(Capture_Handle handle)
A function pointer to a driver specific implementation of Capture_stop().
Definition: Capture.h:299
The definition of a capture function table that contains the required set of functions to control a s...
Definition: Capture.h:306
Capture_CloseFxn closeFxn
Definition: Capture.h:308
Capture_ControlFxn controlFxn
Definition: Capture.h:311
Capture_InitFxn initFxn
Definition: Capture.h:314
int32_t(* Capture_StartFxn)(Capture_Handle handle)
A function pointer to a driver specific implementation of Capture_start().
Definition: Capture.h:293
Definition: Capture.h:225
Capture Parameters.
Definition: Capture.h:252
void Capture_close(Capture_Handle handle)
Function to close a capture driver instance. The corresponding timer peripheral to Capture_handle bec...
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale