usb_interrupt.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /***********************************************************************************
  2. Filename: usb_interrupt.c
  3. Description: USB library interrupt initialisation and ISR.
  4. ***********************************************************************************/
  5. /// \addtogroup module_usb_interrupt
  6. /// @{
  7. #define USBINTERRUPT_C ///< Modifies the behavior of "EXTERN" in usb_interrupt.h
  8. #include "usb_firmware_library_headers.h"
  9. #include "usb_board_cfg.h"
  10. #include "hal_flash.h"
  11. #include "hal_led.h"
  12. /** \brief Initializes the \ref module_usb_interrupt module
  13. *
  14. * This function should be called after the \ref module_usb_framework module has been initialized.
  15. * Use interrupt group priority control (refer to the CC2531 datasheet) to adjust the priority of the
  16. * USB interrupt relative to other interrupts.
  17. *
  18. * \param[in] irqMask
  19. * A bit mask containing USBIRQ_EVENT bits for all events that shall be reported
  20. */
  21. void usbirqInit(uint16 irqMask)
  22. {
  23. // Initialize variables
  24. usbirqData.eventMask = 0x0000;
  25. usbirqData.inSuspend = FALSE;
  26. usbirqData.irqMask = irqMask;
  27. // Select which IRQ flags to handle
  28. USBCIE = irqMask;
  29. USBIIE = irqMask >> 4;
  30. USBOIE = (irqMask >> 9) & 0x3E;
  31. HAL_USB_INT_CLEAR();
  32. HAL_USB_INT_ENABLE();
  33. } // usbirqInit
  34. /** \brief USB interrupt handler
  35. *
  36. * Clears the P2 interrupt flag and converts all USB interrupt flags into events.
  37. * The interrupt also lets \ref usbsuspEnter() break from the suspend loop.
  38. */
  39. #if defined HAL_SB_BOOT_CODE
  40. void usbirqHandler(void)
  41. #else
  42. #pragma vector=P2INT_VECTOR
  43. __interrupt void usbirqHandler(void)
  44. #endif
  45. {
  46. uint8 usbcif;
  47. // First make sure that the crystal oscillator is stable
  48. while (!CC2530_IS_XOSC_STABLE());
  49. // Special handling for reset interrupts
  50. usbcif = USBCIF;
  51. if (usbcif & USBCIF_RSTIF) {
  52. // All interrupts (except suspend) are by default enabled by hardware, so
  53. // re-initialize the enable bits to avoid unwanted interrupts
  54. USBCIE = usbirqData.irqMask;
  55. USBIIE = usbirqData.irqMask >> 4;
  56. USBOIE = (usbirqData.irqMask >> 9) & 0x3E;
  57. // Enable suspend mode when suspend signaling is detected on the bus
  58. USBPOW |= USBPOW_SUSPEND_EN;
  59. }
  60. // Record events (keeping existing)
  61. usbirqData.eventMask |= (uint16) usbcif;
  62. usbirqData.eventMask |= (uint16) USBIIF << 4;
  63. usbirqData.eventMask |= (uint16) USBOIF << 9;
  64. // If we get a suspend event, we should always enter suspend mode. We must,
  65. // however be sure that we exit the suspend loop upon resume or reset
  66. // signaling.
  67. if (usbcif & USBCIF_SUSPENDIF) {
  68. usbirqData.inSuspend = TRUE;
  69. }
  70. if (usbcif & (USBCIF_RSTIF | USBCIF_RESUMEIF)) {
  71. usbirqData.inSuspend = FALSE;
  72. }
  73. if (P2IFG & P2IFG_DPIF) {
  74. // Resume interrupt detected on D+ line while in suspend
  75. P2IFG = ~P2IFG_DPIF;
  76. usbirqData.inSuspend = FALSE;
  77. }
  78. // Handle event which need immediate processing
  79. usbirqHookProcessEvents();
  80. // Clear the interrupt
  81. HAL_USB_INT_CLEAR();
  82. } // usbirqHandler
  83. //@}
  84. /*
  85. +------------------------------------------------------------------------------
  86. | Copyright 2008-2009 Texas Instruments Incorporated. All rights reserved.
  87. |
  88. | IMPORTANT: Your use of this Software is limited to those specific rights
  89. | granted under the terms of a software license agreement between the user who
  90. | downloaded the software, his/her employer (which must be your employer) and
  91. | Texas Instruments Incorporated (the "License"). You may not use this Software
  92. | unless you agree to abide by the terms of the License. The License limits
  93. | your use, and you acknowledge, that the Software may not be modified, copied
  94. | or distributed unless embedded on a Texas Instruments microcontroller or used
  95. | solely and exclusively in conjunction with a Texas Instruments radio
  96. | frequency transceiver, which is integrated into your product. Other than for
  97. | the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  98. | works of, modify, distribute, perform, display or sell this Software and/or
  99. | its documentation for any purpose.
  100. |
  101. | YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  102. | PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  103. | INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  104. | NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  105. | TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  106. | NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  107. | LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING
  108. | BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
  109. | CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
  110. | SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  111. | (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  112. |
  113. | Should you have any questions regarding your right to use this Software,
  114. | contact Texas Instruments Incorporated at www.TI.com.
  115. |
  116. +------------------------------------------------------------------------------
  117. */