usb_interrupt.c

来自「reference about wireless design which is」· C语言 代码 · 共 93 行

C
93
字号
/// \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 + =
减小字号Ctrl + -
显示快捷键?