Exemple #1
0
/*******************************************************************************
* Function Name: USBFS_1_Stop
********************************************************************************
*
* Summary:
*  This function shuts down the USB function including to release
*  the D+ Pullup and disabling the SIE.
*
* Parameters:
*  None.
*
* Return:
*  None.
*
* Global variables:
*   USBFS_1_configuration: Contains current configuration number
*       which is set by the Host using SET_CONFIGURATION request.
*       Initialized to zero in this API.
*   USBFS_1_deviceAddress: Contains current device address. This
*       variable is initialized to zero in this API. Host starts to communicate
*      to device with address 0 and then set it to whatever value using
*      SET_ADDRESS request.
*   USBFS_1_deviceStatus: initialized to 0.
*       This is two bit variable which contain power status in first bit
*       (DEVICE_STATUS_BUS_POWERED or DEVICE_STATUS_SELF_POWERED) and remote
*       wakeup status (DEVICE_STATUS_REMOTE_WAKEUP) in second bit.
*   USBFS_1_configurationChanged: This variable is set to one after
*       SET_CONFIGURATION request and cleared in this function.
*   USBFS_1_intiVar variable is set to zero
*
*******************************************************************************/
void USBFS_1_Stop(void) 
{

    #if(USBFS_1_EP_MM != USBFS_1__EP_MANUAL)
        USBFS_1_Stop_DMA(USBFS_1_MAX_EP);     /* Stop all DMAs */
    #endif   /* End USBFS_1_EP_MM != USBFS_1__EP_MANUAL */

    /* Disable the SIE */
    USBFS_1_CR0_REG &= (uint8)(~USBFS_1_CR0_ENABLE);
    /* Disable the d+ pullup */
    USBFS_1_USBIO_CR1_REG &= (uint8)(~USBFS_1_USBIO_CR1_USBPUEN);
    /* Disable USB in ACT PM */
    USBFS_1_PM_ACT_CFG_REG &= (uint8)(~USBFS_1_PM_ACT_EN_FSUSB);
    /* Disable USB block for Standby Power Mode */
    USBFS_1_PM_STBY_CFG_REG &= (uint8)(~USBFS_1_PM_STBY_EN_FSUSB);

    /* Disable the reset and EP interrupts */
    CyIntDisable(USBFS_1_BUS_RESET_VECT_NUM);
    CyIntDisable(USBFS_1_EP_0_VECT_NUM);
    #if(USBFS_1_EP1_ISR_REMOVE == 0u)
        CyIntDisable(USBFS_1_EP_1_VECT_NUM);
    #endif   /* End USBFS_1_EP1_ISR_REMOVE */
    #if(USBFS_1_EP2_ISR_REMOVE == 0u)
        CyIntDisable(USBFS_1_EP_2_VECT_NUM);
    #endif   /* End USBFS_1_EP2_ISR_REMOVE */
    #if(USBFS_1_EP3_ISR_REMOVE == 0u)
        CyIntDisable(USBFS_1_EP_3_VECT_NUM);
    #endif   /* End USBFS_1_EP3_ISR_REMOVE */
    #if(USBFS_1_EP4_ISR_REMOVE == 0u)
        CyIntDisable(USBFS_1_EP_4_VECT_NUM);
    #endif   /* End USBFS_1_EP4_ISR_REMOVE */
    #if(USBFS_1_EP5_ISR_REMOVE == 0u)
        CyIntDisable(USBFS_1_EP_5_VECT_NUM);
    #endif   /* End USBFS_1_EP5_ISR_REMOVE */
    #if(USBFS_1_EP6_ISR_REMOVE == 0u)
        CyIntDisable(USBFS_1_EP_6_VECT_NUM);
    #endif   /* End USBFS_1_EP6_ISR_REMOVE */
    #if(USBFS_1_EP7_ISR_REMOVE == 0u)
        CyIntDisable(USBFS_1_EP_7_VECT_NUM);
    #endif   /* End USBFS_1_EP7_ISR_REMOVE */
    #if(USBFS_1_EP8_ISR_REMOVE == 0u)
        CyIntDisable(USBFS_1_EP_8_VECT_NUM);
    #endif   /* End USBFS_1_EP8_ISR_REMOVE */

    /* Clear all of the component data */
    USBFS_1_configuration = 0u;
    USBFS_1_interfaceNumber = 0u;
    USBFS_1_configurationChanged = 0u;
    USBFS_1_deviceAddress  = 0u;
    USBFS_1_deviceStatus = 0u;
    USBFS_1_initVar = 0u;

}
/*******************************************************************************
* Function Name: USBFS_1_Suspend
****************************************************************************//**
*
*  This function prepares the USBFS component to enter low power mode. The 
*  interrupt on falling edge on Dp pin is configured to wakeup device when the 
*  host drives resume condition. The pull-up is enabled on the Dp line while 
*  device is in low power mode. The supported low power modes are Deep Sleep 
*  (PSoC 4200L) and Sleep (PSoC 3/ PSoC 5LP).
*  
*  *Note* For PSoC 4200L devices, this function should not be called before 
*  entering Sleep.
*  
*  *Note* After enter low power mode, the data which is left in the IN or OUT 
*  endpoint buffers is not restored after wakeup and lost. Therefore it should 
*  be stored in the SRAM for OUT endpoint or read by the host for IN endpoint 
*  before enter low power mode.
*
* \globalvars
*  USBFS_1_backup.enable:  modified.
*
* \reentrant
*  No.
*
*******************************************************************************/
void USBFS_1_Suspend(void) 
{
    uint8 enableInterrupts;

    enableInterrupts = CyEnterCriticalSection();

    if (0u != (USBFS_1_CR0_REG & USBFS_1_CR0_ENABLE))
    {
        /* USB block is enabled. */
        USBFS_1_backup.enableState = 1u;

    #if (USBFS_1_EP_MANAGEMENT_DMA)
        USBFS_1_Stop_DMA(USBFS_1_MAX_EP);
    #endif /* (USBFS_1_EP_MANAGEMENT_DMA) */

    #if (CY_PSOC4)
        /* Suspend enter sequence. */
        USBFS_1_POWER_CTRL_REG |= (USBFS_1_POWER_CTRL_SUSPEND |
                                            USBFS_1_POWER_CTRL_SUSPEND_DEL);

        /* Store state of USB regulator and disable it. */
        USBFS_1_backup.mode = (uint8)  (USBFS_1_CR1_REG & USBFS_1_CR1_REG_ENABLE);
        USBFS_1_CR1_REG    &= (uint32) ~USBFS_1_CR1_REG_ENABLE;
        
        /* Store SIE interrupt sources. Valid bits are 0 - 4. */
        USBFS_1_backup.intrSeiMask = (uint8) USBFS_1_INTR_SIE_MASK_REG;

    #else
        /* Ensure USB transmit enable is low (USB_USBIO_CR0.ten). - Manual Transmission - Disabled. */
        USBFS_1_USBIO_CR0_REG &= (uint8) ~USBFS_1_USBIO_CR0_TEN;
        CyDelayUs(USBFS_1_WAIT_REG_STABILITY_50NS);  /*~50ns delay. */

        /* Disable the USBIO by asserting PM.USB_CR0.fsusbio_pd_n(Inverted) and pd_pullup_hv(Inverted) high. */
        USBFS_1_PM_USB_CR0_REG &= (uint8) ~(USBFS_1_PM_USB_CR0_PD_N |
                                                     USBFS_1_PM_USB_CR0_PD_PULLUP_N);

        /* Disable the SIE. */
        USBFS_1_CR0_REG &= (uint8) ~USBFS_1_CR0_ENABLE;

        CyDelayUs(USBFS_1_WAIT_REG_STABILITY_50NS);  /* ~50ns delay. */
        /* Store mode and disable VRegulator. */
        USBFS_1_backup.mode = (uint8) (USBFS_1_CR1_REG & USBFS_1_CR1_REG_ENABLE);
        USBFS_1_CR1_REG    &= (uint8) ~USBFS_1_CR1_REG_ENABLE;

        CyDelayUs(USBFS_1_WAIT_REG_STABILITY_1US); /* min 0.5us delay required. */

        /* Disable the USBIO reference by setting PM.USB_CR0.fsusbio_ref_en.*/
        USBFS_1_PM_USB_CR0_REG &= (uint8) ~USBFS_1_PM_USB_CR0_REF_EN;

        /* Switch DP and DM terminals to GPIO mode and disconnect 1.5k pull-up. */
        USBFS_1_USBIO_CR1_REG |= USBFS_1_USBIO_CR1_IOMODE;

        /* Disable USBFS block. */
        /* Clear power active and standby mode templates: disable USB block. */
        USBFS_1_PM_ACT_CFG_REG  &= (uint8) ~USBFS_1_PM_ACT_EN_FSUSB;
        USBFS_1_PM_STBY_CFG_REG &= (uint8) ~USBFS_1_PM_STBY_EN_FSUSB;

        CyDelayUs(USBFS_1_WAIT_REG_STABILITY_1US); /* min 0.5us delay required. */
    #endif /* (CY_PSOC4) */
    }
    else
    {
        USBFS_1_backup.enableState = 0u;
    }

    CyExitCriticalSection(enableInterrupts);

#if (USBFS_1_DP_ISR_ACTIVE)
    /* Clear active mode Dp interrupt source history. */
    (void) USBFS_1_Dp_ClearInterrupt();
    CyIntClearPending(USBFS_1_DP_INTC_VECT_NUM);

    CyIntEnable      (USBFS_1_DP_INTC_VECT_NUM);
#endif /* (USBFS_1_DP_ISR_ACTIVE). */
}