Is there a ioctl call or anything else to flush (= clear) the receive queue of uart, which is opened in interrupt mode? I read mqxrm.pdf and mqxioug.pdf and tested IO_IOCTL_SERIAL_CLEAR_STATS without effect.
I need it for clearing any 'waste' in the queue.
Something like this for output:
pointer x;
x = fopen("ittya:");
fflush(x);
And this for in input (I Just wrote this, but the concept is correct and will work)
void fflush_input(void){ while(fstatus(fBTComm)) { if (fgetc(fBTComm) == IO_ERROR) { //ERROR return; } else { continue; //Keep getting data } } return; //No more data}
TY for the hint. My previous code used read() instead of fgetc(), because I have binary data incl. 0x00 (= EOF).
Now, I've tested with:
_int_disable();
for ( i = 0; i < 8; i++ ) {
buf[i] = fgetc ( ttya_handle );
}
while ( fstatus ( ttya_handle ) ) {
fgetc ( ttya_handle );
}
_int_enable();
However, if I activate 'Periodic Window Update' in µVision 4, the while-loop seems to clear the first byte of the next data telegram (every 5 ms, 8 bytes each). I don't know why, but perhaps the debug probe triggers a NVIC and _int_disable() is for the birds...
I've added new parameter to ioctl. From application now I can call:
ioctl ( ttya_handle, IO_IOCTL_DRAIN_INPUT, &attr );
In serl_int.c function _io_serial_int_ioctl I've added:
case IO_IOCTL_DRAIN_INPUT:
{
KUART_INFO_STRUCT_PTR sci_info_ptr;
sci_info_ptr = int_io_dev_ptr->DEV_INFO_PTR;
sci_info_ptr->SCI_PTR->CFIFO |= UART_CFIFO_RXFLUSH_MASK; // flush HW FIFO
_CHARQ_RESET(int_io_dev_ptr->IN_QUEUE); // flush SW queue
}
break;
The parameter is defined in io.h:
#define IO_IOCTL_DRAIN_INPUT _IO(IO_TYPE_MQX,0x0D)
This works for me :smileyhappy:
@Freescale: PLS could you add this code or similar in next MQX release? TIA