chiark / gitweb /
transmit management - initial cut
[trains.git] / detpic / serout.asm
1 ;======================================================================
2 ; SERIAL PORT - TRANSMISSION TO HOST
3
4  include common.inc
5  code
6 ;----------------------------------------
7 serial_addbyte
8 ;  W                    byte to xmit to host    trashed
9 ;  FSR0                 any                     set for serial_addbyte_another
10 ;  outbuf, outmsg_*     buffer not full         adjusted appropriately
11 ;  STATUS               any                     trashed
12 ;  all others           any                     not interfered with
13 ;
14         mov_lfsr outbuf, 0
15         mov_ff  outmsg_end, FSR0L
16         bs_f    PIR1, TXIE ; ensure we get interrupted
17 ;...
18 serial_addbyte_another
19 ;  W                    byte to xmit to host    trashed
20 ;  FSR0                 from _addbyte[_another] updated for ..._another again
21 ;  outbuf, outmsg_*     buffer not full         adjusted appropriately
22 ;  STATUS               any                     trashed
23 ;  all others           any                     not interfered with
24 ;
25         mov_wf  POSTINC0
26         bc_f    FSR0L, 7
27         mov_fw  FSR0L
28         mov_wf  outmsg_end
29         cmp_fw_ifne outmsg_begin
30         return
31         ; too many
32         panic morse_HB
33
34 ;----------------------------------------------------------------------
35 serialtx_intrl
36         bt_f_if1 INTCON, RBIF
37         rcall   portb_read ; check flow control
38
39         ; are we ready to transmit ?
40         bt_f_if0 PIR1, TXIF
41         return
42         bt_f_if0 PIR1, TXIE
43         return
44
45         mov_lfsr outbuf, 0
46         mov_fw  outmsg_begin
47         mov_wf  FSR0L
48         xor_wfw outmsg_end
49         bra_z   tx_bufempty
50
51         mov_fw  INDF0
52         mov_wf  TXREG
53         bra_n   tx_justsent_noacknmra
54         ; we've just sent the last byte of some message:
55         ; maybe we push an NMRADONE message on the front
56         mov_fw  acknmra
57         bra_nz  tx_acknmra_insert
58 tx_justsent_noacknmra
59         inc_f   outmsg_begin
60         bc_f    outmsg_begin, outbuf_szln2
61         goto    led_green
62
63 tx_bufempty
64         ; maybe we send an NMRADONE
65         mov_fw  acknmra
66         bra_nz  tx_acknmra_send
67         ; nothing at all to do:
68         bc_f    PIR1, TXIE
69         goto    led_black
70
71 tx_acknmra_insert
72         sub_wff acknmra ; we're acking these now
73         mov_wf  INDF0 ; write it over the message we just sent
74         goto    led_green
75
76 tx_acknmra_send
77         sub_wff acknmra ; we're acking these now
78         mov_wf  TXREG
79         goto    led_green
80
81 ;----------------------------------------
82 portb_read
83 ;  W                    undefined       value from PORTB
84         mov_fw  PORTB
85         bc_f    INTCON, RBIF
86
87         bt_w_if0  p0_rs232_fcin >> 4
88         bra     tx_fcdisable
89         ; tx enable:
90
91         bs_f    PIR1, TXIE
92         bc_f    INTCON, RBIE
93         return
94
95 tx_fcdisable
96         bc_f    PIR1, TXIE
97         bs_f    INTCON, RBIE
98         goto    led_red
99
100 ;----------------------------------------------------------------------
101 serialtxfc_init
102         bs_f    INTCON, RBIE
103         bc_f    INTCON2, RBIP
104         rcall   porb_read
105         return
106
107 ;======================================================================
108  include final.inc