' ' buffered smart pin serial object for P2 Eval board, buffering rx/tx in the Cog, supporting 2 full-duplex connrction ' VAR long cog 'cog id of this instance ' '----------------------------------------------------------------------- 'stop cog if already running '----------------------------------------------------------------------- ' PUB stop if cog cogstop(cog-1) cog := 0 ' '----------------------------------------------------------------------- ' PUB start(startparameteraddress) stop long[long[startparameteraddress]] := 0 'set flag to know if the started cog has read its parameters cog := cognew(@cogserial_init,startparameteraddress) + 1 if cog repeat until long[long[startparameteraddress]] == -1 'wait until cog is done reading parameter RESULT := 1 ' '----------------------------------------------------------------------- ' 'the PASM code runs in a COG and just needs 1 long for it's id and '8 longs in the HUB for communication. ' 'All code and buffers for 2 full duplex pairs is in the COG. ' '----------------------------------------------------------------------- ' 'The start parameter block ' '----------------------------------------------------------------------- ' ' When starting the driver you need to provide a memory address to read the parameters from. ' After COG start the memory is not needed anymore, so you can use your stack or some other ' Buffer you have. You will need 21 longs for all parameter. ' ' The first parameter in the start parameter block is the ADDRESS of your 8 long HUB mailbox ' You will use to communicate with the driver, once started. ' ' startparams[0] := @rx1_cmd 'hub address mailbox ' startparams[1] := rxpin1 'pin rx1 ' startparams[2] := 7 + ((CLKFREQ / rxbaudrate1) << 16) 'bitrate rx1 ' startparams[3] := rxmode1 'mode rx1 ' startparams[4] := rxlutstart1 'start lutbuffer rx1 ' startparams[5] := rxlutsize1 'size lutbuffer rx1 ' startparams[6] := txpin1 'pin tx1 ' startparams[7] := 7 + ((CLKFREQ / txbaudrate1) << 16) 'bitrate tx1 ' startparams[8] := txmode1 'mode tx1 ' startparams[9] := txlutstart1 'start lutbuffer tx1 ' startparams[10] := txlutsize1 'size lutbuffer tx1 ' startparams[11] := rxpin2 'pin rx2 ' startparams[12] := 7 + ((CLKFREQ / rxbaudrate2) << 16) 'bitrate rx2 ' startparams[13] := rxmode2 'mode rx2 ' startparams[14] := rxlutstart2 'start lutbuffer rx2 ' startparams[15] := rxlutsize2 'size lutbuffer rx2 ' startparams[16] := txpin2 'pin tx2 ' startparams[17] := 7 + ((CLKFREQ / txbaudrate2) << 16) 'bitrate tx2 ' startparams[18] := txmode2 'mode tx2 ' startparams[19] := txlutstart2 'start lutbuffer tx2 ' startparams[20] := txlutsize2 'size lutbuffer tx2 ' '----------------------------------------------------------------------- ' 'The mailbox interface: ' '----------------------------------------------------------------------- ' ' to use this you just need to write parameter and command into the ' respective hub adresses provided at start ' ' each channel (rx1,tx1,rx2,tx2) has its own mailbox, one long for ' command/status and one long for the parameter ' ' the usual needed sequence is to ' check if mailbox ready (-1) else wait ' set parameter ' set command ' if you need to wait for a result check if mailbox ready (-1) else wait ' ' all mailboxes are independent from each other and you can run commands asyncron for each mailbox/channel ' '----------------------------------------------------------------------- ' 'rx1 mailbox ' rx1_cmd rx1_param 'mailbox for rx1 ' -1 --- 'mailbox ready last command finished ' -2 --- 'rxcheck, returns -1 if buffer empty or char in rx1_param ' -3 --- 'rxcount, returns number of bytes waiting in buffer in rx1_param ' -4 --- 'rxsize, returns size of buffer in bytes in rx1_param ' >0 ' size hubaddress 'rxblock, will read size bytes from buffer to hubaddress ' 'tx1 mailbox ' tx1_cmd tx1_param 'mailbox for tx1 ' -1 --- 'mailbox ready last command finished ' -2 --- 'txcheck, returns -1 if buffer full else bytes waiting in buffer in tx1_param ' -3 --- 'txcount, returns number of bytes waiting in buffer in tx1_param ' -4 --- 'txsize, returns size of buffer in bytes in tx1_param ' -5 hubaddress 'str, will write bytes from hubaddress to buffer until reaching a zero byte ' -6 value 'dec, will write value in tx1_param as decimal without leading zero's to buffer ' -(6+(digits<<8) value 'dec, will write last digits chars of value in tx1_param as decimal replacing leading zero's with space to buffer ' -7 value 'dec, will write 10 chars of value in tx1_param as decimal with leading zero's to buffer ' -(7+(digits<<8) value 'dec, will write last digits chars of value in tx1_param as decimal with leading zero's to buffer ' 'all dec routines will put a '-' as first char if value is negative ' -8 value 'hex, will write value in tx1_param as hex without leading zero's to buffer ' -(8+(digits<<8) value 'hex, will write last digits chars of value in tx1_param as hex replacing leading zero's with space to buffer ' -9 value 'hex, will write 8 chars of value in tx1_param as hex with leading zero's to buffer ' -(9+(digits<<8) value 'hex, will write last digits chars of value in tx1_param as hex with leading zero's to buffer ' >0 ' size hubaddress 'txblock, will write size bytes from hubaddress to buffer ' 'rx2 mailbox ' rx2_cmd rx2_param 'mailbox for rx2 ' -1 --- 'mailbox ready last command finished ' -2 --- 'rxcheck, returns -1 if buffer empty or char in rx2_param ' -3 --- 'rxcount, returns number of bytes waiting in buffer in rx2_param ' -4 --- 'rxsize, returns size of buffer in bytes in rx2_param ' >0 ' size hubaddress 'rxblock, will read size bytes from buffer to hubaddress ' 'tx2 mailbox ' tx2_cmd tx2_param 'mailbox for tx2 ' -1 --- 'mailbox ready last command finished ' -2 --- 'txcheck, returns -1 if buffer full else bytes waiting in buffer in tx2_param ' -3 --- 'txcount, returns number of bytes waiting in buffer in tx2_param ' -4 --- 'txsize, returns size of buffer in bytes in tx2_param ' -5 hubaddress 'str, will write bytes from hubaddress to buffer until reaching a zero byte ' -6 value 'dec, will write value in tx2_param as decimal without leading zero's to buffer ' -(6+(digits<<8) value 'dec, will write last digits chars of value in tx2_param as decimal replacing leading zero's with space to buffer ' -7 value 'dec, will write 10 chars of value in tx2_param as decimal with leading zero's to buffer ' -(7+(digits<<8) value 'dec, will write last digits chars of value in tx2_param as decimal with leading zero's to buffer ' 'all dec routines will put a '-' as first char if value is negative ' -8 value 'hex, will write value in tx2_param as hex without leading zero's to buffer ' -(8+(digits<<8) value 'hex, will write last digits chars of value in tx2_param as hex replacing leading zero's with space to buffer ' -9 value 'hex, will write 8 chars of value in tx2_param as hex with leading zero's to buffer ' -(9+(digits<<8) value 'hex, will write last digits chars of value in tx2_param as hex with leading zero's to buffer ' >0 ' size hubaddress 'txblock, will write size bytes from hubaddress to buffer ' '----------------------------------------------------------------------- ' DAT org 0 ' cogserial_init ' 'loading parameters and reusing init code space for variables ' rx1_mailbox_ptr rdlong rx1_mailbox_ptr,ptra++ 'pointer to mailbox in hub and rx1 mailbox hub address rx1_pin rdlong rx1_pin, ptra++ 'serial1 rxpin1 rx1_bitperiod rdlong rx1_bitperiod, ptra++ 'bitperiod := 7 + ((CLKFREQ / baudrate) << 16) rx1_mode rdlong rx1_mode, ptra++ 'configure rx1_pin for asynchronous receive, always input rx1_lut_buff rdlong rx1_lut_buff, ptra++ 'lut rx1 receive buffer address in lut rx1_lut_btop rdlong rx1_lut_btop, ptra++ 'lut rx1 receive buffer top address in lut (size for rx1) tx1_pin rdlong tx1_pin, ptra++ 'serial1 txpin tx1_bitperiod rdlong tx1_bitperiod, ptra++ 'bitperiod := 7 + ((CLKFREQ / baudrate) << 16) tx1_mode rdlong tx1_mode, ptra++ 'configure tx1_pin for asynchronous transmit, always output tx1_lut_buff rdlong tx1_lut_buff, ptra++ 'lut tx1 send buffer address in lut tx1_lut_btop rdlong tx1_lut_btop, ptra++ 'lut tx1 send buffer top address in lut (size for tx1) rx2_pin rdlong rx2_pin, ptra++ 'serial1 rx2pin rx2_bitperiod rdlong rx2_bitperiod, ptra++ 'bitperiod := 7 + ((CLKFREQ / baudrate) << 16) rx2_mode rdlong rx2_mode, ptra++ 'configure rx2_pin for asynchronous receive, always input rx2_lut_buff rdlong rx2_lut_buff, ptra++ 'lut rx2 receive buffer address in lut rx2_lut_btop rdlong rx2_lut_btop, ptra++ 'lut rx2 receive buffer top address in lut (size for rx2) tx2_pin rdlong tx2_pin, ptra++ 'serial1 tx2pin tx2_bitperiod rdlong tx2_bitperiod, ptra++ 'bitperiod := 7 + ((CLKFREQ / baudrate) << 16) tx2_mode rdlong tx2_mode, ptra++ 'configure tx2_pin for asynchronous transmit, always output tx2_lut_buff rdlong tx2_lut_buff, ptra++ 'lut tx2 send buffer address in lut tx2_lut_btop rdlong tx2_lut_btop, ptra++ 'lut tx2 send buffer top address in lut (size for tx2) ' ' calculate mailbox pointers for later use ' rx1_param_ptr mov rx1_param_ptr, rx1_mailbox_ptr 'rx1 param hub address rx1_head add rx1_param_ptr, #4 'rx1 head position tx1_mailbox_ptr mov tx1_mailbox_ptr,rx1_param_ptr 'tx1 mailbox hub address rx1_tail add tx1_mailbox_ptr,#4 'rx1 tail position tx1_param_ptr mov tx1_param_ptr, tx1_mailbox_ptr 'tx1 param hub address rx1_char add tx1_param_ptr, #4 'tmp char for rx1_isr rx2_mailbox_ptr mov rx2_mailbox_ptr,tx1_param_ptr 'rx2 mailbox hub address rx1_address add rx2_mailbox_ptr,#4 'tmp address for rx1_isr rx2_param_ptr mov rx2_param_ptr, rx2_mailbox_ptr 'rx2 param hub address tx1_head add rx2_param_ptr, #4 'tx1 head position tx2_mailbox_ptr mov tx2_mailbox_ptr,rx2_param_ptr 'tx2 mailbox hub address tx1_tail add tx2_mailbox_ptr,#4 'tx1 tail position tx2_param_ptr mov tx2_param_ptr, tx2_mailbox_ptr 'tx2 param hub address tx1_char add tx2_param_ptr, #4 'tmp char for tx1_send ' ' clear mailbox ' tx1_address wrlong minusOne, tx2_param_ptr 'tmp address for tx1_send rx2_head wrlong minusOne, tx2_mailbox_ptr 'rx2 head position rx2_tail wrlong minusOne, rx2_param_ptr 'rx2 tail position rx2_char wrlong minusOne, rx2_mailbox_ptr 'tmp char for rx2_isr rx2_address wrlong minusOne, tx1_param_ptr 'tmp address for rx2_isr tx2_head wrlong minusOne, tx1_mailbox_ptr 'tx2 head position tx2_tail wrlong minusOne, rx1_param_ptr 'tx2 tail position ' ' this tells calling cog we got the parameters ' tx2_char wrlong minusOne, rx1_mailbox_ptr 'tmp char for tx2_send ' ' init used smartpins ' tx2_address cmp rx1_pin, minusOne wz 'tmp address for tx2_send 'if rx1_pin == -1 txcmd if_z jmp #end_rx1_reset 'tmp cmd used for HEX and DEC out ' skip RX1 setting smart pin ' ' Reset rx1 clear buffer pointers enable pin and int1 ' decbuf setint1 #0 'decbuf(0) reuses the next 11 longs 'disable int1 dirl rx1_pin 'decbuf(1) 'disable receiver mov rx1_head, #0 'decbuf(2) 'reset serial buffer pointers mov rx1_tail, #0 'decbuf(3) mov rx1_char, #%110<<6 'decbuf(4) add rx1_char, rx1_pin 'decbuf(5) wrpin rx1_mode, rx1_pin 'decbuf(6) 'configure rx_pin for asynchronous receive, always input wxpin rx1_bitperiod, rx1_pin 'decbuf(7) setse1 rx1_char 'decbuf(8) 'set se1 to trigger on rx1_pin (rx1_pin high) mov ijmp1, #rx1_isr 'decbuf(9) 'set int1 jump vector to rx1 ISR setint1 #4 'decbuf(10) 'set int1 to trigger on se1 rx1param dirh rx1_pin 'tmp parameter for rx1 cmd 'enable receiver end_rx1_reset txcmdparam cmp tx1_pin, minusOne wz 'blockaddress used in HEX/DEC 'if tx1_pin == -1 rx_char if_z jmp #end_tx1_reset 'rx_char used in command loop ' skip setting TX1 smart pin ' ' Reset tx1 set tx1_mode and tx1_bitperiod, enable pin ' rx1cmdparam dirl tx1_pin 'tmp parameter for rx1 cmd 'disable transmitter tx1param mov tx1_head, #0 'tmp parameter for tx1 cmd 'reset serial buffer pointers tx1cmdparam mov tx1_tail, #0 'tmp parameter for tx1 cmd rx2param wrpin tx1_mode, tx1_pin 'tmp parameter for rx2 cmd 'configure tx1_pin for asynchronous transmit, always output rx2cmdparam wxpin tx1_bitperiod, tx1_pin 'tmp parameter for rx2 cmd tx2param dirh tx1_pin 'tmp parameter for tx2 cmd 'enable transmitter end_tx1_reset rx_address cmp rx2_pin, minusOne wz 'rx_address used in command loop 'if rx2_pin == -1 tx_char if_z jmp #end_rx2_reset 'tx_char used in command loop ' skip RX2 setting smart pin ' ' Reset rx2 clear buffer pointers enable pin and int2 ' tx2cmdparam setint2 #0 'tmp parameter for tx2 cmd 'disable int2 tx_address dirl rx2_pin 'tx_address used in command loop 'disable receiver tx_ct1 mov rx2_head, #0 'tx_ct1 used in tx_isr 'reset serial buffer pointers tx_ct1wait mov rx2_tail, #0 'tx_ct1wait used in tx_isr txdec mov rx2_char, #%110<<6 'txdec used by HEX/DEC txnumptr add rx2_char, rx2_pin 'used as pointer for output of HX/DEC txcogptr wrpin rx2_mode, rx2_pin 'used as pointer for output of HX/DEC 'configure rx_pin for asynchronous receive, always input txloopctr wxpin rx2_bitperiod, rx2_pin setse2 rx2_char 'set se1 to trigger on rx1_pin (rx1_pin high) mov ijmp2, #rx2_isr 'set int2 jump vector to rx2 ISR setint2 #5 'set int2 to trigger on se2 dirh rx2_pin 'enable receiver end_rx2_reset cmp tx2_pin, minusOne wz if_nz call #tx2_reset mov ijmp3,#tx_isr 'set int3 vector - later sysclocks to wait for in tx_isr setint3 #1 'set int3 for ct-passed-ct1 event later decimal num to send getct tx_ct1 'set initial tx_ct1 target later ptr to output decimal num mov tx_ct1wait, #80 ' todo - needs to be adjuted to fastest ports bitfrequence somehow addct1 tx_ct1, tx_ct1wait ' 'command loop ' rx1_cmd_check cmp rx1_pin, minusOne wz if_z jmp #tx1_cmd_check cmp rx1cmd, minusOne wz 'old cmd finished? if_z rdlong rx1cmd, rx1_mailbox_ptr 'cmd from rx1 mailbox if_z rdlong rx1param, rx1_param_ptr 'param from rx1 mailbox cmp rx1cmd, minusOne wz if_nz call #rx1_do_cmd 'do it tx1_cmd_check cmp tx1_pin, minusOne wz if_z jmp #rx2_cmd_check cmp tx1cmd, minusOne wz 'old cmd finished? if_z rdlong tx1cmd, tx1_mailbox_ptr 'cmd from tx1 mailbox if_z rdlong tx1param, tx1_param_ptr 'param from tx1 mailbox cmp tx1cmd, minusOne wz if_nz call #tx1_do_cmd 'do it rx2_cmd_check cmp rx2_pin, minusOne wz if_z jmp #tx2_cmd_check cmp rx2cmd, minusOne wz 'old cmd finished? if_z rdlong rx2cmd, rx2_mailbox_ptr 'cmd from rx2 mailbox if_z rdlong rx2param, rx2_param_ptr 'param from rx2 mailbox cmp rx2cmd, minusOne wz if_nz call #rx2_do_cmd 'do it tx2_cmd_check cmp tx2_pin, minusOne wz if_z jmp #rx1_cmd_check cmp tx2cmd, minusOne wz 'old cmd finished? if_z rdlong tx2cmd, tx2_mailbox_ptr 'cmd from tx2 mailbox if_z rdlong tx2param, tx2_param_ptr 'param from tx2 mailbox cmp tx2cmd, minusOne wz if_nz call #tx2_do_cmd 'do it jmp #rx1_cmd_check ' ' tx1 try to send, reads long in lut buffer ' tx1_send cmp tx1_head, tx1_tail wz 'byte to send? if_z ret 'no wait for next time ' testp tx1_pin wc 'wait for transmit done? ' if_nc ret rdpin tx1_char, tx1_pin wc 'wait for pin ready? if_c ret mov tx1_address, tx1_tail 'adjust to buffer start add tx1_address, tx1_lut_buff 'by adding tx1_lut_buff rdlut tx1_char, tx1_address 'get byte from circular buffer in lut incmod tx1_tail, tx1_lut_btop 'increment buffer tail wypin tx1_char, tx1_pin 'send byte ret ' ' tx2 try to send, reads long in lut buffer ' tx2_send cmp tx2_head, tx2_tail wz 'byte to send? if_z ret 'no wait for next time ' testp tx2_pin wc 'wait for transmit done? ' if_nc ret rdpin tx2_char, tx2_pin wc 'wait for pin ready? if_c ret mov tx2_address, tx2_tail 'adjust to buffer start add tx2_address, tx2_lut_buff 'by adding tx2_lut_buff rdlut tx2_char, tx2_address 'get byte from circular buffer in lut incmod tx2_tail, tx2_lut_btop 'increment buffer tail wypin tx2_char, tx2_pin 'send byte ret ' ' tx write interrupt, reads bytes from longs in lut buffer ' 'int3 isr, runs once every tx_ct1wait clocks tx_isr call #tx2_send call #tx1_send addct1 tx_ct1, tx_ct1wait 'update txct1 target reti3 'return to main program ' ' rx1 read interrupt writes byte as long in lut buffer ' ' testp rxpin wc ' char ready? ' if_c rdpin rxbyte, rxpin ' if_c shr rxbyte, #24 rx1_isr 'testp rx1_pin wc 'char ready? ' if_nc reti1 rdpin rx1_char, rx1_pin 'get received chr mov rx1_address, rx1_head 'test if space in buffer incmod rx1_address, rx1_lut_btop 'try to increment head cmp rx1_address, rx1_tail wz 'hitting tail is bad if_z reti1 'buffer full - ignore shr rx1_char, #32-8 'shift to lsb justify mov rx1_address, rx1_head 'adjust to buffer start add rx1_address, rx1_lut_buff 'by adding rx1_lut_buff wrlut rx1_char, rx1_address 'write byte to circular buffer in lut incmod rx1_head, rx1_lut_btop 'increment buffer head reti1 'exit ' ' rx2 read interrupt writes byte as long in lut buffer ' rx2_isr 'testp rx2_pin wc 'char ready? ' if_nc reti2 rdpin rx2_char, rx2_pin 'get received chr mov rx2_address, rx2_head 'test if space in buffer incmod rx2_address, rx2_lut_btop 'try to increment head cmp rx2_address, rx2_tail wz 'hitting tail is bad if_z reti2 'buffer full - ignore shr rx2_char, #32-8 'shift to lsb justify mov rx2_address, rx2_head 'adjust to buffer start add rx2_address, rx2_lut_buff 'by adding rx1_lut_buff wrlut rx2_char, rx2_address 'write byte to circular buffer in lut incmod rx2_head, rx2_lut_btop 'increment buffer head reti2 'exit ' ' Reset tx2 set tx2_mode and tx2_bitperiod, enable pin ' tx2_reset dirl tx2_pin 'disable transmitter mov tx2_head, #0 'reset serial buffer pointers mov tx2_tail, #0 wrpin tx2_mode, tx2_pin 'configure tx1_pin for asynchronous transmit, always output wxpin tx2_bitperiod, tx2_pin _ret_ dirh tx2_pin 'enable transmitter ' ' handle rx1 mailbox ' rx1_do_cmd cmps rx1cmd, #0 wcz '#rx1_block if_ge jmp #.rx1block neg rx1cmd mov rx1cmdparam, rx1cmd shr rx1cmdparam, #8 and rx1cmd, #$FF cmp rx1cmd, #2 wz '#rx1_check if_z jmp #.rx1check cmp rx1cmd, #3 wz '#rx1_count if_z jmp #.rx1count cmp rx1cmd, #4 wz '#rx1_size if_z jmp #.rx1size jmp #.done .rx1block cmp rx1cmd, #0 wz 'need more bytes? if_z jmp #.done 'no - done cmp rx1_head, rx1_tail wz 'byte received? if_z ret 'no - try again don't block the rest mov rx_address, rx1_tail 'adjust to buffer start add rx_address, rx1_lut_buff 'by adding rx1_lut_buff rdlut rx_char, rx_address 'get byte from circular buffer in lut incmod rx1_tail, rx1_lut_btop 'increment buffer tail wrbyte rx_char, rx1param 'write byte to Block add rx1param, #1 'adjust Block address _ret_ sub rx1cmd, #1 'adjust count .rx1check mov rx_char, minusOne cmp rx1_head, rx1_tail wz 'byte received? if_z jmp #.donewritepar 'no - done .rx1get cmp rx1_head, rx1_tail wz 'byte received? if_z neg rx1cmd 'now get cmd again if_z ret 'try again don't block the rest rdlut rx_char, rx1_tail 'get byte from circular buffer in lut incmod rx1_tail, rx1_lut_btop 'increment buffer tail jmp #.donewritepar .rx1count mov rx_char, rx1_head 'returns count of bytes in receive buffer RX1 in rx_char cmp rx1_head, rx1_tail wcz if_b add rx_char, rx1_lut_btop sub rx_char, rx1_tail jmp #.donewritepar .rx1size mov rx_char, rx1_lut_btop 'returns size of receive buffer RX1 in rx_char .donewritepar wrlong rx_char, rx1_param_ptr 'rx1 parameter back in HUB .done mov rx1cmd, minusOne _ret_ wrlong rx1cmd, rx1_mailbox_ptr 'rx1 command finished ' ' handle rx2 mailbox ' rx2_do_cmd cmps rx2cmd, #0 wcz '#rx2_blck if_ge jmp #.rx2block neg rx2cmd mov rx2cmdparam, rx2cmd shr rx2cmdparam, #8 and rx2cmd, #$FF cmp rx2cmd, #2 wz '#rx2_check if_z jmp #.rx2check cmp rx2cmd, #3 wz '#rx2_count if_z jmp #.rx2count cmp rx2cmd, #4 wz '#rx2_size if_z jmp #.rx2size jmp #.done .rx2block cmp rx2cmd, #0 wz 'need more bytes? if_z jmp #.done 'no - done cmp rx2_head, rx2_tail wz 'byte received? if_z ret 'no - try again don't block the rest mov rx_address, rx2_tail 'adjust to buffer start add rx_address, rx2_lut_buff 'by adding rx2_lut_buff rdlut rx_char, rx_address 'get byte from circular buffer in lut incmod rx2_tail, rx2_lut_btop 'increment buffer tail wrbyte rx_char, rx2param 'write byte to Block add rx2param, #1 'adjust Block address _ret_ sub rx2cmd, #1 'adjust count .rx2check mov rx_char, minusOne cmp rx2_head, rx2_tail wz 'byte received? if_z jmp #.donewritepar 'no - done .rx2get cmp rx2_head, rx2_tail wz 'byte received? if_z neg rx2cmd 'no - now get cmd again if_z ret 'no - try again don't block the rest rdlut rx_char, rx2_tail 'get byte from circular buffer in lut incmod rx2_tail, rx2_lut_btop 'increment buffer tail jmp #.donewritepar .rx2count mov rx_char, rx2_head 'returns count of bytes in receive buffer RX2 in rx_char cmp rx2_head, rx2_tail wcz if_b add rx_char, rx2_lut_btop sub rx_char, rx2_tail jmp #.donewritepar .rx2size mov rx_char, rx2_lut_btop 'returns size of receive buffer RX2 in rx_char .donewritepar wrlong rx_char, rx2_param_ptr 'rx2 parameter back in HUB .done mov rx2cmd, minusOne _ret_ wrlong rx2cmd, rx2_mailbox_ptr 'rx2 command finished ' ' handle tx1 mailbox ' tx1_do_cmd cmps tx1cmd, #0 wcz '#tx1_block if_ge jmp #.tx1block neg tx1cmd mov tx1cmdparam, tx1cmd shr tx1cmdparam, #8 and tx1cmd, #$FF cmp tx1cmd, #2 wz '#get count of free bytes in tx1 buffer or -1 if buffer full if_z jmp #.tx1check cmp tx1cmd, #3 wz 'get count of free bytes in tx1 buffer if_z jmp #.tx1count cmp tx1cmd, #4 wz 'get size of tx1 buffer if_z jmp #.tx1size cmp tx1cmd, #5 wz 'output str on tx1 if_z neg tx1cmd if_z jmp #.tx1block cmp tx1cmd, #6 wz 'output dec without leading zero's on tx1 if_z jmp #.tx1dec cmp tx1cmd, #7 wz 'output dec with leading zero's on tx1 if_z jmp #.tx1dec cmp tx1cmd, #8 wz 'output hex without leading zero's on tx1 if_z jmp #.tx1hex cmp tx1cmd, #9 wz 'output hev with leading zero's on tx1 if_z jmp #.tx1hex jmp #.done 'clear tx1_mailbox - done .tx1block cmp tx1cmd, #0 wz 'more bytes? if_z jmp #.done 'no - clear tx1_mailbox - tx1block finished mov tx_address, tx1_head 'if head+1 = tail incmod tx_address, tx1_lut_btop cmp tx_address, tx1_tail wz 'no - buffer full if_z ret 'no - try again don't block the rest mov tx_char, #0 rdbyte tx_char, tx1param 'get next char cmp tx1cmd, minusFive wz 'string output? if_nz sub tx1cmd, #1 'no - adjust count of bytes to send if_z cmp tx_char, #0 wz 'yes - more bytes? if_z jmp #.done 'no - clear tx2_mailbox - tx2block (string) finished mov tx_address, tx1_head 'adjust to buffer start add tx_address, tx1_lut_buff 'by adding tx1_lut_buff wrlut tx_char, tx_address 'write byte to circular buffer in lut incmod tx1_head, tx1_lut_btop 'increment buffer head _ret_ add tx1param, #1 'adjust Block address .tx1dec mov txdec, tx1param 'output decimal number on tx1 mov txnumptr, #tx1_write_num_wait mov txcmd, tx1cmd mov txcmdparam, tx1cmdparam call #decout jmp #.done 'clear tx1_mailbox - tx1dec finished .tx1hex mov txdec, tx1param 'output hex number on tx1 mov txnumptr, #tx1_write_num_wait mov txcmd, tx1cmd mov txcmdparam, tx1cmdparam call #hexout jmp #.done 'clear tx1_mailbox - tx1hex finished .tx1check mov tx_char, minusOne 'returns -1 or count of bytes in transmit buffer for tx1 mov tx_address, tx1_head 'if head+1 = tail incmod tx_address, tx1_lut_btop cmp tx_address, tx1_tail wz if_z jmp #.donewritepar 'return buffer full else return tx1_count .tx1count mov tx_char, tx1_head 'returns count of bytes free in transmit buffer in tx_char cmp tx1_head, tx1_tail wc wz 'if head0) if_nz mov txcmd, #7 'force ouput of zeroes not spaces after first digit cmp txloopctr, #1 wz if_z mov decbuf, #1 'set Flag also for last digit if_z mov txcmd, #7 'force ouput of zeroes not spaces for last digit cmp decbuf, #0 wz 'now check Flag if we need to output if_z jmp #.done 'no - done cmp txcmdparam, #0 wz 'if no size if_z jmp #.out 'put out char cmp txcmd, #6 wz 'is cmd 6? if_z jmp #.replaceZero cmp txcmd, #8 wz 'is cmd 8? if_z jmp #.replaceZero jmp #.out 'no - put out char .replaceZero cmp tx_char, #0 wz 'if zero replace by space if_z mov tx_char, #16 '48 - 32 ... space instead of 0 if_z neg tx_char 'now -16 .out call txnumptr 'send char (+48) .done sub txcogptr, #1 'next char _ret_ djnz txloopctr, #digitoutloop 'next digit ' minusOne long -1 minusFive long -5 ' rx1cmd long -1 tx1cmd long -1 rx2cmd long -1 tx2cmd long -1 ' ' 'fit 0'476