0
|
1 ;=============================================================================
|
|
2 ;
|
634
|
3 ; File external_flash.inc * combined next generation V3.09.4e
|
0
|
4 ;
|
|
5 ;
|
654
|
6 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved.
|
0
|
7 ;=============================================================================
|
|
8 ; HISTORY
|
|
9 ; 2011-08-12 : [mH] creation
|
|
10
|
631
|
11
|
|
12 ; FLASH Memory Layout:
|
|
13 ;
|
|
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
|
|
16 ; 0x300000 - 0x3DFFFF 896 kB unused
|
634
|
17 ; 0x3C0000 - 0x3DDFFF 120 kB backup firmware
|
|
18 ; 0x3DE000 - 0x3DFFFF 8 kb unused
|
|
19 ; 0x3E0000 - 0x3FDFFF 120 kB firmware buffer
|
|
20 ; 0x3FE000 - 0x3FFFFF 8 kB reserved for factory use
|
631
|
21
|
|
22
|
|
23 ; Write: WREG -> FLASH with address increment and wrap-around at 0x200000
|
634
|
24 extern ext_flash_write_byte_0x20_incdc ; with increment of ext_flash_dive_counter
|
|
25 extern ext_flash_write_byte_0x20 ; standard flash write
|
|
26 extern ext_flash_write_byte_0x20_nodel ; without delete on entering new page
|
631
|
27
|
582
|
28
|
631
|
29 ; Write: WREG -> FLASH with address increment and wrap-around at 0x400000
|
634
|
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)
|
631
|
31
|
|
32
|
|
33 ; Read: block-read FLASH -> WREG
|
|
34 extern ext_flash_read_block_start ; initial read of one byte at ext_flash_address:3
|
|
35 extern ext_flash_read_block_0x40 ; subsequent read of next byte(s) with wrap-around at 0x400000
|
634
|
36 ; extern ext_flash_read_block_0x20 ; subsequent read of next byte(s) with wrap-around at 0x200000
|
631
|
37 extern ext_flash_read_block_stop ; terminate read
|
0
|
38
|
631
|
39
|
|
40 ; Erase:
|
634
|
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
|
631
|
43 extern erase_complete_logbook ; erase complete logbook (FLASH and EEPROM)
|
582
|
44
|
631
|
45
|
|
46 ; Protection:
|
|
47 extern ext_flash_enable_protection ; enable write protection
|
|
48 extern ext_flash_disable_protection ; disable write protection
|
|
49
|
634
|
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
|
582
|
60
|
0
|
61
|
623
|
62 ;-----------------------------------------------------------------------------
|
|
63 ; Macros
|
631
|
64 ;-----------------------------------------------------------------------------
|
623
|
65
|
631
|
66
|
634
|
67 ; read 1 byte from FLASH to WREG with address increment and wrap-around at 0x200000
|
631
|
68 ;
|
|
69 ; the byte read is also copied to ext_flash_rw
|
|
70 ;
|
|
71 FLASH_CW_READ_0x20 macro
|
634
|
72 extern ext_flash_read_byte_0x20
|
|
73 call ext_flash_read_byte_0x20 ; read from FLASH to WREG
|
631
|
74 endm
|
|
75
|
|
76
|
634
|
77 ; read 1 byte from FLASH to WREG with address increment and wrap-around at 0x400000
|
|
78 ;
|
|
79 ; the byte read is also copied to ext_flash_rw
|
631
|
80 ;
|
634
|
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!
|
631
|
90 ;
|
|
91 FLASH_CC_READ_0x20 macro mem_address
|
634
|
92 extern ext_flash_read_byte_0x20
|
|
93 call ext_flash_read_byte_0x20 ; read from FLASH to WREG
|
|
94 movwf mem_address ; copy from WREG to memory
|
631
|
95 endm
|
|
96
|
|
97
|
|
98 ; read 2 bytes from FLASH to memory with address auto-increment and wrap-around at 0x200000
|
|
99 ;
|
634
|
100 ; mem_address: target address in memory, must be in current bank!
|
631
|
101 ;
|
|
102 FLASH_II_READ_0x20 macro mem_address
|
634
|
103 extern ext_flash_read_byte_0x20
|
|
104 call ext_flash_read_byte_0x20 ; read 1st byte from FLASH to WREG
|
|
105 movwf mem_address+0 ; copy 1st byte from WREG to memory
|
|
106 call ext_flash_read_byte_0x20 ; read 2nd byte from FLASH to WREG
|
|
107 movwf mem_address+1 ; copy 2nd byte from WREG to memory
|
0
|
108 endm
|
|
109
|
631
|
110
|
634
|
111 ; read a range of data from FLASH to memory (destroys WREG, FSR1)
|
|
112 ;
|
631
|
113 ; memory_start: address:2 containing start address in memory
|
|
114 ; range : literal:1 giving the number of bytes to read (1-256)
|
|
115 ;
|
634
|
116 ; Attention: function does NOT check for a wrap-around!
|
|
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
|
631
|
122 lfsr FSR1,memory_start ; set start address in memory
|
|
123 movlw low(range) ; set size of range to read
|
|
124 extern ext_flash_read_range
|
|
125 call ext_flash_read_range ; execute range-read
|
|
126 endm
|
|
127
|
|
128
|
634
|
129 ; write a range of data from memory to FLASH (destroys WREG, FSR1)
|
|
130 ;
|
631
|
131 ; memory_start: address:2 containing start address in memory
|
|
132 ; range : literal:1 giving the number of bytes to write (1-256)
|
|
133 ;
|
634
|
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
|
631
|
141 lfsr FSR1,memory_start ; set start address in memory
|
634
|
142 movlw low(range) ; set size of range to write
|
631
|
143 extern ext_flash_write_range
|
|
144 call ext_flash_write_range ; execute range-write
|
582
|
145 endm
|
|
146
|
631
|
147
|
634
|
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
|
|
157 endm
|
|
158
|
|
159
|
631
|
160 ; move forward in FLASH with wrap-around at 0x400000 to 0x000000
|
|
161 ;
|
|
162 ; increment: literal (1-255)
|
|
163 ;
|
634
|
164 EXT_FLASH_INC_ADDRESS_0x40 macro increment
|
|
165 movlw increment
|
|
166 extern ext_flash_inc_address_0x40_exec
|
|
167 call ext_flash_inc_address_0x40_exec
|
631
|
168 endm
|
|
169
|
|
170
|
|
171 ; move forward in FLASH with wrap-around at 0x200000 to 0x000000
|
|
172 ;
|
|
173 ; increment: literal (1-255)
|
|
174 ;
|
634
|
175 EXT_FLASH_INC_ADDRESS_0x20 macro increment
|
|
176 movlw increment
|
|
177 extern ext_flash_inc_address_0x20_exec
|
|
178 call ext_flash_inc_address_0x20_exec
|
582
|
179 endm
|
631
|
180
|
|
181
|
634
|
182 ; decrement length counter by 1
|
631
|
183 ;
|
634
|
184 EXT_FLASH_DEC_LENGTH macro
|
|
185 extern ext_flash_dec_length_exec
|
|
186 call ext_flash_dec_length_exec
|
631
|
187 endm
|