MotorWare f2806x Driver API Documentation
timer.c
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--*/
37 
38 // **************************************************************************
39 // the includes
40 
42 
43 
44 // **************************************************************************
45 // the defines
46 
47 
48 // **************************************************************************
49 // the globals
50 
51 
52 // **************************************************************************
53 // the functions
54 
55 void TIMER_clearFlag(TIMER_Handle timerHandle)
56 {
57  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
58 
59 
60  // set the bits
61  timer->TCR |= (uint16_t)TIMER_TCR_TIF_BITS;
62 
63  return;
64 } // end of TIMER_clearFlag() function
65 
66 
67 void TIMER_disableInt(TIMER_Handle timerHandle)
68 {
69  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
70 
71 
72  // clear the bits
73  timer->TCR &= (~(uint16_t)TIMER_TCR_TIE_BITS);
74 
75  return;
76 } // end of TIMER_disableInt() function
77 
78 
79 void TIMER_enableInt(TIMER_Handle timerHandle)
80 {
81  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
82 
83 
84  // set the bits
85  timer->TCR |= (uint16_t)TIMER_TCR_TIE_BITS;
86 
87  return;
88 } // end of TIMER_enableInt() function
89 
90 
92 {
93  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
94 
95 
96  // get the status
97  TIMER_Status_e status = (TIMER_Status_e)(timer->TCR & (uint16_t)TIMER_TCR_TIF_BITS);
98 
99  return(status);
100 } // end of TIMER_getStatus() function
101 
102 
103 TIMER_Handle TIMER_init(void *pMemory, const size_t numBytes)
104 {
105  TIMER_Handle timerHandle;
106 
107 
108  if(numBytes < sizeof(TIMER_Obj))
109  return((TIMER_Handle)NULL);
110 
111  // assign the handle
112  timerHandle = (TIMER_Handle)pMemory;
113 
114  return(timerHandle);
115 } // end of TIMER_init() function
116 
117 
119  const uint16_t decFactor)
120 {
121  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
122 
123 
124  // set the bits
125  timer->TPR =
126  ((uint32_t)(decFactor & 0xFF00) << 8) | (uint32_t)(decFactor & 0x00FF);
127 
128  return;
129 } // end of TIMER_setDecimationFactor() function
130 
131 
133  const TIMER_EmulationMode_e mode)
134 {
135  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
136 
137 
138  // clear the bits
139  timer->TCR &= (~(uint16_t)TIMER_TCR_FREESOFT_BITS);
140 
141  // set the bits
142  timer->TCR |= (uint16_t)mode;
143 
144  return;
145 } // end of TIMER_setEmulationMode() function
146 
147 
149  const uint16_t preScaler)
150 {
151  TIMER_Obj *timer = (TIMER_Obj *)timerHandle;
152 
153 
154  // set the bits
155  timer->TPR =
156  ((uint32_t)(preScaler & 0xFF00) << 8) | (uint32_t)(preScaler & 0x00FF);
157 
158  return;
159 } // end of TIMER_setPreScaler() function
160 
161 
162 // end of file
Defines the timer (TIMER) object.
Definition: timer.h:122
#define TIMER_TCR_TIF_BITS
Defines the location of the TIF bits in the TCR register.
Definition: timer.h:94
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
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
#define TIMER_TCR_FREESOFT_BITS
Defines the location of the FREESOFT bits in the TCR register.
Definition: timer.h:86
Contains public interface to various functions related to the timer (TIMER) object.
void TIMER_disableInt(TIMER_Handle timerHandle)
Disables the timer (TIMER) interrupt.
Definition: timer.c:67
void TIMER_enableInt(TIMER_Handle timerHandle)
Enables the timer (TIMER) interrupt.
Definition: timer.c:79
#define TIMER_TCR_TIE_BITS
Defines the location of the TIE bits in the TCR register.
Definition: timer.h:90
void TIMER_setDecimationFactor(TIMER_Handle timerHandle, const uint16_t decFactor)
Sets the timer (TIMER) decimation factor.
Definition: timer.c:118
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
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
TIMER_Handle TIMER_init(void *pMemory, const size_t numBytes)
Initializes the timer (TIMER) object handle.
Definition: timer.c:103