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.

CCS/LAUNCHXL-CC1310: When I try to transmit, I can not exit RF_pendCmd

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: SYSBIOS

Tool/software: Code Composer Studio

Hello to all, my test program is to receive a message by the uart, to return it by the uart and to forward it by radio, but when it enters RF_pendCmd (rftxHandle, txCmdHndl, RF_EventLastCmdDone); Does not send the message and does not leave that command. The following is the code of my test program:

/*
* ======== main_tirtos.c ========
*/
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
/* POSIX Header files */
#include <pthread.h>
#include <string.h>
/* RTOS header files */
/* 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 <stddef.h>
#include "RFQueue.h"
//////////////////////////////
/***** Includes *****/
#include <stdlib.h>
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>

#ifdef DEVICE_FAMILY
#undef DEVICE_FAMILY_PATH
#define DEVICE_FAMILY_PATH(x) <ti/devices/DEVICE_FAMILY/x>
#include DEVICE_FAMILY_PATH(driverlib/rf_prop_mailbox.h)
#else
#error "You must define DEVICE_FAMILY at the project level as one of cc26x0, cc26x0r2, cc13x0, etc."
#endif

/* Board Header files */
//#include "Board.h"

#include "RFQueue.h"
#include "smartrf_settings/smartrf_settings.h"

//#include <stdlib.h>

///////////////////////////////
/***** Defines *****/
#define RX_TASK_STACK_SIZE 1024
#define RX_TASK_PRIORITY 2
#define TX_TASK_STACK_SIZE 1024
#define TX_TASK_PRIORITY 2
#define UART_TASK_STACK_SIZE 1500
#define UART_TASK_PRIORITY 2

/* Packet RX Configuration */
#define DATA_ENTRY_HEADER_SIZE 8 /* Constant header size of a Generic Data Entry */
#define MAX_LENGTH 40 /* Max length byte the radio will accept */
#define NUM_DATA_ENTRIES 2 /* NOTE: Only two data entries supported at the moment */
#define NUM_APPENDED_BYTES 2 /* The Data Entries data field will contain:
* 1 Header byte (RF_cmdPropRx.rxConf.bIncludeHdr = 0x1)
* Max 30 payload bytes
* 1 status byte (RF_cmdPropRx.rxConf.bAppendStatus = 0x1) */

/***** Defines *****/

/* Packet TX Configuration */
#define PAYLOAD_LENGTH 30
#define PACKET_INTERVAL (uint32_t)(4000000*0.5f) /* Set packet interval to 500ms */

/***** Prototypes *****/
static void rxTaskFunction(UArg arg0, UArg arg1);
static void RF_readcallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
static void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size);
static void *mainThread(void *arg0);
Void UartTaskFunction(UArg arg0, UArg arg1);
static void txTaskFunction(UArg arg0, UArg arg1);
Semaphore_Struct sem0Struct;
Semaphore_Handle sem;

UART_Handle uart;
UART_Params uartParams;
uint8_t txCmdHndl;
/***** Variable declarations *****/
static Task_Params txTaskParams;
Task_Struct txTask; /* not static so you can see in ROV */
static uint8_t txTaskStack[TX_TASK_STACK_SIZE];
const char mesageready[] = "I am ready:\r\n";
//UART_Handle uart;
//UART_Params uartParams;

/* Stack size in bytes */
#define THREADSTACKSIZE 1024
/////////////////////////
/* Pin driver handle */
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;
char caca;
char flagrxRF=0;
int numero=1;
char flagrxuart=0;
/*
* Application LED pin configuration table:
* - All LEDs board LEDs are off.
*/
PIN_Config pinTable[] =
{
Board_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};


/***** Variable declarations *****/
static Task_Params rxTaskParams;
Task_Struct rxTask; /* not static so you can see in ROV */
static uint8_t rxTaskStack[RX_TASK_STACK_SIZE];
static uint8_t uartTaskStack[UART_TASK_STACK_SIZE];
static RF_Object rfObject;
static RF_Handle rfrxHandle;
static RF_Handle rftxHandle;
static Task_Params uartTaskParams;
Task_Struct uartTask;
/* Buffer which contains all Data Entries for receiving data.
* Pragmas are needed to make sure this buffer is 4 byte aligned (requirement from the RF Core) */
#pragma DATA_ALIGN (rxDataEntryBuffer, 4);
static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES,
MAX_LENGTH,
NUM_APPENDED_BYTES)];

/* Receive dataQueue for RF Core to fill in data */
static dataQueue_t dataQueue;
static rfc_dataEntryGeneral_t* currentDataEntry;
static uint8_t packetLength;
static uint8_t* packetDataPointer;

static PIN_Handle pinHandle;

// uint8_t
char bufrxuart[100];
char* rxuartpointer;
char buftxRF[60];
char packet[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; /* The length byte is stored in a separate variable */
RF_Params rfParams;
uint8_t input;
uint32_t curtime;

////////////////////////
/***** Function definitions *****/
void UartTask_init(void)
{


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

}
//
void RxTask_init(PIN_Handle ledPinHandle) {

pinHandle = ledPinHandle;

Task_Params_init(&rxTaskParams);
rxTaskParams.stackSize = RX_TASK_STACK_SIZE;
rxTaskParams.priority = RX_TASK_PRIORITY;
rxTaskParams.stack = &rxTaskStack;
rxTaskParams.arg0 = (UInt)1000000;

Task_construct(&rxTask, rxTaskFunction, &rxTaskParams, NULL);
}
/// Function definitions
void TxTask_init(PIN_Handle inPinHandle)
{

// pinHandle = inPinHandle;

Task_Params_init(&txTaskParams);
txTaskParams.stackSize = TX_TASK_STACK_SIZE;
txTaskParams.priority = TX_TASK_PRIORITY;
txTaskParams.stack = &txTaskStack;
txTaskParams.arg0 = (UInt)1000000;

Task_construct(&txTask, txTaskFunction, &txTaskParams, NULL);
}


static void rxTaskFunction(UArg arg0, UArg arg1)

{
Semaphore_post(sem);

RF_Params_init(&rfParams);

if( RFQueue_defineQueue(&dataQueue,
rxDataEntryBuffer,
sizeof(rxDataEntryBuffer),
NUM_DATA_ENTRIES,
MAX_LENGTH + NUM_APPENDED_BYTES))
{
// Failed to allocate space for all data entries
while(1);
}

// Modify CMD_PROP_RX command for application needs
RF_cmdPropRx.pQueue = &dataQueue; // Set the Data Entity queue for received data
RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1; // Discard ignored packets from Rx queue
RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1; // Discard packets with CRC error from Rx queue
RF_cmdPropRx.maxPktLen = MAX_LENGTH; // Implement packet length filtering to avoid PROP_ERROR_RXBUF
RF_cmdPropRx.pktConf.bRepeatOk = 0;
RF_cmdPropRx.pktConf.bRepeatNok = 0;


// Request access to the radio
rfrxHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);

// Set the frequency
RF_postCmd(rfrxHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);

// Enter RX mode
RF_CmdHandle rfRxCmd = RF_postCmd(rfrxHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &RF_readcallback, RF_EventRxEntryDone);

// while(1);
}
static void txTaskFunction(UArg arg0, UArg arg1)
{

sleep(2);
Semaphore_pend(sem, BIOS_WAIT_FOREVER);

RF_cmdPropTx.pktLen = PAYLOAD_LENGTH;
RF_cmdPropTx.pPkt =(uint8_t*) buftxRF;
RF_cmdPropTx.startTrigger.triggerType = 0;//TRIG_ABSTIME;
RF_cmdPropTx.startTrigger.pastTrig = 0;//1;
RF_cmdPropTx.startTime = 0;

// Request access to the radio
rftxHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);

// Set the frequency
RF_postCmd(rftxHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);

}
//
Void UartTaskFunction(UArg arg0, UArg arg1)
{
UART_init();

/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);

/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.readMode = UART_MODE_CALLBACK;
uartParams.readCallback = Uart_ReadCallback;
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
rxuartpointer=bufrxuart;
uart = UART_open(Board_UART0, &uartParams);
UART_read(uart, &input, 1);
if (uart == NULL)
{
/* UART_open() failed */
while (1);
}
}
void RF_readcallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
{

if (e & RF_EventRxEntryDone)
{
/* Toggle pin to indicate RX */
PIN_setOutputValue(pinHandle, Board_PIN_LED2,!PIN_getOutputValue(Board_PIN_LED2));

/* Get current unhandled data entry */
currentDataEntry = RFQueue_getDataEntry();

/* Handle the packet data, located at &currentDataEntry->data:
* - Length is the first byte with the current configuration
* - Data starts from the second byte */
packetLength = *(uint8_t*)(&currentDataEntry->data);
packetDataPointer = (uint8_t*)(&currentDataEntry->data + 1);

/* this is for to send message by UART in my main when flag is true */
sprintf(packet,"%06d",numero);
memcpy(packet+6, packetDataPointer, (packetLength + 1));
strcat(packet,"\x0d\x0a");
numero++;
//this flagrxRF say to uart in the mainThread that send the mesage in txpacket
flagrxRF=1;
///// RF_CmdHandle rfRxCmd = RF_postCmd(rfrxHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &RF_readcallback, RF_EventRxEntryDone);

///// RFQueue_nextEntry();


}
}
// Callback function
void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{
UART_read(uart, &input, 1);
rxuartpointer[0]=input;
rxuartpointer++;
if(input==0x0d)
{
rxuartpointer[0]=0;
flagrxuart=1;
}
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
// char input;

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


UART_write(uart,mesageready,strlen(mesageready));

/* Loop main */
//************************************************
while (1) {

if(flagrxuart)
{
rxuartpointer=bufrxuart;
UART_write(uart, bufrxuart, strlen(bufrxuart));
//transmit message RF
RF_cmdPropTx.pktLen =strlen(bufrxuart);// packetLength;
txCmdHndl = RF_postCmd(rftxHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL, 0);

//When I try to transmit, I can not exit from the next RF_pendCmd
RF_pendCmd(rftxHandle, txCmdHndl, RF_EventLastCmdDone);

flagrxuart=0;


}

if(flagrxRF)
{
UART_write(uart, packet, strlen(packet));
flagrxRF=0;

}
}
}


//////////////////////
/*
* ======== main ========
*/
int main(void)
{
pthread_t thread;
pthread_attr_t pAttrs;
struct sched_param priParam;
int retc;
int detachState;
Semaphore_Params semParams;
/* Call driver init functions */
Board_initGeneral();
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
Semaphore_construct(&sem0Struct, 0, &semParams);
sem = Semaphore_handle(&sem0Struct);

/* Set priority and stack size attributes */
pthread_attr_init(&pAttrs);
priParam.sched_priority = 1;

detachState = PTHREAD_CREATE_DETACHED;
retc = pthread_attr_setdetachstate(&pAttrs, detachState);
if (retc != 0) {
/* pthread_attr_setdetachstate() failed */
while (1);
}

pthread_attr_setschedparam(&pAttrs, &priParam);

retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE);
if (retc != 0) {
/* pthread_attr_setstacksize() failed */
while (1);
}

retc = pthread_create(&thread, &pAttrs, mainThread, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1);
}
////////////////////////////
/* Open LED pins */
ledPinHandle = PIN_open(&ledPinState, pinTable);
if(!ledPinHandle)
{
System_abort("Error initializing board LED pins\n");
}

/* Initialize task */

UartTask_init();
RxTask_init(ledPinHandle);
TxTask_init(ledPinHandle);
/* Start BIOS */

BIOS_start();

return (0);
}

I have spent many hours trying to solve this, but it does not work for me, I would appreciate it if someone helped me.

Luis Valseca

  • Hi Luis

    I tested your code by sending data over UART to the LP and then try to transmit them.

    When you post your TX command the radio is still in RX mode, so you need to cancel the RX command first. This is done by using RF_cancelCmd(rfrxHandle, rfRxCmd, 1);

    After the packet is transmitted you need to enter RX again by posting the RX command.

     

    With adding this code I am able to send a packet. The packet length is strlen(bufrxuart) long, but what you send is buftxRF, which is always all 0’s. I guess that you either want to send bufrxuart or at least copy the content to buftxRF before sending.

     

    BR

     

    Siri

  • Hi Siri,
    with the command cancelCmd() every thing works perfectly, thank you very much for your answer,In a few minutes my problem with your answer has been resolved.
    Best regards

    Luis Valseca
  • Hi Luis

    Glad I could help. Good luck with your project.

    BR

    Siri