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

请教TI大神帮我看看代码,为什么UART_open()返回的是0x0000000

#include <xdc/std.h>
/* BIOS Header files */
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/BIOS.h>
/* TI-RTOS Header files */
#include <ti/drivers/UART.h>
/* XDCtools Header files */
#include <xdc/runtime/System.h>
/* Example/Board Header files */
#include "Board.h"
/* Juszou Header files */
#include "Juszou/txTaskUart_init.h"
#include "Juszou/rxTask_init.h"

/***** Defines *****/
#define UART_TASK_STACK_SIZE 1024
#define UART_TASK_PRIORITY 2
#define UART_FIFO_FULL_SIZE 256

uint8_t len;
uint8_t payload[128];
uint8_t uart_rxBuf[UART_FIFO_FULL_SIZE];
Event_Struct uartEvent;
static Event_Handle eventHandle;
static Task_Params uartTaskParams;
static uint8_t uartTaskStack[UART_TASK_STACK_SIZE];
Task_Struct uartTask;
UART_Params uartParams;
UART_Handle uartHandle;
char uart_rxTempBuf[10];
char uart_txTempBuf[10];
int rxBufPos = 0;
int rxBufRead = 0;

void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size){
size_t i;
for(i = 0; i < size; i++){
if(rxBufPos != UART_FIFO_FULL_SIZE){
uart_rxBuf[rxBufPos] = ((uint8_t *)rxBuf)[i];
rxBufPos++;
}else {
rxBufPos = 0;
uart_rxBuf[rxBufPos] = ((uint8_t *)rxBuf)[i];
rxBufPos++;
}
}

UART_read(handle, uart_rxTempBuf, 1);
if(uart_rxBuf[rxBufPos-1] == '\n')
{
//post event to rf
Uart_PostEvent(UART_EVENT_SEND);
}
}

void Uart_WriteCallback(UART_Handle handle, void *txBuf, size_t size){
UART_read(handle, uart_txTempBuf, 1);
}
/*
* ======== echoFxn ========
* Task for this function is created statically. See the project's .cfg file.
*/
static void uartTaskFunction(UArg arg0, UArg arg1){
UART_read(uartHandle, uart_rxTempBuf, 1);
while(1){
uint32_t events = Event_pend(eventHandle, 0, UART_EVENT_ALL, BIOS_WAIT_FOREVER);
if(events & UART_EVENT_PRINT){
UART_write(uartHandle, payload, len);
}
if(events & UART_EVENT_SEND){
if(rxBufRead <= rxBufPos){
SwithtoTx(&uart_rxBuf[rxBufRead], rxBufPos-rxBufRead );
rxBufRead = rxBufPos;
}else{
SwithtoTx(&uart_rxBuf[rxBufRead], UART_FIFO_FULL_SIZE-rxBufRead );
rxBufRead = 0;
}
}
}
}

void txTaskUart_init(void){

/* Creat event used internally for state changes */
Event_Params eventParams;
Event_Params_init(&eventParams);
Event_construct(&uartEvent, &eventParams);
eventHandle = Event_handle(&uartEvent);

/* Creat 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);

/* Creat a UART with data processing off */

UART_Params_init(&uartParams);
uartParams.readMode = UART_MODE_CALLBACK;
uartParams.writeMode = UART_MODE_CALLBACK;
uartParams.readCallback = Uart_ReadCallback;
uartParams.writeCallback = Uart_WriteCallback;
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uartHandle = UART_open(Board_UART0, &uartParams);
if(uartHandle == NULL){
System_abort("UART_open fail");
}
}

void Uart_PostEvent(uint32_t event)
{
Event_post(eventHandle, event);
}

zou Jus:

回复 Alvin Chen:

接口定义完全是根据上面定义的,但是我加上UART_init就可以了,手册上面似乎不需要这个。您看看

Alvin Chen:

回复 zou Jus:

是需要加UART_init的,你可以参考我们SDK里面的demo:
dev.ti.com/…/node

赞(0)
未经允许不得转载:TI中文支持网 » 请教TI大神帮我看看代码,为什么UART_open()返回的是0x0000000
分享到: 更多 (0)