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: Can I call RF_postCmd() function in the RF callback (SWI) function?

Part Number: LAUNCHXL-CC1310

I want to senddata continuous by radio, So I type the code below, Is right?

In main() function:

RF_postCmd(rfHandle, (RF_Op*)RF_pCmdTxHS, RF_PriorityNormal, &tx_callback, RF_EventLastCmdDone);

callback function:

static void tx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
{
    if (e & RF_EventLastCmdDone)
    {
        /* For TC_HSM, the packet length and a pointer to the first byte in the payload can be found as follows:
         *
         * uint8_t packetLength      = ((*(uint8_t*)(&currentDataEntry->data + 1)) << 8) | (*(uint8_t*)(&currentDataEntry->data));
         * uint8_t* packetDataPointer = (uint8_t*)(&currentDataEntry->data + 2);
         *
         * For the other test cases (TC_LRM, TC_OOK and TC_FSK), the packet length and first payload byte is found here:
         *
         * uint8_t packetLength      = *(uint8_t*)(&currentDataEntry->data);
         * uint8_t* packetDataPointer = (uint8_t*)(&currentDataEntry->data + 1);
         */
        packetTransfered = true;
    }
}

  • Sorry the callback function paste wrong,

    static void tx_callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
    {
        if (e & RF_EventLastCmdDone)
        {
            /* For TC_HSM, the packet length and a pointer to the first byte in the payload can be found as follows:
             *
             * uint8_t packetLength      = ((*(uint8_t*)(&currentDataEntry->data + 1)) << 8) | (*(uint8_t*)(&currentDataEntry->data));
             * uint8_t* packetDataPointer = (uint8_t*)(&currentDataEntry->data + 2);
             *
             * For the other test cases (TC_LRM, TC_OOK and TC_FSK), the packet length and first payload byte is found here:
             *
             * uint8_t packetLength      = *(uint8_t*)(&currentDataEntry->data);
             * uint8_t* packetDataPointer = (uint8_t*)(&currentDataEntry->data + 1);
             */
            
            RF_postCmd(rfHandle, (RF_Op*)RF_pCmdTxHS, RF_PriorityNormal, &tx_callback, RF_EventLastCmdDone);
            
        }
    }

  • Hi Chunkai,

    The callback function is executed in SWI context, as seen in the source code (RFCC26X2.h):

    All callback functions run in software interrupt (SWI) context. 

    Also, as the source code of RF_postCmd states, you can use RF_postCmd in SWI context.

    /**
     *  @brief  Appends RF operation commands to the driver's command queue and returns a
     *          command handle.
     *
     *  The RF operation \a pOp may either represent a single operation or may be the first
     *  operation in a chain.
     *  If the command queue is empty, the \a pCmd is dispatched immediately. If there are
     *  other operations pending, then \a pCmd is processed after all other commands have been
     *  finished.
     *  The RF operation command must be compatible to the RF_Mode selected by RF_open(), e.g.
     *  proprietary commands can only be used when the RF core is configured for proprietary mode.
     *
     *  The returned command handle is an identifier that can be used to control command execution
     *  later on, for instance with RF_pendCmd() or RF_cancelCmd().
     *  It is a 16 Bit signed integer value, incremented on every new command.
     *  If the RF driver runs out of command containers, RF_ALLOC_ERROR is returned.
     *
     *  The priority \a ePri is only relevant in multi-client applications where commands of distinct
     *  clients may interrupt each other.
     *  Only commands started by RF_scheduleCmd() can preempt
     *  running commands. #RF_postCmd() or RF_runCmd() do never interrupt a running command.
     *  In single-client applications, \a ePri is ignored and should be set to ::RF_PriorityNormal.
     *
     *  A callback function \a pCb might be specified to get notified about events during command
     *  execution. Events are subscribed by the bit mask \a bmEvent.
     *  Valid event flags are specified in @ref RF_Core_Events and @ref RF_Driver_Events.
     *  If no callback is set, RF_pendCmd() can be used to synchronize the current task to command
     *  execution. For this it is necessary to subscribe all relevant events.
     *  The termination events ::RF_EventLastCmdDone, ::RF_EventCmdCancelled, ::RF_EventCmdAborted and
     *  ::RF_EventCmdStopped are always implicitly subscribed.
     *
     *  The following limitations apply to the execution of command chains:
     *
     *  - If TRIG_ABSTIME is used as a start trigger for the first command, TRIG_REL_FIRST_START
     *    can not be used for any other command. This is because the RF driver may insert a
     *    frequency-select command (CMD_FS) at the front of the chain when it performs an
     *    automatic power-up.
     *  - If a command chain has more than one CMD_FS, the first CMD_FS in the chain is cached.
     *    This CMD_FS is used on the next automatic power-up.
     *  - To avoid execution of cached CMD_FS and directly use a new CMD_FS on power up, place CMD_FS
     *    at the head of the command chain.
     *
     *  @note Calling context : Task/SWI

    So you are safe to do so. Here is the actual documentation: https://dev.ti.com/tirex/explore/content/simplelink_cc13x0_sdk_4_20_02_07/docs/tidrivers/doxygen/html/_r_f_8h.html#a2b0ee444fcb74917df94eefea804ecbb

    Regards,

    Arthur

  • Thanks a lot Arthur R.