summaryrefslogtreecommitdiff
path: root/bsp/gd32105c-eval/Libraries/GD32F10x_usbfs_driver/Source/usbh_int.c
blob: 5a652bcb88984a454027e47ef40d7387f5c08b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
/*!
    \file  usbh_int.c
    \brief USB host mode interrupt handler file

    \version 2014-12-26, V1.0.0, firmware for GD32F10x
    \version 2017-06-20, V2.0.0, firmware for GD32F10x
    \version 2018-07-31, V2.1.0, firmware for GD32F10x
*/

/*
    Copyright (c) 2018, GigaDevice Semiconductor Inc.

    All rights reserved.

    Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this
       list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
    3. Neither the name of the copyright holder nor the names of its contributors
       may be used to endorse or promote products derived from this software without
       specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/

#include "usb_core.h"
#include "usb_defines.h"
#include "usbh_int.h"

static uint32_t usbh_intf_sof                 (usb_core_handle_struct *pudev);
static uint32_t usbh_intf_port                (usb_core_handle_struct *pudev);
static uint32_t usbh_intf_hc                  (usb_core_handle_struct *pudev);
static uint32_t usbh_intf_hc_in               (usb_core_handle_struct *pudev, uint8_t channel_num);
static uint32_t usbh_intf_hc_out              (usb_core_handle_struct *pudev, uint8_t channel_num);
static uint32_t usbh_intf_rxfifo_noempty      (usb_core_handle_struct *pudev);
static uint32_t usbh_intf_nptxfifo_empty      (usb_core_handle_struct *pudev);
static uint32_t usbh_intf_ptxfifo_empty       (usb_core_handle_struct *pudev);
static uint32_t usbh_intf_disconnect          (usb_core_handle_struct *pudev);
static uint32_t usbh_intf_iso_incomplete_xfer (usb_core_handle_struct *pudev);

/*!
    \brief      handle global host interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
uint32_t usbh_isr (usb_core_handle_struct *pudev)
{
    uint32_t retval = 0U;
    __IO uint32_t int_flag = 0U;

    /* check if host mode */
    if (USB_CURRENT_MODE_GET() == HOST_MODE) {
        USB_CORE_INTR_READ(int_flag);

        if (!int_flag) {
            return 0U;
        }

        /* start of frame interrupt handle */
        if (int_flag & GINTF_SOF) {
            retval |= usbh_intf_sof (pudev);
        }

        /* rx fifo non-empty interrupt handle */
        if (int_flag & GINTF_RXFNEIF) {
            retval |= usbh_intf_rxfifo_noempty (pudev);
        }

        /* non-periodic tx fifo empty interrupt hanlde */
        if (int_flag & GINTF_NPTXFEIF) {
            retval |= usbh_intf_nptxfifo_empty (pudev);
        }

        /* periodic tx fifo empty interrupt handle */
        if (int_flag & GINTF_PTXFEIF) {
            retval |= usbh_intf_ptxfifo_empty (pudev);
        }

        /* host channels interrupt handle */
        if (int_flag & GINTF_HCIF) {
            retval |= usbh_intf_hc (pudev);
        }

        /* host port interrupt handle */
        if (int_flag & GINTF_HPIF) {
            retval |= usbh_intf_port (pudev);
        }

        /* disconnect interrupt handle */
        if (int_flag & GINTF_DISCIF) {
            retval |= usbh_intf_disconnect (pudev);
        }

        /* isochronous in transfer not complete interrupt handle */
        if (int_flag & GINTF_ISOONCIF) {
            retval |= usbh_intf_iso_incomplete_xfer (pudev);
        }
    }

    return retval;
}

/*!
    \brief      handle the start-of-frame interrupt in host mode
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_sof (usb_core_handle_struct *pudev)
{
    usbh_hcd_int_fops->sof(pudev);

    /* clear interrupt */
    USB_GINTF = GINTF_SOF;

    return 1U;
}

/*!
    \brief      handle all host channels interrupt in host mode
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_hc (usb_core_handle_struct *pudev)
{
    uint8_t i = 0U;
    uint32_t retval = 0U;

    for (i = 0U; i < pudev->cfg.host_channel_num; i++) {
        if ((USB_HACHINT & HACHINT_HACHINT) & ((uint32_t)1U << i)) {
            if ((USB_HCHxCTL((uint16_t)i) & HCHCTL_EPDIR) >> 15U) {
                retval |= usbh_intf_hc_in (pudev, i);
            } else {
                retval |= usbh_intf_hc_out (pudev, i);
            }
        }
    }

    return retval;
}

/*!
    \brief      handle the disconnect interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_disconnect (usb_core_handle_struct *pudev)
{
    usbh_hcd_int_fops->device_disconnected(pudev);

    /* clear interrupt */
    USB_GINTF = GINTF_DISCIF;

    return 1U;
}

/*!
    \brief      handle the non-periodic tx fifo empty interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_nptxfifo_empty (usb_core_handle_struct *pudev)
{
    uint8_t channel_num = 0U;
    uint32_t dword_len = 0U, len = 0U;
    usb_hostchannel_struct *puhc;

    channel_num = (uint8_t)((USB_HNPTFQSTAT & HNPTFQSTAT_CNUM) >> 27U);
    puhc = &pudev->host.host_channel[channel_num];
    dword_len = (puhc->xfer_len + 3U) / 4U;

    while (((USB_HNPTFQSTAT & HNPTFQSTAT_NPTXFS) > dword_len) && (0U != puhc->xfer_len)) {
        len = (USB_HNPTFQSTAT & HNPTFQSTAT_NPTXFS) * 4U;

        if (len > puhc->xfer_len) {
            /* last packet */
            len = (uint16_t)puhc->xfer_len;

            USB_GINTEN &= ~GINTF_NPTXFEIF;

        }

        dword_len = (puhc->xfer_len + 3U) / 4U;
        usb_fifo_write (puhc->xfer_buff, channel_num, (uint16_t)len);

        puhc->xfer_buff += len;
        puhc->xfer_len -= len;
        puhc->xfer_count += len;
    }

    return 1U;
}

/*!
    \brief      handle the periodic tx fifo empty interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_ptxfifo_empty (usb_core_handle_struct *pudev)
{
    uint8_t channel_num = 0U;
    uint32_t dword_len = 0U, len = 0U;
    usb_hostchannel_struct *puhc;

    channel_num = (uint8_t)((USB_HPTFQSTAT & HPTFQSTAT_CNUM) >> 27U);
    puhc = &pudev->host.host_channel[channel_num];
    dword_len = (puhc->xfer_len + 3U) / 4U;

    while (((USB_HPTFQSTAT & HPTFQSTAT_PTXFS) > dword_len) && (0U != puhc->xfer_len)) {
        len = (USB_HPTFQSTAT & HPTFQSTAT_PTXFS) * 4U;

        if (len > puhc->xfer_len) {
            len = puhc->xfer_len;

            /* last packet */
            USB_GINTEN &= ~GINTF_PTXFEIF;
        }

        dword_len = (puhc->xfer_len + 3U) / 4U;
        usb_fifo_write (puhc->xfer_buff, channel_num, (uint16_t)len);

        puhc->xfer_buff += len;
        puhc->xfer_len -= len;
        puhc->xfer_count += len;
    }

    return 1U;
}

/*!
    \brief      handle the host port interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_port (usb_core_handle_struct *pudev)
{
    uint8_t port_speed = 0U;
    uint8_t port_reset = 0U;
    uint32_t retval = 0U;
    __IO uint32_t hostportdup = USB_HPCS;

    /* clear the interrupt bits in gintsts */
    hostportdup &= ~HPCS_PE;
    hostportdup &= ~HPCS_PCD;
    hostportdup &= ~HPCS_PEDC;

    /* port connect detected */
    if (USB_HPCS & HPCS_PCD) {
        hostportdup |= HPCS_PCD;
        usbh_hcd_int_fops->device_connected(pudev);
        retval |= 1U;
    }

    /* port enable changed */
    if (USB_HPCS & HPCS_PEDC) {
        hostportdup |= HPCS_PEDC;

        if (USB_HPCS & HPCS_PE) {
            port_speed = (uint8_t)((USB_HPCS & HPCS_PS) >> 17U);

            if (HPRT_PRTSPD_LOW_SPEED == port_speed) {
                USB_HFT = 6000U;

                if (HCTLR_6_MHZ != (USB_HCTL & HCTL_CLKSEL)) {
                    if (USB_CORE_EMBEDDED_PHY == pudev->cfg.phy_interface) {
                        USB_FSLSCLOCK_INIT(HCTLR_6_MHZ);
                    }
                    port_reset = 1U;
                }
            } else if(HPRT_PRTSPD_FULL_SPEED == port_speed) {
                USB_HFT = 48000U;

                if (HCTLR_48_MHZ != (USB_HCTL & HCTL_CLKSEL)) {
                    if (USB_CORE_EMBEDDED_PHY == pudev->cfg.phy_interface) {
                        USB_FSLSCLOCK_INIT(HCTLR_48_MHZ);
                    }
                    port_reset = 1U;
                }
            } else {
                /* for high speed device and others */
                port_reset = 1U;
            }
        }
    }

    if (port_reset) {
        usb_port_reset(pudev);
    }

    /* clear port interrupts */
    USB_HPCS = hostportdup;

    return retval;
}

/*!
    \brief      handle the out channel interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[in]  channel_num: host channel number which is in (0..7)
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_hc_out (usb_core_handle_struct *pudev, uint8_t channel_num)
{
    uint32_t channel_intr = USB_HCHxINTF((uint16_t)channel_num);
    usb_hostchannel_struct *puhc = &pudev->host.host_channel[channel_num];

    channel_intr &= USB_HCHxINTEN((uint16_t)channel_num);

    if (channel_intr & HCHINTF_ACK) {
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_ACK;
    } else if (channel_intr & HCHINTF_REQOVR) {
        /* handle queue overrun interrupt */
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        usb_hostchannel_halt(pudev, channel_num);
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_REQOVR;
    } else if (channel_intr & HCHINTF_TF) {
        /* handle transfer finished interrupt */
        puhc->err_count = 0U;
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        usb_hostchannel_halt(pudev, channel_num);
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_TF;
        puhc->status = HC_XF;
    } else if (channel_intr & HCHINTF_STALL) {
        /* handle stall */
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_STALL;
        usb_hostchannel_halt(pudev, channel_num);
        puhc->status = HC_STALL;
    } else if (channel_intr & HCHINTF_NAK) {
        /* handle NAK */
        puhc->err_count = 0U;
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        usb_hostchannel_halt(pudev, channel_num);
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
        puhc->status = HC_NAK;
    } else if (channel_intr & HCHINTF_USBER) {
        /* handle USB bus error */
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        usb_hostchannel_halt(pudev, channel_num);
        puhc->status = HC_TRACERR;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_USBER;
    } else if (channel_intr & HCHINTF_NYET) {
        /* handle NYET */
        puhc->err_count = 0U;
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        usb_hostchannel_halt(pudev, channel_num);
        puhc->status = HC_NYET;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NYET;
    } else if (channel_intr & HCHINTF_DTER) {
        /* handle data toggle error */
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        usb_hostchannel_halt(pudev, channel_num);
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
        puhc->status= HC_DTGERR;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_DTER;
    } else if (channel_intr & HCHINTF_CH) {
        /* handle channel halted */
        USB_HCHxINTEN((uint16_t)channel_num) &= ~HCHINTEN_CHIE;

        switch (puhc->status) {
            case HC_XF:
                puhc->urb_state = URB_DONE;

                if (USB_EPTYPE_BULK == ((USB_HCHxCTL((uint16_t)channel_num) & HCHCTL_EPTYPE) >> 18U)) {
                    puhc->data_tg_out ^= 1U;
                }
                break;
            case HC_NAK:
                puhc->urb_state = URB_NOTREADY;
                break;
            case HC_NYET:
                puhc->urb_state = URB_NOTREADY;
                break;
            case HC_STALL:
                puhc->urb_state = URB_STALL;
                break;
            case HC_TRACERR:
                puhc->urb_state = URB_ERROR;
                break;
            default:
                break;
        }

        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_CH;
    } else {
        /* no operation */
    }

    return 1U;
}

/*!
    \brief      handle the in channel interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[in]  channel_num: host channel number which is in (0..7)
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_hc_in (usb_core_handle_struct *pudev, uint8_t channel_num)
{
    uint8_t endp_type = 0U;
    usb_hostchannel_struct *puhc = &pudev->host.host_channel[channel_num];

    uint32_t channle_intf = USB_HCHxINTF((uint16_t)channel_num);
    __IO uint32_t channel_ctrl = USB_HCHxCTL((uint16_t)channel_num);

    channle_intf &= USB_HCHxINTEN((uint16_t)channel_num);

    endp_type = (uint8_t)((channel_ctrl & HCHCTL_EPTYPE) >> 18U);

    if (channle_intf & HCHINTF_ACK) {
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_ACK;
    } else if (channle_intf & HCHINTF_STALL) {
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        puhc->status = HC_STALL;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_STALL;

        /* NOTE: When there is a 'stall', reset also nak,
           else, the pudev->host.status = HC_STALL
           will be overwritten by 'nak' in code below */
        channle_intf &= ~HCHINTF_NAK;

        usb_hostchannel_halt(pudev, channel_num);
    } else if (channle_intf & HCHINTF_DTER) {
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        usb_hostchannel_halt(pudev, channel_num);
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
        puhc->status = HC_DTGERR;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_DTER;
    } else {
        /* no operation */
    }
    /* handle queue overrun interrupt */
    if (channle_intf & HCHINTF_REQOVR) {
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        usb_hostchannel_halt(pudev, channel_num);
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_REQOVR;
    } else if (channle_intf & HCHINTF_TF) {
        /* handle transfer finished interrupt */
        puhc->status = HC_XF;
        puhc->err_count = 0U;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_TF;

        if ((USB_EPTYPE_CTRL == endp_type) || (USB_EPTYPE_BULK == endp_type)) {
            USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
            usb_hostchannel_halt(pudev, channel_num);
            USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
            puhc->data_tg_in ^= 1U;
        } else if (USB_EPTYPE_INTR == endp_type) {
            channel_ctrl |= HCHCTL_ODDFRM;
            USB_HCHxCTL((uint16_t)channel_num) = channel_ctrl;
            puhc->urb_state = URB_DONE;
        } else {
            /* no operation */
        }
    } else if (channle_intf & HCHINTF_CH) {
        /* handle channel halted */
        USB_HCHxINTEN((uint16_t)channel_num) &= ~HCHINTEN_CHIE;

        switch (puhc->status) {
            case HC_XF:
                puhc->urb_state = URB_DONE;
                break;
            case HC_TRACERR:
            case HC_DTGERR:
                puhc->err_count = 0U;
                puhc->urb_state = URB_ERROR;
                break;
            case HC_STALL:
                puhc->urb_state = URB_STALL;
                break;
            default:
                if (USB_EPTYPE_INTR == endp_type) {
                    puhc->data_tg_in ^= 1U;
                }
                break;
        }

        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_CH;
    } else if (channle_intf & HCHINTF_USBER) {
        /* handle USB bus error */
        USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
        puhc->status = HC_TRACERR;
        usb_hostchannel_halt(pudev, channel_num);
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_USBER;
    } else if (channle_intf & HCHINTF_NAK) {
        /* handle NAK */
        if (USB_EPTYPE_INTR == endp_type) {
            USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
            usb_hostchannel_halt(pudev, channel_num);
        }

        puhc->status = HC_NAK;
        USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;

        if ((USB_EPTYPE_CTRL == endp_type) || (USB_EPTYPE_BULK == endp_type)) {
            /* re-activate the channel */
            channel_ctrl |= HCHCTL_CEN;
            channel_ctrl &= ~HCHCTL_CDIS;
            USB_HCHxCTL((uint16_t)channel_num) = channel_ctrl;
        }
    } else {
        /* no operation */
    }

    return 1U;
}

/*!
    \brief      handle the rx fifo non-empty interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_rxfifo_noempty (usb_core_handle_struct *pudev)
{
    uint32_t count = 0U;
    __IO uint8_t channel_num = 0U;
    __IO uint32_t rx_status = 0U;
    uint32_t usbh_ch_ctl_reg = 0U;
    usb_hostchannel_struct *puhc;

    /* disable the rx status queue level interrupt */
    USB_GINTEN &= ~GINTF_RXFNEIF;

    rx_status = USB_GRSTATP;
    channel_num = (uint8_t)(rx_status & GRSTATRP_CNUM);
    puhc = &pudev->host.host_channel[channel_num];

    switch ((rx_status & GRSTATRP_RPCKST) >> 17) {
        case GRSTATR_RPCKST_IN:
            count = (rx_status & GRSTATRP_BCOUNT) >> 4;

            /* read the data into the host buffer. */
            if ((count > 0U) && (puhc->xfer_buff != (void *)0)) {
                usb_fifo_read(puhc->xfer_buff, (uint16_t)count);

                /* manage multiple Xfer */
                puhc->xfer_buff += count;
                puhc->xfer_count += count;

                if (USB_HCHxLEN((uint16_t)channel_num) & HCHLEN_PCNT) {
                    /* re-activate the channel when more packets are expected */
                    usbh_ch_ctl_reg = USB_HCHxCTL((uint16_t)channel_num);
                    usbh_ch_ctl_reg |= HCHCTL_CEN;
                    usbh_ch_ctl_reg &= ~HCHCTL_CDIS;
                    USB_HCHxCTL((uint16_t)channel_num) = usbh_ch_ctl_reg;
                }
            }
            break;
        case GRSTATR_RPCKST_IN_XFER_COMP:
            break;
        case GRSTATR_RPCKST_DATA_TOGGLE_ERR:
            count = (rx_status & GRSTATRP_BCOUNT) >> 4;
            while (count > 0) {
                rx_status = USB_GRSTATP;
                count--;
            }
            break;
        case GRSTATR_RPCKST_CH_HALTED:
        default:
            break;
    }

    /* enable the rx status queue level interrupt */
    USB_GINTEN |= GINTF_RXFNEIF;

    return 1U;
}

/*!
    \brief      handle the incomplete periodic transfer interrupt
    \param[in]  pudev: pointer to usb device instance
    \param[out] none
    \retval     operation status
*/
static uint32_t usbh_intf_iso_incomplete_xfer (usb_core_handle_struct *pudev)
{
    __IO uint32_t gint_flag = 0U;

    gint_flag = USB_HCHxCTL(0U);
    USB_HCHxCTL(0U) = 0U;

    gint_flag = 0U;

    /* clear interrupt */
    gint_flag |= GINTF_ISOONCIF;
    USB_GINTF = gint_flag;

    return 1U;
}