anyway to access usb_serial input/output buffer?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
yushanh
Posts: 31
Joined: Mon Jul 29, 2013 6:23 pm

anyway to access usb_serial input/output buffer?

Post by yushanh »

Hi, is there any way to know whether there is data in the serial_usb input buffer from the host? Usually I used chSequentialStreamRead(ip, bp, n) in the while loop the get data. However, I'd like to read the data only when there really is something. How could I access the current serial_usb buffer size? Also, is the default maximal buffer size 256 bytes (SERIAL_USB_BUFFERS_SIZE)?

Thanks,

Shan
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: anyway to access usb_serial input/output buffer?

Post by Giovanni »

Hi,

You may use TIME_IMMEDIATE as timeout, the function will exit immediately if there is no data to read.

Giovanni
yushanh
Posts: 31
Joined: Mon Jul 29, 2013 6:23 pm

Re: anyway to access usb_serial input/output buffer?

Post by yushanh »

Hi Giovanni,

When I looked into the read method, it already set the timeout as TIME_INFINITE.

Code: Select all

#define chSequentialStreamRead(ip, bp, n) ((ip)->vmt->read(ip, bp, n))

Code: Select all

static size_t read(void *ip, uint8_t *bp, size_t n) {

  return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp,
                         n, TIME_INFINITE);
}


I wonder if it's ok to use chIQIsEmptyI()? In my application, I have some other conditions before reading data via serial_usb. Not sure if it is feasible.

Thanks,
S
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: anyway to access usb_serial input/output buffer?

Post by Giovanni »

It is feasible but you would be assuming there are queues there, it is like a private field.

Unlikely to change anyway.

Giovanni
Post Reply