Starting 2 PASM cogs from 1 object file ???
Anubispod
Posts: 42
Hi , i try to start 2 programs in its own cog and share the same arry one cogs only writes to it one only reads from it , in separate file they run ok,
but here some how th ppm code wonst run , the dsmx code still runs ok ??
but here some how th ppm code wonst run , the dsmx code still runs ok ??
con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 SVO_MIN = 800 ' servo limits in microseconds SVO_MAX = 2200 SVO_CTR = 1500 var long testoutdsmx long testoutppm long cog1 long cog2 long uscnt ' cnt ticks per microseconds long ppmpin ' ppm output pin long state ' lead/lag pulse state long channels ' servo channels, 1 - 8 long pulsecnt ' cnt ticks for lead/lag puls long framecnt ' cnt ticks for servo frame long dsmx_ptr long rx_head long rx_tail long rx_pin long rxtx_mode long bit_ticks long buffer_ptr long dsmxch_ptr long swap long header byte rx_buffer[16] 'receive buffer long dsmxch[12] long error PUB testme dsmxch_ptr := @dsmxch startppm(21, 0, 9, 300, 20000) waitcnt(clkfreq/100+cnt) startdsmx(12,0, 115200) waitcnt(clkfreq/100+cnt) repeat testoutdsmx := dsmxch[0] PUB startdsmx(rxpin,mode, baudrate) : okay longfill(@dsmxch,1500,12) stopdsmx longfill(@rx_head, 0, 4) longmove(@rx_pin, @rxpin, 3) bit_ticks := clkfreq / baudrate buffer_ptr := @rx_buffer header:= @error okay := cog2 := cognew(@entry_dsmx, @rx_head) + 1 PUB stopdsmx '' Stop DSMX driver - frees a cog if cog2 cogstop(cog2~ - 1) pub startppm(pin, level, nservos, uspulse, usframe) | ok '' Starts PPM cog '' -- pin = output pin '' -- level = active state of lead/lag pulse '' -- nservos = number of servos (1 to 8) '' -- uspulse = microseconds for lead/lag pulse (typically 300, 0.3ms) '' -- usframe = microseconds for servo frame (typically 20_000, 20ms) stopppm ' stop if already running uscnt := clkfreq / 1_000_000 ' ticks per microsecond dsmx_ptr := @dsmxch ppmpin := pin ' setup cog parameters state := level channels := 1 #> nservos <# 9 pulsecnt := uspulse * uscnt framecnt := usframe * uscnt ok := cog1 := cognew(@entry_ppm, @ppmpin) + 1 ' start the cog return ok pub stopppm '' Stops cog (if running) if cog1 cogstop(cog1~ - 1) dat org 0 entry_ppm mov tmp1, par ' start of parameters rdlong tmp2, tmp1 ' read ppm pin# mov ppmmask, #1 ' create mask shl ppmmask, tmp2 add tmp1, #4 rdlong tmp2, tmp1 wz ' read active state of pulse if_z or outa, ppmmask ' if low, make idle high if_nz andn outa, ppmmask ' else make idle low or dira, ppmmask ' make pin an output add tmp1, #4 rdlong chans, tmp1 ' get # channels add tmp1, #4 rdlong pulsetix, tmp1 ' get ticks per lead/lag pulse add tmp1, #4 rdlong frametix, tmp1 ' get ticks per servo frame add tmp1, #4 mov svopntr, tmp1 ' save hub address of servo[0] mov ftimer, frametix ' setup frame timer add ftimer, cnt ' start it ppmframe waitcnt ftimer, frametix ' idle for sync point mov count, chans ' set # channels mov hub, svopntr ' point to servo[0] :loop2 xor outa, ppmmask ' start pulse mov stimer, cnt ' setup pulse timer add stimer, pulsetix rdlong servotix, hub ' get channel timing from hub add hub, #4 ' point to next channel sub servotix, pulsetix ' correct timing for lead/lag pulse waitcnt stimer, servotix ' let pulse finish xor outa, ppmmask ' back to idle waitcnt stimer, pulsetix ' let servo timing finish djnz count, #:loop2 ' update channels xor outa, ppmmask ' lag pulse waitcnt stimer, #0 xor outa, ppmmask jmp #ppmframe ' -------------------------------------------------------------------------------------------------- ppmmask res 1 ' mask for ppm pin chans res 1 ' # of channels pulsetix res 1 ' cnt ticks for lead/lag pulse frametix res 1 ' cnt ticks in servo frame dsmxptr res 1 svopntr res 1 ' pointer to servo[0] ftimer res 1 ' frame (all servos) timer stimer res 1 ' servo timer count res 1 ' for servos loop hub res 1 ' address of activer servo timing dhub res 1 servotix res 1 ' cnt ticks for current servo tmp1 res 1 ' work vars tmp2 res 1 fit DAT org 0 entry_dsmx mov t1,par 'get structure address add t1,#4 << 1 'skip past heads and tails rdlong t2,t1 'get rx_pin mov rxmask,#1 shl rxmask,t2 add t1,#4 'get rxtx_mode rdlong rxtxmode,t1 add t1,#4 'get bit_ticks rdlong bitticks,t1 add t1,#4 'get buffer_ptr ... rdlong rxbuff,t1 'for the receiver add t1,#4 'get sync_ptr ... rdlong ptr_ch,t1 'for the receiver add t1,#4 'get sync_ptr ... rdlong ptr_swap,t1 'for the receiver add t1,#4 'get sync_ptr ... rdlong ptr_header,t1 'for the receiver test rxtxmode,#%100 wz 'if_nz = open drain Tx test rxtxmode,#%010 wc 'if_c = inverted output mov count_byte,#0 or dira,power_mask or outa,power_mask mov t7,#12 ' Receive timer neg t3, cnt mov t1,#0 receive mov t4,ptr_ch add t1,#1 cmps t1,fail_save_time wc add t4,#16 if_nc wrword set_fail_save,t4 test rxtxmode,#%001 wz 'wait for start bit on rx pin test rxmask,ina wc if_z_eq_c jmp #receive mov rxbits,#9 'ready to receive byte mov rxcnt,bitticks shr rxcnt,#1 'half a bit tick add rxcnt,cnt '+ the current clock :bit add rxcnt,bitticks 'ready for the middle of the bit period :wait mov t1,rxcnt 'check if bit receive period done sub t1,cnt cmps t1,#0 wc if_nc jmp #:wait test rxmask,ina wc 'receive bit on rx pin into carry rcr rxdata,#1 'shift carry into receiver djnz rxbits,#:bit 'go get another bit till done test rxtxmode,#%001 wz 'find out if rx is inverted if_z_ne_c jmp #timer 'abort if no stop bit shr rxdata,#32-9 'justify and trim received byte and rxdata,#$FF if_nz xor rxdata,#$FF 'if rx inverted, invert byte add t3, cnt sub t3, #4 CMP time_mask,t3 wc if_c mov count_byte,#0 if_nc add count_byte,#1 mov t2,rxbuff 'get add t2,count_byte wrbyte rxdata,t2 'write the byte to position count_byte CMP count_byte,#15 wz 'see if we have now time to decode buffer next 9 ms if_nz jmp #timer decodedsmx mov t2,rxbuff ' Set pointer behinde byte 1 to 2 add t2,#1 mov t5,ptr_swap mov rxbits,#7 rdbyte decode,t2 sub t2,#1 wrbyte decode,t5 add t5,#1 rdbyte decode,t2 wrbyte decode,t5 add t2,#3 sub t5,#1 rdword decode,t5 mov t4,ptr_header wrlong decode,t4 :loop mov t4,ptr_ch rdbyte decode,t2 sub t2,#1 wrbyte decode,t5 add t5,#1 rdbyte decode,t2 wrbyte decode,t5 add t2,#3 sub t5,#1 rdword decode,t5 shl decode,#17 shr decode,#17 mov ch,decode mov value,decode shr ch,#11 shl value,#21 shr value,#22 mov t6,ch shl t6,#2 add t4,t6 CMP t7,#12 wc add value,base if_nc wrword value,t4 djnz rxbits,#:loop 'loop 7 mal jmp #timer ' power_mask long %100000000000000000000000000 time_mask long 600000 decode long 0 ch long 0 value long 0 fail_save_time long 6_00_000 set_fail_save long 1010 base long 988 t1 res 1 t2 res 1 t3 res 1 t4 res 1 t5 res 1 t6 res 1 t7 res 1 count_byte res 1 rxtxmode res 1 bitticks res 1 rxmask res 1 rxbuff res 1 rxdata res 1 rxbits res 1 rxcnt res 1 rxcode res 1 dsmch res 1 ptr_ch res 1 ptr_swap res 1 ptr_header res 1 fit
Comments