示例#1
0
/*******************************************************************************
* Function Name: Timer_2_RestoreConfig
********************************************************************************
*
* Summary:
*  Restores the current user configuration.
*
* Parameters:
*  void
*
* Return:
*  void
*
* Global variables:
*  Timer_2_backup:  Variables of this global structure are used to
*  restore the values of non retention registers on wakeup from sleep mode.
*
*******************************************************************************/
void Timer_2_RestoreConfig(void) 
{   
    #if (!Timer_2_UsingFixedFunction)
        /* Restore the UDB non-rentention registers for PSoC5A */
        #if (CY_PSOC5A)
            /* Interrupt State Backup for Critical Region*/
            uint8 Timer_2_interruptState;

            Timer_2_WriteCounter(Timer_2_backup.TimerUdb);
            Timer_2_WritePeriod(Timer_2_backup.TimerPeriod);
            /* CyEnterCriticalRegion and CyExitCriticalRegion are used to mark following region critical*/
            /* Enter Critical Region*/
            Timer_2_interruptState = CyEnterCriticalSection();
            /* Use the interrupt output of the status register for IRQ output */
            Timer_2_STATUS_AUX_CTRL |= Timer_2_STATUS_ACTL_INT_EN_MASK;
            /* Exit Critical Region*/
            CyExitCriticalSection(Timer_2_interruptState);
            Timer_2_STATUS_MASK =Timer_2_backup.InterruptMaskValue;
            #if (Timer_2_UsingHWCaptureCounter)
                Timer_2_SetCaptureCount(Timer_2_backup.TimerCaptureCounter);
            #endif /* Restore the UDB non-rentention register capture counter for PSoC5A */
        #endif /* Restore the UDB non-rentention registers for PSoC5A */

        #if (CY_PSOC3 || CY_PSOC5LP)
            Timer_2_WriteCounter(Timer_2_backup.TimerUdb);
            Timer_2_STATUS_MASK =Timer_2_backup.InterruptMaskValue;
            #if (Timer_2_UsingHWCaptureCounter)
                Timer_2_SetCaptureCount(Timer_2_backup.TimerCaptureCounter);
            #endif /* Restore Capture counter register*/
        #endif /* Restore up non retention registers, interrupt mask and capture counter for PSoC3 or PSoC5LP */

        #if(!Timer_2_ControlRegRemoved)
            Timer_2_WriteControlRegister(Timer_2_backup.TimerControlRegister);
        #endif /* Restore the enable state of the Timer component */
    #endif /* Restore non retention registers in the UDB implementation only */
}
示例#2
0
文件: Timer_2.c 项目: Insepet/GRP700U
/*******************************************************************************
* Function Name: Timer_2_Init
********************************************************************************
*
* Summary:
*  Initialize to the schematic state
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void Timer_2_Init(void) 
{
    #if(!Timer_2_UsingFixedFunction)
            /* Interrupt State Backup for Critical Region*/
            uint8 Timer_2_interruptState;
    #endif /* Interrupt state back up for Fixed Function only */

    #if (Timer_2_UsingFixedFunction)
        /* Clear all bits but the enable bit (if it's already set) for Timer operation */
        Timer_2_CONTROL &= Timer_2_CTRL_ENABLE;

        /* Clear the mode bits for continuous run mode */
        #if (CY_PSOC5A)
            Timer_2_CONTROL2 &= ((uint8)(~Timer_2_CTRL_MODE_MASK));
        #endif /* Clear bits in CONTROL2 only in PSOC5A */

        #if (CY_PSOC3 || CY_PSOC5LP)
            Timer_2_CONTROL3 &= ((uint8)(~Timer_2_CTRL_MODE_MASK));
        #endif /* CONTROL3 register exists only in PSoC3 OR PSoC5LP */

        /* Check if One Shot mode is enabled i.e. RunMode !=0*/
        #if (Timer_2_RunModeUsed != 0x0u)
            /* Set 3rd bit of Control register to enable one shot mode */
            Timer_2_CONTROL |= 0x04u;
        #endif /* One Shot enabled only when RunModeUsed is not Continuous*/

        #if (Timer_2_RunModeUsed == 2)
            #if (CY_PSOC5A)
                /* Set last 2 bits of control2 register if one shot(halt on
                interrupt) is enabled*/
                Timer_2_CONTROL2 |= 0x03u;
            #endif /* Set One-Shot Halt on Interrupt bit in CONTROL2 for PSoC5A */

            #if (CY_PSOC3 || CY_PSOC5LP)
                /* Set last 2 bits of control3 register if one shot(halt on
                interrupt) is enabled*/
                Timer_2_CONTROL3 |= 0x03u;
            #endif /* Set One-Shot Halt on Interrupt bit in CONTROL3 for PSoC3 or PSoC5LP */

        #endif /* Remove section if One Shot Halt on Interrupt is not enabled */

        #if (Timer_2_UsingHWEnable != 0)
            #if (CY_PSOC5A)
                /* Set the default Run Mode of the Timer to Continuous */
                Timer_2_CONTROL2 |= Timer_2_CTRL_MODE_PULSEWIDTH;
            #endif /* Set Continuous Run Mode in CONTROL2 for PSoC5A */

            #if (CY_PSOC3 || CY_PSOC5LP)
                /* Clear and Set ROD and COD bits of CFG2 register */
                Timer_2_CONTROL3 &= ((uint8)(~Timer_2_CTRL_RCOD_MASK));
                Timer_2_CONTROL3 |= Timer_2_CTRL_RCOD;

                /* Clear and Enable the HW enable bit in CFG2 register */
                Timer_2_CONTROL3 &= ((uint8)(~Timer_2_CTRL_ENBL_MASK));
                Timer_2_CONTROL3 |= Timer_2_CTRL_ENBL;

                /* Set the default Run Mode of the Timer to Continuous */
                Timer_2_CONTROL3 |= Timer_2_CTRL_MODE_CONTINUOUS;
            #endif /* Set Continuous Run Mode in CONTROL3 for PSoC3ES3 or PSoC5A */

        #endif /* Configure Run Mode with hardware enable */

        /* Clear and Set SYNCTC and SYNCCMP bits of RT1 register */
        Timer_2_RT1 &= ((uint8)(~Timer_2_RT1_MASK));
        Timer_2_RT1 |= Timer_2_SYNC;

        /*Enable DSI Sync all all inputs of the Timer*/
        Timer_2_RT1 &= ((uint8)(~Timer_2_SYNCDSI_MASK));
        Timer_2_RT1 |= Timer_2_SYNCDSI_EN;

        /* Set the IRQ to use the status register interrupts */
        Timer_2_CONTROL2 |= Timer_2_CTRL2_IRQ_SEL;
    #endif /* Configuring registers of fixed function implementation */

    /* Set Initial values from Configuration */
    Timer_2_WritePeriod(Timer_2_INIT_PERIOD);
    Timer_2_WriteCounter(Timer_2_INIT_PERIOD);

    #if (Timer_2_UsingHWCaptureCounter)/* Capture counter is enabled */
        Timer_2_CAPTURE_COUNT_CTRL |= Timer_2_CNTR_ENABLE;
        Timer_2_SetCaptureCount(Timer_2_INIT_CAPTURE_COUNT);
    #endif /* Configure capture counter value */

    #if (!Timer_2_UsingFixedFunction)
        #if (Timer_2_SoftwareCaptureMode)
            Timer_2_SetCaptureMode(Timer_2_INIT_CAPTURE_MODE);
        #endif /* Set Capture Mode for UDB implementation if capture mode is software controlled */

        #if (Timer_2_SoftwareTriggerMode)
            #if (!Timer_2_UDB_CONTROL_REG_REMOVED)
                if (0u == (Timer_2_CONTROL & Timer_2__B_TIMER__TM_SOFTWARE))
                {
                    Timer_2_SetTriggerMode(Timer_2_INIT_TRIGGER_MODE);
                }
            #endif /* (!Timer_2_UDB_CONTROL_REG_REMOVED) */
        #endif /* Set trigger mode for UDB Implementation if trigger mode is software controlled */

        /* CyEnterCriticalRegion and CyExitCriticalRegion are used to mark following region critical*/
        /* Enter Critical Region*/
        Timer_2_interruptState = CyEnterCriticalSection();

        /* Use the interrupt output of the status register for IRQ output */
        Timer_2_STATUS_AUX_CTRL |= Timer_2_STATUS_ACTL_INT_EN_MASK;

        /* Exit Critical Region*/
        CyExitCriticalSection(Timer_2_interruptState);

        #if (Timer_2_EnableTriggerMode)
            Timer_2_EnableTrigger();
        #endif /* Set Trigger enable bit for UDB implementation in the control register*/
		
		
        #if (Timer_2_InterruptOnCaptureCount && !Timer_2_UDB_CONTROL_REG_REMOVED)
            Timer_2_SetInterruptCount(Timer_2_INIT_INT_CAPTURE_COUNT);
        #endif /* Set interrupt count in UDB implementation if interrupt count feature is checked.*/

        Timer_2_ClearFIFO();
    #endif /* Configure additional features of UDB implementation */

    Timer_2_SetInterruptMode(Timer_2_INIT_INTERRUPT_MODE);
}