MotorWare f2806x Driver API Documentation
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 
44 
45 
46 // **************************************************************************
47 // the defines
48 
49 
50 // **************************************************************************
51 // the globals
52 
53 
54 // **************************************************************************
55 // the functions
56 
58 {
59  WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
60 
61 
63 
64  // write first sequence
65  wdog->WDKEY = 0x55;
66 
67  // write second sequence
68  wdog->WDKEY = 0xAA;
69 
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 
86 
87  // store the result
88  wdog->WDCR = regValue | WDOG_WDCR_WRITE_ENABLE;
89 
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 
102 
103  // clear the bits
104  wdog->SCSR &= (~WDOG_SCSR_WDENINT_BITS);
105 
107 
108  return;
109 } // end of WDOG_disableInt() function
110 
111 
113 {
114  WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
115 
116 
118 
119  // clear the bits
120  wdog->SCSR &= (~WDOG_SCSR_WDOVERRIDE_BITS);
121 
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 
138 
139  // store the result
140  wdog->WDCR = regValue | WDOG_WDCR_WRITE_ENABLE;
141 
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 
154 
155  // set the bits
156  wdog->SCSR |= WDOG_SCSR_WDENINT_BITS;
157 
159 
160  return;
161 } // end of WDOG_enableInt() function
162 
163 
165 {
166  WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
167 
168 
170 
171  // set the bits
173 
175 
176  return;
177 } // end of WDOG_enableOverRide() function
178 
179 
181 {
182  WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
183 
184  // mask the bits
185  WDOG_IntStatus_e status =
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 
232 
233  // store the result
234  wdog->WDCR = regValue | WDOG_WDCR_WRITE_ENABLE;
235 
237 
238  return;
239 } // end of WDOG_setPreScaler() function
240 
241 // end of file
WDOG_Handle WDOG_init(void *pMemory, const size_t numBytes)
Initializes the watchdog (WDOG) object handle.
Definition: wdog.c:192
#define DISABLE_PROTECTED_REGISTER_WRITE_MODE
Define to disable protected register writes.
Definition: cpu.h:101
Defines the watchdog (WDOG) object.
Definition: wdog.h:146
void WDOG_enable(WDOG_Handle wdogHandle)
Enables the watchdog (WDOG) timer.
Definition: wdog.c:128
#define WDOG_SCSR_WDINTS_BITS
Defines the location of the WDINTS bits in the SCSR register.
Definition: wdog.h:82
struct _WDOG_Obj_ * WDOG_Handle
Defines the watchdog (WDOG) handle.
Definition: wdog.h:159
#define WDOG_WDCR_WDPS_BITS
Defines the location of the WDPS bits in the WDCR register.
Definition: wdog.h:97
void WDOG_setCount(WDOG_Handle wdogHandle, const uint_least8_t count)
Sets the watchdog (WDOG) counter.
Definition: wdog.c:207
#define ENABLE_PROTECTED_REGISTER_WRITE_MODE
Define to allow protected register writes.
Definition: cpu.h:93
void WDOG_disableInt(WDOG_Handle wdogHandle)
Disables the watchdog (WDOG) timer interrupt.
Definition: wdog.c:96
#define WDOG_WDCR_WRITE_ENABLE
Defines the watchdog write enable mode.
Definition: wdog.h:114
#define WDOG_WDCR_WDDIS_BITS
Defines the location of the WDDIS bits in the WDCR register.
Definition: wdog.h:105
volatile uint16_t WDCR
Watchdog Control Register.
Definition: wdog.h:153
void WDOG_setPreScaler(WDOG_Handle wdogHandle, const WDOG_PreScaler_e preScaler)
Sets the watchdog (WDOG) timer clock prescaler.
Definition: wdog.c:219
void WDOG_enableInt(WDOG_Handle wdogHandle)
Enables the watchdog (WDOG) timer interrupt.
Definition: wdog.c:148
volatile uint16_t WDCNTR
Watchdog Counter Register.
Definition: wdog.h:149
#define WDOG_SCSR_WDOVERRIDE_BITS
Defines the location of the WDOVERRIDE bits in the SCSR register.
Definition: wdog.h:74
volatile uint16_t SCSR
System Control & Status Register.
Definition: wdog.h:148
Contains public interface to various functions related to the watchdog (WDOG) timer object...
void WDOG_clearCounter(WDOG_Handle wdogHandle)
Clears the watchdog (WDOG) counter.
Definition: wdog.c:57
WDOG_IntStatus_e WDOG_getIntStatus(WDOG_Handle wdogHandle)
Gets the watchdog (WDOG) interrupt status.
Definition: wdog.c:180
void WDOG_enableOverRide(WDOG_Handle wdogHandle)
Enables the watchdog (WDOG) timer override.
Definition: wdog.c:164
void WDOG_disable(WDOG_Handle wdogHandle)
Disables the watchdog (WDOG) timer.
Definition: wdog.c:76
volatile uint16_t WDKEY
Watchdog Reset Key Register.
Definition: wdog.h:151
#define WDOG_SCSR_WDENINT_BITS
Defines the location of the WDENINT bits in the SCSR register.
Definition: wdog.h:78
WDOG_PreScaler_e
Enumeration to define the watchdog (WDOG) timer clock prescaler, which sets the clock frequency...
Definition: wdog.h:132
void WDOG_disableOverRide(WDOG_Handle wdogHandle)
Disables the timer override.
Definition: wdog.c:112
WDOG_IntStatus_e
Enumeration to define the watchdog (WDOG) interrupt status.
Definition: wdog.h:123