FX3学习笔记1-创建线程

一、实验环境

  • 硬件平台: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);}

三、完成上述操作,编译烧写进开发板,会看到串口每秒打印一条allen test,,至此完成了一个简单线程的添加。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部