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