; data provided by the host; this means that (fromserial & 0xf0) is
; the first buffer which fails to contain a complete nmra message.
; fromserial is updated only by the (low priority) serial receive
- ; interrupt handler.
+ ; interrupt handler. Furthermore, it always maintains a correct
+ ; and valid value for use by the high-priority nmra readout ISR.
;
; totrack points to the first remaining full byte, which is currently
; being transmitted; if nothing is currently being transmitted
mov_lw 0x0f
and_wfw fromserial
bra_z receive_message_too_long
-
+serial_receive_done
intrl_handled_nostack
receive_message_too_long
; so what's the first byte then ?
mov_lw 0xf0
and_wff FSR0L
- and_wff fromserial
- com_fw INDF0
+ and_wff fromserial ; fromserial := 00BB0000
+ com_fw INDF0 ; where BB is this buffer
bra_nz not_nmra_message
; so, first byte is FF (since complement of it is zero)
; so, move to next buffer
advance_write_buffer
-; clear low 4 bits of fromserial and increment top 4 bits
-; aaaabbbb -> bbbbaaaa -> bbbb(aaaa+1) -> 0000(aaaa+1) -> (aaaa+1)0000
+; increment top 4 bits of fromserial (already cleared low 4 bits)
debug '5'
- swap_fa fromserial
- inc_fa fromserial
- mov_lw 0xF
- and_wffa fromserial
- swap_fa fromserial
+ mov_fw fromserial ; W = 00BB0000
+ add_lw 0x10 ; W = 0?CC0000
+ bc_w 6 ; W = 00CC0000
+ mov_wf fromserial ; where BB is this buffer
+ ; and CC is next buffer
+ fixme check for overruns ie if we caught up with totrack
-; clear bit 6 (will set back to buffer 0 if has overflowed to 4)
- debug '6'
- bc_fa fromserial,6
-
- return
+ bra serial_receive_done
not_nmra_message
+ ; we've already set FSR0 and fromserial to point
+ ; back to beginning of the same buffer
call serialrx_generalmsg
- intrl_handled_nostack
+ bra serial_receive_done
;****************************************************************************