Ejemplo n.º 1
0
void TPM_LED_HANDLER(void)
{
    tpmIsrFlag = true;

    if (brightnessUp)
    {
        /* Increase duty cycle until it reach limited value, don't want to go upto 100% duty cycle
         * as channel interrupt will not be set for 100%
         */
        if (++updatedDutycycle >= 99U)
        {
            updatedDutycycle = 99U;
            brightnessUp = false;
        }
    }
    else
    {
        /* Decrease duty cycle until it reach limited value */
        if (--updatedDutycycle == 1U)
        {
            brightnessUp = true;
        }
    }

    /* Clear interrupt flag.*/
    TPM_ClearStatusFlags(BOARD_TPM_BASEADDR, TPM_CHANNEL_FLAG);
}
Ejemplo n.º 2
0
void us_ticker_set_interrupt(timestamp_t timestamp)
{
    /* We get here absolute interrupt time which takes into account counter overflow.
     * Since we use additional count-down timer to generate interrupt we need to calculate
     * load value based on time-stamp.
     */
    const uint32_t now_ticks = us_ticker_read();
    uint32_t delta_ticks =
            timestamp >= now_ticks ? timestamp - now_ticks : (uint32_t)((uint64_t) timestamp + 0xFFFFFFFF - now_ticks);

    if (delta_ticks == 0) {
        /* The requested delay is less than the minimum resolution of this counter. */
        delta_ticks = 1;
    }

    us_ticker_int_counter   = (uint32_t)(delta_ticks >> 16);
    us_ticker_int_remainder = (uint16_t)(0xFFFF & delta_ticks);

    TPM_StopTimer(TPM2);
    TPM2->CNT = 0;

    if (us_ticker_int_counter > 0) {
        TPM2->MOD = 0xFFFF;
        us_ticker_int_counter--;
    } else {
        TPM2->MOD = us_ticker_int_remainder;
        us_ticker_int_remainder = 0;
    }

    /* Clear the count and set match value */
    TPM_ClearStatusFlags(TPM2, kTPM_TimeOverflowFlag);
    TPM_EnableInterrupts(TPM2, kTPM_TimeOverflowInterruptEnable);
    TPM_StartTimer(TPM2, kTPM_SystemClock);
}
Ejemplo n.º 3
0
void StackTimer_ClearIntFlag(void)
{
#if FSL_FEATURE_SOC_FTM_COUNT
    uint32_t status = FTM_GetStatusFlags(mFtmBase[gStackTimerInstance_c]);
    FTM_ClearStatusFlags(mFtmBase[gStackTimerInstance_c], status);
#else
    uint32_t status = TPM_GetStatusFlags(mTpmBase[gStackTimerInstance_c]);
    TPM_ClearStatusFlags(mTpmBase[gStackTimerInstance_c], status);
#endif
}
Ejemplo n.º 4
0
static void tpm_isr(void)
{
    // Clear the TPM timer overflow flag
    TPM_ClearStatusFlags(TPM2, kTPM_TimeOverflowFlag);
    TPM_StopTimer(TPM2);

    if (us_ticker_int_counter > 0) {
        TPM2->MOD = 0xFFFF;
        TPM_StartTimer(TPM2, kTPM_SystemClock);
        us_ticker_int_counter--;
    } else {
        if (us_ticker_int_remainder > 0) {
            TPM2->MOD = us_ticker_int_remainder;
            TPM_StartTimer(TPM2, kTPM_SystemClock);
            us_ticker_int_remainder = 0;
        } else {
            // This function is going to disable the interrupts if there are
            // no other events in the queue
            us_ticker_irq_handler();
        }
    }
}
Ejemplo n.º 5
0
void us_ticker_clear_interrupt(void)
{
    TPM_ClearStatusFlags(TPM2, kTPM_TimeOverflowFlag);
}