include common.inc
code
+
+;======================================================================
+; QUEUEING MESSAGES FOR TRANSMISSION
+
+;----------
+addbyte_toomany panic morse_HB
+
;----------------------------------------
serial_addbyte
; W byte to xmit to host trashed
;
mov_lfsr outbuf, 0
mov_ff outmsg_end, FSR0L
- bs_f PIR1, TXIE ; ensure we get interrupted and try to xmit
;...
+;----------------------------------------
serial_addbyte_another
; W byte to xmit to host trashed
; FSR0 from _addbyte[_another] updated for ..._another again
bc_f FSR0L, 7
mov_fw FSR0L
mov_wf outmsg_end
- cmp_fw_ifne outmsg_begin
+ xor_wfw outmsg_begin
+ bra_z addbyte_toomany
+ ; no, we're ok:
+
+ bt_f_if1 INTCON, TXIE
+ return ; don't bother messing about if tx is already enabled
+
+; we fall through to portb_read to reenable TXIE if appropriate
+;...
+;======================================================================
+; FLOW CONTROL BY HOST OF OUR TRANSMISSIONS
+
+;...
+;----------------------------------------
+portb_read
+;
+; W undefined value from PORTB
+; TXIE any enabled iff host allows us to xmit
+;
+; Note that this will reenable TXIE even if the serial buffer is empty,
+; every time portb_read is called. This doesn't matter very much
+; because the serialtx_intrl routine will disable it again straight
+; away.
+;
+ mov_fw PORTB
+ bc_f INTCON, RBIF
+
+ bt_w_if0 p0_rs232_fcin >> 4
+ bra txfc_disable
+ ; tx enable:
+
+ bs_f PIR1, TXIE
return
- ; too many
- panic morse_HB
+
+;----------
+txfc_disable
+ bc_f PIR1, TXIE
+ goto led_red ; flow control forces us not to transmit
;----------------------------------------------------------------------
-serialtx_intrl
- bt_f_if1 INTCON, RBIF
+serialtxfc_intrl
+ bt_f_if0 INTCON, RBIF
+ return
+ ; yes, it's us:
+
rcall portb_read ; check flow control
+ intrl_handled_nostack
+
+;----------------------------------------------------------------------
+serialtxfc_init
+ bc_f INTCON2, RBIP
+ bs_f INTCON, RBIE
+ rcall portb_read
+ pin_l p0_rs232_fcout ; set outgoing RTS/CTS active
+ return
+;======================================================================
+; ACTUAL TRANSMISSION
+
+;----------------------------------------------------------------------
+serialtx_intrl
; are we ready to transmit ?
bt_f_if0 PIR1, TXIF
return
bt_f_if0 PIR1, TXIE
return
+ ; yes, it's us:
mov_lfsr outbuf, 0
mov_fw outmsg_begin
tx_justsent_noacknmra
inc_f outmsg_begin
bc_f outmsg_begin, outbuf_szln2
+ call i2c_consider_restartread
+tx_alliswell
call led_green ; we're transmitting
- goto i2c_consider_restartread
-
-tx_bufempty
- ; maybe we send an NMRADONE
- mov_fw acknmra
- bra_nz tx_acknmra_send
- ; nothing at all to do:
- bc_f PIR1, TXIE
- goto led_black ; we're not transmitting
+ intrl_handled_nostack
+;----------
tx_acknmra_insert
sub_wff acknmra ; we're acking these now
mov_wf INDF0 ; write it over the message we just sent
- goto led_green
+ bra tx_alliswell
+;----------
tx_acknmra_send
sub_wff acknmra ; we're acking these now
mov_wf TXREG
- goto led_green
-
-;----------------------------------------
-portb_read
-; W undefined value from PORTB
- mov_fw PORTB
- bc_f INTCON, RBIF
-
- bt_w_if0 p0_rs232_fcin >> 4
- bra tx_fcdisable
- ; tx enable:
+ bra tx_alliswell
- bs_f PIR1, TXIE
- bc_f INTCON, RBIE
- return
-
-tx_fcdisable
+;----------
+tx_bufempty
+ ; maybe we send an NMRADONE
+ mov_fw acknmra
+ bra_nz tx_acknmra_send
+ ; nothing at all to do:
bc_f PIR1, TXIE
- bs_f INTCON, RBIE
- goto led_red ; flow control forces us not to transmit
-
-;----------------------------------------------------------------------
-serialtxfc_init
- bc_f INTCON2, RBIP
- bs_f INTCON, RBIE
- rcall portb_read
- pin_l p0_rs232_fcout ; set outgoing RTS/CTS active
- return
+ call led_black ; we're not transmitting
+ intrl_handled_nostack
;----------------------------------------------------------------------
serialtxbuf_init