📄 usb_endp.c
字号:
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
PROJECT : ARM7 USB Core
MODULE : USB_endp.c
AUTHOR : MCD Application Team
CREATION DATE : 21/04/2004
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
DESCRIPTION : Non control endpoints interrupt service routine
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
MODIFICATIONS :
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#include "USB_lib.h"
#include "USB_conf.h"
#include "USB_prop.h"
#include "USB_desc.h"
#include "USB_mem.h"
/*=============================================================================*/
/*=============================================================================*/
/* bulk buffer = circular queue */
#define BULK_QUEUE_SIZE 1024
BYTE abBulkQueue[BULK_QUEUE_SIZE];
WORD wBulkQIns, wBulkQEst;
BYTE bRxBufUsedFromCell, bTxBufUsedFromCell;
/* function prototypes */
void UserToPMABufferCopy(BYTE *pbUsrBuf,WORD wPMABufAddr, WORD wNBytes);
void PMAToUserBufferCopy(BYTE *pbUsrBuf,WORD wPMABufAddr, WORD wNBytes);
void AddQPointer(WORD *pwQPnt,WORD wNBytes,WORD wQMaxSize);
/* ---------------------------------------------------------------------------- */
/* INTERRUPT endpoint service routine */
/* This routine programs bulk endpoints. */
/* ---------------------------------------------------------------------------- */
void StartDblBuff(void)
{
/* enable bulk out */
SetEPType(BULK_OUT_ENDP, EP_BULK);
SetEPDblBuffAddr(BULK_OUT_ENDP, BULK_OUT_BUF0_ADDR, BULK_OUT_BUF1_ADDR);
SetEPDblBuffCount(BULK_OUT_ENDP, EP_DBUF_OUT, BULK_PAY_LOAD);
SetEPDoubleBuff(BULK_OUT_ENDP);
SetEPRxValid(BULK_OUT_ENDP);
/* enable bulk in */
SetEPType(BULK_IN_ENDP, EP_BULK);
SetEPDblBuffAddr(BULK_IN_ENDP, BULK_IN_BUF0_ADDR, BULK_IN_BUF1_ADDR);
SetEPDblBuffCount(BULK_IN_ENDP, EP_DBUF_IN, BULK_PAY_LOAD);
SetEPDoubleBuff(BULK_IN_ENDP);
SetEPTxValid(BULK_IN_ENDP);
/* work variables initialization */
wBulkQIns = 0;
wBulkQEst = 0;
bRxBufUsedFromCell=EP_BUF0;
bTxBufUsedFromCell=EP_BUF0;
} /* StartDblBuff */
/* ---------------------------------------------------------------------------- */
/* BULK OUT Endpoint service routine */
/* gets data received by the OUT endpoint transferring them */
/* from the PMA buffer to the user buffer area. */
/* Then it prepares IN endpoint transferring previous data buffer back from the */
/* user buffer to the PMA buffer. */
/* ---------------------------------------------------------------------------- */
void BULK_OUT_callback()
{
WORD wRcvb, wRxBufAddr, wTxBufAddr;
/* copy the received data stream into the user buffer */
/**/
/* get address & counter of actual buffer */
if(bRxBufUsedFromCell == EP_BUF0)
{
bRxBufUsedFromCell = EP_BUF1;
wRcvb = GetEPDblBuf0Count((BYTE)BULK_OUT_ENDP);
wRxBufAddr = BULK_OUT_BUF0_ADDR;
}
else if(bRxBufUsedFromCell == EP_BUF1)
{
bRxBufUsedFromCell = EP_BUF0;
wRcvb = GetEPDblBuf1Count(BULK_OUT_ENDP);
wRxBufAddr = BULK_OUT_BUF1_ADDR;
}
/* copy of rx buffer */
PMAToUserBufferCopy((BYTE *)&abBulkQueue[wBulkQIns], wRxBufAddr, wRcvb);
/* update insertion pointer */
AddQPointer(&wBulkQIns,wRcvb,BULK_QUEUE_SIZE);
/* free the user buffer */
FreeUserBuffer(BULK_OUT_ENDP);
/* set bulk-in endpoint for transmission */
if(bTxBufUsedFromCell == EP_BUF0)
{
wTxBufAddr = BULK_IN_BUF0_ADDR;
SetEPDblBuf0Count(BULK_IN_ENDP,EP_DBUF_IN,wRcvb);
}
else if(bTxBufUsedFromCell == EP_BUF1)
{
wTxBufAddr = BULK_IN_BUF1_ADDR;
SetEPDblBuf1Count(BULK_IN_ENDP,EP_DBUF_IN,wRcvb);
}
UserToPMABufferCopy((BYTE *)&abBulkQueue[wBulkQEst],wTxBufAddr, wRcvb);
}/* BULK_OUT_callback */
/* ---------------------------------------------------------------------------- */
/* BULK IN Endpoint service routine */
/* at the end of transmission updates extraction pointer */
/* ---------------------------------------------------------------------------- */
void BULK_IN_callback()
{
WORD wTxmBytes;
/* get counter of sent bytes */
if(bTxBufUsedFromCell == EP_BUF0)
{
bTxBufUsedFromCell = EP_BUF1;
wTxmBytes = GetEPDblBuf0Count(BULK_IN_ENDP);
}
else if(bTxBufUsedFromCell == EP_BUF1)
{
bTxBufUsedFromCell = EP_BUF0;
wTxmBytes = GetEPDblBuf1Count(BULK_IN_ENDP);
}
/* update extraction pointer */
AddQPointer(&wBulkQEst,wTxmBytes,BULK_QUEUE_SIZE);
/* free the user buffer */
FreeUserBuffer(BULK_IN_ENDP);
} /* BULK_IN_callback */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -