with Downstream project. Also fixed a couple of things in upstream_spi.c and upstream_interface_msc.c but due to file rename the diff is not obvious...pull/7/head
parent
7b4e4b3c14
commit
4350666330
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* downstream_interface_msc.h
|
|
||||||
*
|
|
||||||
* Created on: 4/07/2015
|
|
||||||
* Author: Robert Fisk
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INC_DOWNSTREAM_INTERFACE_MSC_H_
|
|
||||||
#define INC_DOWNSTREAM_INTERFACE_MSC_H_
|
|
||||||
|
|
||||||
|
|
||||||
#include "downstream_spi.h"
|
|
||||||
|
|
||||||
|
|
||||||
typedef void (*DownstreamInterfaceMSCCallbackTypeDef)(HAL_StatusTypeDef result);
|
|
||||||
typedef void (*DownstreamInterfaceMSCCallbackPacketTypeDef)(HAL_StatusTypeDef result,
|
|
||||||
DownstreamPacketTypeDef* downstreamPacket,
|
|
||||||
uint16_t dataLength);
|
|
||||||
typedef void (*DownstreamInterfaceMSCCallbackUintPacketTypeDef)(HAL_StatusTypeDef result,
|
|
||||||
uint32_t result_uint[],
|
|
||||||
DownstreamPacketTypeDef* downstreamPacket);
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_TestReady(DownstreamInterfaceMSCCallbackTypeDef callback);
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_GetCapacity(DownstreamInterfaceMSCCallbackUintPacketTypeDef callback);
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_BeginRead(DownstreamInterfaceMSCCallbackTypeDef callback,
|
|
||||||
uint64_t readBlockStart,
|
|
||||||
uint32_t readBlockCount,
|
|
||||||
uint32_t readByteCount);
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_GetStreamDataPacket(DownstreamInterfaceMSCCallbackPacketTypeDef callback);
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_BeginWrite(DownstreamInterfaceMSCCallbackTypeDef callback,
|
|
||||||
uint64_t readBlockStart,
|
|
||||||
uint32_t readBlockCount);
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_PutStreamDataPacket(DownstreamPacketTypeDef* packetToSend,
|
|
||||||
uint32_t dataLength);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* INC_DOWNSTREAM_INTERFACE_MSC_H_ */
|
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* downstream_spi.h
|
|
||||||
*
|
|
||||||
* Created on: 21/06/2015
|
|
||||||
* Author: Robert Fisk
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INC_DOWNSTREAM_SPI_H_
|
|
||||||
#define INC_DOWNSTREAM_SPI_H_
|
|
||||||
|
|
||||||
|
|
||||||
#include "usbd_config.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define DOWNSTREAM_PACKET_HEADER_LEN (2) //Min length = CommandClass & Command bytes
|
|
||||||
#define DOWNSTREAM_PACKET_LEN (DOWNSTREAM_PACKET_HEADER_LEN + MSC_MEDIA_PACKET)
|
|
||||||
#define DOWNSTREAM_PACKET_LEN_MIN (DOWNSTREAM_PACKET_HEADER_LEN)
|
|
||||||
|
|
||||||
|
|
||||||
#define SPI_INTERFACE_FREAKOUT_VOID \
|
|
||||||
do { \
|
|
||||||
while (1); \
|
|
||||||
/*DownstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
|
|
||||||
/*return;*/ \
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
#define SPI_INTERFACE_FREAKOUT_HAL_ERROR \
|
|
||||||
do { \
|
|
||||||
while (1); \
|
|
||||||
/*DownstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
|
|
||||||
/*return HAL_ERROR;*/ \
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
INTERFACE_STATE_RESET = 0,
|
|
||||||
INTERFACE_STATE_WAITING_CLIENT = 1,
|
|
||||||
INTERFACE_STATE_IDLE = 2,
|
|
||||||
INTERFACE_STATE_TX_SIZE_WAIT = 3,
|
|
||||||
INTERFACE_STATE_TX_SIZE = 4,
|
|
||||||
INTERFACE_STATE_TX_PACKET_WAIT = 5,
|
|
||||||
INTERFACE_STATE_TX_PACKET = 6,
|
|
||||||
INTERFACE_STATE_RX_SIZE_WAIT = 7,
|
|
||||||
INTERFACE_STATE_RX_SIZE = 8,
|
|
||||||
INTERFACE_STATE_RX_PACKET_WAIT = 9,
|
|
||||||
INTERFACE_STATE_RX_PACKET = 10,
|
|
||||||
INTERFACE_STATE_ERROR = 11
|
|
||||||
} InterfaceStateTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
NOT_BUSY = 0,
|
|
||||||
BUSY = 1
|
|
||||||
} PacketBusyTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
PacketBusyTypeDef Busy; //Everything after Busy should be word-aligned
|
|
||||||
uint16_t Length __ALIGN_END; //Packet length includes CommandClass, Command, and Data
|
|
||||||
uint8_t CommandClass;
|
|
||||||
uint8_t Command;
|
|
||||||
uint8_t Data[MSC_MEDIA_PACKET]; //Should (must?) be word-aligned, for USB copy routine
|
|
||||||
uint8_t RxCrc;
|
|
||||||
}
|
|
||||||
DownstreamPacketTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef void (*FreePacketCallbackTypeDef)(DownstreamPacketTypeDef* freePacket);
|
|
||||||
typedef void (*SpiPacketReceivedCallbackTypeDef)(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
|
|
||||||
|
|
||||||
void Downstream_InitInterface(void);
|
|
||||||
HAL_StatusTypeDef Downstream_GetFreePacket(FreePacketCallbackTypeDef callback);
|
|
||||||
DownstreamPacketTypeDef* Downstream_GetFreePacketImmediately(void);
|
|
||||||
void Downstream_ReleasePacket(DownstreamPacketTypeDef* packetToRelease);
|
|
||||||
HAL_StatusTypeDef Downstream_SendPacket(DownstreamPacketTypeDef* packetToWrite);
|
|
||||||
HAL_StatusTypeDef Downstream_GetPacket(SpiPacketReceivedCallbackTypeDef callback);
|
|
||||||
void Downstream_TxOkInterrupt(void);
|
|
||||||
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi);
|
|
||||||
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi);
|
|
||||||
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* INC_DOWNSTREAM_SPI_H_ */
|
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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,89 @@
|
|||||||
|
/*
|
||||||
|
* upstream_spi.h
|
||||||
|
*
|
||||||
|
* Created on: 21/06/2015
|
||||||
|
* Author: Robert Fisk
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INC_UPSTREAM_SPI_H_
|
||||||
|
#define INC_UPSTREAM_SPI_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "usbd_config.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define UPSTREAM_PACKET_HEADER_LEN (2) //Min length = CommandClass & Command bytes
|
||||||
|
#define UPSTREAM_PACKET_LEN (UPSTREAM_PACKET_HEADER_LEN + MSC_MEDIA_PACKET)
|
||||||
|
#define UPSTREAM_PACKET_LEN_MIN (UPSTREAM_PACKET_HEADER_LEN)
|
||||||
|
|
||||||
|
|
||||||
|
#define SPI_INTERFACE_FREAKOUT_VOID \
|
||||||
|
do { \
|
||||||
|
while (1); \
|
||||||
|
/*UpstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
|
||||||
|
/*return;*/ \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#define SPI_INTERFACE_FREAKOUT_HAL_ERROR \
|
||||||
|
do { \
|
||||||
|
while (1); \
|
||||||
|
/*UpstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
|
||||||
|
/*return HAL_ERROR;*/ \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
UPSTREAM_INTERFACE_RESET,
|
||||||
|
UPSTREAM_INTERFACE_WAITING_CLIENT,
|
||||||
|
UPSTREAM_INTERFACE_IDLE,
|
||||||
|
UPSTREAM_INTERFACE_TX_SIZE_WAIT,
|
||||||
|
UPSTREAM_INTERFACE_TX_SIZE,
|
||||||
|
UPSTREAM_INTERFACE_TX_PACKET_WAIT,
|
||||||
|
UPSTREAM_INTERFACE_TX_PACKET,
|
||||||
|
UPSTREAM_INTERFACE_RX_SIZE_WAIT,
|
||||||
|
UPSTREAM_INTERFACE_RX_SIZE,
|
||||||
|
UPSTREAM_INTERFACE_RX_PACKET_WAIT,
|
||||||
|
UPSTREAM_INTERFACE_RX_PACKET,
|
||||||
|
UPSTREAM_INTERFACE_ERROR
|
||||||
|
} InterfaceStateTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
NOT_BUSY,
|
||||||
|
BUSY
|
||||||
|
} PacketBusyTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
PacketBusyTypeDef Busy; //Everything after Busy should be word-aligned
|
||||||
|
uint16_t Length __ALIGN_END; //Packet length includes CommandClass, Command, and Data
|
||||||
|
uint8_t CommandClass;
|
||||||
|
uint8_t Command;
|
||||||
|
uint8_t Data[MSC_MEDIA_PACKET]; //Should (must?) be word-aligned, for USB copy routine
|
||||||
|
uint8_t RxCrc;
|
||||||
|
}
|
||||||
|
UpstreamPacketTypeDef;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*FreePacketCallbackTypeDef)(UpstreamPacketTypeDef* freePacket);
|
||||||
|
typedef void (*SpiPacketReceivedCallbackTypeDef)(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
void Upstream_TxOkInterrupt(void);
|
||||||
|
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi);
|
||||||
|
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi);
|
||||||
|
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* INC_UPSTREAM_SPI_H_ */
|
@ -1,105 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file usbd_msc_storage.h
|
|
||||||
* @author MCD Application Team
|
|
||||||
* @version V2.3.0
|
|
||||||
* @date 04-November-2014
|
|
||||||
* @brief Header file for the usbd_msc_storage.c file
|
|
||||||
******************************************************************************
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
|
||||||
*
|
|
||||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
|
||||||
* You may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.st.com/software_license_agreement_liberty_v2
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
||||||
#ifndef __USBD_MSC_STORAGE_H
|
|
||||||
#define __USBD_MSC_STORAGE_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "usbd_msc.h"
|
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE
|
|
||||||
* @brief header file for the usbd_msc_storage.c file
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Defines
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Types
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Macros
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Variables
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
extern USBD_StorageTypeDef USBD_MSC_Template_fops;
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_FunctionsPrototype
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __USBD_MSC_STORAGE_H */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
@ -1,232 +0,0 @@
|
|||||||
/*
|
|
||||||
* downstream_interface_msc.c
|
|
||||||
*
|
|
||||||
* Created on: 4/07/2015
|
|
||||||
* Author: Robert Fisk
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "stm32f4xx_hal.h"
|
|
||||||
#include "downstream_interface_msc.h"
|
|
||||||
#include "downstream_interface_def.h"
|
|
||||||
#include "downstream_spi.h"
|
|
||||||
|
|
||||||
|
|
||||||
//Stuff we need to save for our callbacks to use:
|
|
||||||
DownstreamInterfaceMSCCallbackTypeDef TestReadyCallback;
|
|
||||||
DownstreamInterfaceMSCCallbackUintPacketTypeDef GetCapacityCallback;
|
|
||||||
DownstreamInterfaceMSCCallbackPacketTypeDef GetStreamDataCallback;
|
|
||||||
uint32_t ByteCount;
|
|
||||||
DownstreamPacketTypeDef* ReadStreamPacket;
|
|
||||||
uint8_t ReadStreamBusy;
|
|
||||||
|
|
||||||
|
|
||||||
static void DownstreamInterface_TestReadyReplyCallback(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
static void DownstreamInterface_GetCapacityReplyCallback(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
static void DownstreamInterface_GetStreamDataPacketCallback(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
static void DownstreamInterface_BeginWriteReplyCallback(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_TestReady(DownstreamInterfaceMSCCallbackTypeDef callback)
|
|
||||||
{
|
|
||||||
DownstreamPacketTypeDef* freePacket;
|
|
||||||
HAL_StatusTypeDef tempResult;
|
|
||||||
|
|
||||||
TestReadyCallback = callback;
|
|
||||||
freePacket = Downstream_GetFreePacketImmediately();
|
|
||||||
|
|
||||||
freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN;
|
|
||||||
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
|
||||||
freePacket->Command = COMMAND_MSC_TEST_UNIT_READY;
|
|
||||||
tempResult = Downstream_SendPacket(freePacket);
|
|
||||||
if (tempResult != HAL_OK)
|
|
||||||
{
|
|
||||||
return tempResult;
|
|
||||||
}
|
|
||||||
return Downstream_GetPacket(DownstreamInterface_TestReadyReplyCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownstreamInterface_TestReadyReplyCallback(DownstreamPacketTypeDef* replyPacket)
|
|
||||||
{
|
|
||||||
if ((replyPacket->Length != (DOWNSTREAM_PACKET_HEADER_LEN + 1)) ||
|
|
||||||
(replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
|
|
||||||
(replyPacket->Data[0] != HAL_OK))
|
|
||||||
{
|
|
||||||
Downstream_ReleasePacket(replyPacket);
|
|
||||||
TestReadyCallback(HAL_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Downstream_ReleasePacket(replyPacket);
|
|
||||||
TestReadyCallback(HAL_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_GetCapacity(DownstreamInterfaceMSCCallbackUintPacketTypeDef callback)
|
|
||||||
{
|
|
||||||
DownstreamPacketTypeDef* freePacket;
|
|
||||||
HAL_StatusTypeDef tempResult;
|
|
||||||
|
|
||||||
GetCapacityCallback = callback;
|
|
||||||
freePacket = Downstream_GetFreePacketImmediately();
|
|
||||||
|
|
||||||
freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN;
|
|
||||||
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
|
||||||
freePacket->Command = COMMAND_MSC_GET_CAPACITY;
|
|
||||||
tempResult = Downstream_SendPacket(freePacket);
|
|
||||||
if (tempResult != HAL_OK)
|
|
||||||
{
|
|
||||||
return tempResult;
|
|
||||||
}
|
|
||||||
return Downstream_GetPacket(DownstreamInterface_GetCapacityReplyCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownstreamInterface_GetCapacityReplyCallback(DownstreamPacketTypeDef* replyPacket)
|
|
||||||
{
|
|
||||||
uint32_t uint[2];
|
|
||||||
|
|
||||||
if ((replyPacket->Length != (DOWNSTREAM_PACKET_HEADER_LEN + 8) ||
|
|
||||||
(replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG)))
|
|
||||||
{
|
|
||||||
GetCapacityCallback(HAL_ERROR, NULL, NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint[0] = *(uint32_t*)&(replyPacket->Data[0]);
|
|
||||||
uint[1] = *(uint32_t*)&(replyPacket->Data[4]);
|
|
||||||
GetCapacityCallback(HAL_OK, uint, replyPacket); //usb_msc_scsi will use this packet, so don't release now
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_BeginRead(DownstreamInterfaceMSCCallbackTypeDef callback,
|
|
||||||
uint64_t readBlockStart,
|
|
||||||
uint32_t readBlockCount,
|
|
||||||
uint32_t readByteCount)
|
|
||||||
{
|
|
||||||
DownstreamPacketTypeDef* freePacket;
|
|
||||||
HAL_StatusTypeDef tempResult;
|
|
||||||
|
|
||||||
ReadStreamPacket = NULL; //Prepare for GetStreamDataPacket's use
|
|
||||||
ReadStreamBusy = 0;
|
|
||||||
|
|
||||||
TestReadyCallback = callback;
|
|
||||||
ByteCount = readByteCount;
|
|
||||||
freePacket = Downstream_GetFreePacketImmediately();
|
|
||||||
|
|
||||||
freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN + (4 * 3);
|
|
||||||
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
|
||||||
freePacket->Command = COMMAND_MSC_BEGIN_READ;
|
|
||||||
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
|
|
||||||
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
|
|
||||||
|
|
||||||
tempResult = Downstream_SendPacket(freePacket);
|
|
||||||
if (tempResult != HAL_OK)
|
|
||||||
{
|
|
||||||
TestReadyCallback(tempResult);
|
|
||||||
}
|
|
||||||
return Downstream_GetPacket(DownstreamInterface_TestReadyReplyCallback); //Re-use TestReadyReplyCallback because it does exactly what we want!
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_GetStreamDataPacket(DownstreamInterfaceMSCCallbackPacketTypeDef callback)
|
|
||||||
{
|
|
||||||
GetStreamDataCallback = callback;
|
|
||||||
|
|
||||||
if (ReadStreamBusy != 0)
|
|
||||||
{
|
|
||||||
return HAL_OK;
|
|
||||||
}
|
|
||||||
ReadStreamBusy = 1;
|
|
||||||
|
|
||||||
if (ReadStreamPacket && GetStreamDataCallback) //Do we have a stored packet and an address to send it?
|
|
||||||
{
|
|
||||||
DownstreamInterface_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 Downstream_GetPacket(DownstreamInterface_GetStreamDataPacketCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownstreamInterface_GetStreamDataPacketCallback(DownstreamPacketTypeDef* replyPacket)
|
|
||||||
{
|
|
||||||
uint16_t dataLength;
|
|
||||||
|
|
||||||
ReadStreamBusy = 0;
|
|
||||||
if (GetStreamDataCallback == NULL)
|
|
||||||
{
|
|
||||||
ReadStreamPacket = replyPacket; //We used up our callback already, so save this one for later.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) == 0) || //Any 'command' reply (as opposed to 'data' reply) is an automatic fail here
|
|
||||||
(replyPacket->Length <= DOWNSTREAM_PACKET_HEADER_LEN) || //Should be at least one data byte in the reply.
|
|
||||||
(replyPacket->Length > ByteCount))
|
|
||||||
{
|
|
||||||
GetStreamDataCallback(HAL_ERROR, NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataLength = replyPacket->Length - DOWNSTREAM_PACKET_HEADER_LEN;
|
|
||||||
ByteCount -= dataLength;
|
|
||||||
GetStreamDataCallback(HAL_OK, replyPacket, dataLength); //usb_msc_scsi will use this packet, so don't release now
|
|
||||||
if (ByteCount > 0)
|
|
||||||
{
|
|
||||||
DownstreamInterface_GetStreamDataPacket(NULL); //Try to get the next packet now, before USB asks for it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_BeginWrite(DownstreamInterfaceMSCCallbackTypeDef callback,
|
|
||||||
uint64_t readBlockStart,
|
|
||||||
uint32_t readBlockCount)
|
|
||||||
{
|
|
||||||
DownstreamPacketTypeDef* freePacket;
|
|
||||||
HAL_StatusTypeDef tempResult;
|
|
||||||
|
|
||||||
TestReadyCallback = callback;
|
|
||||||
freePacket = Downstream_GetFreePacketImmediately();
|
|
||||||
|
|
||||||
freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN + (4 * 3);
|
|
||||||
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
|
||||||
freePacket->Command = COMMAND_MSC_BEGIN_WRITE;
|
|
||||||
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
|
|
||||||
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
|
|
||||||
|
|
||||||
tempResult = Downstream_SendPacket(freePacket);
|
|
||||||
if (tempResult != HAL_OK)
|
|
||||||
{
|
|
||||||
TestReadyCallback(tempResult);
|
|
||||||
}
|
|
||||||
return Downstream_GetPacket(DownstreamInterface_BeginWriteReplyCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownstreamInterface_BeginWriteReplyCallback(DownstreamPacketTypeDef* replyPacket)
|
|
||||||
{
|
|
||||||
if ((replyPacket->Length != (DOWNSTREAM_PACKET_HEADER_LEN + 1)) ||
|
|
||||||
(replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
|
|
||||||
((replyPacket->Data[0] != HAL_OK) && (replyPacket->Data[0] != HAL_BUSY)))
|
|
||||||
{
|
|
||||||
Downstream_ReleasePacket(replyPacket);
|
|
||||||
TestReadyCallback(HAL_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Downstream_ReleasePacket(replyPacket);
|
|
||||||
TestReadyCallback(replyPacket->Data[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_PutStreamDataPacket(DownstreamPacketTypeDef* packetToSend,
|
|
||||||
uint32_t dataLength)
|
|
||||||
{
|
|
||||||
packetToSend->Length = dataLength + DOWNSTREAM_PACKET_HEADER_LEN;
|
|
||||||
packetToSend->CommandClass = COMMAND_CLASS_MASS_STORAGE | COMMAND_CLASS_DATA_FLAG;
|
|
||||||
packetToSend->Command = COMMAND_MSC_BEGIN_WRITE;
|
|
||||||
return Downstream_SendPacket(packetToSend);
|
|
||||||
}
|
|
@ -1,245 +0,0 @@
|
|||||||
/*
|
|
||||||
* downstream_interface_msc_mock.c
|
|
||||||
*
|
|
||||||
* Created on: 17/07/2015
|
|
||||||
* Author: Robert Fisk
|
|
||||||
*
|
|
||||||
* This file replaces downstream_interface_msc.c to allow operational
|
|
||||||
* testing of Upstream, without Downstream in place and communicating
|
|
||||||
* over SPI. It still attempts to write downstream packets out the SPI port.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "stm32f4xx_hal.h"
|
|
||||||
#include "downstream_interface_msc.h"
|
|
||||||
#include "downstream_interface_def.h"
|
|
||||||
#include "downstream_spi.h"
|
|
||||||
|
|
||||||
|
|
||||||
//Stuff we need to save for our callbacks to use:
|
|
||||||
DownstreamInterfaceMSCCallbackTypeDef TestReadyCallback;
|
|
||||||
DownstreamInterfaceMSCCallbackUintPacketTypeDef GetCapacityCallback;
|
|
||||||
DownstreamInterfaceMSCCallbackPacketTypeDef GetStreamDataCallback;
|
|
||||||
uint32_t ByteCount;
|
|
||||||
DownstreamPacketTypeDef* ReadStreamPacket;
|
|
||||||
uint8_t ReadStreamBusy;
|
|
||||||
|
|
||||||
|
|
||||||
static void DownstreamInterface_TestReadyReplyCallback(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
static void DownstreamInterface_GetCapacityReplyCallback(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
static void DownstreamInterface_GetStreamDataPacketCallback(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
static void DownstreamInterface_BeginWriteReplyCallback(DownstreamPacketTypeDef* replyPacket);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_TestReady(DownstreamInterfaceMSCCallbackTypeDef callback)
|
|
||||||
{
|
|
||||||
DownstreamPacketTypeDef* freePacket;
|
|
||||||
HAL_StatusTypeDef tempResult;
|
|
||||||
|
|
||||||
TestReadyCallback = callback;
|
|
||||||
freePacket = Downstream_GetFreePacketImmediately();
|
|
||||||
|
|
||||||
freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN;
|
|
||||||
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
|
||||||
freePacket->Command = COMMAND_MSC_TEST_UNIT_READY;
|
|
||||||
tempResult = Downstream_SendPacket(freePacket);
|
|
||||||
if (tempResult != HAL_OK)
|
|
||||||
{
|
|
||||||
return tempResult;
|
|
||||||
}
|
|
||||||
//return Downstream_GetPacket(DownstreamInterface_TestReadyReplyCallback);
|
|
||||||
return Downstream_GetFreePacket(DownstreamInterface_TestReadyReplyCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownstreamInterface_TestReadyReplyCallback(DownstreamPacketTypeDef* replyPacket)
|
|
||||||
{
|
|
||||||
// if ((replyPacket->Length != (DOWNSTREAM_PACKET_HEADER_LEN + 1)) ||
|
|
||||||
// (replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
|
|
||||||
// (replyPacket->Data[0] != HAL_OK))
|
|
||||||
// {
|
|
||||||
// Downstream_ReleasePacket(replyPacket);
|
|
||||||
// TestReadyCallback(HAL_ERROR);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
Downstream_ReleasePacket(replyPacket);
|
|
||||||
TestReadyCallback(HAL_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_GetCapacity(DownstreamInterfaceMSCCallbackUintPacketTypeDef callback)
|
|
||||||
{
|
|
||||||
DownstreamPacketTypeDef* freePacket;
|
|
||||||
HAL_StatusTypeDef tempResult;
|
|
||||||
|
|
||||||
GetCapacityCallback = callback;
|
|
||||||
freePacket = Downstream_GetFreePacketImmediately();
|
|
||||||
|
|
||||||
freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN;
|
|
||||||
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
|
||||||
freePacket->Command = COMMAND_MSC_GET_CAPACITY;
|
|
||||||
tempResult = Downstream_SendPacket(freePacket);
|
|
||||||
if (tempResult != HAL_OK)
|
|
||||||
{
|
|
||||||
return tempResult;
|
|
||||||
}
|
|
||||||
//return Downstream_GetPacket(DownstreamInterface_GetCapacityReplyCallback);
|
|
||||||
return Downstream_GetFreePacket(DownstreamInterface_GetCapacityReplyCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownstreamInterface_GetCapacityReplyCallback(DownstreamPacketTypeDef* replyPacket)
|
|
||||||
{
|
|
||||||
uint32_t uint[2];
|
|
||||||
|
|
||||||
// if ((replyPacket->Length != (DOWNSTREAM_PACKET_HEADER_LEN + 8) ||
|
|
||||||
// (replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG)))
|
|
||||||
// {
|
|
||||||
// GetCapacityCallback(HAL_ERROR, NULL, NULL);
|
|
||||||
// }
|
|
||||||
|
|
||||||
*(uint32_t*)&(replyPacket->Data[0]) = 262144; //* 512B = 128MB
|
|
||||||
*(uint32_t*)&(replyPacket->Data[4]) = 512;
|
|
||||||
|
|
||||||
uint[0] = *(uint32_t*)&(replyPacket->Data[0]);
|
|
||||||
uint[1] = *(uint32_t*)&(replyPacket->Data[4]);
|
|
||||||
GetCapacityCallback(HAL_OK, uint, replyPacket); //usb_msc_scsi will use this packet, so don't release now
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_BeginRead(DownstreamInterfaceMSCCallbackTypeDef callback,
|
|
||||||
uint64_t readBlockStart,
|
|
||||||
uint32_t readBlockCount,
|
|
||||||
uint32_t readByteCount)
|
|
||||||
{
|
|
||||||
DownstreamPacketTypeDef* freePacket;
|
|
||||||
HAL_StatusTypeDef tempResult;
|
|
||||||
|
|
||||||
ReadStreamPacket = NULL; //Prepare for GetStreamDataPacket's use
|
|
||||||
ReadStreamBusy = 0;
|
|
||||||
|
|
||||||
TestReadyCallback = callback;
|
|
||||||
ByteCount = readByteCount;
|
|
||||||
freePacket = Downstream_GetFreePacketImmediately();
|
|
||||||
|
|
||||||
freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN + (4 * 3);
|
|
||||||
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
|
||||||
freePacket->Command = COMMAND_MSC_BEGIN_READ;
|
|
||||||
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
|
|
||||||
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
|
|
||||||
|
|
||||||
tempResult = Downstream_SendPacket(freePacket);
|
|
||||||
if (tempResult != HAL_OK)
|
|
||||||
{
|
|
||||||
TestReadyCallback(tempResult);
|
|
||||||
}
|
|
||||||
//return Downstream_GetPacket(DownstreamInterface_TestReadyReplyCallback); //Re-use TestReadyReplyCallback because it does exactly what we want!
|
|
||||||
return Downstream_GetFreePacket(DownstreamInterface_TestReadyReplyCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_GetStreamDataPacket(DownstreamInterfaceMSCCallbackPacketTypeDef callback)
|
|
||||||
{
|
|
||||||
GetStreamDataCallback = callback;
|
|
||||||
|
|
||||||
if (ReadStreamBusy != 0)
|
|
||||||
{
|
|
||||||
return HAL_OK;
|
|
||||||
}
|
|
||||||
ReadStreamBusy = 1;
|
|
||||||
|
|
||||||
if (ReadStreamPacket && GetStreamDataCallback) //Do we have a stored packet and an address to send it?
|
|
||||||
{
|
|
||||||
DownstreamInterface_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 Downstream_GetPacket(DownstreamInterface_GetStreamDataPacketCallback);
|
|
||||||
return Downstream_GetFreePacket(DownstreamInterface_GetStreamDataPacketCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownstreamInterface_GetStreamDataPacketCallback(DownstreamPacketTypeDef* replyPacket)
|
|
||||||
{
|
|
||||||
uint16_t dataLength;
|
|
||||||
|
|
||||||
ReadStreamBusy = 0;
|
|
||||||
if (GetStreamDataCallback == NULL)
|
|
||||||
{
|
|
||||||
ReadStreamPacket = replyPacket; //We used up our callback already, so save this one for later.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (((replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) == 0) || //Any 'command' reply (as opposed to 'data' reply) is an automatic fail here
|
|
||||||
// (replyPacket->Length <= DOWNSTREAM_PACKET_HEADER_LEN) || //Should be at least one data byte in the reply.
|
|
||||||
// (replyPacket->Length > ByteCount))
|
|
||||||
// {
|
|
||||||
// GetStreamDataCallback(HAL_ERROR, NULL);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
replyPacket->Length = MIN((ByteCount + DOWNSTREAM_PACKET_HEADER_LEN), (MSC_MEDIA_PACKET + DOWNSTREAM_PACKET_HEADER_LEN));
|
|
||||||
|
|
||||||
dataLength = replyPacket->Length - DOWNSTREAM_PACKET_HEADER_LEN;
|
|
||||||
ByteCount -= dataLength;
|
|
||||||
GetStreamDataCallback(HAL_OK, replyPacket, dataLength); //usb_msc_scsi will use this packet, so don't release now
|
|
||||||
if (ByteCount > 0)
|
|
||||||
{
|
|
||||||
DownstreamInterface_GetStreamDataPacket(NULL); //Try to get the next packet now, before USB asks for it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_BeginWrite(DownstreamInterfaceMSCCallbackTypeDef callback,
|
|
||||||
uint64_t readBlockStart,
|
|
||||||
uint32_t readBlockCount)
|
|
||||||
{
|
|
||||||
DownstreamPacketTypeDef* freePacket;
|
|
||||||
HAL_StatusTypeDef tempResult;
|
|
||||||
|
|
||||||
TestReadyCallback = callback;
|
|
||||||
freePacket = Downstream_GetFreePacketImmediately();
|
|
||||||
|
|
||||||
freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN + (4 * 3);
|
|
||||||
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
|
||||||
freePacket->Command = COMMAND_MSC_BEGIN_WRITE;
|
|
||||||
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
|
|
||||||
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
|
|
||||||
|
|
||||||
tempResult = Downstream_SendPacket(freePacket);
|
|
||||||
if (tempResult != HAL_OK)
|
|
||||||
{
|
|
||||||
TestReadyCallback(tempResult);
|
|
||||||
}
|
|
||||||
//return Downstream_GetPacket(DownstreamInterface_BeginWriteReplyCallback);
|
|
||||||
return Downstream_GetFreePacket(DownstreamInterface_BeginWriteReplyCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownstreamInterface_BeginWriteReplyCallback(DownstreamPacketTypeDef* replyPacket)
|
|
||||||
{
|
|
||||||
// if ((replyPacket->Length != (DOWNSTREAM_PACKET_HEADER_LEN + 1)) ||
|
|
||||||
// (replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
|
|
||||||
// ((replyPacket->Data[0] != HAL_OK) && (replyPacket->Data[0] != HAL_BUSY)))
|
|
||||||
// {
|
|
||||||
// Downstream_ReleasePacket(replyPacket);
|
|
||||||
// TestReadyCallback(HAL_ERROR);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
Downstream_ReleasePacket(replyPacket);
|
|
||||||
TestReadyCallback(replyPacket->Data[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HAL_StatusTypeDef DownstreamInterface_PutStreamDataPacket(DownstreamPacketTypeDef* packetToSend,
|
|
||||||
uint32_t dataLength)
|
|
||||||
{
|
|
||||||
packetToSend->Length = dataLength + DOWNSTREAM_PACKET_HEADER_LEN;
|
|
||||||
packetToSend->CommandClass = COMMAND_CLASS_MASS_STORAGE | COMMAND_CLASS_DATA_FLAG;
|
|
||||||
packetToSend->Command = COMMAND_MSC_BEGIN_WRITE;
|
|
||||||
return Downstream_SendPacket(packetToSend);
|
|
||||||
}
|
|
@ -0,0 +1,232 @@
|
|||||||
|
/*
|
||||||
|
* upstream_interface_msc.c
|
||||||
|
*
|
||||||
|
* Created on: 4/07/2015
|
||||||
|
* Author: Robert Fisk
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <upstream_interface_def.h>
|
||||||
|
#include <upstream_interface_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;
|
||||||
|
|
||||||
|
|
||||||
|
static void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
static void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
static void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
static void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_TestReady(UpstreamInterfaceMSCCallbackTypeDef callback)
|
||||||
|
{
|
||||||
|
UpstreamPacketTypeDef* freePacket;
|
||||||
|
HAL_StatusTypeDef tempResult;
|
||||||
|
|
||||||
|
TestReadyCallback = callback;
|
||||||
|
freePacket = Upstream_GetFreePacketImmediately();
|
||||||
|
|
||||||
|
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN;
|
||||||
|
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
||||||
|
freePacket->Command = COMMAND_MSC_TEST_UNIT_READY;
|
||||||
|
tempResult = Upstream_SendPacket(freePacket);
|
||||||
|
if (tempResult != HAL_OK)
|
||||||
|
{
|
||||||
|
return tempResult;
|
||||||
|
}
|
||||||
|
return Upstream_GetPacket(UpstreamInterface_TestReadyReplyCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket)
|
||||||
|
{
|
||||||
|
if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 1)) ||
|
||||||
|
(replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
|
||||||
|
(replyPacket->Data[0] != HAL_OK))
|
||||||
|
{
|
||||||
|
Upstream_ReleasePacket(replyPacket);
|
||||||
|
TestReadyCallback(HAL_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Upstream_ReleasePacket(replyPacket);
|
||||||
|
TestReadyCallback(HAL_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_GetCapacity(UpstreamInterfaceMSCCallbackUintPacketTypeDef callback)
|
||||||
|
{
|
||||||
|
UpstreamPacketTypeDef* freePacket;
|
||||||
|
HAL_StatusTypeDef tempResult;
|
||||||
|
|
||||||
|
GetCapacityCallback = callback;
|
||||||
|
freePacket = Upstream_GetFreePacketImmediately();
|
||||||
|
|
||||||
|
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN;
|
||||||
|
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
||||||
|
freePacket->Command = COMMAND_MSC_GET_CAPACITY;
|
||||||
|
tempResult = Upstream_SendPacket(freePacket);
|
||||||
|
if (tempResult != HAL_OK)
|
||||||
|
{
|
||||||
|
return tempResult;
|
||||||
|
}
|
||||||
|
return Upstream_GetPacket(UpstreamInterface_GetCapacityReplyCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket)
|
||||||
|
{
|
||||||
|
uint32_t uint[2];
|
||||||
|
|
||||||
|
if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 8) ||
|
||||||
|
(replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG)))
|
||||||
|
{
|
||||||
|
GetCapacityCallback(HAL_ERROR, NULL, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint[0] = *(uint32_t*)&(replyPacket->Data[0]);
|
||||||
|
uint[1] = *(uint32_t*)&(replyPacket->Data[4]);
|
||||||
|
GetCapacityCallback(HAL_OK, uint, replyPacket); //usb_msc_scsi will use this packet, so don't release now
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_BeginRead(UpstreamInterfaceMSCCallbackTypeDef callback,
|
||||||
|
uint64_t readBlockStart,
|
||||||
|
uint32_t readBlockCount,
|
||||||
|
uint32_t readByteCount)
|
||||||
|
{
|
||||||
|
UpstreamPacketTypeDef* freePacket;
|
||||||
|
HAL_StatusTypeDef tempResult;
|
||||||
|
|
||||||
|
ReadStreamPacket = NULL; //Prepare for GetStreamDataPacket's use
|
||||||
|
ReadStreamBusy = 0;
|
||||||
|
|
||||||
|
TestReadyCallback = callback;
|
||||||
|
ByteCount = readByteCount;
|
||||||
|
freePacket = Upstream_GetFreePacketImmediately();
|
||||||
|
|
||||||
|
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN + (4 * 3);
|
||||||
|
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
||||||
|
freePacket->Command = COMMAND_MSC_BEGIN_READ;
|
||||||
|
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
|
||||||
|
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
|
||||||
|
|
||||||
|
tempResult = Upstream_SendPacket(freePacket);
|
||||||
|
if (tempResult != HAL_OK)
|
||||||
|
{
|
||||||
|
TestReadyCallback(tempResult);
|
||||||
|
}
|
||||||
|
return Upstream_GetPacket(UpstreamInterface_TestReadyReplyCallback); //Re-use TestReadyReplyCallback because it does exactly what we want!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_GetStreamDataPacket(UpstreamInterfaceMSCCallbackPacketTypeDef callback)
|
||||||
|
{
|
||||||
|
GetStreamDataCallback = callback;
|
||||||
|
|
||||||
|
if (ReadStreamBusy != 0)
|
||||||
|
{
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
ReadStreamBusy = 1;
|
||||||
|
|
||||||
|
if (ReadStreamPacket && GetStreamDataCallback) //Do we have a stored packet and an address to send it?
|
||||||
|
{
|
||||||
|
UpstreamInterface_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket)
|
||||||
|
{
|
||||||
|
uint16_t dataLength;
|
||||||
|
|
||||||
|
ReadStreamBusy = 0;
|
||||||
|
if (GetStreamDataCallback == NULL)
|
||||||
|
{
|
||||||
|
ReadStreamPacket = replyPacket; //We used up our callback already, so save this one for later.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) == 0) || //Any 'command' reply (as opposed to 'data' reply) is an automatic fail here
|
||||||
|
(replyPacket->Length <= UPSTREAM_PACKET_HEADER_LEN) || //Should be at least one data byte in the reply.
|
||||||
|
(replyPacket->Length > ByteCount))
|
||||||
|
{
|
||||||
|
GetStreamDataCallback(HAL_ERROR, NULL, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dataLength = replyPacket->Length - UPSTREAM_PACKET_HEADER_LEN;
|
||||||
|
ByteCount -= dataLength;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_BeginWrite(UpstreamInterfaceMSCCallbackTypeDef callback,
|
||||||
|
uint64_t readBlockStart,
|
||||||
|
uint32_t readBlockCount)
|
||||||
|
{
|
||||||
|
UpstreamPacketTypeDef* freePacket;
|
||||||
|
HAL_StatusTypeDef tempResult;
|
||||||
|
|
||||||
|
TestReadyCallback = callback;
|
||||||
|
freePacket = Upstream_GetFreePacketImmediately();
|
||||||
|
|
||||||
|
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN + (4 * 3);
|
||||||
|
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
||||||
|
freePacket->Command = COMMAND_MSC_BEGIN_WRITE;
|
||||||
|
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
|
||||||
|
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
|
||||||
|
|
||||||
|
tempResult = Upstream_SendPacket(freePacket);
|
||||||
|
if (tempResult != HAL_OK)
|
||||||
|
{
|
||||||
|
TestReadyCallback(tempResult);
|
||||||
|
}
|
||||||
|
return Upstream_GetPacket(UpstreamInterface_BeginWriteReplyCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket)
|
||||||
|
{
|
||||||
|
if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 1)) ||
|
||||||
|
(replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
|
||||||
|
((replyPacket->Data[0] != HAL_OK) && (replyPacket->Data[0] != HAL_BUSY)))
|
||||||
|
{
|
||||||
|
Upstream_ReleasePacket(replyPacket);
|
||||||
|
TestReadyCallback(HAL_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Upstream_ReleasePacket(replyPacket);
|
||||||
|
TestReadyCallback(replyPacket->Data[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_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);
|
||||||
|
}
|
@ -0,0 +1,245 @@
|
|||||||
|
/*
|
||||||
|
* upstream_interface_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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <upstream_interface_def.h>
|
||||||
|
#include <upstream_interface_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;
|
||||||
|
|
||||||
|
|
||||||
|
static void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
static void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
static void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
static void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_TestReady(UpstreamInterfaceMSCCallbackTypeDef callback)
|
||||||
|
{
|
||||||
|
UpstreamPacketTypeDef* freePacket;
|
||||||
|
HAL_StatusTypeDef tempResult;
|
||||||
|
|
||||||
|
TestReadyCallback = callback;
|
||||||
|
freePacket = Upstream_GetFreePacketImmediately();
|
||||||
|
|
||||||
|
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN;
|
||||||
|
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
||||||
|
freePacket->Command = COMMAND_MSC_TEST_UNIT_READY;
|
||||||
|
tempResult = Upstream_SendPacket(freePacket);
|
||||||
|
if (tempResult != HAL_OK)
|
||||||
|
{
|
||||||
|
return tempResult;
|
||||||
|
}
|
||||||
|
//return Upstream_GetPacket(UpstreamInterface_TestReadyReplyCallback);
|
||||||
|
return Upstream_GetFreePacket(UpstreamInterface_TestReadyReplyCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpstreamInterface_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket)
|
||||||
|
{
|
||||||
|
// if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 1)) ||
|
||||||
|
// (replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
|
||||||
|
// (replyPacket->Data[0] != HAL_OK))
|
||||||
|
// {
|
||||||
|
// Upstream_ReleasePacket(replyPacket);
|
||||||
|
// TestReadyCallback(HAL_ERROR);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
Upstream_ReleasePacket(replyPacket);
|
||||||
|
TestReadyCallback(HAL_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_GetCapacity(UpstreamInterfaceMSCCallbackUintPacketTypeDef callback)
|
||||||
|
{
|
||||||
|
UpstreamPacketTypeDef* freePacket;
|
||||||
|
HAL_StatusTypeDef tempResult;
|
||||||
|
|
||||||
|
GetCapacityCallback = callback;
|
||||||
|
freePacket = Upstream_GetFreePacketImmediately();
|
||||||
|
|
||||||
|
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN;
|
||||||
|
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
||||||
|
freePacket->Command = COMMAND_MSC_GET_CAPACITY;
|
||||||
|
tempResult = Upstream_SendPacket(freePacket);
|
||||||
|
if (tempResult != HAL_OK)
|
||||||
|
{
|
||||||
|
return tempResult;
|
||||||
|
}
|
||||||
|
//return Upstream_GetPacket(UpstreamInterface_GetCapacityReplyCallback);
|
||||||
|
return Upstream_GetFreePacket(UpstreamInterface_GetCapacityReplyCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpstreamInterface_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket)
|
||||||
|
{
|
||||||
|
uint32_t uint[2];
|
||||||
|
|
||||||
|
// if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 8) ||
|
||||||
|
// (replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG)))
|
||||||
|
// {
|
||||||
|
// GetCapacityCallback(HAL_ERROR, NULL, NULL);
|
||||||
|
// }
|
||||||
|
|
||||||
|
*(uint32_t*)&(replyPacket->Data[0]) = 262144; //* 512B = 128MB
|
||||||
|
*(uint32_t*)&(replyPacket->Data[4]) = 512;
|
||||||
|
|
||||||
|
uint[0] = *(uint32_t*)&(replyPacket->Data[0]);
|
||||||
|
uint[1] = *(uint32_t*)&(replyPacket->Data[4]);
|
||||||
|
GetCapacityCallback(HAL_OK, uint, replyPacket); //usb_msc_scsi will use this packet, so don't release now
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_BeginRead(UpstreamInterfaceMSCCallbackTypeDef callback,
|
||||||
|
uint64_t readBlockStart,
|
||||||
|
uint32_t readBlockCount,
|
||||||
|
uint32_t readByteCount)
|
||||||
|
{
|
||||||
|
UpstreamPacketTypeDef* freePacket;
|
||||||
|
HAL_StatusTypeDef tempResult;
|
||||||
|
|
||||||
|
ReadStreamPacket = NULL; //Prepare for GetStreamDataPacket's use
|
||||||
|
ReadStreamBusy = 0;
|
||||||
|
|
||||||
|
TestReadyCallback = callback;
|
||||||
|
ByteCount = readByteCount;
|
||||||
|
freePacket = Upstream_GetFreePacketImmediately();
|
||||||
|
|
||||||
|
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN + (4 * 3);
|
||||||
|
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
||||||
|
freePacket->Command = COMMAND_MSC_BEGIN_READ;
|
||||||
|
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
|
||||||
|
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
|
||||||
|
|
||||||
|
tempResult = Upstream_SendPacket(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_GetStreamDataPacket(UpstreamInterfaceMSCCallbackPacketTypeDef callback)
|
||||||
|
{
|
||||||
|
GetStreamDataCallback = callback;
|
||||||
|
|
||||||
|
if (ReadStreamBusy != 0)
|
||||||
|
{
|
||||||
|
return HAL_OK;
|
||||||
|
}
|
||||||
|
ReadStreamBusy = 1;
|
||||||
|
|
||||||
|
if (ReadStreamPacket && GetStreamDataCallback) //Do we have a stored packet and an address to send it?
|
||||||
|
{
|
||||||
|
UpstreamInterface_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpstreamInterface_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket)
|
||||||
|
{
|
||||||
|
uint16_t dataLength;
|
||||||
|
|
||||||
|
ReadStreamBusy = 0;
|
||||||
|
if (GetStreamDataCallback == NULL)
|
||||||
|
{
|
||||||
|
ReadStreamPacket = replyPacket; //We used up our callback already, so save this one for later.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (((replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) == 0) || //Any 'command' reply (as opposed to 'data' reply) is an automatic fail here
|
||||||
|
// (replyPacket->Length <= UPSTREAM_PACKET_HEADER_LEN) || //Should be at least one data byte in the reply.
|
||||||
|
// (replyPacket->Length > ByteCount))
|
||||||
|
// {
|
||||||
|
// GetStreamDataCallback(HAL_ERROR, NULL);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
replyPacket->Length = MIN((ByteCount + UPSTREAM_PACKET_HEADER_LEN), (MSC_MEDIA_PACKET + UPSTREAM_PACKET_HEADER_LEN));
|
||||||
|
|
||||||
|
dataLength = replyPacket->Length - UPSTREAM_PACKET_HEADER_LEN;
|
||||||
|
ByteCount -= dataLength;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_BeginWrite(UpstreamInterfaceMSCCallbackTypeDef callback,
|
||||||
|
uint64_t readBlockStart,
|
||||||
|
uint32_t readBlockCount)
|
||||||
|
{
|
||||||
|
UpstreamPacketTypeDef* freePacket;
|
||||||
|
HAL_StatusTypeDef tempResult;
|
||||||
|
|
||||||
|
TestReadyCallback = callback;
|
||||||
|
freePacket = Upstream_GetFreePacketImmediately();
|
||||||
|
|
||||||
|
freePacket->Length = UPSTREAM_PACKET_HEADER_LEN + (4 * 3);
|
||||||
|
freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE;
|
||||||
|
freePacket->Command = COMMAND_MSC_BEGIN_WRITE;
|
||||||
|
*(uint64_t*)&(freePacket->Data[0]) = readBlockStart;
|
||||||
|
*(uint32_t*)&(freePacket->Data[8]) = readBlockCount;
|
||||||
|
|
||||||
|
tempResult = Upstream_SendPacket(freePacket);
|
||||||
|
if (tempResult != HAL_OK)
|
||||||
|
{
|
||||||
|
TestReadyCallback(tempResult);
|
||||||
|
}
|
||||||
|
//return Upstream_GetPacket(UpstreamInterface_BeginWriteReplyCallback);
|
||||||
|
return Upstream_GetFreePacket(UpstreamInterface_BeginWriteReplyCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpstreamInterface_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket)
|
||||||
|
{
|
||||||
|
// if ((replyPacket->Length != (UPSTREAM_PACKET_HEADER_LEN + 1)) ||
|
||||||
|
// (replyPacket->CommandClass & COMMAND_CLASS_DATA_FLAG) ||
|
||||||
|
// ((replyPacket->Data[0] != HAL_OK) && (replyPacket->Data[0] != HAL_BUSY)))
|
||||||
|
// {
|
||||||
|
// Upstream_ReleasePacket(replyPacket);
|
||||||
|
// TestReadyCallback(HAL_ERROR);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
Upstream_ReleasePacket(replyPacket);
|
||||||
|
TestReadyCallback(replyPacket->Data[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HAL_StatusTypeDef UpstreamInterface_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);
|
||||||
|
}
|
Loading…
Reference in new issue