系统软件的解析:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
整体的框架:SF初始化à关中断à发送欢迎信息à{等待XONà等待命令的到来à执行指令} {}内的为循环
cold_start: CALL SF_init ;initialise StrataFLASH controls 复位读写使能信号,清空内容
CALL delay_1s ;delay because UART is fast and JTAG startup sequence can be slow
ENABLE INTERRUPT ;Interrupt is used for XON/XOFF flow control
welcome_start: CALL send_CR
CALL send_welcome ;start up message and version number
;******************************************************************************
; Main menu and command selection
;******************************************************************************
;
;
warm_start: CALL send_Menu ;Menu and command selection
CALL send_CR
;
prompt: CALL send_CR
CALL send_CR
LOAD UART_data, character_greater_than ;prompt for input ;显示'>'等待输入
CALL send_to_UART ;回显
CALL read_upper_case
COMPARE s0, character_E ;test for commands and execute as required比较输入的字幕,并执行相应的命令
JUMP Z, erase_command
COMPARE s0, character_B
JUMP Z, block_erase_command
COMPARE s0, character_P
JUMP Z, program_command
COMPARE s0, character_W
JUMP Z, write_command
COMPARE s0, character_R
JUMP Z, read_command
COMPARE s0, character_I
JUMP Z, SF_information
COMPARE s0, character_H
JUMP Z, welcome_start
COMPARE s0, character_S
JUMP Z, SF_status
CALL send_CR ;no valid command input
LOAD UART_data, character_question ;display ???
CALL send_to_UART
CALL send_to_UART
CALL send_to_UART
JUMP prompt ;Try again!
在读入一般字符前的工作:首先看接收fifo是不是正在接收数据,如果fifo是空的,子程序等待知道有一个数据可以被读取,如果接收的到的数据是一个XOFF,那么子程序就会等待XON的到来。这意味着剩下的程序背悬挂着,因此不能传递数据。一旦收到一个XON,他会等待一个一般的字符到来(在返回之前)
CALL read_upper_case
read_upper_case: CALL read_from_UART ;read command character from UART
CALL send_to_UART ;echo character
LOAD s0, UART_data ;convert to upper case
CALL upper_case
RETURN
read_from_UART: DISABLE INTERRUPT
wait_Rx_character: INPUT s0, status_port ;test Rx_FIFO buffer
TEST s0, rx_data_present ;rx_data_present=08
JUMP NZ, read_character ;判断是否正在接收数据,如果没有那么开始读取数据,否则继续等待
JUMP wait_Rx_character
read_character: INPUT UART_data, UART_read_port ;read from FIFO,从串口输入数据,
COMPARE UART_data, character_XOFF ;test for XOFF
JUMP Z, wait_XON
ENABLE INTERRUPT ;normal finish
RETURN
wait_XON: INPUT s0, status_port ;test Rx_FIFO buffer
TEST s0, rx_data_present
JUMP NZ, read_XON
JUMP wait_XON
read_XON: INPUT UART_data, UART_read_port ;read from FIFO
COMPARE UART_data, character_XON ;test for XON
JUMP Z, wait_Rx_character ;now wait for normal character
JUMP wait_XON ;continue to wait for XON
下面重点介绍一个其中一个命令program_command的执行过程。
先介绍一下MCS文件的格式:
;Store up to one line of an MCS file as bytes
;: Start character which is not stored
;10 Number of data bytes included (<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />16 in this case)
;aaaa Lower 16-bits of the storage address
;00 Record type (data in this case)
;dddd... Data bytes (typically 16 which is the maximum)
;cc Checksum
;CR/LF Line will end in carriage return and/or line feed which is not stored.
CONSTANT line_start, 2B 在scratch pad memory存储的起始地址,一行数据4+16+1供21字节CONSTANT
data_start, 2F 数据开始的地址
program_command: CALL send_CR
CALL send_Waiting_MCS_file
CALL program_MCS
CALL send_OK
JUMP prompt
send_Waiting_MCS_file: LOAD UART_data, character_W 打印等待信息
CALL send_to_UART
……………………………………….
CALL send_to_UART
LOAD UART_data, character_r
CALL send_to_UART
send_MCS_file: CALL send_space
LOAD UART_data, character_M
……………………………………….
CALL send_CR
RETURN
从串口读取MCS文件,并给SF相应的地址写入相应的数据。这个子程序直到文件的的结束符收到后停止,因为MCS每一行的包含地址,那么当前的地址将会被输出(作为写SF的地址)
program_MCS: CALL read_MCS_line ;read line from UART()主要的
CALL MCS_address ;find start address and record type
COMPARE sB, 01 test for end record
RETURN Z ;end of programming
COMPARE sB, 04 ;test for extended address record
JUMP Z, program_MCS; no data with this record and upper address now correct
write_spm_data: CALL send_hex_3bytes ;send address to indicate progress
CALL send_CR
FETCH sA, line_start ;read number of data bytes to program
CALL SF_buffer_write ;write bytes to memory
JUMP program_MCS
读取一行的MCS字符到scratch pad memory。
在接收到'line_start'后开始读。子程序会检测‘:’,忽略前面的所有的数据,包括多有的回车和LF,然后读取相继两个字符,然后把它转换成为真正的16进制,然后存储在scratch pad memory,当有CR或LF的时候,表示这条线结束。上一个返回的寄存器SE的值,将会指向scratch pad memory下一个读取的数据的存储地址。
read_MCS_line: LOAD sE, line_start ;initialise SPM memory pointer
wait_MCS_line_Start: CALL read_from_UART ;read character
COMPARE UART_data, character_colon ;test for start character“:”
JUMP NZ, wait_MCS_line_Start
read_MCS_byte: CALL read_from_UART ;read character
COMPARE UART_data, character_CR ;test for end of line
RETURN Z
COMPARE UART_data, character_LF ;test for end of line
RETURN Z
LOAD s3, UART_data ;upper nibble character高四位
CALL read_from_UART ;read character
LOAD s2, UART_data ;lower nibble character低四位、
CALL ASCII_byte_to_hex ;convert to true hex value把接收到的字符转换成16进制
STORE s0, (sE) ;write to SPM
ADD sE, 01 ;increment pointer
JUMP read_MCS_byte
Determine the current address for the line of an MCS file in scratch pad memory(决定当前的MCS行在scratch pad memory中的地址。)核对保存在scratch pad memory中的起始符号,并决定当前地址。地址保存在[s9,s8,s7] 。
A record type of 04 will update [s9].
A record type of 00 will update [s8,s7].
register sB will contain the record type
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
发送寄存器s9,s8,s7的六个16进制的数据到UART
send_hex_3bytes: LOAD s0, s9
CALL send_hex_byte
LOAD s0, s8
CALL send_hex_byte
LOAD s0, s7
CALL send_hex_byte
RETURN
send_hex_byte: CALL hex_byte_to_ASCII 先转换
LOAD UART_data, s2
CALL send_to_UART
LOAD UART_data, s1
CALL send_to_UART
RETURN
写入StrataFlash的buffer并program。用buffer的方式写比单个byte谢的速度更快,buffer的大小限制为32.一个buffer的写过程如下:
buffer的写命令为"E8"(HEX)à写的基地址应当背设置à读状态寄存器,如果没有准备好,重复命令直到准备好à写一个特定的将要被写入的BYTe数目(在这个程序中byte的数目将被保存在sA中,而这个值在写数据到memory前需要被减一)à把这个正确的实际byte数目,用相应的地址写入。(地址不要超过32,也就是低bit在range 00000 to 11111之间)à 写命令去确认操作:读状态寄存器并等待直至准备好,(这个子程序在返回前又恢复一般的读状态。)
sA存储着将要被写入SF的byte数目。改制必须在1到32之间。地址存储在 [s9,s8,s7]中,返回前加1. Scratch pad memory保存数据的其实地址由'data_start'决定,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]
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, s3= data_start=2f
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 直到sA变为零,否则一直写入
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
SF_byte_write: OUTPUT s9, SF_addr_hi_port ;set 24-bit address
OUTPUT s8, SF_addr_mi_port
OUTPUT s7, SF_addr_lo_port
OUTPUT s1, SF_data_out_port ;set data byte to be written
LOAD s1, 00 ;set controls
OUTPUT s1, SF_control_port
LOAD s1, 06 ;>60ns delay
LOAD s1, 06 ;but do something useful!
OUTPUT s1, SF_control_port ;clear controls
RETURN
SF_byte_read: OUTPUT s9, SF_addr_hi_port ;set 24-bit address
OUTPUT s8, SF_addr_mi_port
OUTPUT s7, SF_addr_lo_port
LOAD s1, 05 ;set controls
OUTPUT s1, SF_control_port
LOAD s1, 06 ;>75ns delay
LOAD s1, 06 ;but do something useful!
INPUT s0, SF_data_in_port ;read data byte
OUTPUT s1, SF_control_port ;clear controls
RETURN
wait_SF_ready: LOAD sE, 00 ;clear 16-bit counter timer
LOAD sD, 00
wait_SF_loop: ADD sD, 01 ;increment counter timer
ADDCY sE, 00
CALL SF_byte_read ;read status register into s0
TEST s0, 80 ;test ready/busy flag
JUMP Z, wait_SF_loop
CALL set_SF_read_array_mode ;restore normal read array mode
RETURN
文章评论(0条评论)
登录后参与讨论