2 * Copyright (c) 2016, Texas Instruments Incorporated
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
32 /** ============================================================================
35 * @brief Capture driver interface
37 * The Capture header file should be included in an application as follows:
39 * #include <ti/drivers/Capture.h>
43 * The Capture driver facilitates the capture routines by using general purpose
44 * timers. Capture instances must be opened by calling Capture_open() while
45 * passing in a Capture index and parameters data structure.
47 * When a capture instance is opened, the capture triggering edge and callback
48 * function are configured. The capture is stopped after calling Capture_open()
49 * until Capture_start() is called.
51 * When Capture_open() is called, it tries to occupy the user-specified timer by
52 * calling Timer_open(). If that timer is already allocated for other modules,
53 * NULL is returned. Otherwise, the Capture_Handle is returned.
55 * A capture is triggered based on the user-specified capture mode:
56 * - CAPTURE_MODE_RISING_RISING
57 * - CAPTURE_MODE_RISING_FALLING
58 * - CAPTURE_MODE_ANY_EDGE
59 * The user-specified callback function is called once the input signal matches
60 * the capture mode and the value passed into callback function is the interval
61 * between two triggering edge in the user-specified unit.
63 * ## opening the driver ##
66 * Capture_Handle handle;
67 * Capture_Params params;
69 * Capture_Params_init(¶ms);
70 * params.mode = CAPTURE_MODE_RISING_FALLING;
71 * params.callbackFxn = someCaptureCallbackFunction;
72 * params.periodUnit = CAPTURE_PERIOD_US;
73 * handle = Capture_open(someCapture_configIndexValue, ¶ms);
76 * System_printf("Capture did not open");
79 * ## starting the driver ##
82 * status = Capture_start(handle);
83 * if (status == Capture_STATUS_ERROR)
85 * System_printf("Capture cannot start");
89 * ## stoping the driver ##
92 * Capture_stop(handle);
95 * ## closing the driver ##
98 * Capture_close(handle);
103 * This module serves as the main interface for TI-RTOS
104 * applications. Its purpose is to redirect the module's APIs to specific
105 * peripheral implementations which are specified using a pointer to a
108 * The Capture driver interface module is joined (at link time) to a
109 * NULL-terminated array of Capture_Config data structures named *Capture_Config*.
110 * *Capture_Config* is implemented in the application with each entry being an
111 * instance of a Capture module. Each entry in *Capture_Config* contains a:
112 * - (Capture_FxnTable *) to a set of functions that implement a Capture module
113 * - (void *) data object that is associated with the Capture_FxnTable
114 * - (void *) hardware attributes that are associated to the Capture_FxnTable
116 * # Instrumentation #
117 * The Capture driver interface produces log statements if instrumentation is
120 * Diagnostics Mask | Log details |
121 * ---------------- | ----------- |
122 * Diags_USER1 | basic operations performed |
123 * Diags_USER2 | detailed operations performed |
125 * ============================================================================
127 #ifndef ti_drivers_Capture__include
128 #define ti_drivers_Capture__include
139 * @brief A handle that is returned from a Capture_open() call.
141 typedef struct Capture_Config_ *Capture_Handle;
144 * Common Capture_control command code reservation offset.
145 * Capture driver implementations should offset command codes with CAPTURE_CMD_RESERVED
148 * Example implementation specific command codes:
150 * #define CAPTUREXYZ_CMD_COMMAND0 CAPTURE_CMD_RESERVED + 0
151 * #define CAPTUREXYZ_CMD_COMMAND1 CAPTURE_CMD_RESERVED + 1
154 #define CAPTURE_CMD_RESERVED (32)
157 * Common Capture_control status code reservation offset.
158 * Capture driver implementations should offset status codes with
159 * CAPTURE_STATUS_RESERVED growing negatively.
161 * Example implementation specific status codes:
163 * #define CAPTUREXYZ_STATUS_ERROR0 CAPTURE_STATUS_RESERVED - 0
164 * #define CAPTUREXYZ_STATUS_ERROR1 CAPTURE_STATUS_RESERVED - 1
165 * #define CAPTUREXYZ_STATUS_ERROR2 CAPTURE_STATUS_RESERVED - 2
168 #define CAPTURE_STATUS_RESERVED (-32)
171 * @brief Successful status code returned by Capture_control().
173 * Capture_control() returns TIMER_STATUS_SUCCESS if the control code was executed
176 #define CAPTURE_STATUS_SUCCESS (0)
179 * @brief Generic error status code returned by Capture_control().
181 * Capture_control() returns CAPTURE_STATUS_ERROR if the control code was not executed
184 #define CAPTURE_STATUS_ERROR (-1)
187 * @brief An error status code returned by Capture_control() for undefined
190 * Capture_control() returns TIMER_STATUS_UNDEFINEDCMD if the control code is not
191 * recognized by the driver implementation.
193 #define CAPTURE_STATUS_UNDEFINEDCMD (-2)
196 * @brief Capture period unit enum
198 * The Capture period unit needs to be passed in Capture_open() to
199 * specify the unit of two capture triggering interval.
202 typedef enum Capture_Period_Unit_ {
203 CAPTURE_PERIOD_US, /* Period in microseconds */
204 CAPTURE_PERIOD_HZ, /* Period in frequency */
205 CAPTURE_PERIOD_COUNTS, /* Period in counts */
206 } Capture_Period_Unit;
209 * @brief Capture mode enum
211 * The Capture mode needs to be passed in Capture_open() to specify the capture
215 typedef enum Capture_Mode_ {
216 CAPTURE_MODE_RISING_RISING, /*!< capture is triggered at the rising edge followed by the rising edge */
217 CAPTURE_MODE_FALLING_FALLING, /*!< capture is triggered at the falling edge followed by the falling edge */
218 CAPTURE_MODE_ANY_EDGE
219 /*!< capture is triggered at the falling edge followed by the rising edge */
223 * @brief Capture callback function
225 * User definable callback function prototype. The Capture driver will call the
226 * defined function and pass in the Capture driver's handle and the pointer to the
227 * user-specified the argument.
229 * @param handle Capture_Handle
231 * @param interval Interval of two triggering edge in Capture_Period_Unit
234 typedef void (*Capture_CallBackFxn)(Capture_Handle handle, uint32_t interval);
237 * @brief Capture Parameters
239 * Capture parameters are used to with the Capture_open() call. Default values for
240 * these parameters are set using Capture_Params_init().
243 typedef struct Capture_Params_ {
244 Capture_Mode mode; /*!< Capture triggering mode */
245 Capture_CallBackFxn callbackFxn; /*!< Callback function pointer */
246 Capture_Period_Unit periodUnit; /*!< Period unit */
250 * @brief A function pointer to a driver specific implementation of
253 typedef void (*Capture_CloseFxn)(Capture_Handle handle);
256 * @brief A function pointer to a driver specific implementation of
259 typedef int_fast16_t (*Capture_ControlFxn)(Capture_Handle handle,
260 uint_fast16_t cmd, void *arg);
263 * @brief A function pointer to a driver specific implementation of
266 typedef void (*Capture_InitFxn)(Capture_Handle handle);
269 * @brief A function pointer to a driver specific implementation of
272 typedef Capture_Handle (*Capture_OpenFxn)(Capture_Handle handle,
273 Capture_Params *params);
276 * @brief A function pointer to a driver specific implementation of
279 typedef void (*Capture_StartFxn)(Capture_Handle handle);
282 * @brief A function pointer to a driver specific implementation of
285 typedef void (*Capture_StopFxn)(Capture_Handle handle);
288 * @brief The definition of a Capture function table that contains the
289 * required set of functions to control a specific Capture driver
292 typedef struct Capture_FxnTable_ {
293 /*! Function to close the specified peripheral */
294 Capture_CloseFxn closeFxn;
296 /*! Function to send control commands to the specified peripheral */
297 Capture_ControlFxn controlFxn;
299 /*! Function to initialize the specified peripheral */
300 Capture_InitFxn initFxn;
302 /*! Function to open the specified peripheral */
303 Capture_OpenFxn openFxn;
305 /*! Function to start the specified peripheral */
306 Capture_StartFxn startFxn;
308 /*! Function to stop the specified peripheral */
309 Capture_StopFxn stopFxn;
313 typedef struct Capture_Config_ {
314 Capture_FxnTable const *fxnTablePtr;
320 * @brief Function to close a Capture module specified by the Capture handle
322 * The function takes care of timer resource allocation. The corresponding timer
323 * resource to the Capture_Handle is released to be an available timer resource.
325 * @pre Capture_open() had to be called first.
327 * @param handle A Capture_Handle returned from Capture_open
331 extern void Capture_close(Capture_Handle handle);
334 * @brief Function performs implementation specific features on a given
337 * @pre Capture_open() must have been called first.
339 * @param handle A Capture_Handle returned from Capture_open().
341 * @param cmd A command value defined by the driver specific
344 * @param arg A pointer to an optional R/W (read/write) argument that
345 * is accompanied with cmd.
347 * @return A Capture_Status describing an error or success state. Negative values
348 * indicate an error occurred.
352 extern int_fast16_t Capture_control(Capture_Handle handle, uint_fast16_t cmd,
356 * @brief Function to initialize Capture.
358 extern void Capture_init(void);
361 * @brief Function to initialize a given Capture module specified by the
362 * particular index value. The parameter specifies which mode the Capture
365 * The function takes care of timer resource allocation. If the particular timer
366 * passed by user has already been used by other modules, the return value is NULL.
367 * If the particular timer is available to use, Capture module owns it and returns
370 * @param index Logical instance number for the Capture indexed into
371 * the Capture_config table
373 * @param params Pointer to an parameter block, if NULL it will use
374 * default values. All the fields in this structure are
377 * @return A Capture_Handle on success or a NULL on an error if it has been
378 * opened already or used by other modules.
381 * @sa Capture_close()
383 extern Capture_Handle Capture_open(uint_least8_t index, Capture_Params *params);
386 * @brief Function to initialize the Capture_Params struct to its defaults
388 * @param params An pointer to Capture_Params structure for
391 * Defaults values are:
392 * mode = CAPTURE_MODE_RISING_RISING
393 * callbackFxn = user_specified_callbackFxn
394 * periodUnit = Capture_PERIOD_COUNTS
396 extern void Capture_Params_init(Capture_Params *params);
399 * @brief Function to start capture. The Capture running mode
400 * and interval period unit are specfied in the Capture_Params when calling
403 * @param handle Capture_Handle
405 * @return CAPTURE_STATUS_SUCCESS if Capture starts successfully.
406 * CAPTURE_STATUS_ERROR if Capture fails to start.
409 extern void Capture_start(Capture_Handle handle);
412 * @brief Function to stop Capture after Capture_start() is called with success.
414 * @param handle Capture_Handle
417 extern void Capture_stop(Capture_Handle handle);
423 #endif /* ti_drivers_Capture__include */