AN050
GD32 USBFS&USBHS Firmware Library User Guide
23
The interrupt handler function of OUT endpoint is shown as below:
static
uint32_t
usbd_int_epout
(
usb_core_driver
*
udev
)
{
uint32_t
epintnum
=
0U
;
uint8_t
ep_num
=
0U
;
for
(
epintnum
=
usb_oepintnum_read
(
udev
);
epintnum
;
epintnum
>>=
1
,
ep_num
++)
{
if
(
epintnum
&
0x01U
)
{
__IO
uint32_t
oepintr
=
usb_oepintr_read
(
udev
,
ep_num
);
/* transfer complete interrupt */
if
(
oepintr
&
DOEPINTF_TF
)
{
/* clear the bit in DOEPINTF for this interrupt */
udev
->
regs
.
er_out
[
ep_num
]->
DOEPINTF
=
DOEPINTF_TF
;
if
((
uint8_t
)
USB_USE_DMA
==
udev
->
bp
.
transfer_mode
)
{
__IO
uint32_t
eplen
=
udev
->
regs
.
er_out
[
ep_num
]->
DOEPLEN
;
udev
->
dev
.
transc_out
[
ep_num
].
xfer_count
=
udev
->
dev
.
transc_out
[
ep_num
].
max_len
-
\
(
eplen
&
DEPLEN_TLEN
);
}
/* inform upper layer: data ready */
(
void
)
usbd_out_transc
(
udev
,
ep_num
); // out transaction
if
((
uint8_t
)
USB_USE_DMA
==
udev
->
bp
.
transfer_mode
)
{
if
((
0U
==
ep_num
)
&&
((
uint8_t
)
USB_CTL_STATUS_OUT
==
udev
->
dev
.
control
.
ctl_state
))
{
usb_ctlep_startout
(
udev
);
}
}
}
/* setup phase finished interrupt (control endpoints) */
if
(
oepintr
&
DOEPINTF_STPF
)
{
/* inform the upper layer that a setup packet is available */
(
void
)
usbd_setup_transc
(
udev
); // setup
transaction
udev
->
regs
.
er_out
[
ep_num
]->
DOEPINTF
=
DOEPINTF_STPF
;
}
}
}