CC26xx &&CC13xx 多线程
来源:互联网 发布:怎么使用淘宝钻石展位 编辑:程序博客网 时间:2024/06/10 00:50
/* XDC module Headers */#include <xdc/std.h>#include <xdc/runtime/System.h>/* BIOS module Headers */#include <ti/sysbios/BIOS.h>#include <ti/sysbios/knl/Clock.h>#include <ti/sysbios/knl/Task.h>#include <ti/sysbios/knl/Semaphore.h>/* Example/Board Header files */#include "Board.h"#define TASKSTACKSIZE 512Void task1Fxn(UArg arg0, UArg arg1);Void task2Fxn(UArg arg0, UArg arg1);Int resource = 0;Int finishCount = 0;UInt32 sleepTickCount;Task_Struct task1Struct, task2Struct;Char task1Stack[TASKSTACKSIZE], task2Stack[TASKSTACKSIZE];Semaphore_Struct semStruct;Semaphore_Handle semHandle;/* * ======== main ======== */Int main(){ /* Construct BIOS objects */ Task_Params taskParams; Semaphore_Params semParams; /* Call board init functions */ Board_initGeneral(); /* Construct writer/reader Task threads */ Task_Params_init(&taskParams); taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task1Stack; taskParams.priority = 1; Task_construct(&task1Struct, (Task_FuncPtr)task1Fxn, &taskParams, NULL); taskParams.stack = &task2Stack; taskParams.priority = 2; Task_construct(&task2Struct, (Task_FuncPtr)task2Fxn, &taskParams, NULL); /* Construct a Semaphore object to be use as a resource lock, inital count 1 */ Semaphore_Params_init(&semParams); Semaphore_construct(&semStruct, 1, &semParams); /* Obtain instance handle */ semHandle = Semaphore_handle(&semStruct); /* We want to sleep for 10000 microseconds */ sleepTickCount = 10000 / Clock_tickPeriod; BIOS_start(); /* Does not return */ return(0);}/* * ======== task1Fxn ======== */Void task1Fxn(UArg arg0, UArg arg1){ UInt32 time; for (;;) { System_printf("Running task1 function\n"); if (Semaphore_getCount(semHandle) == 0) { System_printf("Sem blocked in task1\n"); } /* Get access to resource */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); /* Do work by waiting for 2 system ticks to pass */ time = Clock_getTicks(); while (Clock_getTicks() <= (time + 1)) { ; } /* Do work on locked resource */ resource += 1; /* Unlock resource */ Semaphore_post(semHandle); Task_sleep(sleepTickCount); }}/* * ======== task2Fxn ======== */Void task2Fxn(UArg arg0, UArg arg1){ for (;;) { System_printf("Running task2 function\n"); if (Semaphore_getCount(semHandle) == 0) { System_printf("Sem blocked in task2\n"); } /* Get access to resource */ Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); /* Do work on locked resource */ resource += 1; /* Unlock resource */ Semaphore_post(semHandle); Task_sleep(sleepTickCount); finishCount++; if (finishCount == 5) { System_printf("Calling BIOS_exit from task2\n"); BIOS_exit(0); } }}
特别注意的一点是很多人用多线程之后会出现BLE不能工作等问题,一般是优先级不够的导致的,注意优先级的设置以及用信号量去控制线程的控制权的获取。
阅读全文
0 0
- CC26xx &&CC13xx 多线程
- CC26xx PWM
- CC26XX SBL
- CC26xx SPI
- CC26xx I2S
- [CortexM3--CC26XX]IO Control
- [CortexM3--CC26XX]UARTs
- [CortexM3--CC26XX]Memory系统VIMS
- CC26xx芯片烧录问题
- CC26XX之OAD(转)
- CC26xx/CC13x0的SCS应用
- CC26XX定时器以及按键中断
- [CortexM3--CC26XX]Power Reset and Clock
- [CortexM3--CC26XX]Watchdog Timer(exp)
- CC26xx之Flash Programmer 2使用
- Cc26xx系列spi驱动失败的解决办法
- CC26xx之内置温度传感器的使用
- CC26xx GPIO如何模拟各种总线。
- Unknown error: Unable to build: the file dx.jar was not loaded from the SDK folder!解决方法
- Eclipse 关闭 updating indexes
- 计数排序java
- Gitblit环境搭建(w7 64位环境)
- Android7.0 android.os.FileUriExposedException
- CC26xx &&CC13xx 多线程
- 轻重链剖分
- android studio使用技巧
- MVP-简单的OkHttp网络请求数据
- poj 2195 Going Home(最小费用流)
- Java之Integer与int类型数据的比较-yellowcong
- 疯狂Spring Cloud连载(16)Hystrix运作流程
- 提防对象切片
- 对XML Feed制作与更新流程研究报告