📄 progctrl.psm
字号:
;The address is in the register set [s9,s8,s7] before and after this routine is
;executed because not all address bits are defined by a given line of MCS and
;the undefined bits remain constant.
;
;A record type of 04 will update [s9].
;A record type of 00 will update [s8,s7].
;
;On return, the register sB will contain the record type and
;register sC will indicate the number of data bytes stored.
;
MCS_address: LOAD sD, line_start ;initialise SPM memory pointer
FETCH sC, (sD) ;read number of bytes on line
ADD sD, 03 ;move to record type
FETCH sB, (sD) ;read record type
COMPARE sB, 00 ;test for data record
JUMP Z, new_low_address
COMPARE sB, 04 ;test for data record
RETURN NZ
ADD sD, 02 ;read upper 8-bits
FETCH s9, (sD)
RETURN
new_low_address: SUB sD, 01 ;read lower 8-bits
FETCH s7, (sD)
SUB sD, 01 ;read middle 8-bits
FETCH s8, (sD)
RETURN
;
;
;**************************************************************************************
; Write to Buffer of StrataFlash Memory and program
;**************************************************************************************
;
; Writing to the buffer allows faster operation than writing individual bytes.
; The buffer size is limited to 32 locations. To perform a buffer write the process
; is as follows:-
; Write command for buffer write to StrataFLASH memory (E8 hex).
; Base address for writing should also be set.
; Read Status register and if not ready repeat command until it is.
; Write a value specifying the number of bytes to be written LESS ONE.
; In this program the number of bytes will be specified in register sA
; and this value needs to be decremented before writing to the memory.
; Write the correct number of actual data bytes with appropriate addresses.
; Ideally the addresses do not cross the boundary of 32 locations
; such that LSBs are always in the range 00000 to 11111 binary.
; Crossing the boundary is OK but will take longer to program.
; Write command to confirm operation (D0 hex).
; Read Status register and wait for ready.
;
; This routine additionally restores the normal read array mode before returning.
;
; The number of bytes to be written should be supplied in register sA and must be
; a value between 1 and 32 (01 and 20 hex).
;
; The 24-bit base address should be supplied in register set [s9,s8,s7].
; On return, this will be increased by the number of locations written.
;
; Scratch pad memory locations starting at location defined by constant
; 'data_start' should contain the data bytes to be written.
;
; The act of writing the buffer to the memory array may take up to 654us to complete.
; The time taken to program is recorded by register pair [sE,sD]. Each count
; equates to 15 instructions which is equivalent to 30 clock cycles (600ns at 50MHz).
;
; Registers used s0,s1,s7,s8,s9,sA,sD,sE
;
;
SF_buffer_write: LOAD s1, E8 ;command for buffer write
CALL SF_byte_write
CALL SF_byte_read ;read status register into s0
TEST s0, 80 ;test ready/busy flag
JUMP Z, SF_buffer_write ;repeat command until ready
LOAD s1, sA ;Specify number of bytes to write
SUB s1, 01 ;one less than actual number!
CALL SF_byte_write
LOAD s3, data_start ;point to data in scratch pad memory
write_buffer_loop: FETCH s1, (s3) ;fetch data
CALL SF_byte_write ;write to buffer
ADD s7, 01 ;increment address
ADDCY s8, 00
ADDCY s9, 00
ADD s3, 01 ;increment SPM pointer
SUB sA, 01 ;count bytes remaining
JUMP NZ, write_buffer_loop
LOAD s1, D0 ;command to confirm write
CALL SF_byte_write
CALL wait_SF_ready ;wait for program to complete and set read array mode
RETURN
;
;
;**************************************************************************************
; Write Command - Write one byte to specified address
;**************************************************************************************
;
write_command: CALL send_address ;obtain 24-bit address 000000 to FFFFFF
CALL obtain_8bits
JUMP C, write_command ;bad input address
LOAD s9, s0
CALL obtain_8bits
JUMP C, write_command ;bad input address
LOAD s8, s0
CALL obtain_8bits
JUMP C, write_command ;bad input address
LOAD s7, s0
get_data: CALL send_data ;obtain 8-bit data 00 to FF into s0
CALL obtain_8bits
JUMP C, get_data ;bad input data
CALL SF_single_byte_write
CALL send_CR
CALL send_OK
JUMP prompt
;
;
;**************************************************************************************
; Write a single byte to StrataFlash Memory
;**************************************************************************************
;
; To write a single byte to StrataFLASH memory the address must be set and the
; single-word/byte program command (40 hex) sent to the memory. Then the data byte can
; be written to the memory using the same address.
;
; The 24-bit address should be supplied in register set [s9,s8,s7].
; Register s0 should contain the byte data to be written to the memory.
;
; The act of writing the memory array may take up to 175us to complete. This routine
; waits for the memory to be ready before restoring the normal read array mode and
; returning. The time taken to program is recorded by register pair [sE,sD]. Each count
; equates to 15 instructions which is equivalent to 30 clock cycles (600ns at 50MHz).
;
; Registers used s0,s1,s7,s8,s9,sD,sE (s7,s8,s9 not changed)
;
; Registers used s0,s1,s7,s8,s9
;
SF_single_byte_write: LOAD s1, 40 ;command for single byte program
CALL SF_byte_write
LOAD s1, s0 ;write data to be programmed
CALL SF_byte_write
CALL wait_SF_ready ;wait for program to complete
RETURN
;
;
;**************************************************************************************
;Read Command - Read one page of memory at specified address
;**************************************************************************************
;
read_command: CALL send_address ;obtain 24-bit address 000000 to FFFFFF
CALL obtain_8bits ;read value from UART
JUMP C, read_command ;bad input address
LOAD s9, s0
CALL obtain_8bits
JUMP C, read_command ;bad input address
LOAD s8, s0
CALL obtain_8bits
JUMP C, read_command ;bad input address
LOAD s7, s0
CALL send_CR
CALL send_SF_page
CALL send_OK
JUMP prompt
;
;The start address should be provided in register set [s9,s8,s7].
;The display will be next 256 bytes displayed as 16 lines of 16 bytes
;with each line commencing with the address of the first byte.
;
send_SF_page: LOAD s6, 10 ;16 lines to display
send_SF_line: CALL send_CR
CALL send_hex_3bytes ;display address
CALL send_space
LOAD s5, 10 ;16 bytes to display on a line
send_SF_byte: CALL send_space
CALL SF_byte_read ;read byte into s0
ADD s7, 01 ;increment StrataFLASH address
ADDCY s8, 00
ADDCY s9, 00
CALL send_hex_byte ;display byte
SUB s5, 01 ;count bytes per line
JUMP NZ, send_SF_byte
SUB s6, 01 ;count lines
JUMP NZ, send_SF_line
CALL send_CR
RETURN
;
;
;**************************************************************************************
; ID Command - Read and display the device information for the StrataFLASH FLASH memory
;**************************************************************************************
;
; Normal response should be
; Device Manufacturer Code (Intel) = 89 hex
; Memory ID code for 128Mbit = 18 hex
;
; To read the device information the Read device information command (90)
; must be written to the memory. The information is read back but assumes
; that 16-bit words are being used and hence address bit0 is not really used.
; hence addresses 000000 and 0000001 both return the Device Manufacturer Code and
; addresses 000002 and 0000003 both return the Memory ID code.
;
; After reading the device information the read array command is written to the
; device to put it back to normal read mode.
;
; Registers used s0,s7,s8,s9
;
SF_information: CALL send_CR ;send 'ID=' to terminal
CALL send_ID
LOAD UART_data, character_equals
CALL send_to_UART
CALL send_space
LOAD s9, 00 ;define base address 000000
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -