MotorWare f2806x Driver API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

flash.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 // **************************************************************************
40 // the includes
41
42 #include "sw/drivers/flash/src/32b/f28x/f2806x/flash.h"
43
44
45 // **************************************************************************
46 // the defines
47
48
49 // **************************************************************************
50 // the globals
51
52
53 // **************************************************************************
54 // the functions
55
56 void FLASH_clear3VStatus(FLASH_Handle flashHandle)
57 {
58 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
59
60
61 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
62
63 // set the bits
64 flash->FSTATUS |= FLASH_FSTATUS_3VSTAT_BITS;
65
66 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
67
68 return;
69 } // end of FLASH_clear3VStatus() function
70
71
72 #pragma CODE_SECTION(FLASH_disablePipelineMode, "ramfuncs");
73 void FLASH_disablePipelineMode(FLASH_Handle flashHandle)
74 {
75 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
76
77
78 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
79
80 // clear the bits
81 flash->FOPT &= (~FLASH_FOPT_ENPIPE_BITS);
82
83 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
84
85 return;
86 } // end of FLASH_disablePipelineMode() function
87
88
89 #pragma CODE_SECTION(FLASH_enablePipelineMode, "ramfuncs");
90 void FLASH_enablePipelineMode(FLASH_Handle flashHandle)
91 {
92 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
93
94
95 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
96
97 // set the bits
98 flash->FOPT |= FLASH_FOPT_ENPIPE_BITS;
99
100 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
101
102 return;
103 } // end of FLASH_enablePipelineMode() function
104
105
106 FLASH_3VStatus_e FLASH_get3VStatus(FLASH_Handle flashHandle)
107 {
108 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
109
110
111 // get the status
112 FLASH_3VStatus_e status = (FLASH_3VStatus_e)(flash->FSTATUS & FLASH_FSTATUS_3VSTAT_BITS);
113
114 return(status);
115 } // end of FLASH_get3VStatus() function
116
117
118 uint16_t FLASH_getActiveWaitCount(FLASH_Handle flashHandle)
119 {
120 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
121
122
123 // get the status
124 uint16_t count = (flash->FACTIVEWAIT & FLASH_FACTIVEWAIT_ACTIVEWAIT_BITS);
125
126 return(count);
127 } // end of FLASH_getActiveWaitCount() function
128
129
130 FLASH_CounterStatus_e FLASH_getActiveWaitStatus(FLASH_Handle flashHandle)
131 {
132 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
133
134
135 // get the status
136 FLASH_CounterStatus_e status = (FLASH_CounterStatus_e)((flash->FSTATUS & FLASH_FSTATUS_ACTIVEWAITS_BITS) >> 3);
137
138 return(status);
139 } // end of FLASH_getActiveWaitStatus() function
140
141
142 FLASH_PowerMode_e FLASH_getPowerMode(FLASH_Handle flashHandle)
143 {
144 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
145
146
147 // get the bits
148 FLASH_PowerMode_e mode = (FLASH_PowerMode_e)(flash->FSTATUS & FLASH_FSTATUS_PWRS_BITS);
149
150 return(mode);
151 } // end of FLASH_getPowerMode() function
152
153
154 uint16_t FLASH_getStandbyWaitCount(FLASH_Handle flashHandle)
155 {
156 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
157
158
159 // get the status
160 uint16_t count = (flash->FSTDBYWAIT & FLASH_FSTDBYWAIT_STDBYWAIT_BITS);
161
162 return(count);
163 } // end of FLASH_getStandbyWaitCount() function
164
165
166 FLASH_CounterStatus_e FLASH_getStandbyWaitStatus(FLASH_Handle flashHandle)
167 {
168 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
169
170
171 // get the status
172 FLASH_CounterStatus_e status = (FLASH_CounterStatus_e)((flash->FSTATUS & FLASH_FSTATUS_STDBYWAITS_BITS) >> 2);
173
174 return(status);
175 } // end of FLASH_getStandbyWaitStatus() function
176
177
178 FLASH_Handle FLASH_init(void *pMemory,const size_t numBytes)
179 {
180 FLASH_Handle flashHandle;
181
182
183 if(numBytes < sizeof(FLASH_Obj))
184 return((FLASH_Handle)NULL);
185
186 // assign the handle
187 flashHandle = (FLASH_Handle)pMemory;
188
189 return(flashHandle);
190 } // end of FLASH_init() function
191
192
193 #pragma CODE_SECTION(FLASH_setActiveWaitCount, "ramfuncs");
194 void FLASH_setActiveWaitCount(FLASH_Handle flashHandle,const uint16_t count)
195 {
196 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
197
198
199 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
200
201 flash->FACTIVEWAIT = count;
202
203 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
204
205 return;
206 } // end of FLASH_setActiveWaitCount() function
207
208
209 #pragma CODE_SECTION(FLASH_setNumPagedReadWaitStates, "ramfuncs");
210 void FLASH_setNumPagedReadWaitStates(FLASH_Handle flashHandle,const FLASH_NumPagedWaitStates_e numStates)
211 {
212 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
213
214
215 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
216
217 // clear the bits
218 flash->FBANKWAIT &= (~FLASH_FBANKWAIT_PAGEWAIT_BITS);
219
220 // set the bits
221 flash->FBANKWAIT |= numStates;
222
223 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
224
225 return;
226 } // end of FLASH_setNumPagedReadWaitStates() function
227
228
229 #pragma CODE_SECTION(FLASH_setNumRandomReadWaitStates, "ramfuncs");
230 void FLASH_setNumRandomReadWaitStates(FLASH_Handle flashHandle,const FLASH_NumRandomWaitStates_e numStates)
231 {
232 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
233
234
235 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
236
237 // clear the bits
238 flash->FBANKWAIT &= (~FLASH_FBANKWAIT_RANDWAIT_BITS);
239
240 // set the bits
241 flash->FBANKWAIT |= numStates;
242
243 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
244
245 return;
246 } // end of FLASH_setNumRandomReadWaitStates() function
247
248
249 #pragma CODE_SECTION(FLASH_setOtpWaitStates, "ramfuncs");
250 void FLASH_setOtpWaitStates(FLASH_Handle flashHandle,const FLASH_NumOtpWaitStates_e numStates)
251 {
252 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
253
254
255 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
256
257 // clear the bits
258 flash->FOTPWAIT &= (~FLASH_FOTPWAIT_OTPWAIT_BITS);
259
260 // set the bits
261 flash->FOTPWAIT |= numStates;
262
263 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
264
265 return;
266 } // end of FLASH_setOneTimeProgrammableStates() function
267
268
269 #pragma CODE_SECTION(FLASH_setPowerMode, "ramfuncs");
270 void FLASH_setPowerMode(FLASH_Handle flashHandle,const FLASH_PowerMode_e mode)
271 {
272 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
273
274
275 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
276
277 // clear the bits
278 flash->FPWR &= (~FLASH_FPWR_PWR_BITS);
279
280 // set the bits
281 flash->FPWR |= mode;
282
283 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
284
285 return;
286 } // end of FLASH_setPowerMode() function
287
288
289 #pragma CODE_SECTION(FLASH_setStandbyWaitCount, "ramfuncs");
290 void FLASH_setStandbyWaitCount(FLASH_Handle flashHandle,const uint16_t count)
291 {
292 FLASH_Obj *flash = (FLASH_Obj *)flashHandle;
293
294
295 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
296
297 flash->FSTDBYWAIT = count;
298
299 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
300
301 return;
302 } // end of FLASH_setStandbyWaitCount() function
303
304
305 // end of file
FLASH_FOTPWAIT_OTPWAIT_BITS
#define FLASH_FOTPWAIT_OTPWAIT_BITS
Defines the location of the OTPWAIT bits in the FOTPWAIT register.
Definition: flash.h:101
FLASH_setOtpWaitStates
void FLASH_setOtpWaitStates(FLASH_Handle flashHandle, const FLASH_NumOtpWaitStates_e numStates)
Sets the number of one-time programmable (OTP) wait states.
Definition: flash.c:250
FLASH_get3VStatus
FLASH_3VStatus_e FLASH_get3VStatus(FLASH_Handle flashHandle)
Gets the 3V status.
Definition: flash.c:106
DISABLE_PROTECTED_REGISTER_WRITE_MODE
#define DISABLE_PROTECTED_REGISTER_WRITE_MODE
Define to disable protected register writes.
Definition: cpu.h:101
FLASH_FBANKWAIT_PAGEWAIT_BITS
#define FLASH_FBANKWAIT_PAGEWAIT_BITS
Defines the location of the PAGEWAIT bits in the FBANKWAIT register.
Definition: flash.h:96
FLASH_FSTDBYWAIT_STDBYWAIT_BITS
#define FLASH_FSTDBYWAIT_STDBYWAIT_BITS
Defines the location of the STDBYWAIT bits in the FSTDBYWAIT register.
Definition: flash.h:128
FLASH_setActiveWaitCount
void FLASH_setActiveWaitCount(FLASH_Handle flashHandle, const uint16_t count)
Sets the active wait count.
Definition: flash.c:194
FLASH_FPWR_PWR_BITS
#define FLASH_FPWR_PWR_BITS
Defines the location of the PWR bits in the FPWR register.
Definition: flash.h:106
FLASH_CounterStatus_e
FLASH_CounterStatus_e
Enumeration to define the counter status.
Definition: flash.h:146
FLASH_FBANKWAIT_RANDWAIT_BITS
#define FLASH_FBANKWAIT_RANDWAIT_BITS
Defines the location of the RANDWAIT bits in the FBANKWAIT register.
Definition: flash.h:92
FLASH_disablePipelineMode
void FLASH_disablePipelineMode(FLASH_Handle flashHandle)
Disables the pipeline mode.
Definition: flash.c:73
_FLASH_Obj_::FSTDBYWAIT
volatile uint16_t FSTDBYWAIT
Flash Sleep To Standby Wait Register.
Definition: flash.h:238
ENABLE_PROTECTED_REGISTER_WRITE_MODE
#define ENABLE_PROTECTED_REGISTER_WRITE_MODE
Define to allow protected register writes.
Definition: cpu.h:93
_FLASH_Obj_::FACTIVEWAIT
volatile uint16_t FACTIVEWAIT
Flash Standby to Active Wait Register.
Definition: flash.h:239
FLASH_getStandbyWaitStatus
FLASH_CounterStatus_e FLASH_getStandbyWaitStatus(FLASH_Handle flashHandle)
Gets the standby wait counter status.
Definition: flash.c:166
FLASH_setNumPagedReadWaitStates
void FLASH_setNumPagedReadWaitStates(FLASH_Handle flashHandle, const FLASH_NumPagedWaitStates_e numStates)
Sets the number of paged read wait states.
Definition: flash.c:210
FLASH_NumOtpWaitStates_e
FLASH_NumOtpWaitStates_e
Enumeration to define the number of one-time programmable wait states.
Definition: flash.h:155
FLASH_getActiveWaitCount
uint16_t FLASH_getActiveWaitCount(FLASH_Handle flashHandle)
Gets the active wait count.
Definition: flash.c:118
_FLASH_Obj_::FBANKWAIT
volatile uint16_t FBANKWAIT
Flash Read Access Wait State Register.
Definition: flash.h:240
FLASH_getActiveWaitStatus
FLASH_CounterStatus_e FLASH_getActiveWaitStatus(FLASH_Handle flashHandle)
Gets the active wait counter status.
Definition: flash.c:130
FLASH_init
FLASH_Handle FLASH_init(void *pMemory, const size_t numBytes)
Initializes the flash (FLASH) handle.
Definition: flash.c:178
FLASH_3VStatus_e
FLASH_3VStatus_e
Enumeration to define the 3V status.
Definition: flash.h:137
_FLASH_Obj_::FOPT
volatile uint16_t FOPT
Flash Option Register.
Definition: flash.h:234
FLASH_setPowerMode
void FLASH_setPowerMode(FLASH_Handle flashHandle, const FLASH_PowerMode_e mode)
Sets the power mode.
Definition: flash.c:270
FLASH_enablePipelineMode
void FLASH_enablePipelineMode(FLASH_Handle flashHandle)
Enables the pipeline mode.
Definition: flash.c:90
_FLASH_Obj_::FOTPWAIT
volatile uint16_t FOTPWAIT
OTP Read Access Wait State Register.
Definition: flash.h:241
FLASH_FSTATUS_STDBYWAITS_BITS
#define FLASH_FSTATUS_STDBYWAITS_BITS
Defines the location of the STDBYWAITS bits in the FSTATUS register.
Definition: flash.h:115
_FLASH_Obj_::FSTATUS
volatile uint16_t FSTATUS
Status Register.
Definition: flash.h:237
FLASH_NumPagedWaitStates_e
FLASH_NumPagedWaitStates_e
Enumeration to define the number of paged wait states.
Definition: flash.h:177
FLASH_FSTATUS_ACTIVEWAITS_BITS
#define FLASH_FSTATUS_ACTIVEWAITS_BITS
Defines the location of the ACTIVEWAITS bits in the FSTATUS register.
Definition: flash.h:119
_FLASH_Obj_
Defines the flash (FLASH) object.
Definition: flash.h:232
FLASH_setStandbyWaitCount
void FLASH_setStandbyWaitCount(FLASH_Handle flashHandle, const uint16_t count)
Sets the standby wait count.
Definition: flash.c:290
_FLASH_Obj_::FPWR
volatile uint16_t FPWR
Flash Power Modes Register.
Definition: flash.h:236
FLASH_getStandbyWaitCount
uint16_t FLASH_getStandbyWaitCount(FLASH_Handle flashHandle)
Gets the standby wait count.
Definition: flash.c:154
FLASH_FOPT_ENPIPE_BITS
#define FLASH_FOPT_ENPIPE_BITS
Defines the location of the ENPIPE bits in the FOPT register.
Definition: flash.h:82
FLASH_NumRandomWaitStates_e
FLASH_NumRandomWaitStates_e
Enumeration to define the number of random wait states.
Definition: flash.h:200
FLASH_FSTATUS_3VSTAT_BITS
#define FLASH_FSTATUS_3VSTAT_BITS
Defines the location of the 3VSTAT bits in the FSTATUS register.
Definition: flash.h:123
FLASH_setNumRandomReadWaitStates
void FLASH_setNumRandomReadWaitStates(FLASH_Handle flashHandle, const FLASH_NumRandomWaitStates_e numStates)
Sets the number of random read wait states.
Definition: flash.c:230
FLASH_getPowerMode
FLASH_PowerMode_e FLASH_getPowerMode(FLASH_Handle flashHandle)
Gets the power mode.
Definition: flash.c:142
FLASH_FACTIVEWAIT_ACTIVEWAIT_BITS
#define FLASH_FACTIVEWAIT_ACTIVEWAIT_BITS
Defines the location of the ACTIVEWAIT bits in the FACTIVEWAIT register.
Definition: flash.h:87
FLASH_Handle
struct _FLASH_Obj_ * FLASH_Handle
Defines the flash (FLASH) handle.
Definition: flash.h:247
flash.h
Contains public interface to various functions related to the flash (FLASH) object.
FLASH_PowerMode_e
FLASH_PowerMode_e
Enumeration to define the power modes.
Definition: flash.h:222
FLASH_FSTATUS_PWRS_BITS
#define FLASH_FSTATUS_PWRS_BITS
Defines the location of the PWRS bits in the FSTATUS register.
Definition: flash.h:111
FLASH_clear3VStatus
void FLASH_clear3VStatus(FLASH_Handle flashHandle)
Clears the 3V status.
Definition: flash.c:56