nio_serial gets blocked

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

nio_serial gets blocked

560 Views
adyr
Contributor V

I am using the printf debug console to show many diagnostics messages in a terminal window. Occasionally the function will block forever waiting for space in the output buffer. I have tracked down the reason but not the cause. In the nio_serial_txcallback function there is the section:

    if (buffer->FLAGS & NIO_SERIAL_WAITING)

    {   /* If the desired place in buffer was released, post blocking semaphore */

        if (!(--buffer->WAIT_NUM))

        {

Sometimes it can reach the --buffer->WAIT_NUM when WAIT_NUM is already 0 so it decrements to 4294967295 and then the semaphore never gets posted so the send function stays permanently blocked. I can't see why WAIT_NUM should be 0 when FLAGS has the NIO_SERIAL_WAITING bit set but it does.

 

For now I have change the test line to:

        if ((buffer->WAIT_NUM == 0) || !(--buffer->WAIT_NUM))

which seems to solve the lockup but I feel it is covering up the real problem.

 

Best regards,

Adrian.

Labels (1)
0 Kudos
3 Replies

397 Views
isaacavila
NXP Employee
NXP Employee

Hello Adrian,

According to what you are describing, it seems to be a nio_serial bug.

I have made a quick review on nio_serial files and NIO_SERIAL_WAITING flag is set to non-zero value when you are wanting to write to Serial port when there is no available space on internal Tx Buffer (buffer is full), in this case, this flag is set and serial driver is waiting for "WAIT_NUM" spaces to be freed in order to resume the serial writing procedure.

In tx callback, when one character is sent, driver decreases the pending "WAIT_NUM" bytes and check if this variable is 0, when this happens, all spaces needed are already freed and now, previous writing request to serial port can be resumed.

I would like to see the moment when "WAIT_NUM" variable is zero and then it is decreased by transmission callback. (I am expecting this variable to be 1 when semaphore is posted) so I would like to ask you your code to reach the condition where tx buffer is full and NIO_SERIAL_WAITING flag is set. could you please be so kind to attach your code, besides, provide additional information such as IDE (kds, iar, etc) and ksdk version?

Best Regards,

Isaac

0 Kudos

397 Views
adyr
Contributor V

Hi Isaac,

Thank you for your time to look into this. Sorry I forgot to provide the basic information. I created the project with KDS 3.0 using KSDK 1.2 and MQX. I am building the code and debugging with IAR Workbench 7.4.2.8570 via the IAR / Processor Expert Connection.

My test code is sending lots of data through the debug consoles so will very frequently have to wait for the UART but this problem only occurs occasionally (once or twice a day). Having analysed the code again the only thing that springs to mind is if while in nio_serial_write the tx interrupt occurs between setting waiting flag and calculating the number of bytes to wait for. I think, as the nio_serial_write code is interacting with variables that are also changed / checked by an interrupt, the interrupts need to be disabled while the checks / changes are made within the nio_serial_write routine. Unfortunately my code is rather large and requires some custom hardware to run so it is not practical to provide it. Also the Hardware has been taken away by the electronics department to add more components so I can't do any testing at the moment.

Best regards,
Adrian.

0 Kudos

397 Views
isaacavila
NXP Employee
NXP Employee

Hi Adrian,

I will try to replicate this issue on my side, but if you can provide a simple code using one Freescale's board that allows me to analyze this issue or any hint, i will thank you a lot.

Have a nice day,

Regards,

Isaac

0 Kudos