1 /*! 2 \file usbh_core.h 3 \brief header file for the usbh_core.c 4 5 \version 2020-08-04, V1.1.0, firmware for GD32VF103 6 */ 7 8 /* 9 Copyright (c) 2020, GigaDevice Semiconductor Inc. 10 11 Redistribution and use in source and binary forms, with or without modification, 12 are permitted provided that the following conditions are met: 13 14 1. Redistributions of source code must retain the above copyright notice, this 15 list of conditions and the following disclaimer. 16 2. Redistributions in binary form must reproduce the above copyright notice, 17 this list of conditions and the following disclaimer in the documentation 18 and/or other materials provided with the distribution. 19 3. Neither the name of the copyright holder nor the names of its contributors 20 may be used to endorse or promote products derived from this software without 21 specific prior written permission. 22 23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 OF SUCH DAMAGE. 33 */ 34 35 #ifndef __USBH_MSC_CORE_H 36 #define __USBH_MSC_CORE_H 37 38 #include "usb_msc.h" 39 #include "usbh_msc_scsi.h" 40 #include "usbh_msc_bbb.h" 41 42 #define MSC_MAX_SUPPORTED_LUN 2U 43 44 typedef enum 45 { 46 MSC_INIT = 0U, 47 MSC_IDLE, 48 MSC_TEST_UNIT_READY, 49 MSC_READ_CAPACITY10, 50 MSC_READ_INQUIRY, 51 MSC_REQUEST_SENSE, 52 MSC_READ, 53 MSC_WRITE, 54 MSC_UNRECOVERED_ERROR, 55 MSC_PERIODIC_CHECK, 56 } msc_state; 57 58 typedef enum 59 { 60 MSC_OK, 61 MSC_NOT_READY, 62 MSC_ERROR, 63 } msc_error; 64 65 typedef enum 66 { 67 MSC_REQ_IDLE = 0U, 68 MSC_REQ_RESET, 69 MSC_REQ_GET_MAX_LUN, 70 MSC_REQ_ERROR, 71 } msc_req_state; 72 73 /* Structure for LUN */ 74 typedef struct 75 { 76 msc_state state; 77 msc_error error; 78 msc_scsi_sense sense; 79 scsi_capacity capacity; 80 scsi_std_inquiry_data inquiry; 81 usbh_status prev_ready_state; 82 uint8_t state_changed; 83 } msc_lun; 84 85 /* structure for msc process */ 86 typedef struct _msc_process 87 { 88 uint8_t pipe_in; 89 uint8_t pipe_out; 90 uint8_t ep_in; 91 uint8_t ep_out; 92 uint16_t ep_size_in; 93 uint16_t ep_size_out; 94 uint8_t cur_lun; 95 uint16_t rw_lun; 96 uint32_t max_lun; 97 msc_state state; 98 msc_error error; 99 msc_req_state req_state; 100 msc_req_state prev_req_state; 101 bot_handle bot; 102 msc_lun unit[MSC_MAX_SUPPORTED_LUN]; 103 uint32_t timer; 104 } usbh_msc_handler; 105 106 extern usbh_class usbh_msc; 107 108 /* function declarations */ 109 /* get msc logic unit information */ 110 usbh_status usbh_msc_lun_info_get (usbh_host *puhost, uint8_t lun, msc_lun *info); 111 /* msc read interface */ 112 usbh_status usbh_msc_read (usbh_host *puhost, 113 uint8_t lun, 114 uint32_t address, 115 uint8_t *pbuf, 116 uint32_t length); 117 /* msc write interface */ 118 usbh_status usbh_msc_write (usbh_host *puhost, 119 uint8_t lun, 120 uint32_t address, 121 uint8_t *pbuf, 122 uint32_t length); 123 124 #endif /* __USBH_MSC_CORE_H */ 125