Hi,
I try to create RF test function include "continuous TX" and "packet RX". But they cannot switch correctly, I provide my steps and program for your reference. Please help us to solve this issue, thank you
1. program start --> RF idle --> press button --> RF continuous TX start(OK) --> press button --> RF continuous TX stop(OK), RF packet RX forever start(NG) --> press button --> RF packet RX forever stop(???), RF continuous TX start(NG)
2. program start --> RF idle --> press button --> RF packet RX forever start(OK) --> press button --> RF packet RX forever stop(OK), RF continuous TX start(OK) --> press button --> RF continuous TX stop(OK), RF packet RX forever start(NG) --> press button --> RF packet RX forever stop(???), RF continuous TX start(NG)
/*
* Copyright (c) 2019, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/***** Includes *****/
/* TI Drivers */
#include <ti/drivers/Power.h>
#include <ti/drivers/rf/RF.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
/* Board Header files */
#include "ti_drivers_config.h"
/* Application Header files */
#include "RFQueue.h"
#include <ti_radio_config.h>
/***** Defines *****/
#define WORK_MODE_NONE 0
#define WORK_MODE_TX 1
#define WORK_MODE_RX 2
/* Packet RX Configuration */
#define DATA_ENTRY_HEADER_SIZE 8 /* Constant header size of a Generic Data Entry */
#define MAX_LENGTH 30 /* 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) */
/***** Prototypes *****/
/***** Variable declarations *****/
static RF_Object rfObject;
static RF_Handle rfHandle;
static RF_CmdHandle rxCmdhandle;
static RF_CmdHandle txCmdhandle;
uint8_t workMode = 0;
static uint8_t
rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES,
MAX_LENGTH,
NUM_APPENDED_BYTES)]
__attribute__((aligned(4)));
/* 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 void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
/*
* ======== gpioButtonFxn0 ========
* Callback function for the GPIO interrupt on CONFIG_GPIO_BUTTON_0.
*
* Note: GPIO interrupts are cleared prior to invoking callbacks.
*/
void gpioButtonFxn0(uint_least8_t index)
{
/* Toggle an LED */
GPIO_toggle(CONFIG_LED_0_GPIO);
if(workMode == WORK_MODE_NONE)
{
workMode = WORK_MODE_TX;
// workMode = WORK_MODE_RX;
txCmdhandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdTxTest, RF_PriorityNormal, NULL, 0);
// rxCmdhandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &callback, RF_EventRxEntryDone);
}
else if(workMode == WORK_MODE_TX)
{
RF_cancelCmd(rfHandle, txCmdhandle, 0);
RF_pendCmd(rfHandle, txCmdhandle, RF_EventLastCmdDone);
workMode = WORK_MODE_RX;
rxCmdhandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, &callback, RF_EventRxEntryDone);
}
else if(workMode == WORK_MODE_RX)
{
RF_cancelCmd(rfHandle, rxCmdhandle, 0);
RF_pendCmd(rfHandle, rxCmdhandle, RF_EventLastCmdDone);
workMode = WORK_MODE_TX;
txCmdhandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdTxTest, RF_PriorityNormal, NULL, 0);
}
}
/***** Function definitions *****/
void *mainThread(void *arg0)
{
workMode = WORK_MODE_NONE;
/* Call driver init functions */
GPIO_init();
/* Configure the LED and button pins */
GPIO_setConfig(CONFIG_LED_0_GPIO, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(CONFIG_LED_1_GPIO, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(CONFIG_GPIO_BUTTON_0_INPUT, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
/* Turn on user LED */
GPIO_write(CONFIG_LED_0_GPIO, CONFIG_GPIO_LED_ON);
GPIO_write(CONFIG_LED_1_GPIO, CONFIG_GPIO_LED_OFF);
/* Install Button callback */
GPIO_setCallback(CONFIG_GPIO_BUTTON_0_INPUT, gpioButtonFxn0);
/* Enable interrupts */
GPIO_enableInt(CONFIG_GPIO_BUTTON_0_INPUT);
/* Configure the radio for Proprietary mode */
RF_Params rfParams;
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 */
/* Set the Data Entity queue for received data */
RF_cmdPropRx.pQueue = &dataQueue;
/* Discard ignored packets from Rx queue */
RF_cmdPropRx.rxConf.bAutoFlushIgnored = 1;
/* Discard packets with CRC error from Rx queue */
RF_cmdPropRx.rxConf.bAutoFlushCrcErr = 1;
/* Implement packet length filtering to avoid PROP_ERROR_RXBUF */
RF_cmdPropRx.maxPktLen = MAX_LENGTH;
RF_cmdPropRx.pktConf.bRepeatOk = 1;
RF_cmdPropRx.pktConf.bRepeatNok = 1;
/* Explicitly configure CW (1) or Modulated (0). Default modulated mode is PRBS-15. */
RF_cmdTxTest.config.bUseCw = 1;
/* In order to achieve +14dBm output power, make sure .txPower = 0xa73f, and
that the define CCFG_FORCE_VDDR_HH = 0x1 in ccfg.c */
/* 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// DeviceFamily_CC26X0R2
/* Send CMD_FS and wait until it has completed */
RF_runCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
/* Send CMD_TX_TEST which sends forever */
// RF_runCmd(rfHandle, (RF_Op*)&RF_cmdTxTest, RF_PriorityNormal, NULL, 0);
/* Should never come here */
while (1);
}
void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
{
if (e & RF_EventRxEntryDone)
{
/* Toggle pin to indicate RX */
//PIN_setOutputValue(ledPinHandle, CONFIG_GPIO_RLED,
// !PIN_getOutputValue(CONFIG_GPIO_RLED));
GPIO_toggle(CONFIG_LED_1_GPIO);
/* Get current unhandled data entry */
currentDataEntry = RFQueue_getDataEntry();
/* Handle the packet data, located at ¤tDataEntry->data:
* - Length is the first byte with the current configuration
* - Data starts from the second byte */
packetLength = *(uint8_t*)(¤tDataEntry->data);
packetDataPointer = (uint8_t*)(¤tDataEntry->data + 1);
/* Copy the payload + the status byte to the packet variable */
// memcpy(packet, packetDataPointer, (packetLength + 1));
RFQueue_nextEntry();
}
}