annotate src/external_flash.inc @ 631:185ba2f91f59

3.09 beta 1 release
author heinrichsweikamp
date Fri, 28 Feb 2020 15:45:07 +0100
parents c40025d8e750
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: 623
diff changeset
3 ; File external_flash.inc combined next generation V3.08.8
0
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ;
heinrichsweikamp
parents:
diff changeset
6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
7 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
8 ; HISTORY
heinrichsweikamp
parents:
diff changeset
9 ; 2011-08-12 : [mH] creation
heinrichsweikamp
parents:
diff changeset
10
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
11
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
12 ; FLASH Memory Layout:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
13 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
14 ; 0x000000 - 0x1FFFFF 2 MB dive profile data, shared ring buffer
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
15 ; 0x200000 - 0x2FFFFF 1 MB dive header data, last 256 dives, 4 kB / dive
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
16 ; 0x300000 - 0x3DFFFF 896 kB unused
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
17 ; 0x3E0000 - 0x3DFFFF 120 kB firmware buffer
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
18 ; 0x3E0000 - 0x3FFFFF 8 kB unused
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
19
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
20
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
21 ; Write: WREG -> FLASH with address increment and wrap-around at 0x200000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
22 extern write_byte_ext_flash_plus_prof ; with increase of ext_flash_dive_counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
23 extern write_byte_ext_flash_plus_nocnt ; without increase of ext_flash_dive_counter
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
24 extern write_byte_ext_flash_plus_nodel ; without increase of ext_flash_dive_counter, without delete on entering new page
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
25
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
26
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
27 ; Write: WREG -> FLASH with address increment and wrap-around at 0x400000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
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)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
29
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
31 ; Read: block-read FLASH -> WREG
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
32 extern ext_flash_read_block_start ; initial read of one byte at ext_flash_address:3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
33 extern ext_flash_read_block_0x40 ; subsequent read of next byte(s) with wrap-around at 0x400000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
34 extern ext_flash_read_block_0x20 ; subsequent read of next byte(s) with wrap-around at 0x200000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
35 extern ext_flash_read_block_stop ; terminate read
0
heinrichsweikamp
parents:
diff changeset
36
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
37
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
38 ; Erase:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
39 extern ext_flash_erase_4kB ; erase one 4 kB sector @ext_flash_address:3
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
40 extern erase_complete_logbook ; erase complete logbook (FLASH and EEPROM)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
41
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
42
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
43 ; Protection:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
44 extern ext_flash_enable_protection ; enable write protection
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
45 extern ext_flash_disable_protection ; disable write protection
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
46
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
47
0
heinrichsweikamp
parents:
diff changeset
48
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 582
diff changeset
49 ;-----------------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 582
diff changeset
50 ; Macros
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
51 ;-----------------------------------------------------------------------------
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 582
diff changeset
52
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
53
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
54 ; read 1 byte from FLASH to WREG with address auto-increment and wrap-around at 0x200000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
55 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
56 ; the byte read is also copied to ext_flash_rw
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
57 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
58 FLASH_CW_READ_0x20 macro
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
59 extern ext_flash_byte_read_plus_0x20
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
60 call ext_flash_byte_read_plus_0x20
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
61 endm
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
62
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
63
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
64 ; read 1 byte from FLASH to memory with address auto-increment and wrap-around at 0x200000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
65 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
66 ; mem_address: address:2 containing target address in memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
67 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
68 FLASH_CC_READ_0x20 macro mem_address
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
69 extern ext_flash_byte_read_plus_0x20
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
70 call ext_flash_byte_read_plus_0x20 ; read from flash
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
71 movff WREG,mem_address ; copy to memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
72 endm
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
73
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
74
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
75 ; read 2 bytes from FLASH to memory with address auto-increment and wrap-around at 0x200000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
76 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
77 ; mem_address: address:2 containing start address in memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
78 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
79 FLASH_II_READ_0x20 macro mem_address
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
80 extern ext_flash_byte_read_plus_0x20
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
81 call ext_flash_byte_read_plus_0x20 ; read 1st byte from flash
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
82 movff WREG,mem_address+0 ; copy 1st byte to memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
83 call ext_flash_byte_read_plus_0x20 ; read 2nd byte from flash
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
84 movff WREG,mem_address+1 ; copy 2nd byte to memory
0
heinrichsweikamp
parents:
diff changeset
85 endm
heinrichsweikamp
parents:
diff changeset
86
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
87
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
88 ; read a range of data from FLASH to memory (destroys WREG, FSR1) - wraps around at 0x400000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
89 ; - increments ext_flash_address
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
90 ; flash_start : address:3 containing start address in flash
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
91 ; memory_start: address:2 containing start address in memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
92 ; range : literal:1 giving the number of bytes to read (1-256)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
93 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
94 FLASH_RR_READ macro flash_start, memory_start, range
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
95 MOVTT flash_start,ext_flash_address ; set start address in FLASH
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
96 lfsr FSR1,memory_start ; set start address in memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
97 movlw low(range) ; set size of range to read
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
98 extern ext_flash_read_range
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
99 call ext_flash_read_range ; execute range-read
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
100 endm
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
101
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
102
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
103 ; write a range of data from memory to FLASH (destroys WREG, FSR1) - Attention: range must fit into a 256 byte block!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
104 ; - does not increment ext_flash_address!
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
105 ; memory_start: address:2 containing start address in memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
106 ; flash_start : address:3 containing start address in flash
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
107 ; range : literal:1 giving the number of bytes to write (1-256)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
108 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
109 FLASH_RR_WRITE macro memory_start, flash_start, range
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
110 lfsr FSR1,memory_start ; set start address in memory
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
111 MOVTT flash_start,ext_flash_address ; set start address in FLASH
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
112 movlw low(range) ; set size of range to read
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
113 extern ext_flash_write_range
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
114 call ext_flash_write_range ; execute range-write
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
115 endm
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
116
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
117
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
118 ; move forward in FLASH with wrap-around at 0x400000 to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
119 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
120 ; increment: literal (1-255)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
121 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
122 ext_flash_inc_address_0x40 macro increment
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
123 movlw increment
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
124 extern incf_ext_flash_address0_0x40
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
125 call incf_ext_flash_address0_0x40
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
126 endm
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
127
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
128
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
129 ; move forward in FLASH with wrap-around at 0x200000 to 0x000000
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
130 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
131 ; increment: literal (1-255)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
132 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
133 ext_flash_inc_address_0x20 macro increment
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
134 movlw increment
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
135 extern incf_ext_flash_address0_0x20
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
136 call incf_ext_flash_address0_0x20
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 561
diff changeset
137 endm
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
138
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
139
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
140 ; decrement length count
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
141 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
142 ; decrement: literal (1-255)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
143 ;
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
144 ext_flash_dec_length macro decrement
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
145 movlw decrement
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
146 extern decf_ext_flash_length0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
147 call decf_ext_flash_length0
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
148 endm