Multithreaded program for UART communication
Hi,
I am new comer to linux programing.I need to run a multithreaded application which will read and write data to 7 UART ports.
for each UART port there will be 2 deidcated threads (i.e. read and write threads).I have a c++ code which creates thread to read and write data to any particualr UART port.But i want to run all the 7 ports parallel.Plese help me to know how i need to modify the below code so that it can create 7 write and read threads for 7 UART ports and could simultaneoulsy read/write from/to all the ports.
Thank u so much in advance.
void *Uartsend(void * threadParameter);
void *Uartread(void * threadParameter);
int m_fd = -1;
struct termios m_tio;
int trun = 1;
int rrun = 1;
pthread_t p_Uartsend, p_Uartread;
int main(int argc, char *argv[])
{
int i, ret;
pthread_t p_Uartsend, p_Uartread;
void *thread_res;
//set baud rate,data bits.stop bit,parity nd flow control
setup serial port();
strncpy(port.uart_dev_name, argv[1], MAX_UART_NAME_LEN);
//Open the serial port
m_fd = SerialPort_Init(port, &m_tio);
// create write thread
ret = pthread_create(&p_Uartsend, NULL, Uartsend, NULL);
if (ret < 0)
{
exit(EXIT_FAILURE);
}
// create read thread
ret = pthread_create(&p_Uartread, NULL, Uartread, NULL);
if (ret < 0)
{
exit(EXIT_FAILURE);
}
ret = pthread_join(p_Uartsend, &thread_res);
ret = pthread_join(p_Uartread, &thread_res);
close(m_fd);
printf("\nExiting Test\n");
return 0;
}
void *Uartsend(void * threadParameter)
{
double speed;
double time;
int strLen = sizeof(test_str);
int writtenBytes = 0;
do
{
writtenBytes = Serial_WriteData(m_fd, test_str, strLen);
} while(1); // Run just once
return 0;
}
|