Hey again guys,
I am having a problem with reading and writing to the serial port.
I am still using the ScmRTOS and am now using 7 processes. One process handles all the output data to the serial port and any other process that wants to output data puts it into an output channel which the output process uses to output the data character by character. I have input data being put into a channel with a simple serial interrupt handler. When serial data is being input constantly or output constantly the program runs just fine but the program freezes when I start doing both together. As per previous discussions on the serial port, I have the serial port protected with a mutex so only input or output can be done at any one time. Additionally, I am not using printf to to output or scanf to input, I am dealing with the data character by character.
Does anyone have any other suggestions as to why this is happening?
The serial interrupt handler code:
void USB_serial() //signal RTOS event that RXinterrupt has been asserted
{
//char count = 0;
//led3 = !led3;
char temp = 0;
OS::TISRW ISRW;
if(!Serial_Mutex.IsLocked())
{
Serial_Mutex.Lock();
while(USB.readable())
{
temp = USB.getc();
if(RX_channel.get_free_size() >0 ) //only push a character onto the channel if there is free space
{
//OUT = &USB;
if(temp != '\n')
{
RX_channel.push(temp);
}
else if(temp == '\n')
{
RX_channel.push('\0');
}
}
else USB.getc(); //start discarding characters!
}
Serial_Mutex.Unlock();
}
else USB.getc(); //start discarding characters!
}
The serial output process:
template<> OS_PROCESS void Serial_Out::Exec() //Output stream handling process
{
char temp1 = 0;
led3 = 0;
for(;;)
{
TX_channel.pop(temp1);
led3 = !led3;
Serial_Mutex.Lock();
USB.putc(temp1);
Serial_Mutex.Unlock();
}
}
#endif
I realise that the freezing may be occurring elsewhere but I have tried to isolate it to this problem, for example, I tried not outputting any characters in the output process and left to work away for over an hour and with no freezes.
Any suggestions/thoughts welcome!
Regards,
Greg
Oh right ok thats grand so. I have everything I need to get my program up and running. Thanks a million for all the help.