This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC1352R1: How to read uart data in callback without semaphore

Part Number: LAUNCHXL-CC1352R1

HI Experts,

i am trying to implement the uartcallback without semaphore, the below code does not read uart data which is available, please let me know how to do this... if i use uart ECHO that also waits forever for uart data this also does not exit from the uartread line, In uartcallback example that is wait in semaphore it's also waiting for semaphore post, i have tried UARTreadtimeout function in UART ECHO example it's not working as expected, semaphore pend and semaphore timeout functions also do not work as expected, 

i am trying to send data to uart at 5sec interval, print the uart data when data is available otherwise my device just send uart data at 5sce interval...

please let me know how to do the above function...

/*
* ======== uart2callback.c ========
*/
#include <stdint.h>
#include <stddef.h>

/* POSIX Header files */
#include <semaphore.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART2.h>

/* Driver configuration */
#include "ti_drivers_config.h"

static sem_t sem;
static volatile size_t numBytesRead;
char input[100];

/*
* ======== callbackFxn ========
*/
void callbackFxn(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
numBytesRead = count;
/* Pass NULL for bytesRead since it's not used in this example */
status = UART2_read(handle, &input, numBytesRead, NULL);

if (status != UART2_STATUS_SUCCESS)
{
/* UART2_read() failed */
while (1) {}
}
//sem_post(&sem);
}

/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
const char echoPrompt[] = "Echoing characters:\r\n";
UART2_Handle uart;
UART2_Params uartParams;
int32_t semStatus;
uint32_t status = UART2_STATUS_SUCCESS;

/* Call driver init functions */
GPIO_init();

/* Configure the LED pin */
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

/* Create a UART in CALLBACK read mode */
UART2_Params_init(&uartParams);
uartParams.readMode = UART2_Mode_CALLBACK;
uartParams.readCallback = callbackFxn;
uartParams.baudRate = 115200;

uart = UART2_open(CONFIG_UART2_0, &uartParams);

if (uart == NULL)
{
/* UART2_open() failed */
while (1) {}
}

/* Turn on user LED to indicate successful initialization */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);

/* Pass NULL for bytesWritten since it's not used in this example */
UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);

/* Loop forever echoing */
while (1)
{

UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);


if (numBytesRead > 0)
{
status = UART2_write(uart, &input, numBytesRead, NULL);

if (status != UART2_STATUS_SUCCESS)
{
/* UART2_write() failed */
while (1) {}
}
numBytesRead = 0;
}
GPIO_toggle(CONFIG_GPIO_LED_0);
sleep(5);
}
}

regards

Surya