clock_manager_error_code_t CLOCK_SYS_GetFreq(clock_names_t clockName,
                                                 uint32_t *frequency)
{
    clock_manager_error_code_t returnCode = kClockManagerSuccess;

    switch (clockName)
    {
        case kCoreClock:
        case kSystemClock:
            *frequency = CLOCK_SYS_GetCoreClockFreq();
            break;
        case kPlatformClock:
            *frequency = CLOCK_SYS_GetSystemClockFreq();
            break;
        case kBusClock:
            *frequency = CLOCK_SYS_GetBusClockFreq();
            break;
        case kFlexBusClock:
            *frequency = CLOCK_SYS_GetFlexbusFreq();
            break;
        case kFlashClock:
            *frequency = CLOCK_SYS_GetFlashClockFreq();
            break;
        case kOsc32kClock:
            *frequency = CLOCK_SYS_GetExternalRefClock32kFreq();
            break;
        case kOsc0ErClock:
            *frequency = CLOCK_SYS_GetOsc0ExternalRefClockFreq();
            break;
        case kRtcoutClock:
            *frequency = CLOCK_SYS_GetRtcOutFreq();
            break;
        case kMcgFfClock:
            *frequency = CLOCK_SYS_GetFixedFreqClockFreq();
            break;
        case kMcgFllClock:
            *frequency = CLOCK_HAL_GetFllClk(MCG_BASE);
            break;
        case kMcgPll0Clock:
            *frequency = CLOCK_HAL_GetPll0Clk(MCG_BASE);
            break;
        case kMcgOutClock:
            *frequency = CLOCK_HAL_GetOutClk(MCG_BASE);
            break;
        case kMcgIrClock:
            *frequency = CLOCK_HAL_GetInternalRefClk(MCG_BASE);
            break;
        case kLpoClock:
            *frequency = CLOCK_SYS_GetLpoClockFreq();
            break;
        default:
            *frequency = 0U;
            returnCode = kClockManagerNoSuchClockName;
            break;
    }

    return returnCode;
}
Ejemplo n.º 2
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_GetFlexcanFreq
 * Description   : Gets FLEXCAN clock frequency.
 * This function gets the FLEXCAN clock frequency.
 *
 *END**************************************************************************/
uint32_t CLOCK_SYS_GetFlexcanFreq(uint32_t instance, clock_flexcan_src_t flexcanSrc)
{
    if (kClockFlexcanSrcOsc0erClk == flexcanSrc)
    {
        return CLOCK_SYS_GetOsc0ExternalRefClockFreq();
    }
    else
    { 
        return CLOCK_SYS_GetSystemClockFreq();
    }
}
Ejemplo n.º 3
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_GetSpiFreq
 * Description   : Gets the clock frequency for SPI.
 *
 *END**************************************************************************/
uint32_t CLOCK_SYS_GetSpiFreq(uint32_t instance)
{
    assert(instance < SPI_INSTANCE_COUNT);

    if (0U == instance)
    {
        return CLOCK_SYS_GetBusClockFreq();
    }
    else
    {
        return CLOCK_SYS_GetSystemClockFreq();
    }
}
Ejemplo n.º 4
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_GetUartFreq
 * Description   : Gets the clock frequency for UART module.
 * This function gets the clock frequency for UART module.
 *
 *END**************************************************************************/
uint32_t CLOCK_SYS_GetUartFreq(uint32_t instance)
{
    uint32_t freq;

    switch (instance)
    {
        case 0:
        case 1:
            freq = CLOCK_SYS_GetSystemClockFreq();
            break;
        default:
            freq = 0U;
            break;
    }

    return freq;
}
Ejemplo n.º 5
0
/*FUNCTION**********************************************************************
 *
 * Function Name : CLOCK_SYS_GetFlashClockFreq
 * Description   : Gets the flash clock frequency.
 * This function gets the flash clock frequency.
 *
 *END**************************************************************************/
uint32_t CLOCK_SYS_GetFlashClockFreq(void)
{
    return CLOCK_SYS_GetSystemClockFreq() / (CLOCK_HAL_GetOutDiv4(SIM) + 1);
}
Ejemplo n.º 6
0
/*FUNCTION**********************************************************************
 * Function Name : POWER_SYS_CheckClocks
 * Description   :Internal function used by POWER_SYS_SetMode function
 *END**************************************************************************/
static power_manager_error_code_t POWER_SYS_CheckClocks(power_manager_modes_t mode)
{   
#if POWER_VLPR_MCG_LITE  
    mcglite_mode_t mcgMode = CLOCK_HAL_GetMode(MCG);
#else
    mcg_modes_t mcgMode = CLOCK_HAL_GetMcgMode(MCG);
   
    /* Check clock monitors */
    switch(mode)
    {
#if FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
    case kPowerManagerHsrun:
#endif      
    case kPowerManagerRun:
    case kPowerManagerWait:
        /* Clock monitors can be enabled */
        break;
    default:
        /* For other modes clock monitors should be disabled */
#if FSL_FEATURE_MCG_HAS_EXTERNAL_CLOCK_MONITOR
        if( CLOCK_HAL_IsOsc0MonitorEnabled(MCG) )
        {
            return kPowerManagerErrorClock;
        }    
#endif        
#if FSL_FEATURE_MCG_HAS_RTC_32K
        if( CLOCK_HAL_IsRtcOscMonitorEnabled(MCG) )
        {
            return kPowerManagerErrorClock;
        }    
#endif
#if FSL_FEATURE_MCG_USE_PLLREFSEL        
        if( CLOCK_HAL_IsOsc1MonitorEnabled(MCG) )
        {
            return kPowerManagerErrorClock;
        }
#endif        
        break;
    }
#endif
    
    /* We need check clocks if goes into VLPR or VLPW over VLPR */
    if( (mode!=kPowerManagerVlpr) && (mode!=kPowerManagerVlpw) )
    {
        return kPowerManagerSuccess;
    }
    
#if POWER_VLPR_MCG_LITE 
    switch(mcgMode)
    {
    case kMcgliteModeLirc8M:
    case kMcgliteModeLirc2M:
    case kMcgliteModeExt:
        /* allowed modes */
        break;
    default:
        return kPowerManagerErrorClock;
    }
    
    if(CLOCK_SYS_GetFlashClockFreq() > POWER_VLPR_MAX_FLASH_BLPE_CLK)
    {
        return kPowerManagerErrorClock;
    }
#else
    switch(mcgMode)
    {
    case kMcgModeBLPI:
        /* fast IRC must be selected */
        if(CLOCK_HAL_GetInternalRefClkMode(MCG) != kMcgIrcFast)
        {
            return kPowerManagerErrorClock;
        }
        if(CLOCK_SYS_GetFlashClockFreq() > POWER_VLPR_MAX_FLASH_BLPI_CLK)
        {
            return kPowerManagerErrorClock;
        }
        break;
    case kMcgModeBLPE:
        if(CLOCK_SYS_GetFlashClockFreq() > POWER_VLPR_MAX_FLASH_BLPE_CLK)
        {
            return kPowerManagerErrorClock;
        }
        break;
    default:
        return kPowerManagerErrorClock;
    }  
#endif
    if(CLOCK_SYS_GetCoreClockFreq() > POWER_VLPR_MAX_CLK)
    {
        return kPowerManagerErrorClock;
    }
    
    if(CLOCK_SYS_GetBusClockFreq() > POWER_VLPR_MAX_CLK)
    {
        return kPowerManagerErrorClock;
    }
    
    if(CLOCK_SYS_GetSystemClockFreq() > POWER_VLPR_MAX_CLK)
    {
        return kPowerManagerErrorClock;
    }
    
    return kPowerManagerSuccess;
}
Ejemplo n.º 7
0
void HEXIWEAR_startup( task_param_t param )
{
    uint8_t
    status = 0;

    /** output GPIO config */

    GPIO_DRV_Init( NULL, OLED_cfg );
    GPIO_DRV_Init( NULL, FLASH_cfg );
    GPIO_DRV_Init( NULL, PWR_cfg );
    GPIO_DRV_Init( NULL, VIBRO_cfg );
    GPIO_DRV_Init( NULL, RGB_cfg );
    GPIO_DRV_Init( NULL, KW40_GPIO_cfg );
    GPIO_DRV_Init( NULL, REL_GPIO_cfg );


    /** input GPIO config */

    GPIO_DRV_Init( BAT_CHG_cfg, NULL );
    GPIO_DRV_Init( TAP_cfg, NULL );

    // lajkatest
    // GPIO_DRV_Init( GPIO_TEST_CFG, NULL );

#if defined( HEXIWEAR_DEBUG )
    GPIO_DRV_Init( NULL, DEBUG_cfg );
#endif

    power_ResetKW40();
    timer_Init( HEXIWEAR_TIMER_SENSOR );

    status |= RTC_Init();
    status |= FLASH_Init( &flashModule, &flashSettings );

    // intern flash initialization
    INTFLASH_Init();

    // enable power save by default
    // power_EnablePowerSave();
    power_DisablePowerSave();

    // set to deep sleep by default
    // power_SetSleepMode( POWER_SLEEP_TYPE_DEEP );

    // RGB off
    FLASH_SetOFF();

    // visual indication for testing HR sensor
//  MAXIM_Test();

    /** create basic tasks */
    status |= Notification_Init();
    status |= HostInterface_Init();
    status |= sensor_Init();
    status |= power_Init();
    status |= GuiDriver_Init();

    haptic_MutexCreate();

    sensor_InitAcc();

    /** set GPIO interrupt for the tap function */
    PORT_HAL_SetPinIntMode( PORTC, 1, kPortIntFallingEdge );

    /** set charging battery interrupt */
    PORT_HAL_SetPinIntMode( PORTC, 12, kPortIntEitherEdge );
    NVIC_SetPriority( PORTC_IRQn, HEXIWEAR_CHG_IRQ_PRIO );
    INT_SYS_EnableIRQ( PORTC_IRQn );

    // status |= Run_USB_Task();

    if ( HEXIWEAR_STATUS_SUCCESS != status )
    {
        catch( CATCH_INIT );
    }

    /** check for settings in flash at startup */
    gui_sensorTag_CheckAtStartup();
    haptic_CheckAtStartup();

    CLOCK_SYS_Init( g_clockManConfigsArr, FSL_CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, FSL_CLOCK_MANAGER_CALLBACK_CNT );
    POWER_SYS_Init( powerConfigsArr, 2U, powerStaticCallbacksConfigsArr , 2U );

    // make battery readings regular
    sensor_SetPacketTargets( PACKET_BAT, sensor_GetPacketTargets( PACKET_BAT) | PACKET_PUSH_POWER_MGMT, true );

    volatile uint32_t
    foo = CLOCK_SYS_GetSystemClockFreq();

    while (1)
    {
        OSA_TaskDestroy( NULL );
    }
}