AN050
GD32 USBFS&USBHS Firmware Library User Guide
25
In interrupt handler function of IN endpoint, process transfer finished interrupt and transmit
FIFO empty interrupt. After corresponding IN endpoint interrupt event generated, MCU
execute the corresponding interrupt handler function through polling interrupt flag.
The interrupt handler function of Rx FIFO non empty is shown as below:
static
uint32_t
usbd_int_rxfifo
(
usb_core_driver
*
udev
)
{
usb_transc
*
transc
=
NULL
;
uint8_t
data_PID
=
0U
;
uint32_t
bcount
=
0U
;
__IO
uint32_t
devrxstat
=
0U
;
/* disable the Rx status queue non-empty interrupt */
udev
->
regs
.
gr
->
GINTEN
&=
~
GINTEN_RXFNEIE
;
/* get the status from the top of the FIFO */
devrxstat
=
udev
->
regs
.
gr
->
GRSTATP
;
uint8_t
ep_num
=
(
uint8_t
)(
devrxstat
&
GRSTATRP_EPNUM
);
transc
=
&
udev
->
dev
.
transc_out
[
ep_num
];
bcount
=
(
devrxstat
&
GRSTATRP_BCOUNT
)
>>
4U
;
data_PID
=
(
uint8_t
)((
devrxstat
&
GRSTATRP_DPID
)
>>
15U
);
switch
((
devrxstat
&
GRSTATRP_RPCKST
)
>>
17U
)
{
case
RSTAT_GOUT_NAK
:
break
;
case
RSTAT_DATA_UPDT
:
if
(
bcount
>
0U
)
{
(
void
)
usb_rxfifo_read
(&
udev
->
regs
,
transc
->
xfer_buf
,
(
uint16_t
)
bcount
); // read
FIFO
transc
->
xfer_buf
+=
bcount
;
transc
->
xfer_count
+=
bcount
;
}
break
;
case
RSTAT_XFER_COMP
:
/* trigger the OUT endpoint interrupt */
break
;