Exemplo n.º 1
0
/*FUNCTION**********************************************************************
 *
 * Function Name : PIT_DRV_ClearIntFlag
 * Description   : Clears the timer interrupt flag.
 *
 *END**************************************************************************/
void PIT_DRV_ClearIntFlag(uint32_t instance, uint32_t channel)
{
    assert(instance < PIT_INSTANCE_COUNT);

    PIT_Type * base = g_pitBase[instance];

    PIT_HAL_ClearIntFlag(base, channel);
}
Exemplo n.º 2
0
/*
** ===================================================================
**     Interrupt handler : PIT0CH0_IRQHandler
**
**     Description :
**         User interrupt service routine. 
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void PIT0CH0_IRQHandler(void)
{
  /* Clear interrupt flag.*/
  PIT_HAL_ClearIntFlag(g_pitBase[pitTimer1_IDX], pitTimer1_CHANNEL);
  /* Write your code here ... */
  total_time_seconds++;
  sec_tick_byte = true;
}
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
/*!
 * @brief Function ltc_timer_init initialize PIT timer
 * to measure time.
 */
static void ltc_timer_init(void)
{
    SIM_HAL_EnableClock(SIM, kSimClockGatePit0);
    PIT_HAL_Enable(pitBase[0]);
    PIT_HAL_StopTimer(pitBase[0], LTC_TIMER_PIT_CHANNEL);
    PIT_HAL_SetTimerPeriodByCount(pitBase[0], LTC_TIMER_PIT_CHANNEL, RELOAD);
    PIT_HAL_SetIntCmd(pitBase[0], LTC_TIMER_PIT_CHANNEL, false);
    PIT_HAL_SetTimerRunInDebugCmd(pitBase[0], false); /* timer stop counting in debug mode */
    PIT_HAL_ClearIntFlag(pitBase[0], LTC_TIMER_PIT_CHANNEL);
}
Exemplo n.º 5
0
Arquivo: Events.c Projeto: mmittek/EFI
/*
** ===================================================================
**     Interrupt handler : PIT0_IRQHandler
**
**     Description :
**         User interrupt service routine. 
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void PIT0_IRQHandler(void)
{
  /* Clear interrupt flag.*/
  PIT_HAL_ClearIntFlag(g_pitBase[pitTimer1_IDX], pitTimer1_CHANNEL);
  /* Write your code here ... */
	GPIO_DRV_TogglePinOutput( PTE24 );
  ECU_Timer_Event();
//  printf("TRIANGLES APPLES AND ORANGES!\n");

}
Exemplo n.º 6
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);
        }
    }
}
void PIT1_IRQHandler(void)
{   
  static bool led_flag = true;
  /* Clear interrupt flag.*/
  PIT_HAL_ClearIntFlag(PIT_BASE, 1U);
  if(led_flag == true)
  {
    LED3_ON;led_flag=false;
  }
  else
  {
    LED3_OFF;led_flag=true;
  }
  //    pitIsrFlag[1] = true;
}
void PIT0_IRQHandler(void)
{
  static bool led_flag = true;
  /* Clear interrupt flag.*/
  PIT_HAL_ClearIntFlag(PIT_BASE, 0U);

//  I2C_getAccelMangData(&memsRawDate);
//  I2C_getGyroData(&memsRawDate);
// 
//  //     static double jiaodu;
//  if(gyro_offset_done == true)
//  {
//    imu_get_euler_angle(&quadAngle,&memsRawDate);
//    
//    //       jiaodu = atan2(memsRawDate.magn_x,memsRawDate.magn_y) * 57.3;
//    //       PRINTF("jiaodu = %d \r\n" ,(int16_t)jiaodu );
//
//    /*Start*********匿名上位机发送的串口数据***********/
//    packet_upper_PC.user_data.trans_accel[0] = BSWAP_16(memsRawDate.accel_x);
//    packet_upper_PC.user_data.trans_accel[1] = BSWAP_16(memsRawDate.accel_y);
//    packet_upper_PC.user_data.trans_accel[2] = BSWAP_16(memsRawDate.accel_z);
//    packet_upper_PC.user_data.trans_gyro[0]  = BSWAP_16(memsRawDate.gyro_x);
//    packet_upper_PC.user_data.trans_gyro[1]  = BSWAP_16(memsRawDate.gyro_y);
//    packet_upper_PC.user_data.trans_gyro[2]  = BSWAP_16(memsRawDate.gyro_z);
//    packet_upper_PC.user_data.trans_mag[0]  = BSWAP_16(memsRawDate.magn_x);
//    packet_upper_PC.user_data.trans_mag[1]  = BSWAP_16(memsRawDate.magn_y);
//    packet_upper_PC.user_data.trans_mag[2]  = BSWAP_16(memsRawDate.magn_z);     
//    
//    packet_upper_PC.user_data.trans_roll = BSWAP_16((int16_t)(quadAngle.imu_roll*100));
//    packet_upper_PC.user_data.trans_pitch = BSWAP_16((int16_t)(quadAngle.imu_pitch*100));
//    packet_upper_PC.user_data.trans_yaw = BSWAP_16((int16_t)(quadAngle.imu_yaw*10));
//    
//    uint8_t *p = (uint8_t*)&packet_upper_PC;
//    
//  //  UART_HAL_SendDataPolling(BOARD_DEBUG_UART_BASEADDR,p,32);
//    
//    /*End*********匿名上位机发送的串口数据***********/
//  }
  static uint16_t i =0;
  if(i==0)
  {
    LED2_ON;i=1;
  }
  else
  {
    LED2_OFF;i=0;
  }
}
Exemplo n.º 9
0
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief Start pit timer module
 *
 * This function enables the timer and leaves it running, timer is
 * periodically generating interrupts.
 *
 * @param hwtimer[in] Pointer to hwtimer structure.
 *
 * @return kHwtimerSuccess Success.
 *
 * @see HWTIMER_SYS_PitInit
 * @see HWTIMER_SYS_PitDeinit
 * @see HWTIMER_SYS_PitSetDiv
 * @see HWTIMER_SYS_PitStop
 * @see HWTIMER_SYS_PitGet_time
 * @see HWTIMER_SYS_PitIsrAction
 */
static _hwtimer_error_code_t HWTIMER_SYS_PitStart(hwtimer_t * hwtimer)
{
    uint32_t pitChannel;
    PIT_Type * base = g_pitBase[0];
    assert(NULL != hwtimer);

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

    PIT_HAL_StopTimer(base, pitChannel);
    PIT_HAL_ClearIntFlag(base, pitChannel);
    PIT_HAL_SetIntCmd(base, pitChannel, true);
    PIT_HAL_StartTimer(base, pitChannel);

    return kHwtimerSuccess;
}
Exemplo n.º 10
0
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief Stop pit timer module
 *
 * Disable timer and interrupt
 *
 * @param hwtimer[in] Pointer to hwtimer structure.
 *
 * @return kHwtimerSuccess Success.
 *
 * @see HWTIMER_SYS_PitInit
 * @see HWTIMER_SYS_PitDeinit
 * @see HWTIMER_SYS_PitSetDiv
 * @see HWTIMER_SYS_PitStart
 * @see HWTIMER_SYS_PitGetTime
 * @see HWTIMER_SYS_PitIsr
 * @see HWTIMER_SYS_PitIsrShared
 */
static _hwtimer_error_code_t HWTIMER_SYS_PitStop(hwtimer_t * hwtimer)
{
    uint32_t pitChannel;
    uint32_t baseAddr = g_pitBaseAddr[0];
    assert(NULL != hwtimer);

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

    /* Disable timer and interrupt */
    PIT_HAL_StopTimer(baseAddr, pitChannel);
    PIT_HAL_SetIntCmd(baseAddr, pitChannel, false);
    PIT_HAL_ClearIntFlag(baseAddr, pitChannel);

    return kHwtimerSuccess;
}
Exemplo n.º 11
0
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief This function initializes caller allocated structure according to given
 * numerical identifier of the timer.
 *
 * Called by hwtimer_init().
 * Initializes the HWTIMER structure.
 * Sets interrupt priority and registers ISR.
 *
 * @param hwtimer[in]   Returns initialized hwtimer structure handle.
 * @param pitId[in]     Determines PIT module and pit channel.
 * @param isrPrior[in]  Interrupt priority for PIT
 * @param data[in]      Specific data. Not used in this timer.
 *
 * @return kHwtimerSuccess              Success.
 * @return kHwtimerInvalidInput         When channel number does not exist in pit module.
 * @return kHwtimerRegisterHandlerError When registration of the interrupt service routine failed.
 *
 * @see HWTIMER_SYS_PitDeinit
 * @see HWTIMER_SYS_PitSetDiv
 * @see HWTIMER_SYS_PitStart
 * @see HWTIMER_SYS_PitStop
 * @see HWTIMER_SYS_PitGetTime
 * @see HWTIMER_SYS_PitIsr
 * @see HWTIMER_SYS_PitIsrShared
 */
static _hwtimer_error_code_t HWTIMER_SYS_PitInit(hwtimer_t * hwtimer, uint32_t pitId, uint32_t isrPrior, void *data)
{
    uint32_t pitChannel;
    uint32_t baseAddr = g_pitBaseAddr[0];
    if (FSL_FEATURE_PIT_TIMER_COUNT < pitId)
    {
        return kHwtimerInvalidInput;
    }

    assert(NULL != hwtimer);

    /* We need to store pitId of timer in context struct */
    hwtimer->llContext[0U] = pitId;

    pitChannel = hwtimer->llContext[0U];

   /* Un-gate pit clock */
    CLOCK_SYS_EnablePitClock(0U);

    /* Enable PIT module clock */
    PIT_HAL_Enable(baseAddr);

    /* Allows the timers to be stopped when the device enters the Debug mode. */
    PIT_HAL_SetTimerRunInDebugCmd(baseAddr, false);

    /* Disable timer and interrupt */
    PIT_HAL_StopTimer(baseAddr, pitChannel);
    PIT_HAL_SetIntCmd(baseAddr, pitChannel, false);
    /* Clear any pending interrupt */
    PIT_HAL_ClearIntFlag(baseAddr, pitChannel);

    /* Store hwtimer in global array */
    g_hwtimersPit[pitChannel] = hwtimer;

    /* Enable PIT interrupt.*/
    if (kStatus_OSA_Success != OSA_InstallIntHandler(g_pitIrqId[pitChannel], HWTIMER_SYS_PitIsr))
    {
        return kHwtimerRegisterHandlerError;
    }

    PIT_HAL_SetIntCmd(baseAddr, pitChannel, true);
    INT_SYS_EnableIRQ(g_pitIrqId[pitChannel]);

    return kHwtimerSuccess;
}
Exemplo n.º 12
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.º 13
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.º 14
0
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief Initialization of pit timer module
 *
 * Called by hwtimer_deinit. Disables the peripheral. Unregisters ISR.
 *
 * @param hwtimer[in] Pointer to hwtimer structure.
 *
 * @return kHwtimerSuccess              Success.
 * @return kHwtimerRegisterHandlerError When un-registration of the interrupt service routine failed.
 *
 * @see HWTIMER_SYS_PitInit
 * @see HWTIMER_SYS_PitSetDiv
 * @see HWTIMER_SYS_PitStart
 * @see HWTIMER_SYS_PitStop
 * @see HWTIMER_SYS_PitGetTime
 * @see HWTIMER_SYS_PitIsr
 * @see HWTIMER_SYS_PitIsrShared
 */
static _hwtimer_error_code_t HWTIMER_SYS_PitDeinit(hwtimer_t * hwtimer)
{
    /* We belive that if isr is shared ,than is shared for every chanells */
    uint32_t baseAddr = g_pitBaseAddr[0];
    uint32_t pitChannel;
    int i;

    assert(NULL != hwtimer);

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

    /* Remove Hwtimer from global array and disable interrupt on this channel */
    PIT_HAL_StopTimer(baseAddr, pitChannel);
    PIT_HAL_SetIntCmd(baseAddr, pitChannel, false);
    PIT_HAL_ClearIntFlag(baseAddr, pitChannel);

    /* Pit can have shared interrupt vectors. We need un-register interrupt only when all hwtimers are de-inited(set to NULL) */
    g_hwtimersPit[pitChannel] = NULL;

    /* Check if this is last hwtimer in pit_hwtimers_array */
    for (i = 0U; i < FSL_FEATURE_PIT_TIMER_COUNT; i++)
    {
        if (NULL != g_hwtimersPit[i])
        {
            break;
        }
    }

    if (i == FSL_FEATURE_PIT_TIMER_COUNT)
    {
        if(kStatus_OSA_Success != OSA_InstallIntHandler(g_pitIrqId[pitChannel], NULL))
        {
            return kHwtimerRegisterHandlerError;
        }
    }

    return kHwtimerSuccess;
}
Exemplo n.º 15
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);
                }
            }
        }
    }
}
Exemplo n.º 16
0
void PIT3_IRQHandler(void)
{
    /* Clear interrupt flag.*/
    PIT_HAL_ClearIntFlag(g_pitBase[0], 3U);
}
Exemplo n.º 17
0
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief This function initializes caller allocated structure according to given
 * numerical identifier of the timer.
 *
 * Called by hwtimer_init().
 * Initializes the HWTIMER structure.
 * Sets interrupt priority and registers ISR.
 *
 * @param hwtimer[in]   Returns initialized hwtimer structure handle.
 * @param pitId[in]     Determines PIT module and pit channel.
 * @param isrPrior[in]  Interrupt priority for PIT
 * @param data[in]      Specific data. Not used in this timer.
 *
 * @return kHwtimerSuccess              Success.
 * @return kHwtimerInvalidInput         When channel number does not exist in pit module.
 * @return kHwtimerLockError            When Locking failed.
 * @return kHwtimerRegisterHandlerError When registration of the interrupt service routine failed.
 *
 * @see HWTIMER_SYS_PitDeinit
 * @see HWTIMER_SYS_PitSetDiv
 * @see HWTIMER_SYS_PitStart
 * @see HWTIMER_SYS_PitStop
 * @see HWTIMER_SYS_PitGetTime
 * @see HWTIMER_SYS_PitIsr
 * @see HWTIMER_SYS_PitIsrShared
 */
static _hwtimer_error_code_t HWTIMER_SYS_PitInit(hwtimer_t * hwtimer, uint32_t pitId, uint32_t isrPrior, void *data)
{
    uint32_t pitChannel;
    uint32_t baseAddr = g_pitBaseAddr[0];
    if (FSL_FEATURE_PIT_TIMER_COUNT < pitId)
    {
        return kHwtimerInvalidInput;
    }

    assert(NULL != hwtimer);

    /* We need to store pitId of timer in context struct */
    hwtimer->llContext[0U] = pitId;

    pitChannel = hwtimer->llContext[0U];

   /* Un-gate pit clock */
    CLOCK_SYS_EnablePitClock(0U);

    /* Enable PIT module clock */
    PIT_HAL_Enable(baseAddr);

    /* Allows the timers to be stopped when the device enters the Debug mode. */
    PIT_HAL_SetTimerRunInDebugCmd(baseAddr, false);

    /* Disable timer and interrupt */
    PIT_HAL_StopTimer(baseAddr, pitChannel);
    PIT_HAL_SetIntCmd(baseAddr, pitChannel, false);
    /* Clear any pending interrupt */
    PIT_HAL_ClearIntFlag(baseAddr, pitChannel);

    /* Create lock if does not exists*/
    /* Enter critical section to avoid interrupt create locking */
    OSA_EnterCritical(kCriticalDisableInt);
    if (g_lock == NULL)
    {
        /* Initialize synchronization object */
        if (kStatus_OSA_Success != OSA_MutexCreate(&g_lock_data))
        {
            return kHwtimerLockError;
        }
        g_lock = &g_lock_data;
    }
    OSA_ExitCritical(kCriticalDisableInt);
    assert(g_lock == &g_lock_data);

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(g_lock, OSA_WAIT_FOREVER))
    {
        return kHwtimerLockError;
    }
    /* Store hwtimer in global array */
    g_hwtimersPit[pitChannel] = hwtimer;

    if (kStatus_OSA_Success != OSA_MutexUnlock(g_lock))
    {
        return kHwtimerLockError;
    }

    /* Enable PIT interrupt.*/
    if (kStatus_OSA_Success != OSA_InstallIntHandler(kpitIrqIds[pitChannel], HWTIMER_SYS_PitIsr))
    {
        return kHwtimerRegisterHandlerError;
    }

    PIT_HAL_SetIntCmd(baseAddr, pitChannel, true);
    INT_SYS_EnableIRQ(kpitIrqIds[pitChannel]);

    return kHwtimerSuccess;
}