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-CC1310:在将电路板模式从 Tx 更改为 Rx 或相反时出现通信问题

Guru**** 2539500 points
Other Parts Discussed in Thread: CC1190, CC1310

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/1005922/launchxl-cc1310-problem-in-communicating-when-changing-board-mode-from-tx-to-rx-or-opposite

器件型号:LAUNCHXL-CC1310
主题中讨论的其他器件:CC1190CC1310

您好!

我们正在进行项目开发、以使两个 CC1310 Launchxl 电路板使用 rfWakeOnTx/Rx 示例与 rfSmartRf studio 中的(目标配置:LAUNCHXL-CC1310-CC1180-US、50kbps / 915MHz)进行通信、并且我们已在代码中激活 CC1190  

1、第一 个板模式为 Tx、另一个 Rx  

我们的第一  块板将在第二 块板上唤醒   

之后、我们的第二个板将其自身模式更改为 Tx 并将数据发送到第一个板

然后、我们的第一块电路板将其模式更改为 Rx 并接收数据。

我们的问题是、当我们的板将其模式 TX 更改为 Rx 或 Rx 更改为 TX 时、射频通信的范围会比 befor 短、因此正常情况下、我们在这里会发生一些错误

正在等待您的回答。 谢谢

Ali。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    第一板代码:

    /** Includes **/
    #include <stdlib.h>
    
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/Assert.h>
    
    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Semaphore.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    
    /* TI-RTOS Header files */
    #include <ti/drivers/rf/RF.h>
    #include <ti/drivers/PIN.h>
    #include <ti/display/Display.h>
    #include <ti/drivers/pin/PINCC26XX.h>
    
    #include <ti/devices/DeviceFamily.h>
    #include DeviceFamily_constructPath(driverlib/cpu.h)
    #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h)
    
    /* Board Header files */
    #include "Board.h"
    
    /* RF settings */
    #include "RFQueue.h"
    #include "smartrf_settings/smartrf_settings.h"
    
    /** Defines **/
    /* Wake-on-Radio configuration */
    #define WOR_WAKEUPS_PER_SECOND 2
    
    /* TX number of random payload bytes */
    #define PAYLOAD_LENGTH 30
    
    /* WOR Example configuration defines */
    #define WOR_PREAMBLE_TIME_RAT_TICKS(x) \
        ((uint32_t)(4000000*(1.0f/(x))))
    
    /* TX task stack size and priority */
    #define TX_TASK_STACK_SIZE 1024
    #define TX_TASK_PRIORITY   2
    
    #define TIMEOUT_MS      1000
    
    /* Packet RX Configuration */
    #define DATA_ENTRY_HEADER_SIZE 8  /* Constant header size of a Generic Data Entry */
    #define MAX_LENGTH             31 /* 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     1  /* 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 **/
    static void txTaskFunction(UArg arg0, UArg arg1);
    static void initializeTxAdvCmdFromTxCmd(rfc_CMD_PROP_TX_ADV_t* RF_cmdPropTxAdv, rfc_CMD_PROP_TX_t* RF_cmdPropTx);
    static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
    
    /** Variable declarations **/
    /* TX task objects and task stack */
    static Task_Params txTaskParams;
    Task_Struct txTask;    /* not static so you can see in ROV */
    static uint8_t txTaskStack[TX_TASK_STACK_SIZE];
    
    /* TX packet payload (length +1 to fit length byte) and sequence number */
    static uint8_t packet[PAYLOAD_LENGTH +1];
    
    /* RF driver objects and handles */
    static RF_Object rfObject;
    static RF_Handle rfHandle;
    
    /* Pin driver objects and handles */
    static PIN_Handle ledPinHandle;
    static PIN_Handle buttonPinHandle;
    static PIN_State ledPinState;
    static PIN_State buttonPinState;
    
    /* TX Semaphore */
    static Semaphore_Struct txSemaphore;
    static Semaphore_Handle txSemaphoreHandle;
    
    /* Advanced TX command for sending long preamble */
    static rfc_CMD_PROP_TX_ADV_t RF_cmdPropTxAdv;
    
    /* RF Rx Conf*/
    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;
    bool flagPropDone = false;
    bool flagRxRcv = false;
    
    static uint8_t packet_Rx[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; /* The length byte is stored in a separate variable */
    static volatile bool bRxSuccess = false;
    
    /* Receive Statistics */
    static rfc_propRxOutput_t rxStatistics;
    
    /*
     * Application LED pin configuration table:
     *   - All LEDs board LEDs are off.
     */
    PIN_Config pinTable[] =
    {
        Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PINCC26XX_DIO29 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PINCC26XX_DIO30 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,   
    	PIN_TERMINATE
    };
    
    /*
     * Application button pin configuration table:
     *   - Buttons interrupts are configured to trigger on falling edge.
     */
    PIN_Config buttonPinTable[] = {
        Board_PIN_BUTTON0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
        PIN_TERMINATE
    };
    
    
    /** Function definitions **/
    /* Pin interrupt Callback function board buttons configured in the pinTable. */
    void buttonCallbackFunction(PIN_Handle handle, PIN_Id pinId) {
    
        /* Simple debounce logic, only toggle if the button is still pushed (low) */
        CPUdelay((uint32_t)((48000000/3)*0.050f));
        if (!PIN_getInputValue(pinId)) {
            /* Post TX semaphore to TX task */
            Semaphore_post(txSemaphoreHandle);
        }
    }
    
    /* TX task function. Executed in Task context by TI-RTOS when the scheduler starts. */
    static void txTaskFunction(UArg arg0, UArg arg1)
    {
        /* Setup callback for button pins */
        PIN_Status status = PIN_registerIntCb(buttonPinHandle, &buttonCallbackFunction);
        Assert_isTrue((status == PIN_SUCCESS), NULL);
    
        RF_Params_init(&rfParams);
        PINCC26XX_setMux(ledPinHandle, PINCC26XX_DIO29, PINCC26XX_MUX_RFC_GPO0);
        PINCC26XX_setMux(ledPinHandle, PINCC26XX_DIO30, PINCC26XX_MUX_RFC_GPO1);
        /* Create queue and data entries (Grd) */
        //preallocated = önceden tahsis edilmiş
        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_TX and CMD_PROP_RX commands for application needs */
        /* Set the Data Entity queue for received data */
        RF_cmdPropRx.pQueue = &dataQueue;
        /* Discard (AT)  ignored (YKSY) 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 = PAYLOAD_LENGTH;
    
        /* End RX operation when a packet is received correctly and move on to the
         * next command in the chain
         * TR - Bir paket doğru bir şekilde alındığında RX işlemini sonlandırın ve
         * zincirdeki bir sonraki komuta geçin */
    
        RF_cmdPropRx.pktConf.bRepeatOk = 0;
        RF_cmdPropRx.pktConf.bRepeatNok = 1;
        RF_cmdPropRx.startTrigger.triggerType = TRIG_NOW;
        RF_cmdPropRx.pNextOp = (rfc_radioOp_t *)&RF_cmdPropTx;
    
        /* Only (SDC) run the TX command if RX is successful */
        RF_cmdPropRx.condition.rule = COND_STOP_ON_FALSE;
        RF_cmdPropRx.pOutput = (uint8_t *)&rxStatistics;
    
        /* Initialize TX_ADV command from TX command */
        initializeTxAdvCmdFromTxCmd(&RF_cmdPropTxAdv, &RF_cmdPropTx);
    
        /* Set application specific fields */
        RF_cmdPropTxAdv.pktLen = PAYLOAD_LENGTH +1; /* +1 for length byte */
        RF_cmdPropTxAdv.pPkt = packet;
        RF_cmdPropTxAdv.preTrigger.triggerType = TRIG_REL_START;
        RF_cmdPropTxAdv.preTime = WOR_PREAMBLE_TIME_RAT_TICKS(WOR_WAKEUPS_PER_SECOND);
    
        /* Request access to the radio */
        rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
    
        /* Set the frequency */
        RF_runCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
    
        /* Enter main TX loop */
        while(1)
        {
            /* Wait for a button press */
            Semaphore_pend(txSemaphoreHandle, BIOS_WAIT_FOREVER);
    
            packet[0] = PAYLOAD_LENGTH;
            packet[1] = 0xAA;
            packet[2] = 0xBB;
            packet[3] = 'I';
            packet[4] = 'N';
            packet[5] = 'O';
            packet[6] = 'V';
            packet[7] = 'A';
            packet[8] = 'R';
    
            /* Send packet */
            RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTxAdv, RF_PriorityNormal,callback, (RF_EventRxEntryDone | RF_EventLastCmdDone));
    
            switch(RF_cmdPropTxAdv.status)
            {
                case PROP_DONE_OK:
                    // Packet transmitted successfully
                    PINCC26XX_setMux(ledPinHandle, PINCC26XX_DIO29, PINCC26XX_MUX_RFC_GPO0);
                    PINCC26XX_setMux(ledPinHandle, PINCC26XX_DIO30, PINCC26XX_MUX_RFC_GPO1);
    
                    RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal,callback, (RF_EventRxEntryDone | RF_EventLastCmdDone));
    
                    /* Log RX_SNIFF status */
                    switch(RF_cmdPropRx.status) {
                        case PROP_DONE_IDLE:
                            /* Idle based on RSSI */
                            break;
                        case PROP_DONE_IDLETIMEOUT:
                            /* Idle based on PQT */
                            break;
                        case PROP_DONE_RXTIMEOUT:
                            /* Got valid preamble on the air, but did not find sync word */
                            break;
                        case PROP_DONE_OK:
                             //Packet Receive successfully
                             flagRxRcv = true;
    
                             /* LED1, LED2 close */
                             PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 0);
                             PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, 0);
                            break;
                        default:
                            /* Unhandled status */
                            break;
                    };
    
                    break;
                default:
                    // Uncaught error event - these could come from the
                    // pool of states defined in rf_mailbox.h
                    while(1);
            }
        }
    }
    
    /* Copy the basic RX configuration from CMD_PROP_RX to CMD_PROP_RX_SNIFF command. */
    static void initializeTxAdvCmdFromTxCmd(rfc_CMD_PROP_TX_ADV_t* RF_cmdPropTxAdv, rfc_CMD_PROP_TX_t* RF_cmdPropTx)
    {
        #define RADIO_OP_HEADER_SIZE 14
    
        /* Copy general radio operation header from TX commmand to TX_ADV */
        memcpy(RF_cmdPropTxAdv, RF_cmdPropTx, RADIO_OP_HEADER_SIZE);
    
        /* Set command to CMD_PROP_TX_ADV */
        RF_cmdPropTxAdv->commandNo = CMD_PROP_TX_ADV;
    
        /* Copy over relevant parameters */
        RF_cmdPropTxAdv->pktConf.bFsOff = RF_cmdPropTx->pktConf.bFsOff;
        RF_cmdPropTxAdv->pktConf.bUseCrc = RF_cmdPropTx->pktConf.bUseCrc;
        RF_cmdPropTxAdv->syncWord = RF_cmdPropTx->syncWord;
    }
    
    
    /*
     *  ======== main ========
     */
    int main(void){
        /* Call driver init functions. */
        Board_initGeneral();
        Display_init();
    
        /* Open LED pins */
        ledPinHandle = PIN_open(&ledPinState, pinTable);
        Assert_isTrue(ledPinHandle != NULL, NULL);
    
        /* Open Button pins */
        buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
        Assert_isTrue(buttonPinHandle != NULL, NULL);
    
        /* Initialize TX semaphore */
        Semaphore_construct(&txSemaphore, 0, NULL);
        txSemaphoreHandle = Semaphore_handle(&txSemaphore);
    
        /* Initialize and create TX task */
        Task_Params_init(&txTaskParams);
        txTaskParams.stackSize = TX_TASK_STACK_SIZE;
        txTaskParams.priority = TX_TASK_PRIORITY;
        txTaskParams.stack = &txTaskStack;
        Task_construct(&txTask, txTaskFunction, &txTaskParams, NULL);
    
        /* Start BIOS */
        BIOS_start();
    
        return (0);
    }
    
    void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
    {
        if((e & RF_EventCmdDone) && !(e & RF_EventLastCmdDone))
        {
            /* Successful TX */
            /* Toggle LED1, clear LED2 to indicate TX */
            PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 0);
            PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, 0);
        }
        else if(e & RF_EventRxEntryDone)
        {
            /* Successful RX */
            bRxSuccess = true;
    
            /* 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);
    
            /* Copy the payload + status byte to the packet_Rx variable */
            memcpy(packet_Rx, packetDataPointer, (packetLength + 1));
    
            /* Check the packet against what was transmitted */
            int16_t status = memcmp(packet, packet_Rx, packetLength);
    
            if(status == 0)
            {
                /* Toggle LED1, clear LED2 to indicate RX */
                PIN_setOutputValue(ledPinHandle, Board_PIN_LED1,
                                   !PIN_getOutputValue(Board_PIN_LED1));
                PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, 0);
    
    
            }
            else
            {
                /* Error Condition: set both LEDs */
                PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 1);
                PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, 1);
    
                memset(packet_Rx,'0',sizeof(packet));
            }
    
            RFQueue_nextEntry();
        }
        else if((e & RF_EventLastCmdDone) && !(e & RF_EventRxEntryDone))
        {
            if(bRxSuccess == true)
            {
                /* Received packet successfully but RX command didn't complete at
                 * the same time RX_ENTRY_DONE event was raised. Reset the flag
                 */
                bRxSuccess = false;
            }
            else
            {
                /* RX timed out */
                /* Set LED2, clear LED1 to indicate TX */
                PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 0);
                PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, 1);
            }
        }
        else
        {
            /* Error Condition: set both LEDs */
            PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 1);
            PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, 1);
        }
    }

    第二板代码:

    /* Standard C Libraries */
    #include <stdlib.h>
    #include <stdio.h>
    
    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Assert.h>
    
    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/drivers/SPI.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    
    /* TI-RTOS Header files */
    #include <ti/drivers/rf/RF.h>
    #include <ti/drivers/PIN.h>
    #include <ti/drivers/pin/PINCC26XX.h>
    
    #include "ti/devices/cc13x0/driverlib/sys_ctrl.h"
    
    /* Board Header files */
    #include "Board.h"
    
    /* Application Header files */
    #include "RFQueue.h"
    #include "smartrf_settings/smartrf_settings.h"
    
    #include <ti/devices/DeviceFamily.h>
    #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h)
    
    /** Defines **/
    /* Wake-on-Radio wakeups per second */
    #define WOR_WAKEUPS_PER_SECOND  2
    
    /* Wake-on-Radio mode. Can be:
     * - RSSI only
     * - PQT, preamble detection
     * - Both, first RSSI and then PQT if RSSI  */
    #define WOR_MODE CarrierSenseMode_RSSIandPQT
    
    /* Threshold for RSSI based Carrier Sense in dBm */
    #define WOR_RSSI_THRESHOLD      ((int8_t)(-111))
    
    /* Data Rate in use */
    #define WOR_RF_PHY_DATARATE_50KBPS  0 // 2-GFSK 50Kbps
    #define WOR_RF_PHY_DATARATE_100KBPS 1 // 2-GFSK 100Kbps
    #define WOR_RF_PHY_DATARATE_200KBPS 2 // 2-GFSK 200Kbps
    #define WOR_RF_PHY_DATARATE_300KBPS 3 // 2-GFSK 300Kbps
    #define WOR_RF_PHY_DATARATE_400KBPS 4 // 2-GFSK 400Kbps
    #define WOR_RF_PHY_DATARATE_500KBPS 5 // 2-GFSK 500Kbps
    
    #define WOR_RF_PHY_DATARATE WOR_RF_PHY_DATARATE_50KBPS
    
    /* Macro used to set actual wakeup interval */
    #define WOR_WAKE_UP_MARGIN_S 0.005f
    #define WOR_WAKE_UP_INTERVAL_RAT_TICKS(x) \
        ((uint32_t)(4000000*(1.0f/(x) - (WOR_WAKE_UP_MARGIN_S))))
    
    /* TI-RTOS Task configuration */
    #define RX_TASK_STACK_SIZE 1024
    #define RX_TASK_PRIORITY   2
    
    /* TX Configuration */
    #define DATA_ENTRY_HEADER_SIZE 8  /* Constant header size of a Generic Data Entry */
    #define MAX_LENGTH             31 /* 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     1  /* Length byte included in the stored packet */
    
    
    /* TX number of random payload bytes */
    #define PAYLOAD_LENGTH 30
    
    /* TX packet payload (length +1 to fit length byte) and sequence number */
    static uint8_t packet[PAYLOAD_LENGTH +1];
    static uint16_t seqNumber;
    
    /* Advanced TX command for sending long preamble */
    //static rfc_CMD_PROP_TX_ADV_t RF_cmdPropTxAdv;
    
    /** Type declarations **/
    /* General wake-on-radio RX statistics */
    struct WorStatistics {
      uint32_t doneIdle;
      uint32_t doneIdleTimeout;
      uint32_t doneRxTimeout;
      uint32_t doneOk;
    };
    
    /* Modes of carrier sense possible */
    enum CarrierSenseMode {
        CarrierSenseMode_RSSI,
        CarrierSenseMode_PQT,
        CarrierSenseMode_RSSIandPQT,
    };
    
    
    /** Variable declarations **/
    /* TX task objects and task stack */
    static Task_Params rxTaskParams;
    static Task_Struct rxTask,
                       spiTask;
    static uint8_t rxTaskStack[RX_TASK_STACK_SIZE];
    
    Char task0Stack[RX_TASK_STACK_SIZE];
    
    Clock_Struct clk1Struct;
    Clock_Handle clk1Handle;
    
    /* RF driver object and handle */
    static RF_Object rfObject;
    static RF_Handle rfHandle;
    
    /* Pin driver object and handle */
    static PIN_Handle ledPinHandle;
    static PIN_State ledPinState;
    
    /* General wake-on-radio sniff status statistics and statistics from the RF Core about received packets */
    static volatile struct WorStatistics worStatistics;
    static rfc_propRxOutput_t rxStatistics;
    
    /*
     * Application LED pin configuration table:
     *   - All LEDs board LEDs are off.
     */
    static PIN_Config pinTable[] =
    {
        Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PINCC26XX_DIO29 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PINCC26XX_DIO30 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PIN_TERMINATE
    };
    
    /* 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) */
    static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES,
                                                                     MAX_LENGTH,
                                                                     NUM_APPENDED_BYTES)];
    
    /* RX Data Queue and Data Entry pointer to read out received packets */
    static dataQueue_t dataQueue;
    static rfc_dataEntryGeneral_t* currentDataEntry;
    
    /* Received packet's length and pointer to the payload */
    static uint8_t packetLength;
    static uint8_t* packetDataPointer;
    
    static volatile uint8_t dummy;
    static uint8_t packet_RX[MAX_LENGTH + NUM_APPENDED_BYTES - 1]; /* The length byte is stored in a separate variable */
    
    /* Sniff command for doing combined Carrier Sense and RX*/
    static rfc_CMD_PROP_RX_SNIFF_t RF_cmdPropRxSniff;
    
    /* SPI Variable */
    uint8_t Buf[16];
    uint8_t gln[8];
    uint16_t counterGln = 0;
    uint8_t *s;
    
    SPI_Handle      slaveSpi;
    SPI_Params      spiParams;
    SPI_Transaction transaction;
    
    /** Prototypes **/
    static void rxTaskFunction(UArg arg0, UArg arg1);
    static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
    static void initializeSniffCmdFromRxCmd(rfc_CMD_PROP_RX_SNIFF_t* rxSniffCmd, rfc_CMD_PROP_RX_t* rxCmd);
    static void configureSniffCmd(rfc_CMD_PROP_RX_SNIFF_t* rxSniffCmd, enum CarrierSenseMode mode, uint32_t datarate, uint8_t wakeupPerSecond);
    static uint32_t calculateSymbolRate(uint8_t prescaler, uint32_t rateWord);
    
    // Callback function
    static void transferCallback(SPI_Handle handle, SPI_Transaction *transaction)
    {
        // Start another transfer
        SPI_transfer(handle, transaction);
    }
    
    void spiInit()
    {
        SPI_Params_init(&spiParams);
        spiParams.frameFormat           = SPI_POL0_PHA1;
        spiParams.mode                  = SPI_SLAVE;
        spiParams.transferMode          = SPI_MODE_CALLBACK;
        spiParams.transferCallbackFxn   = transferCallback;
        spiParams.dataSize              = 8; //8bit
        //spiParams.bitRate               = 38460; //38460
    
        // Configure the transaction
        transaction.count = 14;
        transaction.txBuf = NULL;
        transaction.rxBuf = Buf;
    
        slaveSpi = SPI_open(Board_SPI0, &spiParams);
    
        if (slaveSpi == NULL) {
           // printf("Error initializing slave SPI\n");
            while (1);
        }
        else {
            //printf("Slave SPI initialized\n");
        }
    
        SPI_transfer(slaveSpi, &transaction);
    }
    
    /* RX task function. Executed in Task context by TI-RTOS when the scheduler starts. */
    static void rxTaskFunction(UArg arg0, UArg arg1)
    {
        RF_Params rfParams;
        RF_Params_init(&rfParams);
    
        /* Route out LNA active pin to LED1 */
        PINCC26XX_setMux(ledPinHandle, PINCC26XX_DIO29, PINCC26XX_MUX_RFC_GPO0);
        PINCC26XX_setMux(ledPinHandle, PINCC26XX_DIO30, PINCC26XX_MUX_RFC_GPO1);
        /* Create queue and data entries */
        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);
        }
    
        RF_cmdPropTx.pktLen = PAYLOAD_LENGTH;
        RF_cmdPropTx.pPkt = packet;
        RF_cmdPropTx.startTrigger.triggerType = TRIG_NOW;
    
        /* Copy all RX options from the SmartRF Studio exported RX command to the RX Sniff command */
        initializeSniffCmdFromRxCmd(&RF_cmdPropRxSniff, &RF_cmdPropRx);
    
        /* Configure RX part of RX_SNIFF command */
        RF_cmdPropRxSniff.pQueue    = &dataQueue;
        RF_cmdPropRxSniff.pOutput   = (uint8_t*)&rxStatistics;
        RF_cmdPropRxSniff.maxPktLen = MAX_LENGTH;
    
        /* Discard ignored packets and CRC errors from Rx queue */
        RF_cmdPropRxSniff.rxConf.bAutoFlushIgnored = 1;
        RF_cmdPropRxSniff.rxConf.bAutoFlushCrcErr  = 1;
    
        /* Calculate datarate from prescaler and rate word */
        uint32_t datarate = calculateSymbolRate(RF_cmdPropRadioDivSetup.symbolRate.preScale,
                                                RF_cmdPropRadioDivSetup.symbolRate.rateWord);
    
        /* Configure Sniff-mode part of the RX_SNIFF command */
        configureSniffCmd(&RF_cmdPropRxSniff, WOR_MODE, datarate, WOR_WAKEUPS_PER_SECOND);
    
        /* Request access to the radio */
        rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
    
        /* Set frequency */
        RF_runCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, &callback, 0);
    
        /* Save the current radio time */
        RF_cmdPropRxSniff.startTime = RF_getCurrentTime();
    
        /* Enter main loop */
        while(1)
        {
            /* Set next wakeup time in the future */
            RF_cmdPropRxSniff.startTime += WOR_WAKE_UP_INTERVAL_RAT_TICKS(WOR_WAKEUPS_PER_SECOND);
    
            /* Schedule RX */
            RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRxSniff, RF_PriorityNormal, &callback, RF_EventRxEntryDone);
    
            /* Log RX_SNIFF status */
            switch(RF_cmdPropRxSniff.status) {
                case PROP_DONE_IDLE:
                    /* Idle based on RSSI */
                    worStatistics.doneIdle++;
                    break;
                case PROP_DONE_IDLETIMEOUT:
                    /* Idle based on PQT */
                    worStatistics.doneIdleTimeout++;
                    break;
                case PROP_DONE_RXTIMEOUT:
                    /* Got valid preamble on the air, but did not find sync word */
                    worStatistics.doneRxTimeout++;
                    break;
                case PROP_DONE_OK:
                    /* Received packet */
                    worStatistics.doneOk++;
    
                    counterGln = 0;
    
                    Clock_start(clk1Handle);
    
                    //spiInit();
    
                    // Read sensor over SPI
                    while(counterGln <= 250){
                        PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 1);
                    }
    
                    //SPI_transfer(slaveSpi, &transaction);
    
                    // Create data packet with sensor data
                    packet[0] = PAYLOAD_LENGTH;
                    packet[1] = (uint8_t)(seqNumber >> 8);
                    packet[2] = (uint8_t)(seqNumber++);
                    packet[3] = 'O';
                    packet[4] = 'K';
    
                    // Transmit the packet
                    PINCC26XX_setMux(ledPinHandle, PINCC26XX_DIO29, PINCC26XX_MUX_RFC_GPO0);
                    PINCC26XX_setMux(ledPinHandle, PINCC26XX_DIO30, PINCC26XX_MUX_RFC_GPO1);
                    /* Send packet */
                    RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL, 0);
                    Clock_stop(clk1Handle);
                    //SPI_close(slaveSpi);
    
                    PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, 0);
    
                    //MCU Reset
                    //SysCtrlSystemReset();
    
    
                    break;
                default:
                    /* Unhandled status */
                    break;
            };
        }
    }
    
    
    void clk2Fxn ( UArg arg0 ){
    
        counterGln++;
    }
    
    /* Calculates datarate from prescaler and rate word */
    static uint32_t calculateSymbolRate(uint8_t prescaler, uint32_t rateWord)
    {
        /* Calculate datarate according to TRM Section 23.7.5.2:
         * f_baudrate = (R * f_ref)/(p * 2^20)
         *   - R = rateWord
         *   - f_ref = 24Mhz
         *   - p = prescaler */
        uint64_t numerator = rateWord*24000000ULL;
        uint64_t denominator = prescaler*1048576ULL;
        uint32_t result = (uint32_t)(numerator/denominator);
        return result;
    }
    
    /* Copies all RX options from the SmartRF Studio exported RX command to the RX Sniff command */
    static void initializeSniffCmdFromRxCmd(rfc_CMD_PROP_RX_SNIFF_t* rxSniffCmd, rfc_CMD_PROP_RX_t* rxCmd)
    {
    
        /* Copy RX configuration from RX command */
        memcpy(rxSniffCmd, rxCmd, sizeof(rfc_CMD_PROP_RX_t));
    
        /* Change to RX_SNIFF command from RX command */
        rxSniffCmd->commandNo = CMD_PROP_RX_SNIFF;
    }
    
    /* Configures Sniff-mode part of the RX_SNIFF command based on mode, datarate and wakeup interval */
    static void configureSniffCmd(rfc_CMD_PROP_RX_SNIFF_t* rxSniffCmd, enum CarrierSenseMode mode, uint32_t datarate, uint8_t wakeupPerSecond)
    {
        /* Enable or disable RSSI */
        if ((mode == CarrierSenseMode_RSSI) || (mode == CarrierSenseMode_RSSIandPQT)) {
            rxSniffCmd->csConf.bEnaRssi        = 1;
        } else {
            rxSniffCmd->csConf.bEnaRssi        = 0;
        }
    
        /* Enable or disable PQT */
        if ((mode == CarrierSenseMode_PQT) || (mode == CarrierSenseMode_RSSIandPQT)) {
            rxSniffCmd->csConf.bEnaCorr        = 1;
            rxSniffCmd->csEndTrigger.triggerType  = TRIG_REL_START;
        } else {
            rxSniffCmd->csConf.bEnaCorr        = 0;
            rxSniffCmd->csEndTrigger.triggerType  = TRIG_NEVER;
        }
    
        /* General Carrier Sense configuration */
        rxSniffCmd->csConf.operation       = 1; /* Report Idle if RSSI reports Idle to quickly exit if not above
                                                     RSSI threshold */
        rxSniffCmd->csConf.busyOp          = 0; /* End carrier sense on channel Busy (the receiver will continue when
                                                     carrier sense ends, but it will then not end if channel goes Idle) */
        rxSniffCmd->csConf.idleOp          = 1; /* End on channel Idle */
        rxSniffCmd->csConf.timeoutRes      = 1; /* If the channel is invalid, it will return PROP_DONE_IDLE_TIMEOUT */
    
        /* RSSI configuration */
        rxSniffCmd->numRssiIdle            = 1; /* One idle RSSI samples signals that the channel is idle */
        rxSniffCmd->numRssiBusy            = 1; /* One busy RSSI samples signals that the channel is busy */
        rxSniffCmd->rssiThr    = (int8_t)WOR_RSSI_THRESHOLD; /* Set the RSSI threshold in dBm */
    
        /* PQT configuration */
        rxSniffCmd->corrConfig.numCorrBusy = 1;   /* One busy PQT samples signals that the channel is busy */
        rxSniffCmd->corrConfig.numCorrInv  = 1;   /* One busy PQT samples signals that the channel is busy */
    
        /* Calculate basic timing parameters */
        uint32_t symbolLengthUs  = 1000000UL/datarate;
        uint32_t preambleSymbols = (1000000UL/wakeupPerSecond)/symbolLengthUs;
    
        uint8_t syncWordSymbols  = RF_cmdPropRadioDivSetup.formatConf.nSwBits;
    
        /* Calculate sniff mode parameters */
        #define US_TO_RAT_TICKS 4
        #define CORR_PERIOD_SYM_MARGIN 16
        #define RX_END_TIME_SYM_MARGIN 8
        #define CS_END_TIME_MIN_TIME_SYM 30
    #if ((WOR_RF_PHY_DATARATE == WOR_RF_PHY_DATARATE_50KBPS)  || \
         (WOR_RF_PHY_DATARATE == WOR_RF_PHY_DATARATE_100KBPS) || \
         (WOR_RF_PHY_DATARATE == WOR_RF_PHY_DATARATE_200KBPS))
        #define CS_END_TIME_MIN_TIME_STATIC_US 150
    #elif ((WOR_RF_PHY_DATARATE == WOR_RF_PHY_DATARATE_300KBPS) || \
           (WOR_RF_PHY_DATARATE == WOR_RF_PHY_DATARATE_400KBPS))
        #define CS_END_TIME_MIN_TIME_STATIC_US 200
    #elif (WOR_RF_PHY_DATARATE == WOR_RF_PHY_DATARATE_500KBPS)
        #define CS_END_TIME_MIN_TIME_STATIC_US 250
    #else
    #error "WOR_RF_PHY_DATARATE is undefined or has an invalid option"
    #endif
    
        /* Represents the time in which we need to receive corrConfig.numCorr* correlation peaks to detect preamble.
         * When continously checking the preamble quality, this period has to be wide enough to also contain the sync
         * word, with a margin. If it is not, then there is a chance the SNIFF command will abort while receiving the
         * sync word, as it no longer detects a preamble. */
        uint32_t correlationPeriodUs = (syncWordSymbols + CORR_PERIOD_SYM_MARGIN)*symbolLengthUs;
    
        /* Represents the time where we will force a check if preamble is present (only done once).
         * The main idea is that his should be shorter than "correlationPeriodUs" so that if we get RSSI valid, but
         * there is not a valid preamble on the air, we will leave RX as quickly as possible. */
        uint32_t csEndTimeUs = (CS_END_TIME_MIN_TIME_SYM*symbolLengthUs + CS_END_TIME_MIN_TIME_STATIC_US);
    
        /* Represents the maximum time from the startTrigger to when we expect a sync word to be received. */
        uint32_t rxEndTimeUs = (preambleSymbols + syncWordSymbols + RX_END_TIME_SYM_MARGIN)*symbolLengthUs;
    
        /* Set sniff mode timing configuration in sniff command in RAT ticks */
        rxSniffCmd->corrPeriod = (uint16_t)(correlationPeriodUs * US_TO_RAT_TICKS);
        rxSniffCmd->csEndTime  = (uint32_t)(csEndTimeUs * US_TO_RAT_TICKS);
        rxSniffCmd->endTime    = (uint32_t)(rxEndTimeUs * US_TO_RAT_TICKS);
    
        /* Set correct trigger types */
        rxSniffCmd->endTrigger.triggerType   = TRIG_REL_START;
        rxSniffCmd->startTrigger.triggerType = TRIG_ABSTIME;
        rxSniffCmd->startTrigger.pastTrig    = 1;
    }
    
    /* Called for every received packet and command done */
    void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
    {
        /* If we've received a new packet and it's available to read out */
        if (e & RF_EventRxEntryDone)
        {
            do
            {
                /* Toggle LED on RX */
                //PIN_setOutputValue(ledPinHandle, Board_PIN_LED1, !PIN_getOutputValue(Board_PIN_LED1));
    
                /* 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 code block is added to avoid a compiler warning.
                * Normally, an application will reference these variables for
                * useful data. */
                dummy = packetLength + packetDataPointer[0];
                memcpy(packet_RX, packetDataPointer, (packetLength + 1));
    
            } while(RFQueue_nextEntry() == DATA_ENTRY_FINISHED);
        }
    }
    
    
    /*
     *  ======== main ========
     */
    int main(void)
    {
        Clock_Params clkParams;
    
        /* Call driver init functions. */
        Board_initGeneral();
        SPI_init();
    
        /* Open LED pins */
        ledPinHandle = PIN_open(&ledPinState, pinTable);
        Assert_isTrue(ledPinHandle != NULL, NULL);
    
        /* Initialize task */
        Task_Params_init(&rxTaskParams);
        rxTaskParams.stackSize = RX_TASK_STACK_SIZE;
        rxTaskParams.priority = RX_TASK_PRIORITY;
        rxTaskParams.stack = &rxTaskStack;
    
        Task_construct(&rxTask, rxTaskFunction, &rxTaskParams, NULL);
    
        /* Timer */
        Clock_Params_init(&clkParams);
        clkParams.period = 100;
        clkParams.startFlag = TRUE;
    
        Clock_construct(&clk1Struct, ( Clock_FuncPtr )clk2Fxn, 50, &clkParams);
        clk1Handle = Clock_handle(&clk1Struct);
    
        Clock_stop(clk1Handle);
    
        /* Start BIOS */
        BIOS_start();
    
        return (0);
    }

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您是否已根据 https://www.ti.com/lit/pdf/swra517?修改 WOR 示例以控制 CC1190

    请从 rfPacketRX 和 rfPActket TX 示例开始、添加控制 PA 和 LNA 所需的代码、并确保您在两个方向上都能获得预期的范围。 一旦确定、您可以采用默认的 WOR 示例并对其进行测试(支持 CC1190)。

    在这种情况下、您可以开始对代码进行修改、以便在 RX 和 RX 之间进行更改。

    BR

    Siri

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您能继续。

    e2e.ti.com/.../3717091

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    是的。 关闭这个