Tool/software:
/***** Includes *****/
/* Standard C Libraries */
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h> // For usleep function
/* TI Drivers */
#include <ti/drivers/rf/RF.h>
#include <ti/drivers/GPIO.h>
/* Driverlib Header files */
#include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h)
/* Board Header files */
#include "ti_drivers_config.h"
#include "RFQueue.h"
#include <ti_radio_config.h>
#include <ti/drivers/UART2.h>
/***** Defines *****/
/* Packet RX Configuration */
#define DATA_ENTRY_HEADER_SIZE 8
#define MAX_LENGTH 30
//#define MAX_LENGTH 10
#define NUM_DATA_ENTRIES 2
#define NUM_APPENDED_BYTES 2
/* Packet TX Configuration */
#define PAYLOAD_LENGTH 10
#define PACKET_INTERVAL 500000
/***** Prototypes *****/
static void rxCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
/***** Variable declarations *****/
static RF_Object rfObject;
static RF_Handle rfHandle;
static RF_CmdHandle rfPostHandle;
/* RX Data Entry Buffer */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_ALIGN(rxDataEntryBuffer, 4);
static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)];
#elif defined(__IAR_SYSTEMS_ICC__)
#pragma data_alignment = 4
static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)];
#elif defined(__GNUC__)
static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)] __attribute__((aligned(4)));
#else
#error This compiler is not supported.
#endif
/* Data queue for RX */
static dataQueue_t dataQueue;
static rfc_dataEntryGeneral_t* currentDataEntry;
static uint8_t packetLength;
static uint8_t* packetDataPointer;
/* RX and TX Packets */
static uint8_t rxPacket[MAX_LENGTH + NUM_APPENDED_BYTES - 1];
static uint8_t txPacket[10]; // Make txPacket large enough to hold the received data
static uint8_t save[MAX_LENGTH + NUM_APPENDED_BYTES - 1];
//static uint8_t output[MAX_LENGTH + NUM_APPENDED_BYTES - 1];
static uint8_t output[4];
static uint8_t input[10];
/***** Function definitions *****/
void *mainThread(void *arg0)
{
RF_Params rfParams;
RF_Params_init(&rfParams);
/* Initialize UART parameters */
UART2_Params uartParams;
UART2_Params_init(&uartParams);
UART2_Handle rs232Uart;
uartParams.baudRate = 115200;
rs232Uart = UART2_open(CONFIG_UART2_1, &uartParams);
UART2_write( rs232Uart, "\r\n UART opened successfully \r\n", strlen(" UART opened successfully \r\n"), NULL);
/* Configure LEDs */
GPIO_setConfig(CONFIG_GPIO_RLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(CONFIG_GPIO_GLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_write(CONFIG_GPIO_RLED, CONFIG_GPIO_LED_OFF);
GPIO_write(CONFIG_GPIO_GLED, CONFIG_GPIO_LED_OFF);
/* Initialize RX queue */
if (RFQueue_defineQueue(&dataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES)) {
while (1); // Allocation failed
}
/* Modify RX command */
RF_cmdPropRx.pQueue = &dataQueue;
RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1;
RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1;
RF_cmdPropRx.maxPktLen = MAX_LENGTH;
/* Set up TX command */
// RF_cmdPropTx.pktLen = PAYLOAD_LENGTH;
RF_cmdPropTx.pktLen = 6;
RF_cmdPropTx.pPkt = txPacket;
RF_cmdPropTx.startTrigger.triggerType = TRIG_NOW;
/* Request access to the radio */
#if defined(DeviceFamily_CC26X0R2)
rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioSetup, &rfParams);
#else
rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
#endif
/* Set the frequency */
RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
while (1) {
/* Reset RX queue */
// RFQueue_resetQueue(&dataQueue);
UART2_read(rs232Uart, input, sizeof(input), NULL);
UART2_write( rs232Uart, &input,sizeof(input) , NULL);
for(int c=2;c<=2;c++)
{
txPacket[2]=0x01;
txPacket[3]=0x02;
txPacket[4]= input[c];
txPacket[5]=0x04;
}
/* Transmit packet */
//RF_EventMask txTermination = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL, 0);
RF_EventMask txTermination = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL, 1);
if (txTermination & RF_EventLastCmdDone) {
GPIO_toggle(CONFIG_GPIO_GLED); // Indicate successful TX
// UART2_write( rs232Uart, " \r\nTX DATA successfully \r\n", strlen(" TX DATA successfully \r\n"), NULL);
}
/* Optional delay to ensure RX completes cleanly */
usleep(500000);
/* Start RX */
// RF_EventMask rxTermination = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &rxCallback, RF_EventRxEntryDone);
RF_EventMask rxTermination = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &rxCallback, RF_EventRxEntryDone);
/* Handle RX termination reasons */
// RF_EventMask rxTermination = RF_EventCmdAborted | RF_EventCmdPreempted;
if(( rxTermination & RF_EventCmdAborted ) && ( rxTermination & RF_EventCmdPreempted ))
{
//if (rxTermination & RF_EventLastCmdDone) {
GPIO_toggle(CONFIG_GPIO_RLED); // Indicate successful TX
} else {
// Handle other termination reasons as needed
}
/* Sleep between packets */
usleep(PACKET_INTERVAL);
for(int p=0;p<MAX_LENGTH+ NUM_APPENDED_BYTES - 1;p++)
{
if(rxPacket[p]==0XF0)
{
// UART2_write( rs232Uart,&rxPacket , sizeof(rxPacket), NULL);
for(int q=0;q<=50;q++)
{
if(rxPacket[q]==0x03)
{
GPIO_toggle(CONFIG_GPIO_RLED); // Indicate RX
output[0]=0x05;
output[1]=0x04;
output[2]=rxPacket[4];
output[3]=0x06;
UART2_write( rs232Uart, &output,sizeof(output), NULL);
}
}
}
}
//}
}
}
void rxCallback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
{
if (e & RF_EventRxEntryDone) {
GPIO_toggle(CONFIG_GPIO_RLED); // Indicate RX
/* Get current unhandled data entry */
currentDataEntry = RFQueue_getDataEntry();
/* Extract packet data */
packetLength = *(uint8_t*)(¤tDataEntry->data);
packetDataPointer = (uint8_t*)(¤tDataEntry->data + 1);
memcpy(rxPacket, packetDataPointer, packetLength);
RFQueue_nextEntry();
// usleep(5000);
}
} I want this code as uart interrupt. here when uart read data it should work on interrpt then that read data sholud be send to RF TX then after completion of tx, RF RX will be working after receiving all data from RF RX it sholud print in uart write data which should be also in interrupt mode . Can you please change the code for uart interrupt.