📄 ms_bot.c
字号:
* purpose : No write to flash
*
* input parameters : none
*
* output parameters : none
*
* global data :
*
******************************************************************/
void ms_finishNoFlash( void )
{
usb_send((char*)&usbms_context.csw, sizeof(USBMS_CSW));
usbms_context.state = PROCESS_CSW;
}
/******************************************************************
*
* SUB-ROUTINE : ms_processTx
*
*------------------------------------------------------------------
*
* purpose : Go to state IDLE
*
* input parameters : none
*
* output parameters : none
*
* global data :
*
******************************************************************/
void ms_processTx( void )
{
usbms_context.state = IDLE;
}
/******************************************************************
*
* SUB-ROUTINE : ms_problem
*
*------------------------------------------------------------------
*
* purpose : We have a problem in our automate algorith
*
* input parameters : none
*
* output parameters : none
*
* global data : none
*
******************************************************************/
void ms_problem( void )
{
/* Algorith problem, so make a debug trace */
#ifdef TR_ERROR
TRACE_ERROR( "ev%d-",DBG_EVT);
#endif
}
/******************************************************************
*
* SUB-ROUTINE : ms_initAutomat
*
*------------------------------------------------------------------
*
* purpose : Initialisation of automate
*
* input parameters : none
*
* output parameters : none
*
* global data : ms_auto
*
******************************************************************/
void ms_initAutomat( void )
{
TRACE_DEBUG_H( "initAutomat\n\r");
ms_plugInit( );
/* Init states of automat */
ms_auto[IDLE][MS_PLUG ] = ms_problem;
ms_auto[IDLE][MS_UNPLUG ] = ms_goToInit;
ms_auto[IDLE][MS_STALL_IN ] = ms_problem;
ms_auto[IDLE][MS_STALL_OUT] = ms_problem;
ms_auto[IDLE][MS_USB_RX ] = ms_idleRx;
ms_auto[IDLE][MS_USB_TX ] = ms_problem;
ms_auto[GET_FROM_USB][MS_PLUG ] = ms_problem;
ms_auto[GET_FROM_USB][MS_UNPLUG ] = ms_goToInit;
ms_auto[GET_FROM_USB][MS_STALL_IN ] = ms_problem;
ms_auto[GET_FROM_USB][MS_STALL_OUT] = ms_problem;
ms_auto[GET_FROM_USB][MS_USB_RX ] = ms_getRx;
ms_auto[GET_FROM_USB][MS_USB_TX ] = ms_problem;
ms_auto[SEND_TO_USB][MS_PLUG ] = ms_problem;
ms_auto[SEND_TO_USB][MS_UNPLUG ] = ms_goToInit;
ms_auto[SEND_TO_USB][MS_STALL_IN ] = ms_problem;
ms_auto[SEND_TO_USB][MS_STALL_OUT] = ms_problem;
ms_auto[SEND_TO_USB][MS_USB_RX ] = ms_problem;
ms_auto[SEND_TO_USB][MS_USB_TX ] = ms_sendTx;
ms_auto[USB_SEND_NO_FLASH][MS_PLUG ] = ms_problem;
ms_auto[USB_SEND_NO_FLASH][MS_UNPLUG ] = ms_goToInit;
ms_auto[USB_SEND_NO_FLASH][MS_STALL_IN ] = ms_problem;
ms_auto[USB_SEND_NO_FLASH][MS_STALL_OUT] = ms_problem;
ms_auto[USB_SEND_NO_FLASH][MS_USB_RX ] = ms_problem;
ms_auto[USB_SEND_NO_FLASH][MS_USB_TX ] = ms_finishNoFlash;
ms_auto[RESET_IN_PROGRESS][MS_PLUG ] = ms_problem;
ms_auto[RESET_IN_PROGRESS][MS_UNPLUG ] = ms_goToInit;
ms_auto[RESET_IN_PROGRESS][MS_STALL_IN ] = ms_rstProgStallIn;
ms_auto[RESET_IN_PROGRESS][MS_STALL_OUT] = ms_rstProgStallOut;
ms_auto[RESET_IN_PROGRESS][MS_USB_RX ] = ms_problem;
ms_auto[RESET_IN_PROGRESS][MS_USB_TX ] = ms_problem;
ms_auto[PROCESS_CSW][MS_PLUG ] = ms_problem;
ms_auto[PROCESS_CSW][MS_UNPLUG ] = ms_goToInit;
ms_auto[PROCESS_CSW][MS_STALL_IN ] = ms_problem;
ms_auto[PROCESS_CSW][MS_STALL_OUT] = ms_problem;
ms_auto[PROCESS_CSW][MS_USB_RX ] = ms_problem;
ms_auto[PROCESS_CSW][MS_USB_TX ] = ms_processTx;
ms_auto[INIT][MS_PLUG ] = ms_plugInit;
ms_auto[INIT][MS_UNPLUG ] = ms_plugInit;
ms_auto[INIT][MS_STALL_IN ] = ms_problem;
ms_auto[INIT][MS_STALL_OUT] = ms_problem;
ms_auto[INIT][MS_USB_RX ] = ms_problem;
ms_auto[INIT][MS_USB_TX ] = ms_problem;
}
/*****************************************************************
*
* ROUTINE : ms_classRequest
*
*-----------------------------------------------------------------
*
* Purpose :
*
* Input parameters :
*
* Output parameters :
*
* Global data : USBMS_OK : OK
* USBMS_ERROR : ERROR
*
*****************************************************************/
USBMS_RETURN ms_classRequest( FW_DEVICE_REQUEST commandBuff, UCHAR *databuff, UCHAR *datasize)
{
USBMS_RETURN _status = USBMS_OK;
if( RESET_REQUEST_TYPE == commandBuff.bmRequestType )
{
/* nothing to do */
*datasize = 0;
}
else
{
if( MAX_LUN_REQUEST_TYPE == commandBuff.bmRequestType )
{
/* set */
databuff[0] = 0;
*datasize = 1; /* we support only one media. */
}
else
{
_status = USBMS_ERROR;
TRACE_DEBUG_L( "ClassRequestERR:%d\n\r", commandBuff.bmRequestType );
}
}
return _status;
}
/*****************************************************************
*
* ROUTINE : ms_sendComplete
*
*-----------------------------------------------------------------
*
* Purpose : Send complete
*
* Input parameters : none
*
* Output parameters : none
*
* Global data :
*
*****************************************************************/
void ms_sendComplete( void )
{
#ifdef TR_ERROR
DBG_EVT = MS_USB_TX;
#endif
po_lock();
ms_auto[usbms_context.state][MS_USB_TX]();
po_unlock();
}
/*****************************************************************
*
* ROUTINE : ms_dataReceived
*
*-----------------------------------------------------------------
*
* Purpose : Receive data
*
* Input parameters : none
*
* Output parameters : none
*
* Global data :
*
*****************************************************************/
void ms_dataReceived( void )
{
#ifdef TR_ERROR
DBG_EVT = MS_USB_RX;
#endif
po_lock();
ms_auto[usbms_context.state][MS_USB_RX]();
po_unlock();
}
/*****************************************************************
*
* ROUTINE : ms_usbEvent
*
*-----------------------------------------------------------------
*
* Purpose : Treatment of flag EVENT
*
* Input parameters : eventMask
*
* Output parameters : none
*
* Global data : USB_EVENT
*
*****************************************************************/
#ifdef ADS_COMPIL
void ms_usbEvent( UCHAR eventMask )
#else
__ramfunc void ms_usbEvent( UCHAR eventMask )
#endif
{
if( 0 != (USB_EVENT_MASK_RESUME & eventMask) )
{
/* RESUME has been receive */
USB_EVENT &= ~USB_EVENT_MASK_RESUME;
/* nothing do do in this case ? */
/* ms_auto[usbms_context.state][MS_RESUME] */
TRACE_ERROR( "R\n\r");
}
else
{
if( 0 != (USB_EVENT_MASK_SUSPEND & eventMask) )
{
/* SUSPEND has been receive */
USB_EVENT &= ~USB_EVENT_MASK_SUSPEND;
/* nothing do do in this case ? */
/* ms_auto[usbms_context.state][MS_SUSPEND] */
TRACE_ERROR( "S\n\r");
}
else
{
if( 0 != (USB_EVENT_MASK_UNPLUG & eventMask) )
{
/* UNPLUG has been receive */
USB_EVENT &= ~USB_EVENT_MASK_UNPLUG;
#ifdef TR_ERROR
DBG_EVT = MS_UNPLUG;
#endif
po_lock();
ms_auto[usbms_context.state][MS_UNPLUG]();
po_unlock();
}
else
{
if( 0 != (USB_EVENT_MASK_PLUG & eventMask) )
{
/* PLUG has been receive */
USB_EVENT &= ~USB_EVENT_MASK_PLUG;
#ifdef TR_ERROR
DBG_EVT = MS_PLUG;
#endif
po_lock();
ms_auto[usbms_context.state][MS_PLUG]();
po_unlock();
}
else
{
if( 0 != (USB_EVENT_MASK_OUT_STALL_CLEARED & eventMask) )
{
/* OUT_STALL_CLEARED has been receive */
USB_EVENT &= ~USB_EVENT_MASK_OUT_STALL_CLEARED;
#ifdef TR_ERROR
DBG_EVT = MS_STALL_OUT;
#endif
po_lock();
ms_auto[usbms_context.state][MS_STALL_OUT]();
po_unlock();
}
else
{
if( 0 != (USB_EVENT_MASK_IN_STALL_CLEARED & eventMask) )
{
/* IN_STALL_CLEARED has been receive */
USB_EVENT &= ~USB_EVENT_MASK_IN_STALL_CLEARED;
#ifdef TR_ERROR
DBG_EVT = MS_STALL_IN;
#endif
po_lock();
ms_auto[usbms_context.state][MS_STALL_IN]();
po_unlock();
}
else
{
/* ERROR */
TRACE_ERROR( "Event ERROR\n\r");
USB_EVENT &= ( USB_EVENT_MASK_SUSPEND | USB_EVENT_MASK_RESUME
| USB_EVENT_MASK_PLUG | USB_EVENT_MASK_UNPLUG
| USB_EVENT_MASK_OUT_STALL_CLEARED
| USB_EVENT_MASK_IN_STALL_CLEARED );
}
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -