4 cog 4 serial
luigi_dip
Posts: 9
Hi,
i'm using 4 cog for receive simultaneusly from 4 serial trasmitter after the same trigger.
After that, i've to send all the data (4 bytes for serial) to another serial.
My problem is to syncronize all the data: i wish that the trasmission begin when all the 4 rx serial have finished.
I attach the code i'm using for receive the data and send it. This is an extrapolation of the FullDuplexSerial Object.
I don't know how to set a flag in the 4 cog that could be read from the hub and start the transmission.
Any suggestions???
Gigi
i'm using 4 cog for receive simultaneusly from 4 serial trasmitter after the same trigger.
After that, i've to send all the data (4 bytes for serial) to another serial.
My problem is to syncronize all the data: i wish that the trasmission begin when all the 4 rx serial have finished.
I attach the code i'm using for receive the data and send it. This is an extrapolation of the FullDuplexSerial Object.
I don't know how to set a flag in the 4 cog that could be read from the hub and start the transmission.
Any suggestions???
Gigi
spin
24K
Comments
For example i wish to set a counter at the end of the reading procedure that start from 4 to 0. When this counter goes to zero i set this flag; after that i've read all the 4 flag setted, I clear it in the spin part of the code. How can i do it? i'm not able to pass easily a variable from asm to spin. I've read many example and try it but these doesn't work.
For example at the end of the receiver routine i use this counter cnt1. Every time I pass from there I subtract 1. When this counter became 0 i set the flag. Can you explain me how to do it?
I declare a variable in the spin part
long ptr_flag1
...........
ptr_flag1:=@flag1
.............
rdlong t2,par 'save received byte and inc head
add t2,rxbuff
wrbyte rxdata,t2
sub t2,rxbuff
add t2,#1
and t2,#$03
wrlong t2,par
rdlong temp,flag1
sub cnt1,#1
cmp cnt1, #0 wz
if_nz mov cnt1,#4
if_nz mov temp, #1
wrlong temp,flag1
jmp #receive 'byte done, receive next byte
temp long 0
flag1 long 0
This doesn't work.
The issue here is that you're proposing a solution before you've laid out the problem to be solved. For example, your packet size is 22 bytes and represents 4 successive bytes from each of 4 serial ports. How often are the triggers expected? I ask because you're transmitting more than you're receiving and you'll run out of transmit buffer space if the triggers come in too quickly. What happens if the data gets out of sync? What if there's noise on one of the data lines and a byte is dropped?
My bias is to leave the assembly language stuff alone, maybe write another assembly routine (for a separate cog) that essentially implements the loop I wrote above, but, rather than calling rxcheck, implements the equivalent by checking the buffer pointers directly to see whether there are characters in the buffer. This cog could even implement your main loop completely if your timing constraints are tight enough.
So i've to take this 4 byte (380us in parallel at 115200) from every sensor by serial. Simultaneously I've to take a packet of 20 bytes from another sensor by SPI (about 400us). I've maximum 500us since the trigger to take all these informations. After that i've to create a packet to send.
In reality i've to send this packet by a parallel bus 8 bit/1Mhz on request before that arrive another trigger. So i've only to set high a pin to give the information of a data_ready to another microcontroller and wait for the clock on another pin to send the data.
Obviously i've to syncronize all the pkt that arrive after the trigger for sure. I can discard all the pkt received before the trigger.
Note that I receive from serial a pkt without markers so i recognise that a byte it's arrived only from the bit start.
Do you need other information?
It's just what i'm looking for but unfortunately it doesn't work!!!
This is the spin i've prove. I've only change the pins. I send the trigger and the serial pkt in the right way (i've seen it with an oscilloscope)
what's wrong?? The code appears good!
The flags are never been set. I've try with this code to take a look at the flags but all the serial vector has value 0x80...every byte
I made some corrections to your program as well