void Meter_GetSamples(void *pData) { static uint8_t numberOfSamples = 0; for(;;) { OS_SemaphoreWait(SamplesReady, 0); //Wait until the sampler module has sampled the data if (numberOfSamples != 16) { if (!PerformingCalculations) { //If we are not currently running calculations on these private global arrays, they are available for assignment VoltageSamples[numberOfSamples] = Sampler_VoltageSample; CurrentSamples[numberOfSamples] = Sampler_CurrentSample; numberOfSamples++; } } else { //We have collected all the required samples, signal other calculation thread to run its routines. numberOfSamples = 0; OS_SemaphoreSignal(RunCalculations); } } }
/*! * @brief This-stuff-hasn't-been-adjusted-yet thread. */ void EventThread(void *data) { for (;;) { OS_SemaphoreWait(EventSemaphore, 0); if (ToggleSwitch) { ToggleSwitch = bFALSE; ChangeMode(MODE_TOGGLE); continue; } if (GameSwitch) { GameSwitch = bFALSE; ChangeMode(MODE_GAME); continue; } if (ToggleFinishedFlag) { ToggleFinishedFlag = bFALSE; ChangeMode(MODE_DEFAULT); continue; } if (GameFinishedFlag) { GameFinishedFlag = bFALSE; ChangeMode(MODE_DEFAULT); continue; } } }
/*! * @brief Thread for the bread (packets). */ void PacketThread(void *data) { for (;;) { if (!Packet_Semaphore) { OS_TimeDelay(10); continue; } OS_SemaphoreWait(Packet_Semaphore, 0); LEDs_On(LED_BLUE); Timer_Start(&PacketTimer); HandlePacket(); /* * If there is a new packet available, * turn on the blue LED, start the timer * to turn the LED off and finally * handle the packet. * * Packet_Get blocks until a packet is available. */ // if (Packet_Get()) // { // LEDs_On(LED_BLUE); // Timer_Start(&PacketTimer); // HandlePacket(); // } } }
void Meter_RunCalculations(void *pData) { for(;;) { OS_SemaphoreWait(RunCalculations, 0); //Wait until the sample arrays have been accordingly populated PerformingCalculations = bTRUE; runCalculations(); } }
/*! * @brief Thread handling the RTC */ void RtcThread(void *data) { for (;;) { OS_SemaphoreWait(RtcSemaphore, 0); uint8_t h, m, s; RTC_Get(&h, &m, &s); CMD_SendTime(h, m, s); if (ProjectMode == MODE_DEFAULT) { LEDs_Toggle(LED_YELLOW); } } }
/*! * @brief Initialisation thread. runs once. */ void InitThread(void *data) { for (;;) { OS_SemaphoreWait(InitSemaphore, 0); Random_Init(); //Switches mate Switch_Init(S1Callback, (void *) 0, S2Callback, (void *) 0); Toggle_Init(ToggleModeFinished); Game_Init(GameModeFinished); Touch_Init(); //Initialize all the modules LEDs_Init(); I2C_Init(100000, MODULE_CLOCK); Accel_Init(&AccelSetup); PIT_Init(MODULE_CLOCK, &PitCallback, (void *) 0); PIT_Set(500000000, bFALSE); PIT_Enable(bTRUE); Packet_Init(BAUD_RATE, MODULE_CLOCK); Flash_Init(); CMD_Init(); //Best to do this one last //TODO: disabled for yellow RTC_Init((void (*)(void*))OS_SemaphoreSignal, (void *) RtcSemaphore); Timer_Init(); Timer_Set(&PacketTimer); Timer_Set(&AccTimer); CMD_SpecialGetStartupValues(); LEDs_On(LED_ORANGE); } }