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.

Radio Example Application with periodic Rf_open() and Rf_close()

Other Parts Discussed in Thread: CC2650

Hi all,


I am using two CC2650+SmartRFBoard with TI-RTOS 2.14.03.28.

One node transmits a radio packet every 2 seconds (radio proprietary mode).

The other node should wait for external events (e.g., button press) and then either (A) enter rx mode to receive the packet or (B) close connection with radio driver and go to power standby mode.

However, after posting event (B) for closing the radio, the task does not receive any further event, and I see no output to the console anymore.

I think I am doing something wrong with the sequence of RF commands.

Could anybody help me and provide a simple example code with proper use of radio API for periodic switch on/off the radio?

This is the code I am using:

void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {

    System_printf("Button pressed.\n");
    System_flush();
  
    CPUdelay(8000*50);
    if (!PIN_getInputValue(pinId)) {
        switch (pinId) {
            case Board_KEY_LEFT:
                Event_post(masterEvent, Event_Id_28);
                break;

            case Board_KEY_RIGHT:
                Event_post(masterEvent, Event_Id_29);
                break;

            default:
                /* Do nothing */
                break;
        }
    }
}



static void rxTaskFunction(UArg arg0, UArg arg1)
{
    RF_Event e;
    RF_Params_init(&rfParams);
    int i;


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

    /* 4.1. Modify CMD_PROP_RX command for application needs */
    RF_cmdPropRx.pQueue = &dataQueue;               /* Set the Data Entity queue for received data */
    RF_cmdPropRx.pOutput = (uint8_t*)&rxStatistics;

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

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

    /* indicate the board is alive */
//    PIN_setOutputValue(pinHandle, Board_LED1, 1);

    System_printf("Start rx task\n");
    System_flush();

    while(1)
    {
        events = Event_pend(myEvent, Event_Id_NONE,
                            Event_Id_00 + Event_Id_01,
                            BIOS_WAIT_FOREVER);


        if (events & Event_Id_00) { /* Rx Mode */
            System_printf("Event_Id_00: Rx mode\n");
            System_flush();

            rx_cmd = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, NULL);
            e = RF_waitCmd(rfHandle, rx_cmd, RF_EventCmdDone);

            if (e == RF_EventCmdDone)
            {
                do {
                    /* Toggle pin to indicate RX */
                    PIN_setOutputValue(pinHandle, Board_LED4,!PIN_getOutputValue(Board_LED4));

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

                    System_printf("rx data: ");
                    System_flush();
                    for (i=0; i < packetLength; i++)
                        System_printf("0x%x ", packetDataPointer[i]);
                    System_printf("\n");
                    System_flush();

                    /* This code block is added to avoid a compiler warning.
                    * Normally, an application will reference these variables for
                    * useful data. */
                    volatile uint8_t dummy;
                    dummy = packetLength;
                    dummy = packetDataPointer[0];

                } while(RFQueue_nextEntry() == DATA_ENTRY_FINISHED);
                Event_post(masterEvent, Event_Id_30);
            }
        }
    }
}


/*
 *  ======== masterEventFxn ========
 *
 */
Void masterEventFxn(UArg arg0, UArg arg1)
{
    while(1){

          events = Event_pend(masterEvent, Event_Id_NONE,
                                Event_Id_30 + Event_Id_29 + Event_Id_28,
                                BIOS_WAIT_FOREVER);


          if (events & Event_Id_29) { /* Radio close */
            System_printf("Event_Id_29\n");
            System_flush();
            RF_abortCmd(rfHandle, rx_cmd); // abort previous rx cmd
            System_printf("aborting cmd...\n");
            System_flush();
            RF_waitCmd(rfHandle, rx_cmd, RF_EventCmdDone);
            System_printf("closing radio...\n");
            System_flush();
            RF_close(rfHandle);
            System_printf("radio closed\n");
            System_flush();
            PIN_setOutputValue(pinHandle, Board_LED4, 0);
        } else if (events & Event_Id_28) { /* Radio open */
            System_printf("Event_Id_28\n");
            System_flush();
            rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdRadioSetup, &rfParams);
            System_printf("radio opened\n");
            System_flush();
            /* Set the frequency */
            rx_cmd = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL);
            System_printf("setting frequency...\n");
            System_flush();
            RF_waitCmd(rfHandle, rx_cmd, RF_EventCmdDone);
            System_printf("radio configured\n");
            System_flush();
            Event_post(myEvent, Event_Id_00);
        } else if (events & Event_Id_30) { /* Rx mode */
            Event_post(myEvent, Event_Id_00);
        }
    }
}

/*
 *  ======== main ========
 */
int main(void)
{
    /* Call board init functions. */
    Board_initGeneral();

    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, pinTable);
    if(!ledPinHandle)
    {
        System_abort("Error initializing board LED pins\n");
    }

    buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
     if(!buttonPinHandle) {
         System_abort("Error initializing button pins\n");
     }

     /* Setup callback for button pins */
     if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
         System_abort("Error registering button callback function");
     }

    Error_init(&eb);

    /* create an Event object. All events are binary */
    myEvent = Event_create(NULL, &eb);
    if (myEvent == NULL) {
        System_abort("Event create failed");
    }
    masterEvent = Event_create(NULL, &eb);
    if (masterEvent == NULL) {
        System_abort("Event create failed");
    }

    /* Clear LED pins */
    PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
    PIN_setOutputValue(ledPinHandle, Board_LED2, 0);
    PIN_setOutputValue(ledPinHandle, Board_LED3, 0);
    PIN_setOutputValue(ledPinHandle, Board_LED4, 0);

#ifdef UART_INTERFACE
    uart_init();
#endif

#ifdef SPI_INTERFACE
    spi_init();
#endif

    /* Initialize task */
    RxTask_init(ledPinHandle);
    MasterTask_init(ledPinHandle);

    /* Start BIOS */
    BIOS_start();

    return (0);
}

Best regards

Pietro