annotate src/external_flash.asm @ 633:690c48db7b5b

3.09 beta 2 release
author heinrichsweikamp
date Thu, 05 Mar 2020 15:06:14 +0100
parents 185ba2f91f59
children 4050675965ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
3 ; File external_flash.asm combined next generation V3.08.8
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
16 ext_flash CODE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
17
0
heinrichsweikamp
parents:
diff changeset
18 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
19
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
20 ; increase flash address by one with wrap-around at 0x400000 to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
21 incf_ext_flash_address_p1_0x40:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
22 movlw .1 ; increase by 1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
23 ;bra incf_ext_flash_address0_0x40 ; continue
0
heinrichsweikamp
parents:
diff changeset
24
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
25
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
26 ; increase flash address by value in WREG with wrap-around at 0x400000 to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
27 global incf_ext_flash_address0_0x40
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
28 incf_ext_flash_address0_0x40:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
29 clrf ext_flash_rollover_threshold ; set wrap-around threshold without destroying WREG to ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
30 bsf ext_flash_rollover_threshold,6 ; ... 0x40
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
31 bra incf_ext_flash_address0_common ; continue with common part
0
heinrichsweikamp
parents:
diff changeset
32
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
33
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
34 ; increase flash address by one with wrap-around at 0x200000 to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
35 incf_ext_flash_address_p1_0x20:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
36 movlw .1 ; increase by one
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
37 ;bra incf_ext_flash_address0_0x20 ; continue
0
heinrichsweikamp
parents:
diff changeset
38
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
39
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
40 ; increase flash address by value in WREG with wrap-around at 0x200000 to 0x000000
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
41 global incf_ext_flash_address0_0x20
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
42 incf_ext_flash_address0_0x20:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
43 clrf ext_flash_rollover_threshold ; set wrap-around threshold without destroying WREG to ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
44 bsf ext_flash_rollover_threshold,5 ; ... 0x20
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
45 ;bra incf_ext_flash_address0_common ; continue with common part
0
heinrichsweikamp
parents:
diff changeset
46
heinrichsweikamp
parents:
diff changeset
47
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
48 incf_ext_flash_address0_common:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
49 bcf address_wrap_around ; clear wrap-around flag
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
50 addwf ext_flash_address+0,F ; add WREG to address:3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
51 movlw d'0' ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
52 addwfc ext_flash_address+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
53 addwfc ext_flash_address+2,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
54 movf ext_flash_rollover_threshold,W ; get wrap-around threshold
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
55 cpfseq ext_flash_address+2 ; at wrap-around threshold ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
56 bra incf_ext_flash_address1 ; NO - no wrap-around needed
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
57 ; clrf ext_flash_address+0 ; YES - wrap-around to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
58 ; clrf ext_flash_address+1 ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
59 clrf ext_flash_address+2 ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
60 bsf address_wrap_around ; - set wrap-around flag
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
61 incf_ext_flash_address1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
62 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
63 return ; done
0
heinrichsweikamp
parents:
diff changeset
64
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
65
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
66 ; decrease flash length counter by value in WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
67 global decf_ext_flash_length0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
68 decf_ext_flash_length0:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
69 subwf ext_flash_length_counter+0,F ; decrease address by value in WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
70 movlw d'0' ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
71 subwfb ext_flash_length_counter+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
72 subwfb ext_flash_length_counter+2,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
73 return ; done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
74
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
75 ; ----------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
76
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
77 ; global ext_flash_byte_read_plus_0x40 ; return data read in ext_flash_rw and WREG, increase address after read with wrap-around at 0x400000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
78 ;ext_flash_byte_read_plus_0x40:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
79 ; rcall ext_flash_byte_read ; read byte into ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
80 ; bra incf_ext_flash_address_p1_0x40 ; increase address with wrap-around at 0x400000 to 0x000000 (and return)
0
heinrichsweikamp
parents:
diff changeset
81
heinrichsweikamp
parents:
diff changeset
82
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
83 global ext_flash_byte_read_plus_0x20 ; return data read in ext_flash_rw and WREG, increase address after read with wrap-around at 0x200000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
84 ext_flash_byte_read_plus_0x20:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
85 rcall ext_flash_byte_read ; read byte into ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
86 bra incf_ext_flash_address_p1_0x20 ; increase address with roll-over at 0x200000 to 0x000000 (and return)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
87
0
heinrichsweikamp
parents:
diff changeset
88
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
89 global ext_flash_byte_read ; return data read in WREG and ext_flash_rw, no address change
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
90 ext_flash_byte_read:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
91 movlw 0x03 ; set up read command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
92 rcall shift_spi ; prepare read command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
93 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
94 rcall shift_spi ; shift the SPI to read data into WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
95 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
96 movwf ext_flash_rw ; return data read in WREG and ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
97 return ; done
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
98
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
99 ; ----------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
100 ; read-range base functions
0
heinrichsweikamp
parents:
diff changeset
101
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
102 global ext_flash_read_block_start ; return data read in WREG
0
heinrichsweikamp
parents:
diff changeset
103 ext_flash_read_block_start:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
104 movlw 0x03 ; set up read command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
105 rcall shift_spi ; execute read command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
106 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
107 bra shift_spi ; shift the SPI to read data into WREG (and return)
0
heinrichsweikamp
parents:
diff changeset
108
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
109
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
110 global ext_flash_read_block_0x40 ; return data read in WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
111 ext_flash_read_block_0x40:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
112 rcall incf_ext_flash_address_p1_0x40 ; increase address with wrap-around at 0x400000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
113 btfss address_wrap_around ; did the address wrap-around?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
114 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
115 rcall ext_flash_read_block_stop ; YES - do a block-stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
116 bra ext_flash_read_block_start ; - do a block-start, read data into WREG and return
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
117
0
heinrichsweikamp
parents:
diff changeset
118
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
119 global ext_flash_read_block_0x20 ; return data read in WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
120 ext_flash_read_block_0x20:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
121 rcall incf_ext_flash_address_p1_0x20 ; increase address with wrap-around at 0x200000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
122 btfss address_wrap_around ; did the address wrap-around?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
123 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
124 rcall ext_flash_read_block_stop ; YES - do a block-stop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
125 bra ext_flash_read_block_start ; - do a block-start, read data into WREG and return
0
heinrichsweikamp
parents:
diff changeset
126
heinrichsweikamp
parents:
diff changeset
127
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
128 global ext_flash_read_block_stop ; end block operation
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
129 ext_flash_read_block_stop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
130 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
131 return ; done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
132
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
133 ; ----------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
134 ; read-range function, to be used through macro
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
135 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
136 global ext_flash_read_range
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
137 ext_flash_read_range:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
138 movwf eeprom_loop ; load loop counter (eeprom variable used here)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
139 rcall ext_flash_read_block_start ; read first byte from flash
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
140 bra ext_flash_read_range_loop_start ; jump into loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
141 ext_flash_read_range_loop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
142 rcall ext_flash_read_block_0x40 ; read next byte from flash
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
143 ext_flash_read_range_loop_start:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
144 movwf POSTINC1 ; write byte to memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
145 decfsz eeprom_loop,F ; decrement loop counter, all done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
146 bra ext_flash_read_range_loop ; NO - continue loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
147 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
148
279
62c7af4795b0 bugfix wrong profile length in header
heinrichsweikamp
parents: 278
diff changeset
149
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
150 ; ----------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
151 ; write-range base functions
6
13cda523891f bugfix: dive length in normal header
heinrichsweikamp
parents: 0
diff changeset
152
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
153 ext_flash_write_block_start:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
154 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
155 movlw 0x06 ; set up WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
156 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
157 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
158 movlw 0x02 ; set up write (PP, Page-Program) command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
159 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
160 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
161 movf ext_flash_rw,W ; get byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
162 bra shift_spi ; write the byte (and return)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
163
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
164 ext_flash_write_block:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
165 movf ext_flash_rw,W ; get byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
166 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
167
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
168 ext_flash_write_block_stop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
169 bra ext_flash_wait_write ; wait for completion (and return)
0
heinrichsweikamp
parents:
diff changeset
170
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
171 ; ----------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
172 ; write-range function, to be used through macro
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
173 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
174 global ext_flash_write_range
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
175 ext_flash_write_range:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
176 movwf eeprom_loop ; load loop counter (eeprom variable used here)
633
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
177
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
178 ; btfsc flash_block_write ; does the FLASH support block-write?
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
179 ; bra ext_flash_write_range_block ; YES - write date via block operation
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
180 ; ;bra ext_flash_write_range_seq ; NO - write data via sequential single writes
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
181
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
182 ext_flash_write_range_seq: ; sequential write
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
183 ext_flash_write_range_loop_s:
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
184 movff POSTINC1,ext_flash_rw ; read byte from memory to ext_flash_rw
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
185 rcall ext_flash_byte_write ; write byte from ext_flash_rw to FLASH
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
186 rcall incf_ext_flash_address_p1_0x40 ; increase address with wrap-around at 0x400000
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
187 decfsz eeprom_loop,F ; decrement loop counter, all done?
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
188 bra ext_flash_write_range_loop_s ; NO - continue loop
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
189 return ; YES - done
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
190
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
191 ext_flash_write_range_block: ; block write
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
192 movff POSTINC1,ext_flash_rw ; read first byte from memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
193 rcall ext_flash_write_block_start ; write first byte to FLASH
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
194 bra ext_flash_write_range_loop_start; jump into loop
633
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
195 ext_flash_write_range_loop_b:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
196 movff POSTINC1,ext_flash_rw ; read next byte from memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
197 rcall ext_flash_write_block ; write next byte to FLASH
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
198 ext_flash_write_range_loop_start:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
199 decfsz eeprom_loop,F ; decrement loop counter, all done?
633
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
200 bra ext_flash_write_range_loop_b ; NO - continue loop
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
201 bra ext_flash_write_block_stop ; YES - end writing to flash (and return)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
202
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
203 ; ----------------------------------------------------------------------------
633
690c48db7b5b 3.09 beta 2 release
heinrichsweikamp
parents: 631
diff changeset
204
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
205 ; global write_byte_ext_flash_plus_header
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
206 ; write_byte_ext_flash_plus_header:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
207 ; movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
208 ; ; test if write is done at first byte of 4kB block, if yes delete 4kB block first
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
209 ; tstfsz ext_flash_address+0 ; at 0x....00 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
210 ; bra write_byte_ext_flash_plus_h1 ; NO - normal write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
211 ; movf ext_flash_address+1,W ; YES - get high byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
212 ; andlw 0x0F ; - mask lower nibble
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
213 ; tstfsz WREG ; - at 0x..0...?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
214 ; bra write_byte_ext_flash_plus_h1 ; NO - normal write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
215 ; rcall ext_flash_erase_4kB ; YES - at beginning of 4kB block -> erases 4kB sector @ext_flash_address:3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
216 ;write_byte_ext_flash_plus_h1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
217 ; rcall ext_flash_byte_write ; write the byte in ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
218 ; bra incf_ext_flash_address_p1_0x40 ; increase address with wrap-around at 0x400000 and return
0
heinrichsweikamp
parents:
diff changeset
219
heinrichsweikamp
parents:
diff changeset
220
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
221 global write_byte_ext_flash_plus_prof
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
222 write_byte_ext_flash_plus_prof:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
223 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
224 incf ext_flash_length_counter+0,F ; increase dive length counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
225 movlw .0 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
226 addwfc ext_flash_length_counter+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
227 addwfc ext_flash_length_counter+2,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
228 bra write_byte_ext_flash_plus_nocnt1; continue with checking for begin of new page
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
229
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
230
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
231 global write_byte_ext_flash_plus_nocnt
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
232 write_byte_ext_flash_plus_nocnt:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
233 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
234 write_byte_ext_flash_plus_nocnt1: ; test if write is done at first byte of 4kB block, if yes delete 4kB block first
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
235 tstfsz ext_flash_address+0 ; at 0x....00?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
236 bra write_byte_ext_flash_plus_nodel1; NO - execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
237 movf ext_flash_address+1,W ; YES - mask lower nibble
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
238 andlw 0x0F ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
239 tstfsz WREG ; - at 0x..0...?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
240 bra write_byte_ext_flash_plus_nodel1; NO - execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
241 ; YES - at beginning of 4kB block -> erase first!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
242 rcall ext_flash_erase_4kB ; - erases 4kB sector @ext_flash_address:3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
243 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
244
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
245
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
246 global write_byte_ext_flash_plus_nodel
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
247 write_byte_ext_flash_plus_nodel:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
248 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
249 write_byte_ext_flash_plus_nodel1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
250 rcall ext_flash_byte_write ; write the byte in ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
251 bra incf_ext_flash_address_p1_0x20 ; increase address with wrap-around at 0x200000 and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
252
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
253
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
254 global write_byte_ext_flash_plus_comms ; write from WREG without wait, ~86us fixed delay due to 115200 Baud, use with caution!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
255 write_byte_ext_flash_plus_comms:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
256 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
257 bcf flash_wait ; do not wait on flash write to complete
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
258 rcall ext_flash_byte_write_common ; write the byte in ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
259 bra incf_ext_flash_address_p1_0x40 ; increase address with wrap-around at 0x400000 and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
260
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
261
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
262 ext_flash_byte_write:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
263 bsf flash_wait ; wait for flash write to complete
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
264 ext_flash_byte_write_common:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
265 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
266 movlw 0x06 ; set up WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
267 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
268 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
269 movlw 0x02 ; set up write (PP, Page-Program) command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
270 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
271 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
272 movf ext_flash_rw,W ; get byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
273 rcall shift_spi ; write the byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
274 btfsc flash_wait ; shall wait on flash write to complete?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
275 bra ext_flash_wait_write ; YES - wait for completion (and return)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
276 bsf flash_ncs ; NO - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
277 return ; - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
278
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
279 ; ----------------------------------------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
280
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
281 global ext_flash_disable_protection ; disable write protection
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
282 ext_flash_disable_protection:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
283 ; unlock old memory
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
284 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
285 movlw 0x50 ; EWSR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
286 rcall shift_spi
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
287 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
288 movlw 0x01 ; WRSR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
289 rcall shift_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
290 movlw b'00000000' ; new status
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
291 rcall shift_spi
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
292 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
293 ; unlock new memory
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
294 movlw 0x06 ; WREN command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
295 rcall shift_spi
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
296 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
297 movlw 0x98 ; ULBPR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
298 rcall shift_spi
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
299 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
300 movlw 0x06 ; WREN command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
301 rcall shift_spi
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
302 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
303 movlw 0x42 ; WBPR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
304 rcall shift_spi
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
305 movlw .18 ; 18 bytes to do
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
306 movwf lo ; initialize loop counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
307 ext_flash_disable_prot_loop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
308 movlw 0x00 ; prepare writing a zero
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
309 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
310 decfsz lo,F ; all bytes done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
311 bra ext_flash_disable_prot_loop ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
312 bsf flash_ncs ; YES - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
313 return ; - done
0
heinrichsweikamp
parents:
diff changeset
314
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
315
0
heinrichsweikamp
parents:
diff changeset
316 global ext_flash_enable_protection
heinrichsweikamp
parents:
diff changeset
317 ext_flash_enable_protection:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
318 ; lock old memory
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 0x50 ; prepare EWSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
321 rcall shift_spi ; execute EWSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
322 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
323 movlw 0x01 ; prepare WRSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
324 rcall shift_spi ; execute WRSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
325 movlw b'00011100' ; prepare write protection on
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
326 rcall shift_spi ; execute write protection on
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
327 bsf flash_ncs ; set CS=1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
328 ; lock new memory
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
329 ; movlw 0x06 ; WREN command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
330 ; rcall shift_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
331 ; bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
332 ; movlw 0x8D ; LBPR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
333 ; rcall shift_spi
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
334 ; bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
335 movlw 0x06 ; prepare WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
336 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
337 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
338 movlw 0x42 ; prepare WBPR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
339 rcall shift_spi ; execute WBPR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
340 movlw .18 ; 18 bytes to do
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
341 movwf lo ; initialize loop counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
342 ext_flash_enable_prot_loop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
343 movlw 0xFF ; prepare writing 0xFF
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
344 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
345 decfsz lo,F ; all bytes done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
346 bra ext_flash_enable_prot_loop ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
347 bsf flash_ncs ; YES - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
348 return ; - done
0
heinrichsweikamp
parents:
diff changeset
349
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
350 ; ----------------------------------------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
351
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
352 global erase_complete_logbook
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
353 erase_complete_logbook:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
354 ; clear logbook data in EPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
355 CLRT mpr ; prepare a 3 byte zero integer
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
356 EEPROM_II_WRITE mpr,eeprom_num_dives ; reset total number of dives
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
357 EEPROM_TT_WRITE mpr,eeprom_log_pointer ; reset pointer to begin of log data
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
358 ; erase logbook data in FLASH (0x000000 -> 0x2FFFFF -> 3 MByte -> 3145728 Bytes)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
359 bsf flash_ncs ; CS=1
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
360 clrf ext_flash_address+0 ; set address to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
361 clrf ext_flash_address+1 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
362 clrf ext_flash_address+2 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
363 clrf ext_flash_rw ; write zeros
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
364 ext_flash_erase_logbook_loop: ; 256 * 12 kB = 3.145.728 bytes to do
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
365 rcall ext_flash_erase_4kB ; erase 4kB block
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
366 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
367 rcall ext_flash_erase_4kB ; erase 4kB block
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
368 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
369 rcall ext_flash_erase_4kB ; erase 4kB block
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
370 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
371 decfsz ext_flash_rw,F ; decrement loop counter, done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
372 bra ext_flash_erase_logbook_loop ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
373 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
374
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
375
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
376 global ext_flash_erase_4kB ; erase a 4kB sector
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
377 ext_flash_erase_4kB:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
378 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
379 movlw 0x06 ; prepare WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
380 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
381 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
382 movlw 0x20 ; prepare sector erase command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
383 rcall shift_spi ; execute sector erase command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
384 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
385 bra ext_flash_wait_write ; wait for write to complete and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
386
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
387 ; ----------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
388
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
389 ; send address
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
390 ext_flash_set_address:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
391 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
392 rcall shift_spi ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
393 movf ext_flash_address+1,W ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
394 rcall shift_spi ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
395 movf ext_flash_address+0,W ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
396 bra shift_spi ; ... and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
397
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
398 ; wait on write operation to complete
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
399 ext_flash_wait_write:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
400 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
401 ; WAITMS d'1' ; TBE/TSE=25ms...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
402 movlw 0x05 ; prepare RDSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
403 rcall shift_spi ; 1st cycle: execute command to read status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
404 rcall shift_spi ; 2nd cycle: read status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
405 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
406 btfsc SSP2BUF,0 ; write operation still in process?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
407 bra ext_flash_wait_write ; YES - loop waiting
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
408 return ; NO - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
409
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
410 ; add 0x001000 to flash address
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
411 ext_flash_add_4kB:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
412 movlw 0x10 ; add 0x10 to high byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
413 addwf ext_flash_address+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
414 movlw d'0' ; propagate carry to upper byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
415 addwfc ext_flash_address+2,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
416 return ; done
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
417
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
418 ; shift the SPI bus for a combined write/read: WREG --->\ /---> WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
419 shift_spi: ; flash chip
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
420 bcf flash_ncs ; set CS=0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
421 shift_spi_loop_1:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
422 bcf SSP2STAT,WCOL ; clear flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
423 movwf SSP2BUF ; write to buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
424 btfsc SSP2STAT,WCOL ; was buffer full?
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
425 bra shift_spi_loop_1 ; YES - try again
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
426 shift_spi_loop_2:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
427 btfss SSP2STAT,BF ; buffer full?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
428 bra shift_spi_loop_2 ; NO - loop waiting
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
429 movf SSP2BUF,W ; YES - copy received data to WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
430 return ; - done
0
heinrichsweikamp
parents:
diff changeset
431
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
432 END