一、实验环境
- 硬件平台:CYUSB3KIT-003 EZ-USB® FX3™ SuperSpeed Explorer Kit
- sdk版本:EZ-USB FX3 SDK1.3 / SuperSpeed Explorer Kit 1.0
- 实验例程:USBBulkSourceSinkLED
二、创建线程步骤
- 1、在cyfxbulksrcsink.h中定义线程栈大小和优先级
//add by allen
//#define CY_FX_ALLEN_TEST_DMA_TX_SIZE (0) /* DMA transfer size is set to infinite */
#define CY_FX_ALLEN_TEST_THREAD_STACK (0x1000) /* Bulk loop application thread stack size */
#define CY_FX_ALLEN_TEST_THREAD_PRIORITY (9) /* Bulk loop application thread priority */
- 2、在cyfxbulksrcsink.c中定义线程结构体变量(结构体内容暂不做分析)
//add by allen
CyU3PThread allenTestAppThread; /* Application thread structure */
- 3、在cyfxbulksrcsink.c中定义线程事件结构体变量(结构体内容暂不做分析)
//add by allen
CyU3PEvent allenTestEvent; /* Event group used to signal the thread that there is a pending request. */
- 4、在cyfxbulksrcsink.c中创建线程处理函数
/* Entry function for the allen test Thread. */
void AllenTestAppThread_Entry (uint32_t input)
{
/* Initialize the application */
for (;;)
{
CyU3PThreadSleep (1000);
CyU3PDebugPrint (1, "allen test\r\n");
}
}
- 5、在cyfxbulksrcsink.c中的
void CyFxApplicationDefine (void)
函数中添加自己的线程创建代码
//add by allen
/* Create an event flag group that will be used for signalling the application thread. */
ret = CyU3PEventCreate (&allenTestEvent);
if (ret != 0)
{
/* Loop indefinitely */
while (1);
}
/* Allocate the memory for the threads */
ptr = CyU3PMemAlloc (CY_FX_ALLEN_TEST_THREAD_STACK);
/* Create the thread for the application */
ret = CyU3PThreadCreate (&allenTestAppThread, /* App thread structure */
"22:allen_test", /* Thread ID and thread name */
AllenTestAppThread_Entry, /* App thread entry function */
0, /* No input parameter to thread */
ptr, /* Pointer to the allocated thread stack */
CY_FX_ALLEN_TEST_THREAD_STACK, /* App thread stack size */
CY_FX_ALLEN_TEST_THREAD_PRIORITY, /* App thread priority */
CY_FX_ALLEN_TEST_THREAD_PRIORITY, /* App thread priority */
CYU3P_NO_TIME_SLICE, /* No time slice for the application thread */
CYU3P_AUTO_START /* Start the thread immediately */
);
/* Check the return code */
if (ret != 0)
{
/* Thread Creation failed with the error code retThrdCreate */
/* Add custom recovery or debug actions here */
/* Application cannot continue */
/* Loop indefinitely */
while(1);
}