More refactoring in Upstream project

pull/7/head
Robert Fisk 9 years ago
parent 4350666330
commit b271e038a3

@ -109,7 +109,7 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="Src/upstream_interface_msc.c|Src/downstream_interface_msc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_crc.c|Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_storage_template.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_wwdg.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_usart.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_smartcard.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sai.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pccard.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_nor.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_nand.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_irda.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hash.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hash_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma2d.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dcmi.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_msp_template.c|Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_conf_template.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry excluding="Src/upstream_msc.c|Src/upstream_interface_msc.c|Src/downstream_interface_msc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_crc.c|Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_storage_template.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_wwdg.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_usart.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_smartcard.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sai.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pccard.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_nor.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_nand.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_irda.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hash.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hash_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma2d.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dcmi.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_msp_template.c|Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_conf_template.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
@ -234,7 +234,7 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="Src/upstream_interface_msc.c|Src/downstream_interface_msc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_crc.c|Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_storage_template.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_wwdg.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_usart.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_smartcard.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sai.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pccard.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_nor.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_nand.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_irda.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hash.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hash_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma2d.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dcmi.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_msp_template.c|Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_conf_template.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry excluding="Src/upstream_msc.c|Src/upstream_interface_msc.c|Src/downstream_interface_msc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_crc.c|Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_storage_template.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_wwdg.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_usart.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_smartcard.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sai.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rng.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pccard.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_nor.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_nand.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_iwdg.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_irda.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hash.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hash_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_eth.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma2d.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dcmi.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c|Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_msp_template.c|Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_conf_template.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>

@ -1,5 +1,5 @@
/*
* interface_def.h
* upstream_interface_def.h
*
* Created on: 22/06/2015
* Author: Robert Fisk
@ -25,20 +25,26 @@
typedef enum
{
COMMAND_CLASS_INTERFACE = 0,
COMMAND_CLASS_MASS_STORAGE = 1,
COMMAND_CLASS_MAX = 2,
COMMAND_CLASS_INTERFACE,
COMMAND_CLASS_MASS_STORAGE
}
InterfaceCommandClassTypeDef;
typedef enum
{
COMMAND_MSC_TEST_UNIT_READY = 0, //Returns HAL_StatusTypeDef result
COMMAND_MSC_GET_CAPACITY = 2, //Returns uint32_t blk_nbr, uint32_t blk_size
COMMAND_MSC_BEGIN_READ = 3, //Returns HAL_StatusTypeDef result, then data stream
COMMAND_MSC_BEGIN_WRITE = 4, //Returns HAL_OK, HAL_ERROR if medium not present, HAL_BUSY if write-protected result, then waits for data stream
COMMAND_MSC_MAX = 5,
COMMAND_INTERFACE_ECHO, //Returns echo packet including all data
COMMAND_INTERFACE_NOTIFY_DEVICE //Returns COMMAND_CLASS_*** byte when downstream USB device is connected
}
InterfaceCommandInterfaceTypeDef;
typedef enum
{
COMMAND_MSC_TEST_UNIT_READY, //Returns HAL_StatusTypeDef result
COMMAND_MSC_GET_CAPACITY, //Returns uint32_t blk_nbr, uint32_t blk_size
COMMAND_MSC_BEGIN_READ, //Returns HAL_StatusTypeDef result, then data stream
COMMAND_MSC_BEGIN_WRITE, //Returns HAL_OK, HAL_ERROR if medium not present, HAL_BUSY if write-protected result, then waits for data stream
}
InterfaceCommandMscTypeDef;

@ -1,39 +0,0 @@
/*
* upstream_interface_msc.h
*
* Created on: 4/07/2015
* Author: Robert Fisk
*/
#ifndef INC_UPSTREAM_INTERFACE_MSC_H_
#define INC_UPSTREAM_INTERFACE_MSC_H_
#include <upstream_spi.h>
typedef void (*UpstreamInterfaceMSCCallbackTypeDef)(HAL_StatusTypeDef result);
typedef void (*UpstreamInterfaceMSCCallbackPacketTypeDef)(HAL_StatusTypeDef result,
UpstreamPacketTypeDef* upstreamPacket,
uint16_t dataLength);
typedef void (*UpstreamInterfaceMSCCallbackUintPacketTypeDef)(HAL_StatusTypeDef result,
uint32_t result_uint[],
UpstreamPacketTypeDef* upstreamPacket);
HAL_StatusTypeDef UpstreamInterface_TestReady(UpstreamInterfaceMSCCallbackTypeDef callback);
HAL_StatusTypeDef UpstreamInterface_GetCapacity(UpstreamInterfaceMSCCallbackUintPacketTypeDef callback);
HAL_StatusTypeDef UpstreamInterface_BeginRead(UpstreamInterfaceMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount,
uint32_t readByteCount);
HAL_StatusTypeDef UpstreamInterface_GetStreamDataPacket(UpstreamInterfaceMSCCallbackPacketTypeDef callback);
HAL_StatusTypeDef UpstreamInterface_BeginWrite(UpstreamInterfaceMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount);
HAL_StatusTypeDef UpstreamInterface_PutStreamDataPacket(UpstreamPacketTypeDef* packetToSend,
uint32_t dataLength);
#endif /* INC_UPSTREAM_INTERFACE_MSC_H_ */

@ -0,0 +1,39 @@
/*
* upstream_msc.h
*
* Created on: 4/07/2015
* Author: Robert Fisk
*/
#ifndef INC_UPSTREAM_MSC_H_
#define INC_UPSTREAM_MSC_H_
#include <upstream_spi.h>
typedef void (*UpstreamMSCCallbackTypeDef)(HAL_StatusTypeDef result);
typedef void (*UpstreamMSCCallbackPacketTypeDef)(HAL_StatusTypeDef result,
UpstreamPacketTypeDef* upstreamPacket,
uint16_t dataLength);
typedef void (*UpstreamMSCCallbackUintPacketTypeDef)(HAL_StatusTypeDef result,
uint32_t result_uint[],
UpstreamPacketTypeDef* upstreamPacket);
HAL_StatusTypeDef Upstream_MSC_TestReady(UpstreamMSCCallbackTypeDef callback);
HAL_StatusTypeDef Upstream_MSC_GetCapacity(UpstreamMSCCallbackUintPacketTypeDef callback);
HAL_StatusTypeDef Upstream_MSC_BeginRead(UpstreamMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount,
uint32_t readByteCount);
HAL_StatusTypeDef Upstream_MSC_GetStreamDataPacket(UpstreamMSCCallbackPacketTypeDef callback);
HAL_StatusTypeDef Upstream_MSC_BeginWrite(UpstreamMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount);
HAL_StatusTypeDef Upstream_MSC_PutStreamDataPacket(UpstreamPacketTypeDef* packetToSend,
uint32_t dataLength);
#endif /* INC_UPSTREAM_MSC_H_ */

@ -17,26 +17,32 @@
#define UPSTREAM_PACKET_LEN_MIN (UPSTREAM_PACKET_HEADER_LEN)
#define SPI_INTERFACE_FREAKOUT_VOID \
#define SPI_INTERFACE_FREAKOUT_RETURN_VOID \
do { \
while (1); \
/*UpstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
/*UpstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
/*return;*/ \
} while (0);
#define SPI_INTERFACE_FREAKOUT_HAL_ERROR \
#define SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR \
do { \
while (1); \
/*UpstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
/*UpstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
/*return HAL_ERROR;*/ \
} while (0);
#define SPI_INTERFACE_FREAKOUT_NO_RETURN \
do { \
while (1); \
/*while (1);*/ \
} while (0);
typedef enum
{
UPSTREAM_INTERFACE_RESET,
UPSTREAM_INTERFACE_WAITING_CLIENT,
UPSTREAM_INTERFACE_AWAITING_DEVICE,
UPSTREAM_INTERFACE_IDLE,
UPSTREAM_INTERFACE_TX_SIZE_WAIT,
UPSTREAM_INTERFACE_TX_SIZE,
@ -47,14 +53,16 @@ typedef enum
UPSTREAM_INTERFACE_RX_PACKET_WAIT,
UPSTREAM_INTERFACE_RX_PACKET,
UPSTREAM_INTERFACE_ERROR
} InterfaceStateTypeDef;
}
InterfaceStateTypeDef;
typedef enum
{
NOT_BUSY,
BUSY
} PacketBusyTypeDef;
}
PacketBusyTypeDef;
typedef struct
@ -78,8 +86,8 @@ void Upstream_InitSPI(void);
HAL_StatusTypeDef Upstream_GetFreePacket(FreePacketCallbackTypeDef callback);
UpstreamPacketTypeDef* Upstream_GetFreePacketImmediately(void);
void Upstream_ReleasePacket(UpstreamPacketTypeDef* packetToRelease);
HAL_StatusTypeDef Upstream_SendPacket(UpstreamPacketTypeDef* packetToWrite);
HAL_StatusTypeDef Upstream_GetPacket(SpiPacketReceivedCallbackTypeDef callback);
HAL_StatusTypeDef Upstream_TransmitPacket(UpstreamPacketTypeDef* packetToWrite);
HAL_StatusTypeDef Upstream_ReceivePacket(SpiPacketReceivedCallbackTypeDef callback);
void Upstream_TxOkInterrupt(void);
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi);

@ -27,7 +27,7 @@
/* Includes ------------------------------------------------------------------*/
#include <upstream_interface_def.h>
#include <upstream_interface_msc.h>
#include <upstream_msc.h>
#include <upstream_spi.h>
#include "usbd_msc_bot.h"
#include "usbd_msc_scsi.h"
@ -234,7 +234,7 @@ void SCSI_TestUnitReady(void)
return;
}
if (UpstreamInterface_TestReady(SCSI_TestUnitReadyCallback) != HAL_OK)
if (Upstream_MSC_TestReady(SCSI_TestUnitReadyCallback) != HAL_OK)
{
SCSI_TestUnitReadyCallback(HAL_ERROR);
}
@ -314,7 +314,7 @@ static void SCSI_Inquiry(void)
*/
static void SCSI_ReadCapacity10(void)
{
if (UpstreamInterface_GetCapacity(SCSI_ReadCapacity10Callback) != HAL_OK)
if (Upstream_MSC_GetCapacity(SCSI_ReadCapacity10Callback) != HAL_OK)
{
SCSI_ReadCapacity10Callback(HAL_ERROR, NULL, NULL);
}
@ -364,7 +364,7 @@ void SCSI_ReadCapacity10Callback(HAL_StatusTypeDef result,
*/
static void SCSI_ReadFormatCapacity(void)
{
if (UpstreamInterface_GetCapacity(SCSI_ReadFormatCapacityCallback) != HAL_OK)
if (Upstream_MSC_GetCapacity(SCSI_ReadFormatCapacityCallback) != HAL_OK)
{
SCSI_ReadFormatCapacityCallback(HAL_ERROR, NULL, NULL);
}
@ -589,7 +589,7 @@ static void SCSI_Read10(void)
return;
}
if (UpstreamInterface_BeginRead(SCSI_Read10BeginCallback,
if (Upstream_MSC_BeginRead(SCSI_Read10BeginCallback,
SCSI_ProcessCmd_hmsc->scsi_blk_addr,
SCSI_ProcessCmd_hmsc->scsi_blk_len,
SCSI_ProcessCmd_hmsc->cbw.dDataLength) != HAL_OK)
@ -600,7 +600,7 @@ static void SCSI_Read10(void)
}
//hmsc->bot_state is already USBD_BOT_DATA_IN
if (UpstreamInterface_GetStreamDataPacket(SCSI_Read10ReplyCallback) != HAL_OK)
if (Upstream_MSC_GetStreamDataPacket(SCSI_Read10ReplyCallback) != HAL_OK)
{
SCSI_Read10ReplyCallback(HAL_ERROR, NULL, 0);
}
@ -620,7 +620,7 @@ void SCSI_Read10BeginCallback(HAL_StatusTypeDef result)
}
SCSI_ProcessCmd_hmsc->bot_state = USBD_BOT_DATA_IN;
if (UpstreamInterface_GetStreamDataPacket(SCSI_Read10ReplyCallback) != HAL_OK)
if (Upstream_MSC_GetStreamDataPacket(SCSI_Read10ReplyCallback) != HAL_OK)
{
SCSI_Read10ReplyCallback(HAL_ERROR, NULL, 0);
}
@ -716,7 +716,7 @@ static void SCSI_Write10(void)
return;
}
if (UpstreamInterface_BeginWrite(SCSI_Write10BeginCallback,
if (Upstream_MSC_BeginWrite(SCSI_Write10BeginCallback,
SCSI_ProcessCmd_hmsc->scsi_blk_addr,
SCSI_ProcessCmd_hmsc->scsi_blk_len) != HAL_OK)
{
@ -728,7 +728,7 @@ static void SCSI_Write10(void)
//hmsc->bot_state is already USBD_BOT_DATA_OUT
dataLength = MIN(SCSI_ProcessCmd_hmsc->csw.dDataResidue, MSC_MEDIA_PACKET);
if (UpstreamInterface_PutStreamDataPacket(SCSI_ProcessCmd_hmsc->bot_packet,
if (Upstream_MSC_PutStreamDataPacket(SCSI_ProcessCmd_hmsc->bot_packet,
dataLength) != HAL_OK)
{
SCSI_SenseCode(SCSI_ProcessCmd_pdev,

@ -1,5 +1,5 @@
/*
* upstream_interface_msc.c
* upstream_msc.c
*
* Created on: 4/07/2015
* Author: Robert Fisk
@ -7,28 +7,28 @@
#include <upstream_interface_def.h>
#include <upstream_interface_msc.h>
#include <upstream_msc.h>
#include <upstream_spi.h>
#include "stm32f4xx_hal.h"
//Stuff we need to save for our callbacks to use:
UpstreamInterfaceMSCCallbackTypeDef TestReadyCallback;
UpstreamInterfaceMSCCallbackUintPacketTypeDef GetCapacityCallback;
UpstreamInterfaceMSCCallbackPacketTypeDef GetStreamDataCallback;
uint32_t ByteCount;
UpstreamPacketTypeDef* ReadStreamPacket;
uint8_t ReadStreamBusy;
UpstreamMSCCallbackTypeDef TestReadyCallback;
UpstreamMSCCallbackUintPacketTypeDef GetCapacityCallback;
UpstreamMSCCallbackPacketTypeDef GetStreamDataCallback;
uint32_t ByteCount;
UpstreamPacketTypeDef* ReadStreamPacket;
uint8_t ReadStreamBusy;
static void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket);
static void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void Upstream_MSC_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void Upstream_MSC_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void Upstream_MSC_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket);
static void Upstream_MSC_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket);
HAL_StatusTypeDef UpstreamInterface_TestReady(UpstreamInterfaceMSCCallbackTypeDef callback)
HAL_StatusTypeDef Upstream_MSC_TestReady(UpstreamMSCCallbackTypeDef callback)
{
UpstreamPacketTypeDef* freePacket;
HAL_StatusTypeDef tempResult;
@ -39,15 +39,16 @@ HAL_StatusTypeDef UpstreamInterface_TestReady(UpstreamInterfaceMSCCallbackTypeDe
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN;
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
freePacket->Command = COMMAND_MSC_TEST_UNIT_READY;
tempResult = Upstream_SendPacket(freePacket);
tempResult = Upstream_TransmitPacket(freePacket);
if (tempResult != HAL_OK)
{
return tempResult;
}
return Upstream_GetPacket(UpstreamInterface_TestReadyReplyCallback);
return Upstream_ReceivePacket(Upstream_MSC_TestReadyReplyCallback);
}
void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket)
void Upstream_MSC_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket)
{
if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 1)) ||
(replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
@ -64,7 +65,7 @@ void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket
HAL_StatusTypeDef UpstreamInterface_GetCapacity(UpstreamInterfaceMSCCallbackUintPacketTypeDef callback)
HAL_StatusTypeDef Upstream_MSC_GetCapacity(UpstreamMSCCallbackUintPacketTypeDef callback)
{
UpstreamPacketTypeDef* freePacket;
HAL_StatusTypeDef tempResult;
@ -75,15 +76,16 @@ HAL_StatusTypeDef UpstreamInterface_GetCapacity(UpstreamInterfaceMSCCallbackUint
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN;
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
freePacket->Command = COMMAND_MSC_GET_CAPACITY;
tempResult = Upstream_SendPacket(freePacket);
tempResult = Upstream_TransmitPacket(freePacket);
if (tempResult != HAL_OK)
{
return tempResult;
}
return Upstream_GetPacket(UpstreamInterface_GetCapacityReplyCallback);
return Upstream_ReceivePacket(Upstream_MSC_GetCapacityReplyCallback);
}
void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket)
void Upstream_MSC_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket)
{
uint32_t uint[2];
@ -101,10 +103,10 @@ void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPack
HAL_StatusTypeDef UpstreamInterface_BeginRead(UpstreamInterfaceMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount,
uint32_t readByteCount)
HAL_StatusTypeDef Upstream_MSC_BeginRead(UpstreamMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount,
uint32_t readByteCount)
{
UpstreamPacketTypeDef* freePacket;
HAL_StatusTypeDef tempResult;
@ -122,17 +124,17 @@ HAL_StatusTypeDef UpstreamInterface_BeginRead(UpstreamInterfaceMSCCallbackTypeDe
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
tempResult = Upstream_SendPacket(freePacket);
tempResult = Upstream_TransmitPacket(freePacket);
if (tempResult != HAL_OK)
{
TestReadyCallback(tempResult);
}
return Upstream_GetPacket(UpstreamInterface_TestReadyReplyCallback); //Re-use TestReadyReplyCallback because it does exactly what we want!
return Upstream_ReceivePacket(Upstream_MSC_TestReadyReplyCallback); //Re-use TestReadyReplyCallback because it does exactly what we want!
}
HAL_StatusTypeDef UpstreamInterface_GetStreamDataPacket(UpstreamInterfaceMSCCallbackPacketTypeDef callback)
HAL_StatusTypeDef Upstream_MSC_GetStreamDataPacket(UpstreamMSCCallbackPacketTypeDef callback)
{
GetStreamDataCallback = callback;
@ -144,14 +146,15 @@ HAL_StatusTypeDef UpstreamInterface_GetStreamDataPacket(UpstreamInterfaceMSCCall
if (ReadStreamPacket && GetStreamDataCallback) //Do we have a stored packet and an address to send it?
{
UpstreamInterface_GetStreamDataPacketCallback(ReadStreamPacket); //Send it now!
Upstream_MSC_GetStreamDataPacketCallback(ReadStreamPacket); //Send it now!
ReadStreamPacket = NULL;
return HAL_OK; //Our callback will call us again, so we don't need to get a packet in this case.
}
return Upstream_GetPacket(UpstreamInterface_GetStreamDataPacketCallback);
return Upstream_ReceivePacket(Upstream_MSC_GetStreamDataPacketCallback);
}
void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket)
void Upstream_MSC_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket)
{
uint16_t dataLength;
@ -175,15 +178,15 @@ void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyP
GetStreamDataCallback(HAL_OK, replyPacket, dataLength); //usb_msc_scsi will use this packet, so don't release now
if (ByteCount > 0)
{
UpstreamInterface_GetStreamDataPacket(NULL); //Try to get the next packet now, before USB asks for it
Upstream_MSC_GetStreamDataPacket(NULL); //Try to get the next packet now, before USB asks for it
}
}
HAL_StatusTypeDef UpstreamInterface_BeginWrite(UpstreamInterfaceMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount)
HAL_StatusTypeDef Upstream_MSC_BeginWrite(UpstreamMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount)
{
UpstreamPacketTypeDef* freePacket;
HAL_StatusTypeDef tempResult;
@ -197,15 +200,16 @@ HAL_StatusTypeDef UpstreamInterface_BeginWrite(UpstreamInterfaceMSCCallbackTypeD
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
tempResult = Upstream_SendPacket(freePacket);
tempResult = Upstream_TransmitPacket(freePacket);
if (tempResult != HAL_OK)
{
TestReadyCallback(tempResult);
}
return Upstream_GetPacket(UpstreamInterface_BeginWriteReplyCallback);
return Upstream_ReceivePacket(Upstream_MSC_BeginWriteReplyCallback);
}
void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket)
void Upstream_MSC_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket)
{
if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 1)) ||
(replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
@ -222,11 +226,12 @@ void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacke
HAL_StatusTypeDef UpstreamInterface_PutStreamDataPacket(UpstreamPacketTypeDef* packetToSend,
uint32_t dataLength)
HAL_StatusTypeDef Upstream_MSC_PutStreamDataPacket(UpstreamPacketTypeDef* packetToSend,
uint32_t dataLength)
{
packetToSend->Length = dataLength + UPSTREAM_PACKET_HEADER_LEN;
packetToSend->CommandClass = COMMAND_CLASS_MASS_STORAGE | COMMAND_CLASS_DATA_FLAG;
packetToSend->Command = COMMAND_MSC_BEGIN_WRITE;
return Upstream_SendPacket(packetToSend);
return Upstream_TransmitPacket(packetToSend);
}

@ -1,38 +1,38 @@
/*
* upstream_interface_msc_mock.c
* upstream_msc_mock.c
*
* Created on: 17/07/2015
* Author: Robert Fisk
*
* This file replaces upstream_interface_msc.c to allow operational
* testing of Upstream, without Upstream in place and communicating
* over SPI. It still attempts to write downstream packets out the SPI port.
* This file replaces upstream_msc.c to allow operational testing of Upstream,
* without Upstream in place and communicating over SPI.
* It still attempts to write downstream packets out the SPI port.
*/
#include <upstream_interface_def.h>
#include <upstream_interface_msc.h>
#include <upstream_msc.h>
#include <upstream_spi.h>
#include "stm32f4xx_hal.h"
//Stuff we need to save for our callbacks to use:
UpstreamInterfaceMSCCallbackTypeDef TestReadyCallback;
UpstreamInterfaceMSCCallbackUintPacketTypeDef GetCapacityCallback;
UpstreamInterfaceMSCCallbackPacketTypeDef GetStreamDataCallback;
uint32_t ByteCount;
UpstreamPacketTypeDef* ReadStreamPacket;
uint8_t ReadStreamBusy;
UpstreamMSCCallbackTypeDef TestReadyCallback;
UpstreamMSCCallbackUintPacketTypeDef GetCapacityCallback;
UpstreamMSCCallbackPacketTypeDef GetStreamDataCallback;
uint32_t ByteCount;
UpstreamPacketTypeDef* ReadStreamPacket;
uint8_t ReadStreamBusy;
static void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket);
static void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void Upstream_MSC_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void Upstream_MSC_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket);
static void Upstream_MSC_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket);
static void Upstream_MSC_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket);
HAL_StatusTypeDef UpstreamInterface_TestReady(UpstreamInterfaceMSCCallbackTypeDef callback)
HAL_StatusTypeDef Upstream_MSC_TestReady(UpstreamMSCCallbackTypeDef callback)
{
UpstreamPacketTypeDef* freePacket;
HAL_StatusTypeDef tempResult;
@ -43,16 +43,16 @@ HAL_StatusTypeDef UpstreamInterface_TestReady(UpstreamInterfaceMSCCallbackTypeDe
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN;
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
freePacket->Command = COMMAND_MSC_TEST_UNIT_READY;
tempResult = Upstream_SendPacket(freePacket);
tempResult = Upstream_TransmitPacket(freePacket);
if (tempResult != HAL_OK)
{
return tempResult;
}
//return Upstream_GetPacket(UpstreamInterface_TestReadyReplyCallback);
return Upstream_GetFreePacket(UpstreamInterface_TestReadyReplyCallback);
//return Upstream_GetPacket(Upstream_MSC_TestReadyReplyCallback);
return Upstream_GetFreePacket(Upstream_MSC_TestReadyReplyCallback);
}
void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket)
void Upstream_MSC_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket)
{
// if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 1)) ||
// (replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
@ -69,7 +69,7 @@ void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket
HAL_StatusTypeDef UpstreamInterface_GetCapacity(UpstreamInterfaceMSCCallbackUintPacketTypeDef callback)
HAL_StatusTypeDef Upstream_MSC_GetCapacity(UpstreamMSCCallbackUintPacketTypeDef callback)
{
UpstreamPacketTypeDef* freePacket;
HAL_StatusTypeDef tempResult;
@ -80,16 +80,17 @@ HAL_StatusTypeDef UpstreamInterface_GetCapacity(UpstreamInterfaceMSCCallbackUint
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN;
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
freePacket->Command = COMMAND_MSC_GET_CAPACITY;
tempResult = Upstream_SendPacket(freePacket);
tempResult = Upstream_TransmitPacket(freePacket);
if (tempResult != HAL_OK)
{
return tempResult;
}
//return Upstream_GetPacket(UpstreamInterface_GetCapacityReplyCallback);
return Upstream_GetFreePacket(UpstreamInterface_GetCapacityReplyCallback);
//return Upstream_GetPacket(Upstream_MSC_GetCapacityReplyCallback);
return Upstream_GetFreePacket(Upstream_MSC_GetCapacityReplyCallback);
}
void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket)
void Upstream_MSC_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket)
{
uint32_t uint[2];
@ -109,10 +110,10 @@ void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPack
HAL_StatusTypeDef UpstreamInterface_BeginRead(UpstreamInterfaceMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount,
uint32_t readByteCount)
HAL_StatusTypeDef Upstream_MSC_BeginRead(UpstreamMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount,
uint32_t readByteCount)
{
UpstreamPacketTypeDef* freePacket;
HAL_StatusTypeDef tempResult;
@ -130,18 +131,18 @@ HAL_StatusTypeDef UpstreamInterface_BeginRead(UpstreamInterfaceMSCCallbackTypeDe
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
tempResult = Upstream_SendPacket(freePacket);
tempResult = Upstream_TransmitPacket(freePacket);
if (tempResult != HAL_OK)
{
TestReadyCallback(tempResult);
}
//return Upstream_GetPacket(UpstreamInterface_TestReadyReplyCallback); //Re-use TestReadyReplyCallback because it does exactly what we want!
return Upstream_GetFreePacket(UpstreamInterface_TestReadyReplyCallback);
//return Upstream_GetPacket(Upstream_MSC_TestReadyReplyCallback); //Re-use TestReadyReplyCallback because it does exactly what we want!
return Upstream_GetFreePacket(Upstream_MSC_TestReadyReplyCallback);
}
HAL_StatusTypeDef UpstreamInterface_GetStreamDataPacket(UpstreamInterfaceMSCCallbackPacketTypeDef callback)
HAL_StatusTypeDef Upstream_MSC_GetStreamDataPacket(UpstreamMSCCallbackPacketTypeDef callback)
{
GetStreamDataCallback = callback;
@ -153,15 +154,16 @@ HAL_StatusTypeDef UpstreamInterface_GetStreamDataPacket(UpstreamInterfaceMSCCall
if (ReadStreamPacket && GetStreamDataCallback) //Do we have a stored packet and an address to send it?
{
UpstreamInterface_GetStreamDataPacketCallback(ReadStreamPacket); //Send it now!
Upstream_MSC_GetStreamDataPacketCallback(ReadStreamPacket); //Send it now!
ReadStreamPacket = NULL;
return HAL_OK; //Our callback will call us again, so we don't need to get a packet in this case.
}
//return Upstream_GetPacket(UpstreamInterface_GetStreamDataPacketCallback);
return Upstream_GetFreePacket(UpstreamInterface_GetStreamDataPacketCallback);
//return Upstream_GetPacket(Upstream_MSC_GetStreamDataPacketCallback);
return Upstream_GetFreePacket(Upstream_MSC_GetStreamDataPacketCallback);
}
void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket)
void Upstream_MSC_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket)
{
uint16_t dataLength;
@ -187,15 +189,15 @@ void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyP
GetStreamDataCallback(HAL_OK, replyPacket, dataLength); //usb_msc_scsi will use this packet, so don't release now
if (ByteCount > 0)
{
UpstreamInterface_GetStreamDataPacket(NULL); //Try to get the next packet now, before USB asks for it
Upstream_MSC_GetStreamDataPacket(NULL); //Try to get the next packet now, before USB asks for it
}
}
HAL_StatusTypeDef UpstreamInterface_BeginWrite(UpstreamInterfaceMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount)
HAL_StatusTypeDef Upstream_MSC_BeginWrite(UpstreamMSCCallbackTypeDef callback,
uint64_t readBlockStart,
uint32_t readBlockCount)
{
UpstreamPacketTypeDef* freePacket;
HAL_StatusTypeDef tempResult;
@ -209,16 +211,17 @@ HAL_StatusTypeDef UpstreamInterface_BeginWrite(UpstreamInterfaceMSCCallbackTypeD
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
tempResult = Upstream_SendPacket(freePacket);
tempResult = Upstream_TransmitPacket(freePacket);
if (tempResult != HAL_OK)
{
TestReadyCallback(tempResult);
}
//return Upstream_GetPacket(UpstreamInterface_BeginWriteReplyCallback);
return Upstream_GetFreePacket(UpstreamInterface_BeginWriteReplyCallback);
//return Upstream_GetPacket(Upstream_MSC_BeginWriteReplyCallback);
return Upstream_GetFreePacket(Upstream_MSC_BeginWriteReplyCallback);
}
void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket)
void Upstream_MSC_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket)
{
// if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 1)) ||
// (replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
@ -235,11 +238,12 @@ void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacke
HAL_StatusTypeDef UpstreamInterface_PutStreamDataPacket(UpstreamPacketTypeDef* packetToSend,
uint32_t dataLength)
HAL_StatusTypeDef Upstream_MSC_PutStreamDataPacket(UpstreamPacketTypeDef* packetToSend,
uint32_t dataLength)
{
packetToSend->Length = dataLength + UPSTREAM_PACKET_HEADER_LEN;
packetToSend->CommandClass = COMMAND_CLASS_MASS_STORAGE | COMMAND_CLASS_DATA_FLAG;
packetToSend->Command = COMMAND_MSC_BEGIN_WRITE;
return Upstream_SendPacket(packetToSend);
return Upstream_TransmitPacket(packetToSend);
}

@ -78,13 +78,13 @@ HAL_StatusTypeDef Upstream_GetFreePacket(FreePacketCallbackTypeDef callback)
if ((UpstreamInterfaceState < UPSTREAM_INTERFACE_IDLE) ||
(UpstreamInterfaceState > UPSTREAM_INTERFACE_RX_PACKET))
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
//Do we already have a queued callback?
if (PendingFreePacketCallback != NULL)
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
//Check if there is a free buffer now
@ -113,7 +113,7 @@ UpstreamPacketTypeDef* Upstream_GetFreePacketImmediately(void)
if ((UpstreamInterfaceState < UPSTREAM_INTERFACE_IDLE) ||
(UpstreamInterfaceState > UPSTREAM_INTERFACE_RX_PACKET))
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
//We are expecting a free buffer now
@ -129,7 +129,7 @@ UpstreamPacketTypeDef* Upstream_GetFreePacketImmediately(void)
}
//Should not happen:
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_NO_RETURN;
}
@ -141,7 +141,7 @@ void Upstream_ReleasePacket(UpstreamPacketTypeDef* packetToRelease)
if ((packetToRelease != &UpstreamPacket0) &&
(packetToRelease != &UpstreamPacket1))
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
if (PendingFreePacketCallback != NULL)
@ -160,19 +160,23 @@ void Upstream_ReleasePacket(UpstreamPacketTypeDef* packetToRelease)
//Used by USB interface classes only.
//OK to call when still transmitting another packet.
//Not OK to call when receiving or waiting for downstream reply.
HAL_StatusTypeDef Upstream_SendPacket(UpstreamPacketTypeDef* packetToWrite)
HAL_StatusTypeDef Upstream_TransmitPacket(UpstreamPacketTypeDef* packetToWrite)
{
//Sanity checks
if ((packetToWrite != &UpstreamPacket0) &&
(packetToWrite != &UpstreamPacket1))
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
if ((packetToWrite->Busy != BUSY) ||
(packetToWrite->Length < UPSTREAM_PACKET_LEN_MIN) ||
(packetToWrite->Length > UPSTREAM_PACKET_LEN))
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
if (NextTxPacket != NULL)
{
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
switch (UpstreamInterfaceState)
@ -181,10 +185,6 @@ HAL_StatusTypeDef Upstream_SendPacket(UpstreamPacketTypeDef* packetToWrite)
case UPSTREAM_INTERFACE_TX_SIZE:
case UPSTREAM_INTERFACE_TX_PACKET_WAIT:
case UPSTREAM_INTERFACE_TX_PACKET:
if (NextTxPacket != NULL)
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
}
NextTxPacket = packetToWrite;
break;
@ -193,21 +193,17 @@ HAL_StatusTypeDef Upstream_SendPacket(UpstreamPacketTypeDef* packetToWrite)
case UPSTREAM_INTERFACE_RX_PACKET_WAIT:
case UPSTREAM_INTERFACE_RX_PACKET:
//We can't let the size/packet sequence get out of sync.
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
case UPSTREAM_INTERFACE_IDLE:
UpstreamInterfaceState = UPSTREAM_INTERFACE_TX_SIZE_WAIT;
CurrentWorkingPacket = packetToWrite;
SentCommandClass = CurrentWorkingPacket->CommandClass;
SentCommand = CurrentWorkingPacket->Command;
if (DOWNSTREAM_TX_OK_ACTIVE)
{
Upstream_TxOkInterrupt(); //Manually trigger edge interrupt processing if the line was already asserted
}
break;
default:
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
return HAL_OK;
}
@ -223,16 +219,12 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
if ((UpstreamInterfaceState != UPSTREAM_INTERFACE_TX_SIZE) &&
(UpstreamInterfaceState != UPSTREAM_INTERFACE_TX_PACKET))
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
if (UpstreamInterfaceState == UPSTREAM_INTERFACE_TX_SIZE)
{
UpstreamInterfaceState = UPSTREAM_INTERFACE_TX_PACKET_WAIT;
if (DOWNSTREAM_TX_OK_ACTIVE)
{
Upstream_TxOkInterrupt();
}
return;
}
@ -240,7 +232,7 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
{
if ((PendingFreePacketCallback != NULL) && (NextTxPacket == NULL))
{
//SPI_INTERFACE_FREAKOUT_VOID; ///////////////////////////////////////!
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
Upstream_ReleasePacket(CurrentWorkingPacket);
@ -251,10 +243,6 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
UpstreamInterfaceState = UPSTREAM_INTERFACE_TX_SIZE_WAIT;
CurrentWorkingPacket = NextTxPacket;
NextTxPacket = NULL;
if (DOWNSTREAM_TX_OK_ACTIVE)
{
Upstream_TxOkInterrupt();
}
return;
}
@ -270,11 +258,11 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
//Used by USB interface classes.
//Ok to call when idle or transmitting.
//Not OK to call when receiving or waiting for downstream reply.
HAL_StatusTypeDef Upstream_GetPacket(SpiPacketReceivedCallbackTypeDef callback)
HAL_StatusTypeDef Upstream_ReceivePacket(SpiPacketReceivedCallbackTypeDef callback)
{
if (ReceivePacketCallback != NULL)
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
ReceivePacketCallback = callback;
@ -288,28 +276,19 @@ HAL_StatusTypeDef Upstream_CheckBeginPacketReception(void)
if ((UpstreamInterfaceState < UPSTREAM_INTERFACE_IDLE) ||
(UpstreamInterfaceState > UPSTREAM_INTERFACE_RX_SIZE_WAIT))
{
SPI_INTERFACE_FREAKOUT_HAL_ERROR;
SPI_INTERFACE_FREAKOUT_RETURN_HAL_ERROR;
}
if (UpstreamInterfaceState == UPSTREAM_INTERFACE_IDLE)
{
UpstreamInterfaceState = UPSTREAM_INTERFACE_RX_SIZE_WAIT;
}
if (UpstreamInterfaceState == UPSTREAM_INTERFACE_RX_SIZE_WAIT)
{
if (DOWNSTREAM_TX_OK_ACTIVE)
{
//UpstreamTxOkInterrupt();
Upstream_GetFreePacket(Upstream_BeginPacketReception); //Take a shortcut here :)
}
}
return HAL_OK;
}
//This is called by EXTI3 falling edge interrupt,
//indicating that downstream is ready for next transaction.
//indicating that downstream is ready for the next transaction.
void Upstream_TxOkInterrupt(void)
{
switch (UpstreamInterfaceState)
@ -321,7 +300,7 @@ void Upstream_TxOkInterrupt(void)
(uint8_t*)&CurrentWorkingPacket->Length,
2) != HAL_OK)
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
break;
@ -332,7 +311,7 @@ void Upstream_TxOkInterrupt(void)
&CurrentWorkingPacket->CommandClass,
CurrentWorkingPacket->Length)) != HAL_OK)
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
break;
@ -347,12 +326,12 @@ void Upstream_TxOkInterrupt(void)
&CurrentWorkingPacket->CommandClass,
(CurrentWorkingPacket->Length + 1))) != HAL_OK) //"When the CRC feature is enabled the pData Length must be Size + 1"
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
break;
default:
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
}
@ -363,7 +342,7 @@ void Upstream_BeginPacketReception(UpstreamPacketTypeDef* freePacket)
{
if (UpstreamInterfaceState != UPSTREAM_INTERFACE_RX_SIZE_WAIT)
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
UpstreamInterfaceState = UPSTREAM_INTERFACE_RX_SIZE;
CurrentWorkingPacket = freePacket;
@ -373,12 +352,12 @@ void Upstream_BeginPacketReception(UpstreamPacketTypeDef* freePacket)
(uint8_t*)&CurrentWorkingPacket->Length,
(2 + 1)) != HAL_OK) //"When the CRC feature is enabled the pData Length must be Size + 1"
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
}
//Called at the end of the SPI TX DMA transfer,
//Called at the end of the SPI RX DMA transfer,
//at DMA2 interrupt priority. Assume *hspi points to our hspi1.
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
@ -389,7 +368,7 @@ void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
if ((UpstreamInterfaceState != UPSTREAM_INTERFACE_RX_SIZE) &&
(UpstreamInterfaceState != UPSTREAM_INTERFACE_RX_PACKET))
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
if (UpstreamInterfaceState == UPSTREAM_INTERFACE_RX_SIZE)
@ -397,13 +376,9 @@ void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
if ((CurrentWorkingPacket->Length < UPSTREAM_PACKET_LEN_MIN) ||
(CurrentWorkingPacket->Length > UPSTREAM_PACKET_LEN))
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
UpstreamInterfaceState = UPSTREAM_INTERFACE_RX_PACKET_WAIT;
if (DOWNSTREAM_TX_OK_ACTIVE)
{
Upstream_TxOkInterrupt();
}
return;
}
@ -413,11 +388,11 @@ void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
if ((SentCommandClass != (CurrentWorkingPacket->CommandClass & COMMAND_CLASS_MASK)) ||
(SentCommand != CurrentWorkingPacket->Command))
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
if (ReceivePacketCallback == NULL)
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
//USB interface may want to receive another packet immediately,
//so clear ReceivePacketCallback before the call.
@ -432,5 +407,5 @@ void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
//Something bad happened! Possibly CRC error...
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
{
SPI_INTERFACE_FREAKOUT_VOID;
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}

Loading…
Cancel
Save