Mercurial > public > hwos_code
comparison src/external_flash.inc @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 185ba2f91f59 |
children | 75e90cd0c2c3 |
comparison
equal
deleted
inserted
replaced
633:690c48db7b5b | 634:4050675965ea |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File external_flash.inc combined next generation V3.08.8 | 3 ; File external_flash.inc * combined next generation V3.09.4e |
4 ; | 4 ; |
5 ; | 5 ; |
6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
7 ;============================================================================= | 7 ;============================================================================= |
8 ; HISTORY | 8 ; HISTORY |
12 ; FLASH Memory Layout: | 12 ; FLASH Memory Layout: |
13 ; | 13 ; |
14 ; 0x000000 - 0x1FFFFF 2 MB dive profile data, shared ring buffer | 14 ; 0x000000 - 0x1FFFFF 2 MB dive profile data, shared ring buffer |
15 ; 0x200000 - 0x2FFFFF 1 MB dive header data, last 256 dives, 4 kB / dive | 15 ; 0x200000 - 0x2FFFFF 1 MB dive header data, last 256 dives, 4 kB / dive |
16 ; 0x300000 - 0x3DFFFF 896 kB unused | 16 ; 0x300000 - 0x3DFFFF 896 kB unused |
17 ; 0x3E0000 - 0x3DFFFF 120 kB firmware buffer | 17 ; 0x3C0000 - 0x3DDFFF 120 kB backup firmware |
18 ; 0x3E0000 - 0x3FFFFF 8 kB unused | 18 ; 0x3DE000 - 0x3DFFFF 8 kb unused |
19 ; 0x3E0000 - 0x3FDFFF 120 kB firmware buffer | |
20 ; 0x3FE000 - 0x3FFFFF 8 kB reserved for factory use | |
19 | 21 |
20 | 22 |
21 ; Write: WREG -> FLASH with address increment and wrap-around at 0x200000 | 23 ; Write: WREG -> FLASH with address increment and wrap-around at 0x200000 |
22 extern write_byte_ext_flash_plus_prof ; with increase of ext_flash_dive_counter | 24 extern ext_flash_write_byte_0x20_incdc ; with increment of ext_flash_dive_counter |
23 extern write_byte_ext_flash_plus_nocnt ; without increase of ext_flash_dive_counter | 25 extern ext_flash_write_byte_0x20 ; standard flash write |
24 extern write_byte_ext_flash_plus_nodel ; without increase of ext_flash_dive_counter, without delete on entering new page | 26 extern ext_flash_write_byte_0x20_nodel ; without delete on entering new page |
25 | 27 |
26 | 28 |
27 ; Write: WREG -> FLASH with address increment and wrap-around at 0x400000 | 29 ; Write: WREG -> FLASH with address increment and wrap-around at 0x400000 |
28 extern write_byte_ext_flash_plus_comms ; without wait for use with fast comm (~86us fixed delay due to 115200 Bauds - use with caution) | 30 extern ext_flash_write_byte_0x40_nowait ; without wait for use with fast comm (~86us fixed delay due to 115200 Bauds - use with caution) |
29 | 31 |
30 | 32 |
31 ; Read: block-read FLASH -> WREG | 33 ; Read: block-read FLASH -> WREG |
32 extern ext_flash_read_block_start ; initial read of one byte at ext_flash_address:3 | 34 extern ext_flash_read_block_start ; initial read of one byte at ext_flash_address:3 |
33 extern ext_flash_read_block_0x40 ; subsequent read of next byte(s) with wrap-around at 0x400000 | 35 extern ext_flash_read_block_0x40 ; subsequent read of next byte(s) with wrap-around at 0x400000 |
34 extern ext_flash_read_block_0x20 ; subsequent read of next byte(s) with wrap-around at 0x200000 | 36 ; extern ext_flash_read_block_0x20 ; subsequent read of next byte(s) with wrap-around at 0x200000 |
35 extern ext_flash_read_block_stop ; terminate read | 37 extern ext_flash_read_block_stop ; terminate read |
36 | 38 |
37 | 39 |
38 ; Erase: | 40 ; Erase: |
39 extern ext_flash_erase_4kB ; erase one 4 kB sector @ext_flash_address:3 | 41 extern ext_flash_erase_4kB ; erase one 4kB block starting at ext_flash_address:3 |
42 extern ext_flash_erase_range ; erase #WREG 4kB blocks starting at ext_flash_address:3 | |
40 extern erase_complete_logbook ; erase complete logbook (FLASH and EEPROM) | 43 extern erase_complete_logbook ; erase complete logbook (FLASH and EEPROM) |
41 | 44 |
42 | 45 |
43 ; Protection: | 46 ; Protection: |
44 extern ext_flash_enable_protection ; enable write protection | 47 extern ext_flash_enable_protection ; enable write protection |
45 extern ext_flash_disable_protection ; disable write protection | 48 extern ext_flash_disable_protection ; disable write protection |
46 | 49 |
50 ; Misc | |
51 extern ext_flash_read_jedec ; read JEDEC IDs | |
52 extern ext_flash_inc_address_4kB ; increment address by 0x001000, no check for wrap-around | |
53 | |
54 | |
55 IFDEF _firmware_recovery | |
56 ; Firmware Copying | |
57 extern copy_fw_active_to_backup ; copy active firmware code to backup storage | |
58 extern copy_fw_backup_to_active ; copy backup firmware code to update storage | |
59 ENDIF | |
47 | 60 |
48 | 61 |
49 ;----------------------------------------------------------------------------- | 62 ;----------------------------------------------------------------------------- |
50 ; Macros | 63 ; Macros |
51 ;----------------------------------------------------------------------------- | 64 ;----------------------------------------------------------------------------- |
52 | 65 |
53 | 66 |
54 ; read 1 byte from FLASH to WREG with address auto-increment and wrap-around at 0x200000 | 67 ; read 1 byte from FLASH to WREG with address increment and wrap-around at 0x200000 |
55 ; | 68 ; |
56 ; the byte read is also copied to ext_flash_rw | 69 ; the byte read is also copied to ext_flash_rw |
57 ; | 70 ; |
58 FLASH_CW_READ_0x20 macro | 71 FLASH_CW_READ_0x20 macro |
59 extern ext_flash_byte_read_plus_0x20 | 72 extern ext_flash_read_byte_0x20 |
60 call ext_flash_byte_read_plus_0x20 | 73 call ext_flash_read_byte_0x20 ; read from FLASH to WREG |
61 endm | 74 endm |
62 | 75 |
63 | 76 |
64 ; read 1 byte from FLASH to memory with address auto-increment and wrap-around at 0x200000 | 77 ; read 1 byte from FLASH to WREG with address increment and wrap-around at 0x400000 |
65 ; | 78 ; |
66 ; mem_address: address:2 containing target address in memory | 79 ; the byte read is also copied to ext_flash_rw |
80 ; | |
81 FLASH_CW_READ_0x40 macro | |
82 extern ext_flash_read_byte_0x40 | |
83 call ext_flash_read_byte_0x40 ; read from FLASH to WREG | |
84 endm | |
85 | |
86 | |
87 ; read 1 byte from FLASH to memory with address increment and wrap-around at 0x200000 | |
88 ; | |
89 ; mem_address: target address in memory, must be in current bank! | |
67 ; | 90 ; |
68 FLASH_CC_READ_0x20 macro mem_address | 91 FLASH_CC_READ_0x20 macro mem_address |
69 extern ext_flash_byte_read_plus_0x20 | 92 extern ext_flash_read_byte_0x20 |
70 call ext_flash_byte_read_plus_0x20 ; read from flash | 93 call ext_flash_read_byte_0x20 ; read from FLASH to WREG |
71 movff WREG,mem_address ; copy to memory | 94 movwf mem_address ; copy from WREG to memory |
72 endm | 95 endm |
73 | 96 |
74 | 97 |
75 ; read 2 bytes from FLASH to memory with address auto-increment and wrap-around at 0x200000 | 98 ; read 2 bytes from FLASH to memory with address auto-increment and wrap-around at 0x200000 |
76 ; | 99 ; |
77 ; mem_address: address:2 containing start address in memory | 100 ; mem_address: target address in memory, must be in current bank! |
78 ; | 101 ; |
79 FLASH_II_READ_0x20 macro mem_address | 102 FLASH_II_READ_0x20 macro mem_address |
80 extern ext_flash_byte_read_plus_0x20 | 103 extern ext_flash_read_byte_0x20 |
81 call ext_flash_byte_read_plus_0x20 ; read 1st byte from flash | 104 call ext_flash_read_byte_0x20 ; read 1st byte from FLASH to WREG |
82 movff WREG,mem_address+0 ; copy 1st byte to memory | 105 movwf mem_address+0 ; copy 1st byte from WREG to memory |
83 call ext_flash_byte_read_plus_0x20 ; read 2nd byte from flash | 106 call ext_flash_read_byte_0x20 ; read 2nd byte from FLASH to WREG |
84 movff WREG,mem_address+1 ; copy 2nd byte to memory | 107 movwf mem_address+1 ; copy 2nd byte from WREG to memory |
85 endm | 108 endm |
86 | 109 |
87 | 110 |
88 ; read a range of data from FLASH to memory (destroys WREG, FSR1) - wraps around at 0x400000 | 111 ; read a range of data from FLASH to memory (destroys WREG, FSR1) |
89 ; - increments ext_flash_address | 112 ; |
90 ; flash_start : address:3 containing start address in flash | |
91 ; memory_start: address:2 containing start address in memory | 113 ; memory_start: address:2 containing start address in memory |
92 ; range : literal:1 giving the number of bytes to read (1-256) | 114 ; range : literal:1 giving the number of bytes to read (1-256) |
93 ; | 115 ; |
94 FLASH_RR_READ macro flash_start, memory_start, range | 116 ; Attention: function does NOT check for a wrap-around! |
95 MOVTT flash_start,ext_flash_address ; set start address in FLASH | 117 ; |
118 ; -> flash_start is at ext_flash_address | |
119 ; -> ext_flash_address is NOT changed | |
120 ; | |
121 FLASH_RR_READ macro memory_start, range | |
96 lfsr FSR1,memory_start ; set start address in memory | 122 lfsr FSR1,memory_start ; set start address in memory |
97 movlw low(range) ; set size of range to read | 123 movlw low(range) ; set size of range to read |
98 extern ext_flash_read_range | 124 extern ext_flash_read_range |
99 call ext_flash_read_range ; execute range-read | 125 call ext_flash_read_range ; execute range-read |
100 endm | 126 endm |
101 | 127 |
102 | 128 |
103 ; write a range of data from memory to FLASH (destroys WREG, FSR1) - Attention: range must fit into a 256 byte block! | 129 ; write a range of data from memory to FLASH (destroys WREG, FSR1) |
104 ; - does not increment ext_flash_address! | 130 ; |
105 ; memory_start: address:2 containing start address in memory | 131 ; memory_start: address:2 containing start address in memory |
106 ; flash_start : address:3 containing start address in flash | |
107 ; range : literal:1 giving the number of bytes to write (1-256) | 132 ; range : literal:1 giving the number of bytes to write (1-256) |
108 ; | 133 ; |
109 FLASH_RR_WRITE macro memory_start, flash_start, range | 134 ; Attention: low(ext_flash_address) + range must be <= 256 ! |
135 ; | |
136 ; -> flash_start is at ext_flash_address | |
137 ; -> old flash chip: ext_flash_address is incremented according to range parameter | |
138 ; -> new flash chip: ext_flash_address is set to start of next 256 byte block | |
139 ; | |
140 FLASH_RR_WRITE macro memory_start, range | |
110 lfsr FSR1,memory_start ; set start address in memory | 141 lfsr FSR1,memory_start ; set start address in memory |
111 MOVTT flash_start,ext_flash_address ; set start address in FLASH | 142 movlw low(range) ; set size of range to write |
112 movlw low(range) ; set size of range to read | |
113 extern ext_flash_write_range | 143 extern ext_flash_write_range |
114 call ext_flash_write_range ; execute range-write | 144 call ext_flash_write_range ; execute range-write |
145 endm | |
146 | |
147 | |
148 ; set ext_flash_address to a given address | |
149 ; | |
150 EXT_FLASH_ADDR macro address | |
151 movlw LOW (address ) | |
152 movwf ext_flash_address+0 | |
153 movlw HIGH (address & 0xFFFF) | |
154 movwf ext_flash_address+1 | |
155 movlw UPPER (address ) | |
156 movwf ext_flash_address+2 | |
115 endm | 157 endm |
116 | 158 |
117 | 159 |
118 ; move forward in FLASH with wrap-around at 0x400000 to 0x000000 | 160 ; move forward in FLASH with wrap-around at 0x400000 to 0x000000 |
119 ; | 161 ; |
120 ; increment: literal (1-255) | 162 ; increment: literal (1-255) |
121 ; | 163 ; |
122 ext_flash_inc_address_0x40 macro increment | 164 EXT_FLASH_INC_ADDRESS_0x40 macro increment |
123 movlw increment | 165 movlw increment |
124 extern incf_ext_flash_address0_0x40 | 166 extern ext_flash_inc_address_0x40_exec |
125 call incf_ext_flash_address0_0x40 | 167 call ext_flash_inc_address_0x40_exec |
126 endm | 168 endm |
127 | 169 |
128 | 170 |
129 ; move forward in FLASH with wrap-around at 0x200000 to 0x000000 | 171 ; move forward in FLASH with wrap-around at 0x200000 to 0x000000 |
130 ; | 172 ; |
131 ; increment: literal (1-255) | 173 ; increment: literal (1-255) |
132 ; | 174 ; |
133 ext_flash_inc_address_0x20 macro increment | 175 EXT_FLASH_INC_ADDRESS_0x20 macro increment |
134 movlw increment | 176 movlw increment |
135 extern incf_ext_flash_address0_0x20 | 177 extern ext_flash_inc_address_0x20_exec |
136 call incf_ext_flash_address0_0x20 | 178 call ext_flash_inc_address_0x20_exec |
137 endm | 179 endm |
138 | 180 |
139 | 181 |
140 ; decrement length count | 182 ; decrement length counter by 1 |
141 ; | 183 ; |
142 ; decrement: literal (1-255) | 184 EXT_FLASH_DEC_LENGTH macro |
143 ; | 185 extern ext_flash_dec_length_exec |
144 ext_flash_dec_length macro decrement | 186 call ext_flash_dec_length_exec |
145 movlw decrement | |
146 extern decf_ext_flash_length0 | |
147 call decf_ext_flash_length0 | |
148 endm | 187 endm |