Hi,
I suggest you to implement this as follows :
- add support for the interrupt driven serial driver to your MQX BSP by setting
BSPCFG_ENABLE_ITTYA (or ITTYB ... depending on the serial port to use) to 1 in config/board_name/user_config.h
then rebuild your BSP. The driver will be installed at MQX startup
- in you application, create a task at higher priority than other tasks. In this task open the serial port, then do a read() on it. The read and so the task will sleep until a full character is received. At this moment, the task immediately run, assuming no other task of same or higher priority is already running. Example for second serial port :
com2fd = fopen("ittyb:", (char_ptr)BSP_DEFAULT_IO_OPEN_MODE);
while (1) {
char buf;
fread (&buf, 1, 1, com2fd);
/// you can process character received here or wakeup another task
}
- you can wakeup another task using a lightweight semaphore (_lwsem..) or process everything after the read, as show above
The UART+driver has a FIFO so If you fail to call fread() before several characters are received, they are not lost and will be read by subsequent fread() calls. I don't remember the FIFO size (16 or 64 maybe).
You may need to disable echo on serial line so that the equipement sending characters do not receive an echo of them back. For this
_mqx_uint flags;
ioctl(com2fd, IO_IOCTL_SERIAL_GET_FLAGS, (pointer)&flags);
flags &= ~IO_SERIAL_ECHO;
ioctl(com2fd, IO_IOCTL_SERIAL_SET_FLAGS, &flags);