Datasheet
Migrating from EZ-USB
®
FX2LP™ Based Design to EZ-USB FX3 Based Design
www.cypress.com Document No. 001-76348 Rev. ** 8
CyU3PDeviceConfigureIOMatrix function (in the
library) is invoked.
4. The final step in the main() function is invocation of
the OS. The invocation is done by issuing a call to the
CyU3PKernelEntry() function. This function is
defined in the library and is a non-returning call. This
function is a wrapper to the actual ThreadX OS entry
call. This function:
a. Initializes the OS
b. Sets up the OS timer
Application Definition
The function CyFxApplicationDefine() is called by
the FX3 library after the OS is invoked. In this function
application specific threads are created. This function is
similar to the TD_Poll() in FX2LP firmware, where we
write the application logic.
In the bulkloop example, only one thread is created in the
application define function. This is shown as follows:
/* Allocate the memory for the threads */
ptr = CyU3PMemAlloc
(CY_FX_BULKLP_THREAD_STACK);
/* Create the thread for the application */
retThrdCreate = CyU3PThreadCreate
(&BulkLpAppThread, /*
Bulk loop App Thread structure */
"21:Bulk_loop_AUTO",
/* Thread ID and Thread name */
BulkLpAppThread_Entry,
/* Bulk loop App Thread Entry function */
0,
/* No input parameter to thread */
ptr,
/* Pointer to the allocated thread stack */
CY_FX_BULKLP_THREAD_STACK,
/* Bulk loop App Thread stack size */
CY_FX_BULKLP_THREAD_PRIORITY,
/* Bulk loop App Thread priority */
CY_FX_BULKLP_THREAD_PRIORITY,
/* Bulk loop App Thread priority */
CYU3P_NO_TIME_SLICE,
/* No time slice for the application thread */
CYU3P_AUTO_START
/* Start the Thread immediately */
);
Note that more threads (as required by the user
application) can be created in the application define
function. All other FX3 specific programming must be done
only in the user threads.
Application Code
In the bulkloop example, 1 Auto DMA channel is created
after setting up the Producer (OUT) and Consumer (IN)
endpoint. This DMA channel connects the two sockets of
the USB port. Two endpoints 1 IN and 1 OUT are
configured as bulk endpoints. The endpoint
maxPacketSize is updated based on the speed.
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 = 1;
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);
}
