1 /*
2  * Copyright 2021 MindMotion Microelectronics Co., Ltd.
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef __HAL_USB_BDT_H__
9 #define __HAL_USB_BDT_H__
10 
11 #include "hal_common.h"
12 
13 /*!
14  * @addtogroup USB
15  * @{
16  */
17 
18 /*!
19  * @brief USB BufDesp EndPoint number.
20  */
21 #define USB_BDT_EP_NUM          16u  /*!< USB BufDesp EndPoint num. */
22 
23 /*!
24  * @brief USB BufDesp EndPoint direction number.
25  */
26 #define USB_BDT_DIRECTION_NUM   2u  /*!< USB BufDesp EndPoint direction num. */
27 
28 /*!
29  * @brief  USB BufDesp EndPoint buffer number.
30  */
31 #define USB_BDT_BUF_NUM         2u  /*!< USB BufDesp EndPoint buffer num. */
32 
33 /*!
34  * @brief This type of structure instance is used to implement the buffer descriptor for USB.
35  */
36 typedef struct
37 {
38     union
39     {
40         uint32_t HEAD; /*!< Head. */
41         struct
42         {
43             uint32_t RESEVED0   :2;  /*!< RESEVED. */
44             uint32_t BDT_STALL  :1;  /*!< Stall. */
45             uint32_t DTS        :1;  /*!< Data shift sync. */
46             uint32_t NINC       :1;  /*!< DMA addr cannot increasing. */
47             uint32_t KEEP       :1;  /*!< Keep BD held by USB. */
48             uint32_t DATA       :1;  /*!< DATA0 or DATA1. */
49             uint32_t OWN        :1;  /*!< Owner, 0 is CPU, 1 is USB. */
50             uint32_t RESEVED1   :8;  /*!< RESEVED. */
51             uint32_t BC         :10; /*!< Packet size. */
52             uint32_t RESEVED2   :6;  /*!< RESEVED. */
53         };
54         struct
55         {
56             uint32_t RESEVED3   :2;  /*!< RESEVED. */
57             uint32_t TOK_PID    :4;  /*!< Token pid. */
58             uint32_t RESEVED4   :26; /*!< RESEVED. */
59         };
60     };
61     uint32_t ADDR; /*!< Buffer addr. */
62 } USB_BufDesp_Type;
63 
64 /*!
65  * @brief This type of structure instance is used to implement the buffer descriptor table for USB.
66  */
67 typedef union
68 {
69     USB_BufDesp_Type Table[USB_BDT_EP_NUM][ USB_BDT_DIRECTION_NUM][ USB_BDT_BUF_NUM]; /*!< [EndPoint] [Direction] [Odd_Even]. */
70     USB_BufDesp_Type Index[USB_BDT_EP_NUM * USB_BDT_DIRECTION_NUM * USB_BDT_BUF_NUM]; /*!< Index. */
71 } USB_BufDespTable_Type;
72 
73 /*!
74  * @}
75  */
76 
77 #endif /* __HAL_USB_BDT_H__ */
78 
79