diff options
| author | hathach <[email protected]> | 2018-04-18 18:05:08 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-04-18 18:05:08 +0700 |
| commit | 8c0a5f7d3b093102662798fa89799d0af76d0608 (patch) | |
| tree | a4709b3a121de41d3ee2a5678baefcbd7ea24cdc /examples | |
| parent | a9ada8ea5ee3cc7d130c489da1a30c9e68c586b9 (diff) | |
update nrf52840 examples
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/device/nrf52840/src/msc_device_app.c | 49 | ||||
| -rw-r--r-- | examples/device/nrf52840/src/msc_device_ramdisk.c | 4 | ||||
| -rw-r--r-- | examples/device/nrf52840/src/tusb_config.h | 35 |
3 files changed, 52 insertions, 36 deletions
diff --git a/examples/device/nrf52840/src/msc_device_app.c b/examples/device/nrf52840/src/msc_device_app.c index 1730975dd..5fc3f20f8 100644 --- a/examples/device/nrf52840/src/msc_device_app.c +++ b/examples/device/nrf52840/src/msc_device_app.c @@ -98,47 +98,62 @@ void msc_app_umount(uint8_t rhport) } -msc_csw_status_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t scsi_cmd[16], void const ** pp_buffer, uint16_t* p_length) +bool tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t scsi_cmd[16], void* buffer, uint16_t* p_len) { // read10 & write10 has their own callback and MUST not be handled here + + void* bufptr = NULL; + uint16_t buflen = 0; + switch (scsi_cmd[0]) { case SCSI_CMD_INQUIRY: - (*pp_buffer) = &mscd_inquiry_data; - (*p_length) = sizeof(scsi_inquiry_data_t); + bufptr = &mscd_inquiry_data; + buflen = sizeof(scsi_inquiry_data_t); break; case SCSI_CMD_READ_CAPACITY_10: - (*pp_buffer) = &mscd_read_capacity10_data; - (*p_length) = sizeof(scsi_read_capacity10_data_t); + bufptr = &mscd_read_capacity10_data; + buflen = sizeof(scsi_read_capacity10_data_t); break; case SCSI_CMD_REQUEST_SENSE: - (*pp_buffer) = &mscd_sense_data; - (*p_length) = sizeof(scsi_sense_fixed_data_t); + bufptr = &mscd_sense_data; + buflen = sizeof(scsi_sense_fixed_data_t); break; case SCSI_CMD_READ_FORMAT_CAPACITY: - (*pp_buffer) = &mscd_format_capacity_data; - (*p_length) = sizeof(scsi_read_format_capacity_data_t); + bufptr = &mscd_format_capacity_data; + buflen = sizeof(scsi_read_format_capacity_data_t); break; case SCSI_CMD_MODE_SENSE_6: - (*pp_buffer) = &msc_dev_mode_para; - (*p_length) = sizeof(msc_dev_mode_para); + bufptr = &msc_dev_mode_para; + buflen = sizeof(msc_dev_mode_para); break; case SCSI_CMD_TEST_UNIT_READY: - (*pp_buffer) = NULL; - (*p_length) = 0; + bufptr = NULL; + buflen= 0; break; case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: - (*pp_buffer) = NULL; - (*p_length) = 0; + bufptr = NULL; + buflen= 0; break; - default: return MSC_CSW_STATUS_FAILED; + default: + (*p_len) = 0; + return false; + } + + if ( bufptr && buflen ) + { + // Response len must not larger than expected from host + TU_ASSERT( (*p_len) >= buflen ); + + memcpy(buffer, bufptr, buflen); + (*p_len) = buflen; } //------------- clear sense data if it is not request sense command -------------// @@ -149,7 +164,7 @@ msc_csw_status_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t scsi_cmd[ mscd_sense_data.additional_sense_qualifier = 0; } - return MSC_CSW_STATUS_PASSED; + return true; } //--------------------------------------------------------------------+ diff --git a/examples/device/nrf52840/src/msc_device_ramdisk.c b/examples/device/nrf52840/src/msc_device_ramdisk.c index bb9c53e4c..8e34942d6 100644 --- a/examples/device/nrf52840/src/msc_device_ramdisk.c +++ b/examples/device/nrf52840/src/msc_device_ramdisk.c @@ -91,13 +91,13 @@ uint8_t msc_device_ramdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] = //--------------------------------------------------------------------+ // IMPLEMENTATION //--------------------------------------------------------------------+ -uint16_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) +uint16_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer) { (*pp_buffer) = msc_device_ramdisk[lba]; return min16_of(block_count, DISK_BLOCK_NUM); } -uint16_t tud_msc_write10_cb(uint8_t rhport, uint8_t lun, void** pp_buffer, uint32_t lba, uint16_t block_count) +uint16_t tud_msc_write10_cb(uint8_t rhport, uint8_t lun, uint32_t lba, uint16_t block_count, void** pp_buffer) { (*pp_buffer) = msc_device_ramdisk[lba]; diff --git a/examples/device/nrf52840/src/tusb_config.h b/examples/device/nrf52840/src/tusb_config.h index a885ab89f..86e3698f8 100644 --- a/examples/device/nrf52840/src/tusb_config.h +++ b/examples/device/nrf52840/src/tusb_config.h @@ -46,10 +46,14 @@ //--------------------------------------------------------------------+ // CONTROLLER CONFIGURATION //--------------------------------------------------------------------+ -//#define CFG_TUSB_MCU will be passed from IDE/command line for easy board/mcu switching +#define CFG_TUSB_MCU OPT_MCU_NRF5X +#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE + +#define CFG_TUSB_DEBUG 2 + +#define CFG_TUSB_OS OPT_OS_NONE // be passed from IDE/command line for easy project switching +//#define CFG_TUD_TASK_PRIO 0 // be passed from IDE/command line for easy project switching -#define CFG_TUSB_MCU OPT_MCU_NRF5X -#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE) //--------------------------------------------------------------------+ // DEVICE CONFIGURATION @@ -63,27 +67,24 @@ #define CFG_TUD_MSC 1 #define CFG_TUD_CDC 1 -//--------------------------------------------------------------------+ -// COMMON CONFIGURATION -//--------------------------------------------------------------------+ -#define CFG_TUSB_DEBUG 2 +/*------------------------------------------------------------------*/ +/* CLASS DRIVER + *------------------------------------------------------------------*/ + +// FIFO size of CDC TX and RX +#define CFG_TUD_CDC_BUFSIZE 64 + +// TX is sent automatically every Start of Frame event. +// If not enabled, application must call tud_cdc_flush() periodically +#define CFG_TUD_CDC_FLUSH_ON_SOF 1 -#define CFG_TUSB_OS OPT_OS_NONE // be passed from IDE/command line for easy project switching -//#define CFG_TUD_TASK_PRIO 0 // be passed from IDE/command line for easy project switching //--------------------------------------------------------------------+ // USB RAM PLACEMENT //--------------------------------------------------------------------+ #define CFG_TUSB_ATTR_USBRAM +#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) -// LPC11uxx and LPC13uxx requires each buffer has to be 64-byte alignment -#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX - #define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(64) -#elif CFG_TUSB_MCU == OPT_MCU_NRF5X - #define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) -#else - #define CFG_TUSB_MEM_ALIGN -#endif #ifdef __cplusplus } |
