[En-Nut-Discussion] Calling the same function from different threads.
Javier Longares
supertxaby at gmail.com
Wed Dec 2 10:57:44 CET 2009
Dear collegues,
In my application I need to have both TCP and UART ports open and waiting
for data. There are specific data bytes indicating where the data packet
ends, and so we can start processing the specific data (i.e. CRC
calculations, send the ACK and send by UART the data received via TCP).
So, I've created both threads for UART and TCP sockets and specific data
structures as follows:
typedef struct {
unsigned char Data[BUFFER_LENGTH];
FILE *stream;
unsigned int Flags:16;
unsigned char Retries;
unsigned int Index:16;
unsigned int CRC_RX:16;
unsigned int CRC_Computed:16;
}COM_CHANNEL;
static COM_CHANNEL TCPSocket;
static COM_CHANNEL UART;
int main(void)
{
NutThreadCreate("Uart", Thread2, 0, 512);
NutThreadCreate("Socket", Thread1, 0, 512);
while(1) NutSleep(125);
}
However, because they are allways listening, both threads calls the getc
functions and I think it can be a problem. On the one hand, I can test the
UART tasks and it works fine, but when I open the TCP port the systems
doesn't work further, neither UART and TCP. TCP thread is based in the
tcps.c sample.
I think the problem could start because at the starting point the UART
threads is waiting for data with a getc command, and when connected, the TCP
process goes to a similar state. If this is the problem how can I switch
the context between both threads?? I've seen the threads.c example but it is
too simple and there is no need for context switching there.
Thank you in advance.
More information about the En-Nut-Discussion
mailing list