Serial IO_SERIAL_NON_BLOCKING flag

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

Serial IO_SERIAL_NON_BLOCKING flag

Jump to solution
2,186 Views
Teckna
Contributor V

Hi everyone,

I would like to know why the serial drivers (both polled and interrupt) open function tests the IO_SERIAL_NON_BLOCKING flag to be non simultaneous with the IO_SERIAL_TRANSLATION, IO_SERIAL_ECHO or IO_SERIAL_XON_XOFF flags. Which problem can arise if a device is opened with IO_SERIAL_NON_BLOCKING flag and one of the other IO_SERIAL_TRANSLATION, IO_SERIAL_ECHO or IO_SERIAL_XON_XOFF flags?

Many thanks

Teckna

0 Kudos
1 Solution
920 Views
c0170
Senior Contributor III

Hi Teckna,

please review code in function _io_serial_int_read.

If IO_SERIAL_NON_BLOCKING is set, interrupts are enabled, and data are passed directly to buffer, without any interventions.

On the other hand, if NON_BLOCKING flag is not set, while loop continues and those 3 flags IO_SERIAL_TRANSLATION, IO_SERIAL_ECHO or IO_SERIAL_XON_XOFF are checked and appropriate actions are carried out in case of any of those flags are enabled .

Anyway, you can customize interrupt mode to your needs. Share with us your code :smileywink:

Regards,

MartinK

View solution in original post

0 Kudos
10 Replies
920 Views
ivanpajuelo
Contributor II

Kojto is right.

You can't use IO_SERIAL_NON_BLOCKING whit IO_SERIAL_TRANSLATION, IO_SERIAL_ECHO or IO_SERIAL_XON_XOFF.

If you need a translation or an echo you must implement it manually.

0 Kudos
920 Views
DavidS
NXP Employee
NXP Employee

Hi Teckna,

Not 100% certain of an answer.

A clue might be in the MQXIOUG.pdf:

C:\Freescale\Freescale MQX 3.8\doc\mqx\MQXIOUG.pdf

5.6 I/O Open Flags

This section describes the flagvalues you can pass when you call_io_fopen()for a particular

interrupt-driven or polled serial-device driver. They are defined in serial.h.

Command Description

IO_SERIAL_RAW_IO No processing of I/O done.

IO_SERIAL_XON_XOFF Software flow control enabled.

IO_SERIAL_TRANSLATION Translation of:

outgoing \n to CRLF

incoming CR to \n

incoming backspace outputs backspace

space backspace and drops the input.

IO_SERIAL_ECHO Echoes incoming characters.

IO_SERIAL_HW_FLOW_CONTROL Enables hardware flow control (RTS/CTS)

where available.

IO_SERIAL_NON_BLOCKING Open the serial driver in non blocking mode.

In this mode the _io_read() function doesn’t

wait till the receive buffer is full, but it

immediately returns received characters

and number of received characters.

IO_SERIAL_HW_485_FLOW_CONTROL Enables hardware support for RS485 if it is

available on target processor. Target HW

automatically asserts RTS signal before

transmit message and deasserts it after

transmission is done.

Regards,

David

920 Views
Teckna
Contributor V

Many thanks David,

I did read the document you told me, but I stil don't understand why I can't call the _io_fopen function with both

IO_SERIAL_NON_BLOCKING and IO_SERIAL_TRANSLATION flags (for example).

Many thanks

Teckna

0 Kudos
920 Views
DavidS
NXP Employee
NXP Employee

Hi Teckna,

From a high level the polled UART mode is blocking by definitiion.

The interrupt UART mode is non-blocking by definition.

I've used both polled and interrupt and know that when I have used interrupt that the translation works.

Have you tried using the interrupt mode?

Regards,

David

0 Kudos
920 Views
Teckna
Contributor V

"The interrupt UART mode is non-blocking by definition."

Hi David,

I think it's not correct, because if I call _io_fopen with NULL pointer to the flags parameter and then I call _io_fread to read, for example, 20 bytes, if there are not at least 20 bytes in the receive buffer, the task is put in a waiting state until all the 20 bytes are received: this way the task is blocked.

Many thanks

Teckna

0 Kudos
921 Views
c0170
Senior Contributor III

Hi Teckna,

please review code in function _io_serial_int_read.

If IO_SERIAL_NON_BLOCKING is set, interrupts are enabled, and data are passed directly to buffer, without any interventions.

On the other hand, if NON_BLOCKING flag is not set, while loop continues and those 3 flags IO_SERIAL_TRANSLATION, IO_SERIAL_ECHO or IO_SERIAL_XON_XOFF are checked and appropriate actions are carried out in case of any of those flags are enabled .

Anyway, you can customize interrupt mode to your needs. Share with us your code :smileywink:

Regards,

MartinK

0 Kudos
920 Views
Teckna
Contributor V

Hi Martin,

The _io_serial_int_read function is clear, but it's not clear for me why there is the test to have not both IO_SERIAL_NON_BLOCKING and IO_SERIAL_TRANSLATION flags (for example) set in the _io_serial_int_open (lines 296-297 in serl_int.c) and _io_serial_polled_open (lines 270-271 in serl_int.c) functions.

I'm using MQX 3.8.1.

Many thanks

Teckna

0 Kudos
920 Views
c0170
Senior Contributor III

Hello there,

I have explained you why there's test of those flags in open function. If you set IO_SERIAL_NON_BLOCKING, none of IO_SERIAL_TRANSLATION | IO_SERIAL_ECHO | IO_SERIAL_XON_XOFF flags are functional therefore you get an error as return value.

If your intention is for example SERIAL_ECHO flag functionality, you have to edit ISR to change directly data before they are stored into buffer.

Regards,

MartinK

0 Kudos
920 Views
Teckna
Contributor V

Hi David,

I'm using the interrupt mode.

My original question came because i tried to call the _io_fopen function with both IO_SERIAL_NON_BLOCKING and IO_SERIAL_TRANSLATION flags and the result was ko. I read the source code and I saw that the _io_serial_int_open and _io_serial_polled_open functions return MQX_INVALID_PARAMETER in this condition.

I'd want to modify the source code to handle my condition, but I'm not sure if this can get some problem.

Many thanks

Teckna

0 Kudos
920 Views
DavidS
NXP Employee
NXP Employee

Hi Teckna,

Why would you want to setup the interrupt mode to be polled?  That is defeating the purpose of the driver (I think).

If you want polled use the polled driver mode and not the interrupt mode.  Or am I missing something in the post?

Regards,

David

0 Kudos