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.

How to generate UART interrupt from SCE

Other Parts Discussed in Thread: CC2560

Hi

I try to add SCE UART usage in SimpleBLEPeripheral code of CC2560, since there is no main_tirtos.c from SCS, so I refer to Analog light sensor code write below code in scif_task.c. But UART interupt can only be triggered at the first time. How can I modify to make it useful everytime? Thank you very much

void taskFxn(UArg a0, UArg a1) {

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

    // Enable power domains
    PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH);
    while (PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON);

    // Enable peripheral clocks
    PRCMPeripheralRunEnable(PRCM_PERIPH_GPIO);
    PRCMLoadSet();
    while (!PRCMLoadGet());

    // Initialize and start the Sensor Controller
    scifInit(&scifDriverSetup);

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

    // Enable baud rate generation
    scifUartSetBaudRate(57600);

    // Enable RX
    scifUartSetRxTimeout(20);
    scifUartSetRxEnableReqIdleCount(1);
    scifUartRxEnable(1);

    // Enable events
    //scifUartSetEventMask(0xF);
    scifUartSetEventMask(BV_SCIF_UART_ALERT_RX_BYTE_TIMEOUT);


    // Main loop
    while (1) {
     
      // Wait for an ALERT callback
        Semaphore_pend(Semaphore_handle(&semScTaskAlert), BIOS_WAIT_FOREVER);       

        // Clear the ALERT interrupt source
        scifClearAlertIntSource();

        while (scifUartGetRxFifoCount()) {
          scifUartTxPutChar((char) scifUartRxGetChar());
        }
    }

} // taskFxn

  • Hello barbara,

    You must set "Operating system" to "TI_RTOS" in the project setting in SCS for it to generate main_tirtos.c. scif_osal_tirtos.c

    After you get the UART alert you should try to call scifUartClearEvents (found in scif.c) before waiting for the next alert.

  • Hi Eirik,

    I tried to set "Operating system" to "TI_RTOS", but get compiling issue "error "Generated SCIF driver supports incorrect operating system. Please change to 'None' in the Sensor Controller Studio project panel and re-generate the driver."

    So I try to write my own main_tirtos.c file reference to light sensor demo and main.c file.

    With scifUartClearEvents it works. Thanks.

    Do you know why I get compiling issue with "TI_RTOS" setting?

    Best Regards,

    Barbara Wu

  • I tried it without getting any errors.
    Which version are you using? The version from WEB?
  • Version is 1.0.1.35847 is this the latest one? What is your version?
  • Maybe you can try to backup and delete your project then re-install SCS and try again.
  • Barbara,

    The UART example is not made for TI RTOS so you must be careful with copying code from it. More specifically, the following code should not be in a TI RTOS project;

       // Enable power domains
    
       PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH);
    
       while (PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON);
    
       // Enable peripheral clocks
    
       PRCMPeripheralRunEnable(PRCM_PERIPH_GPIO);
    
       PRCMLoadSet();
    
       while (!PRCMLoadGet());

    Controlling power domains should be done with the TI RTOS API. To control GPIO's you would run PIN_init() in main and PIN_open instead of the above code.

    In the hardware interrupt callback (taskAlertCallback) you can either post the semaphore or directly read out and clear the events in the ISR such as below:

    void taskAlertCallback(void) 
      {
    
        //Clear the ALERT interrupt source
        scifClearAlertIntSource();
    
        volatile Uint32 events = scifUartGetEvents();
        
        if(events & (BV_SCIF_UART_ALERT_RX_FIFO_ABOVE_THR | BV_SCIF_UART_ALERT_RX_BYTE_TIMEOUT))
        {
          while (scifUartGetRxFifoCount()) 
          {
            appSwRxBuf[appSwRxIdxTail] = scifUartRxGetChar();
            appSwRxIdxTail++;
    
            if (appSwRxIdxTail == APP_UART_RX_BUF_SIZE)
            {
              appSwRxIdxTail = 0;
            }
          }
        }
        
        if(events & BV_SCIF_UART_ALERT_RX_BREAK_OR_FRAMING_ERROR)
        {
          //Error handling
          while (scifUartGetRxFifoCount()) 
          {
            //empty the buffer
            scifUartRxGetChar();
          }
          appSwRxIdxTail = 0;
          appSwRxIdxHead = 0;
    
          SwBrakeDetect = 1;
        }
        
        if(events & BV_SCIF_UART_ALERT_TX_FIFO_BELOW_THR)
        {
          //Refill TX buffer
        }
    
        scifUartClearEvents();
    
        //Acknowledge the alert event
        scifAckAlertEvents();
    
      } // taskAlertCallback

    Regards,

    Svend

  • I thought the error was in studio,
    Svend has nailed down the remaining issue!
  • Hi Eirik, Svend,

    Really appreciate.
    I get my answer for this question. : )

    Best Regards,
    Barbara Wu