1 /******************************************************************************
2 * Copyright (c) 2018 Texas Instruments Incorporated - http://www.ti.com
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *****************************************************************************/
34 /**
35 *
36 * \file usb_host_test.h
37 *
38 * \brief This is the header file for usb host diagnostic test.
39 *
40 */
43 #ifndef _USB_HOST_TEST_H_
44 #define _USB_HOST_TEST_H_
46 /* ========================================================================== */
47 /* Include Files */
48 /* ========================================================================== */
50 #include "types.h"
52 #include <ti/board/board.h>
54 #include "diag_common_cfg.h"
56 #if (defined(SOC_AM335x) || defined (SOC_AM437x))
57 #include "example_utils_mmu.h"
58 #include "mmu.h"
60 #include "cache.h"
61 #endif
63 #include <ti/drv/uart/UART_stdio.h>
65 #include <ti/fs/fatfs/FATFS.h>
67 #include "fatfs_port_usbmsc.h"
68 #include "fs_shell_app_utils.h"
70 #include "usb_drv.h"
71 #include "usb_osal.h"
72 #include "usblib.h"
73 #include "usbhost.h"
74 #include "usbhmsc.h"
75 #include "hw_usb.h"
77 #include "timer.h"
79 #if defined(BUILD_ARM) && (defined(SOC_OMAPL137) || defined(SOC_OMAPL138))
80 #include "ti/csl/arch/arm9/V0/csl_cp15.h"
81 #endif
83 #if (defined(SOC_AM65XX) && defined(BUILD_MCU))
84 #include "intRouter.h"
85 #endif
86 #if defined(am65xx_evm)
87 #include "board_cfg.h"
88 #include "ti/board/src/evmKeystone3/include/board_i2c_io_exp.h"
89 #include "ti/board/src/evmKeystone3/include/board_internal.h"
90 #endif
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
97 /* ========================================================================== */
98 /* Macros */
99 /* ========================================================================== */
100 #define USB_INSTANCE_CP (1U)
101 #define USB_INSTANCE_SER (0U)
102 #define NO_ERROR (0U)
104 /* The instance data for the MSC driver. */
106 void* g_ulMSCInstance = (void*)NULL;
108 #if defined(BUILD_ARM) && (defined(SOC_OMAPL137) || defined(SOC_OMAPL138))
109 /* USB param struture variable should be used as global variable because
110 * ARM9 does not support interrupt hander with arguments
111 */
112 USB_Params usb_host_params;
113 #endif
115 /**
116 * \brief Enum defining states of the mass storage device.
117 */
118 typedef enum
119 {
120 /* No device is present */
121 STATE_NO_DEVICE,
123 /* Mass storage device is being enumerated */
124 STATE_DEVICE_ENUM,
126 /* Mass storage device is ready */
127 STATE_DEVICE_READY,
129 /* An unsupported device has been attached */
130 STATE_UNKNOWN_DEVICE,
132 /* A power fault has occurred */
133 STATE_POWER_FAULT
134 } tState;
136 volatile tState g_eState;
139 /* FAT fs variables.*/
141 /**
142 * \brief USBMSC function table for USB implementation
143 */
145 FATFS_DrvFxnTable FATFS_drvFxnTable = {
146 /* closeDrvFxn */
147 FATFSPortUSBDiskClose,
148 /* controlDrvFxn */
149 FATFSPortUSBDiskIoctl,
150 /* initDrvFxn */
151 FATFSPortUSBDiskInitialize,
152 /* openDrvFxn */
153 FATFSPortUSBDiskOpen,
154 /* writeDrvFxn */
155 FATFSPortUSBDiskWrite,
156 /* readDrvFxn */
157 FATFSPortUSBDiskRead
158 };
160 /**
161 * \brief FATFS configuration structure.
162 */
163 FATFS_HwAttrs FATFS_initCfg[_VOLUMES] =
164 {
165 {
166 0U
167 },
168 {
169 1U
170 },
171 {
172 2U
173 },
174 {
175 3U
176 }
177 };
179 /* FATFS objects */
180 FATFS_Object FATFS_objects[_VOLUMES];
182 /**
183 * \brief FATFS configuration structure.
184 */
185 const FATFS_Config FATFS_config[_VOLUMES + 1] = {
186 {
187 &FATFS_drvFxnTable,
188 &FATFS_objects[0],
189 &FATFS_initCfg[0]
190 },
192 {
193 &FATFS_drvFxnTable,
194 &FATFS_objects[1],
195 &FATFS_initCfg[1]
196 },
198 {
199 &FATFS_drvFxnTable,
200 &FATFS_objects[2],
201 &FATFS_initCfg[2]
202 },
204 {
205 &FATFS_drvFxnTable,
206 &FATFS_objects[3],
207 &FATFS_initCfg[3]
208 },
209 {NULL, NULL, NULL}
210 };
212 FATFS_Handle fatfsHandle = NULL;
214 extern void CSL_A15_INIT_copyVectorTable(void);
216 /* ========================================================================== */
217 /* Prototypes */
218 /* ========================================================================== */
220 /**
221 * \brief callback from the MSC driver
222 *
223 * \param ulInstance [IN] USB instance used
224 * ulEvent [IN] one of the events defined
225 * by the driver.
226 * pvData [IN] pointer to data passed into
227 * the initial call to register
228 * the callback.
229 *
230 */
231 void MSCCallback(void *ulInstance, uint32_t ulEvent, void *pvData);
233 /**
234 * \brief Setting up the MMU for USB.
235 */
236 void setupMMUForUSB(void);
238 /**
239 * \brief main entry point for USB core interrupt handler
240 *
241 * \param pUsbParam [IN] Parameters used
242 * for configuring USB
243 *
244 */
245 void usbCoreIntrHandler(void* pUsbParam);
247 /**
248 * \brief usb host Diagnostic test main function
249 *
250 * \return int - usb host Diagnostic test status.
251 * 0 - in case of success
252 * -1 - in case of failure.
253 *
254 */
255 int8_t BoardDiag_run_usbHost_test(void);
257 #ifdef __cplusplus
258 }
259 #endif /* __cplusplus */
261 #endif /* #ifndef _USB_HOST_TEST_H_ */