annotate src/external_flash.asm @ 418:a5fc007634c5

some cleanup
author heinrichsweikamp
date Tue, 19 Apr 2016 14:03:24 +0200
parents 4389fe9673b2
children 789230298511
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File external_flash.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; External flash
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-12 : [mH] creation
heinrichsweikamp
parents:
diff changeset
11
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 167
diff changeset
12 #include "hwos.inc"
0
heinrichsweikamp
parents:
diff changeset
13 #include "wait.inc"
heinrichsweikamp
parents:
diff changeset
14
heinrichsweikamp
parents:
diff changeset
15 basic CODE
heinrichsweikamp
parents:
diff changeset
16 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
17
heinrichsweikamp
parents:
diff changeset
18 global incf_ext_flash_address_p1
heinrichsweikamp
parents:
diff changeset
19 incf_ext_flash_address_p1: ; Increase by one
heinrichsweikamp
parents:
diff changeset
20 movlw .1
heinrichsweikamp
parents:
diff changeset
21
heinrichsweikamp
parents:
diff changeset
22 global incf_ext_flash_address0
heinrichsweikamp
parents:
diff changeset
23 incf_ext_flash_address0:
heinrichsweikamp
parents:
diff changeset
24 addwf ext_flash_address+0,F ; increase address
heinrichsweikamp
parents:
diff changeset
25 movlw d'0'
heinrichsweikamp
parents:
diff changeset
26 addwfc ext_flash_address+1,F
heinrichsweikamp
parents:
diff changeset
27 addwfc ext_flash_address+2,F
heinrichsweikamp
parents:
diff changeset
28
heinrichsweikamp
parents:
diff changeset
29 movlw 0x40
heinrichsweikamp
parents:
diff changeset
30 cpfseq ext_flash_address+2 ; at address 40FFFF?
heinrichsweikamp
parents:
diff changeset
31 return ; No, return
167
05f2100d2eb8 logbook
heinrichsweikamp
parents: 6
diff changeset
32 ; clrf ext_flash_address+0
05f2100d2eb8 logbook
heinrichsweikamp
parents: 6
diff changeset
33 ; clrf ext_flash_address+1
05f2100d2eb8 logbook
heinrichsweikamp
parents: 6
diff changeset
34 clrf ext_flash_address+2 ; Yes, rollover to 0x000000
0
heinrichsweikamp
parents:
diff changeset
35 return
heinrichsweikamp
parents:
diff changeset
36
heinrichsweikamp
parents:
diff changeset
37 global incf_ext_flash_address0_p1_0x20
heinrichsweikamp
parents:
diff changeset
38 incf_ext_flash_address0_p1_0x20: ; Increase by one
heinrichsweikamp
parents:
diff changeset
39 movlw .1
heinrichsweikamp
parents:
diff changeset
40
heinrichsweikamp
parents:
diff changeset
41 global incf_ext_flash_address0_0x20
heinrichsweikamp
parents:
diff changeset
42 incf_ext_flash_address0_0x20: ; with roll-over at 0x200000 to 0x000000
heinrichsweikamp
parents:
diff changeset
43 addwf ext_flash_address+0,F ; increase address
heinrichsweikamp
parents:
diff changeset
44 movlw d'0'
heinrichsweikamp
parents:
diff changeset
45 addwfc ext_flash_address+1,F
heinrichsweikamp
parents:
diff changeset
46 addwfc ext_flash_address+2,F
heinrichsweikamp
parents:
diff changeset
47
heinrichsweikamp
parents:
diff changeset
48 movlw 0x20
heinrichsweikamp
parents:
diff changeset
49 cpfseq ext_flash_address+2 ; at address 0x200000?
heinrichsweikamp
parents:
diff changeset
50 return ; No, return
167
05f2100d2eb8 logbook
heinrichsweikamp
parents: 6
diff changeset
51 ; clrf ext_flash_address+0
05f2100d2eb8 logbook
heinrichsweikamp
parents: 6
diff changeset
52 ; clrf ext_flash_address+1
05f2100d2eb8 logbook
heinrichsweikamp
parents: 6
diff changeset
53 clrf ext_flash_address+2 ; Yes, rollover to 0x000000
0
heinrichsweikamp
parents:
diff changeset
54 return
heinrichsweikamp
parents:
diff changeset
55
heinrichsweikamp
parents:
diff changeset
56 global decf_ext_flash_address0
heinrichsweikamp
parents:
diff changeset
57 decf_ext_flash_address0:
heinrichsweikamp
parents:
diff changeset
58 subwf ext_flash_address+0,F ; decrease address: do a 16-8bits substract.
heinrichsweikamp
parents:
diff changeset
59 movlw d'0'
heinrichsweikamp
parents:
diff changeset
60 subwfb ext_flash_address+1,F
heinrichsweikamp
parents:
diff changeset
61 movlw d'0'
heinrichsweikamp
parents:
diff changeset
62 subwfb ext_flash_address+2,F
heinrichsweikamp
parents:
diff changeset
63
heinrichsweikamp
parents:
diff changeset
64 btfss ext_flash_address+2,7 ; Rollover to 0xFFFFFF?
heinrichsweikamp
parents:
diff changeset
65 return ; No, return
heinrichsweikamp
parents:
diff changeset
66 clrf ext_flash_address+2 ; Set to 0x00FFFFF
heinrichsweikamp
parents:
diff changeset
67 setf ext_flash_address+1
heinrichsweikamp
parents:
diff changeset
68 setf ext_flash_address+0
heinrichsweikamp
parents:
diff changeset
69 return
heinrichsweikamp
parents:
diff changeset
70
heinrichsweikamp
parents:
diff changeset
71 global ext_flash_power_down
heinrichsweikamp
parents:
diff changeset
72 ext_flash_power_down:
heinrichsweikamp
parents:
diff changeset
73 movlw 0x04 ; Write disable
heinrichsweikamp
parents:
diff changeset
74 rcall write_spi
heinrichsweikamp
parents:
diff changeset
75 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
76 return
heinrichsweikamp
parents:
diff changeset
77
heinrichsweikamp
parents:
diff changeset
78 global ext_flash_byte_read_plus ; Return data read in WREG and SSP2BUF and
heinrichsweikamp
parents:
diff changeset
79 ext_flash_byte_read_plus: ; increase address after read
heinrichsweikamp
parents:
diff changeset
80 rcall ext_flash_byte_read
heinrichsweikamp
parents:
diff changeset
81 movwf temp1 ; store received data
heinrichsweikamp
parents:
diff changeset
82 bra incf_ext_flash_address_p1 ; +1 and return
heinrichsweikamp
parents:
diff changeset
83
heinrichsweikamp
parents:
diff changeset
84 global ext_flash_byte_read_plus_0x20; Return data read in WREG and SSP2BUF and
heinrichsweikamp
parents:
diff changeset
85 ext_flash_byte_read_plus_0x20: ; increase address after read with banking at 0x200000
heinrichsweikamp
parents:
diff changeset
86 rcall ext_flash_byte_read
heinrichsweikamp
parents:
diff changeset
87 movwf temp1 ; store received data
heinrichsweikamp
parents:
diff changeset
88 bra incf_ext_flash_address0_p1_0x20 ;+1 and return
heinrichsweikamp
parents:
diff changeset
89
heinrichsweikamp
parents:
diff changeset
90
heinrichsweikamp
parents:
diff changeset
91 global ext_flash_byte_read ; Return data read in WREG
heinrichsweikamp
parents:
diff changeset
92 ext_flash_byte_read:
heinrichsweikamp
parents:
diff changeset
93 movlw 0x03 ; Read command
heinrichsweikamp
parents:
diff changeset
94 rcall write_spi
heinrichsweikamp
parents:
diff changeset
95 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI
heinrichsweikamp
parents:
diff changeset
96 rcall write_spi ; Dummy write to read data into WREG
heinrichsweikamp
parents:
diff changeset
97 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
98 movwf temp1
heinrichsweikamp
parents:
diff changeset
99 return ; Return data read in WREG and temp1
heinrichsweikamp
parents:
diff changeset
100
heinrichsweikamp
parents:
diff changeset
101 ext_flash_write_address: ; Write 24bit address ext_flash_address:3 via SPI
heinrichsweikamp
parents:
diff changeset
102 movf ext_flash_address+2,W ; 24Bit Address
heinrichsweikamp
parents:
diff changeset
103 rcall write_spi
heinrichsweikamp
parents:
diff changeset
104 movf ext_flash_address+1,W
heinrichsweikamp
parents:
diff changeset
105 rcall write_spi
heinrichsweikamp
parents:
diff changeset
106 movf ext_flash_address+0,W
heinrichsweikamp
parents:
diff changeset
107 bra write_spi ; And return....
heinrichsweikamp
parents:
diff changeset
108
heinrichsweikamp
parents:
diff changeset
109 global ext_flash_read_block_start ; Return data read in WREG
heinrichsweikamp
parents:
diff changeset
110 ext_flash_read_block_start:
heinrichsweikamp
parents:
diff changeset
111 movlw 0x03 ; Read command
heinrichsweikamp
parents:
diff changeset
112 rcall write_spi
heinrichsweikamp
parents:
diff changeset
113 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI
heinrichsweikamp
parents:
diff changeset
114 rcall write_spi ; Dummy write to read data into WREG
heinrichsweikamp
parents:
diff changeset
115 return ; Return data read in WREG
heinrichsweikamp
parents:
diff changeset
116
heinrichsweikamp
parents:
diff changeset
117 global ext_flash_read_block ; Return data read in WREG
heinrichsweikamp
parents:
diff changeset
118 ext_flash_read_block:
heinrichsweikamp
parents:
diff changeset
119 rcall incf_ext_flash_address_p1 ; Increase address +1
heinrichsweikamp
parents:
diff changeset
120 bra write_spi1 ; Dummy write to read data into WREG and return
heinrichsweikamp
parents:
diff changeset
121
heinrichsweikamp
parents:
diff changeset
122 global ext_flash_read_block_stop ; Return data read in WREG
heinrichsweikamp
parents:
diff changeset
123 ext_flash_read_block_stop:
heinrichsweikamp
parents:
diff changeset
124 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
125 return ; NO data in WREG
heinrichsweikamp
parents:
diff changeset
126
heinrichsweikamp
parents:
diff changeset
127 global write_byte_ext_flash_plus_header
heinrichsweikamp
parents:
diff changeset
128 write_byte_ext_flash_plus_header: ; Write from WREG and increase address after write
heinrichsweikamp
parents:
diff changeset
129 movwf temp1 ; store data
heinrichsweikamp
parents:
diff changeset
130 ; test if write is done at first byte of 4kB block
heinrichsweikamp
parents:
diff changeset
131 ; if yes -> delete 4kB block first
heinrichsweikamp
parents:
diff changeset
132 tstfsz ext_flash_address+0 ; at 0x00?
heinrichsweikamp
parents:
diff changeset
133 bra write_byte_ext_flash_plus_h1 ; No, normal Write
heinrichsweikamp
parents:
diff changeset
134
heinrichsweikamp
parents:
diff changeset
135 movf ext_flash_address+1,W
heinrichsweikamp
parents:
diff changeset
136 andlw 0x0F ; Mask lower nibble
heinrichsweikamp
parents:
diff changeset
137 tstfsz WREG ; at 0x.0?
heinrichsweikamp
parents:
diff changeset
138 bra write_byte_ext_flash_plus_h1; No, normal Write
heinrichsweikamp
parents:
diff changeset
139
heinrichsweikamp
parents:
diff changeset
140 ; At beginning of 4kB block -> rease first!
heinrichsweikamp
parents:
diff changeset
141 rcall ext_flash_erase4kB ; Erases 4kB sector @ext_flash_address:3
heinrichsweikamp
parents:
diff changeset
142 write_byte_ext_flash_plus_h1:
heinrichsweikamp
parents:
diff changeset
143 movf temp1,W
heinrichsweikamp
parents:
diff changeset
144 rcall ext_flash_byte_write ; Write the byte
heinrichsweikamp
parents:
diff changeset
145 bra incf_ext_flash_address_p1 ; +1 and return
heinrichsweikamp
parents:
diff changeset
146
279
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
147 global write_byte_ext_flash_plus_nocnt ; No increase of ext_flash_dive_counter:3
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
148 write_byte_ext_flash_plus_nocnt:
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
149 movwf temp1 ; store data
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
150 bra write_byte_ext_flash_plus2
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
151
278
dfac47ac2e1d BUGFIX: There was a 1:4096 chance that a portion of a dive was not stored correctly resulting in download issues
heinrichsweikamp
parents: 275
diff changeset
152 global write_byte_ext_flash_plus_nodel ; Does NOT delete 4kB Page when required
279
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
153 write_byte_ext_flash_plus_nodel: ; Write from WREG and increase address after write with banking at 0x200000
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
154 movwf temp1 ; store data
278
dfac47ac2e1d BUGFIX: There was a 1:4096 chance that a portion of a dive was not stored correctly resulting in download issues
heinrichsweikamp
parents: 275
diff changeset
155 bra write_byte_ext_flash_plus1 ; Ignore possible begin of 4kB page, there have been written 0xFF already
6
13cda523891f bugfix: dive length in normal header
heinrichsweikamp
parents: 0
diff changeset
156
0
heinrichsweikamp
parents:
diff changeset
157 global write_byte_ext_flash_plus ; Write from WREG and increase address after write with banking at 0x200000
heinrichsweikamp
parents:
diff changeset
158 write_byte_ext_flash_plus:
heinrichsweikamp
parents:
diff changeset
159 movwf temp1 ; store data
heinrichsweikamp
parents:
diff changeset
160
heinrichsweikamp
parents:
diff changeset
161 ; First, increase dive length counter
heinrichsweikamp
parents:
diff changeset
162 incf ext_flash_dive_counter+0,F
heinrichsweikamp
parents:
diff changeset
163 movlw .0
heinrichsweikamp
parents:
diff changeset
164 addwfc ext_flash_dive_counter+1,F
heinrichsweikamp
parents:
diff changeset
165 addwfc ext_flash_dive_counter+2,F ; 24bit++
heinrichsweikamp
parents:
diff changeset
166
6
13cda523891f bugfix: dive length in normal header
heinrichsweikamp
parents: 0
diff changeset
167 write_byte_ext_flash_plus2:
0
heinrichsweikamp
parents:
diff changeset
168 ; Now test if write is done at first byte of 4kB block
heinrichsweikamp
parents:
diff changeset
169 ; if yes -> delete 4kB block first
heinrichsweikamp
parents:
diff changeset
170 tstfsz ext_flash_address+0 ; at 0x00?
heinrichsweikamp
parents:
diff changeset
171 bra write_byte_ext_flash_plus1 ; No, normal Write
heinrichsweikamp
parents:
diff changeset
172
heinrichsweikamp
parents:
diff changeset
173 movf ext_flash_address+1,W
heinrichsweikamp
parents:
diff changeset
174 andlw 0x0F ; Mask lower nibble
heinrichsweikamp
parents:
diff changeset
175 tstfsz WREG ; at 0x.0?
heinrichsweikamp
parents:
diff changeset
176 bra write_byte_ext_flash_plus1 ; No, normal Write
heinrichsweikamp
parents:
diff changeset
177
heinrichsweikamp
parents:
diff changeset
178 ; At beginning of 4kB block -> erase first!
heinrichsweikamp
parents:
diff changeset
179 rcall ext_flash_erase4kB ; Erases 4kB sector @ext_flash_address:3
heinrichsweikamp
parents:
diff changeset
180 write_byte_ext_flash_plus1:
heinrichsweikamp
parents:
diff changeset
181 movf temp1,W
heinrichsweikamp
parents:
diff changeset
182 rcall ext_flash_byte_write ; Write the byte
heinrichsweikamp
parents:
diff changeset
183 bra incf_ext_flash_address0_p1_0x20 ; +1 and roll over at 0x200000 to 0x000000 and return
heinrichsweikamp
parents:
diff changeset
184
heinrichsweikamp
parents:
diff changeset
185 global ext_flash_byte_write ; Write from WREG
heinrichsweikamp
parents:
diff changeset
186 ext_flash_byte_write:
heinrichsweikamp
parents:
diff changeset
187 movwf temp1 ; store data byte
heinrichsweikamp
parents:
diff changeset
188 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
189 movlw 0x06 ; WREN command
heinrichsweikamp
parents:
diff changeset
190 rcall write_spi
heinrichsweikamp
parents:
diff changeset
191 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
192 movlw 0x02 ; Write command
heinrichsweikamp
parents:
diff changeset
193 rcall write_spi
heinrichsweikamp
parents:
diff changeset
194 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI
heinrichsweikamp
parents:
diff changeset
195 movf temp1,W ; load data byte
heinrichsweikamp
parents:
diff changeset
196 rcall write_spi ; write one byte of data!
heinrichsweikamp
parents:
diff changeset
197 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
198 return
heinrichsweikamp
parents:
diff changeset
199
heinrichsweikamp
parents:
diff changeset
200 global ext_flash_disable_protection ; Disable write protection
heinrichsweikamp
parents:
diff changeset
201 ext_flash_disable_protection:
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
202 ; unlock old memory
0
heinrichsweikamp
parents:
diff changeset
203 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
204 movlw 0x50 ; EWSR command
heinrichsweikamp
parents:
diff changeset
205 rcall write_spi
heinrichsweikamp
parents:
diff changeset
206 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
207
heinrichsweikamp
parents:
diff changeset
208 movlw 0x01 ; WRSR command
heinrichsweikamp
parents:
diff changeset
209 rcall write_spi
heinrichsweikamp
parents:
diff changeset
210 movlw b'00000000' ; New status
heinrichsweikamp
parents:
diff changeset
211 rcall write_spi
heinrichsweikamp
parents:
diff changeset
212 bsf flash_ncs ; CS=1
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
213
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
214 ; unlock new memory
416
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 414
diff changeset
215 ; bsf flash_ncs ; CS=1
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
216 movlw 0x06 ; WREN command
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
217 rcall write_spi
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
218 bsf flash_ncs ; CS=1
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
219 movlw 0x98 ; ULBPR command
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
220 rcall write_spi
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
221 bsf flash_ncs ; CS=1
0
heinrichsweikamp
parents:
diff changeset
222 return
heinrichsweikamp
parents:
diff changeset
223
heinrichsweikamp
parents:
diff changeset
224 global ext_flash_enable_protection
heinrichsweikamp
parents:
diff changeset
225 ext_flash_enable_protection:
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
226 ; lock old memory
0
heinrichsweikamp
parents:
diff changeset
227 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
228 movlw 0x50 ; EWSR command
heinrichsweikamp
parents:
diff changeset
229 rcall write_spi
heinrichsweikamp
parents:
diff changeset
230 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
231
heinrichsweikamp
parents:
diff changeset
232 movlw 0x01 ; WRSR command
heinrichsweikamp
parents:
diff changeset
233 rcall write_spi
heinrichsweikamp
parents:
diff changeset
234 movlw b'00011100' ; New status (Write protect on)
heinrichsweikamp
parents:
diff changeset
235 rcall write_spi
416
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 414
diff changeset
236 ; bsf flash_ncs ; CS=1
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
237
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
238 ; lock new memory
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
239 bsf flash_ncs ; CS=1
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
240 movlw 0x06 ; WREN command
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
241 rcall write_spi
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
242 bsf flash_ncs ; CS=1
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
243 movlw 0x42 ; WBPR command
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
244 rcall write_spi
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
245 movlw .18
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
246 movwf temp1
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
247 ext_flash_enable_protection2:
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
248 movlw 0xFF
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
249 rcall write_spi
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
250 decfsz temp1,F ; 18 bytes with 0xFF
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
251 bra ext_flash_enable_protection2
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
252 bsf flash_ncs ; CS=1
0
heinrichsweikamp
parents:
diff changeset
253 return
heinrichsweikamp
parents:
diff changeset
254
heinrichsweikamp
parents:
diff changeset
255
heinrichsweikamp
parents:
diff changeset
256 global ext_flash_erase4kB ; Erases 4kB sector
heinrichsweikamp
parents:
diff changeset
257 ext_flash_erase4kB:
heinrichsweikamp
parents:
diff changeset
258 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
259 movlw 0x06 ; WREN command
heinrichsweikamp
parents:
diff changeset
260 rcall write_spi
heinrichsweikamp
parents:
diff changeset
261 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
262 movlw 0x20 ; Sector erase command
heinrichsweikamp
parents:
diff changeset
263 rcall write_spi
heinrichsweikamp
parents:
diff changeset
264 rcall ext_flash_write_address ; Write 24bit address ext_flash_address:3 via SPI
heinrichsweikamp
parents:
diff changeset
265 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
266 ; bra ext_flash_wait_write ; Wait for write... and return
heinrichsweikamp
parents:
diff changeset
267 ext_flash_wait_write:
416
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 414
diff changeset
268 WAITMS d'5' ; TBE/TSE=25ms...
0
heinrichsweikamp
parents:
diff changeset
269 movlw 0x05 ; RDSR command
heinrichsweikamp
parents:
diff changeset
270 rcall write_spi ; Read status
heinrichsweikamp
parents:
diff changeset
271 rcall write_spi ; Read status into WREG
heinrichsweikamp
parents:
diff changeset
272 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
273 btfsc SSP2BUF,0 ; Write operation in process?
heinrichsweikamp
parents:
diff changeset
274 bra ext_flash_wait_write ; Yes, wait more..
heinrichsweikamp
parents:
diff changeset
275 return
heinrichsweikamp
parents:
diff changeset
276
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
277 global ext_flash_erase_logbook ; erases logbook memory (000000h -> 2FFFFFh -> 3MByte -> 3145728 Bytes)
0
heinrichsweikamp
parents:
diff changeset
278 ext_flash_erase_logbook:
heinrichsweikamp
parents:
diff changeset
279 bsf flash_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
280 clrf ext_flash_address+0
heinrichsweikamp
parents:
diff changeset
281 clrf ext_flash_address+1
heinrichsweikamp
parents:
diff changeset
282 clrf ext_flash_address+2
heinrichsweikamp
parents:
diff changeset
283
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
284 setf temp1 ; 256*12kB=3145728 Bytes
0
heinrichsweikamp
parents:
diff changeset
285 ext_flash_erase_logbook_loop:
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
286 rcall ext_flash_erase4kB ; 4kB
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
287 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
288 rcall ext_flash_erase4kB ; 4kB
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
289 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
290 rcall ext_flash_erase4kB ; 4kB
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
291 rcall ext_flash_add_4kB ; Increase ext_flash_address:3 by 4kB
0
heinrichsweikamp
parents:
diff changeset
292 decfsz temp1,F
heinrichsweikamp
parents:
diff changeset
293 bra ext_flash_erase_logbook_loop
heinrichsweikamp
parents:
diff changeset
294 return
heinrichsweikamp
parents:
diff changeset
295
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
296 ext_flash_add_4kB:
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
297 movlw 0x10
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
298 addwf ext_flash_address+1,F
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
299 movlw d'0'
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
300 addwfc ext_flash_address+2,F
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
301 return
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
302
0
heinrichsweikamp
parents:
diff changeset
303
heinrichsweikamp
parents:
diff changeset
304 write_spi: ; With data in WREG...
heinrichsweikamp
parents:
diff changeset
305 bcf flash_ncs ; CS
heinrichsweikamp
parents:
diff changeset
306 global write_spi1
heinrichsweikamp
parents:
diff changeset
307 write_spi1: ; With data in WREG...
heinrichsweikamp
parents:
diff changeset
308 bcf SSP2STAT,WCOL ; Clear flag
heinrichsweikamp
parents:
diff changeset
309 movwf SSP2BUF ; Write to buffer
heinrichsweikamp
parents:
diff changeset
310 btfsc SSP2STAT,WCOL ; Was buffer full?
heinrichsweikamp
parents:
diff changeset
311 bra write_spi1 ; Yes, try again
heinrichsweikamp
parents:
diff changeset
312
heinrichsweikamp
parents:
diff changeset
313 write_spi2: ; Wait for write command
heinrichsweikamp
parents:
diff changeset
314 btfss SSP2STAT, BF ; Buffer full?
heinrichsweikamp
parents:
diff changeset
315 bra write_spi2 ; No, wait.
heinrichsweikamp
parents:
diff changeset
316 movf SSP2BUF,W
heinrichsweikamp
parents:
diff changeset
317 return ; Returns RX data in WREG and SSP2BUF
heinrichsweikamp
parents:
diff changeset
318
281
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
319 global fix_180_dives
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
320 fix_180_dives: ; fix dives made with the 1.80
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
321 clrf divesecs ; Here: # of dive (0-255) in TOC
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
322 fix_180_dives2:
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
323 rcall fix_load_dive_into_buffer ; Load header #divesecs into buffer:256
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
324 rcall fix_check_buffer ; Check the buffered dive
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
325 tstfsz WREG ; Dive needs fix?
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
326 rcall fix_buffered_dive ; Yes, fix and save it
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
327 decfsz divesecs,F ; All done?
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
328 bra fix_180_dives2 ; No, continue
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
329 return ; All done.
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
330
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
331 fix_buffered_dive: ; Yes, fix and save it
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
332 rcall ext_flash_disable_protection ; Disable write protection for external flash
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
333 banksel buffer
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
334 ; Set to 1.81
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
335 movlw .81
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
336 movwf buffer+.49
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
337 ; Fix wrong profile length
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
338 movlw .3
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
339 subwf buffer+.9,F
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
340 movlw d'0'
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
341 subwfb buffer+.10,F
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
342 subwfb buffer+.11,F
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
343 banksel common
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
344 ; save result into external flash again
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
345 rcall fix_set_to_toc_start
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
346 clrf lo
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
347 lfsr FSR0,buffer+0
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
348 fix_buffered_dive2:
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
349 movf POSTINC0,W
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
350 rcall write_byte_ext_flash_plus_header; Write from WREG and increase address after write
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
351 decfsz lo,F ; All done?
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
352 bra fix_buffered_dive2 ; No, continue
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
353 return
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
354
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
355 fix_check_buffer: ; Check the buffered dive
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
356 movff buffer+.48,temp1
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
357 movlw .1
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
358 cpfseq temp1 ; buffer+.48 = .1 ?
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
359 retlw .0 ; No, abort
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
360 movff buffer+.49,temp1
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
361 movlw .80
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
362 cpfseq temp1 ; buffer+.49 = .80 ?
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
363 retlw .0 ; No, abort
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
364 retlw .1 ; Yes, fix this dive
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
365
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
366 fix_load_dive_into_buffer: ; Load header #divesecs into buffer:256
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
367 rcall fix_set_to_toc_start
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
368 clrf lo
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
369 lfsr FSR0,buffer+0
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
370 fix_load_dive_into_buffer2:
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
371 rcall ext_flash_byte_read_plus ; increase address after read
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
372 movff temp1,POSTINC0 ; copy into buffer
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
373 decfsz lo,F ; All done?
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
374 bra fix_load_dive_into_buffer2 ; No, continue
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
375
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
376 fix_set_to_toc_start:
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
377 clrf ext_flash_address+0
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
378 clrf ext_flash_address+1
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
379 movlw 0x20
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
380 movwf ext_flash_address+2
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
381 movlw .16
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
382 mulwf divesecs; divesecs*16 = offset to 0x2000 (up:hi)
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
383 movf PRODL,W
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
384 addwf ext_flash_address+1,F
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
385 movf PRODH,W
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
386 addwfc ext_flash_address+2,F
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
387 ; pointer at the first 0xFA of header
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
388 return
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
389
eb758a5b44eb BUGFIX: Fix download issue for dives made with 1.80 firmware
heinrichsweikamp
parents: 279
diff changeset
390
0
heinrichsweikamp
parents:
diff changeset
391 END