IO_IOCTL_SERIAL_WAIT_FOR_TC behaves strange (MQX4.0)

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

IO_IOCTL_SERIAL_WAIT_FOR_TC behaves strange (MQX4.0)

Jump to solution
812 Views
mikhailburakov
Contributor III

Hello!

I am trying to implement support for custom protocol working via RS-485. However I stumbled upon a problem with IO_IOCTL_SERIAL_WAIT_FOR_TC. In my configuration I need to switch a gpio pin after all the data has been sent. To ensure all the data is sent, I tried to use the above ioctl. But on the receiving side I do not get the tail of my data, so it looks like the ioctl returns before all the data is sent. However, I figured out that actually this ioctl does nothing other than waiting for the TC bit in UARTx_S1 register in an infinite loop. I simply removed the ioctl call and replaced it with exact the same infinite loop. Everything started to work as expected afterwards. So my question is, how is this possible? I looked through the serial ioctls part of MQX code and did not found any suspicious calls. For the reference, I am running MQX 4.0.1 on MK20DX256VLK7 CPU. Is there anything I missed in the documentation?

Best regards,

Mikhail Burakov

Tags (3)
1 Solution
481 Views
mikhailburakov
Contributor III

I am following a good tradition and replying to myself.

Actually it appears there's a bug in MQX source code. The file Freescale_MQX_4_0\mqx\source\io\serial\polled\serl_pol_kuart.c, line 958:

         while( ! sci_ptr->S1 & UART_S1_TC_MASK )
must be replaced with:

         while( ! (sci_ptr->S1 & UART_S1_TC_MASK))

to bring it in peace with operators precedence.

Best regards,

Mikhail Burakov

View solution in original post

3 Replies
481 Views
davidtietz
Contributor III

Hi Mikhail,

Just wanted to say thank you for your post and findings. It saved me a lot of headache today because I was having a similar problem until I stumbled on your post.

Thanks,

David

0 Kudos
482 Views
mikhailburakov
Contributor III

I am following a good tradition and replying to myself.

Actually it appears there's a bug in MQX source code. The file Freescale_MQX_4_0\mqx\source\io\serial\polled\serl_pol_kuart.c, line 958:

         while( ! sci_ptr->S1 & UART_S1_TC_MASK )
must be replaced with:

         while( ! (sci_ptr->S1 & UART_S1_TC_MASK))

to bring it in peace with operators precedence.

Best regards,

Mikhail Burakov

481 Views
Martin_
NXP Employee
NXP Employee

Hi Mikhail, you are absolutely right! It will be fixed in next MQX release. Thanks !

0 Kudos