' oscmode = $010c3f04 con oscmode = 17579780 ' freq = 160_000_000 freq = 160000000 ' baud = 230_400 baud = 230400 ' _rom_baud = 115_200 _rom_baud = 115200 ' _rom_rx_pin = 51 ' pin serial receiver _rom_rx_pin = 51 ' _rom_tx_pin = 53 ' pin serial transmitter _rom_tx_pin = 53 dat ' start original program in COG1 and jmp COG0 into TAQOZ, patching ROM serial pins orgh 0 org 0 ' patch ROM ' tx_pin in _Enter_Monitor wrbyte #_rom_tx_pin, ##$FCA98 ' new - wypin lmm_x, #_rom_tx_pin ' old - wypin lmm_x, #tx_pin ' tx_pin & rx_pin in _SerialInit wrbyte #_rom_tx_pin, ##$FCABC ' new - wrpin ##_txmode, #_rom_tx_pin ' old - wrpin ##_txmode, #tx_pin wrbyte #_rom_tx_pin, ##$FCAC0 ' new - wxpin lmm_x, #_rom_tx_pin ' old - wxpin lmm_x, #tx_pin wrbyte #(_rom_tx_pin<<1),##$FCAC5 ' new - dirh #_rom_tx_pin ' old - dirh #tx_pin wrbyte #$88, ##$FCACA ' new - wrpin ##%0000_0001_000_0000000000000_00_11111_0, #_rx_pin ' old - wrpin ##_rxmode, #rx_pin wrbyte #_rom_rx_pin, ##$FCACC ' new - wrpin ##%0000_0001_000_0000000000000_00_11111_0, #_rom_rx_pin ' old - wrpin ##_rxmode, #rx_pin wrbyte #_rom_rx_pin, ##$FCAD0 ' new - wxpin lmm_x, #_rom_rx_pin ' old - wxpin lmm_x, #rx_pin wrbyte #(_rom_rx_pin<<1),##$FCAD5 ' new - dirh #_rom_rx_pin ' old - dirh #rx_pin wrbyte #_rom_tx_pin, ##$FCADC ' new - wypin lmm_x, #_rom_tx_pin ' old - wypin lmm_x, #tx_pin ' tx_pin in _HubTx wrbyte #(_rom_tx_pin<<1),##$FCAF5 ' new - testp #_rom_tx_pin wc ' old - testp #tx_pin wc wrbyte #_rom_tx_pin, ##$FCAFC ' new - wypin lmm_x, #_rom_tx_pin ' old - wypin lmm_x, #tx_pin ' rx_pin in _HubRx wrbyte #(_rom_rx_pin<<1),##$FCB11 ' new - testp #_rom_rx_pin wc ' old - testp #rx_pin wc wrbyte #_rom_rx_pin, ##$FCB18 ' new - rdpin lmm_x, #_rom_tx_pin ' old - rdpin lmm_x, #tx_pin ' _REENTER_TAQOZ not _START_TAQOZ on ESC cr wrbyte #$B4, ##$FCD8C ' new - if_e jmp #@_REENTER_TAQOZ ' old - if_e jmp #@_START_TAQOZ 'TAQOZ wrbyte #(_rom_tx_pin<<1),##$FE9D1 ' new - dirh #_rom_tx_pin ' old - dirh #tx_pin wrbyte #_rom_tx_pin, ##$FE9D4 ' new - wypin #$0D, #_rom_tx_pin ' old - wypin #$0D, #tx_pin wrbyte #(_rom_rx_pin<<1),##$FE9DD ' new - dirh #_rom_rx_pin ' old - dirh #rx_pin wrbyte #_rom_rx_pin, ##$FE9E0 ' new - rdpin fz,#_rom_rx_pin wc ' old - rdpin fz,#rx_pin wc wrlong rxsetsel, ##$FE9F0 ' new - setse1 #%110<<6+_rom_rx_pin ' old - setse1 #%110<<6+rx_pin wrbyte #_rom_rx_pin, ##$FEA14 ' new - rdpin fz,#_rom_rx_pin ' old - rdpin fz,#rx_pin wc wrbyte #_rom_tx_pin, ##$FF358 ' new - mov txpin,#_rom_tx_pin ' old - mov txpin,#tx_pin wrbyte #_rom_tx_pin, ##$FF370 ' new - txpin long _rom_tx_pin ' old - txpin long tx_pin ' now start mov $1ef, ##$FC000 ' lmm_bufad, locn of hub buffer for serial routine mov $1e0, ##(freq / _rom_baud) << 16 + 7 ' _rom_baud baud, 8 bits ' lmm_x, sets serial baud call #$fcab8 ' initialise serial _SerialInit 'SETQ ptra_val ' would end up in ptra of new cog coginit #1,##@_mainprogram ' Start Main program in COG #1 '.monitor call #$fcd78 ' to the monitor/debugger ' jmp #.monitor ' loop back in case of "Q" jmp #$FD028 ' and transfer control of COG 0 to TAQOZ rxsetsel setse1 #%110<<6+_rom_rx_pin fit $1E0 ' ensure LMM reserved area cog $1E0-$1EF available ''--------------------------------------------------------------------------------------------------- orgh $10000 ' leave the first 64K free for TAQOZ org 0 _mainprogram ''--------------------------------------------------------------------------------------------------- '' HERE NOW THE SOURCE OF WHATEVER YOU WANT TO PLAY WITH (it will run on COG #1++) '' '' you have to change orgh $400 against orgh $10400 in you code following this ''--------------------------------------------------------------------------------------------------- cogid $1d0 coginit $1d0,##$10400 orgh $10010 long 0 'reserved long 0 ' clock frequency: will default to 160000000 long 0 ' clock mode: will default to $10007f8 orgh $10400 org 0 entry cmp ptra, #0 wz if_ne jmp #spininit mov ptra, ptr_stackspace_ calla #_demo cogexit cogid arg01 cogstop arg01 spininit rdlong objptr, ptra add ptra, #4 rdlong result1, ptra add ptra, #4 rdlong arg01, ptra add ptra, #4 rdlong arg02, ptra add ptra, #4 rdlong arg03, ptra add ptra, #4 rdlong arg04, ptra sub ptra, #16 calla result1 jmp #cogexit COUNT_ long 0 RETADDR_ long 0 pushregs_ rdlong RETADDR_, --ptra tjz COUNT_, #pushregs_done_ sub COUNT_, #1 setq COUNT_ wrlong local01, ptra add COUNT_, #1 pushregs_done_ shl COUNT_, #2 add ptra, COUNT_ shr COUNT_, #2 wrlong COUNT_, ptra++ wrlong fp, ptra++ mov fp, ptra jmp RETADDR_ popregs_ rdlong RETADDR_, --ptra rdlong fp, --ptra rdlong COUNT_, --ptra tjz COUNT_, #popregs__ret shl COUNT_, #2 sub ptra, COUNT_ shr COUNT_, #2 sub COUNT_, #1 setq COUNT_ rdlong local01, ptra popregs__ret jmp RETADDR_ unsdivide_ setq #0 qdiv muldiva_, muldivb_ getqx muldivb_ getqy muldiva_ reta divide_ abs muldiva_,muldiva_ wc 'abs(x) muxc itmp2_,#%11 'store sign of x abs muldivb_,muldivb_ wcz 'abs(y) if_c xor itmp2_,#%10 'store sign of y calla #unsdivide_ test itmp2_,#1 wc 'restore sign, remainder negc muldiva_,muldiva_ test itmp2_,#%10 wc 'restore sign, division result negc muldivb_,muldivb_ reta fp long 0 itmp1_ long 0 itmp2_ long 0 objptr long @objmem ptr_L__0035_ long @LR__0036 ptr_L__0036_ long @LR__0037 ptr_L__0037_ long @LR__0038 ptr__FullDuplexSerial2_dat__ long @_FullDuplexSerial2_dat_ ptr_stackspace_ long @stackspace result1 long 0 COG_BSS_START fit 496 orgh hubentry ' ' PUB demo | c _demo ' clkset(oscmode, freq) mov arg01, ##17579780 mov arg02, ##160000000 mov arg03, #3 calla #__system__clkset ' ser.start(63, 62, 0, baud) mov arg01, #63 mov arg02, #62 mov arg03, #0 mov arg04, ##230400 calla #_FullDuplexSerial2_start ' rom.start(_rom_tx_pin+1, _rom_rx_pin+1, 0, _rom_baud) mov arg01, #54 mov arg02, #52 mov arg03, #0 mov arg04, ##115200 add objptr, #156 calla #_TaqozSerial_start sub objptr, #156 ' ' repeat 30000 mov _demo__idx__0019, ##30000 LR__0001 ' ' if (c:=rom.rxcheck)>-1 add objptr, #156 calla #_TaqozSerial_rxcheck sub objptr, #156 mov _demo_c, result1 cmps _demo_c, ##-1 wcz if_be jmp #LR__0002 ' ser.tx(c) mov arg01, _demo_c mov arg02, #0 calla #_FullDuplexSerial2_tx LR__0002 ' if (c:=ser.rxcheck)>-1 mov arg01, #0 calla #_FullDuplexSerial2_rxcheck mov _demo_c, result1 cmps _demo_c, ##-1 wcz if_be jmp #LR__0003 ' rom.tx(c) mov arg01, _demo_c add objptr, #156 calla #_TaqozSerial_tx sub objptr, #156 LR__0003 djnz _demo__idx__0019, #LR__0001 ' ' rom.tx(13) mov arg01, #13 add objptr, #156 calla #_TaqozSerial_tx ' rom.tx(10) mov arg01, #10 calla #_TaqozSerial_tx ' rom.str(string("56 BLINK",13,10)) mov arg01, ptr_L__0035_ calla #_TaqozSerial_str ' rom.str(string("57 BLINK",13,10)) mov arg01, ptr_L__0036_ calla #_TaqozSerial_str ' rom.str(string("2 2 + .",13,10)) mov arg01, ptr_L__0037_ calla #_TaqozSerial_str sub objptr, #156 ' ' repeat LR__0004 ' ' if (c:=rom.rxcheck)>-1 add objptr, #156 calla #_TaqozSerial_rxcheck sub objptr, #156 mov _demo_c, result1 cmps _demo_c, ##-1 wcz if_be jmp #LR__0005 ' ser.tx(c) mov arg01, _demo_c mov arg02, #0 calla #_FullDuplexSerial2_tx LR__0005 ' if (c:=ser.rxcheck)>-1 mov arg01, #0 calla #_FullDuplexSerial2_rxcheck mov _demo_c, result1 cmps _demo_c, ##-1 wcz if_be jmp #LR__0006 ' rom.tx(c) mov arg01, _demo_c add objptr, #156 calla #_TaqozSerial_tx sub objptr, #156 LR__0006 jmp #LR__0004 _demo_ret reta ' ' ' '======================================================================= ' ' ' '----------------------------------------------------------------------- ' 'stop pasm cog if already running ' '----------------------------------------------------------------------- ' ' ' PUB stop _FullDuplexSerial2_stop mov COUNT_, #1 calla #pushregs_ ' if cog rdlong local01, objptr wz if_e jmp #LR__0007 ' cogstop(cog-1) rdlong arg01, objptr sub arg01, #1 ' a global variable, on the stack, or in the heap (memory allocated via cogstop arg01 ' a reference copy, the garbage collector will leave the memory alone. If mov result1, #0 ' cog := 0 mov local01, #0 wrlong local01, objptr LR__0007 mov ptra, fp calla #popregs_ _FullDuplexSerial2_stop_ret reta ' ' ' '----------------------------------------------------------------------- ' 'use this to start a 1 port driver with 1024 bytes buffer each channel ' '----------------------------------------------------------------------- ' ' ' PUB start(rxpin = 63, txpin = 62, mode = 0, baudrate = 230_400) | bitrate,rxmode1,txmode1 _FullDuplexSerial2_start mov COUNT_, #8 calla #pushregs_ mov local01, arg01 mov local02, arg02 mov local03, arg03 mov muldivb_, arg04 ' '' mode bit 0 = invert rx ' '' mode bit 1 = invert tx ' '' mode bit 2 = open-drain/source tx - not supported yet ' '' mode bit 3 = ignore tx echo on rx - not supported yet ' bitrate := 7 + ((CLKFREQ / baudrate) << 16) rdlong muldiva_, #20 calla #divide_ mov local04, muldivb_ shl local04, #16 mov local05, #7 add local05, local04 ' rxmode1 := _rx_mode_default mov local06, #62 ' txmode1 := _tx_mode_default mov local07, #124 ' if (mode > -1) cmps local03, ##-1 wcz if_be jmp #LR__0008 ' if (mode & %1) > 0 mov local08, local03 and local08, #1 cmps local08, #0 wcz ' rxmode1 := _rx_mode_inverted if_a mov local06, ##-2147483586 ' if (mode & %10) > 0 and local03, #2 cmps local03, #0 wcz ' txmode1 := _tx_mode_inverted if_a mov local07, ##-2147483524 LR__0008 ' RETURN startpasm(@rx1cmd, rxpin, bitrate, rxmode1, 0, $3FF, txpin, bitrate, txmode1, $100, $3FF, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 100) add objptr, #4 mov arg01, objptr sub objptr, #4 mov arg02, local01 mov arg03, local05 mov arg04, local06 mov arg05, #0 mov arg06, ##1023 mov arg07, local02 mov arg08, local05 mov arg09, local07 mov arg10, #256 mov arg11, ##1023 mov arg12, ##-1 mov arg13, ##-1 mov arg14, ##-1 mov arg15, ##-1 mov arg16, ##-1 mov arg17, ##-1 mov arg18, ##-1 mov arg19, ##-1 mov arg20, ##-1 mov arg21, ##-1 mov arg22, #100 calla #_FullDuplexSerial2_startpasm mov ptra, fp calla #popregs_ _FullDuplexSerial2_start_ret reta ' ' ' '----------------------------------------------------------------------- ' 'this provides the parameter array needed to start the pasm cog on the stack ' '----------------------------------------------------------------------- ' ' ' PRI startpasm(mailboxaddress, rxpin1, rxbitrate1, rxmode1, rxlutstart1, rxlutsize1, txpin1, txbitrate1, txmode1, txlutstart1, txlutsize1, rxpin2, rxbitrate2, rxmode2, rxlutstart2, rxlutsize2, txpin2, txbitrate2, txmode2, txlutstart2, txlutsize2, txclocks) _FullDuplexSerial2_startpasm mov COUNT_, #26 calla #pushregs_ mov local01, arg01 mov local02, arg02 mov local03, arg03 mov local04, arg04 mov local05, arg05 mov local06, arg06 mov local07, arg07 mov local08, arg08 mov local09, arg09 mov local10, arg10 mov local11, arg11 mov local12, arg12 mov local13, arg13 mov local14, arg14 mov local15, arg15 mov local16, arg16 mov local17, arg17 mov local18, arg18 mov local19, arg19 mov local20, arg20 mov local21, arg21 mov local22, arg22 mov local23, #0 ' stop calla #_FullDuplexSerial2_stop ' ' hmailboxaddress := mailboxaddress add objptr, #36 wrlong local01, objptr ' hrxpin1 := rxpin1 add objptr, #4 wrlong local02, objptr ' hrxbitrate1 := rxbitrate1 add objptr, #4 wrlong local03, objptr ' hrxmode1 := rxmode1 add objptr, #4 wrlong local04, objptr ' hrxlutstart1 := rxlutstart1 add objptr, #4 wrlong local05, objptr ' hrxlutsize1 := rxlutsize1 add objptr, #4 wrlong local06, objptr ' htxpin1 := txpin1 add objptr, #4 wrlong local07, objptr ' htxbitrate1 := txbitrate1 add objptr, #4 wrlong local08, objptr ' htxmode1 := txmode1 add objptr, #4 wrlong local09, objptr ' htxlutstart1 := txlutstart1 add objptr, #4 wrlong local10, objptr ' htxlutsize1 := txlutsize1 add objptr, #4 wrlong local11, objptr ' hrxpin2 := rxpin2 add objptr, #4 wrlong local12, objptr ' hrxbitrate2 := rxbitrate2 add objptr, #4 wrlong local13, objptr ' hrxmode2 := rxmode2 add objptr, #4 wrlong local14, objptr ' hrxlutstart2 := rxlutstart2 add objptr, #4 wrlong local15, objptr ' hrxlutsize2 := rxlutsize2 add objptr, #4 wrlong local16, objptr ' htxpin2 := txpin2 add objptr, #4 wrlong local17, objptr ' htxbitrate2 := txbitrate2 add objptr, #4 wrlong local18, objptr ' htxmode2 := txmode2 add objptr, #4 wrlong local19, objptr ' htxlutstart2 := txlutstart2 add objptr, #4 wrlong local20, objptr ' htxlutsize2 := txlutsize2 add objptr, #4 wrlong local21, objptr ' htxclocks := txclocks add objptr, #4 wrlong local22, objptr ' 'Mailbox. So now I use long[long[]] to access the first long in the later used mailbox as Flag ' long[long[@hmailboxaddress]] := 0 'set flag (0) to know if the started cog has read its parameters sub objptr, #84 rdlong local24, objptr mov local25, #0 wrlong local25, local24 ' cog := cognew(@cogserial_init,@hmailboxaddress) + 1 mov arg02, ptr__FullDuplexSerial2_dat__ mov arg03, objptr sub objptr, #36 mov arg01, #30 calla #__system___coginit mov local26, result1 add local26, #1 wz wrlong local26, objptr ' if cog 'if I was able to start the COG if_e jmp #LR__0010 ' repeat until long[long[@hmailboxaddress]] == -1 'I wait until Flag states cog is done reading parameter and ready to roll (-1) LR__0009 add objptr, #36 rdlong local24, objptr sub objptr, #36 rdlong local25, local24 cmp local25, ##-1 wz if_ne jmp #LR__0009 ' RESULT := 1 'now start done mov local23, #1 LR__0010 ' RETURN mov result1, local23 mov ptra, fp calla #popregs_ _FullDuplexSerial2_startpasm_ret reta ' ' ' '----------------------------------------------------------------------- ' ' check if byte received (never waits) ' ' returns -1 if no byte, otherwise received byte ' '----------------------------------------------------------------------- ' ' ' PUB rxcheck(port=0) _FullDuplexSerial2_rxcheck ' RETURN read(0, -2, port) mov arg03, arg01 mov arg01, #0 mov arg02, ##-2 calla #_FullDuplexSerial2_read _FullDuplexSerial2_rxcheck_ret reta ' ' ' '----------------------------------------------------------------------- ' ' receive a block from serial to memory of given size in bytes (waits until done) ' '----------------------------------------------------------------------- ' ' ' PUB read(hubaddress, size, port=0) _FullDuplexSerial2_read mov COUNT_, #1 calla #pushregs_ ' read_async(hubaddress, size, port) mov local01, arg03 calla #_FullDuplexSerial2_read_async ' RETURN wait_rxready(port, -1) mov arg01, local01 mov arg02, ##-1 calla #_FullDuplexSerial2_wait_rxready mov ptra, fp calla #popregs_ _FullDuplexSerial2_read_ret reta ' ' ' '----------------------------------------------------------------------- ' ' transmit a byte (waits until done) ' '----------------------------------------------------------------------- ' ' ' PUB tx(val, port=0) _FullDuplexSerial2_tx mov COUNT_, #1 calla #pushregs_ ' write(-1,val, port) mov local01, arg01 mov arg03, arg02 mov arg01, ##-1 mov arg02, local01 calla #_FullDuplexSerial2_write mov ptra, fp calla #popregs_ _FullDuplexSerial2_tx_ret reta ' ' ' '----------------------------------------------------------------------- ' ' transmit a block from memory to serial of given size in bytes (waits until done) ' '----------------------------------------------------------------------- ' ' ' PUB write(hubaddress, size, port=0) _FullDuplexSerial2_write mov COUNT_, #1 calla #pushregs_ ' write_async(hubaddress, size, port) mov local01, arg03 calla #_FullDuplexSerial2_write_async ' RETURN wait_txready(port) mov arg01, local01 calla #_FullDuplexSerial2_wait_txready mov ptra, fp calla #popregs_ _FullDuplexSerial2_write_ret reta ' ' ' '----------------------------------------------------------------------- ' ' waits until rx port cmd = -1, signaling completion of last cmd or being ready for next cmd ' '----------------------------------------------------------------------- ' ' ' PUB wait_rxready(port=0, timeout=-1) _FullDuplexSerial2_wait_rxready ' RESULT := -2 mov _var01, ##-2 ' if port cmp arg01, #0 wz if_e jmp #LR__0017 ' if timeout > 0 cmps arg02, #0 wcz if_be jmp #LR__0014 ' repeat LR__0011 ' timeout-- sub arg02, #1 ' if rx2cmd == -1 add objptr, #20 rdlong _var02, objptr sub objptr, #20 cmp _var02, ##-1 wz if_ne jmp #LR__0012 ' RESULT := rx2param add objptr, #24 rdlong _var01, objptr sub objptr, #24 ' timeout := -10 mov arg02, ##-10 LR__0012 cmps arg02, #0 wcz if_ae jmp #LR__0011 ' until timeout < 0 ' if timeout > -10 cmps arg02, ##-10 wcz if_be jmp #LR__0013 ' rx2cmd := -1 mov _var02, ##-1 add objptr, #20 wrlong _var02, objptr ' rx2param := -1 add objptr, #4 wrlong _var02, objptr sub objptr, #24 LR__0013 ' else jmp #LR__0016 LR__0014 ' repeat until rx2cmd == -1 LR__0015 add objptr, #20 rdlong _var02, objptr sub objptr, #20 cmp _var02, ##-1 wz if_ne jmp #LR__0015 ' RESULT := rx2param add objptr, #24 rdlong _var01, objptr sub objptr, #24 LR__0016 ' else jmp #LR__0024 LR__0017 ' if timeout > 0 cmps arg02, #0 wcz if_be jmp #LR__0021 ' repeat LR__0018 ' timeout-- sub arg02, #1 ' if rx1_cmd == -1 add ptr__FullDuplexSerial2_dat__, ##1532 rdlong _var02, ptr__FullDuplexSerial2_dat__ sub ptr__FullDuplexSerial2_dat__, ##1532 cmp _var02, ##-1 wz if_ne jmp #LR__0019 ' RESULT := rx1param add objptr, #8 rdlong _var01, objptr sub objptr, #8 ' timeout := -10 mov arg02, ##-10 LR__0019 cmps arg02, #0 wcz if_ae jmp #LR__0018 ' until timeout < 0 ' if timeout > -10 cmps arg02, ##-10 wcz if_be jmp #LR__0020 ' rx1cmd := -1 mov _var02, ##-1 add objptr, #4 wrlong _var02, objptr ' rx1param := -1 add objptr, #4 wrlong _var02, objptr sub objptr, #8 LR__0020 ' else jmp #LR__0023 LR__0021 ' repeat until rx1cmd == -1 LR__0022 add objptr, #4 rdlong _var02, objptr sub objptr, #4 cmp _var02, ##-1 wz if_ne jmp #LR__0022 ' RESULT := rx1param add objptr, #8 rdlong _var01, objptr sub objptr, #8 LR__0023 LR__0024 mov result1, _var01 _FullDuplexSerial2_wait_rxready_ret reta ' ' ' '----------------------------------------------------------------------- ' ' receive a block from serial to memory of given size in bytes (does not wait for completion - you may need to check rxX_cmd for -1 [done] or not later in your code) ' '----------------------------------------------------------------------- ' ' ' PUB read_async(hubaddress, size, port=0) _FullDuplexSerial2_read_async mov COUNT_, #3 calla #pushregs_ mov local01, arg01 mov local02, arg02 mov local03, arg03 ' wait_rxready(port, -1) mov arg01, local03 mov arg02, ##-1 calla #_FullDuplexSerial2_wait_rxready ' if port cmp local03, #0 wz if_e jmp #LR__0025 ' rx2param := hubaddress add objptr, #24 wrlong local01, objptr ' rx2cmd := size sub objptr, #4 wrlong local02, objptr sub objptr, #20 ' else jmp #LR__0026 LR__0025 ' rx1param := hubaddress add objptr, #8 wrlong local01, objptr ' rx1cmd := size sub objptr, #4 wrlong local02, objptr sub objptr, #4 LR__0026 mov ptra, fp calla #popregs_ _FullDuplexSerial2_read_async_ret reta ' ' ' '----------------------------------------------------------------------- ' ' waits until tx port cmd = -1, signaling completion of last cmd or being ready for next cmd ' '----------------------------------------------------------------------- ' ' ' PUB wait_txready(port=0) _FullDuplexSerial2_wait_txready ' if port cmp arg01, #0 wz if_e jmp #LR__0028 ' repeat until tx2cmd == -1 LR__0027 add objptr, #28 rdlong _var01, objptr sub objptr, #28 cmp _var01, ##-1 wz if_ne jmp #LR__0027 ' RESULT := tx2param add objptr, #32 rdlong _var02, objptr sub objptr, #32 ' else jmp #LR__0030 LR__0028 ' repeat until tx1cmd == -1 LR__0029 add objptr, #12 rdlong _var01, objptr sub objptr, #12 cmp _var01, ##-1 wz if_ne jmp #LR__0029 ' RESULT := tx1param add objptr, #16 rdlong _var02, objptr sub objptr, #16 LR__0030 mov result1, _var02 _FullDuplexSerial2_wait_txready_ret reta ' ' ' '----------------------------------------------------------------------- ' ' sends a block from memory to serial of given size in bytes (does not wait for completion - you may need to check tx1_cmd if done or not later in your code) ' '----------------------------------------------------------------------- ' ' ' PUB write_async(hubaddress, size, port=0) _FullDuplexSerial2_write_async mov COUNT_, #3 calla #pushregs_ mov local01, arg01 mov local02, arg02 mov local03, arg03 ' wait_txready(port) mov arg01, local03 calla #_FullDuplexSerial2_wait_txready ' if port cmp local03, #0 wz if_e jmp #LR__0031 ' tx2param := hubaddress add objptr, #32 wrlong local01, objptr ' tx2cmd := size sub objptr, #4 wrlong local02, objptr sub objptr, #28 ' else jmp #LR__0032 LR__0031 ' tx1param := hubaddress add objptr, #16 wrlong local01, objptr ' tx1cmd := size sub objptr, #4 wrlong local02, objptr sub objptr, #12 LR__0032 mov ptra, fp calla #popregs_ _FullDuplexSerial2_write_async_ret reta ' ' PUB start(rxpin, txpin, mode, baudrate) | bitperiod, txmode, rxmode _TaqozSerial_start ' bitperiod := 7 + ((CLKFREQ / baudrate) << 16) rdlong muldiva_, #20 mov muldivb_, arg04 calla #divide_ shl muldivb_, #16 mov _var01, #7 add _var01, muldivb_ ' rx_pin := rxpin wrlong arg01, objptr ' tx_pin := txpin add objptr, #4 wrlong arg02, objptr sub objptr, #4 ' txmode := _txmode mov _var02, #124 ' rxmode := _rxmode mov _var03, ##1879048254 ' asm wrpin _var02, arg02 wxpin _var01, arg02 dirh arg02 wrpin _var03, arg01 wxpin _var01, arg01 dirh arg01 ' return 1 mov result1, #1 _TaqozSerial_start_ret reta ' ' PUB tx(val) | txpin, z _TaqozSerial_tx ' txpin := tx_pin add objptr, #4 rdlong _var01, objptr sub objptr, #4 ' asm wypin arg01, _var01 waitx #1 ' z := 1 mov _var02, #1 wz ' repeat while z <> 0 LR__0033 ' asm testp _var01 wc if_b mov _var02, #0 cmp _var02, #0 wz if_ne jmp #LR__0033 _TaqozSerial_tx_ret reta ' ' ' check if byte received (never waits) ' ' returns -1 if no byte, otherwise byte ' ' PUB rxcheck : rxbyte | rxpin, z _TaqozSerial_rxcheck ' rxbyte := -1 mov result1, ##-1 ' rxpin := rx_pin rdlong _var01, objptr ' asm testp _var01 wc if_b rdpin result1, _var01 if_b shr result1, #24 _TaqozSerial_rxcheck_ret reta ' while v == -1 ' ' ' transmit a string ' PUB str(s) | c _TaqozSerial_str mov COUNT_, #2 calla #pushregs_ mov local01, arg01 ' REPEAT WHILE ((c := byte[s++]) <> 0) LR__0034 rdbyte local02, local01 wz add local01, #1 if_e jmp #LR__0035 ' tx(c) mov arg01, local02 calla #_TaqozSerial_tx jmp #LR__0034 LR__0035 mov ptra, fp calla #popregs_ _TaqozSerial_str_ret reta hubexit jmp #cogexit ' $e == known to be in HUB memory (so no specific COG owner) __system__clkset ' $f == free rdlong _var01, #20 ' $10 = reserved (never free automatically) wrlong arg02, #20 andn _var01, #3 ' $20 = inuse (block was observed to be in use during GC) wrlong arg01, #24 ' the upper 10 bits of flags should be GC_MAGIC, used for sanity checking hubset _var01 hubset arg01 waitx ##200000 add arg01, arg03 hubset arg01 __system__clkset_ret reta ' GC_OWNER_MASK = $000f __system___coginit ' GC_FLAG_RESERVED = $0010 setq arg03 coginit arg01, arg02 wc if_b neg arg01, #1 ' OFF_FLAGS = 2 mov result1, arg01 __system___coginit_ret reta LR__0036 byte "56 BLINK" byte 13 byte 10 byte 0 LR__0037 byte "57 BLINK" byte 13 byte 10 byte 0 LR__0038 byte "2 2 + ." byte 13 byte 10 byte 0 alignl _FullDuplexSerial2_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 byte $61, $01, $04, $fb '-' rx1_pin rdlong rx1_pin, ptra++ 'serial1 rxpin1 byte $61, $03, $04, $fb '-' rx1_bitperiod rdlong rx1_bitperiod, ptra++ 'bitperiod := 7 + ((CLKFREQ / baudrate) << 16) byte $61, $05, $04, $fb '-' rx1_mode rdlong rx1_mode, ptra++ 'configure rx1_pin for asynchronous receive, always input byte $61, $07, $04, $fb '-' rx1_lut_buff rdlong rx1_lut_buff, ptra++ 'lut rx1 receive buffer address in lut byte $61, $09, $04, $fb '-' rx1_lut_btop rdlong rx1_lut_btop, ptra++ 'lut rx1 receive buffer top address in lut (size for rx1) byte $61, $0b, $04, $fb '-' tx1_pin rdlong tx1_pin, ptra++ 'serial1 txpin byte $61, $0d, $04, $fb '-' tx1_bitperiod rdlong tx1_bitperiod, ptra++ 'bitperiod := 7 + ((CLKFREQ / baudrate) << 16) byte $61, $0f, $04, $fb '-' tx1_mode rdlong tx1_mode, ptra++ 'configure tx1_pin for asynchronous transmit, always output byte $61, $11, $04, $fb '-' tx1_lut_buff rdlong tx1_lut_buff, ptra++ 'lut tx1 send buffer address in lut byte $61, $13, $04, $fb '-' tx1_lut_btop rdlong tx1_lut_btop, ptra++ 'lut tx1 send buffer top address in lut (size for tx1) byte $61, $15, $04, $fb '-' rx2_pin rdlong rx2_pin, ptra++ 'serial1 rx2pin byte $61, $17, $04, $fb '-' rx2_bitperiod rdlong rx2_bitperiod, ptra++ 'bitperiod := 7 + ((CLKFREQ / baudrate) << 16) byte $61, $19, $04, $fb '-' rx2_mode rdlong rx2_mode, ptra++ 'configure rx2_pin for asynchronous receive, always input byte $61, $1b, $04, $fb '-' rx2_lut_buff rdlong rx2_lut_buff, ptra++ 'lut rx2 receive buffer address in lut byte $61, $1d, $04, $fb '-' rx2_lut_btop rdlong rx2_lut_btop, ptra++ 'lut rx2 receive buffer top address in lut (size for rx2) byte $61, $1f, $04, $fb '-' tx2_pin rdlong tx2_pin, ptra++ 'serial1 tx2pin byte $61, $21, $04, $fb '-' tx2_bitperiod rdlong tx2_bitperiod, ptra++ 'bitperiod := 7 + ((CLKFREQ / baudrate) << 16) byte $61, $23, $04, $fb '-' tx2_mode rdlong tx2_mode, ptra++ 'configure tx2_pin for asynchronous transmit, always output byte $61, $25, $04, $fb '-' tx2_lut_buff rdlong tx2_lut_buff, ptra++ 'lut tx2 send buffer address in lut byte $61, $27, $04, $fb '-' tx2_lut_btop rdlong tx2_lut_btop, ptra++ 'lut tx2 send buffer top address in lut (size for tx2) byte $61, $29, $04, $fb '-' tx_i_ct1wait rdlong tx_i_ct1wait, ptra++ 'sysclocks to wait between calls to tx interrupt byte $61, $2b, $04, $fb '-' '----------------------------------------------------------------------- '-' ' '-' ' calculate mailbox pointers for later use '-' ' '-' '----------------------------------------------------------------------- '-' rx1_param_ptr mov rx1_param_ptr, rx1_mailbox_ptr 'rx1 param hub address byte $00, $2c, $00, $f6 '-' rx1_head add rx1_param_ptr, #4 'rx1 head position byte $04, $2c, $04, $f1 '-' tx1_mailbox_ptr mov tx1_mailbox_ptr, rx1_param_ptr 'tx1 mailbox hub address byte $16, $30, $00, $f6 '-' rx1_tail add tx1_mailbox_ptr, #4 'rx1 tail position byte $04, $30, $04, $f1 '-' tx1_param_ptr mov tx1_param_ptr, tx1_mailbox_ptr 'tx1 param hub address byte $18, $34, $00, $f6 '-' rx1_i_char add tx1_param_ptr, #4 'tmp char for rx1_isr byte $04, $34, $04, $f1 '-' rx2_mailbox_ptr mov rx2_mailbox_ptr, tx1_param_ptr 'rx2 mailbox hub address byte $1a, $38, $00, $f6 '-' rx1_i_address add rx2_mailbox_ptr, #4 'tmp address for rx1_isr byte $04, $38, $04, $f1 '-' rx2_param_ptr mov rx2_param_ptr, rx2_mailbox_ptr 'rx2 param hub address byte $1c, $3c, $00, $f6 '-' tx1_head add rx2_param_ptr, #4 'tx1 head position byte $04, $3c, $04, $f1 '-' tx2_mailbox_ptr mov tx2_mailbox_ptr, rx2_param_ptr 'tx2 mailbox hub address byte $1e, $40, $00, $f6 '-' tx1_tail add tx2_mailbox_ptr, #4 'tx1 tail position byte $04, $40, $04, $f1 '-' tx2_param_ptr mov tx2_param_ptr, tx2_mailbox_ptr 'tx2 param hub address byte $20, $44, $00, $f6 '-' tx_i_test add tx2_param_ptr, #4 'tmp char for tx1_send byte $04, $44, $04, $f1 '-' '----------------------------------------------------------------------- '-' ' '-' ' clear mailboxes '-' ' '-' '----------------------------------------------------------------------- '-' tx_i_char wrlong minusOne, tx2_param_ptr 'tmp address for tx1_send byte $22, $f8, $62, $fc '-' tx_i_byteindex wrlong minusOne, tx2_mailbox_ptr 'rx2 head position byte $20, $f8, $62, $fc '-' tx_i_ct1 wrlong minusOne, rx2_param_ptr 'rx2 tail position byte $1e, $f8, $62, $fc '-' rx2_i_char wrlong minusOne, rx2_mailbox_ptr 'tmp char for rx2_isr byte $1c, $f8, $62, $fc '-' rx2_i_address wrlong minusOne, tx1_param_ptr 'tmp address for rx2_isr byte $1a, $f8, $62, $fc '-' tx2_head wrlong minusOne, tx1_mailbox_ptr 'tx2 head position byte $18, $f8, $62, $fc '-' tx2_tail wrlong minusOne, rx1_param_ptr 'tx2 tail position byte $16, $f8, $62, $fc '-' '----------------------------------------------------------------------- '-' ' '-' ' Reset rx1 clear buffer pointers enable pin and int1 '-' ' '-' '----------------------------------------------------------------------- '-' mov rx1_head, #0 'reset serial buffer pointers byte $00, $2e, $04, $f6 '-' mov rx1_tail, #0 byte $00, $32, $04, $f6 '-' rx1_i_lut_value cmp rx1_pin, minusOne wz 'tmp address for tx2_send 'if rx1_pin == -1 byte $7c, $03, $08, $f2 '-' tx_i_tail if_z jmp #end_rx1_reset 'tmp cmd used for HEX and DEC out ' skip RX1 setting smart pin byte $28, $00, $90, $ad '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' setint1 #0 'disable int1 byte $25, $00, $64, $fd '-' dirl rx1_pin 'disable receiver byte $40, $02, $60, $fd '-' mov rx1_i_char, #%110<<6 byte $80, $37, $04, $f6 '-' add rx1_i_char, rx1_pin byte $01, $36, $00, $f1 '-' wrpin rx1_mode, rx1_pin 'configure rx_pin for asynchronous receive, always input byte $01, $06, $00, $fc '-' wxpin rx1_bitperiod, rx1_pin byte $01, $04, $10, $fc '-' setse1 rx1_i_char 'set se1 to trigger on rx1_pin (rx1_pin high) byte $20, $36, $60, $fd '-' mov ijmp1, #rx1_isr 'set int1 jump vector to rx1 ISR byte $ab, $e8, $07, $f6 '-' setint1 #4 'set int1 to trigger on se1 byte $25, $08, $64, $fd '-' rx1_i_byte_index dirh rx1_pin 'enable receiver byte $41, $02, $60, $fd '-' end_rx1_reset '-' '----------------------------------------------------------------------- '-' ' '-' ' Reset tx1 set tx1_mode and tx1_bitperiod, enable pin '-' ' '-' '----------------------------------------------------------------------- '-' tx1_param mov tx1_head, #0 'tmp parameter for tx1 cmd 'reset serial buffer pointers byte $00, $3e, $04, $f6 '-' lutvalue mov tx1_tail, #0 byte $00, $42, $04, $f6 '-' rx2_i_byte_index cmp tx1_pin, minusOne wz 'if tx1_pin == -1 byte $7c, $0d, $08, $f2 '-' tx_i_lutbuf if_z jmp #end_tx1_reset 'value used in command loop ' skip setting TX1 smart pin byte $10, $00, $90, $ad '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' byteindex dirl tx1_pin 'tmp parameter for rx1 cmd 'disable transmitter byte $40, $0c, $60, $fd '-' rx2_i_lut_value wrpin tx1_mode, tx1_pin 'configure tx1_pin for asynchronous transmit, always output byte $06, $10, $00, $fc '-' cmd wxpin tx1_bitperiod, tx1_pin 'tmp parameter for rx2 cmd byte $06, $0e, $10, $fc '-' tx2_param dirh tx1_pin 'tmp parameter for tx2 cmd 'enable transmitter byte $41, $0c, $60, $fd '-' end_tx1_reset '-' '----------------------------------------------------------------------- '-' ' '-' ' Reset rx2 clear buffer pointers enable pin and int2 '-' ' '-' '----------------------------------------------------------------------- '-' rx2_head mov rx2_head, #0 'tx_i_ct1 used in tx_isr 'reset serial buffer pointers byte $00, $82, $04, $f6 '-' rx2_tail mov rx2_tail, #0 'tx_i_ct1wait used in tx_isr byte $00, $84, $04, $f6 '-' lutaddress cmp rx2_pin, minusOne wz 'lutaddress used in command loop 'if rx2_pin == -1 byte $7c, $17, $08, $f2 '-' value if_z jmp #end_rx2_reset 'value used in command loop ' skip RX2 setting smart pin byte $28, $00, $90, $ad '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' txblock setint2 #0 'tmp parameter for tx2 cmd 'disable int2 byte $26, $00, $64, $fd '-' pxtail dirl rx2_pin 'pointer to current TXtail 'disable receiver byte $40, $16, $60, $fd '-' tx_i_address mov rx2_i_char, #%110<<6 'txdec used by HEX/DEC byte $80, $4f, $04, $f6 '-' tx_i_lutvalue add rx2_i_char, rx2_pin 'pointer for output of HX/DEC byte $0b, $4e, $00, $f1 '-' txcogptr wrpin rx2_mode, rx2_pin 'pointer for output of HX/DEC 'configure rx_pin for asynchronous receive, always input byte $0b, $1a, $00, $fc '-' txloopctr wxpin rx2_bitperiod, rx2_pin byte $0b, $18, $10, $fc '-' lutbuff setse2 rx2_i_char 'set se1 to trigger on rx1_pin (rx1_pin high) byte $21, $4e, $60, $fd '-' pxdonewritepar mov ijmp2, #rx2_isr 'set int2 jump vector to rx2 ISR byte $bc, $e4, $07, $f6 '-' pxdone setint2 #5 'pointer to current TX donewritepar 'set int2 to trigger on se2 byte $26, $0a, $64, $fd '-' lutbtop dirh rx2_pin 'enable receiver byte $41, $16, $60, $fd '-' end_rx2_reset '-' '----------------------------------------------------------------------- '-' ' '-' ' Reset tx2 set tx2_mode and tx2_bitperiod, enable pin '-' ' '-' '----------------------------------------------------------------------- '-' pxcmd mov tx2_head, #0 'reset serial buffer pointers byte $00, $52, $04, $f6 '-' pxparam mov tx2_tail, #0 byte $00, $54, $04, $f6 '-' head cmp tx2_pin, minusOne wz 'if tx2_pin == -1 byte $7c, $21, $08, $f2 '-' tail if_z jmp #end_tx2_reset ' skip setting TX2 smart pin byte $10, $00, $90, $ad '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' pxhead dirl tx2_pin 'disable transmitter byte $40, $20, $60, $fd '-' tx1_address wrpin tx2_mode, tx2_pin 'configure tx2_pin for asynchronous transmit, always output byte $10, $24, $00, $fc '-' rx1_param wxpin tx2_bitperiod, tx2_pin 'tmp parameter for rx1 cmd byte $10, $22, $10, $fc '-' cmdparam dirh tx2_pin 'enable transmitter byte $41, $20, $60, $fd '-' end_tx2_reset '-' '----------------------------------------------------------------------- '-' ' '-' ' Enable int3 for TX '-' ' '-' '----------------------------------------------------------------------- '-' tx2_address mov ijmp3, #tx_isr 'set int3 vector - later sysclocks to wait for in tx_isr byte $cd, $e0, $07, $f6 '-' rx2_param setint3 #1 'tmp parameter for rx2 cmd 'set int3 for ct-passed-ct1 event later decimal num to send byte $27, $02, $64, $fd '-' rxstring getct tx_i_ct1 'set initial tx_i_ct1 target byte $1a, $4c, $60, $fd '-' txmailboxpointer addct1 tx_i_ct1, tx_i_ct1wait byte $15, $4c, $60, $fa '-' '----------------------------------------------------------------------- '-' ' '-' ' this tells calling cog we got the parameters and are ready to roll '-' ' '-' '----------------------------------------------------------------------- '-' pxgetchar wrlong minusOne, rx1_mailbox_ptr 'write -1 into rx1_mailbox_ptr in the HUB, now cogstart finished byte $00, $f8, $62, $fc '-' '======================================================================= '-' ' '-' 'command loop - calls R1/TX1/RX2/TX2 routines to check the mailboxes and to do HUB/LUT LUT/HUB buffer transfer '-' ' - first check if pin used (<>-1) then check if last command still running (<>-1) '-' ' - if not get new one, else resume old one '-' ' - do this for each channel. '-' ' '-' '======================================================================= '-' rx1_cmd_check cmp rx1_pin, minusOne wz 'RX1 pin active? 'gone 8 byte $7c, $03, $08, $f2 '-' if_z jmp #tx1_cmd_check 'no - check TX1 next byte $48, $00, $90, $ad '-' cmp rx1_cmd, minusOne wz 'old cmd finished? byte $7c, $ff, $0a, $f2 '-' if_z rdlong rx1_cmd, rx1_mailbox_ptr 'yes - new cmd from rx1 mailbox byte $00, $fe, $02, $ab '-' if_z rdlong rx1_param, rx1_param_ptr 'yes - new param from rx1 mailbox byte $16, $aa, $00, $ab '-' cmp rx1_cmd, minusOne wz 'do we have a active command running? byte $7c, $ff, $0a, $f2 '-' if_z jmp #tx1_cmd_check 'no - check TX1 next byte $34, $00, $90, $ad '-' mov pxdonewritepar, #rx1_donewritepar 'set up pointers and values for RX1 byte $ff, $98, $04, $f6 '-' mov pxdone, #rx1_done 'to use a common rxdocmd byte $00, $9b, $04, $f6 '-' mov pxgetchar, #rx1_get_value byte $f5, $b6, $04, $f6 '-' mov pxparam, #rx1_param byte $55, $a0, $04, $f6 '-' mov pxcmd, #rx1_cmd byte $7f, $9f, $04, $f6 '-' mov pxtail, #rx1_tail byte $19, $8c, $04, $f6 '-' mov txmailboxpointer, tx1_mailbox_ptr byte $18, $b4, $00, $f6 '-' mov lutbuff, rx1_lut_buff byte $04, $96, $00, $f6 '-' mov lutbtop, rx1_lut_btop byte $05, $9c, $00, $f6 '-' mov head, rx1_head byte $17, $a2, $00, $f6 '-' mov tail, rx1_tail byte $19, $a4, $00, $f6 '-' mov cmd, rx1_cmd byte $7f, $7f, $00, $f6 '-' call #rxdocmd 'and call the common rxdocmd byte $54, $02, $b0, $fd '-' tx1_cmd_check cmp tx1_pin, minusOne wz 'TX1 pin active? byte $7c, $0d, $08, $f2 '-' if_z jmp #rx2_cmd_check 'no - check RX2 next byte $44, $00, $90, $ad '-' cmp tx1_cmd, minusOne wz 'old cmd finished? byte $7c, $01, $0b, $f2 '-' if_z rdlong tx1_cmd, tx1_mailbox_ptr 'yes - new cmd from tx1 mailbox byte $18, $00, $03, $ab '-' if_z rdlong tx1_param, tx1_param_ptr 'yes - new param from tx1 mailbox byte $1a, $72, $00, $ab '-' cmp tx1_cmd, minusOne wz 'do we have a active command running? byte $7c, $01, $0b, $f2 '-' if_z jmp #rx2_cmd_check 'no - check RX2 next byte $30, $00, $90, $ad '-' mov pxdonewritepar, #tx1_donewritepar 'set up pointers and values for TX1 byte $38, $99, $04, $f6 '-' mov pxdone, #tx1_done 'to use a common txdocmd byte $39, $9b, $04, $f6 '-' mov pxparam, #tx1_param byte $39, $a0, $04, $f6 '-' mov pxcmd, #tx1_cmd byte $80, $9f, $04, $f6 '-' mov pxhead, #tx1_head byte $1f, $a6, $04, $f6 '-' mov pxtail, #tx1_tail byte $21, $8c, $04, $f6 '-' mov lutbtop, tx1_lut_btop byte $0a, $9c, $00, $f6 '-' mov lutbuff, tx1_lut_buff byte $09, $96, $00, $f6 '-' mov head, tx1_head byte $1f, $a2, $00, $f6 '-' mov tail, tx1_tail byte $21, $a4, $00, $f6 '-' mov cmd, tx1_cmd byte $80, $7f, $00, $f6 '-' call #txdocmd 'and call the common txdocmd byte $ec, $02, $b0, $fd '-' rx2_cmd_check cmp rx2_pin, minusOne wz 'RX2 pin active? byte $7c, $17, $08, $f2 '-' if_z jmp #tx2_cmd_check 'no - check TX2 next byte $48, $00, $90, $ad '-' cmp rx2_cmd, minusOne wz 'old cmd finished? byte $7c, $03, $0b, $f2 '-' if_z rdlong rx2_cmd, rx2_mailbox_ptr 'yes - new cmd from rx2 mailbox byte $1c, $02, $03, $ab '-' if_z rdlong rx2_param, rx2_param_ptr 'yes - new param from rx2 mailbox byte $1e, $b0, $00, $ab '-' cmp rx2_cmd, minusOne wz 'do we have a active command running? byte $7c, $03, $0b, $f2 '-' if_z jmp #tx2_cmd_check 'no - check TX2 next byte $34, $00, $90, $ad '-' mov pxdonewritepar, #rx2_donewritepar 'set up pointers and values for RX2 byte $02, $99, $04, $f6 '-' mov pxdone, #rx2_done 'to use a common rxdocmd byte $03, $9b, $04, $f6 '-' mov pxgetchar, #rx2_get_value byte $f7, $b6, $04, $f6 '-' mov pxparam, #rx2_param byte $58, $a0, $04, $f6 '-' mov pxcmd, #rx2_cmd byte $81, $9f, $04, $f6 '-' mov pxtail, #rx2_tail byte $42, $8c, $04, $f6 '-' mov txmailboxpointer, tx2_mailbox_ptr byte $20, $b4, $00, $f6 '-' mov lutbuff, rx2_lut_buff byte $0e, $96, $00, $f6 '-' mov lutbtop, rx2_lut_btop byte $0f, $9c, $00, $f6 '-' mov head, rx2_head byte $41, $a2, $00, $f6 '-' mov tail, rx2_tail byte $42, $a4, $00, $f6 '-' mov cmd, rx2_cmd byte $81, $7f, $00, $f6 '-' call #rxdocmd 'and call the common rxdocmd byte $b8, $01, $b0, $fd '-' tx2_cmd_check cmp tx2_pin, minusOne wz 'TX2 pin active? byte $7c, $21, $08, $f2 '-' if_z jmp #rx1_cmd_check 'no - check RX1 next -- loop byte $0c, $ff, $9f, $ad '-' cmp tx2_cmd, minusOne wz 'old cmd finished? byte $7c, $05, $0b, $f2 '-' if_z rdlong tx2_cmd, tx2_mailbox_ptr 'yes - new cmd from tx2 mailbox byte $20, $04, $03, $ab '-' if_z rdlong tx2_param, tx2_param_ptr 'yes - new param from tx2 mailbox byte $22, $80, $00, $ab '-' cmp tx2_cmd, minusOne wz 'do we have a active command running? byte $7c, $05, $0b, $f2 '-' if_z jmp #rx1_cmd_check 'no - check RX1 next -- loop byte $f8, $fe, $9f, $ad '-' mov pxdonewritepar, #tx2_donewritepar 'set up pointers and values for TX2 byte $3b, $99, $04, $f6 '-' mov pxdone, #tx2_done 'to use a common xdocmd byte $3c, $9b, $04, $f6 '-' mov pxparam, #tx2_param byte $40, $a0, $04, $f6 '-' mov pxcmd, #tx2_cmd byte $82, $9f, $04, $f6 '-' mov pxhead, #tx2_head byte $29, $a6, $04, $f6 '-' mov pxtail, #tx2_tail byte $2a, $8c, $04, $f6 '-' mov lutbtop, tx2_lut_btop byte $14, $9c, $00, $f6 '-' mov lutbuff, tx2_lut_buff byte $13, $96, $00, $f6 '-' mov head, tx2_head byte $29, $a2, $00, $f6 '-' mov tail, tx2_tail byte $2a, $a4, $00, $f6 '-' mov cmd, tx2_cmd byte $82, $7f, $00, $f6 '-' call #txdocmd 'and call the common txdocmd byte $50, $02, $b0, $fd '-' jmp #rx1_cmd_check ' -- loop byte $c4, $fe, $9f, $fd '-' '======================================================================= '-' ' '-' ' INT 1 - rx1 read interrupt writes byte in lut buffer, runs if pin receives a char '-' ' '-' '======================================================================= '-' rx1_isr mov rx1_i_char, rx1_head 'do I have space in my buffer? byte $17, $36, $00, $f6 '-' incmod rx1_i_char, rx1_lut_btop 'rx1_i_char = head+1 byte $05, $36, $00, $f7 '-' cmp rx1_i_char, rx1_tail wz 'hitting tail is bad byte $19, $36, $08, $f2 '-' rdpin rx1_i_char, rx1_pin 'get received char byte $01, $36, $88, $fa '-' if_z reti1 'and return if buffer full - we lost a char - exit byte $f5, $ff, $3b, $ab '-' shr rx1_i_char, #32-8 'shift char to lsb justify byte $18, $36, $44, $f0 '-' mov rx1_i_byte_index, rx1_head 'take last two bits of head byte $17, $70, $00, $f6 '-' and rx1_i_byte_index, #%11 'now index 0 to 3 byte $03, $70, $04, $f5 '-' mov rx1_i_address, rx1_head 'adjust address to buffer start (I need the long containing the byte) byte $17, $3a, $00, $f6 '-' shr rx1_i_address, #2 'adjust address to buffer start byte $02, $3a, $44, $f0 '-' add rx1_i_address, rx1_lut_buff 'by adding rx1_lut_buff byte $04, $3a, $00, $f1 '-' rdlut rx1_i_lut_value, rx1_i_address 'get correct LUT long byte $1d, $5a, $a0, $fa '-' altsb rx1_i_byte_index, #rx1_i_lut_value 'patch the index byte $2d, $70, $64, $f9 '-' setbyte 0, rx1_i_char, #0-0 'change the needed byte byte $1b, $00, $c0, $f8 '-' wrlut rx1_i_lut_value, rx1_i_address 'write long back to circular buffer in lut byte $1d, $5a, $30, $fc '-' incmod rx1_head, rx1_lut_btop 'increment buffer head byte $05, $2e, $00, $f7 '-' reti1 'exit byte $f5, $ff, $3b, $fb '-' '======================================================================= '-' ' '-' ' INT 2 - rx2 read interrupt writes byte in lut buffer, runs if pin receives a char '-' ' '-' '======================================================================= '-' rx2_isr mov rx2_i_char, rx2_head 'do I have space in my buffer? byte $41, $4e, $00, $f6 '-' incmod rx2_i_char, rx2_lut_btop 'rx2_i_char = head+1 mod byte $0f, $4e, $00, $f7 '-' cmp rx2_i_char, rx2_tail wz 'hitting tail is bad byte $42, $4e, $08, $f2 '-' rdpin rx2_i_char, rx2_pin 'get received chr byte $0b, $4e, $88, $fa '-' if_z reti2 'and return if buffer full - we lost a char - exit byte $f3, $ff, $3b, $ab '-' shr rx2_i_char, #32-8 'shift char to lsb justify byte $18, $4e, $44, $f0 '-' mov rx2_i_byte_index, rx2_head 'take last two bits of head byte $41, $76, $00, $f6 '-' and rx2_i_byte_index, #%11 'now index 0 to 3 byte $03, $76, $04, $f5 '-' mov rx2_i_address, rx2_head 'adjust to buffer start (I need the long containing the byte) byte $41, $50, $00, $f6 '-' shr rx2_i_address, #2 'adjust address to buffer start byte $02, $50, $44, $f0 '-' add rx2_i_address, rx2_lut_buff 'by adding rx2_lut_buff byte $0e, $50, $00, $f1 '-' rdlut rx2_i_lut_value, rx2_i_address 'get correct LUT long byte $28, $7c, $a0, $fa '-' altsb rx2_i_byte_index, #rx2_i_lut_value 'patch the index byte $3e, $76, $64, $f9 '-' setbyte 0, rx2_i_char, #0-0 'change the needed byte byte $27, $00, $c0, $f8 '-' wrlut rx2_i_lut_value, rx2_i_address 'write long back to circular buffer in lut byte $28, $7c, $30, $fc '-' incmod rx2_head, rx2_lut_btop 'increment buffer head byte $0f, $82, $00, $f7 '-' reti2 'exit byte $f3, $ff, $3b, $fb '-' '======================================================================= '-' ' '-' ' INT 3 - tx write interrupt, reads bytes from lut buffer , runs once every tx_i_ct1wait clocks '-' ' '-' '======================================================================= '-' tx_isr cmp tx1_pin, minusOne wz 'tx1 active? byte $7c, $0d, $08, $f2 '-' if_z jmp #.tx2_send 'no - check tx2 byte $24, $00, $90, $ad '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' cmp tx1_head, tx1_tail wz 'tx1 byte to send? byte $21, $3e, $08, $f2 '-' if_z jmp #.tx2_send 'no - wait for next time byte $1c, $00, $90, $ad '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' rdpin tx_i_test, tx1_pin wc 'wait for pin ready? byte $06, $46, $98, $fa '-' if_c jmp #.tx2_send 'no - wait for next time byte $14, $00, $90, $cd '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' mov tx_i_tail, tx1_tail 'adjust to buffer start byte $21, $5c, $00, $f6 '-' mov tx_i_lutbuf, tx1_lut_buff 'by adding tx1_lut_buff byte $09, $78, $00, $f6 '-' call #.txgetlutchar 'get the needed byte byte $3c, $00, $b0, $fd '-' incmod tx1_tail, tx1_lut_btop 'increment buffer tail byte $0a, $42, $00, $f7 '-' wypin tx_i_char, tx1_pin 'send the byte byte $06, $48, $20, $fc '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' .tx2_send cmp tx2_pin, minusOne wz 'tx2 active? byte $7c, $21, $08, $f2 '-' if_z jmp #.end_isr 'no - done byte $24, $00, $90, $ad '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' cmp tx2_head, tx2_tail wz 'tx2 byte to send? byte $2a, $52, $08, $f2 '-' if_z jmp #.end_isr 'no - wait for next time byte $1c, $00, $90, $ad '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' rdpin tx_i_test, tx2_pin wc 'wait for pin ready? byte $10, $46, $98, $fa '-' if_c jmp #.end_isr 'no - wait for next time byte $14, $00, $90, $cd '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' mov tx_i_tail, tx2_tail 'adjust to buffer start byte $2a, $5c, $00, $f6 '-' mov tx_i_lutbuf, tx2_lut_buff 'by adding tx2_lut_buff byte $13, $78, $00, $f6 '-' call #.txgetlutchar 'get the needed byte byte $10, $00, $b0, $fd '-' incmod tx2_tail, tx2_lut_btop 'increment buffer tail byte $14, $54, $00, $f7 '-' wypin tx_i_char, tx2_pin 'send the byte byte $10, $48, $20, $fc '-' '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '-' .end_isr addct1 tx_i_ct1, tx_i_ct1wait 'update txct1 target byte $15, $4c, $60, $fa '-' reti3 'return to main program byte $f1, $ff, $3b, $fb '-' '----------------------------------------------------------------------- '-' .txgetlutchar mov tx_i_byteindex, tx_i_tail 'take last two bits of tail byte $2e, $4a, $00, $f6 '-' and tx_i_byteindex, #%11 'now index 0 to 3 byte $03, $4a, $04, $f5 '-' mov tx_i_address, tx_i_tail 'adjust to buffer start (I need the long containing the byte) byte $2e, $8e, $00, $f6 '-' shr tx_i_address, #2 'adjust address to buffer start byte $02, $8e, $44, $f0 '-' add tx_i_address, tx_i_lutbuf 'by adding txX_lut_buff byte $3c, $8e, $00, $f1 '-' rdlut tx_i_lutvalue, tx_i_address 'get correct LUT long byte $47, $90, $a0, $fa '-' altgb tx_i_byteindex, #tx_i_lutvalue 'patch the index byte $48, $4a, $6c, $f9 '-' _ret_ getbyte tx_i_char, tx_i_lutvalue, #0 'get the needed byte byte $48, $48, $e0, $08 '-' '======================================================================= '-' ' '-' ' used for both RX and both TX ports '-' ' '-' '======================================================================= '-' getbufused mov value, head 'returns count of bytes used in given buffe in value byte $51, $88, $00, $f6 '-' cmps head, tail wcz 'if head