@ -13,6 +13,7 @@
# include "usbh_core.h"
# include "usbh_msc.h"
# include "led.h"
# include "interrupts.h"
@ -153,9 +154,9 @@ void Downstream_PacketProcessor_ClassReply(DownstreamPacketTypeDef* replyPacket)
}
//This callback receives various event ids from the host stack, either
// at INT_PRIORITY_OTG_FS or from main(). We should therefore be prepared
// for pre-emption by USB or SPI/DMA interrupts .
//This callback receives various event ids from the host stack,
// either at INT_PRIORITY_OTG_FS or from main().
// We should therefore elevate our execution priority to INT_PRIORITY_OTG_FS where necessary .
void Downstream_HostUserCallback ( USBH_HandleTypeDef * phost , uint8_t id )
{
InterfaceCommandClassTypeDef newActiveClass = COMMAND_CLASS_INTERFACE ;
@ -172,7 +173,19 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id)
return ;
}
//Called from main(). Beware pre-emption!
//Elevate our priority level so we aren't interrupted
__set_BASEPRI ( INT_PRIORITY_OTG_FS ) ;
//Called from main()
if ( id = = HOST_USER_UNRECOVERED_ERROR )
{
DOWNSTREAM_STATEMACHINE_FREAKOUT_NORETURN ;
__set_BASEPRI ( 0 ) ;
return ;
}
//Called from main()
if ( id = = HOST_USER_CLASS_ACTIVE )
{
switch ( phost - > pActiveClass - > ClassCode )
@ -186,11 +199,12 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id)
//Add other classes here...
// Any unsupported device will cause a slow fault flash.
// Unsupported device classes will cause a slow fault flash.
//This is distinct from the fast freakout flash caused by internal errors or attacks.
default :
LED_Fault_SetBlinkRate ( LED_SLOW_BLINK_RATE ) ;
DownstreamState = STATE_ERROR ;
__set_BASEPRI ( 0 ) ;
return ;
}
@ -198,7 +212,9 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id)
//If the new device has failed its 'approval' checks, we are sufficiently freaked out.
if ( newActiveClass = = COMMAND_CLASS_INTERFACE )
{
DOWNSTREAM_STATEMACHINE_FREAKOUT ;
DOWNSTREAM_STATEMACHINE_FREAKOUT_NORETURN ;
__set_BASEPRI ( 0 ) ;
return ;
}
//If we already configured a device class, we cannot change to a different one without rebooting.
@ -206,23 +222,29 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id)
if ( ( ConfiguredDeviceClass ! = COMMAND_CLASS_INTERFACE ) & &
( ConfiguredDeviceClass ! = newActiveClass ) )
{
DOWNSTREAM_STATEMACHINE_FREAKOUT ;
DOWNSTREAM_STATEMACHINE_FREAKOUT_NORETURN ;
__set_BASEPRI ( 0 ) ;
return ;
}
ConfiguredDeviceClass = newActiveClass ;
if ( DownstreamState = = STATE_WAIT_DEVICE_READY )
{
Downstream_GetFreePacket ( Downstream_PacketProcessor_Interface_ReplyNotifyDevice ) ;
__set_BASEPRI ( 0 ) ;
return ;
}
if ( DownstreamState = = STATE_DEVICE_NOT_READY )
{
DownstreamState = STATE_DEVICE_READY ;
__set_BASEPRI ( 0 ) ;
return ;
}
DOWNSTREAM_STATEMACHINE_FREAKOUT ;
DOWNSTREAM_STATEMACHINE_FREAKOUT_NORETURN ;
__set_BASEPRI ( 0 ) ;
return ;
}
}