コード例 #1
0
ファイル: Timer_1_PM.c プロジェクト: Hsue66/Zumo-PSoC
/*******************************************************************************
* Function Name: Timer_1_RestoreConfig
********************************************************************************
*
* Summary:
*  Restores the current user configuration.
*
* Parameters:
*  void
*
* Return:
*  void
*
* Global variables:
*  Timer_1_backup:  Variables of this global structure are used to
*  restore the values of non retention registers on wakeup from sleep mode.
*
*******************************************************************************/
void Timer_1_RestoreConfig(void) 
{   
    #if (!Timer_1_UsingFixedFunction)

        Timer_1_WriteCounter(Timer_1_backup.TimerUdb);
        Timer_1_STATUS_MASK =Timer_1_backup.InterruptMaskValue;
        #if (Timer_1_UsingHWCaptureCounter)
            Timer_1_SetCaptureCount(Timer_1_backup.TimerCaptureCounter);
        #endif /* Restore Capture counter register*/

        #if(!Timer_1_UDB_CONTROL_REG_REMOVED)
            Timer_1_WriteControlRegister(Timer_1_backup.TimerControlRegister);
        #endif /* Restore the enable state of the Timer component */
    #endif /* Restore non retention registers in the UDB implementation only */
}
コード例 #2
0
ファイル: Timer_1_PM.c プロジェクト: Kledal/semesterprojekt3
/*******************************************************************************
* Function Name: Timer_1_RestoreConfig
********************************************************************************
*
* Summary:
*  Restores the current user configuration.
*
* Parameters:
*  void
*
* Return:
*  void
*
* Global variables:
*  Timer_1_backup:  Variables of this global structure are used to
*  restore the values of non retention registers on wakeup from sleep mode.
*
*******************************************************************************/
void Timer_1_RestoreConfig(void) 
{   
    #if (!Timer_1_UsingFixedFunction)
        /* Restore the UDB non-rentention registers for CY_UDB_V0 */
        #if (CY_UDB_V0)
            /* Interrupt State Backup for Critical Region*/
            uint8 Timer_1_interruptState;

            Timer_1_WriteCounter(Timer_1_backup.TimerUdb);
            Timer_1_WritePeriod(Timer_1_backup.TimerPeriod);
            /* CyEnterCriticalRegion and CyExitCriticalRegion are used to mark following region critical*/
            /* Enter Critical Region*/
            Timer_1_interruptState = CyEnterCriticalSection();
            /* Use the interrupt output of the status register for IRQ output */
            Timer_1_STATUS_AUX_CTRL |= Timer_1_STATUS_ACTL_INT_EN_MASK;
            /* Exit Critical Region*/
            CyExitCriticalSection(Timer_1_interruptState);
            Timer_1_STATUS_MASK =Timer_1_backup.InterruptMaskValue;
            #if (Timer_1_UsingHWCaptureCounter)
                Timer_1_SetCaptureCount(Timer_1_backup.TimerCaptureCounter);
            #endif /* Restore the UDB non-rentention register capture counter for CY_UDB_V0 */
        #endif /* Restore the UDB non-rentention registers for CY_UDB_V0 */

        #if (CY_UDB_V1)
            Timer_1_WriteCounter(Timer_1_backup.TimerUdb);
            Timer_1_STATUS_MASK =Timer_1_backup.InterruptMaskValue;
            #if (Timer_1_UsingHWCaptureCounter)
                Timer_1_SetCaptureCount(Timer_1_backup.TimerCaptureCounter);
            #endif /* Restore Capture counter register*/
        #endif /* Restore up non retention registers, interrupt mask and capture counter for CY_UDB_V1 */

        #if(!Timer_1_ControlRegRemoved)
            Timer_1_WriteControlRegister(Timer_1_backup.TimerControlRegister);
        #endif /* Restore the enable state of the Timer component */
    #endif /* Restore non retention registers in the UDB implementation only */
}
コード例 #3
0
ファイル: Timer_1.c プロジェクト: Kledal/semesterprojekt3
/*******************************************************************************
* Function Name: Timer_1_Init
********************************************************************************
*
* Summary:
*  Initialize to the schematic state
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void Timer_1_Init(void) 
{
    #if(!Timer_1_UsingFixedFunction)
            /* Interrupt State Backup for Critical Region*/
            uint8 Timer_1_interruptState;
    #endif /* Interrupt state back up for Fixed Function only */

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

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

        #if (CY_PSOC3 || CY_PSOC5LP)
            Timer_1_CONTROL3 &= ((uint8)(~Timer_1_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_1_RunModeUsed != 0x0u)
            /* Set 3rd bit of Control register to enable one shot mode */
            Timer_1_CONTROL |= 0x04u;
        #endif /* One Shot enabled only when RunModeUsed is not Continuous*/

        #if (Timer_1_RunModeUsed == 2)
            #if (CY_PSOC5A)
                /* Set last 2 bits of control2 register if one shot(halt on
                interrupt) is enabled*/
                Timer_1_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_1_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_1_UsingHWEnable != 0)
            #if (CY_PSOC5A)
                /* Set the default Run Mode of the Timer to Continuous */
                Timer_1_CONTROL2 |= Timer_1_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_1_CONTROL3 &= ((uint8)(~Timer_1_CTRL_RCOD_MASK));
                Timer_1_CONTROL3 |= Timer_1_CTRL_RCOD;

                /* Clear and Enable the HW enable bit in CFG2 register */
                Timer_1_CONTROL3 &= ((uint8)(~Timer_1_CTRL_ENBL_MASK));
                Timer_1_CONTROL3 |= Timer_1_CTRL_ENBL;

                /* Set the default Run Mode of the Timer to Continuous */
                Timer_1_CONTROL3 |= Timer_1_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_1_RT1 &= ((uint8)(~Timer_1_RT1_MASK));
        Timer_1_RT1 |= Timer_1_SYNC;

        /*Enable DSI Sync all all inputs of the Timer*/
        Timer_1_RT1 &= ((uint8)(~Timer_1_SYNCDSI_MASK));
        Timer_1_RT1 |= Timer_1_SYNCDSI_EN;

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

    /* Set Initial values from Configuration */
    Timer_1_WritePeriod(Timer_1_INIT_PERIOD);
    Timer_1_WriteCounter(Timer_1_INIT_PERIOD);

    #if (Timer_1_UsingHWCaptureCounter)/* Capture counter is enabled */
        Timer_1_CAPTURE_COUNT_CTRL |= Timer_1_CNTR_ENABLE;
        Timer_1_SetCaptureCount(Timer_1_INIT_CAPTURE_COUNT);
    #endif /* Configure capture counter value */

    #if (!Timer_1_UsingFixedFunction)
        #if (Timer_1_SoftwareCaptureMode)
            Timer_1_SetCaptureMode(Timer_1_INIT_CAPTURE_MODE);
        #endif /* Set Capture Mode for UDB implementation if capture mode is software controlled */

        #if (Timer_1_SoftwareTriggerMode)
            if (0u == (Timer_1_CONTROL & Timer_1__B_TIMER__TM_SOFTWARE))
            {
                Timer_1_SetTriggerMode(Timer_1_INIT_TRIGGER_MODE);
            }
        #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_1_interruptState = CyEnterCriticalSection();

        /* Use the interrupt output of the status register for IRQ output */
        Timer_1_STATUS_AUX_CTRL |= Timer_1_STATUS_ACTL_INT_EN_MASK;

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

        #if (Timer_1_EnableTriggerMode)
            Timer_1_EnableTrigger();
        #endif /* Set Trigger enable bit for UDB implementation in the control register*/

        #if (Timer_1_InterruptOnCaptureCount)
             #if (!Timer_1_ControlRegRemoved)
                Timer_1_SetInterruptCount(Timer_1_INIT_INT_CAPTURE_COUNT);
            #endif /* Set interrupt count in control register if control register is not removed */
        #endif /*Set interrupt count in UDB implementation if interrupt count feature is checked.*/

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

    Timer_1_SetInterruptMode(Timer_1_INIT_INTERRUPT_MODE);
}