Howto clear rx buffer of :ittya ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Howto clear rx buffer of :ittya ?

1,201 Views
Fabi
Contributor III

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.

0 Kudos
Reply
3 Replies

654 Views
CarlFST60L
Senior Contributor II

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}

 

 

0 Kudos
Reply

654 Views
Fabi
Contributor III

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...

0 Kudos
Reply

654 Views
Fabi
Contributor III

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

0 Kudos
Reply