TI中文支持网
TI专业的中文技术问题搜集分享网站

cc1310使用TI-RTOS中任务切换的问题

原希望每5秒执行一次nodeTaskFunction(),有串口数据接收执行回调函数,但调试发现nodeTaskFunction()不被执行,clock回调函数是正常执行的,nodeTask的优先级比uartTask 的高啊,为什么?

另外在uartTaskFunction的while(1)循环体中加Task_sleep()就可正常运行nodeTask,这个好理解。

void testClockCallback(Uarg arg0)
{
Semaphore_post(testSemHandle);
}
/***** Function definitions *****/
void NodeTask_init(void)
{
/* Create clock object which is used for fast report timeout */
Clock_Params clkParams;
Clock_Params_init(&clkParams);
clkParams.period = 5000 * 1000 / Clock_tickPeriod;
clkParams.startFlag = FALSE;
Clock_construct(&testClock, (Clock_FuncPtr)testClockCallback, 0, &clkParams);
testClockHandle = Clock_handle(&testClock);

Semaphore_Params semParam;
Semaphore_Params_init(&semParam);
Semaphore_construct(&testSem, 1, &semParam);
testSemHandle = Semaphore_handle(&testSem);

UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 38400;
uartParams.readMode= UART_MODE_CALLBACK;
uartParams.writeMode=UART_MODE_CALLBACK;
uartParams.readCallback = uartReadCB; uartParams.writeCallback = uartWriteCB; uarthandle = UART_open(Board_UART0, &uartParams);
if (!uarthandle) {
      while (1);//UART_open() failed }

/* Create the node task */
Task_Params_init(&nodeTaskParams);
nodeTaskParams.stackSize = 1024;
nodeTaskParams.priority = 4;
nodeTaskParams.stack = &nodeTaskStack;
Task_construct(&nodeTask, nodeTaskFunction, &nodeTaskParams, NULL);

/* Create the uart task */
Task_Params_init(&uartTaskParams);
uartTaskParams.stackSize = 1024;
uartTaskParams.priority = 3;
uartTaskParams.stack = &uartTaskStack;
Task_construct(&uartTask, uartTaskFunction, &uartTaskParams, NULL);
}

static void nodeTaskFunction(UArg arg0, UArg arg1)
{
Clock_start(testClockHandle);
while (1)
{
Semaphore_pend(testSemHandle, BIOS_WAIT_FOREVER);
…………………
}
}

void uartReadCB(UART_Handle handle, void *rxBuf, size_t size)
{
uint16_t i=0;
static uint16_t y=0;
for(i = 0; i < size; i++)
{
u0txBuf[y] = ((uint8_t*)rxBuf)[i];
y++;
}
UART_read(handle, u0rxBuf,1);
}

void uartWriteCB(UART_Handle handle, void *rxBuf, size_t size)
{
//Do nothing
}

static void uartTaskFunction(UArg arg0, UArg arg1)
{
int rxBytes = UART_read(uarthandle, u0rxBuf, 1);
while(1)
{
// Task_sleep(1000 * (1000 / Clock_tickPeriod));
}
}

Viki Shi:

需要设置两个任务为不同的优先级,然后TI RTOS根据任务优先级自动切换,需要 Event_post()事件来启动优先任务的执行。可以参考SDK中的mutex例程

赞(0)
未经允许不得转载:TI中文支持网 » cc1310使用TI-RTOS中任务切换的问题
分享到: 更多 (0)