Example #1
0
static void rt1052_hwtimer_init(rt_hwtimer_t *timer, rt_uint32_t state)
{
    GPT_Type *hwtimer_dev;
    gpt_config_t gptConfig;
    hwtimer_dev = (GPT_Type *)timer->parent.user_data;

    RT_ASSERT(timer != RT_NULL);

    GPT_Deinit(hwtimer_dev);

    if (state == 1)
    {
        /*Clock setting for GPT*/
        CLOCK_SetMux(kCLOCK_PerclkMux, EXAMPLE_GPT_CLOCK_SOURCE_SELECT);
        CLOCK_SetDiv(kCLOCK_PerclkDiv, EXAMPLE_GPT_CLOCK_DIVIDER_SELECT);

        /* Initialize GPT module by default config */
        GPT_GetDefaultConfig(&gptConfig);
        GPT_Init(hwtimer_dev, &gptConfig);
    }
}
Example #2
0
/** Initialize the low power ticker
 *
 */
void lp_ticker_init(void)
{
    gpt_config_t gptConfig;

    if (!lp_ticker_inited) {
        /* Setup GPT */
        GPT_GetDefaultConfig(&gptConfig);
        /* Use 32kHz drive */
        gptConfig.clockSource = kGPT_ClockSource_LowFreq;
        gptConfig.enableFreeRun = true;
        gptConfig.enableMode = false;

        GPT_Init(GPT2, &gptConfig);
        GPT_EnableInterrupts(GPT2, kGPT_OutputCompare1InterruptEnable);
        NVIC_ClearPendingIRQ(GPT2_IRQn);
        NVIC_SetVector(GPT2_IRQn, (uint32_t)gpt_isr);
        EnableIRQ(GPT2_IRQn);
        GPT_StartTimer(GPT2);
        lp_ticker_inited = true;
    } else {
        GPT_DisableInterrupts(GPT2, kGPT_OutputCompare1InterruptEnable);
    }
}