📄 flashcode1.lst
字号:
C51 COMPILER V7.06 FLASHCODE1 10/10/2004 20:51:48 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE FLASHCODE1
OBJECT MODULE PLACED IN Flashcode1.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Flashcode1.c LARGE BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*
2
3 psd834f2.c
4
5 Revision History:
6
7 08/21/2002 (JAM) - Uncommented psd834f2.h include. Added #defines to
8 enable flash routines used by firmware. Added xdata
9 modifier to flash_write_with_poll pointer variables.
10 Changed all variables named 'data' to 'dat' to avoid
11 conflict with Keil compiler reserved word.
12
13 */
14
15 /*
16 These functions are provided to help you develop your initial code.
17 They are optimized for speed rather that size. As a result, you will
18 see very few nested function calls. If speed is not critical, you
19 can use function calls for common tasks (like dat polling after
20 writing a byte to Flash or EEPROM) The penalty is the extra processor
21 time to make the nested calls.
22
23 These files have been compiled using a C cross compiler from COSMIC
24 Software Inc. You may have to implement some syntax changes to be
25 compatible with other compilers. The intent of this generated C code
26 is to provide you with a core of useful broadbased functions that are
27 adaptable to many vendor's compilers and microcontrollers.
28
29
30 NOTES:
31
32 1.
33 Some of the routines provided may not have been thoroughly tested.
34 Please check them in your system. If you find a bug, or a place
35 where the code could be improved, PLEASE forward your comments by
36 emailing to apps.psd@st.com. Any comments and feedback are
37 appreciated. Please tell us what you like and or what you think
38 can be improved.
39
40 2.
41 The Software is provided "AS IS."
42
43 LIMITATION OF LIABILITY: NEITHER WSI NOR ITS VENDORS OR AGENTS
44 SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
45 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
46 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
47 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
48
49 You are free to use/modify any of the provided code at your own risk
50 in your applications with the expressed limitation of liability above.
51 */
52
53
54
55 /*
C51 COMPILER V7.06 FLASHCODE1 10/10/2004 20:51:48 PAGE 2
56 Be sure to uncomment the associated #define statements inside the
57 header file, psd834f2.h, to use individual desired functions
58 contained in this file, psd834f2.c. Your compiler will ignore the functions
59 in this file unless you do so.
60 */
61
62 #include "general.h"
63 #include <psd834f2.h> /* uncomment this include statement
64 to use the header files generated by
65 PSDsoft */
66
67 /* Function prototypes
68 */
69
70 #define _F_W_W_P
71 #define _F_E_B
72
73 unsigned char flash_write_with_poll(
74 volatile unsigned char xdata *addr, unsigned char dat);
75 unsigned char flash_erase_bulk(
76 volatile unsigned char xdata* flash_bulk_erase_address);
77 unsigned char flash_boot_write_with_poll(
78 volatile unsigned char xdata *addr, unsigned char dat);
79 unsigned char flash_boot_erase_bulk(
80 volatile unsigned char xdata* flash_boot_bulk_erase_address);
81
82 unsigned char flash_write_with_toggle(unsigned char *addr,unsigned char dat);
83 void flash_reset(void);
84 unsigned char flash_read_id(unsigned char *flash_id_address);
85 unsigned char flash_read_sector_protect(void);
86 unsigned char flash_boot_write_with_toggle(volatile unsigned char *addr,
87 unsigned char dat);
88 void flash_boot_reset(void);
89 unsigned char flash_boot_read_id(volatile unsigned char *flash_boot_id_address);
90 unsigned char flash_boot_read_sector_protect(void);
91
92
93 /* main_flash.c
94
95 - 12/20/99, msr
96 >> New release. Incorporates all prior revisions to C code.
97
98 -1/6/00, msr
99 >> Added delay of 3 msec after reset after flash error per dat sheet
100 >> Notation updates for PSD9XXF
101
102 - 4/27/01, msr
103 >> Notation updates
104
105 */
106
107
108 /*
109 Functions
110 */
111
112 /*
113 Group: Main Flash Memory
114 Coverage: Program, Erase, Reset, Read ID, Read Protection
115 */
116
117
C51 COMPILER V7.06 FLASHCODE1 10/10/2004 20:51:48 PAGE 3
118 /*
119 Module: flash_write_with_poll
120 Programs a single byte, checks status using polling method.
121 You'll need to include the header files generated by PSDsoft
122 Express. Important: if memory paging is used, the correct
123 page value must be set in the PSD page register prior to
124 calling this function.
125 */
126
127 #ifdef _F_W_W_P
128
129 unsigned char flash_write_with_poll(volatile uchar xdata* addr, uchar dat)
130 {
131 1 unsigned char done;
132 1 unsigned char error;
133 1 unsigned char err;
134 1 unsigned char poll;
135 1
136 1 done = FALSE;
137 1 err = FALSE;
138 1
139 1 // Note: the following constants (FLASH_COMMON_XXXX)
140 1 // are declared type volatile in the header file
141 1 // so they are not optimized away by the compiler
142 1
143 1
144 1 *(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
145 1 *(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
146 1 *(FLASH_COMMON_X555) = 0xA0; // write 0xA0 command to program
147 1
148 1 *(addr) = dat; // write byte to flash
149 1
150 1 dat = dat & NVM_DATA_POLL; // get bit DQ7 of original dat
151 1
152 1 do // now use dat polling method to verify successful write
153 1 {
154 2
155 2 poll = *(addr); // Read the location that was just programmed
156 2
157 2 error = poll & NVM_ERROR; // save timeout error bit at DQ5
158 2
159 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
160 2
161 2 if (dat == poll) // compare DQ7
162 2
163 2 done = TRUE; // dat byte programmed into flash OK,
164 2 // indicate successful exit criteria
165 2
166 2 else if (error == NVM_ERROR ) // check for timeout error
167 2 err = TRUE; // indicate timeout error occurred
168 2
169 2 } while((done == FALSE) && (err == FALSE));
170 1
171 1
172 1 if (err == TRUE) // make sure timeout error and dat poll didn't
173 1 // occur simultaneously
174 1 {
175 2 poll = *(addr); // Read location in flash again
176 2
177 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
178 2
179 2 if (dat == poll) // compare DQ7
C51 COMPILER V7.06 FLASHCODE1 10/10/2004 20:51:48 PAGE 4
180 2
181 2 done = TRUE; // dat byte programmed into flash OK at the same
182 2 // time timout error occured, indicate successful
183 2 // exit criteria
184 2
185 2 *(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
186 2 // now delay 3 msec per dat sheet
187 2 }
188 1
189 1 return(done); // a successful flash write returns 1, timeout error returns 0
190 1 }
191
192 unsigned char flash_boot_write_with_poll(volatile uchar xdata* addr, uchar dat)
193 {
194 1 unsigned char done;
195 1 unsigned char error;
196 1 unsigned char err;
197 1 unsigned char poll;
198 1
199 1 done = FALSE;
200 1 err = FALSE;
201 1
202 1 // Note: the following constants (FLASH_BOOT_XXXX)
203 1 // are declared type volatile in the header file
204 1 // so they are not optimized away by the compiler
205 1
206 1
207 1 *(FLASH_BOOT_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
208 1 *(FLASH_BOOT_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -