waitcnt asm
TomS
Posts: 128
I'm having a problem with waitcnt in assembly that I can't figure out. The loop repeats in about 20 seconds no matter what I assign to LoopTime. The "transmit" code seems to work fine and was taken from FullDuplexSerial and extensively modified.
Here's my code:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom
Here's my code:
{{Serial_tx_asm.spin Tom Smuts }} VAR long cog long tx_pin '6 contiguous longs (Don't change order or add/delete var's) long desc_ptr long ip_ptr long dbm_ptr long pcent_ptr long bit_ticks PUB Start(txpin, descPntr, ipPntr, dBmPntr, pcentPntr, baudrate) : okay stop longmove(@tx_pin, @txpin, 5) 'Fill var's from passed parms bit_ticks := clkfreq / baudrate 'bit_ticks = num clks per bit okay := cog := cognew(@entry, @tx_pin) + 1 PUB Stop if cog cogstop(cog~ - 1) DAT entry org 0 mov t1, par 'get structure address rdlong t2, t1 'get tx_pin mov txmask, #1 shl txmask, t2 'txmask defines transmit pin add t1, #4 'get desc_ptr rdlong descptr, t1 add t1, #4 'get ip_ptr rdlong ipptr, t1 add t1, #4 'get dbm_ptr rdlong dbmptr, t1 add t1, #4 'get pcent_ptr rdlong pcentptr, t1 add t1, #4 'get bit_ticks rdlong bitticks, t1 mov rxtxmode, #0 'mode = 0 test rxtxmode, #%100 wz 'init tx pin according to mode test rxtxmode, #%010 wc or outa, txmask or dira, txmask '---------------------------------------------------------------------------------------------- loop_start '---------------------------------------------------------------------------------------------- 'Line 1 mov bytecntr, descptr call #transmit mov bytecntr, ipptr call #transmit 'wait mov time, cnt add time, LoopTime waitcnt time, LoopTime jmp #loop_start '---------------------------------------------------------------------------------------------- '---------------------------------------------------------------------------------------------- transmit rdbyte txdata, bytecntr 'get 1st byte cmp txdata, #0 wz 'check for end of string if_z jmp transmit_ret 'exit when end of string reached 'ready byte to transmit or txdata, #$100 shl txdata, #2 ' 2 stop bits or txdata, #1 mov txbits, #11 ' 11 total bits mov txcnt, cnt '---------------------------------------------------------------------------------------------- :bit shr txdata, #1 wc 'output bit on tx pin muxc outa, txmask add txcnt, bitticks 'ready next cnt '---------------------------------------------------------------------------------------------- :wait mov t1, txcnt 'check if bit transmit period done sub t1, cnt cmps t1, #0 wc if_nc jmp #:wait '---------------------------------------------------------------------------------------------- djnz txbits, #:bit 'another bit to transmit? '---------------------------------------------------------------------------------------------- add bytecntr, #1 'next byte in string jmp #transmit '---------------------------------------------------------------------------------------------- transmit_ret ret { ######################################## Undefined data #################################### } ' temp variables t1 res 1 t2 res 1 t3 res 1 descptr res 1 ipptr res 1 dbmptr res 1 pcentptr res 1 bitticks res 1 bytecntr res 1 rxtxmode res 1 txmask res 1 txbuff res 1 txdata res 1 txbits res 1 txcnt res 1 time res 1 { ######################################### Defined data ##################################### } LoopTime Long 2_000 line1a Byte "test string 1", 0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom
Comments
Cheers!
Paul Rowntree
That portion of the code is direct from FullDuplexSerial so I don't think that's the problem. Thanks all the same.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom
-Phil
That did it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom
I believe you are incorrect on CNT always being unsigned.· In my experiments here, CNT is signed running from -max to +max.
Chris
-Phil