/** * * There may be more than one of these. */ void* ProcessPackets(void* v) { PacketRec* p; int PacketSlot; DEBUGPATH; pthread_setspecific (Globals.DThreadsKey, v); while (!Globals.Done) { PacketSlot = PopFromPending(); if (PacketSlot == PACKET_NONE) break; pthread_mutex_lock (&PLimitMutex); if (Globals.PacketLimit == 0){ printf("Packet Limit Reached\n"); Globals.Done=TRUE; } if (Globals.PacketLimit > 0) Globals.PacketLimit--; pthread_mutex_unlock (&PLimitMutex); p=&Globals.Packets[PacketSlot]; #ifdef DEBUG printf("++++++++++++++++++++++++++++++++%u\n",p->PacketNum); #endif if (p->tv.tv_sec) HandleTimers(p->tv.tv_sec); if (!Decode(Globals.DecoderRoot, PacketSlot)) { printf("Error Processing Packet\n"); } UpdateStats (PacketSlot); if (!BitFieldIsEmpty(p->RuleBits,Globals.NumRules)) { #ifdef DEBUG printf("There are rule matches\n"); #endif AddPacketToWaiting (PacketSlot); } else { RouteAndSend(PacketSlot); } /* And we are done with this packet */ } return NULL; }
void SimpleReactor::RunReactor() { m_running=true; while (m_running) { boost::mutex::scoped_lock lock(m_mutex); m_condition.timed_wait(lock, NextTimer()); if (m_timeToDispatch) { DoDispatch(); m_timeToDispatch=false; } //Check timers HandleTimers(); } }
/* Sensor data flow: * 1. Sensor interrupts on data ready. * 2. IRQ handler is solely expected to call SendDataReadyIndication. * 3. SensorAcqTask will see a message data is available. * 4. Data is read. Sensor driver is expected to clear * the interrupt from the read function. */ ASF_TASK void SensorAcqTask(ASF_TASK_ARG) { MessageBuffer *rcvMsg = NULLP; volatile uint8_t i; #ifndef WAIT_FOR_HOST_SYNC osDelay(50); #else WaitForHostSync(); //This also allows for startup time for sensors #endif /* Setup I2C bus here? */ dev_i2c_init(); /* Setup interface for the Magnetometer */ Mag_HardwareSetup(true); Mag_Initialize(); /* Setup interface for the accelerometers */ Accel_HardwareSetup(true); Accel_Initialize(INIT_NORMAL); /* Setup Gyro */ Gyro_HardwareSetup(true); Gyro_Initialize(); D0_printf("Gyro init done:\r\n"); /* Setup Pressure */ Pressure_HardwareSetup(true); Pressure_Initialize(); ASFTimerStart(SENSOR_ACQ_TASK_ID, TIMER_REF_PRESSURE_READ, PRESSURE_SAMPLE_PERIOD, &sPressureTimer); #ifndef INTERRUPT_BASED_SAMPLING /* Start sample period timer */ ASFTimerStart(SENSOR_ACQ_TASK_ID, TIMER_REF_SENSOR_READ, SENSOR_SAMPLE_PERIOD, &sSensorTimer); #else /* Enable Sensor interrupts */ Mag_ConfigDataInt(true); Accel_ConfigDataInt(true); Gyro_ConfigDataInt(true); # ifdef TRIGGERED_MAG_SAMPLING D0_printf("Set mag to low power mode\r\n"); Mag_SetLowPowerMode(); //Low power mode until triggered # endif #endif D0_printf("%s initialized\r\n", __func__); /* Magnetometer sensor does not re-generate interrupt if its outputs are not read. */ Mag_ClearDataInt(); /* Indicate sensor init done */ sTskRdyFlag = 1; while (1) { ASFReceiveMessage(SENSOR_ACQ_TASK_ID, &rcvMsg); // D0_printf("rcvMsg->msgId = %d\r\n",rcvMsg->msgId); switch (rcvMsg->msgId) { case MSG_TIMER_EXPIRY: HandleTimers(&rcvMsg->msg.msgTimerExpiry); break; case MSG_CAL_EVT_NOTIFY: #ifdef ENABLE_FLASH_STORE StoreCalibrationData((CalEvent_t)rcvMsg->msg.msgCalEvtNotify.byte); #else D0_printf("#### WARNING - NV Storage Not Implemented! #####\r\n"); #endif break; case MSG_SENSOR_DATA_RDY: //D0_printf("MSG_SENSOR_DATA_RDY msg id %d\r\n", rcvMsg->msgId); #ifdef INTERRUPT_BASED_SAMPLING SensorDataHandler((InputSensor_t)rcvMsg->msg.msgSensorDataRdy.sensorId, rcvMsg->msg.msgSensorDataRdy.timeStamp); #endif break; case MSG_SENSOR_CONTROL: //D0_printf("MSG_SENSOR_CONTROL msg id %d\r\n",rcvMsg->msgId); SensorControlCmdHandler(&rcvMsg->msg.msgSensorControlData); break; default: /* Unhandled messages */ D2_printf("SensorAcqTask:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId); break; } ASFDeleteMessage( SENSOR_ACQ_TASK_ID, &rcvMsg ); } }
void AllegroEngine::Run() { ALLEGRO_EVENT ev; while (!quit) { al_wait_for_event(event_queue, &ev); switch (ev.type) { /* ALLEGRO_EVENT_KEY_DOWN - a keyboard key was pressed. * The three keyboard event fields we use here are: * * keycode -- an integer constant representing the key, e.g. * AL_KEY_ESCAPE; * * unichar -- the Unicode character being typed, if any. This can * depend on the modifier keys and previous keys that were * pressed, e.g. for accents. * * modifiers -- a bitmask containing the state of Shift/Ctrl/Alt, etc. * keys. */ case ALLEGRO_EVENT_KEY_DOWN: if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) quit = true; KeyDown(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers); break; /* ALLEGRO_EVENT_KEY_REPEAT - a keyboard key was held down long enough to * 'repeat'. This is a useful event if you are working on something * that requires typed input. The repeat rate should be determined * by the operating environment the program is running in. */ case ALLEGRO_EVENT_KEY_CHAR: KeyDown(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers, ev.keyboard.repeat); break; /* ALLEGRO_EVENT_KEY_UP - a keyboard key was released. * Note that the unichar field is unused for this event. */ case ALLEGRO_EVENT_KEY_UP: KeyUp(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers); break; /* ALLEGRO_EVENT_MOUSE_AXES - at least one mouse axis changed value. * The 'z' axis is for the scroll wheel. We also have a fourth 'w' * axis for mice with two scroll wheels. */ case ALLEGRO_EVENT_MOUSE_AXES: MouseMoved(ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz); break; /* ALLEGRO_EVENT_MOUSE_BUTTON_UP - a mouse button was pressed. * The axis fields are also valid for this event. */ case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: MouseButtonDown(ev.mouse.button, ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz); break; /* ALLEGRO_EVENT_MOUSE_BUTTON_UP - a mouse button was released. * The axis fields are also valid for this event. */ case ALLEGRO_EVENT_MOUSE_BUTTON_UP: MouseButtonUp(ev.mouse.button, ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz); break; /* ALLEGRO_EVENT_TIMER - a timer 'ticked'. * The `source' field in the event structure tells us which timer * went off, and the `count' field tells us the timer's counter * value at the time that the event was generated. It's not * redundant, because although you can query the timer for its * counter value, that value might have changed by the time you got * around to processing this event. */ case ALLEGRO_EVENT_TIMER: HandleTimers(ev.timer.source, ev.timer.count); break; /* ALLEGRO_EVENT_DISPLAY_CLOSE - the window close button was pressed. */ case ALLEGRO_EVENT_DISPLAY_CLOSE: quit = true; return; /*case ALLEGRO_EVENT_DISPLAY_SWITCH_IN: log_general("Switch In"); break; case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT: log_general("Switch Out"); break;*/ /* We received an event of some type we don't know about. * Just ignore it. */ default: break; } } }