Has anyone modified the MQX serial driver to include a timeout?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Has anyone modified the MQX serial driver to include a timeout?

1,136件の閲覧回数
waynetaylor
Contributor II

The serial protocol I'm implementing has packet and inter-character timeouts. Is there a way besides polling the driver for available characters to implement timeouts like windows and linux support?

Currently we use blocking until the first character is received, then switch to non-blocking and poll for available characters. There has to be a better way!

I have thought about using two timer event to unblock the task that calls getc(). The first timer event callback would unblock the calling task when the packet timeout occurs, the second callback would unblobk the task at the end of each inter-character timeout. The inter-character timeout would be cancelled with the reception of each character, and then restarted.

All that seems very cumbersome.

Does anyone have a better idea?

Wayne

タグ(1)
3 返答(返信)

849件の閲覧回数
matthewkendall
Contributor V

The underlying issue is that the thread can only block on one thing at a time; if it's blocked waiting for a character then it can't also be blocked waiting for a timeout.

A solution I have used for this kind of problem is lightweight events. A lightweight event group contains a number of bits, and a task can block waiting for any of them to get set. So, have a thread that does blocking getc calls and posts an event when it gets one, and have the timer task post events to the same event group on various timeouts, then have your main task block waiting for any of the events. Once it unblocks it can see which events have happened with _lwevent_get_signalled().

849件の閲覧回数
DavidS
NXP Employee
NXP Employee

Hi Wayne,

I did a hack a while back.  Not certain you like but have a look.

Regards,

David

0 件の賞賛
返信

849件の閲覧回数
waynetaylor
Contributor II

Mr Seymour, your answer works, but it is exactly what I described. I want to avoid polling and calls to _time_delay(). What I was really hoping for was help figuring out how to use timer events to unblock calls to fgetc() when either the inter-character or packet timer expires. This solution would be completely deterministic with no polling.

0 件の賞賛
返信