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,,至此完成了一个简单线程的添加。

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路人 假

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值