📄 parser.c
字号:
* -------------------------------------*/
USB_Send_Data(byteToWrite,writePtr);
writePtr += byteToWrite;
}
else
/* ------------------------------------------------------------------------------
* Send a new packet, each byte of which is equal to a one determined by the host.
*-------------------------------------------------------------------------------*/
USB_bulk_write_data(byteToWrite,bulkState.data);
}
}
/*---------------------------------
* There is no more data to send
*--------------------------------*/
else
{
/*------------------------------------
* Send zero length packet to
* mark end of the data, if needed
* -----------------------------------*/
if (bulkState.zeroPacketNeed)
{
usbn9604_tx_enable(ENDPOINT_1);
bulkState.zeroPacketNeed = FALSE;
}
clear_event(EVT_USB_BULK_TX);
/*--------------------------------------------------
* Put the pointer to the begging of the local buffer
*-------------------------------------------------*/
writePtr = buffer;
bulkState.bulkCommand = BULK_NO_COMMAND;
bulkState.dataSize = 0;
bulkState.numOfErrors = 0;
bulkState.data = 0;
}
}
/*---------------------------------
* Should interrupt packet be sent?
*---------------------------------*/
if (event_table&EVT_TIMER_INT)
{
/*-------------------------------
* Is it interrupt get command
*------------------------------*/
if (interruptState.interruptCommand == INTERRUPT_GET_INT)
{
/*-------------------------------------
* Send new interrupt packet containing
* this interrupt serial number
*--------------------------------------*/
USB_Send_Interrupt(interruptState.interruptNum - interruptState.restToSend);
clear_event(EVT_TIMER_INT);
interruptState.restToSend--;
/*-------------------------------
* Should we send more interrupts?
* -------------------------------*/
if (interruptState.restToSend != 0)
/*---------------------------------------------------
* restart the timer for next interrupt generation
*--------------------------------------------------*/
TOUCH_WATCHDOG(interruptState.interval);
else
{ /*-----------------------------------------------
* All the interrupts were sent. Stop the timer
*-----------------------------------------------*/
WATCHDOG_STOP;
interruptState.interruptCommand = INTERRUPT_NO_COMMAND;
}
}
}
}
}
return 1;
}
/*----------------------------------------------------------------------------------------------
* Prototype
* byte Bulk_Parser(USB_request_t *req)
*
* Parameters
* req - pointer to structure representing host request
*
* Returns
* Success
*
* Description
* Parses an imcoming bulk command
----------------------------------------------------------------------------------------------*/
byte Bulk_Parser(USB_request_t *req)
{
byte count;
byte command;
/*-----------------------------------------------------------------------------------
* Read the command, parse it and update relevant fields in the bulk state structure.
*----------------------------------------------------------------------------------*/
command = REQ_VENDOR(req);
bulkState.bulkCommand = command;
bulkState.dataSize = ((dword)(REQ_VALUE(req).lsw)|(((dword)(REQ_INDEX(req).msw)) << 16));
bulkState.numOfErrors = 0;
switch (command)
{
case BULK_SEND_IMM_BACK:
bulkState.restToRead = bulkState.dataSize;
bulkState.restToWrite = bulkState.dataSize;
bulkState.zeroPacketNeed = !(bulkState.dataSize%TX_BULK_EP_FIFO_SIZE);
bulkState.bufferForGetData = 0;
bulkState.bufferForSendData = 0;
bulkState.bulkBuff[0].getReady = TRUE;
bulkState.bulkBuff[1].getReady = TRUE;
bulkState.bulkBuff[0].sendReady = FALSE;
bulkState.bulkBuff[1].sendReady = FALSE;
bulkState.bulkBuff[0].nextBuf = 1;
bulkState.bulkBuff[1].nextBuf = 0;
send_event(EVT_USB_BULK_TX);
break;
case BULK_SEND_AFTER_LAST_BACK:
bulkState.restToRead = bulkState.dataSize;
bulkState.restToWrite = bulkState.dataSize;
bulkState.zeroPacketNeed = !(bulkState.dataSize%TX_BULK_EP_FIFO_SIZE);
break;
case BULK_GET_DATA:
bulkState.restToRead = bulkState.dataSize;
bulkState.data = (REQ_LENGTH(req)&0x00ff);
break;
case BULK_SEND_DATA:
bulkState.restToWrite = bulkState.dataSize;
bulkState.data = (REQ_LENGTH(req)&0x00ff);
bulkState.zeroPacketNeed = !(bulkState.dataSize%TX_BULK_EP_FIFO_SIZE);
send_event(EVT_USB_BULK_TX);
break;
default :
return 0;
break;
}
zero_length_data_response(ENDPOINT_0);
return 1;
}
/*----------------------------------------------------------------------------------------------
* Prototype
* byte Interrupt_Parser(USB_request_t *req)
*
* Parameters
* req - pointer to structure representing host request
*
* Returns
* Success
*
* Description
* Parses an imcoming interrupt command
----------------------------------------------------------------------------------------------*/
byte Interrupt_Parser(USB_request_t *req)
{
byte command;
/*-----------------------------------------------------------------------------------
* Read the command, parse it and update relevant fields in the interrupt state structure.
*----------------------------------------------------------------------------------*/
command = REQ_VENDOR(req);
interruptState.interruptCommand = command;
switch( command )
{
case INTERRUPT_GET_INT:
interruptState.interruptNum = (word) REQ_VALUE(req).lsw;
interruptState.interval = (word)REQ_INDEX(req).msw;
interruptState.restToSend = interruptState.interruptNum;
/*----------------------------------------------------
* Initialize and start timer for interrupts generation
* using interval determined by the host
*----------------------------------------------------*/
TOUCH_WATCHDOG(interruptState.interval);
WATCHDOG_START;
break;
default :
break;
}
zero_length_data_response(ENDPOINT_0);
return 1;
}
/*----------------------------------------------------------------------------------------------
* Prototype
* byte Gen_Parser(USB_request_t *req)
*
* Parameters
* req - pointer to structure representing host request
*
* Returns
* Success
*
* Description
* Parses an imcoming general command
----------------------------------------------------------------------------------------------*/
byte Gen_Parser(USB_request_t *req)
{
byte command;
command = REQ_VENDOR(req);
switch (command)
{
case GET_FEEDBACK:
if (bulkState.bulkCommand == BULK_GET_DATA)
{
/*----------------------------------------------
* number of bytes received in the last request
-----------------------------------------------*/
*((dword *)&feedback[0]) = bulkState.dataSize - bulkState.restToRead ;
*((dword *)&feedback[4]) = bulkState.numOfErrors;
device_buffers.zero_data=1;
send_control_data(feedback,8);
}
break;
case STOP_REQUEST:
default :
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -