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.

CC2640R2F-Q1: after sending out a data with 12 bytes long, for example, when the data is out from the Tx FiFo, I want to get an interrupt event

Part Number: CC2640R2F-Q1

Hi TI experts,

I would like to know how to get an event when the output data transferring is complete.

For example, after sending out a data with 12 bytes long, when the data is out from the Tx FiFo, I want to get an interrupt event using scifGetAlertEvents().

BR,

Ji Won

  • When I configured the related APIs as below, I can get the status.

    I think that I should monitor and use the BV_SCIF_UART_ALERT_TX_FIFO_BELOW_THR for it. right?

    How to configure if I want to get this BV_SCIF_UART_ALERT_TX_FIFO_BELOW_THR? My below implementation is right?

    /// UART ALERT event: RX FIFO at or above the specified threshold

    #define BV_SCIF_UART_ALERT_RX_FIFO_ABOVE_THR         0x0001
    /// UART ALERT event: RX byte timeout occurred
    #define BV_SCIF_UART_ALERT_RX_BYTE_TIMEOUT           0x0002
    /// UART ALERT event: Break or framing error occurred
    #define BV_SCIF_UART_ALERT_RX_BREAK_OR_FRAMING_ERROR 0x0004
    /// UART ALERT event: TX FIFO at or below the specified threshold
    #define BV_SCIF_UART_ALERT_TX_FIFO_BELOW_THR         0x0008

    void SimpleBLECentral_processScUartEvents(uint16_t events)
    {
      Display_printf(dispHandle, 6, 0, "UART Tx FiFo Threshold events: %x\r\n", events);
      g_trigger_write_callback = FALSE;   // set when Tx output is complete
    }

    void SimpleBLECentrall_scUartEventsHandler(uint16 events)
    {
      SimpleBLECentral_processScUartEvents(events);
    }

    void ScUart_taskFxn(UArg a0, UArg a1) {

        // Initialize the Sensor Controller
        scifOsalInit();

        /*
         * There are two event signals from the Sensor Controller to the MCU domain:
         * . READY indicates that the control interface used to start or stop Sensor Controller tasks is idle and  ready.
         * . ALERT is used by Sensor Controller tasks to wake up the System CPU from standby and exchange data.
         */
        scifOsalRegisterCtrlReadyCallback(scCtrlReadyCallback);
        scifOsalRegisterTaskAlertCallback(scTaskAlertCallback);
        scifInit(&scifDriverSetup);

        // Start the UART emulator
        scifExecuteTasksOnceNbl(BV(SCIF_UART_EMULATOR_TASK_ID));

        // Enable baud rate generation
        scifUartSetBaudRate(19200);

        // Enable RX (10 idle bit periods required before enabling start bit detection)
        scifUartSetRxFifoThr(SCIF_UART_RX_FIFO_MAX_COUNT / 2);
        scifUartSetRxTimeout(10 * 2);
        scifUartSetRxEnableReqIdleCount(10 * 2);
        scifUartSetTxFifoThr(0x02);  // SCIF_UART_TX_FIFO_MAX_COUNT / 2
        scifUartRxEnable(1);

        // Enable events (half full RX FIFO or 10 bit period timeout
        scifUartSetEventMask(BV_SCIF_UART_RX_FRAMING_ERROR | BV_SCIF_UART_ALERT_RX_FIFO_ABOVE_THR | BV_SCIF_UART_ALERT_RX_BYTE_TIMEOUT | BV_SCIF_UART_ALERT_TX_FIFO_BELOW_THR);

        //unsigned char output[] = { "ABCDEFH" };
        //scifUartTxPutChars(output, sizeof(output));
        
        // Main loop
        while (1) {

            // Wait for an ALERT callback
            // Allow application to sleep until receiving the desired number of characters.
            Semaphore_pend(Semaphore_handle(&semScTaskAlert), BIOS_WAIT_FOREVER);

            int uartEvents = scifUartGetEvents();
            SimpleBLECentrall_scUartEventsHandler(uartEvents);        
            
            // Clear the ALERT interrupt source
            scifClearAlertIntSource();        

            // Echo all characters currently in the RX FIFO
            int rxFifoCount = scifUartGetRxFifoCount();

            ....

    }

    BR,

    Ji Won

  • I fount the related example from shared_io.

    void taskFxn(UArg a0, UArg a1) {

        // Initialize UART parameters
        UART_Params_init(&uParams);
        uParams.baudRate      = 57600;
        uParams.writeDataMode = UART_DATA_TEXT;
        uParams.dataLength    = UART_LEN_8;
        uParams.stopBits      = UART_STOP_TWO;

        // Initialize the Sensor Controller
        scifOsalInit();
        scifOsalRegisterCtrlReadyCallback(scCtrlReadyCallback);
        scifOsalRegisterTaskAlertCallback(scTaskAlertCallback);
        scifInit(&scifDriverSetup);

        // Main loop
        int n = 0;
        while (1) {

            // S E N S O R   C O N T R O L L E R

            // Start the UART emulator
            scifResetTaskStructs(BV(SCIF_UART_EMULATOR_TASK_ID), BV(SCIF_STRUCT_CFG));
            scifExecuteTasksOnceNbl(BV(SCIF_UART_EMULATOR_TASK_ID));

            // Enable baud rate generation
            scifUartSetBaudRate(57600);

            // Create and send the message
            sprintf(pLine, "%d: This line was sent using the Sensor Controller UART Emulator task\r\n", n);
            scifUartTxPutChars(pLine, strlen(pLine));

            // Produce ALERT interrupt when the TX FIFO has been emptied
            scifUartSetTxFifoThr(0);
            scifUartSetEventMask(BV_SCIF_UART_ALERT_TX_FIFO_BELOW_THR);

            // Wait for and handle the ALERT callback, which tells us that we're done. We also stop the TX
            // FIFO ALERT interrupt, so it is not generated again (the event is level type and the TX FIFO
            // will still be empty)
            Semaphore_pend(Semaphore_handle(&semScTaskAlert), BIOS_WAIT_FOREVER);
            scifClearAlertIntSource();
            scifAckAlertEvents();
            scifUartSetEventMask(0);
            scifUartClearEvents();

            // Stop the UART emulator
            scifUartStopEmulator();
            scifWaitOnNbl(1000);

            // Stop UART baud rate generation
            scifUartSetBaudRate(0);


            // T I - R T O S   U A R T   D R I V E R   W I T H   U A R T   H A R D W A R E   P E R I P H E R A L

            // Open UART
            // This transfers ownership of the UART I/O pins to the UART hardware peripheral
            uHandle = UART_open(Board_UART, &uParams);

             // Create and send the message
            sprintf(pLine, "%d: This line was sent using the TI-RTOS UART driver with hardware peripheral\r\n", n);
            UART_write(uHandle, pLine, strlen(pLine));

            // Close UART
            UART_close(uHandle);

            // Hand the UART I/O pins back to the Sensor Controller
            scifReinitTaskIo(BV(SCIF_UART_EMULATOR_TASK_ID));

            n++;
        }

    } // taskFxn

  • Hi Ji Won,

    Sounds like you resolved your problem!

    Cheers,
    Fredrik