📄 uart_1.asm
字号:
; ARGUMENTS:
; none.
;
; RETURNS:
; none.
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
UART_1_PutCRLF:
_UART_1_PutCRLF:
RAM_PROLOGUE RAM_USE_CLASS_1
mov A,0x0D ; Send CR
call UART_1_PutChar
mov A,0x0A ; Send LF
call UART_1_PutChar
RAM_EPILOGUE RAM_USE_CLASS_1
ret
.ENDSECTION
IF (UART_1_RXBUF_ENABLE)
;=============================================================================
;=============================================================================
;
; Command Buffer commands
;
;=============================================================================
;=============================================================================
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: UART_1_CmdReset
;
; DESCRIPTION:
; Reset command string and status flags
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; none.
;
; RETURNS:
; none.
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
; THEORY of OPERATION or PROCEDURE:
; Clear the command buffer, command counter, and flag.
;
UART_1_CmdReset:
_UART_1_CmdReset:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >UART_1_aRxBuffer
mov [UART_1_aRxBuffer], 0x00
RAM_SETPAGE_CUR >UART_1_bRxCnt
mov [UART_1_bRxCnt], 0x00
and [UART_1_fStatus], 0x00
RAM_SETPAGE_CUR >ptrParam
mov [ptrParam],0x00
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: UART_1_bCmdCheck
;
; DESCRIPTION:
; Check to see if valid command in buffer.
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; none.
;
; RETURNS:
; BYTE fStatus - Status of command receive buffer.
; Returns non-zero value in A if command is valid.
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
; THEORY of OPERATION or PROCEDURE:
; Read the status and control register.
;
UART_1_bCmdCheck:
_UART_1_bCmdCheck:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >UART_1_fStatus
mov A, [UART_1_fStatus]
and A, UART_1_RX_BUF_CMDTERM ; Mask off Command status
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: UART_1_bErrCheck
;
; DESCRIPTION:
; Check to see if an error has occured since last CmdReset
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; none.
;
; RETURNS:
; BYTE fStatus - Status of command receive buffer.
; Returns non-zero value in A if command is valid.
; 0x80 => Parity Error
; 0x40 => OverRun Error
; 0x20 => Framing Error
; 0x10 => Software Buffer OverRun
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
; Error Status is clear when read.
;
; THEORY of OPERATION or PROCEDURE:
; Read RX buffer error status and clear status
;
UART_1_bErrCheck:
_UART_1_bErrCheck:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >UART_1_fStatus
mov A, [UART_1_fStatus]
and A, UART_1_RX_BUF_ERROR ; Mask off Error status
and [UART_1_fStatus], ~UART_1_RX_BUF_ERROR
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: UART_1_bCmdLength
;
; DESCRIPTION:
; Get length of command string
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; none.
;
; RETURNS:
; BYTE bRxCnt Returns the command length in A.
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
UART_1_bCmdLength:
_UART_1_bCmdLength:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >UART_1_bRxCnt
mov A, [UART_1_bRxCnt]
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: UART_1_szGetParam
;
; DESCRIPTION:
; Return next parameter from UART_1 Rx buffer
;-----------------------------------------------------------------------------
;
; ARGUMENTS: none
;
; RETURNS:
; A => MSB of parameter address
; X => LSB of parameter address
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
; IDX_PP
;
; The receive string is modified by placing Null characters at the end
; of each parameter as they are recovered.
;
; THEORY OF OPERATION:
; This function is a stateful generator of addresses to the "parameters"
; of an input "Command". It scans the (optional) input buffer and breaks
; each lexically distinct element into a null-terminated string by replacing
; delimiters with nulls, as appropriate. The state of the generator is
; maintained by the private variable ptrParam, which is a buffer-relative
; offset. The generator is initialized by a call to the function
; UART_1_CmdReset which resets the entire buffer to the 'empty'
; state. Typically this function, UART_1_szGetParam, is
; not called until the buffer has been loaded with an entire command
; (See UART_1_bCmdCheck).
;
; Note, there is no special distinction between the "command" and the
; "parameters". The first non-delimiter character of the buffer---the first
; character of the "command"---is also, for the purposes of this function,
; the first "parameter" to which it returns an address.
;
; The value of a delimiter (commonly an ascii space, 0x20 and decimal 32)
; is determined at configuration time by a user module parameter.
;
UART_1_szGetParam:
_UART_1_szGetParam:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_SETPAGE_CUR >ptrParam
mov A, <UART_1_aRxBuffer ; Get address to receive buffer
add A, [ptrParam] ; Add string offset
mov X, A
RAM_SETPAGE_IDX >UART_1_aRxBuffer
mov A, [X] ; Get character pointed by X
jnz .SkipOverDelimitersLoop ; Null? No, continue...
push X ; Yes, Save LSB of current pointer
jmp .End_GetNextParam
; Check for delimiter and keep looping until
; all leading delimiters have been found.
.SkipOverDelimitersLoop:
cmp A, UART_1_DELIMITER ; Do we have a delimiter?
jnz .ParamStartFound ; No, Bingo! found a parameter
inc X ; Yes, Increment both index and...
inc [ptrParam] ; the stored pointer.
mov A, [X] ; Get character pointed by X
cmp [ptrParam], (UART_1_RX_BUFFER_SIZE -1) ; End of buffer?
jnz .SkipOverDelimitersLoop ; No, continue the scan
.EndOfString: ; Yes, end of string found...
push X ; Save ptr
.TerminateString:
mov [X], 0x00 ; Make sure string is zero
jmp .End_GetNextParam
.ParamStartFound:
push X ; Beginning of parameter found, save pointer
.ParamLoop: ; Now loop until end of parameter found.
inc X ; Advance pointers.
inc [ptrParam]
cmp [ptrParam], (UART_1_RX_BUFFER_SIZE -1) ; Check if we are at the end of buffer
jz .TerminateString
mov A, [X] ; Get next character
jz .End_GetNextParam
cmp A, UART_1_DELIMITER ; Check if we have a delimiter
jnz .ParamLoop ; Still no delimiter, loop again
mov [X], 0x00 ; Replace delimiter with null for end of substring
inc [ptrParam]
cmp [ptrParam], (UART_1_RX_BUFFER_SIZE -1) ; Check if we are at the end of buffer
jnz .End_GetNextParam ; If not end of string leave
mov [ptrParam], (UART_1_RX_BUFFER_SIZE -1) ; Reset pointer to end of string.
.End_GetNextParam:
pop X
push X
cmp [X], 0x00
jnz .NotNullString
pop X
mov X, 0x00
mov A, >UART_1_aRxBuffer
RAM_EPILOGUE RAM_USE_CLASS_3
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.NotNullString:
pop X
mov A, >UART_1_aRxBuffer ; Return pointer
RAM_EPILOGUE RAM_USE_CLASS_3
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: UART_1_szGetRestOfParams
;
; DESCRIPTION:
; Returns a pointer to the rest of the UART RX buffer
;-----------------------------------------------------------------------------
;
; ARGUMENTS: none
;
; RETURNS:
; A => MSB of parameter
; X => LSB of parameter
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
UART_1_szGetRestOfParams:
_UART_1_szGetRestOfParams:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR >ptrParam
mov A, <UART_1_aRxBuffer ; Get address to receive buffer
add A, [ptrParam] ; Add string offset
mov X,A
mov A,>UART_1_aRxBuffer ; Return pointer
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
ENDIF
; End of File UART_1.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -