Re: SerialDriver strange loopback
Posted: Wed Apr 01, 2015 5:02 pm
I modified the code to read the data I got from the loopback
In my reader thread I have
but after every write, I have one read of 0 data so the thread is very time consuming. Is it possible to have it waiting for the real data to be read? I mean, in the writer thread I'm sure to read every char from the loopback, so why I've got a CHN_INPUT_AVAILABLE flags active?
Thanks
Code: Select all
chMtxLock(&mtxRs485);
palSetPad(GPIOC, GPIOC_RS485_DE);//enable write
chprintf((BaseSequentialStream*)&SD2,"%s","ABCDEF\n\r"); // write
eventflags_t flags;
do{
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
flags = chEvtGetAndClearFlags(&Writer);
if (flags & [b]CHN_TRANSMISSION_END[/b]) {
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"transmission end\r\n");
chMtxUnlock(&mtx);
break;
}
}while(1);
//read data from loopback
msg_t charbuf;
do
{
charbuf = chnGetTimeout(&SD2, TIME_IMMEDIATE);
if ( charbuf != Q_TIMEOUT )
{
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"%c ",(char)charbuf);
chMtxUnlock(&mtx);
}
}while (charbuf != Q_TIMEOUT);
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"\r\n");
chMtxUnlock(&mtx);
palClearPad(GPIOC, GPIOC_RS485_DE); /* switch to read mode */
chMtxUnlock(&mtxRs485);In my reader thread I have
Code: Select all
while(1){
chMtxLock(&mtxRs485);
palClearPad(GPIOC, GPIOC_RS485_DE); /* switch to reader mode*/
eventflags_t flags;
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
flags = chEvtGetAndClearFlags(&Listener);
if (flags & CHN_INPUT_AVAILABLE) {
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"Got data to be read\r\n");
chMtxUnlock(&mtx);
msg_t charbuf;
do
{
charbuf = chnGetTimeout(&SD2, TIME_IMMEDIATE);
if ( charbuf != Q_TIMEOUT )
{
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"%c ",(char)charbuf);
chMtxUnlock(&mtx);
}
}
while (charbuf != Q_TIMEOUT);
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"\r\n");
chMtxUnlock(&mtx);
chMtxUnlock(&mtxRs485);but after every write, I have one read of 0 data so the thread is very time consuming. Is it possible to have it waiting for the real data to be read? I mean, in the writer thread I'm sure to read every char from the loopback, so why I've got a CHN_INPUT_AVAILABLE flags active?
Thanks