Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / msc / at32_msc_diskio.c
blob8d30d6b9a58392c53ca6920e5a0c253d9efe1866
1 /*
2 * At32 MSC scsi interface
3 * FLASH emfat reads and writes are implemented
4 * Other storage read and write services, such as sd, are not supported
8 */
11 #include <stdbool.h>
13 #include "at32_msc_diskio.h"
14 #include "platform.h"
16 #include "common/utils.h"
17 #include "msc_bot_scsi.h"
18 #include "drivers/usb_msc.h"
22 #define STORAGE_LUN_NBR 1
23 #define SCSI_BLOCK_SIZE 512
25 static const uint8_t scsi_inquiry[MSC_SUPPORT_MAX_LUN][SCSI_INQUIRY_DATA_LENGTH] =
27 /* lun = 0 */
29 0x00, /* peripheral device type (direct-access device) */
30 0x80, /* removable media bit */
31 0x00, /* ansi version, ecma version, iso version */
32 0x01, /* respond data format */
33 SCSI_INQUIRY_DATA_LENGTH - 5, /* additional length */
34 0x00, 0x00, 0x00, /* reserved */
35 'I', 'N', 'A', 'V', ' ', 'F', 'C', ' ', // Manufacturer : 8 bytes
36 'O', 'n', 'b', 'o', 'a', 'r', 'd', ' ', // Product : 16 Bytes
37 'F', 'l', 'a', 's', 'h', ' ', ' ', ' ', //
38 ' ', ' ', ' ' ,' ', // Version : 4 Bytes
42 usb_sts_type msc_disk_capacity(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
44 UNUSED(lun);
45 *block_size = SCSI_BLOCK_SIZE;
46 *block_num = emfat.disk_sectors;
47 return USB_OK;
52 if( ((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun ,
53 hmsc->bot_data,
54 hmsc->scsi_blk_addr / hmsc->scsi_blk_size,
55 len / hmsc->scsi_blk_size) < 0)
57 static int8_t STORAGE_Read(
58 uint8_t lun, // logical unit number
59 uint8_t *buf, // Pointer to the buffer to save data
60 uint32_t blk_addr, // address of 1st block to be read
61 uint16_t blk_len) // nmber of blocks to be read
63 UNUSED(lun);
64 mscSetActive();
65 emfat_read(&emfat, buf, blk_addr, blk_len);
66 return 0;
70 usb_sts_type msc_disk_read(
71 uint8_t lun, // logical unit number
72 uint32_t blk_addr, // address of 1st block to be read
73 uint8_t *buf, // Pointer to the buffer to save data
74 uint32_t blk_len) // nmber of blocks to be read
76 UNUSED(lun);
77 //mscSetActive();
78 emfat_read(&emfat, buf, blk_addr/SCSI_BLOCK_SIZE , blk_len/SCSI_BLOCK_SIZE);
79 return USB_OK;
82 usb_sts_type msc_disk_write(uint8_t lun,
83 uint32_t blk_addr,
84 uint8_t *buf,
85 uint32_t blk_len)
87 UNUSED(lun);
88 UNUSED(buf);
89 UNUSED(blk_addr);
90 UNUSED(blk_len);
92 return USB_FAIL;
96 /**
97 * @brief get disk inquiry
98 * @param lun: logical units number
99 * @retval inquiry string
101 uint8_t * get_inquiry(uint8_t lun)
103 if(lun < MSC_SUPPORT_MAX_LUN)
104 return (uint8_t *)scsi_inquiry[lun];
105 else
106 return NULL;