Tool/software: TI-RTOS
Hi all.
I'm testing the Uart Echo using Read Call Back.
I'm using the SWI to avoid call Uart_read in its own call back.
It worked fine when I send an array has 15 bytes or below), but when I send an array that has 16 bytes or above, it just echo just 1 byte begin.
For example, when I send an array 02 FF FF FF FF FF FE 31 32 33 34 35 36 30 51 03, it just echo 02 (the first byte)
Below is my code, thank you for your reading and I'm looking forward to listen to your help.
/* * ======== uartecho.c ======== */ #include <stdint.h> #include <stddef.h> #include <unistd.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/UART.h> #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> /* Example/Board Header files */ #include "Board.h" #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Swi.h> #include <ti/sysbios/knl/Mailbox.h> /* * ======== mainThread ======== */ #define NUMMSGS 40 typedef struct MsgObj { Int id; Char val; } MsgObj; typedef struct MailboxMsgObj { Mailbox_MbxElem elem; /* Mailbox header */ MsgObj obj; /* Application's mailbox */ } MailboxMsgObj; /* This buffer is not directly accessed by the application */ MailboxMsgObj mailboxBuffer[NUMMSGS]; Mailbox_Struct mbxStruct; Mailbox_Handle mbxHandle; Swi_Handle swi0Handle; UART_Handle uart; char input; static void fnreadCallback(UART_Handle handle, void *rxBuf, size_t size) { Swi_post(swi0Handle); } void swi0Fxn(UArg arg0, UArg arg1) { UART_write(uart, &input, 1); UART_read(uart, &input, 1); } void *mainThread(void *arg0) { UART_Params uartParams; /* Call driver init functions */ UART_init(); /* Create a UART with data processing off. */ 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 = 9600; uartParams.readMode = UART_MODE_CALLBACK; uartParams.writeMode = UART_MODE_BLOCKING; uartParams.readCallback = fnreadCallback; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) { /* UART_open() failed */ while (1); } Swi_Params swiParams; Swi_Params_init(&swiParams); swiParams.arg0 = 1; swiParams.arg1 = 0; swiParams.priority = 2; swiParams.trigger = 0; Swi_Struct swi0Struct; Swi_construct(&swi0Struct, (Swi_FuncPtr)swi0Fxn, &swiParams, NULL); swi0Handle = Swi_handle(&swi0Struct); UART_read(uart, &input, 1); /* Loop forever echoing */ while (1) { usleep(10000); } }