AN050
GD32 USBFS&USBHS Firmware Library User Guide
55
}
else
if
(
PIPE_PERIOD
==
pp_mode
)
{
txfiforeg
=
&
udev
->
regs
.
hr
->
HPTFQSTAT
;
}
else
{
return
0U
;
}
txfifostate
=
*
txfiforeg
;
pp_num
=
(
uint8_t
)((
txfifostate
&
TFQSTAT_CNUM
)
>>
27U
);
word_count
=
(
uint16_t
)(
udev
->
host
.
pipe
[
pp_num
].
xfer_len
+
3U
)
/
4U
;
while
(((
txfifostate
&
TFQSTAT_TXFS
)
>=
word_count
)
&&
(
0U
!=
udev
->
host
.
pipe
[
pp_num
].
xfer_len
))
{
len
=
(
uint16_t
)(
txfifostate
&
TFQSTAT_TXFS
)
*
4U
;
if
(
len
>
udev
->
host
.
pipe
[
pp_num
].
xfer_len
)
{
/* last packet */
len
=
(
uint16_t
)
udev
->
host
.
pipe
[
pp_num
].
xfer_len
;
if
(
PIPE_NON_PERIOD
==
pp_mode
)
{
udev
->
regs
.
gr
->
GINTEN
&=
~
GINTEN_NPTXFEIE
;
}
else
{
udev
->
regs
.
gr
->
GINTEN
&=
~
GINTEN_PTXFEIE
;
}
}
word_count
=
(
uint16_t
)((
udev
->
host
.
pipe
[
pp_num
].
xfer_len
+
3U
)
/
4U
);
usb_txfifo_write
(&
udev
->
regs
,
udev
->
host
.
pipe
[
pp_num
].
xfer_buf
,
pp_num
,
len
); // write
FIFO
udev
->
host
.
pipe
[
pp_num
].
xfer_buf
+=
len
;
udev
->
host
.
pipe
[
pp_num
].
xfer_len
-=
len
;
udev
->
host
.
pipe
[
pp_num
].
xfer_count
+=
len
;
txfifostate
=
*
txfiforeg
;
}
return
1U
;
}