IO_IOCTL_SERIAL_WAIT_FOR_TC behaves strange (MQX4.0)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

IO_IOCTL_SERIAL_WAIT_FOR_TC behaves strange (MQX4.0)

跳至解决方案
831 次查看
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

标记 (3)
1 解答
500 次查看
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

在原帖中查看解决方案

3 回复数
500 次查看
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 项奖励
501 次查看
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

500 次查看
Martin_
NXP Employee
NXP Employee

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

0 项奖励