annotate src/external_flash.asm @ 653:8bcd138ab744

add tools/o3pack.bat and the required tools/libs
author heinrichsweikamp
date Fri, 11 Aug 2023 15:53:49 +0200
parents 4050675965ea
children 75e90cd0c2c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
3 ; File external_flash.asm * combined next generation V3.09.4e
0
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"
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
14 #include "eeprom_rs232.inc"
0
heinrichsweikamp
parents:
diff changeset
15
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
16 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
17 ext_flash CODE
0
heinrichsweikamp
parents:
diff changeset
18 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
19
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
20 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
21 ; increase Flash Address by one with wrap-around at 0x400000 to 0x000000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
22 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
23 ext_flash_inc_address_0x40_p1:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
24 movlw .1 ; increment by 1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
25 ;bra ext_flash_inc_address_0x40_exec ; execute incrementing
0
heinrichsweikamp
parents:
diff changeset
26
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
27
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
28 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
29 ; increase Flash Address by Value in WREG with wrap-around at 0x400000 to 0x000000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
30 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
31 global ext_flash_inc_address_0x40_exec
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
32 ext_flash_inc_address_0x40_exec:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
33 clrf ext_flash_address_limit ; | set wrap-around threshold to
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
34 bsf ext_flash_address_limit,6 ; | 0x40 without destroying WREG
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
35 bra incf_ext_flash_address0_common ; continue with common part
0
heinrichsweikamp
parents:
diff changeset
36
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
37
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
38 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
39 ; increase Flash Address by one with wrap-around at 0x200000 to 0x000000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
40 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
41 ext_flash_inc_address_0x20_p1:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
42 movlw .1 ; increment by one
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
43 ;bra ext_flash_inc_address_0x20_exec ; execute incrementing
0
heinrichsweikamp
parents:
diff changeset
44
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
45
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
46 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
47 ; increase Flash Address by Value in WREG with wrap-around at 0x200000 to 0x000000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
48 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
49 global ext_flash_inc_address_0x20_exec
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
50 ext_flash_inc_address_0x20_exec:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
51 clrf ext_flash_address_limit ; | set wrap-around threshold to
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
52 bsf ext_flash_address_limit,5 ; | 0x20 without destroying WREG
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
53 ;bra incf_ext_flash_address0_common ; continue with common part
0
heinrichsweikamp
parents:
diff changeset
54
heinrichsweikamp
parents:
diff changeset
55
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
56 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
57 ; common Part for Flash Address Increasing
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
58 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
59 incf_ext_flash_address0_common:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
60 bcf flash_wrap_around ; clear wrap-around flag
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
61 addwf ext_flash_address+0,F ; add WREG to address:3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
62 movlw d'0' ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
63 addwfc ext_flash_address+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
64 addwfc ext_flash_address+2,F ; ...
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
65 movf ext_flash_address_limit,W ; get wrap-around threshold
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
66 cpfseq ext_flash_address+2 ; at wrap-around threshold ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
67 bra incf_ext_flash_address1 ; NO - no wrap-around needed
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
68 ; clrf ext_flash_address+0 ; YES - wrap-around to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
69 ; clrf ext_flash_address+1 ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
70 clrf ext_flash_address+2 ; - ...
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
71 bsf flash_wrap_around ; - set wrap-around flag
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
72 incf_ext_flash_address1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
73 movf ext_flash_rw,W ; export current value of ext_flash_rw via WREG, too
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
74 return ; done
0
heinrichsweikamp
parents:
diff changeset
75
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
76
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
77 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
78 ; add 0x001000 to Flash Address, no Check for wrap-around
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
79 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
80 global ext_flash_inc_address_4kB
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
81 ext_flash_inc_address_4kB:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
82 movlw 0x10 ; add 0x10 to high byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
83 addwf ext_flash_address+1,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
84 movlw 0x00 ; propagate carry to upper byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
85 addwfc ext_flash_address+2,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
86 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
87
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
88
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
89 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
90 ; decrement Length Counter by 1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
91 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
92 global ext_flash_dec_length_exec
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
93 ext_flash_dec_length_exec:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
94 movlw .1 ; decrement by 1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
95 subwf ext_flash_length_counter+0,F ; ...
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
96 movlw d'0' ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
97 subwfb ext_flash_length_counter+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
98 subwfb ext_flash_length_counter+2,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
99 return ; done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
100
0
heinrichsweikamp
parents:
diff changeset
101
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
102 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
103 ; read a Byte from Flash and increment Address with wrap-around at 0x20 / 0x40
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
104 ; returns in ext_flash_rw and WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
105 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
106 global ext_flash_read_byte_0x40
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
107 ext_flash_read_byte_0x40:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
108 bsf flash_wrap_around ; wrap-around at 0x400000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
109 bra ext_flash_read_byte_common ; continue with common part
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
110
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
111 global ext_flash_read_byte_0x20
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
112 ext_flash_read_byte_0x20:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
113 bcf flash_wrap_around ; wrap-around at 0x200000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
114 ;bra ext_flash_read_byte_common ; continue with common part
0
heinrichsweikamp
parents:
diff changeset
115
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
116 ext_flash_read_byte_common:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
117 movlw 0x03 ; prepare read command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
118 rcall shift_spi ; execute read command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
119 rcall ext_flash_set_address ; write 24 bit address ext_flash_address:3 via SPI
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
120 rcall shift_spi ; shift the SPI to read data into WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
121 bsf flash_ncs ; set CS=1
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
122 movwf ext_flash_rw ; copy byte read from WREG to ext_flash_rw
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
123 btfss flash_wrap_around ; shall wrap-around at 0x40000 ?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
124 bra ext_flash_inc_address_0x20_p1 ; NO - increment address with wrap-around at 0x200000 and return
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
125 bra ext_flash_inc_address_0x40_p1 ; YES - increment address with wrap-around at 0x200000 and return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
126
0
heinrichsweikamp
parents:
diff changeset
127
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
128 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
129 ; Read-Range Base Functions - start reading
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
130 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
131 global ext_flash_read_block_start ; return data read in WREG
0
heinrichsweikamp
parents:
diff changeset
132 ext_flash_read_block_start:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
133 movlw 0x03 ; set up read command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
134 rcall shift_spi ; execute read command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
135 rcall ext_flash_set_address ; write 24 bit address ext_flash_address:3 via SPI
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
136 bra shift_spi ; shift the SPI to read data into WREG (and return)
0
heinrichsweikamp
parents:
diff changeset
137
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
138
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
139 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
140 ; Read-Range Base Functions - increment Address and read a Byte, wrap-around at 0x40
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
141 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
142 global ext_flash_read_block_0x40 ; return data read in WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
143 ext_flash_read_block_0x40:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
144 rcall ext_flash_inc_address_0x40_p1 ; increase address with wrap-around at 0x400000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
145 btfss flash_wrap_around ; did the address wrap-around?
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
146 bra shift_spi_loop_1 ; NO - shift the SPI to read data into WREG and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
147 rcall ext_flash_read_block_stop ; YES - do a block-stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
148 bra ext_flash_read_block_start ; - do a block-start, read data into WREG and return
0
heinrichsweikamp
parents:
diff changeset
149
heinrichsweikamp
parents:
diff changeset
150
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
151 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
152 ; Read-Range Base Functions - increment Address and read a Byte, wrap-around at 0x20
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
153 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
154 ; global ext_flash_read_block_0x20 ; return data read in WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
155 ;ext_flash_read_block_0x20:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
156 ; rcall ext_flash_inc_address_0x20_p1 ; increase address with wrap-around at 0x200000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
157 ; btfss flash_wrap_around ; did the address wrap-around?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
158 ; bra shift_spi_loop_1 ; NO - shift the SPI to read data into WREG and return
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
159 ; rcall ext_flash_read_block_stop ; YES - do a block-stop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
160 ; bra ext_flash_read_block_start ; - do a block-start, read data into WREG and return
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
161
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
162
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
163 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
164 ; Read-Range Base Functions - terminate reading
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
165 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
166 global ext_flash_read_block_stop ; end block operation
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
167 ext_flash_read_block_stop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
168 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
169 return ; done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
170
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
171
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
172 ; ----------------------------------------------------------------------------
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
173 ; read a Range of Bytes, to be used via Macro
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
174 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
175 global ext_flash_read_range
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
176 ext_flash_read_range:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
177 movwf eeprom_loop ; load loop counter (eeprom variable used here)
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
178 rcall ext_flash_read_block_start ; read first byte from FLASH to WREG
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
179 bra ext_flash_read_range_loop_start ; jump into loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
180 ext_flash_read_range_loop:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
181 rcall shift_spi_loop_1 ; read next byte from FLASH to WREG
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
182 ext_flash_read_range_loop_start:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
183 movwf POSTINC1 ; write byte from WREG to memory
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
184 decfsz eeprom_loop,F ; decrement loop counter, all done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
185 bra ext_flash_read_range_loop ; NO - continue loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
186 bra ext_flash_read_block_stop ; YES - end reading from flash (and return)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
187
279
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
188
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
189 ; ----------------------------------------------------------------------------
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
190 ; Write-Range Base Functions - for use with SST26VF Chip only!
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
191 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
192 ext_flash_write_block_start:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
193 movwf ext_flash_rw ; copy byte to write from WREG to ext_flash_rw
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
194 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
195 movlw 0x06 ; set up WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
196 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
197 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
198 movlw 0x02 ; set up write (PP, Page-Program) command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
199 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
200 rcall ext_flash_set_address ; write 24 bit address ext_flash_address:3 via SPI
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
201 movf ext_flash_rw,W ; get back byte to write
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
202 bra shift_spi ; write the byte (and return)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
203
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
204 ext_flash_write_block:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
205 bra shift_spi_loop_1 ; shift the SPI to write data into FLASH (and return)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
206
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
207 ext_flash_write_block_stop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
208 bra ext_flash_wait_write ; wait for completion (and return)
0
heinrichsweikamp
parents:
diff changeset
209
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
210
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
211 ; ----------------------------------------------------------------------------
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
212 ; write a Range of Bytes, to be used via Macro
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
213 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
214 global ext_flash_write_range
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
215 ext_flash_write_range:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
216 movwf eeprom_loop ; load loop counter (eeprom variable used here)
633
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
217
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
218 btfsc flash_block_write ; does the FLASH support block-write?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
219 bra ext_flash_write_range_block ; YES - write data in block mode
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
220 ;bra ext_flash_write_range_seq ; NO - write data in sequential mode
633
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
221
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
222 ; sequential write
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
223 ext_flash_write_range_seq:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
224 bsf flash_wait ; wait for flash writes to complete
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
225 ext_flash_write_range_seq_loop:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
226 movf POSTINC1,W ; copy byte from memory to WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
227 rcall ext_flash_byte_write_common_W ; write byte from WREG to FLASH
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
228 rcall ext_flash_inc_address_0x40_p1 ; increase address with wrap-around at 0x400000
633
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
229 decfsz eeprom_loop,F ; decrement loop counter, all done?
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
230 bra ext_flash_write_range_seq_loop ; NO - loop
633
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
231 return ; YES - done
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
232
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
233 ; block write
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
234 ext_flash_write_range_block:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
235 movf POSTINC1,W ; copy first byte from memory to WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
236 rcall ext_flash_write_block_start ; copy first byte from WREG to FLASH
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
237 bra ext_flash_write_range_loop_start; jump into loop
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
238 ext_flash_write_range_block_loop:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
239 movf POSTINC1,W ; copy next byte from memory to WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
240 rcall ext_flash_write_block ; copy next byte from WREG to FLASH
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
241 ext_flash_write_range_loop_start:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
242 decfsz eeprom_loop,F ; decrement loop counter, all done?
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
243 bra ext_flash_write_range_block_loop; NO - loop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
244 rcall ext_flash_write_block_stop ; YES - initiate FLASH write
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
245 clrf ext_flash_address+0 ; - advance address to start of next block
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
246 infsnz ext_flash_address+1,F ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
247 incf ext_flash_address+2,F ; - ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
248 return ; - done
0
heinrichsweikamp
parents:
diff changeset
249
heinrichsweikamp
parents:
diff changeset
250
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
251 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
252 ; write a Byte with wrap-around at 0x200000,
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
253 ; erase on entering new 4kB Block,
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
254 ; increment Dive Length Counter
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
255 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
256 global ext_flash_write_byte_0x20_incdc
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
257 ext_flash_write_byte_0x20_incdc:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
258 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
259 incf ext_flash_length_counter+0,F ; increase dive length counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
260 movlw .0 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
261 addwfc ext_flash_length_counter+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
262 addwfc ext_flash_length_counter+2,F ; ...
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
263 bra write_byte_ext_flash_plus_nocnt1; continue with checking for begin of new block
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
264
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
265
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
266 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
267 ; write a Byte with wrap-around at 0x200000,
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
268 ; erase on entering new 4kB Block
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
269 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
270 global ext_flash_write_byte_0x20
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
271 ext_flash_write_byte_0x20:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
272 movwf ext_flash_rw ; store byte to write
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
273 write_byte_ext_flash_plus_nocnt1:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
274 ; check if at 1st byte of a 4kB block,
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
275 ; if yes the block needs to be erased
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
276 ; before new data can be written to it
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
277 tstfsz ext_flash_address+0 ; is the low byte of the address = 0x00 ?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
278 bra write_byte_ext_flash_plus_nodel1; NO - not at 1st byte, can execute write
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
279 movf ext_flash_address+1,W ; YES - get high byte of the address
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
280 andlw 0x0F ; - keep only the lower nibble
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
281 tstfsz WREG ; - is the lower nibble = 0x0 ?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
282 bra write_byte_ext_flash_plus_nodel1; NO - not at 1st byte, can execute write
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
283 rcall ext_flash_erase_4kB ; YES - at 1st byte, erase 4kB block
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
284 bra write_byte_ext_flash_plus_nodel1; - execute write
423
ccaaac45b61a _another_ timing fix for firmware updates (2.07 was not published yet anyway)
heinrichsweikamp
parents: 421
diff changeset
285
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
286
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
287 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
288 ; write a Byte with wrap-around at 0x200000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
289 ; NO erase on entering new 4kB Block
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
290 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
291 global ext_flash_write_byte_0x20_nodel
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
292 ext_flash_write_byte_0x20_nodel:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
293 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
294 write_byte_ext_flash_plus_nodel1:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
295 bsf flash_wait ; wait for flash write to complete
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
296 rcall ext_flash_byte_write_common_F ; write the byte in ext_flash_rw
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
297 bra ext_flash_inc_address_0x20_p1 ; increase address with wrap-around at 0x200000 and return
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
298
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
299
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
300 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
301 ; write a Byte without Wait (used by comm mode)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
302 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
303 ; time budget for flash to complete a write is ~86 us at 115200 Baud on serial
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
304 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
305 global ext_flash_write_byte_0x40_nowait
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
306 ext_flash_write_byte_0x40_nowait:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
307 bcf flash_wait ; do not wait on flash write to complete
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
308 rcall ext_flash_byte_write_common_W ; write the byte in WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
309 bra ext_flash_inc_address_0x40_p1 ; increase address with wrap-around at 0x400000 and return
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
310
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
311
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
312 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
313 ; internal common Write Functions W: WREG -> FLASH(ext_flash_address)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
314 ; F: ext_flash_rw -> FLASH(ext_flash_address)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
315 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
316 ext_flash_byte_write_common_W:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
317 movwf ext_flash_rw ; copy byte to write from WREG to ext_flash_rw
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
318 ext_flash_byte_write_common_F:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
319 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
320 movlw 0x06 ; set up WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
321 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
322 bsf flash_ncs ; set CS=1
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
323 movlw 0x02 ; prepare write (PP, Page-Program) command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
324 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
325 rcall ext_flash_set_address ; write 24 bit address ext_flash_address:3 via SPI
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
326 movf ext_flash_rw,W ; get back byte to write
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
327 rcall shift_spi ; write the byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
328 btfsc flash_wait ; shall wait on flash write to complete?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
329 bra ext_flash_wait_write ; YES - wait for completion (and return)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
330 bsf flash_ncs ; NO - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
331 return ; - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
332
0
heinrichsweikamp
parents:
diff changeset
333
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
334 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
335 ; switch off Write-Protection
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
336 ;
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
337 global ext_flash_disable_protection ; disable write protection
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
338 ext_flash_disable_protection:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
339 ; unlock old memory
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
340 bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
341 movlw 0x50 ; prepare EWSR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
342 rcall shift_spi ; execute EWSR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
343 bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
344 movlw 0x01 ; prepare WRSR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
345 rcall shift_spi ; execute WRSR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
346 movlw b'00000000' ; prepare new status
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
347 rcall shift_spi ; set new status
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
348
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
349 ; unlock new memory
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
350 bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
351 movlw 0x06 ; prepare WREN command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
352 rcall shift_spi ; execute WREN command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
353 bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
354 movlw 0x98 ; prepare ULBPR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
355 rcall shift_spi ; execute ULBPR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
356 bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
357 movlw 0x06 ; prepare WREN command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
358 rcall shift_spi ; execute WREN command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
359 bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
360 movlw 0x42 ; prepare WBPR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
361 rcall shift_spi ; execute WBPR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
362
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
363 movlw .18 ; 18 bytes to do
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
364 movwf lo ; initialize loop counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
365 ext_flash_disable_prot_loop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
366 movlw 0x00 ; prepare writing a zero
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
367 rcall shift_spi ; write a zero
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
368 decfsz lo,F ; all bytes done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
369 bra ext_flash_disable_prot_loop ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
370 bsf flash_ncs ; YES - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
371 return ; - done
0
heinrichsweikamp
parents:
diff changeset
372
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
373
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
374 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
375 ; switch on Write-Protection
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
376 ;
0
heinrichsweikamp
parents:
diff changeset
377 global ext_flash_enable_protection
heinrichsweikamp
parents:
diff changeset
378 ext_flash_enable_protection:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
379 ; lock old memory
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
380 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
381 movlw 0x50 ; prepare EWSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
382 rcall shift_spi ; execute EWSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
383 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
384 movlw 0x01 ; prepare WRSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
385 rcall shift_spi ; execute WRSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
386 movlw b'00011100' ; prepare write protection on
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
387 rcall shift_spi ; execute write protection on
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
388
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
389 ; lock new memory
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
390 bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
391 ; movlw 0x06 ; prepare WREN command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
392 ; rcall shift_spi ; execute WREN command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
393 ; bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
394 ; movlw 0x8D ; prepare LBPR command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
395 ; rcall shift_spi ; execute LBPR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
396 ; bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
397 movlw 0x06 ; prepare WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
398 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
399 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
400 movlw 0x42 ; prepare WBPR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
401 rcall shift_spi ; execute WBPR command
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
402
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
403 movlw .18 ; 18 bytes to do
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
404 movwf lo ; initialize loop counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
405 ext_flash_enable_prot_loop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
406 movlw 0xFF ; prepare writing 0xFF
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
407 rcall shift_spi ; write a zero
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
408 decfsz lo,F ; all bytes done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
409 bra ext_flash_enable_prot_loop ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
410 bsf flash_ncs ; YES - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
411 return ; - done
0
heinrichsweikamp
parents:
diff changeset
412
heinrichsweikamp
parents:
diff changeset
413
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
414 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
415 ; erase complete Logbook
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
416 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
417 global erase_complete_logbook
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
418 erase_complete_logbook:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
419 ; set address to 0x000000 / prepare a 3 byte zero integer
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
420 CLRT ext_flash_address
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
421
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
422 ; clear logbook data in EPROM by writing all zeros
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
423 EEPROM_II_WRITE ext_flash_address,eeprom_num_dives ; reset the total number of dives
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
424 EEPROM_TT_WRITE ext_flash_address,eeprom_log_pointer ; reset pointer to begin of profile data
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
425
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
426 ; erase logbook data in FLASH from 0x000000 - 0x2FFFFF = 3 MByte = 3 * 256 blocks * 4 kB/block
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
427
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
428 clrf WREG ; erase 256 blocks per call
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
429 rcall ext_flash_erase_range ; erase 1st bunch of 256 blocks
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
430 rcall ext_flash_erase_range_loop ; erase 2nd bunch of 256 blocks
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
431 rcall ext_flash_erase_range_loop ; erase 3rd bunch of 256 blocks
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
432 return ; done
0
heinrichsweikamp
parents:
diff changeset
433
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
434
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
435 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
436 ; erase a Number of 4kB Blocks
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
437 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
438 global ext_flash_erase_range
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
439 ext_flash_erase_range:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
440 movwf eeprom_loop ; initialize loop counter
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
441 ext_flash_erase_range_loop:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
442 rcall ext_flash_erase_4kB ; erase one block
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
443 rcall ext_flash_inc_address_4kB ; increase start address by 0x1000 (4kB)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
444 btfsc ext_flash_address+2,6 ; reached 0x400000 ?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
445 return ; YES - reached end of address range, done anyhow
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
446 decfsz eeprom_loop,F ; NO - decrement number of blocks to do, all blocks done?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
447 bra ext_flash_erase_range_loop ; NO - loop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
448 return ; YES - done, back to command loop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
449
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
450
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
451 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
452 ; erase one 4kB Block
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
453 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
454 global ext_flash_erase_4kB
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
455 ext_flash_erase_4kB:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
456 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
457 movlw 0x06 ; prepare WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
458 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
459 bsf flash_ncs ; set CS=1
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
460 movlw 0x20 ; prepare block erase command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
461 rcall shift_spi ; execute block erase command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
462 rcall ext_flash_set_address ; write 24 bit address ext_flash_address:3 via SPI
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
463 bra ext_flash_wait_write ; wait for write to complete and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
464
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
465
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
466 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
467 ; read JEDEC IDs
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
468 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
469 global ext_flash_read_jedec
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
470 ext_flash_read_jedec:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
471 movlw 0x9F ; prepare JEDEC read command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
472 rcall shift_spi ; execute JEDEC read command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
473 rcall shift_spi ; shift the SPI to read the manufacturer ID into WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
474 movwf lo ; store the manufacturer ID in lo
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
475 rcall shift_spi ; shift the SPI to read the device type ID into WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
476 movwf hi ; store the device type ID in hi
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
477 rcall shift_spi ; shift the SPI to read the device model ID into WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
478 movwf up ; store the device model ID in up
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
479 bsf flash_ncs ; set CS=1
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
480 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
481
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
482
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
483 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
484 ; low level Functions - send Address
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
485 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
486 ext_flash_set_address:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
487 movf ext_flash_address+2,W ; write 24 bit address ext_flash_address:3 via SPI
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
488 rcall shift_spi ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
489 movf ext_flash_address+1,W ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
490 rcall shift_spi ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
491 movf ext_flash_address+0,W ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
492 bra shift_spi ; ... and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
493
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
494
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
495 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
496 ; low level Functions - wait for Completion of a Write Operation
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
497 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
498 ext_flash_wait_write:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
499 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
500 ; WAITMS d'1' ; TBE/TSE=25ms...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
501 movlw 0x05 ; prepare RDSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
502 rcall shift_spi ; 1st cycle: execute command to read status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
503 rcall shift_spi ; 2nd cycle: read status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
504 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
505 btfsc SSP2BUF,0 ; write operation still in process?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
506 bra ext_flash_wait_write ; YES - loop waiting
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
507 return ; NO - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
508
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
509
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
510 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
511 ; low level functions - shift the SPI Bus for a combined Write/Read
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
512 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
513 ; WREG --> write --->\ /---> read --> WREG
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
514 ; flash chip
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
515 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
516 shift_spi:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
517 bcf flash_ncs ; set CS=0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
518 shift_spi_loop_1:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
519 bcf SSP2STAT,WCOL ; clear flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
520 movwf SSP2BUF ; write to buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
521 btfsc SSP2STAT,WCOL ; was buffer full?
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
522 bra shift_spi_loop_1 ; YES - try again
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
523 shift_spi_loop_2:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
524 btfss SSP2STAT,BF ; buffer full?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
525 bra shift_spi_loop_2 ; NO - loop waiting
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
526 movf SSP2BUF,W ; YES - copy received data to WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
527 return ; - done
0
heinrichsweikamp
parents:
diff changeset
528
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
529
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
530 IFDEF _firmware_recovery
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
531
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
532 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
533 ; copy active Firmware to Backup Storage
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
534 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
535 global copy_fw_active_to_backup
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
536 copy_fw_active_to_backup:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
537 ; erase FLASH for recovery firmware (120 kByte = 30 * 4 kByte)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
538 rcall ext_flash_to_recovery_fw ; set ext_flash_address to 0x3C0000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
539 movlw .30 ; 30 blocks to do
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
540 rcall ext_flash_erase_range ; erase #WREG 4kB blocks starting at ext_flash_address
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
541
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
542 ; copy firmware (120 kByte = 2 x 240 x 256 byte)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
543 rcall ext_flash_to_productive_fw ; set ext_flash_address to 0x3E0000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
544 clrf hi ; flag in 1st round
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
545 copy_fw_active_to_backup_loop1:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
546 movlw .240 ; load loop counter
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
547 movwf lo ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
548 copy_fw_active_to_backup_loop2:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
549 ; read active firmware
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
550 bsf ext_flash_address+2,1 ; switch to productive firmware
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
551 lfsr FSR1,buffer ; set start address in memory
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
552 movlw low(.256) ; set size of range to read
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
553 rcall ext_flash_read_range ; execute range-read (ext_flash_address NOT incremented)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
554 ; write to backup storage
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
555 bcf ext_flash_address+2,1 ; switch to backup storage
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
556 lfsr FSR1,buffer ; set start address in memory
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
557 movlw low(.256) ; set size of range to write
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
558 rcall ext_flash_write_range ; execute range-write (ext_flash_address GETS incremented)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
559 ; operate loop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
560 decfsz lo,F ; decrement loop counter, done?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
561 bra copy_fw_active_to_backup_loop2 ; NO - continue copying
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
562 tstfsz hi ; YES - 2nd round finished?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
563 return ; YES - done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
564 setf hi ; NO - flag in 2nd round now
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
565 bra copy_fw_active_to_backup_loop1 ; - start 2nd round
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
566
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
567
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
568 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
569 ; copy Backup-Firmware to Update Storage
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
570 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
571 global copy_fw_backup_to_active
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
572 copy_fw_backup_to_active:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
573 ; erase FLASH for productive firmware (120 kByte = 30 * 4 kByte)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
574 rcall ext_flash_to_productive_fw ; set ext_flash_address to 0x3E0000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
575 movlw .30 ; 30 blocks to do
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
576 rcall ext_flash_erase_range ; erase #WREG 4kB blocks starting at ext_flash_address
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
577
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
578 ; copy firmware (120 kByte = 2 x 240 x 256 byte)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
579 rcall ext_flash_to_recovery_fw ; set ext_flash_address to 0x3C0000
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
580 clrf hi ; flag in 1st round
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
581 copy_fw_backup_to_active_loop1:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
582 movlw .240 ; load loop counter
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
583 movwf lo ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
584 copy_fw_backup_to_active_loop2:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
585 ; read backup firmware
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
586 bcf ext_flash_address+2,1 ; switch to backup firmware
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
587 lfsr FSR1,buffer ; set start address in memory
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
588 movlw low(.256) ; set size of range to read
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
589 rcall ext_flash_read_range ; execute range-read (ext_flash_address NOT incremented)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
590 ; write to update storage
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
591 bsf ext_flash_address+2,1 ; switch to update storage
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
592 lfsr FSR1,buffer ; set start address in memory
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
593 movlw low(.256) ; set size of range to write
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
594 rcall ext_flash_write_range ; execute range-write (ext_flash_address GETS incremented)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
595 ; operate loop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
596 decfsz lo,F ; decrement loop counter, done?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
597 bra copy_fw_backup_to_active_loop2 ; NO - continue copying
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
598 tstfsz hi ; YES - 2nd round finished?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
599 return ; YES - done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
600 setf hi ; NO - flag in 2nd round now
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
601 bra copy_fw_backup_to_active_loop1 ; - start 2nd round
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
602
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
603
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
604 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
605 ; Helper Functions - point ext_flash_address to active / backup firmware storage
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
606 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
607 ext_flash_to_recovery_fw
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
608 movlw 0x3C ; 0x3C|
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
609 bra ext_flash_common
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
610
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
611 ext_flash_to_productive_fw:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
612 movlw 0x3E ; 0x3E|
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
613 ;bra ext_flash_common
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
614
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
615 ext_flash_common:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
616 movwf ext_flash_address+2 ; ....|
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
617 clrf ext_flash_address+1 ; ....|00|
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
618 clrf ext_flash_address+0 ; .......|00
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
619 return
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
620
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
621 ENDIF
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
622
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
623 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 633
diff changeset
624
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
625 END