annotate src/external_flash.asm @ 631:185ba2f91f59

3.09 beta 1 release
author heinrichsweikamp
date Fri, 28 Feb 2020 15:45:07 +0100
parents cd58f7fc86db
children 690c48db7b5b
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)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
177 movff POSTINC1,ext_flash_rw ; read first byte from memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
178 rcall ext_flash_write_block_start ; write first byte to FLASH
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
179 bra ext_flash_write_range_loop_start; jump into loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
180 ext_flash_write_range_loop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
181 movff POSTINC1,ext_flash_rw ; read next byte from memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
182 rcall ext_flash_write_block ; write next byte to FLASH
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
183 ext_flash_write_range_loop_start:
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_write_range_loop ; NO - continue loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
186 bra ext_flash_write_block_stop ; YES - end writing to flash (and return)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
187
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
188 ; ----------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
189
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
190 ; global write_byte_ext_flash_plus_header
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
191 ; write_byte_ext_flash_plus_header:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
192 ; movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
193 ; ; 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
194 ; tstfsz ext_flash_address+0 ; at 0x....00 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
195 ; bra write_byte_ext_flash_plus_h1 ; NO - normal write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
196 ; movf ext_flash_address+1,W ; YES - get high byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
197 ; andlw 0x0F ; - mask lower nibble
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
198 ; tstfsz WREG ; - at 0x..0...?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
199 ; bra write_byte_ext_flash_plus_h1 ; NO - normal write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
200 ; 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
201 ;write_byte_ext_flash_plus_h1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
202 ; rcall ext_flash_byte_write ; write the byte in ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
203 ; bra incf_ext_flash_address_p1_0x40 ; increase address with wrap-around at 0x400000 and return
0
heinrichsweikamp
parents:
diff changeset
204
heinrichsweikamp
parents:
diff changeset
205
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
206 global write_byte_ext_flash_plus_prof
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
207 write_byte_ext_flash_plus_prof:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
208 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
209 incf ext_flash_length_counter+0,F ; increase dive length counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
210 movlw .0 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
211 addwfc ext_flash_length_counter+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
212 addwfc ext_flash_length_counter+2,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
213 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
214
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
215
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
216 global write_byte_ext_flash_plus_nocnt
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
217 write_byte_ext_flash_plus_nocnt:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
218 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
219 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
220 tstfsz ext_flash_address+0 ; at 0x....00?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
221 bra write_byte_ext_flash_plus_nodel1; NO - execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
222 movf ext_flash_address+1,W ; YES - mask lower nibble
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
223 andlw 0x0F ; - ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
224 tstfsz WREG ; - at 0x..0...?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
225 bra write_byte_ext_flash_plus_nodel1; NO - execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
226 ; YES - at beginning of 4kB block -> erase first!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
227 rcall ext_flash_erase_4kB ; - erases 4kB sector @ext_flash_address:3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
228 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
229
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
230
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
231 global write_byte_ext_flash_plus_nodel
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
232 write_byte_ext_flash_plus_nodel:
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_nodel1:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
235 rcall ext_flash_byte_write ; write the byte in ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
236 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
237
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
238
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
239 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
240 write_byte_ext_flash_plus_comms:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
241 movwf ext_flash_rw ; store byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
242 bcf flash_wait ; do not wait on flash write to complete
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
243 rcall ext_flash_byte_write_common ; write the byte in ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
244 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
245
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
246
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
247 ext_flash_byte_write:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
248 bsf flash_wait ; wait for flash write to complete
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
249 ext_flash_byte_write_common:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
250 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
251 movlw 0x06 ; set up WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
252 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
253 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
254 movlw 0x02 ; set up write (PP, Page-Program) command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
255 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
256 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
257 movf ext_flash_rw,W ; get byte to write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
258 rcall shift_spi ; write the byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
259 btfsc flash_wait ; shall wait on flash write to complete?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
260 bra ext_flash_wait_write ; YES - wait for completion (and return)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
261 bsf flash_ncs ; NO - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
262 return ; - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
263
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
264 ; ----------------------------------------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
265
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
266 global ext_flash_disable_protection ; disable write protection
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
267 ext_flash_disable_protection:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
268 ; unlock old memory
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
269 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
270 movlw 0x50 ; EWSR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
271 rcall shift_spi
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
272 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
273 movlw 0x01 ; WRSR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
274 rcall shift_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
275 movlw b'00000000' ; new status
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
276 rcall shift_spi
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
277 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
278 ; unlock new memory
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
279 movlw 0x06 ; WREN command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
280 rcall shift_spi
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
281 bsf flash_ncs ; CS=1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
282 movlw 0x98 ; ULBPR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
283 rcall shift_spi
582
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 0x06 ; WREN 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 0x42 ; WBPR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
289 rcall shift_spi
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
290 movlw .18 ; 18 bytes to do
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
291 movwf lo ; initialize loop counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
292 ext_flash_disable_prot_loop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
293 movlw 0x00 ; prepare writing a zero
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
294 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
295 decfsz lo,F ; all bytes done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
296 bra ext_flash_disable_prot_loop ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
297 bsf flash_ncs ; YES - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
298 return ; - done
0
heinrichsweikamp
parents:
diff changeset
299
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
300
0
heinrichsweikamp
parents:
diff changeset
301 global ext_flash_enable_protection
heinrichsweikamp
parents:
diff changeset
302 ext_flash_enable_protection:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
303 ; lock old memory
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
304 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
305 movlw 0x50 ; prepare EWSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
306 rcall shift_spi ; execute EWSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
307 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
308 movlw 0x01 ; prepare WRSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
309 rcall shift_spi ; execute WRSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
310 movlw b'00011100' ; prepare write protection on
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
311 rcall shift_spi ; execute write protection on
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
312 bsf flash_ncs ; set CS=1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
313 ; lock new memory
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
314 ; movlw 0x06 ; WREN command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
315 ; rcall shift_spi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
316 ; bsf flash_ncs ; CS=1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
317 ; movlw 0x8D ; LBPR command
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
318 ; rcall shift_spi
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 ; prepare 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
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
323 movlw 0x42 ; prepare WBPR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
324 rcall shift_spi ; execute WBPR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
325 movlw .18 ; 18 bytes to do
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
326 movwf lo ; initialize loop counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
327 ext_flash_enable_prot_loop:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
328 movlw 0xFF ; prepare writing 0xFF
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
329 rcall shift_spi ; execute write
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
330 decfsz lo,F ; all bytes done?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
331 bra ext_flash_enable_prot_loop ; NO - loop
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
332 bsf flash_ncs ; YES - set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
333 return ; - done
0
heinrichsweikamp
parents:
diff changeset
334
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
335 ; ----------------------------------------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
336
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
337 global erase_complete_logbook
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
338 erase_complete_logbook:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
339 ; clear logbook data in EPROM
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
340 CLRT mpr ; prepare a 3 byte zero integer
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
341 EEPROM_II_WRITE mpr,eeprom_num_dives ; reset total number of dives
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
342 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
343 ; erase logbook data in FLASH (0x000000 -> 0x2FFFFF -> 3 MByte -> 3145728 Bytes)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
344 bsf flash_ncs ; CS=1
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
345 clrf ext_flash_address+0 ; set address to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
346 clrf ext_flash_address+1 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
347 clrf ext_flash_address+2 ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
348 clrf ext_flash_rw ; write zeros
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
349 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
350 rcall ext_flash_erase_4kB ; erase 4kB block
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
351 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
352 rcall ext_flash_erase_4kB ; erase 4kB block
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
353 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
354 rcall ext_flash_erase_4kB ; erase 4kB block
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
355 rcall ext_flash_add_4kB ; increase ext_flash_address:3 by 4kB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
356 decfsz ext_flash_rw,F ; decrement loop counter, done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
357 bra ext_flash_erase_logbook_loop ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
358 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
359
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
360
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
361 global ext_flash_erase_4kB ; erase a 4kB sector
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
362 ext_flash_erase_4kB:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
363 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
364 movlw 0x06 ; prepare WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
365 rcall shift_spi ; execute WREN command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
366 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
367 movlw 0x20 ; prepare sector erase command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
368 rcall shift_spi ; execute sector erase command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
369 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
370 bra ext_flash_wait_write ; wait for write to complete and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
371
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
372 ; ----------------------------------------------------------------------------
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
373
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
374 ; send address
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
375 ext_flash_set_address:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
376 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
377 rcall shift_spi ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
378 movf ext_flash_address+1,W ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
379 rcall shift_spi ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
380 movf ext_flash_address+0,W ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
381 bra shift_spi ; ... and return
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
382
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
383 ; wait on write operation to complete
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
384 ext_flash_wait_write:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
385 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
386 ; WAITMS d'1' ; TBE/TSE=25ms...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
387 movlw 0x05 ; prepare RDSR command
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
388 rcall shift_spi ; 1st cycle: execute command to read status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
389 rcall shift_spi ; 2nd cycle: read status
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
390 bsf flash_ncs ; set CS=1
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
391 btfsc SSP2BUF,0 ; write operation still in process?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
392 bra ext_flash_wait_write ; YES - loop waiting
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
393 return ; NO - done
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
394
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
395 ; add 0x001000 to flash address
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
396 ext_flash_add_4kB:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
397 movlw 0x10 ; add 0x10 to high byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
398 addwf ext_flash_address+1,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
399 movlw d'0' ; propagate carry to upper byte
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
400 addwfc ext_flash_address+2,F ; ...
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
401 return ; done
414
35bdfd89323c support for new flash memory
heinrichsweikamp
parents: 281
diff changeset
402
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
403 ; shift the SPI bus for a combined write/read: WREG --->\ /---> WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
404 shift_spi: ; flash chip
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
405 bcf flash_ncs ; set CS=0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
406 shift_spi_loop_1:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
407 bcf SSP2STAT,WCOL ; clear flag
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
408 movwf SSP2BUF ; write to buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
409 btfsc SSP2STAT,WCOL ; was buffer full?
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
410 bra shift_spi_loop_1 ; YES - try again
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
411 shift_spi_loop_2:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
412 btfss SSP2STAT,BF ; buffer full?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
413 bra shift_spi_loop_2 ; NO - loop waiting
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
414 movf SSP2BUF,W ; YES - copy received data to WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
415 return ; - done
0
heinrichsweikamp
parents:
diff changeset
416
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
417 END