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

CC1310任务建立问题

你好:

        TI的工程师,最近再调CC1310,想建立个任务,但是不能成功,仿照的是WDT提出来的Easylink 代码,不太明白原因,希望能给与解释,代码如下:

代码1:

void UartTask_init(void) {

    /* Create event used internally for state changes */
    Event_Params eventParam;
    Event_Params_init(&eventParam);
    Event_construct(&uartEvent, &eventParam);
    uartEventHandle = Event_handle(&uartEvent);

    /* Create the node task */
    Task_Params_init(&uartTaskParams);
    uartTaskParams.stackSize = UART_TASK_STACK_SIZE;
    uartTaskParams.priority = UART_TASK_PRIORITY;
    uartTaskParams.stack = &uartTaskStack;
    Task_construct(&uartTask, uartTaskFunction, &uartTaskParams, NULL);
    
        /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.readMode = UART_MODE_CALLBACK;
    uartParams.readCallback = Uart_ReadCallback;
    uartParams.writeCallback = Uart_WriteCallback;
    uartParams.writeMode = UART_MODE_CALLBACK;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 9600;
    uart = UART_open(Board_UART0, &uartParams);

    if (uart == NULL) {
        System_abort("Error opening the UART");
    }
    
}

这是TI WDT贴出的代码 我仿照这个代码自己建立了个任务:

代码2
void data_process_init(void)
{
    /* Create event used internally for state changes */
    Event_Params dataeventParam;
    Event_Params_init(&dataeventParam);
    Event_construct(&data_processEvent, &dataeventParam);
    data_processEventHandle = Event_handle(&data_processEvent);

    /* Create the node task */
    Task_Params_init(&data_processTaskParams);
    data_processTaskParams.stackSize = DATA_PROCESS_TASK_STACK_SIZE;
    data_processTaskParams.priority = DATA_PROCESS_TASK_PRIORITY;
    data_processTaskParams.stack = &data_processTaskStack;
     data_processTaskParams.arg0 = (UInt)1500000;
    Task_construct(&data_processTask, data_processTaskFunction, &data_processTaskParams, NULL);
}

我的主程序:
int main(void)
{
     /* Call board init functions. */
    Board_initGeneral();

    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, pinTable);
    if(!ledPinHandle) {
        System_abort("Error initializing board LED pins\n");
    }

    //add by barbara — end
    //System_printf("main\n");
    
    /* Clear LED pins */
    PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
    PIN_setOutputValue(ledPinHandle, Board_LED2, 1);
    PIN_setOutputValue(ledPinHandle, Board_LED3, 1);
    PIN_setOutputValue(ledPinHandle, Board_LED4, 1);

    rxTask_init(ledPinHandle);

    UartTask_init();            //add by barbara
  //  data_process_init();               //add by yu    /* Start BIOS */
    BIOS_start();

    return (0);
}

当我打开 data_process_init()时,Uart任务不能正常触发串口接收事件,任务不能切换,屏蔽后可以正常运行,我想请教下,如何正确的建立个自己的任务,保证任务间正常切换工作。此外:我建立的任务和TI 工程师建立的串口任务优先级相同,但是我尝试过不同的任务优先级也不能正常运行。

我把功能函数也贴出来:
/*
 *  ======== echoFxn ========
 *  Task for this function is created statically. See the project's .cfg file.
 */
static void data_processTaskFunction(UArg arg0, UArg arg1)
{
   while(1)
  {
        /* Wait for event */
        uint32_t events = Event_pend(data_processEventHandle, 0, DATA_PROCESS_EVENT_ALL, BIOS_NO_WAIT);  //uint32_t events = Event_pend(uartEventHandle, 0, UART_EVENT_ALL, BIOS_WAIT_FOREVER);  //__extern xdc_UInt ti_sysbios_knl_Event_pend__E( ti_sysbios_knl_Event_Handle __inst, xdc_UInt andMask, xdc_UInt orMask, xdc_UInt32 timeout );
        //uint32_t events = Event_pend(uartEventHandle, 0, UART_EVENT_ALL, 100000);//1s
        if(!(events & 0x3F))
        {
          continue;
        }
        //am_devices_Runled_flicker(1,50);
        if(events & DATA_PROCESS_EVENT_IDENTIFY)  //1
        {        am_devices_LEDx_flicker(1,5, 500);
        }
        if(events & DATA_PROCESS_EVENT_SYNCHRONIZATION)//2
        {          am_devices_LEDx_flicker(2,5, 500);
        }
        if(events & DATA_PROCESS_EVENT_DATA)//3
        {            am_devices_LEDx_flicker(3,5, 500);
          //用户程序 数据处理
        //  am_devices_Runled_flicker(1,50);
         // payload_data_analysis_handle((uint8_t * volatile )mac_radio_rx.frame.source_address);          
        }
        if(events & DATA_PROCESS_EVENT_MANAGEMENT)//4
        {
            am_devices_LEDx_flicker(4,5, 500);
         // am_devices_Runled_flicker(4,500);
        }
        if(events & DATA_PROCESS_EVENT_RESPONSE)//5
        {           am_devices_LEDx_flicker(1,10, 500);
        //  am_devices_Runled_flicker(5,500);
        }
        if(events & DATA_PROCESS_EVENT_BROADCAST)//6
        {            am_devices_LEDx_flicker(2,10, 500);
          //用户程序 数据处理
         // am_devices_Runled_flicker(2,50);
         // payload_broadcast_analysis_handle((uint8_t * volatile )mac_radio_rx.frame.source_address);               
        }          
  }//end while(1)  
}

串口的功能函数:

static void uartTaskFunction(UArg arg0, UArg arg1)
{
    uint8_t i;
    UART_read(uart, Uart_RxTempBuf, 1);
    
    /* Loop forever echoing */
    while (1)    {  
        /* Wait for event */
       
        uint32_t events = Event_pend(uartEventHandle, 0, UART_EVENT_ALL, BIOS_WAIT_FOREVER);
        /* If new ADC value, send this data */
        if(events & UART_EVENT_PRINT)        {   
          UART_write(uart, payload, len);          
        }  
        if(events & UART_EVENT_RECEIVED)
        {
            if(RxBufRead <= RxBufPos)
            {
                memcpy(mac_uart_rx.data,Uart_RxBuf,RxBufPos);
                SwithtoTx(mac_uart_rx.frame.destination_address,4,mac_uart_rx.data, mac_radio_rx.frame.len + 15);
//               // RxBufRead = RxBufPos;
//                RxBufPos=0;
            }
//            else                     //del by yu begin
//            {
//                SwithtoTx(Uart_RxBuf[0],&Uart_RxBuf[RxBufRead], 256-RxBufRead );
//                RxBufRead = 0;
//            }                        //del by yu end
        }

    }
}

fenglin hu:

你这个多任务的解决了吗?我现在也遇到问题了,

Felix ZF:

回复 fenglin hu:

你可以使用ROV观察一下两个任务的状态,以及分配的stack是否足够

赞(0)
未经允许不得转载:TI中文支持网 » CC1310任务建立问题
分享到: 更多 (0)