1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-24 00:35:14 +03:00

Bootloader MAC fixes from Mike

This commit is contained in:
bsongis 2014-04-08 10:26:08 +02:00
parent a72df4ca16
commit 30111d9299
6 changed files with 73 additions and 6 deletions

View file

@ -715,8 +715,11 @@ int main()
uint8_t event = getEvent(); uint8_t event = getEvent();
if (usbPlugged()) { if (state != ST_USB) {
state = ST_USB; if (usbPlugged()) {
state = ST_USB;
usbPluggedIn();
}
} }
if (state == ST_START) { if (state == ST_START) {

View file

@ -54,7 +54,7 @@ static SBCInquiryData inquiryData = {
SBC_PERIPHERAL_DEVICE_CONNECTED,// Peripheral device is connected SBC_PERIPHERAL_DEVICE_CONNECTED,// Peripheral device is connected
0x00, // Reserved bits 0x00, // Reserved bits
0x01, // Media is removable 0x01, // Media is removable
SBC_SPC_VERSION_4, // SPC-4 supported 0x02, // SBC_SPC_VERSION_4, // SPC-4 supported
0x2, // Response data format, must be 0x2 0x2, // Response data format, must be 0x2
0, // Hierarchical addressing not supported 0, // Hierarchical addressing not supported
0, // ACA not supported 0, // ACA not supported

View file

@ -94,6 +94,8 @@
#define SBC_VERIFY_10 0x2F #define SBC_VERIFY_10 0x2F
/// Request a list of the possible capacities that can be formatted on medium /// Request a list of the possible capacities that can be formatted on medium
#define SBC_READ_FORMAT_CAPACITIES 0x23 #define SBC_READ_FORMAT_CAPACITIES 0x23
#define SBC_START_STOP 0x19
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -620,6 +622,21 @@ typedef struct {
} __attribute__ ((packed)) SBCReadWriteErrorRecovery; // GCC } __attribute__ ((packed)) SBCReadWriteErrorRecovery; // GCC
//------------------------------------------------------------------------------
/// \brief start/stop command
/// \see
//------------------------------------------------------------------------------
typedef struct {
unsigned char bModeDataLength; //!< Length of mode data to follow
unsigned char bImmediate:1, //!<
bReserved1:7; //!< Reserved bits
unsigned char pReserved[2]; //!< Reserved bytes
unsigned char startStop:1, //!< DPO/FUA bits supported ?
eject:1, //!< Reserved bits
bReserved2:6; //!< Is medium write-protected ?
} __attribute__ ((packed)) SBCStartStop; // GCC
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/// \brief Generic structure for holding information about SBC commands /// \brief Generic structure for holding information about SBC commands
/// \see SBCInquiry /// \see SBCInquiry
@ -642,6 +659,7 @@ typedef union {
SBCWrite10 write10; //!< WRITE (10) command SBCWrite10 write10; //!< WRITE (10) command
SBCMediumRemoval mediumRemoval; //!< PREVENT/ALLOW MEDIUM REMOVAL command SBCMediumRemoval mediumRemoval; //!< PREVENT/ALLOW MEDIUM REMOVAL command
SBCModeSense6 modeSense6; //!< MODE SENSE (6) command SBCModeSense6 modeSense6; //!< MODE SENSE (6) command
SBCStartStop startStopCmd; //!< START-STOP command
} SBCCommand; } SBCCommand;

View file

@ -1430,7 +1430,7 @@ unsigned char SBC_GetCommandInformation(void *command,
//------------------------------------ //------------------------------------
case SBC_PREVENT_ALLOW_MEDIUM_REMOVAL: case SBC_PREVENT_ALLOW_MEDIUM_REMOVAL:
case 0x1B: case SBC_START_STOP:
//------------------------------------ //------------------------------------
(*type) = MSDD_NO_TRANSFER; (*type) = MSDD_NO_TRANSFER;
break; break;
@ -1590,7 +1590,6 @@ unsigned char SBC_ProcessCommand(MSDLun *lun,
//------------------------------------ //------------------------------------
case SBC_PREVENT_ALLOW_MEDIUM_REMOVAL: case SBC_PREVENT_ALLOW_MEDIUM_REMOVAL:
case 0x1B:
//------------------------------------ //------------------------------------
TRACE_INFO_WP("PrevAllowRem "); TRACE_INFO_WP("PrevAllowRem ");
@ -1600,6 +1599,19 @@ unsigned char SBC_ProcessCommand(MSDLun *lun,
result = MSDD_STATUS_SUCCESS; result = MSDD_STATUS_SUCCESS;
break; break;
case SBC_START_STOP:
TRACE_INFO_WP("StartStop ");
result = command->startStopCmd.startStop ;
if (result == 0) {
lun->status = LUN_EJECTED ;
}
else {
lun->status = LUN_CHANGED ;
}
result = MSDD_STATUS_SUCCESS;
break;
#if 0 #if 0
//------------------------------------ //------------------------------------
case SBC_READ_FORMAT_CAPACITIES: case SBC_READ_FORMAT_CAPACITIES:

View file

@ -432,9 +432,24 @@ void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC)
* @param params: Command parameters * @param params: Command parameters
* @retval status * @retval status
*/ */
extern uint8_t lunReady[] ;
static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params) static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params)
{ {
MSC_BOT_DataLen = 0; MSC_BOT_DataLen = 0;
if (lun < 2) {
if (params[4] & 1) {
// lun to be active
lunReady[lun] = 1 ;
}
else {
// lun to be ejected
lunReady[lun] = 0 ;
}
}
return 0; return 0;
} }

View file

@ -161,6 +161,19 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
return 0; return 0;
} }
uint8_t lunReady[2] ;
void usbPluggedIn()
{
if (lunReady[0] == 0) {
lunReady[0] = 1;
}
if (lunReady[1] == 0) {
lunReady[1] = 1;
}
}
/** /**
* @brief check whether the medium is ready * @brief check whether the medium is ready
* @param lun : logical unit number * @param lun : logical unit number
@ -169,9 +182,15 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
int8_t STORAGE_IsReady (uint8_t lun) int8_t STORAGE_IsReady (uint8_t lun)
{ {
if (lun == 1) { if (lun == 1) {
return 0; if (lunReady[1] == 0) {
return -1 ;
}
return 0 ;
} }
else { else {
if (lunReady[0] == 0) {
return -1 ;
}
return SD_CARD_PRESENT() ? 0 : -1; return SD_CARD_PRESENT() ? 0 : -1;
} }
} }