usb_int.c
Upload User: yyyd609
Upload Date: 2022-07-18
Package Size: 183k
Code Size: 4k
Development Platform:

C/C++

  1. /******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
  2. * File Name          : usb_int.c
  3. * Author             : MCD Application Team
  4. * Date First Issued  : 27/10/2003
  5. * Description        : Endpoint CTR interrupt service routine
  6. *
  7. ********************************************************************************/
  8. #include "USB_lib.h"
  9. extern void const (*pEpInt[15])(void);
  10. /*------------------------------------------------------------------------------*/
  11. void CTR_ISR()
  12. {
  13.  WORD wEPVal;
  14.   /* stay in loop while pending ints */
  15. while(((wIstr = _GetISTR()) & ISTR_CTR)!= 0)
  16. {
  17.     _SetISTR((WORD)CLR_CTR); /* clear CTR flag */
  18. /* extract highest priority endpoint number */
  19. EPindex = (BYTE)(wIstr & ISTR_EP_ID);
  20. if(EPindex == 0)
  21. {
  22. /*==================================================================*/
  23. /* Decode and service control endpoint interrupt */
  24. /* calling related service routine */
  25. /* (Setup0_Process, In0_Process, Out0_Process) */
  26. /*==================================================================*/
  27. /* save RX & TX status */
  28. /* and set both to NAK */
  29. SaveRState = _GetEPRxStatus(ENDP0);
  30. SaveTState = _GetEPTxStatus(ENDP0);
  31. _SetEPRxStatus(ENDP0, EP_RX_NAK);
  32. _SetEPTxStatus(ENDP0, EP_TX_NAK);
  33.     /*-------------------------------------------------*/
  34. /* DIR bit = origin of the interrupt */
  35.     /*-------------------------------------------------*/
  36. if((wIstr & ISTR_DIR) == 0)
  37. {/* DIR = 0 */
  38.     /*-------------------------------------------------*/
  39. /* DIR = 0      => IN  int */
  40. /* DIR = 0 implies that (EP_CTR_TX = 1) always  */
  41.     /*-------------------------------------------------*/
  42. /* wEPVal = GetENDPOINT(ENDP0); */
  43. /* if((wEPVal & EP_CTR_TX) != 0) */
  44. /* { */
  45. _ClearEP_CTR_TX(ENDP0);
  46. In0_Process();
  47. /* } */
  48. /* check if SETUP arrived during IN processing */
  49. wEPVal = _GetENDPOINT(ENDP0);
  50. if((wEPVal & (EP_CTR_RX|EP_SETUP)) != 0)
  51. {
  52. _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
  53. Setup0_Process();
  54. }
  55. }/* DIR = 0 */
  56. else
  57. {/* DIR = 1 */
  58.     /*-------------------------------------------------*/
  59. /* DIR = 1 & CTR_RX       => SETUP or OUT int */
  60. /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
  61.     /*-------------------------------------------------*/
  62. wEPVal = _GetENDPOINT(ENDP0);
  63. if((wEPVal & EP_CTR_TX) != 0)
  64. {
  65. _ClearEP_CTR_TX(ENDP0);
  66. In0_Process();
  67. }
  68. if((wEPVal & (EP_CTR_RX|EP_SETUP)) != 0)
  69. {
  70. _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
  71. Setup0_Process();
  72. }
  73. else if((wEPVal & EP_CTR_RX) != 0)
  74. {
  75. _ClearEP_CTR_RX(ENDP0);
  76. Out0_Process();
  77. }
  78. }/* DIR = 1 */
  79. /* before terminate set Tx & Rx status */
  80. _SetEPRxStatus(ENDP0, SaveRState);
  81. _SetEPTxStatus(ENDP0, SaveTState);
  82. }/* if(EPindex == 0) */
  83. else
  84. {
  85. /*===============================================================*/
  86. /* Decode and service non control endpoints interrupt  */
  87. /*===============================================================*/
  88. /* process related endpoint register */
  89. wEPVal = _GetENDPOINT(EPindex);
  90. if((wEPVal & EP_CTR_RX) != 0)
  91. {
  92. /* clear int flag */
  93. _ClearEP_CTR_RX(EPindex);
  94. } /* if((wEPVal & EP_CTR_RX) */
  95. if((wEPVal & EP_CTR_TX) != 0)
  96. {
  97. /* clear int flag */
  98. _ClearEP_CTR_TX(EPindex);
  99. } /* if((wEPVal & EP_CTR_TX) != 0) */
  100. /* call service function */
  101. (*pEpInt[EPindex-1])();
  102. }/* if(EPindex == 0) else */
  103. }/* while(...) */
  104. } /* CTR_ISR */