Microchip® Advanced Software Framework

device_mass_storage_task.c File Reference
#include "conf_usb.h"
#include "board.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#include "usb_drv.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "ctrl_access.h"
#include "scsi_decoder.h"
#include "device_mass_storage_task.h"
#include "supervisor.h"

Functions

void device_mass_storage_task (void *pvParameters)
 Entry point of the device mass-storage task management. More...
 
void device_mass_storage_task_init (void)
 This function initializes the hardware/software resources required for device mass-storage task. More...
 
static void usb_mass_storage_cbw (void)
 USB Command Block Wrapper (CBW) management. More...
 
static void usb_mass_storage_csw (void)
 USB Command Status Wrapper (CSW) management. More...
 
void usb_sof_action (void)
 usb_sof_action More...
 

Variables

static U32 dCBWTag
 
U8 ms_endpoint
 
volatile bool ms_multiple_drive
 
static U16 sof_cnt
 
U8 usb_LUN
 
static portBASE_TYPE xGiveUsbMutex = pdFALSE
 
xSemaphoreHandle xUSBMutex
 

void device_mass_storage_task ( void pvParameters)

Entry point of the device mass-storage task management.

This function links the device mass-storage SCSI commands to the USB bus.

Parameters
pvParametersInput. Unused.

References configTSK_USB_DMS_PERIOD, EP_MS_OUT, Is_device_enumerated, Is_usb_out_received, usb_mass_storage_cbw(), usb_mass_storage_csw(), vTaskDelayUntil(), and xTaskGetTickCount().

Referenced by device_mass_storage_task_init().

void device_mass_storage_task_init ( void  )

This function initializes the hardware/software resources required for device mass-storage task.

References configTSK_USB_DMS_NAME, configTSK_USB_DMS_PRIORITY, configTSK_USB_DMS_STACK_SIZE, device_mass_storage_task(), EP_MS_IN, EP_MS_OUT, g_scsi_ep_ms_in, g_scsi_ep_ms_out, NULL, sof_cnt, and xTaskCreate.

Referenced by b_usbsys_start().

static void usb_mass_storage_cbw ( void  )
static

USB Command Block Wrapper (CBW) management.

This function decodes the CBW command and stores the SCSI command.

Check if dCBWSignature is correct

Store CBW Tag to be repeated in CSW

if (bmCBWFlags.bit7 == 1) {direction = IN;}

Dummy CBWCBLength read

Store scsi_command

References dCBWTag, EP_MS_IN, EP_MS_OUT, g_scsi_command, g_scsi_data_remaining, get_cur_lun(), ms_endpoint, ms_multiple_drive, NULL, pdFALSE, scsi_decode_command(), Usb_ack_out_received_free, Usb_enable_stall_handshake, usb_format_usb_to_mcu_data, usb_LUN, Usb_read_endpoint_data, usb_read_ep_rxpacket(), Usb_reset_endpoint_fifo_access, x_supervisor_SemaphoreTake(), and xGiveUsbMutex.

Referenced by device_mass_storage_task().

static void usb_mass_storage_csw ( void  )
static

USB Command Status Wrapper (CSW) management.

This function sends the status in relation with the last CBW.

Write CSW Signature

Write stored CBW Tag

Write data residual value

Write command status

References dCBWTag, EP_MS_IN, EP_MS_OUT, g_scsi_data_remaining, g_scsi_status, Is_usb_endpoint_stall_requested, Is_usb_in_ready, Is_usb_out_received, Is_usb_setup_received, Usb_ack_in_ready_send, Usb_ack_out_received_free, usb_format_mcu_to_usb_data, Usb_nb_busy_bank, usb_process_request(), Usb_reset_endpoint_fifo_access, Usb_write_endpoint_data, x_supervisor_SemaphoreGive(), and xGiveUsbMutex.

Referenced by device_mass_storage_task().

U32 dCBWTag
static
U8 ms_endpoint
volatile bool ms_multiple_drive
U16 sof_cnt
static
portBASE_TYPE xGiveUsbMutex = pdFALSE
static
xSemaphoreHandle xUSBMutex

The USB system mutex.