⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_interrupt.c

📁 reference about wireless design which is helpful to everyone
💻 C
字号:
/// \addtogroup module_usb_interrupt
/// @{
#define USBINTERRUPT_C
#include "cc2511_usb_library_headers.h"




/** \brief Initializes the \ref module_usb_interrupt module
*
* This function should be called after the \ref module_usb_framework module has been initialized.
* Use interrupt group priority control (refer to the CC2511 datasheet) to adjust the priority of the
* USB interrupt relative to other interrupts.
*
* \param[in]       irqMask
*     A bit mask containing USBIRQ_EVENT bits for all events that shall be reported
*/
void usbirqInit(WORD irqMask) {

   // Set P2 Interrupt
   INT_ENABLE(INUM_P2INT, INT_ON);

   PICTL |= 0x10;// Port 0, inputs 7 to 4 interrupt enable. Rising edge on input gives interrupt
   INT_ENABLE(INUM_P0INT, INT_ON);// Enable USB Resume Interrupt on P0

   // Clear the mask
   usbirqData.eventMask = 0x0000;

   // Select IRQ flags to handle
   USBCIE = irqMask;
   USBIIE = irqMask >> 4;
   USBOIE = (irqMask >> 9) & 0x3E;

} // usbirqInit




/** \brief USB interrupt handler
*
* Clears the P2 interrupt flag and converts all USB interrupt flags into events.
*/
#pragma vector=P2INT_VECTOR
__interrupt void usbirqHandler(void) {
   BYTE tempUsbcif;
   INT_ENABLE(INUM_P0INT, INT_OFF);//to avoid conflict with resume interrupt
   while( ! XOSC_STABLE ); //wait  for xosc running and stable.

   tempUsbcif = USBCIF;
   if(tempUsbcif & 0x01) {//if SUSPENDIF is set.
      usbsuspInit();
      usbirqData.inSuspend = TRUE;
   }
   if(tempUsbcif & 0x06) { usbirqData.inSuspend = FALSE; }//if RESUMIF or RSTIF is set.

   // Record events (keeping existing)
   usbirqData.eventMask |= (WORD) tempUsbcif;
   usbirqData.eventMask |= (WORD) USBIIF << 4;
   usbirqData.eventMask |= (WORD) USBOIF << 9;
   INT_ENABLE(INUM_P0INT, INT_ON);

   // Hand them over to the application
   usbirqHookProcessEvents();

   // Clear P2 Interrupt flag
   INT_SETFLAG(INUM_P2INT, INT_CLR);

} // usbirqHandler


/** \\brief USB resume interrupt handler
*
* Clears the USB resume interrupt flag.
* This interrupt is necessary to wake the chip if it is in power mode 1.
* When the chip wakes up a RESUME interrupt will occur on the P2INT_VECTOR.
* The application will be notified through a USBIRQ_EVENT_RESUME event.
*/
#pragma vector = P0INT_VECTOR
__interrupt void usbResumeHandler(void){

   // Clear USB_Resume flag
   if(P0IFG & 0x80) {
      usbsuspExit();
      P0IFG &= ~0x80;
   }

   // Clear P0 Interrupt flag
   INT_SETFLAG(INUM_P0INT, INT_CLR);
}// usbResumeHandler

/// @}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -