MotorWare f2806x Driver API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

wdog.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--*/
32
38
39
40 // **************************************************************************
41 // the includes
42
43 #include "sw/drivers/wdog/src/32b/f28x/f2806x/wdog.h"
44
45
46 // **************************************************************************
47 // the defines
48
49
50 // **************************************************************************
51 // the globals
52
53
54 // **************************************************************************
55 // the functions
56
57 void WDOG_clearCounter(WDOG_Handle wdogHandle)
58 {
59 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
60
61
62 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
63
64 // write first sequence
65 wdog->WDKEY = 0x55;
66
67 // write second sequence
68 wdog->WDKEY = 0xAA;
69
70 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
71
72 return;
73 } // end of WDOG_clearCounter() function
74
75
76 void WDOG_disable(WDOG_Handle wdogHandle)
77 {
78 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
79 uint16_t regValue = wdog->WDCR;
80
81
82 // set the bits
83 regValue |= WDOG_WDCR_WDDIS_BITS;
84
85 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
86
87 // store the result
88 wdog->WDCR = regValue | WDOG_WDCR_WRITE_ENABLE;
89
90 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
91
92 return;
93 } // end of WDOG_disable() function
94
95
96 void WDOG_disableInt(WDOG_Handle wdogHandle)
97 {
98 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
99
100
101 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
102
103 // clear the bits
104 wdog->SCSR &= (~WDOG_SCSR_WDENINT_BITS);
105
106 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
107
108 return;
109 } // end of WDOG_disableInt() function
110
111
112 void WDOG_disableOverRide(WDOG_Handle wdogHandle)
113 {
114 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
115
116
117 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
118
119 // clear the bits
120 wdog->SCSR &= (~WDOG_SCSR_WDOVERRIDE_BITS);
121
122 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
123
124 return;
125 } // end of WDOG_disableOverRide() function
126
127
128 void WDOG_enable(WDOG_Handle wdogHandle)
129 {
130 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
131 uint16_t regValue = wdog->WDCR;
132
133
134 // clear the bits
135 regValue &= (~WDOG_WDCR_WDDIS_BITS);
136
137 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
138
139 // store the result
140 wdog->WDCR = regValue | WDOG_WDCR_WRITE_ENABLE;
141
142 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
143
144 return;
145 } // end of WDOG_enable() function
146
147
148 void WDOG_enableInt(WDOG_Handle wdogHandle)
149 {
150 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
151
152
153 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
154
155 // set the bits
156 wdog->SCSR |= WDOG_SCSR_WDENINT_BITS;
157
158 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
159
160 return;
161 } // end of WDOG_enableInt() function
162
163
164 void WDOG_enableOverRide(WDOG_Handle wdogHandle)
165 {
166 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
167
168
169 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
170
171 // set the bits
172 wdog->SCSR |= WDOG_SCSR_WDOVERRIDE_BITS;
173
174 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
175
176 return;
177 } // end of WDOG_enableOverRide() function
178
179
180 WDOG_IntStatus_e WDOG_getIntStatus(WDOG_Handle wdogHandle)
181 {
182 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
183
184 // mask the bits
185 WDOG_IntStatus_e status =
186 (WDOG_IntStatus_e)(wdog->SCSR & WDOG_SCSR_WDINTS_BITS);
187
188 return(status);
189 } // end of WDOG_getIntStatus() function
190
191
192 WDOG_Handle WDOG_init(void *pMemory, const size_t numBytes)
193 {
194 WDOG_Handle wdogHandle;
195
196
197 if(numBytes < sizeof(WDOG_Obj))
198 return((WDOG_Handle)NULL);
199
200 // assign the handle
201 wdogHandle = (WDOG_Handle)pMemory;
202
203 return(wdogHandle);
204 } // end of WDOG_init() function
205
206
207 void WDOG_setCount(WDOG_Handle wdogHandle, const uint_least8_t count)
208 {
209 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
210
211
212 // set the bits
213 wdog->WDCNTR = count;
214
215 return;
216 } // end of WDOG_setCount() function
217
218
219 void WDOG_setPreScaler(WDOG_Handle wdogHandle, const WDOG_PreScaler_e preScaler)
220 {
221 WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
222 uint16_t regValue = wdog->WDCR;
223
224
225 // clear the bits
226 regValue &= (~WDOG_WDCR_WDPS_BITS);
227
228 // set the bits
229 regValue |= preScaler;
230
231 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
232
233 // store the result
234 wdog->WDCR = regValue | WDOG_WDCR_WRITE_ENABLE;
235
236 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
237
238 return;
239 } // end of WDOG_setPreScaler() function
240
241 // end of file
WDOG_init
WDOG_Handle WDOG_init(void *pMemory, const size_t numBytes)
Initializes the watchdog (WDOG) object handle.
Definition: wdog.c:192
DISABLE_PROTECTED_REGISTER_WRITE_MODE
#define DISABLE_PROTECTED_REGISTER_WRITE_MODE
Define to disable protected register writes.
Definition: cpu.h:101
_WDOG_Obj_
Defines the watchdog (WDOG) object.
Definition: wdog.h:146
WDOG_enable
void WDOG_enable(WDOG_Handle wdogHandle)
Enables the watchdog (WDOG) timer.
Definition: wdog.c:128
WDOG_SCSR_WDINTS_BITS
#define WDOG_SCSR_WDINTS_BITS
Defines the location of the WDINTS bits in the SCSR register.
Definition: wdog.h:82
WDOG_Handle
struct _WDOG_Obj_ * WDOG_Handle
Defines the watchdog (WDOG) handle.
Definition: wdog.h:159
WDOG_WDCR_WDPS_BITS
#define WDOG_WDCR_WDPS_BITS
Defines the location of the WDPS bits in the WDCR register.
Definition: wdog.h:97
WDOG_setCount
void WDOG_setCount(WDOG_Handle wdogHandle, const uint_least8_t count)
Sets the watchdog (WDOG) counter.
Definition: wdog.c:207
ENABLE_PROTECTED_REGISTER_WRITE_MODE
#define ENABLE_PROTECTED_REGISTER_WRITE_MODE
Define to allow protected register writes.
Definition: cpu.h:93
WDOG_disableInt
void WDOG_disableInt(WDOG_Handle wdogHandle)
Disables the watchdog (WDOG) timer interrupt.
Definition: wdog.c:96
WDOG_WDCR_WRITE_ENABLE
#define WDOG_WDCR_WRITE_ENABLE
Defines the watchdog write enable mode.
Definition: wdog.h:114
WDOG_WDCR_WDDIS_BITS
#define WDOG_WDCR_WDDIS_BITS
Defines the location of the WDDIS bits in the WDCR register.
Definition: wdog.h:105
_WDOG_Obj_::WDCR
volatile uint16_t WDCR
Watchdog Control Register.
Definition: wdog.h:153
WDOG_setPreScaler
void WDOG_setPreScaler(WDOG_Handle wdogHandle, const WDOG_PreScaler_e preScaler)
Sets the watchdog (WDOG) timer clock prescaler.
Definition: wdog.c:219
WDOG_enableInt
void WDOG_enableInt(WDOG_Handle wdogHandle)
Enables the watchdog (WDOG) timer interrupt.
Definition: wdog.c:148
_WDOG_Obj_::WDCNTR
volatile uint16_t WDCNTR
Watchdog Counter Register.
Definition: wdog.h:149
WDOG_SCSR_WDOVERRIDE_BITS
#define WDOG_SCSR_WDOVERRIDE_BITS
Defines the location of the WDOVERRIDE bits in the SCSR register.
Definition: wdog.h:74
_WDOG_Obj_::SCSR
volatile uint16_t SCSR
System Control & Status Register.
Definition: wdog.h:148
wdog.h
Contains public interface to various functions related to the watchdog (WDOG) timer object...
WDOG_clearCounter
void WDOG_clearCounter(WDOG_Handle wdogHandle)
Clears the watchdog (WDOG) counter.
Definition: wdog.c:57
WDOG_getIntStatus
WDOG_IntStatus_e WDOG_getIntStatus(WDOG_Handle wdogHandle)
Gets the watchdog (WDOG) interrupt status.
Definition: wdog.c:180
WDOG_enableOverRide
void WDOG_enableOverRide(WDOG_Handle wdogHandle)
Enables the watchdog (WDOG) timer override.
Definition: wdog.c:164
WDOG_disable
void WDOG_disable(WDOG_Handle wdogHandle)
Disables the watchdog (WDOG) timer.
Definition: wdog.c:76
_WDOG_Obj_::WDKEY
volatile uint16_t WDKEY
Watchdog Reset Key Register.
Definition: wdog.h:151
WDOG_SCSR_WDENINT_BITS
#define WDOG_SCSR_WDENINT_BITS
Defines the location of the WDENINT bits in the SCSR register.
Definition: wdog.h:78
WDOG_PreScaler_e
WDOG_PreScaler_e
Enumeration to define the watchdog (WDOG) timer clock prescaler, which sets the clock frequency...
Definition: wdog.h:132
WDOG_disableOverRide
void WDOG_disableOverRide(WDOG_Handle wdogHandle)
Disables the timer override.
Definition: wdog.c:112
WDOG_IntStatus_e
WDOG_IntStatus_e
Enumeration to define the watchdog (WDOG) interrupt status.
Definition: wdog.h:123