1 /**
2  * @file       tmr_utils.h
3  * @brief      Timer utility function declarations
4  */
5 /* *****************************************************************************
6  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
22  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25  *
26  * Except as contained in this notice, the name of Maxim Integrated
27  * Products, Inc. shall not be used except as stated in the Maxim Integrated
28  * Products, Inc. Branding Policy.
29  *
30  * The mere transfer of this software does not imply any licenses
31  * of trade secrets, proprietary technology, copyrights, patents,
32  * trademarks, maskwork rights, or any other form of intellectual
33  * property whatsoever. Maxim Integrated Products, Inc. retains all
34  * ownership rights.
35  *
36  * $Date: 2018-10-17 14:16:30 -0500 (Wed, 17 Oct 2018) $
37  * $Revision: 38560 $
38  *
39  **************************************************************************** */
40 
41 /* Define to prevent redundant inclusion */
42 #ifndef _TMR_UTILS_H
43 #define _TMR_UTILS_H
44 
45 /***** Includes *****/
46 #include "mxc_config.h"
47 #include "tmr_regs.h"
48 #include "mxc_sys.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /**
55  * @ingroup tmr
56  * @defgroup tmr_utils Timer Utility Functions
57  * @{
58  */
59 
60 /* **** Definitions **** */
61 
62 /** @def Macro to convert the parameter \p s from seconds to micro-seconds. */
63 #define SEC(s)            (((unsigned long)s) * 1000000UL)
64 
65 /** @def Macro to convert the parameter \p ms from milli-seconds to micro-seconds. */
66 #define MSEC(ms)          (ms * 1000UL)
67 
68 /** @def Macro to convert the parameter \p us to micro-seconds. */
69 #define USEC(us)          (us)
70 
71 /* **** Globals **** */
72 
73 /* **** Function Prototypes **** */
74 
75 /**
76  * @brief      Delays for the specified number of microseconds.
77  * @param      tmr   Which Timer instance to use
78  * @param      us    Number of microseconds to delay.
79  * @param      sys_cfg  System configuration object, identical to TMR_Init()
80  */
81 void TMR_Delay(mxc_tmr_regs_t *tmr, unsigned long us, const sys_cfg_tmr_t *sys_cfg);
82 
83 /**
84  * @brief      Start the timeout time for the specified number of microseconds.
85  * @param      tmr     Which Timer instance to use
86  * @param      us      Number of microseconds in the timeout.
87  * @param      sys_cfg  System configuration object, identical to TMR_Init()
88  */
89 void TMR_TO_Start(mxc_tmr_regs_t *tmr, unsigned long us, const sys_cfg_tmr_t *sys_cfg);
90 
91 /**
92  * @brief      Check if the timeout has occurred.
93  * @param      tmr   Which Timer instance to use
94  * @return     #E_NO_ERROR if the timeout has not occurred, #E_TIME_OUT if it has.
95  */
96 int TMR_TO_Check(mxc_tmr_regs_t *tmr);
97 
98 /**
99  * @brief      Stops the timer for the timeout.
100  * @param      tmr   Which Timer instance to use
101  */
102 void TMR_TO_Stop(mxc_tmr_regs_t *tmr);
103 
104 /**
105  * @brief      Clears the timeout flag.
106  * @param      tmr   Which Timer instance to use
107  */
108 void TMR_TO_Clear(mxc_tmr_regs_t *tmr);
109 
110 /**
111  * @brief      Get the number of microseconds elapsed since TMR_TO_Start().
112  * @param      tmr   Which Timer instance to use
113  * @return     Number of microseconds since TMR_TO_Start().
114  */
115 unsigned int TMR_TO_Elapsed(mxc_tmr_regs_t *tmr);
116 
117 /**
118  * @brief      Get the number of microseconds remaining in the timeout.
119  * @param      tmr   Which Timer instance to use
120  * @return     Number of microseconds until timeout.
121  */
122 unsigned int TMR_TO_Remaining(mxc_tmr_regs_t *tmr);
123 
124 /**
125  * @brief      Start the stopwatch.
126  * @note 	   This function does not handle overflows
127  * @param      tmr   Which Timer to use
128  * @param      sys_cfg  System configuration object, identical to TMR_Init()
129  */
130 void TMR_SW_Start(mxc_tmr_regs_t *tmr, const sys_cfg_tmr_t *sys_cfg);
131 
132 /**
133  * @brief      Stop the stopwatch and return the number of microseconds that
134  *             have elapsed.
135  * @note 	   This function does not handle overflows
136  * @param      tmr   Which Timer instance to use
137  * @return     Number of microseconds since TMR_SW_Start().
138  */
139 unsigned int TMR_SW_Stop(mxc_tmr_regs_t *tmr);
140 
141 /**@} end of defgroup tmr_utils*/
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif /* _TMR_UTILS_H */
147