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