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