/******************************************************************************* * Function Name: USBUART_Resume ******************************************************************************** * * Summary: * This function enables the USBFS block after power down mode. * * Parameters: * None. * * Return: * None. * * Global variables: * USBUART_backup - checked. * * Reentrant: * No. * *******************************************************************************/ void USBUART_Resume(void) { uint8 enableInterrupts; enableInterrupts = CyEnterCriticalSection(); if(USBUART_backup.enableState != 0u) { #if(USBUART_DP_ISR_REMOVE == 0u) CyIntDisable(USBUART_DP_INTC_VECT_NUM); #endif /* USBUART_DP_ISR_REMOVE */ /* Enable USB block */ USBUART_PM_ACT_CFG_REG |= USBUART_PM_ACT_EN_FSUSB; /* Enable USB block for Standby Power Mode */ USBUART_PM_STBY_CFG_REG |= USBUART_PM_STBY_EN_FSUSB; /* Enable core clock */ USBUART_USB_CLK_EN_REG |= USBUART_USB_CLK_ENABLE; /* Enable the USBIO reference by setting PM.USB_CR0.fsusbio_ref_en.*/ USBUART_PM_USB_CR0_REG |= USBUART_PM_USB_CR0_REF_EN; /* The reference will be available ~40us after power restored */ CyDelayUs(40u); /* Return VRegulator*/ USBUART_CR1_REG |= USBUART_backup.mode; CyDelayUs(0u); /*~50ns delay */ /* Enable USBIO */ USBUART_PM_USB_CR0_REG |= USBUART_PM_USB_CR0_PD_N; CyDelayUs(2u); /* Set the USBIO pull-up enable */ USBUART_PM_USB_CR0_REG |= USBUART_PM_USB_CR0_PD_PULLUP_N; /* Re-init Arbiter configuration for DMA transfers */ #if(USBUART_EP_MM != USBUART__EP_MANUAL) /* Usb arb interrupt enable */ USBUART_ARB_INT_EN_REG = USBUART_ARB_INT_MASK; #if(USBUART_EP_MM == USBUART__EP_DMAMANUAL) USBUART_ARB_CFG_REG = USBUART_ARB_CFG_MANUAL_DMA; #endif /* USBUART_EP_MM == USBUART__EP_DMAMANUAL */ #if(USBUART_EP_MM == USBUART__EP_DMAAUTO) /*Set cfg cmplt this rises DMA request when the full configuration is done */ USBUART_ARB_CFG_REG = USBUART_ARB_CFG_AUTO_DMA | USBUART_ARB_CFG_AUTO_MEM; #endif /* USBUART_EP_MM == USBUART__EP_DMAAUTO */ #endif /* USBUART_EP_MM != USBUART__EP_MANUAL */ /* STALL_IN_OUT */ CY_SET_REG8(USBUART_EP0_CR_PTR, USBUART_MODE_STALL_IN_OUT); /* Enable the SIE with a last address */ USBUART_CR0_REG |= USBUART_CR0_ENABLE; CyDelayCycles(1u); /* Finally, Enable d+ pullup and select iomode to USB mode*/ CY_SET_REG8(USBUART_USBIO_CR1_PTR, USBUART_USBIO_CR1_USBPUEN); /* Restore USB register settings */ USBUART_RestoreConfig(); } CyExitCriticalSection(enableInterrupts); }
/******************************************************************************* * Function Name: USBUART_Resume ****************************************************************************//** * * This function prepares the USBFS component for active mode operation after * exit low power mode. It restores the component active mode configuration such * as device address assigned previously by the host, endpoints buffer and disables * interrupt on Dp pin. * 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 after * exiting Sleep. * * *Note* To resume communication with the host, the data endpoints must be * managed: the OUT endpoints must be enabled and IN endpoints must be loaded * with data. For DMA with Automatic Buffer Management, all endpoints buffers * must be initialized again before making them available to the host. * * * \globalvars * USBUART_backup - checked. * * \reentrant * No. * *******************************************************************************/ void USBUART_Resume(void) { uint8 enableInterrupts; enableInterrupts = CyEnterCriticalSection(); if (0u != USBUART_backup.enableState) { #if (USBUART_DP_ISR_ACTIVE) CyIntDisable(USBUART_DP_INTC_VECT_NUM); #endif /* (USBUART_DP_ISR_ACTIVE) */ #if (CY_PSOC4) /* Enable clock to USB IP. */ USBUART_USB_CLK_EN_REG |= USBUART_USB_CLK_CSR_CLK_EN; /* Restore arbiter configuration for DMA transfers. */ #if (USBUART_EP_MANAGEMENT_DMA) #if (USBUART_ARB_ISR_ACTIVE) /* Enable ARB EP interrupt sources. */ USBUART_ARB_INT_EN_REG = USBUART_DEFAULT_ARB_INT_EN; #endif /* (USBUART_EP_MANAGEMENT_DMA) */ /* Configure arbiter for Manual or Auto DMA operation and clear * configuration completion. */ USBUART_ARB_CFG_REG = USBUART_DEFAULT_ARB_CFG; #endif /* (USBUART_EP_MANAGEMENT_DMA) */ /* Restore level (hi, lo, med) for each interrupt source. */ USBUART_INTR_LVL_SEL_REG = USBUART_DEFAULT_INTR_LVL_SEL; /* Store SIE interrupt sources. */ USBUART_INTR_SIE_MASK_REG = (uint32) USBUART_backup.intrSeiMask; /* Set EP0.CR: ACK Setup, NAK IN/OUT. */ USBUART_EP0_CR_REG = USBUART_MODE_NAK_IN_OUT; /* Restore data EP1-8 configuration. */ USBUART_RestoreConfig(); /* Restore state of USB regulator and wait until it supples stable power. */ USBUART_CR1_REG |= USBUART_backup.mode; CyDelayUs(USBUART_WAIT_VREF_STABILITY); /* Suspend exit sequence. */ USBUART_POWER_CTRL_REG &= (uint32) ~USBUART_POWER_CTRL_SUSPEND; CyDelayUs(USBUART_WAIT_SUSPEND_DEL_DISABLE); USBUART_POWER_CTRL_REG &= (uint32) ~USBUART_POWER_CTRL_SUSPEND_DEL; #else /* Set power active and standby mode templates: enable USB block. */ USBUART_PM_ACT_CFG_REG |= USBUART_PM_ACT_EN_FSUSB; USBUART_PM_STBY_CFG_REG |= USBUART_PM_STBY_EN_FSUSB; /* Enable core clock. */ USBUART_USB_CLK_EN_REG |= USBUART_USB_CLK_ENABLE; /* Enable the USBIO reference by setting PM.USB_CR0.fsusbio_ref_en.*/ USBUART_PM_USB_CR0_REG |= USBUART_PM_USB_CR0_REF_EN; /* The reference is available ~40us after power restored. */ CyDelayUs(USBUART_WAIT_VREF_RESTORE); /* Restore state of USB regulator and wait until it supples stable power. */ USBUART_CR1_REG |= USBUART_backup.mode; CyDelayUs(USBUART_WAIT_VREF_STABILITY); /*~50ns delay. */ /* Enable USBIO. */ USBUART_PM_USB_CR0_REG |= USBUART_PM_USB_CR0_PD_N; CyDelayUs(USBUART_WAIT_PD_PULLUP_N_ENABLE); /* Set the USBIO pull-up enable. */ USBUART_PM_USB_CR0_REG |= USBUART_PM_USB_CR0_PD_PULLUP_N; /* Restore arbiter configuration for DMA transfers. */ #if (USBUART_EP_MANAGEMENT_DMA) #if (USBUART_ARB_ISR_ACTIVE) /* Enable ARB EP interrupt sources. */ USBUART_ARB_INT_EN_REG = USBUART_DEFAULT_ARB_INT_EN; #endif /* (USBUART_EP_MANAGEMENT_DMA) */ /* Configure arbiter for Manual or Auto DMA operation and clear * configuration completion. */ USBUART_ARB_CFG_REG = USBUART_DEFAULT_ARB_CFG; #endif /* (USBUART_EP_MANAGEMENT_DMA) */ /* Set EP0.CR: ACK Setup, STALL IN/OUT. */ USBUART_EP0_CR_REG = USBUART_MODE_STALL_IN_OUT; /* Enable the USB IP to respond to USB traffic with the last address. */ USBUART_CR0_REG |= USBUART_CR0_ENABLE; CyDelayCycles(USBUART_WAIT_CR0_REG_STABILITY); /* Enable D+ pull-up and keep USB control on IO. */ USBUART_USBIO_CR1_REG = USBUART_USBIO_CR1_USBPUEN; /* Restore data EP1-8 configuration. */ USBUART_RestoreConfig(); #endif /* (CY_PSOC4) */ } CyExitCriticalSection(enableInterrupts); }