Exemplo n.º 1
0
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief Atomically captures current time into HWTIMER_TIME_STRUCT structure
 *
 * Corrects/normalizes the values if necessary (interrupt pending, etc.)
 *
 * @param hwtimer[in] Pointer to hwtimer structure.
 * @param time[out]   Pointer to time structure. This value is filled with current value of the timer.
 *
 * @return kHwtimerSuccess Success.
 *
 * @see HWTIMER_SYS_PitInit
 * @see HWTIMER_SYS_PitDeinit
 * @see HWTIMER_SYS_PitSetDiv
 * @see HWTIMER_SYS_PitStart
 * @see HWTIMER_SYS_PitStop
 * @see HWTIMER_SYS_PitIsr
 * @see HWTIMER_SYS_PitIsrShared
 */
static _hwtimer_error_code_t HWTIMER_SYS_PitGetTime(hwtimer_t *hwtimer, hwtimer_time_t *time)
{
    uint32_t    pitChannel;
    uint32_t    tempCval;
    uint32_t baseAddr = g_pitBaseAddr[0];
    assert(NULL != hwtimer);
    assert(NULL != time);

    pitChannel = hwtimer->llContext[0U];
    assert(pitChannel < FSL_FEATURE_PIT_TIMER_COUNT);

    /* Enter critical section to avoid disabling interrupt from pit for very long time */
    OSA_EnterCritical(kCriticalDisableInt);
    PIT_HAL_SetIntCmd(baseAddr, pitChannel, false);

    time->ticks = hwtimer->ticks;

    tempCval = PIT_HAL_ReadTimerCount(baseAddr, pitChannel);
    /* Check pending interrupt flag */
   if (PIT_HAL_IsIntPending(baseAddr, pitChannel))
    {
        PIT_HAL_SetIntCmd(baseAddr, pitChannel, true);
        OSA_ExitCritical(kCriticalDisableInt);
        time->subTicks = hwtimer->modulo - 1U;
    }
    else
    {
        PIT_HAL_SetIntCmd(baseAddr, pitChannel, true);
        OSA_ExitCritical(kCriticalDisableInt);
        /* todo: following line should be updated when HAL will be updated with this functionality. */
        time->subTicks = HW_PIT_LDVALn_RD(baseAddr, pitChannel) - tempCval;
    }

    return kHwtimerSuccess;
}
Exemplo n.º 2
0
/*FUNCTION**********************************************************************
 *
 * Function Name : PIT_DRV_IsIntPending
 * Description   : Reads the current timer timeout flag.
 *
 *END**************************************************************************/
bool PIT_DRV_IsIntPending(uint32_t instance, uint32_t channel)
{
    assert(instance < PIT_INSTANCE_COUNT);

    PIT_Type * base = g_pitBase[instance];

    return PIT_HAL_IsIntPending(base, channel);
}
Exemplo n.º 3
0
void PIT_IRQHandler(void)
{
    if (PIT_HAL_IsIntPending(g_pitBase[0], 0))
    {
        PIT_HAL_ClearIntFlag(g_pitBase[0], 0);
        param.uFrequencyHZ = notes[beeps[position]];
        position = (position + 1) % sizeof(beeps);
        if (param.uFrequencyHZ)
            TPM_DRV_PwmStart(0, &param, 3);
        else
            TPM_DRV_PwmStop(0, &param, 3);
    }
    if (PIT_HAL_IsIntPending(g_pitBase[0], 1))
    {
        PIT_HAL_ClearIntFlag(g_pitBase[0], 1);
    }
}
Exemplo n.º 4
0
void PIT_IRQHandler(void)
{
    uint32_t i;
    for(i=0; i < FSL_FEATURE_PIT_TIMER_COUNT; i++)
    {
        if (PIT_HAL_IsIntPending(g_pitBase[0], i))
        {
            /* Clear interrupt flag.*/
            PIT_HAL_ClearIntFlag(g_pitBase[0], i);
        }
    }
}
Exemplo n.º 5
0
void PIT0_PIT1_IRQHandler(void)
{
    uint32_t i;
    for(i=0; i < PIT_INSTANCE_COUNT; i++)
    {
        if (CLOCK_SYS_GetPitGateCmd(i))
        {
            for(i=0; i < FSL_FEATURE_PIT_TIMER_COUNT; i++)
            {
                if (PIT_HAL_IsIntPending(g_pitBase[0], i))
                {
                    /* Clear interrupt flag.*/
                    PIT_HAL_ClearIntFlag(g_pitBase[0], i);
                }
            }
        }
    }
}
Exemplo n.º 6
0
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief Interrupt service routine.
 *
 * Checks whether callback_func is not NULL,
 * and unless callback is blocked by callback_blocked being non-zero it calls the callback function with callback_data as parameter,
 * otherwise callback_pending is set to non-zero value.
 *
 * @return void
 *
 * @see HWTIMER_SYS_Pitdeinit
 * @see HWTIMER_SYS_PitsetDiv
 * @see HWTIMER_SYS_Pitstart
 * @see HWTIMER_SYS_Pitstop
 * @see HWTIMER_SYS_PitgetTime
 * @see HWTIMER_SYS_PitisrShared
 */
static void HWTIMER_SYS_PitIsr(void)
{
    uint32_t baseAddr = g_pitBaseAddr[0];
    int i;
    for (i = 0U; i < FSL_FEATURE_PIT_TIMER_COUNT; i++)
    {
        hwtimer_t *hwtimer =  g_hwtimersPit[i];
        /* If hwtimer exist*/
        if (NULL != hwtimer)
        {
            uint32_t pitChannel =  hwtimer->llContext[0U];
            assert(pitChannel < FSL_FEATURE_PIT_TIMER_COUNT);

            /* Check if interrupt is enabled for this channel. Cancel spurious interrupt */
            if (!(BR_PIT_TCTRLn_TIE(baseAddr, pitChannel)))
            {
                continue;
            }

            /* If interrupt occurred for this pit and channel*/
            if(PIT_HAL_IsIntPending(baseAddr, pitChannel))
            {
                /* Clear interrupt flag */
                PIT_HAL_ClearIntFlag(baseAddr, pitChannel);
                /* Following part of function is typically the same for all low level hwtimer drivers */
                hwtimer->ticks++;

                if (NULL != hwtimer->callbackFunc)
                {
                    if (hwtimer->callbackBlocked)
                    {
                        hwtimer->callbackPending = 1U;
                    }
                    else
                    {
                        /* Run user function*/
                        hwtimer->callbackFunc(hwtimer->callbackData);
                    }
                }
            }
        }
    }
}
Exemplo n.º 7
0
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief Called from the Interrupt service routine.
 *
 * Checks whether callback_func is not NULL,
 * and unless callback is blocked by callback_blocked being non-zero it calls the callback function with callback_data as parameter,
 * otherwise callback_pending is set to non-zero value.
 *
 * @return void
 *
 * @see HWTIMER_SYS_Pitdeinit
 * @see HWTIMER_SYS_PitsetDiv
 * @see HWTIMER_SYS_Pitstart
 * @see HWTIMER_SYS_Pitstop
 * @see HWTIMER_SYS_PitgetTime
 */
void HWTIMER_SYS_PitIsrAction(uint8_t pitChannel)
{
    PIT_Type * base = g_pitBase[0];
    hwtimer_t *hwtimer =  g_hwtimersPit[pitChannel];

    /* If hwtimer exist*/
    if (NULL != hwtimer)
    {
        /* Check if interrupt is enabled for this channel. Cancel spurious interrupt */
        if (!(PIT_BRD_TCTRL_TIE(base, pitChannel)))
        {
            return;
        }

        /* If interrupt occurred for this pit and channel*/
        if(PIT_HAL_IsIntPending(base, pitChannel))
        {
            /* Clear interrupt flag */
            PIT_HAL_ClearIntFlag(base, pitChannel);
            /* Following part of function is typically the same for all low level hwtimer drivers */
            hwtimer->ticks++;

            if (NULL != hwtimer->callbackFunc)
            {
                if (hwtimer->callbackBlocked)
                {
                    hwtimer->callbackPending = 1U;
                }
                else
                {
                    /* Run user function*/
                    hwtimer->callbackFunc(hwtimer->callbackData);
                }
            }
        }
    }
}