static void AppThread(void *arg) { chRegSetThreadName("App"); uint32_t EvtMsk; bool PillConnected = false; while(true) { EvtMsk = chEvtWaitAny(ALL_EVENTS); // ==== Process dose ==== // if(EvtMsk & EVTMSK_DOSE_INC) { // // Check if radio damage occured. Will return 1 if no. // uint32_t FDamage = Radio.Damage; // //if(FDamage != 1) Uart.Printf("Dmg=%u\r", FDamage); // Dose.Increase(FDamage, diUsual); // //Uart.Printf("Dz=%u; Dmg=%u\r", Dose.Get(), FDamage); // } // ==== Store dose ==== // if(EvtMsk & EVTMSK_DOSE_STORE) { // //if(Dose.Save() != OK) Uart.Printf("EE Fail\r"); // DEBUG // } // ==== Check pill ==== if(EvtMsk & EVTMSK_PILL_CHECK) { // Check if new connection occured if(PillMgr.CheckIfConnected(PILL_I2C_ADDR) == OK) { if(!PillConnected) { PillConnected = true; App.IPillHandler(); } } else PillConnected = false; } // if EVTMSK_PILL_CHECK } // while 1 }
int main() { // ==== Setup clock ==== Clk.UpdateFreqValues(); uint8_t ClkResult = FAILURE; Clk.SetupFlashLatency(12); // Setup Flash Latency for clock in MHz // 12 MHz/6 = 2; 2*192 = 384; 384/8 = 48 (preAHB divider); 384/8 = 48 (USB clock) Clk.SetupPLLDividers(6, 192, pllSysDiv8, 8); // 48/4 = 12 MHz core clock. APB1 & APB2 clock derive on AHB clock Clk.SetupBusDividers(ahbDiv4, apbDiv1, apbDiv1); if((ClkResult = Clk.SwitchToPLL()) == 0) Clk.HSIDisable(); Clk.UpdateFreqValues(); // ==== Init OS ==== halInit(); chSysInit(); // ==== Init Hard & Soft ==== App.PThd = chThdSelf(); Uart.Init(115200); Uart.Printf("\rLockNFC3 F205 AHB freq=%uMHz", Clk.AHBFreqHz/1000000); // Report problem with clock if any if(ClkResult) Uart.Printf("Clock failure\r"); LedService.Init(); LedService.StartSequence(lsqBlinkGreenX2); Led.Init(); Led.StartSequence(lsqDoorClose); Sensors.Init(); Pn.Init(); SD.Init(); // SD-card init App.IDStore.Load(); // Init Srorage of IDs SndList.Init(); App.ReadConfig(); // Read config from SD-card Sound.Init(); Sound.SetVolume(250); Sound.RegisterAppThd(chThdSelf()); Sound.Play("alive.wav"); #if USB_ENABLED MassStorage.Init(); // Init USB MassStorage device #endif // ==== Main cycle ==== App.ITask(); }
int main(void) { // ==== Setup clock frequency ==== uint8_t ClkResult = 1; Clk.SetupFlashLatency(64); // Setup Flash Latency for clock in MHz Clk.EnablePrefetch(); // 12 MHz/6 = 2; 2*192 = 384; 384/6 = 64 (preAHB divider); 384/8 = 48 (USB clock) Clk.SetupPLLDividers(6, 192, pllSysDiv6, 8); // 64/1 = 64 MHz core clock. APB1 & APB2 clock derive on AHB clock; APB1max = 42MHz, APB2max = 84MHz // Keep APB freq at 32 MHz to left peripheral settings untouched Clk.SetupBusDividers(ahbDiv1, apbDiv2, apbDiv2); if((ClkResult = Clk.SwitchToPLL()) == 0) Clk.HSIDisable(); Clk.UpdateFreqValues(); // Init OS halInit(); chSysInit(); // ==== Init hardware ==== Uart.Init(115200, UART_GPIO, UART_TX_PIN, UART_GPIO, UART_RX_PIN); Uart.Printf("\r%S %S", APP_NAME, APP_VERSION); Clk.PrintFreqs(); if(ClkResult != 0) Uart.Printf("\rXTAL failure"); App.InitThread(); // Leds LedAux.Init(); for(uint8_t i=0; i<4; i++) { Led[i].Init(); // for(uint8_t j=0; j<250; j++) { // Led[i].Set(j); // chThdSleepMilliseconds(4); // } // Led[i].Set(0); } // Debug: init CS2 as output PinSetupOut(GPIOC, 13, omPushPull, pudNone); // ==== USB ==== UsbAu.Init(); UsbAu.Connect(); Pcm.Init(); // Main cycle App.ITask(); }
int main(void) { // ==== Init Vcore & clock system ==== SetupVCore(vcore1V5); // Clk.SetMSI4MHz(); Clk.SetupFlashLatency(16); Clk.SwitchToHSI(); Clk.UpdateFreqValues(); // Init OS halInit(); chSysInit(); App.InitThread(); // ==== Init hardware ==== Uart.Init(115200, UART_GPIO, UART_TX_PIN);//, UART_GPIO, UART_RX_PIN); Uart.Printf("\r%S %S\r", APP_NAME , BUILD_TIME); Clk.PrintFreqs(); Effects.Init(); if(Radio.Init() == OK) { // Effects.AllTogetherSmoothly(clGreen, 45); // chEvtWaitAny(EVT_LEDS_DONE); // Effects.AllTogetherSmoothly(clBlack, 45); // chEvtWaitAny(EVT_LEDS_DONE); } else { Effects.AllTogetherNow(clRed); chThdSleepMilliseconds(180); Effects.AllTogetherNow(clBlack); chThdSleepMilliseconds(180); Effects.AllTogetherNow(clRed); chThdSleepMilliseconds(180); Effects.AllTogetherNow(clBlack); chThdSleepMilliseconds(180); Effects.AllTogetherNow(clRed); chThdSleepMilliseconds(180); Effects.AllTogetherNow(clBlack); } // Effects.ChunkRunningRandom(clGreen, 2, 180); Effects.ChunkRunningRandom(clYellow, 2, 0); // Main cycle App.ITask(); }
int main(void) { // ==== Init Vcore & clock system ==== SetupVCore(vcore1V5); Clk.UpdateFreqValues(); // ==== Init OS ==== halInit(); chSysInit(); // ==== Init Hard & Soft ==== Uart.Init(115200); Uart.Printf("\rLocket AHB=%u", Clk.AHBFreqHz); App.InitThread(); // App.LoadSettings(); // PinSensors.Init(); // Beeper.Init(); // Beeper.StartSequence(bsqBeepBeep); Led.Init(); Led.StartSequence(lsqStart); // Vibro.Init(); // Vibro.StartSequence(vsqBrrBrr); // PinSetupOut(GPIOB, 8, omPushPull, pudNone); // PinClear(GPIOB, 8); // PwmPin_t IPin; // IPin.Init(GPIOB, 8, TIM4, 3, 22); // IPin.SetFreqHz(450); // IPin.Set(11); // Radio.Init(); // Main cycle App.ITask(); }
int main(void) { // ==== Init Vcore & clock system ==== SetupVCore(vcore1V5); Clk.SetupFlashLatency(16); uint8_t ClkRslt = Clk.SwitchToHSI(); if(ClkRslt == OK) Clk.DisableMSI(); Clk.UpdateFreqValues(); // ==== Init OS ==== halInit(); chSysInit(); // ==== Init Hard & Soft ==== Uart.Init(115200); Uart.Printf("\rBmstuCtrl AHB=%u", Clk.AHBFreqHz); if(ClkRslt != OK) Uart.Printf("\rClk switch failure"); // Path init PinSetupOut(PATH_GPIO, PATH21_PIN, omPushPull); PinSetupOut(PATH_GPIO, PATH31_PIN, omPushPull); PinSetupOut(PATH_GPIO, PATH22_PIN, omPushPull); PinSetupOut(PATH_GPIO, PATH32_PIN, omPushPull); // Led init PinSetupOut(LED_GPIO, LED_PIN, omPushPull); // App.Init(); App.PThread = chThdSelf(); // Timers chSysLock(); chVTSetI(&App.TmrUartRx, MS2ST(UART_RX_POLLING_MS), TmrUartRxCallback, nullptr); chSysUnlock(); // Main cycle while(true) App.ITask(); }
// Universal VirtualTimer callback void TmrGeneralCallback(void *p) { chSysLockFromIsr(); App.SignalEvtI((eventmask_t)p); chSysUnlockFromIsr(); }