コード例 #1
0
ファイル: adc16_temperature.c プロジェクト: cjc1029nice/ksdk
/*!
 * @Brief enable the trigger source
 *
 * @param instance The ADC instance number
 */
void adc16InitPitTriggerSource(uint32_t adcInstance)
{
    /* Change the timer period here in unit of microseconds.*/
    uint32_t timerPeriod = 500;
    uint32_t pitInstance = BOARD_PIT_INSTANCE;
    uint32_t pitChannel = 0;

    if(sPdbInitialized)
    {
        return;
    }
    sPdbInitialized = 1;

    pitUserConf.isInterruptEnabled = false;
    pitUserConf.periodUs = timerPeriod;

    /* Init pit module and enable run in debug */
    PIT_DRV_Init(pitInstance, false);

    /* Initialize PIT timer 0 */
    PIT_DRV_InitChannel(pitInstance, pitChannel, &pitUserConf);

    /* Set timer0 period and start it.*/
    PIT_DRV_SetTimerPeriodByUs(pitInstance, pitChannel, timerPeriod * 1000);

    // Configure SIM for ADC hw trigger source PIT
    SIM_HAL_SetAdcAlternativeTriggerCmd(gSimBase[0], adcInstance, true);

    SIM_HAL_SetAdcTriggerMode(gSimBase[0], adcInstance, kSimAdcTrgSelPit0);

    PIT_DRV_StartTimer(pitInstance, pitChannel);
}
コード例 #2
0
ファイル: lptmr_trigger.c プロジェクト: cjc1029nice/ksdk
/*!
 * @Brief enable the trigger source of LPTimer
 */
void init_trigger_source(uint32_t adcInstance)
{
    uint32_t freqUs;

    lptmr_user_config_t lptmrUserConfig =
    {
        .timerMode = kLptmrTimerModeTimeCounter,
        .freeRunningEnable = false,
        .prescalerEnable = false, // bypass perscaler
#if (CLOCK_INIT_CONFIG == CLOCK_VLPR)
        // use MCGIRCCLK, 4M or 32KHz
        .prescalerClockSource = kClockLptmrSrcMcgIrClk,
#else
        // Use LPO clock 1KHz
        .prescalerClockSource = kClockLptmrSrcLpoClk,
#endif
        .isInterruptEnabled = false
    };

    // Init LPTimer driver
    LPTMR_DRV_Init(0, &gLPTMRState, &lptmrUserConfig);

    // Set the LPTimer period
    freqUs = 1000000U/(INPUT_SIGNAL_FREQ*NR_SAMPLES)*2;
    LPTMR_DRV_SetTimerPeriodUs(0, freqUs);

    // Start the LPTimer
    LPTMR_DRV_Start(0);

    // Configure SIM for ADC hw trigger source selection
#if defined(KM34Z7_SERIES)
    SIM_HAL_EnableClock(gSimBase[0], kSimClockGateXbar0);
    SIM_HAL_SetAdcTrgSelMode(gSimBase[0], kSimAdcTrgSelXbar);
    XBAR_DRV_ConfigSignalConnection(kXbaraInputLPTMR0_Output, kXbaraOutputADC_TRGA);
#else
    SIM_HAL_SetAdcAlternativeTriggerCmd(gSimBase[0], adcInstance, true);
    SIM_HAL_SetAdcPreTriggerMode(gSimBase[0], adcInstance, kSimAdcPretrgselA);
    SIM_HAL_SetAdcTriggerMode(gSimBase[0], adcInstance, kSimAdcTrgSelLptimer);
#endif
}

/*!
 * @Brief disable the trigger source
 */
void deinit_trigger_source(uint32_t adcInstance)
{
    LPTMR_DRV_Stop(0);
    LPTMR_DRV_Deinit(0);
}
コード例 #3
0
/*!
 * @Brief enable the trigger source of LPTimer
 */
void init_trigger_source(uint32_t adcInstance)
{
    uint32_t freqUs;
    
    lptmr_user_config_t lptmrUserConfig =
    {
        .timerMode = kLptmrTimerModeTimeCounter,
        .freeRunningEnable = false,
        .prescalerEnable = false, // bypass perscaler
        .prescalerClockSource = kClockLptmrSrcMcgIrClk, // use MCGIRCCLK, 4M or 32KHz
        .isInterruptEnabled = false
    };
    
    // Init LPTimer driver
    LPTMR_DRV_Init(0, &lptmrUserConfig, &gLPTMRState);

    // Set the LPTimer period
    freqUs = 1000000U/(INPUT_SIGNAL_FREQ*NR_SAMPLES)*2;
    LPTMR_DRV_SetTimerPeriodUs(0, freqUs);

    // Start the LPTimer
    LPTMR_DRV_Start(0);

    // Configure SIM for ADC hw trigger source selection
    SIM_HAL_SetAdcAlternativeTriggerCmd(gSimBase[0], adcInstance, true);
    SIM_HAL_SetAdcPreTriggerMode(gSimBase[0], adcInstance, kSimAdcPretrgselA);
    SIM_HAL_SetAdcTriggerMode(gSimBase[0], adcInstance, kSimAdcTrgSelLptimer);
}

/*!
 * @Brief disable the trigger source
 */
void deinit_trigger_source(uint32_t adcInstance)
{
    LPTMR_DRV_Stop(0);
    LPTMR_DRV_Deinit(0);
}