1 /*!
2  * @file        usbd_msc_bot.h
3  *
4  * @brief       MSC BOT protocol core functions
5  *
6  * @version     V1.0.1
7  *
8  * @date        2022-09-20
9  *
10  * @attention
11  *
12  *  Copyright (C) 2020-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be useful and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 /* Define to prevent recursive inclusion */
27 #ifndef __USBD_MSC_BOT_H
28 #define __USBD_MSC_BOT_H
29 
30 /* Includes */
31 #include "usbd_core.h"
32 
33 /** @addtogroup USB_Driver_Library USB Driver Library
34   @{
35 */
36 
37 /** @addtogroup Core_Device Core Device
38   @{
39 */
40 
41 /** @addtogroup Class
42   @{
43 */
44 
45 /** @addtogroup MSC_BOT
46   @{
47 */
48 
49 /** @defgroup MSC_BOT_Macros Macros
50   @{
51 */
52 
53 #define MSC_BOT_CBW_SIGNATURE             (uint32_t)(0x43425355)
54 #define MSC_BOT_CBW_LENGTH                31
55 
56 #define MSC_BOT_CSW_SIGNATURE             (uint32_t)(0x53425355)
57 #define MSC_BOT_CSW_LENGTH                13
58 
59 /**@} end of group MSC_BOT_Macros */
60 
61 /** @defgroup MSC_BOT_Enumerations Enumerations
62   @{
63 */
64 
65 typedef enum
66 {
67     BOT_STATE_IDLE,          /*!< Idle state */
68     BOT_STATE_DATA_OUT,      /*!< Data Out state */
69     BOT_STATE_DATA_IN,       /*!< Data In state */
70     BOT_STATE_LAST_DATA_IN,  /*!< Last Data In Last */
71     BOT_STATE_SEND_DATA      /*!< Send Immediate data */
72 } BOT_STATE_T;
73 
74 typedef enum
75 {
76     BOT_STATUS_NORMAL,
77     BOT_STATUS_RECOVERY,
78     BOT_STATUS_ERROR
79 } BOT_STATUS_T;
80 
81 typedef enum
82 {
83     BOT_CSW_STATUS_CMD_OK,
84     BOT_CSW_STATUS_CMD_FAIL,
85     BOT_CSW_STATUS_PHASE_ERROR
86 } BOT_CSW_STATUS_T;
87 
88 /**@} end of group MSC_BOT_Enumerations */
89 
90 /** @defgroup MSC_BOT_Structures Structures
91   @{
92 */
93 
94 /**
95  * @brief   Command Block Wrapper
96  */
97 typedef struct
98 {
99     uint32_t dSignature;
100     uint32_t dTag;
101     uint32_t dDataXferLen;
102     uint8_t  bmFlags;
103     uint8_t  bLUN;
104     uint8_t  bCBLen;
105     uint8_t  CB[16];
106 } BOT_CBW_T;
107 
108 /**
109  * @brief   Command Status Wrapper
110  */
111 typedef struct
112 {
113     uint32_t dSignature;
114     uint32_t dTag;
115     uint32_t dDataResidue;
116     uint8_t  bStatus;
117 } BOT_CSW_T;
118 
119 typedef struct
120 {
121     uint8_t   state;
122     uint8_t   status;
123     uint16_t  dataLen;
124     BOT_CBW_T CBW;
125     BOT_CSW_T CSW;
126     uint8_t   data[MSC_MEDIA_PACKET];
127 } BOT_Info_T;
128 
129 /**@} end of group MSC_BOT_Structures */
130 
131 /** @defgroup MSC_BOT_Variables Variables
132   @{
133 */
134 
135 extern BOT_Info_T g_BOTInfo;
136 
137 /**@} end of group MSC_BOT_Variables */
138 
139 /** @defgroup MSC_BOT_Functions Functions
140   @{
141 */
142 
143 void USBD_MSC_BOT_Reset(void);
144 void USBD_MSC_BOT_Init(void);
145 void USBD_MSC_BOT_OutData(uint8_t ep);
146 void USBD_MSC_BOT_InData(uint8_t ep);
147 void USBD_MSC_BOT_TxCSW(uint8_t cswStatus);
148 void USBD_MSV_BOT_ClearFeatureHandler(void);
149 
150 #endif /*__USBD_MSC_BOT_H */
151 
152 /**@} end of group MSC_BOT_Functions */
153 /**@} end of group MSC_BOT_ */
154 /**@} end of group Class */
155 /**@} end of group Core_Device */
156 /**@} end of group USB_Driver_Library */
157