MotorWare f2806x Driver API Documentation
timer.h
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2015, 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  * --/COPYRIGHT--*/
32 #ifndef _TIMER_H_
33 #define _TIMER_H_
34 
41 
42 // **************************************************************************
43 // the includes
44 
45 #include "sw/modules/types/src/types.h"
46 
51 
52 
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 
59 // **************************************************************************
60 // the defines
61 
62 
65 #define TIMER0_BASE_ADDR (0x00000C00)
66 
69 #define TIMER1_BASE_ADDR (0x00000C08)
70 
73 #define TIMER2_BASE_ADDR (0x00000C10)
74 
75 
78 #define TIMER_TCR_TSS_BITS (1 << 4)
79 
82 #define TIMER_TCR_TRB_BITS (1 << 5)
83 
86 #define TIMER_TCR_FREESOFT_BITS (3 << 10)
87 
90 #define TIMER_TCR_TIE_BITS (1 << 14)
91 
94 #define TIMER_TCR_TIF_BITS (1 << 15)
95 
96 
97 // **************************************************************************
98 // the typedefs
99 
100 
103 typedef enum
104 {
109 
110 
113 typedef enum
114 {
118 
119 
122 typedef struct _TIMER_Obj_
123 {
124  volatile uint32_t TIM;
125  volatile uint32_t PRD;
126  volatile uint16_t TCR;
127  volatile uint16_t resvd_1;
128  volatile uint32_t TPR;
129 } TIMER_Obj;
130 
131 
134 typedef struct _TIMER_Obj_ *TIMER_Handle;
135 
136 
137 // **************************************************************************
138 // the globals
139 
140 
141 // **************************************************************************
142 // the function prototypes
143 
144 
147 extern void TIMER_clearFlag(TIMER_Handle timerHandle);
148 
149 
152 extern void TIMER_disableInt(TIMER_Handle timerHandle);
153 
154 
157 extern void TIMER_enableInt(TIMER_Handle timerHandle);
158 
159 
163 static inline uint32_t TIMER_getCount(TIMER_Handle timerHandle)
164 {
165  TIMER_Obj *volatile timer = (TIMER_Obj *)timerHandle;
166 
167 
168  // get the count
169  uint32_t cnt = timer->TIM;
170 
171  return(cnt);
172 } // end of TIMER_getCount() function
173 
174 
178 extern TIMER_Status_e TIMER_getStatus(TIMER_Handle timerHandle);
179 
180 
185 extern TIMER_Handle TIMER_init(void *pMemory,const size_t numBytes);
186 
187 
190 static inline void TIMER_reload(TIMER_Handle timerHandle)
191 {
192  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
193 
194 
195  // clear the bits
196  timer->TCR |= (uint16_t)TIMER_TCR_TRB_BITS;
197 
198  return;
199 } // end of TIMER_reload() function
200 
201 
205 extern void TIMER_setDecimationFactor(TIMER_Handle timerHandle,
206  const uint16_t decFactor);
207 
208 
212 extern void TIMER_setEmulationMode(TIMER_Handle timerHandle,
213  const TIMER_EmulationMode_e mode);
214 
215 
219 static inline uint32_t TIMER_getPeriod(TIMER_Handle timerHandle)
220 {
221  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
222 
223 
224  // get the period
225  uint32_t period = timer->PRD;
226 
227  return(period);
228 } // end of TIMER_getPeriod() function
229 
230 
234 static inline void TIMER_setPeriod(TIMER_Handle timerHandle,
235  const uint32_t period)
236 {
237  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
238 
239 
240  // set the bits
241  timer->PRD = period;
242 
243  return;
244 } // end of TIMER_setPeriod() function
245 
246 
250 extern void TIMER_setPreScaler(TIMER_Handle timerHandle,
251  const uint16_t preScaler);
252 
253 
256 static inline void TIMER_start(TIMER_Handle timerHandle)
257 {
258  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
259 
260 
261  // clear the bits
262  timer->TCR &= (~(uint16_t)TIMER_TCR_TSS_BITS);
263 
264  return;
265 } // end of TIMER_start() function
266 
267 
270 static inline void TIMER_stop(TIMER_Handle timerHandle)
271 {
272  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
273 
274 
275  // set the bits
276  timer->TCR |= (uint16_t)TIMER_TCR_TSS_BITS;
277 
278  return;
279 } // end of TIMER_stop() function
280 
281 
282 #ifdef __cplusplus
283 }
284 #endif // extern "C"
285 
287 #endif // end of _TIMER_H_ definition
Denotes that the counter is zero.
Definition: timer.h:116
static void TIMER_setPeriod(TIMER_Handle timerHandle, const uint32_t period)
Sets the timer (TIMER) period.
Definition: timer.h:234
Defines the timer (TIMER) object.
Definition: timer.h:122
void TIMER_clearFlag(TIMER_Handle timerHandle)
Clears the timer (TIMER) flag.
Definition: timer.c:55
volatile uint16_t TCR
Timer Control Register.
Definition: timer.h:126
Denotes that the timer will stop after the next decrement.
Definition: timer.h:105
TIMER_Status_e
Enumeration to define the timer (TIMER) status.
Definition: timer.h:113
struct _TIMER_Obj_ * TIMER_Handle
Defines the timer (TIMER) handle.
Definition: timer.h:134
void TIMER_disableInt(TIMER_Handle timerHandle)
Disables the timer (TIMER) interrupt.
Definition: timer.c:67
#define TIMER_TCR_TSS_BITS
Defines the location of the TSS bits in the TCR register.
Definition: timer.h:78
void TIMER_enableInt(TIMER_Handle timerHandle)
Enables the timer (TIMER) interrupt.
Definition: timer.c:79
Denotes that the timer will run free.
Definition: timer.h:107
static uint32_t TIMER_getCount(TIMER_Handle timerHandle)
Gets the timer (TIMER) count.
Definition: timer.h:163
Denotes that the timer will stop when it reaches zero.
Definition: timer.h:106
#define TIMER_TCR_TRB_BITS
Defines the location of the TRB bits in the TCR register.
Definition: timer.h:82
volatile uint16_t resvd_1
Reserved.
Definition: timer.h:127
volatile uint32_t TIM
Timer Counter Register.
Definition: timer.h:124
static void TIMER_stop(TIMER_Handle timerHandle)
Stops the timer (TIMER)
Definition: timer.h:270
void TIMER_setDecimationFactor(TIMER_Handle timerHandle, const uint16_t decFactor)
Sets the timer (TIMER) decimation factor.
Definition: timer.c:118
static void TIMER_reload(TIMER_Handle timerHandle)
Reloads the timer (TIMER) value.
Definition: timer.h:190
TIMER_Status_e TIMER_getStatus(TIMER_Handle timerHandle)
Gets the timer (TIMER) status.
Definition: timer.c:91
void TIMER_setEmulationMode(TIMER_Handle timerHandle, const TIMER_EmulationMode_e mode)
Sets the timer (TIMER) emulation mode.
Definition: timer.c:132
static void TIMER_start(TIMER_Handle timerHandle)
Starts the timer (TIMER)
Definition: timer.h:256
volatile uint32_t PRD
Period Register.
Definition: timer.h:125
static uint32_t TIMER_getPeriod(TIMER_Handle timerHandle)
Gets the timer (TIMER) period.
Definition: timer.h:219
volatile uint32_t TPR
Timer Prescaler Register.
Definition: timer.h:128
void TIMER_setPreScaler(TIMER_Handle timerHandle, const uint16_t preScaler)
Sets the timer (TIMER) prescaler.
Definition: timer.c:148
TIMER_EmulationMode_e
Enumeration to define the timer (TIMER) emulation mode.
Definition: timer.h:103
Denotes that the counter is non-zero.
Definition: timer.h:115
struct _TIMER_Obj_ TIMER_Obj
Defines the timer (TIMER) object.
TIMER_Handle TIMER_init(void *pMemory, const size_t numBytes)
Initializes the timer (TIMER) object handle.
Definition: timer.c:103