Exemplo n.º 1
0
Arquivo: main.cpp Projeto: Kreyl/nute
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();
}