lwevents not working as documented ?

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

lwevents not working as documented ?

Jump to solution
520 Views
gpontis
Contributor IV

Re: MQX 4.2 on K64

I am having quite a bit of trouble with lwevents. The event is created with the auto_clear option. An ISR sets an event at the end of a DMA scan of ADC channels. Two or more tasks wait for the event. The event is generated periodically, about every 17ms. I verified this by toggling an IO pin in the ISR.

Two tasks, with different priorities, contain nothing but a while loop that waits on the same event. I am expecting that both will briefly go active each time the event is set. In fact what happens is that each task gets half the events. This is contrary to the documentation, and not nearly as useful a mechanism.

I also see that the lwevent unblocks immediately and without a fresh event, if there were previous events set when no task was waiting on them. I don't think that this is proper if the event group was created with the LWEVENT_AUTO_CLEAR option. This might be avoided by calling lwevent_clear in the ISR immediately after calling lwevent_set. At least it seems to fix this so far as I can see in 1 minute of testing.

I am going to try the "heavy" events in MQX and I hope that they work better.

George

1 Solution
322 Views
DavidS
NXP Employee
NXP Employee

Hi George,

I think the lwevents with one mask for multiple tasks is what is making it difficult.

Attached is example that works with auto clear or manual clear.

I used the lwevent example in the MQX_4.2 as a starting point.

Note it is not humming along at 17msec but is using the 1 second timeout in the example.

I added two more task: hello_task and world_task.

At top of lwevent.c file you can switch between using auto clear or manual using:

#define LWEVENTAUTOCLEAR 0//DES 1=use auto clear, 0=manual clear

Each task is waiting for a different bit in the lwevent mask and the isr is setting the mask to "7".

"service_task" waits for bit 1.

"hello_task" waits for bit 2.

"world_task" waits for bit 4.

If I had all the task waiting on just "1" I saw your results.  If I switched to using manual lwevent clearing, then it would work OK.

Regards,

David

View solution in original post

0 Kudos
2 Replies
322 Views
gpontis
Contributor IV

Thanks for suggesting this workaround. I think that it would be practical in most situations. Long term, let's hope that the MQX developers fix both of these bugs. I guess that our posts will have to do as a form of an errata on lwevents for the current users.

George

0 Kudos
323 Views
DavidS
NXP Employee
NXP Employee

Hi George,

I think the lwevents with one mask for multiple tasks is what is making it difficult.

Attached is example that works with auto clear or manual clear.

I used the lwevent example in the MQX_4.2 as a starting point.

Note it is not humming along at 17msec but is using the 1 second timeout in the example.

I added two more task: hello_task and world_task.

At top of lwevent.c file you can switch between using auto clear or manual using:

#define LWEVENTAUTOCLEAR 0//DES 1=use auto clear, 0=manual clear

Each task is waiting for a different bit in the lwevent mask and the isr is setting the mask to "7".

"service_task" waits for bit 1.

"hello_task" waits for bit 2.

"world_task" waits for bit 4.

If I had all the task waiting on just "1" I saw your results.  If I switched to using manual lwevent clearing, then it would work OK.

Regards,

David

0 Kudos