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.

RTOS/CC2640R2F: how to signal an event from scs task to app task

Part Number: CC2640R2F


Tool/software: TI-RTOS

Hi TI experts,

Successfully, I installed and generated the SCS code for UART emulation.

So, when receiving a data from PC, it sends back to PC.

My question is how to signal the receiving event to APP MCU instead of PC.

My understanding is that scTaskAlertCallback is called to generate the signal by using 'Semaphore_post'.

But, I don't know how to link with an event in APP CPU. I am still not familiar with the signalling.

Should I add or modify something in scTaskAlertCallback() ?

void scTaskAlertCallback(void) {

    // Wake up the OS task
    Semaphore_post(Semaphore_handle(&semScTaskAlert));

} // scTaskAlertCallback

typedef struct
{
  uint8_t  event;  // Sensor Controller events
  uint16_t data;   // UART data
} uartEvt_t;


static void SimpleBLECentral_scUART_enqueueMsg(uint8_t event, uint8_t data)
{
  uartEvt_t *pMsg;

  // Create dynamic pointer to message.
  if (pMsg = ICall_malloc(sizeof(uartEvt_t)))
  {
    pMsg->event = event;
    pMsg->data = data;

    // Enqueue the message.
    Util_enqueueMsg(appMsgQueue, syncEvent, (uint8*)pMsg);
  }
}

void SimpleBLECentrall_scUartTransferHandler(uint8 data)
{
  SimpleBLECentral_scUART_enqueueMsg(SBC_UART_EVT, data);
}

static void SimpleBLECentral_processAppMsg(hbcEvt_t *pMsg)
{

  switch (pMsg->hdr.event)
  {
    case SBC_STATE_CHANGE_EVT:
      SimpleBLECentral_processStackMsg((ICall_Hdr *)pMsg->pData);

      // Free the stack message
      ICall_freeMsg(pMsg->pData);
      break;
   
    case SBC_UART_EVT:
      SimpleBLECentral_processUART( ((uartEvt_t*)pMsg)->data);
      break;
      
    default:
      // Do nothing.
      break;
  }
}

static void SimpleBLECentral_processUART(uint16_t data)
{
  Display_printf(dispHandle, 6, 0, "UART data: %x", data);
}

BR,

Ji Won

  • I modified the echo part in below code to signal an event and data, it seems to be OK, but I am not sure about this.

    Let me know if it is OK.

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

       scifUartRxEnable(1);

       // Enable events (half full RX FIFO or 10 bit period timeout

       scifUartSetEventMask(BV_SCIF_UART_ALERT_RX_FIFO_ABOVE_THR | BV_SCIF_UART_ALERT_RX_BYTE_TIMEOUT);

       char output[] = { "ABCDEFH" };

       scifUartTxPutChars(output, sizeof(output));

       // Main loop

       while (1) {

           // Wait for an ALERT callback

           Semaphore_pend(Semaphore_handle(&semScTaskAlert), BIOS_WAIT_FOREVER);

           // Clear the ALERT interrupt source

           scifClearAlertIntSource();

           // Echo all characters currently in the RX FIFO

           int rxFifoCount = scifUartGetRxFifoCount();

           while (rxFifoCount--) {

               //scifUartTxPutChar((char) scifUartRxGetChar());

               SimpleBLECentrall_scUartTransferHandler((char) scifUartRxGetChar());

           }

           // Clear the events that triggered this

           scifUartClearEvents();

           // Acknowledge the alert event

           scifAckAlertEvents();

       }

    } // ScUart_taskFxn

  • the above approach is good, but not perfect.
    if PC terminal sends some data very fast continually, APP CPU side is getting lost a couple of byte of some data.
    the FAQ of ScS mentions that "APP-CPU can poll on variable in AUX RAM".
    So, APP CPU used the scifUartRxGetChar() to read directly. Instead, SimpleBLECentrall_scUartTransferHandler(rxFifoCount ) is being used to indicate the length to be sent to APP CPU side.

    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);
        scifUartRxEnable(1);

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

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

            // Wait for an ALERT callback
            Semaphore_pend(Semaphore_handle(&semScTaskAlert), BIOS_WAIT_FOREVER);

            // Clear the ALERT interrupt source
            scifClearAlertIntSource();

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

    /*
            while (rxFifoCount--) {
                char rx_data = scifUartRxGetChar();
                //scifUartTxPutChar(rx_data);
                HufBLECentrall_scUartTransferHandler(rx_data);
            }

            // Clear the events that triggered this
            scifUartClearEvents();

            // Acknowledge the alert event
            scifAckAlertEvents();
    */        
        }

    } // ScUart_taskFxn

    static void SimpleBLECentral_processUART(uint8_t length)
    {
      Display_printf(dispHandle, 6, 0, "UART data length: %d", length);
      while (length--) {
          char rx_data = scifUartRxGetChar();
          //scifUartTxPutChar(rx_data);
          Display_printf(dispHandle, 6, 0, "UART data: %x", rx_data);
      }
      // Clear the events that triggered this
      scifUartClearEvents();

      // Acknowledge the alert event
      scifAckAlertEvents();  
    }

    I hope that this is useful for those who want to inteegrate SC UART emulator.

    BR,

    Ji Won

  • Hi Ji Won,

    I'm glad you found an implementation that works for you.