Ask about Event on ver 2.4.x
Posted: Fri Apr 05, 2013 9:34 am
Hi all,
Chibi is the first OS I use so that I have many misunderstanding when using it. Now I try to use Event and BroadcastFlag, however I see it doesn't work as I wish, or I have something misunderstand. I have 2 threads need to be call by 1 interrupt, like that:
It's main thread:
It's MeasurementThread
And in RTC interrupt, base on Alarm or Wakeup interrupt I will broadcast with EventMask(1) or EventMask(2)
Absolutely that I make Alarm and Wakeup interrupt never occur at the same time. And I see that when chEvtBroadcastFlagsI() function is called, both threads (with different ListenEvent and Mask) will wake up, and this is not what I expect.
Follow what I understand, Broadcast will call exactly a thread that has specific SourceEvent, ListenEvent and EventMask. Is that right? Can you explain for me?
Thanks!
Chibi is the first OS I use so that I have many misunderstanding when using it. Now I try to use Event and BroadcastFlag, however I see it doesn't work as I wish, or I have something misunderstand. I have 2 threads need to be call by 1 interrupt, like that:
It's main thread:
Code: Select all
EventSource evtS1;
void main(void)
{
EventListener evtL1;
chEvtInit(&evtS1);
chEvtRegister(&evtS1, &evtL1, 1);
chThdCreateStatic(waMeasurementThread, sizeof(waMeasurementThread), NORMALPRIO, MeasureProcess, NULL);
while (TRUE)
{
chEvtWaitOne(EVENT_MASK(1));
CP_SENSOR();
}
}
It's MeasurementThread
Code: Select all
extern EventSource evtS1;
msg_t MeasureProcess(void *p)
{
EventListener evtL2;
chEvtRegister(&evtS1, &evtL2, 2);
while(1)
{
chEvtWaitOne(EVENT_MASK(2));
MeasureTemperature();
}
}
And in RTC interrupt, base on Alarm or Wakeup interrupt I will broadcast with EventMask(1) or EventMask(2)
Code: Select all
CH_IRQ_HANDLER(4)
{
CH_IRQ_PROLOGUE();
if(RTC_GetITStatus(RTC_IT_WUT)==SET)
{
RTC_ClearITPendingBit(RTC_IT_WUT);
chEvtBroadcastFlagsI(&evtS1, EVENT_MASK(2));
}
if(RTC_GetITStatus(RTC_IT_ALRA)==SET)
{
RTC_ClearITPendingBit(RTC_IT_ALRA);
chEvtBroadcastFlagsI(&evtS1, EVENT_MASK(1));
}
CH_IRQ_EPILOGUE();
}
Absolutely that I make Alarm and Wakeup interrupt never occur at the same time. And I see that when chEvtBroadcastFlagsI() function is called, both threads (with different ListenEvent and Mask) will wake up, and this is not what I expect.
Follow what I understand, Broadcast will call exactly a thread that has specific SourceEvent, ListenEvent and EventMask. Is that right? Can you explain for me?
Thanks!