Mercurial > public > hwos_code
diff 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 |
line wrap: on
line diff
--- a/src/external_flash.inc Fri Feb 21 10:51:36 2020 +0100 +++ b/src/external_flash.inc Fri Feb 28 15:45:07 2020 +0100 @@ -1,6 +1,6 @@ ;============================================================================= ; -; File external_flash.inc combined next generation V3.0.1 +; File external_flash.inc combined next generation V3.08.8 ; ; ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. @@ -8,53 +8,141 @@ ; HISTORY ; 2011-08-12 : [mH] creation -; Misc - extern incf_ext_flash_address_p1 ; +1 for the ext_flash_address:3 - extern ext_flash_disable_protection ; disables write protection - extern ext_flash_enable_protection ; enables write protection + +; FLASH Memory Layout: +; +; 0x000000 - 0x1FFFFF 2 MB dive profile data, shared ring buffer +; 0x200000 - 0x2FFFFF 1 MB dive header data, last 256 dives, 4 kB / dive +; 0x300000 - 0x3DFFFF 896 kB unused +; 0x3E0000 - 0x3DFFFF 120 kB firmware buffer +; 0x3E0000 - 0x3FFFFF 8 kB unused + + +; Write: WREG -> FLASH with address increment and wrap-around at 0x200000 + extern write_byte_ext_flash_plus_prof ; with increase of ext_flash_dive_counter + extern write_byte_ext_flash_plus_nocnt ; without increase of ext_flash_dive_counter + extern write_byte_ext_flash_plus_nodel ; without increase of ext_flash_dive_counter, without delete on entering new page + -; Writes - extern write_byte_ext_flash_plus ; write from WREG and increase address after write with banking at 0x200000 - extern write_byte_ext_flash_plus_nocnt ; no increase of ext_flash_dive_counter:3 - extern write_byte_ext_flash_plus_nodel ; does NOT delete 4kB Page when required - extern write_byte_ext_flash_plus_header ; write from WREG and increase address after write - extern ext_flash_byte_write ; writes one byte from WREG @ext_flash_address:3 - extern ext_flash_byte_write_comms ; without wait, ~86us fixed delay due to 115200 Bauds (Use with caution) - extern write_spi1 ; just (dummy)write to read a byte +; Write: WREG -> FLASH with address increment and wrap-around at 0x400000 + extern write_byte_ext_flash_plus_comms ; without wait for use with fast comm (~86us fixed delay due to 115200 Bauds - use with caution) + + +; Read: block-read FLASH -> WREG + extern ext_flash_read_block_start ; initial read of one byte at ext_flash_address:3 + extern ext_flash_read_block_0x40 ; subsequent read of next byte(s) with wrap-around at 0x400000 + extern ext_flash_read_block_0x20 ; subsequent read of next byte(s) with wrap-around at 0x200000 + extern ext_flash_read_block_stop ; terminate read -; Delete - extern ext_flash_erase_logbook ; erases logbook memory (000000h -> 2FFFFFh -> 3MByte) - extern ext_flash_erase4kB ; erases 4kB sector @ext_flash_address:3 + +; Erase: + extern ext_flash_erase_4kB ; erase one 4 kB sector @ext_flash_address:3 + extern erase_complete_logbook ; erase complete logbook (FLASH and EEPROM) -; Reads - extern ext_flash_read_block_start ; block read start and reads one byte@ext_flash_address:3 into WREG - extern ext_flash_read_block ; read another byte into WREG - extern ext_flash_read_block_stop ; stop block read - extern ext_flash_byte_read ; read one byte@ext_flash_address:3 into WREG and ext_flash_rw - extern ext_flash_byte_read_plus ; return data read in WREG and ext_flash_rw and increase address after read with banking at 0x200000 - extern ext_flash_byte_read_plus_0x20 ; return data read in WREG and ext_flash_rw + +; Protection: + extern ext_flash_enable_protection ; enable write protection + extern ext_flash_disable_protection ; disable write protection + ;----------------------------------------------------------------------------- ; Macros +;----------------------------------------------------------------------------- -; decrease ext_flash_address:2 by the 8 bit value "ext_flash_temp1" - extern decf_ext_flash_address0 -decf_ext_flash_address macro ext_flash_temp1 - movlw ext_flash_temp1 - call decf_ext_flash_address0 + +; read 1 byte from FLASH to WREG with address auto-increment and wrap-around at 0x200000 +; +; the byte read is also copied to ext_flash_rw +; +FLASH_CW_READ_0x20 macro + extern ext_flash_byte_read_plus_0x20 + call ext_flash_byte_read_plus_0x20 + endm + + +; read 1 byte from FLASH to memory with address auto-increment and wrap-around at 0x200000 +; +; mem_address: address:2 containing target address in memory +; +FLASH_CC_READ_0x20 macro mem_address + extern ext_flash_byte_read_plus_0x20 + call ext_flash_byte_read_plus_0x20 ; read from flash + movff WREG,mem_address ; copy to memory + endm + + +; read 2 bytes from FLASH to memory with address auto-increment and wrap-around at 0x200000 +; +; mem_address: address:2 containing start address in memory +; +FLASH_II_READ_0x20 macro mem_address + extern ext_flash_byte_read_plus_0x20 + call ext_flash_byte_read_plus_0x20 ; read 1st byte from flash + movff WREG,mem_address+0 ; copy 1st byte to memory + call ext_flash_byte_read_plus_0x20 ; read 2nd byte from flash + movff WREG,mem_address+1 ; copy 2nd byte to memory endm -; increase ext_flash_address:2 by the 8 bit value "ext_flash_temp1" - extern incf_ext_flash_address0 -incf_ext_flash_address macro ext_flash_temp1 - movlw ext_flash_temp1 - call incf_ext_flash_address0 + +; read a range of data from FLASH to memory (destroys WREG, FSR1) - wraps around at 0x400000 +; - increments ext_flash_address +; flash_start : address:3 containing start address in flash +; memory_start: address:2 containing start address in memory +; range : literal:1 giving the number of bytes to read (1-256) +; +FLASH_RR_READ macro flash_start, memory_start, range + MOVTT flash_start,ext_flash_address ; set start address in FLASH + lfsr FSR1,memory_start ; set start address in memory + movlw low(range) ; set size of range to read + extern ext_flash_read_range + call ext_flash_read_range ; execute range-read + endm + + +; write a range of data from memory to FLASH (destroys WREG, FSR1) - Attention: range must fit into a 256 byte block! +; - does not increment ext_flash_address! +; memory_start: address:2 containing start address in memory +; flash_start : address:3 containing start address in flash +; range : literal:1 giving the number of bytes to write (1-256) +; +FLASH_RR_WRITE macro memory_start, flash_start, range + lfsr FSR1,memory_start ; set start address in memory + MOVTT flash_start,ext_flash_address ; set start address in FLASH + movlw low(range) ; set size of range to read + extern ext_flash_write_range + call ext_flash_write_range ; execute range-write endm -; increase ext_flash_address:2 by the 8 bit value "ext_flash_temp1" with banking at 0x200000 - extern incf_ext_flash_address0_0x20 -incf_ext_flash_address_0x20 macro ext_flash_temp1 - movlw ext_flash_temp1 + +; move forward in FLASH with wrap-around at 0x400000 to 0x000000 +; +; increment: literal (1-255) +; +ext_flash_inc_address_0x40 macro increment + movlw increment + extern incf_ext_flash_address0_0x40 + call incf_ext_flash_address0_0x40 + endm + + +; move forward in FLASH with wrap-around at 0x200000 to 0x000000 +; +; increment: literal (1-255) +; +ext_flash_inc_address_0x20 macro increment + movlw increment + extern incf_ext_flash_address0_0x20 call incf_ext_flash_address0_0x20 endm + + +; decrement length count +; +; decrement: literal (1-255) +; +ext_flash_dec_length macro decrement + movlw decrement + extern decf_ext_flash_length0 + call decf_ext_flash_length0 + endm