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.

BOOSTXL-CC3135: Porting query : iMX RT1052 FreeRTOS

Part Number: BOOSTXL-CC3135
Other Parts Discussed in Thread: CC3135

Hi,

We am trying to port Host driver for NXP-iMX RT1052 with FreeRTOS.

Is there any porting example for OS Adaptation layer for FreeRTOS?

I particularly have questions regarding #define sl_SyncObjCreate(pSyncObj,pName).

As per my current implementation,

user.h:-------------

#define _SlSyncObj_t     SemaphoreHandle_t

#define sl_SyncObjCreate(pSyncObj,pName)    sem_init_fo(pSyncObj, 0, 0)

cc_pal.c:---------

int sem_init_fo(SemaphoreHandle_t *sem, int pshared, unsigned value)
{
   SemaphoreHandle_t sem_hndl;

    sem_hndl = xSemaphoreCreateCounting((UBaseType_t)65536,(UBaseType_t)value);
    sem = &sem_hndl;

   if(NULL == sem_hndl)
   {
       return -1;
   }
   else
  {
      return 0;
  }

}

Could you provide suggestion on this implementation?

Regards,

Aniket.

  • Hi Aniket,

    For an example of porting the CC3135 host driver to FreeRTOS, I suggest you take a look at the FreeRTOS port in the SimpleLink SDK Wi-Fi plugin:https://www.ti.com/tool/download/SIMPLELINK-SDK-WIFI-PLUGIN

    This plugin has a port of the host driver to the MSP432 platforms, and supports FreeRTOS in addition to TIRTOS. This support is done through a POSIX layer that is implemented in the MSP432 SDK: https://www.ti.com/tool/download/SIMPLELINK-MSP432-SDK

    Regards,
    Michael

  • Hi Michael,

    We are already referring both the plugins that you have suggested.

    But the FreeRTOS is supported through POSIX. In our case we do not use POSIX.

    We have implemented all the functions for OS Adaptaion layer, but have doubt regarding our implementation of sl_SyncObjCreate.

    Could you provide suggestions regarding the sl_SyncObjCreate code implemetation ?

    Regards,

    Aniket.

  • Hi Michael,

    Is there any update regarding sl_SyncObjCreate code implemetation in plain freeRTOS?

    Regards,

    Aniket.

  • Hi Aniket,

    For the POSIX functions, the SimpleLink SDKs should have a porting file that translate a given POSIX call to plain freeRTOS. For example, the sem_init() function that is used within the host driver port provided in the SmipleLink Wi-Fi plugin is defined like so:

    int sem_init(sem_t *semaphore, int pshared, unsigned value)
    {
        sem_obj *obj = (sem_obj*)(&semaphore->freertos);
    
        /* TODO object size validation */
    //  assert(sizeof(sem_obj) <= sizeof(sem_t));
    
        if (value > SEM_VALUE_MAX) {
            errno = EINVAL;
            return (-1);
        }
    
        /*  FreeRTOS xSemaphoreCreateCounting() creates a queue of
         *  length maxCount, where maxCount is the maximum count that
         *  the semaphore should ever reach.  It looks like this should be
         *  ok since the item length for a semaphore queue is 0, so the
         *  memory allocated is not dependent on maxCount.
         */
        obj->sem = xSemaphoreCreateCounting((UBaseType_t)SEM_VALUE_MAX,
                (UBaseType_t)value);
    
        if (obj->sem == NULL) {
            errno = ENOSPC;
            return (-1);
        }
    
        return (0);
    }
    

    The full implementations of all POSIX to FreeRTOS functions can be found in /source/ti/posix/freertos/ of the MSP432 SDK.

    Alternatively, you can look at the implementations of the source driver functions from the DPL. In user.h an alternative for sl_SyncObjCreate() is SemaphoreP_create_handle(). It is defined in plain FreeRTOS in kernel/freertos/dpl/SemaphoeP_freertos.c:

    /*
     *  ======== SemaphoreP_construct ========
     */
    SemaphoreP_Handle SemaphoreP_construct(SemaphoreP_Struct *handle,
        unsigned int count, SemaphoreP_Params *params)
    {
        SemaphoreHandle_t sem = NULL;
    
    #if (configSUPPORT_STATIC_ALLOCATION == 1)
        SemaphoreP_Params semParams;
        if (params == NULL) {
            params = &semParams;
            SemaphoreP_Params_init(params);
        }
    
        if (params->mode == SemaphoreP_Mode_COUNTING) {
    #if (configUSE_COUNTING_SEMAPHORES == 1)
            /*
             *  The size of the semaphore queue is not dependent on MAXCOUNT.
             *
             *  FreeRTOS xSemaphoreCreateCounting() appears from the
             *  code in xQueueCreateCountingSemaphore() to create
             *  a queue of length maxCount, where maxCount is the
             *  maximum count that the semaphore should ever reach.
             *  However, the queue item size (queueSEMAPHORE_QUEUE_ITEM_LENGTH),
             *  is 0, so no actual memoory is allocated for the queue items.
             *  Therefore we can pass any non-zero number as the maximum
             *  semaphore count.
             */
            sem = xSemaphoreCreateCountingStatic((UBaseType_t)MAXCOUNT,
                    (UBaseType_t)count, (StaticSemaphore_t *)handle);
    #endif
        }
        else {
            sem = xSemaphoreCreateBinaryStatic((StaticSemaphore_t *)handle);
            if ((sem != NULL) && (count != 0)) {
                xSemaphoreGive(sem);
            }
        }
    #endif
    
        return ((SemaphoreP_Handle)sem);
    }

    I suggest you look at the POSIX to FreeRTOS abstraction layer porting files in the MSP432 SDK for more porting details.

    Regards,

    Michael

  • Hi Michael,

    Thanks for reply. 

    I noticed that SemaphoreP_create_handle() is used as alternative when SL_PLATFORM_MULTI_THREADED is NOT defined.

    While using FreeRTOS on iMX RT1052, what is your recommendation regarding SL_PLATFORM_MULTI_THREADED ? should it be defined or not.

    Regards,

    Aniket.

  • Hi Aniket,

    SL_PLATFORM_MULTI_THREADED should be defined if you are using FreeRTOS.

    Regards,

    Michael

  • Michael,

    Thanks for your reply,

    Regards,

    Aniket.