- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the fx3 SDK did not have vend_request sample,so,I just want to write one,
but,when I download,fx3 can not be detected,,,,
who just give me some advices?thank you..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Please attach the vendor request part of your code here I would like to take a look at it.
Regards,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the main code added in the SlaveFifoSync is here,
CyU3PThread slFifoAppThread; /* Slave FIFO application thread structure */
CyU3PDmaChannel glChHandleSlFifoUtoP; /* DMA Channel handle for U2P transfer. */
CyU3PDmaChannel glChHandleSlFifoPtoU; /* DMA Channel handle for P2U transfer. */
uint32_t glDMARxCount = 0; /* Counter to track the number of buffers received from USB. */
uint32_t glDMATxCount = 0; /* Counter to track the number of buffers sent to USB. */
CyBool_t glIsApplnActive = CyFalse; /* Whether the loopback application is active or not. */
static CyU3PThread vndAppEP0Thread;
static CyU3PEvent glFxVREQEvent; // vendor request event flags
static uint8_t Ep0_InData[16]; // ep0 in data buffer
static uint8_t Ep0_OutData[16]; // ep0 out data buffer
void VndReqEP0Thread_Entry (uint32_t); /* Declaration for the thread entry function */
/* Application Error Handler */
void
CyFxAppErrorHandler (
CyU3PReturnStatus_t apiRetStatus /* API return status */
)
{
/* Application failed with the error code apiRetStatus */
/* Add custom debug or recovery actions here */
/* Loop Indefinitely */
for (;;)
{
/* Thread sleep : 100 ms */
CyU3PThreadSleep (100);
}
}
/* This function initializes the debug module. The debug prints
* are routed to the UART and can be seen using a UART console
* running at 115200 baud rate. */
void
CyFxSlFifoApplnDebugInit (void)
{
CyU3PUartConfig_t uartConfig;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
/* Initialize the UART for printing debug messages */
apiRetStatus = CyU3PUartInit();
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyFxAppErrorHandler(apiRetStatus);
}
/* Set UART configuration */
CyU3PMemSet ((uint8_t *)&uartConfig, 0, sizeof (uartConfig));
uartConfig.baudRate = CY_U3P_UART_BAUDRATE_115200;
uartConfig.stopBit = CY_U3P_UART_ONE_STOP_BIT;
uartConfig.parity = CY_U3P_UART_NO_PARITY;
uartConfig.txEnable = CyTrue;
uartConfig.rxEnable = CyFalse;
uartConfig.flowCtrl = CyFalse;
uartConfig.isDma = CyTrue;
apiRetStatus = CyU3PUartSetConfig (&uartConfig, NULL);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}
/* Set the UART transfer to a really large value. */
apiRetStatus = CyU3PUartTxSetBlockXfer (0xFFFFFFFF);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}
/* Initialize the debug module. */
apiRetStatus = CyU3PDebugInit (CY_U3P_LPP_SOCKET_UART_CONS, 8);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}
}
/* DMA callback function to handle the produce events for U to P transfers. */
void
CyFxSlFifoUtoPDmaCallback (
CyU3PDmaChannel *chHandle,
CyU3PDmaCbType_t type,
CyU3PDmaCBInput_t *input
)
{
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
if (type == CY_U3P_DMA_CB_PROD_EVENT)
{
/* This is a produce event notification to the CPU. This notification is
* received upon reception of every buffer. The buffer will not be sent
* out unless it is explicitly committed. The call shall fail if there
* is a bus reset / usb disconnect or if there is any application error. */
status = CyU3PDmaChannelCommitBuffer (chHandle, input->buffer_p.count, 0);
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCommitBuffer failed, Error code = %d\n", status);
}
/* Increment the counter. */
glDMARxCount++;
}
}
/* DMA callback function to handle the produce events for P to U transfers. */
void
CyFxSlFifoPtoUDmaCallback (
CyU3PDmaChannel *chHandle,
CyU3PDmaCbType_t type,
CyU3PDmaCBInput_t *input
)
{
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
if (type == CY_U3P_DMA_CB_PROD_EVENT)
{
/* This is a produce event notification to the CPU. This notification is
* received upon reception of every buffer. The buffer will not be sent
* out unless it is explicitly committed. The call shall fail if there
* is a bus reset / usb disconnect or if there is any application error. */
status = CyU3PDmaChannelCommitBuffer (chHandle, input->buffer_p.count, 0);
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCommitBuffer failed, Error code = %d\n", status);
}
/* Increment the counter. */
glDMATxCount++;
}
}
/* This function starts the slave FIFO loop application. This is called
* when a SET_CONF event is received from the USB host. The endpoints
* are configured and the DMA pipe is setup in this function. */
void
CyFxSlFifoApplnStart (
void)
{
uint16_t size = 0;
CyU3PEpConfig_t epCfg;
CyU3PDmaChannelConfig_t dmaCfg;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
CyU3PUSBSpeed_t usbSpeed = CyU3PUsbGetSpeed();
/* First identify the usb speed. Once that is identified,
* create a DMA channel and start the transfer on this. */
/* Based on the Bus Speed configure the endpoint packet size */
switch (usbSpeed)
{
case CY_U3P_FULL_SPEED:
size = 64;
break;
case CY_U3P_HIGH_SPEED:
size = 512;
break;
case CY_U3P_SUPER_SPEED:
size = 1024;
break;
default:
CyU3PDebugPrint (4, "Error! Invalid USB speed.\n");
CyFxAppErrorHandler (CY_U3P_ERROR_FAILURE);
break;
}
CyU3PMemSet ((uint8_t *)&epCfg, 0, sizeof (epCfg));
epCfg.enable = CyTrue;
epCfg.epType = CY_U3P_USB_EP_BULK;
epCfg.burstLen = CY_FX_SLFIFO_PACKETS_PER_BURST;
epCfg.streams = 0;
epCfg.pcktSize = size;
/* Producer endpoint configuration */
apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_PRODUCER, &epCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler (apiRetStatus);
}
/* Consumer endpoint configuration */
apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_CONSUMER, &epCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler (apiRetStatus);
}
/* Create a DMA MANUAL channel for U2P transfer.
* DMA size is set based on the USB speed. */
dmaCfg.size = size;
dmaCfg.count = CY_FX_SLFIFO_DMA_BUF_COUNT;
dmaCfg.prodSckId = CY_FX_PRODUCER_USB_SOCKET;
dmaCfg.consSckId = CY_FX_CONSUMER_PPORT_SOCKET;
dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE;
/* Enabling the callback for produce event. */
dmaCfg.notification = CY_U3P_DMA_CB_PROD_EVENT;
dmaCfg.cb = CyFxSlFifoUtoPDmaCallback;
dmaCfg.prodHeader = 0;
dmaCfg.prodFooter = 0;
dmaCfg.consHeader = 0;
dmaCfg.prodAvailCount = 0;
apiRetStatus = CyU3PDmaChannelCreate (&glChHandleSlFifoUtoP,
CY_U3P_DMA_TYPE_AUTO, &dmaCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCreate failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Create a DMA MANUAL channel for P2U transfer. */
dmaCfg.prodSckId = CY_FX_PRODUCER_PPORT_SOCKET;
dmaCfg.consSckId = CY_FX_CONSUMER_USB_SOCKET;
dmaCfg.cb = CyFxSlFifoPtoUDmaCallback;
apiRetStatus = CyU3PDmaChannelCreate (&glChHandleSlFifoPtoU,
CY_U3P_DMA_TYPE_AUTO, &dmaCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCreate failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Flush the Endpoint memory */
CyU3PUsbFlushEp(CY_FX_EP_PRODUCER);
CyU3PUsbFlushEp(CY_FX_EP_CONSUMER);
/* Set DMA channel transfer size. */
apiRetStatus = CyU3PDmaChannelSetXfer (&glChHandleSlFifoUtoP, CY_FX_SLFIFO_DMA_TX_SIZE);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelSetXfer Failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
apiRetStatus = CyU3PDmaChannelSetXfer (&glChHandleSlFifoPtoU, CY_FX_SLFIFO_DMA_TX_SIZE);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelSetXfer Failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Update the status flag. */
glIsApplnActive = CyTrue;
}
/* This function stops the slave FIFO loop application. This shall be called
* whenever a RESET or DISCONNECT event is received from the USB host. The
* endpoints are disabled and the DMA pipe is destroyed by this function. */
void
CyFxSlFifoApplnStop (
void)
{
CyU3PEpConfig_t epCfg;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
/* Update the flag. */
glIsApplnActive = CyFalse;
/* Flush the endpoint memory */
CyU3PUsbFlushEp(CY_FX_EP_PRODUCER);
CyU3PUsbFlushEp(CY_FX_EP_CONSUMER);
/* Destroy the channel */
CyU3PDmaChannelDestroy (&glChHandleSlFifoUtoP);
CyU3PDmaChannelDestroy (&glChHandleSlFifoPtoU);
/* Disable endpoints. */
CyU3PMemSet ((uint8_t *)&epCfg, 0, sizeof (epCfg));
epCfg.enable = CyFalse;
/* Producer endpoint configuration. */
apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_PRODUCER, &epCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler (apiRetStatus);
}
/* Consumer endpoint configuration. */
apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_CONSUMER, &epCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler (apiRetStatus);
}
}
/* Callback to handle the USB setup requests. */
CyBool_t
CyFxSlFifoApplnUSBSetupCB (
uint32_t setupdat0,
uint32_t setupdat1
)
{
uint8_t setupReqType, setupReq;
CyU3PReturnStatus_t apiRetStatus;
CyBool_t vndHandleReq = CyFalse;
/* Obtain Request Type and Request */
setupReqType = (uint8_t)(setupdat0 & CY_FX_USB_SETUP_REQ_TYPE_MASK);
setupReq = (uint8_t)((setupdat0 & CY_FX_USB_SETUP_REQ_MASK) >> 8);
/* Check for user vendor request */
if (setupReq == CY_FX_VND_REQ1)
{
/* Vendor requests are handled in the application */
vndHandleReq = CyTrue;
/* Check for vendor request upload */
if (setupReqType == CY_FX_USB_VND_GET_REQ_TYPE)
{
apiRetStatus = CyU3PEventSet(&glFxVREQEvent,CY_FX_VREQ_RD,CYU3P_EVENT_OR);
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyU3PDebugPrint (4, "Get Vendor Request Event Failed, Error Code = %d\n",apiRetStatus);
}
}
/* Check for vendor request download */
else if (setupReqType == CY_FX_USB_VND_SET_REQ_TYPE)
apiRetStatus = CyU3PEventSet(&glFxVREQEvent,CY_FX_VREQ_WR,CYU3P_EVENT_OR);
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyU3PDebugPrint (4, "Set Vendor Request Event Failed, Error Code = %d\n",apiRetStatus);
}
/* Fast enumeration is used. Only class, vendor and unknown requests
* are received by this function. These are not handled in this
* application. Hence return CyFalse. */
}
return CyFalse;
}
/* This is the callback function to handle the USB events. */
void
CyFxSlFifoApplnUSBEventCB (
CyU3PUsbEventType_t evtype,
uint16_t evdata
)
{
switch (evtype)
{
case CY_U3P_USB_EVENT_SETCONF:
/* Stop the application before re-starting. */
if (glIsApplnActive)
{
CyFxSlFifoApplnStop ();
}
/* Start the loop back function. */
CyFxSlFifoApplnStart ();
break;
case CY_U3P_USB_EVENT_RESET:
case CY_U3P_USB_EVENT_DISCONNECT:
/* Stop the loop back function. */
if (glIsApplnActive)
{
CyFxSlFifoApplnStop ();
}
break;
default:
break;
}
}
/* This function initializes the GPIF interface and initializes
* the USB interface. */
void
CyFxSlFifoApplnInit (void)
{
CyU3PPibClock_t pibClock;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
/* Initialize the p-port block. */
pibClock.clkDiv = 2;
pibClock.clkSrc = CY_U3P_SYS_CLK;
pibClock.isHalfDiv = CyFalse;
/* Disable DLL for sync GPIF */
pibClock.isDllEnable = CyFalse;
apiRetStatus = CyU3PPibInit(CyTrue, &pibClock);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "P-port Initialization failed, Error Code = %d\n",apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Load the GPIF configuration for Slave FIFO sync mode. */
apiRetStatus = CyU3PGpifLoad (&Sync_Slave_Fifo_2Bit_CyFxGpifConfig);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PGpifLoad failed, Error Code = %d\n",apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Start the state machine. */
apiRetStatus = CyU3PGpifSMStart (SYNC_SLAVE_FIFO_2BIT_RESET, SYNC_SLAVE_FIFO_2BIT_ALPHA_RESET);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PGpifSMStart failed, Error Code = %d\n",apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Start the USB functionality. */
apiRetStatus = CyU3PUsbStart();
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PUsbStart failed to Start, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* The fast enumeration is the easiest way to setup a USB connection,
* where all enumeration phase is handled by the library. Only the
* class / vendor requests need to be handled by the application. */
CyU3PUsbRegisterSetupCallback(CyFxSlFifoApplnUSBSetupCB, CyTrue);
/* Setup the callback to handle the USB events. */
CyU3PUsbRegisterEventCallback(CyFxSlFifoApplnUSBEventCB);
/* Set the USB Enumeration descriptors */
/* Super speed device descriptor. */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_DEVICE_DESCR, NULL, (uint8_t *)CyFxUSB30DeviceDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set device descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* High speed device descriptor. */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_DEVICE_DESCR, NULL, (uint8_t *)CyFxUSB20DeviceDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set device descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* BOS descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_BOS_DESCR, NULL, (uint8_t *)CyFxUSBBOSDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set configuration descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Device qualifier descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_DEVQUAL_DESCR, NULL, (uint8_t *)CyFxUSBDeviceQualDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set device qualifier descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Super speed configuration descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_CONFIG_DESCR, NULL, (uint8_t *)CyFxUSBSSConfigDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set configuration descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* High speed configuration descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_CONFIG_DESCR, NULL, (uint8_t *)CyFxUSBHSConfigDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB Set Other Speed Descriptor failed, Error Code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Full speed configuration descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_FS_CONFIG_DESCR, NULL, (uint8_t *)CyFxUSBFSConfigDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB Set Configuration Descriptor failed, Error Code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* String descriptor 0 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 0, (uint8_t *)CyFxUSBStringLangIDDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* String descriptor 1 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 1, (uint8_t *)CyFxUSBManufactureDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* String descriptor 2 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Connect the USB Pins with super speed operation enabled. */
apiRetStatus = CyU3PConnectState(CyTrue, CyTrue);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB Connect failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
}
/* Entry function for the slFifoAppThread. */
void
SlFifoAppThread_Entry (
uint32_t input)
{
/* Initialize the debug module */
CyFxSlFifoApplnDebugInit();
/* Initialize the slave FIFO application */
CyFxSlFifoApplnInit();
for (;;)
{
CyU3PThreadSleep (1000);
if (glIsApplnActive)
{
/* Print the number of buffers received so far from the USB host. */
CyU3PDebugPrint (6, "Data tracker: buffers received: %d, buffers sent: %d.\n",
glDMARxCount, glDMATxCount);
}
}
}
void VndReqEP0Thread_Entry(uint32_t input)
{
uint32_t flag;
uint16_t readcount;
uint8_t i;
CyU3PReturnStatus_t apiRetStatus;
for (;;)
{
/* Check for Vendor request event */
if (CyU3PEventGet (&glFxVREQEvent, (CY_FX_VREQ_RD | CY_FX_VREQ_WR) ,CYU3P_EVENT_OR_CLEAR, &flag,CYU3P_WAIT_FOREVER) == CY_U3P_SUCCESS)
{
/* Check for Vendor request upload event */
if (flag & CY_FX_VREQ_RD)
{
//multiply download data by 2
for (i = 0; i < 16; i++)
Ep0_OutData = Ep0_InData * 2;
apiRetStatus = CyU3PUsbSendEP0Data(16, Ep0_OutData);
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyU3PDebugPrint (4, "EP0 Send Data Failed, Error Code = %d\n",apiRetStatus);
}
}
/* Check for Vendor request download event */
else if (flag & CY_FX_VREQ_WR)
apiRetStatus = CyU3PUsbGetEP0Data(16, Ep0_InData, &readcount);
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyU3PDebugPrint (4, "EP0 Get Data Failed, Error Code = %d\n",apiRetStatus);
}
}
/* Relinguish the thread */
CyU3PThreadRelinquish ();
}
}
/* Application define function which creates the threads. */
void
CyFxApplicationDefine (
void)
{
void *ptr = NULL;
uint32_t retThrdCreate = CY_U3P_SUCCESS;
/* Allocate the memory for the thread */
ptr = CyU3PMemAlloc (CY_FX_SLFIFO_THREAD_STACK);
/* Create the thread for the application */
retThrdCreate = CyU3PThreadCreate (&slFifoAppThread, /* Slave FIFO app thread structure */
"21:Slave_FIFO_sync", /* Thread ID and thread name */
SlFifoAppThread_Entry, /* Slave FIFO app thread entry function */
0, /* No input parameter to thread */
ptr, /* Pointer to the allocated thread stack */
CY_FX_SLFIFO_THREAD_STACK, /* App Thread stack size */
CY_FX_SLFIFO_THREAD_PRIORITY, /* App Thread priority */
CY_FX_SLFIFO_THREAD_PRIORITY, /* App Thread pre-emption threshold */
CYU3P_NO_TIME_SLICE, /* No time slice for the application thread */
CYU3P_AUTO_START /* Start the thread immediately */
);
/* Check the return code */
if (retThrdCreate != 0)
{
/* Thread Creation failed with the error code retThrdCreate */
/* Add custom recovery or debug actions here */
/* Application cannot continue */
/* Loop indefinitely */
while(1);
}
void *ptr2 = NULL;
/* Allocate the memory for the thread */
ptr = CyU3PMemAlloc (VndReq_EP0_THREAD_STACK);
/* Create the thread for the application */
retThrdCreate = CyU3PThreadCreate (&vndAppEP0Thread, /* Slave FIFO app thread structure */
"31:Vendor EP0 Thread", /* Thread ID and thread name */
VndReqEP0Thread_Entry, /* Slave FIFO app thread entry function */
0, /* No input parameter to thread */
ptr2, /* Pointer to the allocated thread stack */
VndReq_EP0_THREAD_STACK, /* App Thread stack size */
VndReq_EP0_THREAD_PRIORITY, /* App Thread priority */
VndReq_EP0_THREAD_PRIORITY, /* App Thread pre-emption threshold */
CYU3P_NO_TIME_SLICE, /* No time slice for the application thread */
CYU3P_AUTO_START /* Start the thread immediately */
);
/* Check the return code */
if (retThrdCreate != 0)
{
/* Thread Creation failed with the error code retThrdCreate */
/* Add custom recovery or debug actions here */
/* Application cannot continue */
/* Loop indefinitely */
while(1);
}
}
/*
* Main function
*/
int
main (void)
{
CyU3PIoMatrixConfig_t io_cfg;
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
/* Initialize the device */
status = CyU3PDeviceInit (NULL);
if (status != CY_U3P_SUCCESS)
{
goto handle_fatal_error;
}
/* Initialize the caches. Enable instruction cache and keep data cache disabled.
* The data cache is useful only when there is a large amount of CPU based memory
* accesses. When used in simple cases, it can decrease performance due to large
* number of cache flushes and cleans and also it adds to the complexity of the
* code. */
status = CyU3PDeviceCacheControl (CyTrue, CyFalse, CyFalse);
if (status != CY_U3P_SUCCESS)
{
goto handle_fatal_error;
}
/* Configure the IO matrix for the device. On the FX3 DVK board, the COM port
* is connected to the IO(53:56). This means that either DQ32 mode should be
* selected or lppMode should be set to UART_ONLY. Here we are choosing
* UART_ONLY configuration for 16 bit slave FIFO configuration and setting
* isDQ32Bit for 32-bit slave FIFO configuration. */
io_cfg.useUart = CyTrue;
io_cfg.useI2C = CyFalse;
io_cfg.useI2S = CyFalse;
io_cfg.useSpi = CyFalse;
#if (CY_FX_SLFIFO_GPIF_16_32BIT_CONF_SELECT == 0)
io_cfg.isDQ32Bit = CyFalse;
io_cfg.lppMode = CY_U3P_IO_MATRIX_LPP_UART_ONLY;
#else
io_cfg.isDQ32Bit = CyTrue;
io_cfg.lppMode = CY_U3P_IO_MATRIX_LPP_DEFAULT;
#endif
/* No GPIOs are enabled. */
io_cfg.gpioSimpleEn[0] = 0;
io_cfg.gpioSimpleEn[1] = 0;
io_cfg.gpioComplexEn[0] = 0;
io_cfg.gpioComplexEn[1] = 0;
status = CyU3PDeviceConfigureIOMatrix (&io_cfg);
if (status != CY_U3P_SUCCESS)
{
goto handle_fatal_error;
}
/* This is a non returnable call for initializing the RTOS kernel */
CyU3PKernelEntry ();
/* Dummy return to make the compiler happy */
return 0;
handle_fatal_error:
/* Cannot recover from this error. */
while (1);
}
/* [ ] */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the main code added in the SlaveFifoSync is here,
CyU3PThread slFifoAppThread; /* Slave FIFO application thread structure */
CyU3PDmaChannel glChHandleSlFifoUtoP; /* DMA Channel handle for U2P transfer. */
CyU3PDmaChannel glChHandleSlFifoPtoU; /* DMA Channel handle for P2U transfer. */
uint32_t glDMARxCount = 0; /* Counter to track the number of buffers received from USB. */
uint32_t glDMATxCount = 0; /* Counter to track the number of buffers sent to USB. */
CyBool_t glIsApplnActive = CyFalse; /* Whether the loopback application is active or not. */
static CyU3PThread vndAppEP0Thread;
static CyU3PEvent glFxVREQEvent; // vendor request event flags
static uint8_t Ep0_InData[16]; // ep0 in data buffer
static uint8_t Ep0_OutData[16]; // ep0 out data buffer
void VndReqEP0Thread_Entry (uint32_t); /* Declaration for the thread entry function */
/* Application Error Handler */
void
CyFxAppErrorHandler (
CyU3PReturnStatus_t apiRetStatus /* API return status */
)
{
/* Application failed with the error code apiRetStatus */
/* Add custom debug or recovery actions here */
/* Loop Indefinitely */
for (;;)
{
/* Thread sleep : 100 ms */
CyU3PThreadSleep (100);
}
}
/* This function initializes the debug module. The debug prints
* are routed to the UART and can be seen using a UART console
* running at 115200 baud rate. */
void
CyFxSlFifoApplnDebugInit (void)
{
CyU3PUartConfig_t uartConfig;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
/* Initialize the UART for printing debug messages */
apiRetStatus = CyU3PUartInit();
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyFxAppErrorHandler(apiRetStatus);
}
/* Set UART configuration */
CyU3PMemSet ((uint8_t *)&uartConfig, 0, sizeof (uartConfig));
uartConfig.baudRate = CY_U3P_UART_BAUDRATE_115200;
uartConfig.stopBit = CY_U3P_UART_ONE_STOP_BIT;
uartConfig.parity = CY_U3P_UART_NO_PARITY;
uartConfig.txEnable = CyTrue;
uartConfig.rxEnable = CyFalse;
uartConfig.flowCtrl = CyFalse;
uartConfig.isDma = CyTrue;
apiRetStatus = CyU3PUartSetConfig (&uartConfig, NULL);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}
/* Set the UART transfer to a really large value. */
apiRetStatus = CyU3PUartTxSetBlockXfer (0xFFFFFFFF);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}
/* Initialize the debug module. */
apiRetStatus = CyU3PDebugInit (CY_U3P_LPP_SOCKET_UART_CONS, 8);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyFxAppErrorHandler(apiRetStatus);
}
}
/* DMA callback function to handle the produce events for U to P transfers. */
void
CyFxSlFifoUtoPDmaCallback (
CyU3PDmaChannel *chHandle,
CyU3PDmaCbType_t type,
CyU3PDmaCBInput_t *input
)
{
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
if (type == CY_U3P_DMA_CB_PROD_EVENT)
{
/* This is a produce event notification to the CPU. This notification is
* received upon reception of every buffer. The buffer will not be sent
* out unless it is explicitly committed. The call shall fail if there
* is a bus reset / usb disconnect or if there is any application error. */
status = CyU3PDmaChannelCommitBuffer (chHandle, input->buffer_p.count, 0);
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCommitBuffer failed, Error code = %d\n", status);
}
/* Increment the counter. */
glDMARxCount++;
}
}
/* DMA callback function to handle the produce events for P to U transfers. */
void
CyFxSlFifoPtoUDmaCallback (
CyU3PDmaChannel *chHandle,
CyU3PDmaCbType_t type,
CyU3PDmaCBInput_t *input
)
{
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
if (type == CY_U3P_DMA_CB_PROD_EVENT)
{
/* This is a produce event notification to the CPU. This notification is
* received upon reception of every buffer. The buffer will not be sent
* out unless it is explicitly committed. The call shall fail if there
* is a bus reset / usb disconnect or if there is any application error. */
status = CyU3PDmaChannelCommitBuffer (chHandle, input->buffer_p.count, 0);
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCommitBuffer failed, Error code = %d\n", status);
}
/* Increment the counter. */
glDMATxCount++;
}
}
/* This function starts the slave FIFO loop application. This is called
* when a SET_CONF event is received from the USB host. The endpoints
* are configured and the DMA pipe is setup in this function. */
void
CyFxSlFifoApplnStart (
void)
{
uint16_t size = 0;
CyU3PEpConfig_t epCfg;
CyU3PDmaChannelConfig_t dmaCfg;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
CyU3PUSBSpeed_t usbSpeed = CyU3PUsbGetSpeed();
/* First identify the usb speed. Once that is identified,
* create a DMA channel and start the transfer on this. */
/* Based on the Bus Speed configure the endpoint packet size */
switch (usbSpeed)
{
case CY_U3P_FULL_SPEED:
size = 64;
break;
case CY_U3P_HIGH_SPEED:
size = 512;
break;
case CY_U3P_SUPER_SPEED:
size = 1024;
break;
default:
CyU3PDebugPrint (4, "Error! Invalid USB speed.\n");
CyFxAppErrorHandler (CY_U3P_ERROR_FAILURE);
break;
}
CyU3PMemSet ((uint8_t *)&epCfg, 0, sizeof (epCfg));
epCfg.enable = CyTrue;
epCfg.epType = CY_U3P_USB_EP_BULK;
epCfg.burstLen = CY_FX_SLFIFO_PACKETS_PER_BURST;
epCfg.streams = 0;
epCfg.pcktSize = size;
/* Producer endpoint configuration */
apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_PRODUCER, &epCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler (apiRetStatus);
}
/* Consumer endpoint configuration */
apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_CONSUMER, &epCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler (apiRetStatus);
}
/* Create a DMA MANUAL channel for U2P transfer.
* DMA size is set based on the USB speed. */
dmaCfg.size = size;
dmaCfg.count = CY_FX_SLFIFO_DMA_BUF_COUNT;
dmaCfg.prodSckId = CY_FX_PRODUCER_USB_SOCKET;
dmaCfg.consSckId = CY_FX_CONSUMER_PPORT_SOCKET;
dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE;
/* Enabling the callback for produce event. */
dmaCfg.notification = CY_U3P_DMA_CB_PROD_EVENT;
dmaCfg.cb = CyFxSlFifoUtoPDmaCallback;
dmaCfg.prodHeader = 0;
dmaCfg.prodFooter = 0;
dmaCfg.consHeader = 0;
dmaCfg.prodAvailCount = 0;
apiRetStatus = CyU3PDmaChannelCreate (&glChHandleSlFifoUtoP,
CY_U3P_DMA_TYPE_AUTO, &dmaCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCreate failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Create a DMA MANUAL channel for P2U transfer. */
dmaCfg.prodSckId = CY_FX_PRODUCER_PPORT_SOCKET;
dmaCfg.consSckId = CY_FX_CONSUMER_USB_SOCKET;
dmaCfg.cb = CyFxSlFifoPtoUDmaCallback;
apiRetStatus = CyU3PDmaChannelCreate (&glChHandleSlFifoPtoU,
CY_U3P_DMA_TYPE_AUTO, &dmaCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelCreate failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Flush the Endpoint memory */
CyU3PUsbFlushEp(CY_FX_EP_PRODUCER);
CyU3PUsbFlushEp(CY_FX_EP_CONSUMER);
/* Set DMA channel transfer size. */
apiRetStatus = CyU3PDmaChannelSetXfer (&glChHandleSlFifoUtoP, CY_FX_SLFIFO_DMA_TX_SIZE);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelSetXfer Failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
apiRetStatus = CyU3PDmaChannelSetXfer (&glChHandleSlFifoPtoU, CY_FX_SLFIFO_DMA_TX_SIZE);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PDmaChannelSetXfer Failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Update the status flag. */
glIsApplnActive = CyTrue;
}
/* This function stops the slave FIFO loop application. This shall be called
* whenever a RESET or DISCONNECT event is received from the USB host. The
* endpoints are disabled and the DMA pipe is destroyed by this function. */
void
CyFxSlFifoApplnStop (
void)
{
CyU3PEpConfig_t epCfg;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
/* Update the flag. */
glIsApplnActive = CyFalse;
/* Flush the endpoint memory */
CyU3PUsbFlushEp(CY_FX_EP_PRODUCER);
CyU3PUsbFlushEp(CY_FX_EP_CONSUMER);
/* Destroy the channel */
CyU3PDmaChannelDestroy (&glChHandleSlFifoUtoP);
CyU3PDmaChannelDestroy (&glChHandleSlFifoPtoU);
/* Disable endpoints. */
CyU3PMemSet ((uint8_t *)&epCfg, 0, sizeof (epCfg));
epCfg.enable = CyFalse;
/* Producer endpoint configuration. */
apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_PRODUCER, &epCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler (apiRetStatus);
}
/* Consumer endpoint configuration. */
apiRetStatus = CyU3PSetEpConfig(CY_FX_EP_CONSUMER, &epCfg);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PSetEpConfig failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler (apiRetStatus);
}
}
/* Callback to handle the USB setup requests. */
CyBool_t
CyFxSlFifoApplnUSBSetupCB (
uint32_t setupdat0,
uint32_t setupdat1
)
{
uint8_t setupReqType, setupReq;
CyU3PReturnStatus_t apiRetStatus;
CyBool_t vndHandleReq = CyFalse;
/* Obtain Request Type and Request */
setupReqType = (uint8_t)(setupdat0 & CY_FX_USB_SETUP_REQ_TYPE_MASK);
setupReq = (uint8_t)((setupdat0 & CY_FX_USB_SETUP_REQ_MASK) >> 8);
/* Check for user vendor request */
if (setupReq == CY_FX_VND_REQ1)
{
/* Vendor requests are handled in the application */
vndHandleReq = CyTrue;
/* Check for vendor request upload */
if (setupReqType == CY_FX_USB_VND_GET_REQ_TYPE)
{
apiRetStatus = CyU3PEventSet(&glFxVREQEvent,CY_FX_VREQ_RD,CYU3P_EVENT_OR);
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyU3PDebugPrint (4, "Get Vendor Request Event Failed, Error Code = %d\n",apiRetStatus);
}
}
/* Check for vendor request download */
else if (setupReqType == CY_FX_USB_VND_SET_REQ_TYPE)
apiRetStatus = CyU3PEventSet(&glFxVREQEvent,CY_FX_VREQ_WR,CYU3P_EVENT_OR);
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyU3PDebugPrint (4, "Set Vendor Request Event Failed, Error Code = %d\n",apiRetStatus);
}
/* Fast enumeration is used. Only class, vendor and unknown requests
* are received by this function. These are not handled in this
* application. Hence return CyFalse. */
}
return CyFalse;
}
/* This is the callback function to handle the USB events. */
void
CyFxSlFifoApplnUSBEventCB (
CyU3PUsbEventType_t evtype,
uint16_t evdata
)
{
switch (evtype)
{
case CY_U3P_USB_EVENT_SETCONF:
/* Stop the application before re-starting. */
if (glIsApplnActive)
{
CyFxSlFifoApplnStop ();
}
/* Start the loop back function. */
CyFxSlFifoApplnStart ();
break;
case CY_U3P_USB_EVENT_RESET:
case CY_U3P_USB_EVENT_DISCONNECT:
/* Stop the loop back function. */
if (glIsApplnActive)
{
CyFxSlFifoApplnStop ();
}
break;
default:
break;
}
}
/* This function initializes the GPIF interface and initializes
* the USB interface. */
void
CyFxSlFifoApplnInit (void)
{
CyU3PPibClock_t pibClock;
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
/* Initialize the p-port block. */
pibClock.clkDiv = 2;
pibClock.clkSrc = CY_U3P_SYS_CLK;
pibClock.isHalfDiv = CyFalse;
/* Disable DLL for sync GPIF */
pibClock.isDllEnable = CyFalse;
apiRetStatus = CyU3PPibInit(CyTrue, &pibClock);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "P-port Initialization failed, Error Code = %d\n",apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Load the GPIF configuration for Slave FIFO sync mode. */
apiRetStatus = CyU3PGpifLoad (&Sync_Slave_Fifo_2Bit_CyFxGpifConfig);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PGpifLoad failed, Error Code = %d\n",apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Start the state machine. */
apiRetStatus = CyU3PGpifSMStart (SYNC_SLAVE_FIFO_2BIT_RESET, SYNC_SLAVE_FIFO_2BIT_ALPHA_RESET);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PGpifSMStart failed, Error Code = %d\n",apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Start the USB functionality. */
apiRetStatus = CyU3PUsbStart();
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "CyU3PUsbStart failed to Start, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* The fast enumeration is the easiest way to setup a USB connection,
* where all enumeration phase is handled by the library. Only the
* class / vendor requests need to be handled by the application. */
CyU3PUsbRegisterSetupCallback(CyFxSlFifoApplnUSBSetupCB, CyTrue);
/* Setup the callback to handle the USB events. */
CyU3PUsbRegisterEventCallback(CyFxSlFifoApplnUSBEventCB);
/* Set the USB Enumeration descriptors */
/* Super speed device descriptor. */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_DEVICE_DESCR, NULL, (uint8_t *)CyFxUSB30DeviceDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set device descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* High speed device descriptor. */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_DEVICE_DESCR, NULL, (uint8_t *)CyFxUSB20DeviceDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set device descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* BOS descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_BOS_DESCR, NULL, (uint8_t *)CyFxUSBBOSDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set configuration descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Device qualifier descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_DEVQUAL_DESCR, NULL, (uint8_t *)CyFxUSBDeviceQualDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set device qualifier descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Super speed configuration descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_SS_CONFIG_DESCR, NULL, (uint8_t *)CyFxUSBSSConfigDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set configuration descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* High speed configuration descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_HS_CONFIG_DESCR, NULL, (uint8_t *)CyFxUSBHSConfigDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB Set Other Speed Descriptor failed, Error Code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Full speed configuration descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_FS_CONFIG_DESCR, NULL, (uint8_t *)CyFxUSBFSConfigDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB Set Configuration Descriptor failed, Error Code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* String descriptor 0 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 0, (uint8_t *)CyFxUSBStringLangIDDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* String descriptor 1 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 1, (uint8_t *)CyFxUSBManufactureDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* String descriptor 2 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscr);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
/* Connect the USB Pins with super speed operation enabled. */
apiRetStatus = CyU3PConnectState(CyTrue, CyTrue);
if (apiRetStatus != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (4, "USB Connect failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}
}
/* Entry function for the slFifoAppThread. */
void
SlFifoAppThread_Entry (
uint32_t input)
{
/* Initialize the debug module */
CyFxSlFifoApplnDebugInit();
/* Initialize the slave FIFO application */
CyFxSlFifoApplnInit();
for (;;)
{
CyU3PThreadSleep (1000);
if (glIsApplnActive)
{
/* Print the number of buffers received so far from the USB host. */
CyU3PDebugPrint (6, "Data tracker: buffers received: %d, buffers sent: %d.\n",
glDMARxCount, glDMATxCount);
}
}
}
void VndReqEP0Thread_Entry(uint32_t input)
{
uint32_t flag;
uint16_t readcount;
uint8_t i;
CyU3PReturnStatus_t apiRetStatus;
for (;;)
{
/* Check for Vendor request event */
if (CyU3PEventGet (&glFxVREQEvent, (CY_FX_VREQ_RD | CY_FX_VREQ_WR) ,CYU3P_EVENT_OR_CLEAR, &flag,CYU3P_WAIT_FOREVER) == CY_U3P_SUCCESS)
{
/* Check for Vendor request upload event */
if (flag & CY_FX_VREQ_RD)
{
//multiply download data by 2
for (i = 0; i < 16; i++)
Ep0_OutData = Ep0_InData * 2;
apiRetStatus = CyU3PUsbSendEP0Data(16, Ep0_OutData);
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyU3PDebugPrint (4, "EP0 Send Data Failed, Error Code = %d\n",apiRetStatus);
}
}
/* Check for Vendor request download event */
else if (flag & CY_FX_VREQ_WR)
apiRetStatus = CyU3PUsbGetEP0Data(16, Ep0_InData, &readcount);
if (apiRetStatus != CY_U3P_SUCCESS)
{
/* Error handling */
CyU3PDebugPrint (4, "EP0 Get Data Failed, Error Code = %d\n",apiRetStatus);
}
}
/* Relinguish the thread */
CyU3PThreadRelinquish ();
}
}
/* Application define function which creates the threads. */
void
CyFxApplicationDefine (
void)
{
void *ptr = NULL;
uint32_t retThrdCreate = CY_U3P_SUCCESS;
/* Allocate the memory for the thread */
ptr = CyU3PMemAlloc (CY_FX_SLFIFO_THREAD_STACK);
/* Create the thread for the application */
retThrdCreate = CyU3PThreadCreate (&slFifoAppThread, /* Slave FIFO app thread structure */
"21:Slave_FIFO_sync", /* Thread ID and thread name */
SlFifoAppThread_Entry, /* Slave FIFO app thread entry function */
0, /* No input parameter to thread */
ptr, /* Pointer to the allocated thread stack */
CY_FX_SLFIFO_THREAD_STACK, /* App Thread stack size */
CY_FX_SLFIFO_THREAD_PRIORITY, /* App Thread priority */
CY_FX_SLFIFO_THREAD_PRIORITY, /* App Thread pre-emption threshold */
CYU3P_NO_TIME_SLICE, /* No time slice for the application thread */
CYU3P_AUTO_START /* Start the thread immediately */
);
/* Check the return code */
if (retThrdCreate != 0)
{
/* Thread Creation failed with the error code retThrdCreate */
/* Add custom recovery or debug actions here */
/* Application cannot continue */
/* Loop indefinitely */
while(1);
}
void *ptr2 = NULL;
/* Allocate the memory for the thread */
ptr2 = CyU3PMemAlloc (VndReq_EP0_THREAD_STACK);
/* Create the thread for the application */
retThrdCreate = CyU3PThreadCreate (&vndAppEP0Thread, /* Slave FIFO app thread structure */
"31:Vendor EP0 Thread", /* Thread ID and thread name */
VndReqEP0Thread_Entry, /* Slave FIFO app thread entry function */
0, /* No input parameter to thread */
ptr2, /* Pointer to the allocated thread stack */
VndReq_EP0_THREAD_STACK, /* App Thread stack size */
VndReq_EP0_THREAD_PRIORITY, /* App Thread priority */
VndReq_EP0_THREAD_PRIORITY, /* App Thread pre-emption threshold */
CYU3P_NO_TIME_SLICE, /* No time slice for the application thread */
CYU3P_AUTO_START /* Start the thread immediately */
);
/* Check the return code */
if (retThrdCreate != 0)
{
/* Thread Creation failed with the error code retThrdCreate */
/* Add custom recovery or debug actions here */
/* Application cannot continue */
/* Loop indefinitely */
while(1);
}
}
/*
* Main function
*/
int
main (void)
{
CyU3PIoMatrixConfig_t io_cfg;
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
/* Initialize the device */
status = CyU3PDeviceInit (NULL);
if (status != CY_U3P_SUCCESS)
{
goto handle_fatal_error;
}
/* Initialize the caches. Enable instruction cache and keep data cache disabled.
* The data cache is useful only when there is a large amount of CPU based memory
* accesses. When used in simple cases, it can decrease performance due to large
* number of cache flushes and cleans and also it adds to the complexity of the
* code. */
status = CyU3PDeviceCacheControl (CyTrue, CyFalse, CyFalse);
if (status != CY_U3P_SUCCESS)
{
goto handle_fatal_error;
}
/* Configure the IO matrix for the device. On the FX3 DVK board, the COM port
* is connected to the IO(53:56). This means that either DQ32 mode should be
* selected or lppMode should be set to UART_ONLY. Here we are choosing
* UART_ONLY configuration for 16 bit slave FIFO configuration and setting
* isDQ32Bit for 32-bit slave FIFO configuration. */
io_cfg.useUart = CyTrue;
io_cfg.useI2C = CyFalse;
io_cfg.useI2S = CyFalse;
io_cfg.useSpi = CyFalse;
#if (CY_FX_SLFIFO_GPIF_16_32BIT_CONF_SELECT == 0)
io_cfg.isDQ32Bit = CyFalse;
io_cfg.lppMode = CY_U3P_IO_MATRIX_LPP_UART_ONLY;
#else
io_cfg.isDQ32Bit = CyTrue;
io_cfg.lppMode = CY_U3P_IO_MATRIX_LPP_DEFAULT;
#endif
/* No GPIOs are enabled. */
io_cfg.gpioSimpleEn[0] = 0;
io_cfg.gpioSimpleEn[1] = 0;
io_cfg.gpioComplexEn[0] = 0;
io_cfg.gpioComplexEn[1] = 0;
status = CyU3PDeviceConfigureIOMatrix (&io_cfg);
if (status != CY_U3P_SUCCESS)
{
goto handle_fatal_error;
}
/* This is a non returnable call for initializing the RTOS kernel */
CyU3PKernelEntry ();
/* Dummy return to make the compiler happy */
return 0;
handle_fatal_error:
/* Cannot recover from this error. */
while (1);
}
/* [ ] */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok ,I found the mistake.my fault.
the Event did not create.
so .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear jogn_li,
It seems that I have a similar problem.
Could you please explain how you fixed your problem about "didn't create the event"?
Thank you for your help.
Gary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I think its the glFxVREQEvent that needs created add following code to CyFxBulkLpApplnInit (void)
txApiRetStatus = CyU3PEventCreate(&glFxVREQEvent); to CyFxBulkLpApplnInit (void)
Also have a look at this post http://www.cypress.com/?app=forum&id=167&rID=53345 and have a look at the Cypress I2C project that uses vendor requests to access an eeprom cyfxusbi2cregmode
Sodafarl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content