I think events is the most complicated thing on chibios, I'm having a really hard time on making it work properly. Sorry for the long post and codes. I have 5 events(0, 1, 2, 3 and 4). 0 and 1 are events from interrupts, 2 and 3 are polling threads from sensors(that only runs when interrupt AND EKF are fired) and 4 is the EKF algorithm state. Interrupts are being fired as verified in debug as the sensors are running perfectly. What is happening on the code below is that everything are being fired randomly instead of waiting proper events to run.
Initialize on main():
Code: Select all
chEvtInit(&imu_event);
chEvtBroadcastFlags(&imu_event, EVENT_MASK(4));
Take a look on these interrupts:
Code: Select all
void mpu6050_interrupt_handler(EXTDriver *extp, expchannel_t channel) {
(void) extp;
(void) channel;
chSysLockFromIsr();
chEvtBroadcastFlagsI(&imu_event, EVENT_MASK(0) );
chSysUnlockFromIsr();
}
void hmc5883l_interrupt_handler(EXTDriver *extp, expchannel_t channel) {
(void) extp;
(void) channel;
chSysLockFromIsr();
chEvtBroadcastFlagsI(&imu_event, EVENT_MASK(1) );
chSysUnlockFromIsr();
}
And these threads:
Code: Select all
static WORKING_AREA(PollIMUThreadWA, 512);
static msg_t PollIMUThread(void *arg){
(void)arg;
chRegSetThreadName("PollIMU");
EventListener self_el1, self_el2;
chEvtRegister(&imu_event, &self_el1, 0);
chEvtRegister(&imu_event, &self_el2, 4);
while (TRUE) {
chEvtWaitAll(EVENT_MASK(0) | EVENT_MASK(4));
// do stuff
chEvtBroadcastFlags(&imu_event, EVENT_MASK(2));
}
}
static WORKING_AREA(PollMagnThreadWA, 512);
static msg_t PollMagnThread(void *arg){
(void)arg;
chRegSetThreadName("PollMagn");
EventListener self_el1, self_el2;
chEvtRegister(&imu_event, &self_el1, 1);
chEvtRegister(&imu_event, &self_el2, 4);
while (TRUE) {
chEvtWaitAll(EVENT_MASK(1) | EVENT_MASK(4));
// do stuff
chEvtBroadcastFlags(&imu_event, EVENT_MASK(3));
}
}
static WORKING_AREA(PollEKFThreadWA, 512);
static msg_t PollEKFThread(void *arg){
(void)arg;
chRegSetThreadName("PollEKF");
EventListener self_el1, self_el2;
chEvtRegister(&imu_event, &self_el1, 2);
chEvtRegister(&imu_event, &self_el2, 3);
while (TRUE) {
chEvtWaitAll(EVENT_MASK(2) | EVENT_MASK(3));
// do stuff
chEvtBroadcastFlags(&imu_event, EVENT_MASK(4));
}
}
I read wiki documentation and a PDF that was attached to another post but I couldn't make it work.