GD32F1x0: USB/GD32_USB_Device_Driver/src/usb_int.c Source File

GD32F1x0

usb_int.c
Go to the documentation of this file.
1 
11 /* Includes ------------------------------------------------------------------*/
12 #include "usb_int.h"
13 
29 extern uint32_t InterruptMask;
30 extern USB_CORE_HANDLE USB_Device_dev;
31 extern USB_INTHandler_TypeDef *USB_INT_fops;
32 
33 #ifdef LPM_ENABLED
34 __IO uint32_t L1_remote_wakeup = 0;
35 __IO uint32_t BESL = 0;
36 __IO uint16_t LPM_Istr = 0;
37 #endif
38 
52 void USB_Ifr (void)
53 {
54  __IO uint16_t Ifr = 0;
55  __IO uint16_t Ctlr = 0;
56 
57  Ifr = _GetIFR();
58 
59 #ifdef LPM_ENABLED
60  LPM_Istr = GetLPM_ISTR();
61 #endif
62 
63  if (Ifr & IFR_STIF & InterruptMask)
64  {
65  /* The endpoint successful transfer interrupt service */
66  USB_INT_fops->LP_ST(&USB_Device_dev);
67  }
68 
69  if (Ifr & IFR_RSTIF & InterruptMask)
70  {
71  /* Clear reset interrupt flag in IFR */
72  _SetIFR((uint16_t)CLR_RSTIF);
73 
74  /* USB reset interrupt handle */
75  USB_INT_fops->Reset(&USB_Device_dev);
76  }
77 
78 #if (IER_MASK & IFR_PMOUIF)
79  if (Ifr & IFR_PMOUIF & InterruptMask)
80  {
81  /* Clear packet memory overrun/underrun interrupt flag in IFR */
82  _SetIFR((uint16_t)CLR_PMOUIF);
83 
84  /* USB packet memory overrun/underrun interrrupt handle */
85  USB_INT_fops->PMOU(&USB_Device_dev);
86  }
87 #endif
88 
89 #if (IER_MASK & IFR_ERRIF)
90  if (Ifr & IFR_ERRIF & InterruptMask)
91  {
92  /* Clear error interrupt flag in IFR */
93  _SetIFR((uint16_t)CLR_ERRIF);
94 
95  /* USB error interrupt handle */
96  USB_INT_fops->Error(&USB_Device_dev);
97  }
98 #endif
99 
100 #if (IER_MASK & IFR_WKUPIF)
101  if (Ifr & IFR_WKUPIF & InterruptMask)
102  {
103  /* Clear wakeup interrupt flag in IFR */
104  _SetIFR((uint16_t)CLR_WKUPIF);
105 
106  /* USB wakeup interrupt handle */
107  USB_INT_fops->WakeUp(&USB_Device_dev);
108 
109 #ifdef LPM_ENABLED
110  /* clear L1 remote wakeup flag */
111  L1_remote_wakeup = 0;
112 #endif
113  }
114 #endif
115 
116 #if (IER_MASK & IFR_SPSIF)
117  if (Ifr & IFR_SPSIF & InterruptMask)
118  {
119  if(!(_GetCTLR() & CTLR_RSREQ))
120  {
121  /* Process library core layer suspend routine*/
122  USB_INT_fops->Suspend(&USB_Device_dev);
123 
124  /* Clear of suspend interrupt flag bit must be done after setting of CTLR_SETSPS */
125  _SetIFR((uint16_t)CLR_SPSIF);
126  }
127  }
128 #endif
129 
130 #if (IER_MASK & IFR_SOFIF)
131  if (Ifr & IFR_SOFIF & InterruptMask)
132  {
133  /* clear SOF interrupt flag in IFR */
134  _SetIFR((uint16_t)CLR_SOFIF);
135 
136  /* USB SOF interrupt handle */
137  USB_INT_fops->SOF(&USB_Device_dev);
138  }
139 
140  if (Ifr & IFR_ESOFIF & InterruptMask)
141  {
142  /* clear ESOF interrupt flag in IFR */
143  _SetIFR((uint16_t)CLR_ESOFIF);
144 
145  /* USB ESOF interrupt handle */
146  USB_INT_fops->ESOF(&USB_Device_dev);
147  }
148 #endif
149 
150 #ifdef LPM_ENABLED
151  if (LPM_Istr & _GetLPM_CNTR())
152  {
153  /* Clear L1 ST flag in LPM ISTR */
154  _SetLPM_ISTR(LPM_CLR_STIF);
155 
156  /* Read BESL field from subendpoint0 register which coressponds to HIRD parameter in LPM spec */
157  BESL = (_GetSUBEP0R() & ATTR_HIRD) >> 4;
158 
159  /* Read BREMOTEWAKE bit from subendpoint0 register which corresponding to bRemoteWake bit in LPM request */
160  L1_remote_wakeup = (_GetSUBEP0R() & ATTR_BREMOTEWAKE) >> 8;
161 
162  /* Process usb device core layer suspend routine */
163  USB_INT_fops->Suspend(&USB_Device_dev);
164 
165  /* Enter usb model in suspend and system in low power mode (DEEP_SLEEP mode) */
166  Suspend();
167  }
168 #endif
169 }
170 
187 /************************ (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
#define CTLR_RSREQ
Definition: usb_regs.h:160
#define CLR_SOFIF
Definition: usb_regs.h:186
#define IFR_SOFIF
Definition: usb_regs.h:175
#define ATTR_HIRD
Definition: usb_regs.h:212
#define CLR_RSTIF
Definition: usb_regs.h:185
#define ATTR_BREMOTEWAKE
Definition: usb_regs.h:211
void USB_Ifr(void)
USB interrupt events service routine.
Definition: usb_int.c:52
#define IFR_PMOUIF
Definition: usb_regs.h:170
#define IFR_WKUPIF
Definition: usb_regs.h:172
USB device interrupt management header file.
#define IFR_STIF
IFR interrupt events bits definitions.
Definition: usb_regs.h:169
#define CLR_SPSIF
Definition: usb_regs.h:184
#define IFR_RSTIF
Definition: usb_regs.h:174
#define CLR_PMOUIF
Definition: usb_regs.h:181
#define LPM_CLR_STIF
Definition: usb_regs.h:232
#define IFR_SPSIF
Definition: usb_regs.h:173
#define CLR_ESOFIF
Definition: usb_regs.h:187
#define IFR_ESOFIF
Definition: usb_regs.h:176
#define CLR_ERRIF
Definition: usb_regs.h:182
#define CLR_WKUPIF
Definition: usb_regs.h:183
#define IFR_ERRIF
Definition: usb_regs.h:171
Generated by   doxygen 1.8.10