⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nios2_germs_monitor.s

📁 一款基于FPGA的对于VGA实现全彩控制的程序
💻 S
📖 第 1 页 / 共 3 页
字号:

  

errorWaitForEOL:
    CALL    WaitForEOL
    MOVUI   r4, '?'                             # unknown command
    CALL    PutChar
    MOVUI   r4, CR
    CALL    PutChar

    BR      ReceiveCommand

doColon:

    # First 2 chars: record length, for data only
    MOVUI   r7, 1                               # fetch record length 
    CALL    GetHexBytes
    MOV     r20, r5                             # record length stashed
    #
    # Next 4 chars: address offset
    #
    MOVUI   r7, 2                               # we want 2 byte/ 4 chars of hex
    CALL    GetHexBytes
    OR      r21, r12, r5                        # Get most recent upper-bytes address 
                                                # construct full address into r21 
    # Get record type
    #
    #
    MOVUI   r7, 1                               # 1 byte/2 chars for record type
    CALL    GetHexBytes

    BEQ     r0, r5, doSReadData                 # same code as reading S-Record data
    CMPNEI  r15, r5, 4                          # I-Hex 4 sets upper bits of destination address
    BNE     r0, r15, doColonNot4

    MOVUI   r7, 2                               # upper 16 bits is 2 bytes worth
    CALL    GetHexBytes
    
    SLLI    r12, r5, 16                         # and save upper bits there...

doColonNot4:
    BR      happyWaitForEOL

#--------------------------------------------
# M Command
# M<addr>               show 16 bytes
# M<addr>-<addr>        show range
# M<addr>:val val val   write values to addr
# M<addr>-<addr>:val    fill range
#

doM:
    MOVUI    r6, ':'
    CALL    GetHexUntil
    
    # 
    # Write operation?
    #

    CMPEQI  r15, r4, ':'
    BNE     r0, r15, doMWrite

    _CLRLOBITS r14,r5,ADDR_LOBITS # align to word, r14=addr
    #
    # If showing range, compute it...
    #
    BNE     r0, r3, doMShowRange                

    #
    # Show r22 words...
    #

    BR      doCR

    # 
    # Show Range
    # Show from r3 to r5, inclusive
    # (though we use r14's rounded base address)
    #

doMShowRange:
    SUB     r7, r5, r3        # r7 = # words
    SRLI    r22, r7, 2        # if they hit return, they get this many again
    _CLRLOBITS r14,r3,ADDR_LOBITS  # align to word, r14=addr

doCR:
    MOV     r7, r22           # <CR> shows r22 words from r14

doMShowRangeLine:
    #
    # Come here with r7 = #words to show, r14 = address to show
    #

    MOVUI   r17, 4            # countdown for this line
    
    # Print #addr:
    CALL    PutHash

    # 
    # print the address
    #

    MOV     r5, r14
    CALL    PutHex
    MOVUI   r4, ':'
    CALL    PutChar
    MOVUI   r4, ' '
    CALL    PutChar

doMShowRangeLoop:
    LDWIO   r5, 0(r14)
    CALL    PutHex
    MOVUI   r4, ' '
    CALL    PutChar

    #
    # Bump address and decrement to show count
    #
    ADDI    r14, r14, 4
    ADDI    r7, r7, -1
    BLE     r7, r0, doneMCR 
    
    # see if it's time for a newline
    ADDI    r17, r17, -1
    BNE     r0, r17, doMShowRangeLoop

    MOVUI   r4, CR
    CALL    PutChar
    BR      doMShowRangeLine

doneMCR:
    MOVUI   r4, CR
    CALL    PutChar
    BR      ReceiveCommand

doMWrite:
    MOV     r14, r5
    BNE     r0, r3, doMFill                    
    
    #
    # Write space-separated values until CR
    #
    _CLRLOBITS r21,r5,ADDR_LOBITS  # r21 = round_down(r5)

doMWriteLoop:
    MOVUI   r6, ' '
    MOV     r18, r0           # (GetHexUntil needs this to count bytes)
    CALL    GetHexUntil
    MOV     r24, r4           # save the break-character...

.if GM_WIDTHS
    # decide which kind of write to do: 8, 16, or 32
    # r18 == bytesize of user-entered value

    MOVUI   r15,2
    BEQ     r18,r15,doMWrite16
    BLTU    r18, r15, doMWrite8

    STWIO   r5, 0(r21)
    BR      doMWrite_did

doMWrite8:
    CALL    StashByte
    BR      doMWrite_did

doMWrite16:
    CALL    Stash16

.else
    # Send in two bytes to the StashByte routine
    # so that it handles writing to flash
    MOV     r16, r5                 # reserve high (later) byte 
    CALL    StashByte
    SRLI    r5, r16, 8              # send the high byte                         
    ADDI    r21, r21, 1
    CALL    StashByte
.endif

doMWrite_did:
    CMPNEI  r15, r24, CR            # r24 has break char from GetHex
    ADD     r21, r21, r18           # increment address
    BNE     r0, r15, doMWriteLoop
    BR      ReceiveCommand

doMFill:
    MOV     r16, r3               # preserve low end of range
    MOV     r14, r5               # preserve end of range
    CALL    GetHex
    MOV     r7, r16               # preserve for <CR> later
    CALL    FillRAM
    MOV     r14, r7               # restore for <CR> to show from start
    CALL    ReceiveCommand

#-----------------------------
# FillRAM
#
# r16 = start, r14 = end, r5 = value
#

FillRAM:
    _CLRLOBITS r16,r16,ADDR_LOBITS
fillRAMLoop:
    STWIO   r5, 0(r16)
    ADDI    r16, r16, 4
    BLTU    r16,r14,fillRAMLoop   # keep writing until we reach the end
    RET

#-------------------------------
# S-Record handlin'
#
doS:
    CALL    GetChar                     # Fetch the record type
    MOV     r19, r4                     # record type stashed
    MOVUI   r7, 1                       # Fetch record length
    CALL    GetHexBytes
    ADDI    r20, r5, -1                 # record length (including address) stashed
                                        # decrement to ignore the checksum @ the end
    ANDI    r19, r19, LOW_NIBBLE_MASK   # mask of low bits of presumed ascii digit
    BEQ     r0, r19, ignores            # zero? that's a kind we ignore
    CMPLTUI r15, r19, 4                 # data record?
    BNE     r0, r15, doS123             # yup! go do data record
    ADDI    r19, r19, -7                # 789->012
    BLT     r19, r0, ignores            # was a 45 or 6...
    CMPLTUI r15, r19, 3
    BNE     r0, r15, doS789

ignores:
happyWaitForEOL:                        # Ignores until the end of line, then begins anew.
    CALL    WaitForEOL
    CALL    ReceiveCommand

doS123:
    ADDI    r19, r19, 1                 # got here with r19 = 12 or 3, change to addr bytes
    SUB     r20, r20, r19               # r20 = number of data bytes to absorb, now
    MOV     r7, r19                     # count of bytes to get
    CALL    GetHexBytes
    MOV     r21, r5                     # r21 = address to read into

#----------------------------------
# Come here with r21 = address to read bytes into
#                r20 = number of bytes to read
#                r13 = forced offset (relocation) to apply to all addresses (or zero)

doSReadData:
    ADD     r21, r21, r13               # Override the start address with r13 (force address)
doSReadData1:
    MOVUI   r7, 1                       # bytecount = 1
    CALL    GetHexBytes                 # Read a byte of data

    CALL    StashByte                   # puts r5 into [r21], and does FLASH stuff if needed
    
    ADDI    r21, r21, 1                 # bump to next byte in any case
    ADDI    r20, r20, -1                # zero bytes remaining?
    BNE     r0, r20, doSReadData1       # no: loop back around
    
    BR      ignores                     # ignore the checksum, and continue onward

doS789:
    SUB     r19, r0, r19                # got here with r19=012 for 789
    ADDI    r19, r19, 4                 # now 987->234, byte count for GO address
    MOV     r7, r19                     # bytes of address to read
    CALL    GetHexBytes
    CALL    WaitForEOL                  # don't do anything until the line is finished
    BR      Go                          # r5 is ready...

doG:
    CALL    GetHex
    
Go:
    # SRLI    r5, r5, 1                   # divide in half for JMP action
    CALLR   r5
    BR      postFlash_start

doE:
    CALL    GetHex
    _CLRLOBITS r5,r5,ADDR_LOBITS

.ifdef GM_FlashTop

        # |
        # | call C version of flash erase
        # | flash address in r5
        # |

    CALL    germs_erase_sector

    BR      ReceiveCommand

.endif  # GM_FlashTop

#---------------------------------
# doR: Set Relocate
# usage:
#           +r10800         <--- add 0x10800 to addresses in s-records/i-hex
#           +r4000-180000   <--- add 0x140000 to addresses in s-records/i-hex
#
doR:
    CALL    GetHex
    SUB     r13, r5, r3                  # offset end address - start address (or just end)
    CALL    ReceiveCommand


#---------------------------------------
# GetChar and PutChar
# both work on r4
# GetChar always echoes
    # 
    # The UART version of GetChar
    #
getCharLFEcho:                                # loop to echo ignored linefeeds
    LDWIO   r15, 4*np_uartstatus(r8)          # status register
    ANDI    r15, r15, np_uartstatus_trdy_mask # masking out bit 6   
    BEQ     r0, r15, getCharLFEcho
    STWIO   r4,  4(r8)

GetChar:
    LDWIO   r15, 4*np_uartstatus(r8)
    BR0     r15, r15, np_uartstatus_rrdy_bit, GetChar
    LDWIO   r4, 4*np_uartrxdata(r8)

    CMPEQI  r15, r4, 0x0A                     # ignore linefeeds
    BNE     r0, r15, getCharLFEcho            # echo the LF, but don't return it
    CMPEQI  r15, r4, 0x1B                     # <ESC> restarts monitor:
                                              # the only line editing
    BNE     r0, r15, postFlash_start 

PutChar:
    #
    # The UART version of PutChar
    #
    LDWIO   r15, 4*np_uartstatus(r8)
    BR0     r15, r15, np_uartstatus_trdy_bit, PutChar   # checking transmit ready bit
    STWIO   r4, 4*np_uarttxdata(r8)          # send out character
    RET

PutHash:
    MOVUI   r4, '#'
    BR      PutChar

WaitForEOL:
    MOV     r23, ra                             # save return address
waitForEOLLoop:
    CALL    GetChar
    CMPEQI  r15, r4, CR                         # check to see if received carriage return
    BEQ     r0, r15, waitForEOLLoop             # keep looping until received CR
    JMP     r23

#-----------------------------------
# PutHex r5
#
# Prints eight characters (32 bit value)
#
# Uses r6 for shift amount
# Uses r23 as alternate return address

PutHex:
    MOV     r23, ra                             # save return address
    MOVUI   r16, 28                               

putHexLoop:
    SRL     r4, r5, r16
    ANDI    r4, r4, LOW_NIBBLE_MASK             # mask out low nibble
    CMPGTUI r15, r4, 9                               # checking if number or letter
    BEQ     r0, r15, IsNumber
    #BNE    r0, r15, IsLetter

IsLetter:
    ADDI    r4, r4, 'A'-'0'-10

IsNumber:
    ADDI    r4, r4, '0'

    CALL    PutChar
    ADDI    r16, r16, -4                        # get ready to look at next nibble
    BGE     r16, r0, putHexLoop                 # unless already finished
    JMP     r23                                 # if so, return

##########################################################################
#
# Procedure:        GetHexUntil
#                   GetHex
#
# Description: Gets hex value until CR
#              A hyphen-seperated pair returns the 2nd in r5 and the 1st in r3
#
#              GetHexUntil will scan hex chars until either a CR
#              or the character in r6 (still with a hyphen moving stuff to r3)
#
#              Return number of bytes read in r18 (caller MUST clear r18 first, 
#              for this feature to work)
#
# Arguments:
#         r7 - number of character to read (GetHexBytes only)
#         r6 - character to break on, in addition to CR
#
# Return Values:
#         r5  - value read (second value when
#                  hyphen-seperated pair encountered)
#         r3  - first value read (only when hyphen-seperated pair encountered)
#         r4  - last character typed (CR or r6 break char)
#         r18 - number of bytes read (if caller cleared r14 first)
#
# Local Variables:  None
# Shared Variables: None
# Global Variables: None
#
# Input:            None
# Output:           Character to UART
#
# Error Handling:   None
#
# Registers Used:   r23, r18, r15, r8, r7, r6, r5, r4, r3
# Stack Depth:      None
#
# Algorithms:       None
# Data Structures:  None
#
# Known Bugs:       None
# Limitations:      None
#
# Revision History:
#   7/25/2003      Joseph Lin      initial revision (modified from Nios GERMS)
#   8/04/2003      Joseph Lin      updated comments

GetHexUntil:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -