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/LAUNCHXL-CC2650: Simple-central and binary semaphore

Part Number: LAUNCHXL-CC2650
Other Parts Discussed in Thread: CC2650

Tool/software: TI-RTOS

Hi,

I'm trying to developpe my own central application drived by UART connection but I'm facing to a strange issue here.

I implemented my UART with callback on the example uart_echo and used binary semaphore on it. Like that, my callback send a semaphore and my task is running only when it receive this semaphore. I'm joinning you the uartecho.c.

This example with semaphore is working very well, I have to send 16 bytes to have my semaphore and have to send again 16 bytes to have a second semaphore.

I now add the UART to the simple-central example and it's working, I'm able to read and write datas. The issue is coming with the semaphore, I build the exactly same semaphore that I made on my uartecho.c but this time, the task never waits at the ligne  : 

Semaphore_pend(hSemUART, BIOS_WAIT_FOREVER);

I can comment the ligne or not, it's the same result my task is running without any carring of that.

Is it unadvice to use this kind of semaphore on this project ? Can someone confirm the task should wait it ?

Best regards,

John

/*
 * Copyright (c) 2015-2016, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  ======== uartecho.c ========
 */

/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/knl/Semaphore.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>

/* TI-RTOS Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/UART.h>

/* Example/Board Header files */
#include "Board.h"

#include <stdint.h>

#include <ti/drivers/PIN.h>
#include <ti/drivers/pin/PINCC26XX.h>

#define TASKSTACKSIZE     1024 //768

Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];

/* Global memory storage for a PIN_Config table */
static PIN_State ledPinState;
PIN_Handle ledPinHandle;
/*
 * Application LED pin configuration table:
 *   - All LEDs board LEDs are off.
 */
PIN_Config ledPinTable[] = {
    Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    Board_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
    PIN_TERMINATE
};

char tab[16];
Semaphore_Struct semUART;
//static ICall_Semaphore semUART;
Semaphore_Handle hSemUART;
UART_Handle uart;
UART_Params uartParams;
char test;


static void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{


	//UART_write(uart, "CALLBACK\n\r", 10);

	Semaphore_post(hSemUART);
	PIN_setOutputValue(ledPinHandle, Board_LED1, !PINCC26XX_getOutputValue(Board_LED1));
	test=1;

}


/*
 *  ======== echoFxn ========
 *  Task for this function is created statically. See the project's .cfg file.
 */
Void echoFxn(UArg arg0, UArg arg1)
{
   // char input;

    const char echoPrompt[] = "\fEchoing characters:\r\n";

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readMode = UART_MODE_CALLBACK;
   // uartParams.readReturnMode = UART_RETURN_NEWLINE;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;
    uartParams.readCallback=Uart_ReadCallback;
    uart = UART_open(Board_UART0, &uartParams);

    Semaphore_Params sParams;
    Semaphore_Params_init(&sParams);
    sParams.mode = Semaphore_Mode_BINARY;

    Semaphore_construct(&semUART, 0, &sParams);
    hSemUART = Semaphore_handle(&semUART);


    if (uart == NULL) {
        System_abort("Error opening the UART");
    }

    UART_write(uart, echoPrompt, sizeof(echoPrompt));

    /* Loop forever echoing */
    while (1) {

    	if(test==1)
    	{
    		test=0;
    		UART_write(uart, "Callback\n\r",10);
    	}
    //    UART_read(uart, &input, 1);
    	UART_write(uart, "Running!\n\r",10);
    	UART_read(uart, tab, 16);

        Semaphore_pend(hSemUART, BIOS_WAIT_FOREVER);

    //    UART_write(uart, &input, 1);
    }
}

/*
 *  ======== main ========
 */
int main(void)
{

    Task_Params taskParams;

    /* Call board init functions */
    Board_initGeneral();
    Board_initUART();

    /* Construct BIOS objects */
    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)echoFxn, &taskParams, NULL);

    /* Open LED pins */
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    if(!ledPinHandle) {
        System_abort("Error initializing board LED pins\n");
    }

    PIN_setOutputValue(ledPinHandle, Board_LED1, 1);

    /* This example has logging and many other debug capabilities enabled */
    System_printf("This example does not attempt to minimize code or data "
                  "footprint\n");
    System_flush();

    System_printf("Starting the UART Echo example\nSystem provider is set to "
                  "SysMin. Halt the target to view any SysMin contents in "
                  "ROV.\n");
    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    /* Start BIOS */
    BIOS_start();

    return (0);
}
simple_central app.rar

  • Have you tried to use ROV to see if your task is actually getting blocked by the Semaphore_pend()? Also, as an experiment, you can use a try it being counting semaphore and let a run for a bit. If the count value is gradually increasing, that your are probably posting the semaphores faster than what you are consuming with the "pends".
  • Hi Tom Kopriva,

    Thank you about your answer. I tried your experiment but it's not counting.

    I saw there is a priority task issue on what I did, I moved the priority of the UART function from 1 to 4. It caused "internal error" on the UART function as I can see on ROV.

    Anyway, I still have the same issue the semaphore_pend doesn't wait anything. The count isn't increasing and, btw, I removed the semaphore_post of my code but the function is still running. I don't understand in which case the pend cannot work if the semaphore is well initialized.

    In ROV I can see strange things about the UARTtask. I put the debug on pause few times and the task has differents "BlockedOn" status : "internal error", "unknow" "Semaphore: 0x20000026c". But in all case, the task is running.

    Plus, I put a led blinking on my callback and it's working, the callback is working well.

    Can someone confirm this issue ?

    Regards,

    John

  • New data: When I do a semaphore post, the task is "preempted" as I can see in ROV but no other task are running, only the ICall_taskEntry is "Ready" but no task is running.

  • How are you initializing the semaphore? Is it created or constructed? Can you see the state of the Semaphore in ROV as well? (When constructing the Semphore, don't make the Semaphore_Struct static so ROV can see it.) Just to make sure that the Semaphore was properly initialized.
  • Hi Tom,

    Thank you about your answer.

    Yes I'm initializing it well because it's exactly the same code than my uartecho example and it's working very well on it.

    I can see the sempahore on ROV, sometimes it's pending the task, sometimes doing nothing. When it's pending the task, the task is running without caring about the semaphore.

    Regards,

    John

  • John73 said:
    When it's pending the task, the task is running without caring about the semaphore.


    Hi John73,

    Can you explain more detail? It will be easier if you can copy your code to initialize the task and semaphore.

  • Hi Luu,

    Thank you about your answer.

    Here is the code used to initialize the task and the semaphore :

    - Global :

    Semaphore_Struct semUART;
    Semaphore_Params sParams;
    
    Semaphore_Handle hSemUART;
    #define TASK_STACK_SIZE 864
    #define TASK_PRI        4
    void taskUART_create(void)
    {
    	  Task_Params params;
    	  Task_Params_init(&params);
    	  params.priority = TASK_PRI;
    	  params.stackSize = TASK_STACK_SIZE;
    	  params.stack = sbcTaskStack;
    
    	  Task_construct(&sbcTask, taskUART, &params, NULL);
    
    }



    - In the function : taskUART(UArg a0, UArg a1)

    Semaphore_Params_init(&sParams);
    sParams.mode = Semaphore_Mode_BINARY;
    
    Semaphore_construct(&semUART, 0, &sParams);
    hSemUART = Semaphore_handle(&semUART);

    Here is my complete function and the callback function : 

    static void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
    {
    
    	  PIN_setOutputValue(ledPinHandle, Board_LED1, !PINCC26XX_getOutputValue(Board_LED1));
    
    	  Semaphore_post(hSemUART);
    
    }

    void taskUART(UArg a0, UArg a1) {
    
    
    	  Board_initUART();
    	  UART_Params_init(&uartParams);
    
    	  uartParams.writeDataMode = UART_DATA_BINARY;
    	  uartParams.readDataMode = UART_DATA_BINARY;
    	  uartParams.readReturnMode = UART_RETURN_FULL;
    	  uartParams.readMode = UART_MODE_CALLBACK;
    //	  uartParams.writeMode = UART_MODE_BLOCKING;
    //	  uartParams.dataLength = UART_LEN_8;
    	  uartParams.readEcho = UART_ECHO_OFF;
    	  uartParams.baudRate = 115200;
    	  uartParams.readCallback=Uart_ReadCallback;
    
    	  uart = UART_open(Board_UART0, &uartParams);
    
    	  if (uart == NULL) {
    
    	  	  // ERREUR ( LED rouge ? )
    	    }
    
    	    Semaphore_Params_init(&sParams);
    	    sParams.mode = Semaphore_Mode_BINARY;
    
    	    Semaphore_construct(&semUART, 0, &sParams);
    	    hSemUART = Semaphore_handle(&semUART);
    
    	    UART_write(uart,"MiqroMaster ",12);
    	    UART_write(uart,"initialise\n\r",12);
    
    
    	    while(1) {
    
    	    UART_read(uart, rxBuff, BUFSIZE);
    
    	    UART_write(uart, "Running!\n\r",10);
    
    
    	    Semaphore_pend(hSemUART, BIOS_WAIT_FOREVER);
    }
    }

    With this code on the uartecho, I can see "Running!" one time on my UART link and a second time if I send 16 characters to the CC2650 with my computer. But on the simple_central, I'm seeing "Running!" much and much time, same like if I comment the Semaphore_pend.

    Best regards,

    John

  • Hi John73,
    code of uartecho dont have any problem. Do you send the code of your second task?
  • Hi Luu,

    I'm sure to understand what do you mean by "Do you send the code of your second task?". Here is all my code if it's hat you are asking (joined file)

    2117.simple_central.c

    /******************************************************************************
    
     @file  main.c
    
     @brief main entry of the BLE stack sample application.
    
     Group: WCS, BTS
     Target Device: CC2650, CC2640, CC1350
    
     ******************************************************************************
     
     Copyright (c) 2013-2016, Texas Instruments Incorporated
     All rights reserved.
    
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions
     are met:
    
     *  Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
    
     *  Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
    
     *  Neither the name of Texas Instruments Incorporated nor the names of
        its contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.
    
     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
     ******************************************************************************
     Release Name: ble_sdk_2_02_01_18
     Release Date: 2016-10-26 15:20:04
     *****************************************************************************/
     
    /*******************************************************************************
     * INCLUDES
     */
    
    #include <xdc/runtime/Error.h>
    
    #include <ti/drivers/Power.h>
    #include <ti/drivers/power/PowerCC26XX.h>
    #include <ti/sysbios/BIOS.h>
    
    #include "icall.h"
    #include "hal_assert.h"
    #include "central.h"
    #include "simple_central.h"
    
    /* Header files required to enable instruction fetch cache */
    #include <inc/hw_memmap.h>
    #include <driverlib/vims.h>
    
    #ifndef USE_DEFAULT_USER_CFG
    
    #include "ble_user_config.h"
    
    // BLE user defined configuration
    bleUserCfg_t user0Cfg = BLE_USER_CFG;
    
    #endif // USE_DEFAULT_USER_CFG
    
    #include <ti/mw/display/Display.h>
    
    #ifdef USE_FPGA
    #include <inc/hw_prcm.h>
    #endif // USE_FPGA
    
    /*******************************************************************************
     * MACROS
     */
    
    /*******************************************************************************
     * CONSTANTS
     */
    
    #if defined( USE_FPGA )
      #define RFC_MODE_BLE                 PRCM_RFCMODESEL_CURR_MODE1
      #define RFC_MODE_ANT                 PRCM_RFCMODESEL_CURR_MODE4
      #define RFC_MODE_EVERYTHING_BUT_ANT  PRCM_RFCMODESEL_CURR_MODE5
      #define RFC_MODE_EVERYTHING          PRCM_RFCMODESEL_CURR_MODE6
      //
      #define SET_RFC_BLE_MODE(mode) HWREG( PRCM_BASE + PRCM_O_RFCMODESEL ) = (mode)
    #endif // USE_FPGA
    
    /*******************************************************************************
     * TYPEDEFS
     */
    
    /*******************************************************************************
     * LOCAL VARIABLES
     */
    
    /*******************************************************************************
     * GLOBAL VARIABLES
     */
    
    /*******************************************************************************
     * EXTERNS
     */
    
    extern void AssertHandler(uint8 assertCause, uint8 assertSubcause);
    
    extern Display_Handle dispHandle;
    
    /*******************************************************************************
     * @fn          Main
     *
     * @brief       Application Main
     *
     * input parameters
     *
     * @param       None.
     *
     * output parameters
     *
     * @param       None.
     *
     * @return      None.
     */
    int main()
    {
    #if defined( USE_FPGA )
      HWREG(PRCM_BASE + PRCM_O_PDCTL0) &= ~PRCM_PDCTL0_RFC_ON;
      HWREG(PRCM_BASE + PRCM_O_PDCTL1) &= ~PRCM_PDCTL1_RFC_ON;
    #endif // USE_FPGA
      
      /* Register Application callback to trap asserts raised in the Stack */
      RegisterAssertCback(AssertHandler);
    
      PIN_init(BoardGpioInitTable);
    
    #if defined( USE_FPGA )
      // set RFC mode to support BLE
      // Note: This must be done before the RF Core is released from reset!
      SET_RFC_BLE_MODE(RFC_MODE_BLE);
    #endif // USE_FPGA
    
      // Enable iCache prefetching
      VIMSConfigure(VIMS_BASE, TRUE, TRUE);
    
      // Enable cache
      VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
    
    #if !defined( POWER_SAVING ) || defined( USE_FPGA )
      /* Set constraints for Standby, powerdown and idle mode */
      // PowerCC26XX_SB_DISALLOW may be redundant
      Power_setConstraint(PowerCC26XX_SB_DISALLOW);
      Power_setConstraint(PowerCC26XX_IDLE_PD_DISALLOW);
    #endif // POWER_SAVING | USE_FPGA
    
      /* Initialize ICall module */
      ICall_init();
    
      /* Start tasks of external images - Priority 5 */
      ICall_createRemoteTasks();
    
      /* Kick off profile - Priority 3 */
      GAPCentralRole_createTask();
    
      Eteind_LED();
    
       /* Kick off application - Priority 1 */
      SimpleBLECentral_createTask();
    
      taskUART_create();
    
      /* enable interrupts and start SYS/BIOS */
      BIOS_start();
    
      return 0;
    }
    
    
    /*******************************************************************************
     * @fn          AssertHandler
     *
     * @brief       This is the Application's callback handler for asserts raised
     *              in the stack.  When EXT_HAL_ASSERT is defined in the Stack
     *              project this function will be called when an assert is raised, 
     *              and can be used to observe or trap a violation from expected 
     *              behavior.       
     *              
     *              As an example, for Heap allocation failures the Stack will raise 
     *              HAL_ASSERT_CAUSE_OUT_OF_MEMORY as the assertCause and 
     *              HAL_ASSERT_SUBCAUSE_NONE as the assertSubcause.  An application
     *              developer could trap any malloc failure on the stack by calling
     *              HAL_ASSERT_SPINLOCK under the matching case.
     *
     *              An application developer is encouraged to extend this function
     *              for use by their own application.  To do this, add hal_assert.c
     *              to your project workspace, the path to hal_assert.h (this can 
     *              be found on the stack side). Asserts are raised by including
     *              hal_assert.h and using macro HAL_ASSERT(cause) to raise an 
     *              assert with argument assertCause.  the assertSubcause may be
     *              optionally set by macro HAL_ASSERT_SET_SUBCAUSE(subCause) prior
     *              to asserting the cause it describes. More information is
     *              available in hal_assert.h.
     *
     * input parameters
     *
     * @param       assertCause    - Assert cause as defined in hal_assert.h.
     * @param       assertSubcause - Optional assert subcause (see hal_assert.h).
     *
     * output parameters
     *
     * @param       None.
     *
     * @return      None.
     */
    void AssertHandler(uint8 assertCause, uint8 assertSubcause)
    {
      // Open the display if the app has not already done so
      if ( !dispHandle )
      {
        dispHandle = Display_open(Display_Type_LCD, NULL);
      }
    
      Display_print0(dispHandle, 0, 0, ">>>STACK ASSERT");
    
      // check the assert cause
      switch (assertCause)
      {
        case HAL_ASSERT_CAUSE_OUT_OF_MEMORY:
          Display_print0(dispHandle, 0, 0, "***ERROR***");
          Display_print0(dispHandle, 2, 0, ">> OUT OF MEMORY!");
          break;
    
        case HAL_ASSERT_CAUSE_INTERNAL_ERROR:
          // check the subcause
          if (assertSubcause == HAL_ASSERT_SUBCAUSE_FW_INERNAL_ERROR)
          {
            Display_print0(dispHandle, 0, 0, "***ERROR***");
            Display_print0(dispHandle, 2, 0, ">> INTERNAL FW ERROR!");
          }
          else
          {
            Display_print0(dispHandle, 0, 0, "***ERROR***");
            Display_print0(dispHandle, 2, 0, ">> INTERNAL ERROR!");
          }
          break;
    
        case HAL_ASSERT_CAUSE_ICALL_ABORT:
          Display_print0(dispHandle, 0, 0, "***ERROR***");
          Display_print0(dispHandle, 2, 0, ">> ICALL ABORT!");
          HAL_ASSERT_SPINLOCK;
          break;
    
        default:
          Display_print0(dispHandle, 0, 0, "***ERROR***");
          Display_print0(dispHandle, 2, 0, ">> DEFAULT SPINLOCK!");
          HAL_ASSERT_SPINLOCK;
      }
    
      return;
    }
    
    
    /*******************************************************************************
     * @fn          smallErrorHook
     *
     * @brief       Error handler to be hooked into TI-RTOS.
     *
     * input parameters
     *
     * @param       eb - Pointer to Error Block.
     *
     * output parameters
     *
     * @param       None.
     *
     * @return      None.
     */
    void smallErrorHook(Error_Block *eb)
    {
      for (;;);
    }
    
    
    /*******************************************************************************
     */
    

    simple_central.h

  • Hi John73,
    You cannot use the same sbcTask for  Task_construct(&sbcTask, taskUART, &params, NULL); and Task_construct(&sbcTask, SimpleBLECentral_taskFxn, &taskParams, NULL);
    They are two tasks. So you need two pointer to store the information of each task.

    Besides, You should separate it. You can see the sensortag example to see how the multi-tasks work. This is my code for the uart task. The FIOT_UART_CreateTask function will be called in the main function.

    void FIOT_UART_Serial_Rx_Cb(UART_Handle iHandle, void *oData, size_t count)
    {  
      //!***********************************************
      //!Copy UART_Rx_Buf to UART_Tx_Buf
      //!***********************************************    
    
      //!***********************************************
      //!Wake task to process
      //!***********************************************        
      Semaphore_post(UART_hSem);
    } 
    /********************************************************************************
     * FUNCTIONS - TASK
     ********************************************************************************/
    /*!
     ********************************************************************************
     * @fn      void FIOT_UART_CreateTask(void)
     * 
     * @brief   Task creation function for the protocol
     * 
     * @param   None
     * 
     * @return  None
     *
     ********************************************************************************/ 
    void FIOT_UART_CreateTask(void)
    {
      Task_Params TaskParams;
      //!***********************************************
      //!Configure task
      //!***********************************************    
      Task_Params_init(&TaskParams);
      TaskParams.stack          = UART_TaskStack;
      TaskParams.stackSize  = UART_TASK_STACK_SIZE;
      TaskParams.priority   = UART_TASK_PRIORITY;
    
      Task_construct(&UART_TaskStruct, FIOT_UART_TaskFxn, &TaskParams, NULL);
    }
    /*!
     ********************************************************************************
     * @fn      void FIOT_UART_InitTask(void)
     * 
     * @brief   Initilize UART layer
     * 
     * @param   None
     * 
     * @return  None
     *
     ********************************************************************************/
    void FIOT_UART_InitTask(void)
    {
      //!***********************************************
      //!Initilize UART
      //!***********************************************
      UART_Params uParams;
        
      UART_Params_init(&uParams);
      
      uParams.writeDataMode  = UART_DATA_BINARY;
      uParams.readDataMode   = UART_DATA_BINARY;
      uParams.readReturnMode = UART_RETURN_FULL;
      uParams.readMode       = UART_MODE_CALLBACK;
      uParams.readCallback   = FIOT_UART_Serial_Rx_Cb;
    
      UART_uHandle = UART_open(Board_UART,&uParams);    
      //!***********************************************
      //!Initilize Semaphore
      //!***********************************************    
      Semaphore_Params sParams;
      Semaphore_Params_init(&sParams);
      sParams.mode = Semaphore_Mode_BINARY;
    
      Semaphore_construct(&UART_sSem, 0, &sParams);
      UART_hSem = Semaphore_handle(&UART_sSem); 
    }
    /*!
     ********************************************************************************
     * @fn      void FIOT_UART_TaskFxn(UArg a0, UArg a1)
     * 
     * @brief   Application task entry point for the protocol.
     * 
     * @param   a0, a1 - not used.
     * 
     * @return  None
     *
     ********************************************************************************/
    void FIOT_UART_TaskFxn(UArg a0, UArg a1)
    {               
      //!***********************************************
      //!Initilize uart layer
      //!***********************************************    
      FIOT_UART_InitTask();
      //!***********************************************
      //!Loop of uart layer
      //!***********************************************        
      for (;;)
      {
        //!***********************************************
        //!Refesh to read new Data
        //!***********************************************    
        UART_read(UART_uHandle, &UART_Rx, 1);
    
        Semaphore_pend(UART_hSem, BIOS_WAIT_FOREVER);
        //!***********************************************
        //!Process Data
        //!***********************************************  
      }
    }

  • Hi Luu Vy,

    Thank you so much for your answers and your help. It solved my issue !
    I will try your way to manage my UART connection, it seems the best way indeed.

    Best regards,
    John
  • Hi John73,
    Ok. Nice to help you ^^