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.

Opening UART in registered Clock function throws Error

Other Parts Discussed in Thread: CC2650

Hello,

I'm trying to call UART_read() within a callbackFxn registered by Clock_construct(). Calling UART_read() completes the callback function, but then throws a "policySpin" error with the following code:

*
 *  ======== Pulse: registered with Clock_construct() =======
 */
Void Pulse(UArg arg0, UArg arg1)
{
	System_printf("Entering secondPulseFxn.\n");
	// For continuous runs, poll UART for STOP message
	unsigned char alertRx;
	if (continuousRun) {

		UART_read(uart, &alertRx, sizeof(alertRx));
		System_printf("Our alert: %i", alertRx);
}
}

// Somewhere else in code

    UART_Params_init(&uartParams);
    uartParams.readMode = UART_MODE_BLOCKING;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL; // Unblock when buffer is full
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;
    uartParams.readTimeout = 10;
    uart = UART_open(Board_UART0, &uartParams);

If it helps, I'm using:

CCS Version: 6.1.3.00034

MCU: CC2650

TI-RTOS: 2.20

Not quick sure where to start with this one - commenting out UART_read() does not produce hanging of any kid. What's odd is the hanging only occurs after the callback is exited (i.e. I step though the last line of the callback). I've already enabled "BIOS.libType = BIOS.LibType_Debug;" in my .cfg script in an attempt for proper debug symbols to allow me to step through code with no such luck.

Ultimately, I'm trying to poll a UART handle periodically. I have several clock functions that are all time sensitive (micro-second granularity) and am trying to poll uart with the least amount of latency possible. This means avoiding for/while loops or using large receive buffers and this clock function is in charge of polling UART. If possible, I'd like to keep it within a Clock_construct() function as all of the clock functions are chained together. I've already tried closing my previous UART session and opening a UART session within this clock function without calling UART_read(). The same error is produced.

  • Hi Michael,

    I see two problems:

    1. You should not use a blocking call (your UART_read) from a Swi (you clock callback). It might take a long time and block other tasks.
    2. The definition of the function pointer that you pass to clock construct takes only 1 argument Below is the definition of the function pointer that is expected:
    typedef Void (*Clock_FuncPtr)(UArg);

    I would recommend that you use polling from within a task. It will unblock after the "delay" and therefore offer a form of synchronism.

    Alternatively, if you must use the clock to synchonize your tasks, you can use UART_MODE_CALLBACK (refer to documentation for more info). When using the callback mode, read only 1 character at a time. In your callback, you could store the character, and your clock callback would only check if any new characters have arrived.
    Here is the pseudo code:

    yourUARTcallback(....) {
      //fetch and store your character
    
      // Execute another non-blocking read
      UART_read(someTemporaryBuffer, 1);
    }
    
    yourClockCallback(....) {
      if (buffer is not empty(someTemporaryBuffer)) {
        // Execute some action here
      }
    }
    
    main(...) {
      // initialize and open your uart
      // construct your clock and pass the clock callback function
    
      BIOS_start();
    }

    Regards,

    Michel

  • There was a suggested answer and since there has been no active on this thread for more than a week, the suggested answer was marked as verify. Please feel free to select the "Reject Answer" button and reply with more details.