SWRA704 June   2021 CC3120 , CC3130 , CC3135

 

  1.   Trademarks
  2. 1Introduction
  3. 2Porting the Host Driver
    1. 2.1 Porting Layer Files
    2. 2.2 Driver Enable/Disable
    3. 2.3 SPI Interface
      1. 2.3.1 Hardware Setup and Configuring Clocks
    4. 2.4 Memory Management
    5. 2.5 OS Abstraction: FreeRTOS
    6. 2.6 Timestamp Mechanism
    7. 2.7 Asynchronous Event Handler Routines
  4. 3Tips for Porting
    1. 3.1 Hardware Setup
    2. 3.2 Servicepack
    3. 3.3 Starting the Wi-Fi Driver in the Application Code
    4. 3.4 Configuring Clocks on the STM32L4
    5. 3.5 Terminal I/O Printing
    6. 3.6 Location of the Host Driver and Porting Files
    7. 3.7 Updating to the Latest Host Driver Version
  5. 4References
  6. 5License Information

OS Abstraction: FreeRTOS

This application report utilizes FreeRTOS, which is included in the STM32Cube software package. This application does not use the CMSIS abstraction layer.

For guidance on a non-RTOS implementation, see the Porting the Host Driver sections of the SimpleLink Wi-Fi CC3x20, CC3x3x Network Processor User’s Guide.

In user.h, you can see that the names given to the different sl_Sync and sl_Lock objects have a pattern. The APIs that start with "x" or "v" (such as xSemaphoreGive) can be directly defined as FreeRTOS APIs. The other APIs are implemented in cc_pal, since they need some additional parameters or error-checking to be compatible.

user.h:

#define SL_PLATFORM_MULTI_THREADED

#define SL_OS_RET_CODE_OK     ((int)OS_OK)

#define SL_OS_WAIT_FOREVER    ((uint32_t)OS_WAIT_FOREVER)

#define SL_OS_NO_WAIT         ((uint32_t)OS_NO_WAIT)
#define _SlTime_t             uint32_t

#define _SlSyncObj_t          SemaphoreHandle_t
#define sl_SyncObjCreate(pSyncObj,pName)    Semaphore_create(pSyncObj)
#define sl_SyncObjDelete(pSyncObj)    vSemaphoreDelete((SemaphoreHandle_t)*pSyncObj)
#define sl_SyncObjSignal(pSyncObj)    xSemaphoreGive((SemaphoreHandle_t)*pSyncObj)
#define sl_SyncObjSignalFromIRQ(pSyncObj)    Semaphore_SignalFromISR(pSyncObj)
#define sl_SyncObjWait(pSyncObj,Timeout)    Semaphore_pend_handle(pSyncObj,Timeout)
#define sl_SyncObjGetCount(pSyncObj,pValue)    Semaphore_get_count(pSyncObj, pValue);

#define _SlLockObj_t    SemaphoreHandle_t
#define sl_LockObjCreate(pLockObj, pName)    Mutex_create_handle(pLockObj)
#define sl_LockObjDelete(pLockObj)    vSemaphoreDelete((SemaphoreHandle_t)*pLockObj)
#define sl_LockObjLock(pLockObj,Timeout)    Mutex_pend_handle(pLockObj, Timeout)
#define sl_LockObjUnlock(pLockObj)    xSemaphoreGive((SemaphoreHandle_t)*pLockObj)

#define sl_GetThreadID()    xTaskGetCurrentTaskHandle()

cc_pal.h:

#include "FreeRTOS.h"
#include "semphr.h"
#include "time.h"

#define MAX_QUEUE_SIZE       (4)
#define OS_WAIT_FOREVER      (0xFFFFFFFF)
#define OS_NO_WAIT           (0)
#define OS_OK                (0)

#define Semaphore_OK         (0)
#define Semaphore_FAILURE    (-1)
#define	Semaphore_TIMEOUT    (-2)

#define Mutex_OK             (0)
#define Mutex_FAILURE        (-1)
#define	Mutex_TIMEOUT        (-2)

int Semaphore_create(SemaphoreHandle_t* pSemHandle);

int Semaphore_SignalFromISR(SemaphoreHandle_t* pSemHandle);
int Semaphore_pend_handle(SemaphoreHandle_t* pSemHandle,
 uint32_t timeout);
int Semaphore_get_count(SemaphoreHandle_t *semaphore, int *value);
int Mutex_create_handle(SemaphoreHandle_t* pMutexHandle);

int Mutex_pend_handle(SemaphoreHandle_t* pMutexHandle, uint32_t timeout);

cc_pal.c:

/****************************************************************************
* Semaphore_create
****************************************************************************/
int Semaphore_create(SemaphoreHandle_t* pSemHandle)
{
    //Check for NULL
    if(NULL == pSemHandle)
    {
        return Semaphore_FAILURE;
    }

    *pSemHandle = xSemaphoreCreateCounting(SEM_VALUE_MAX, 0);

    if(*pSemHandle != NULL)
    {
        return Semaphore_OK; 
    }
    else
    {
        return Semaphore_FAILURE;
    }
}

/****************************************************************************
* Semaphore_SignalFromISR
****************************************************************************/
int Semaphore_SignalFromISR(SemaphoreHandle_t* pSemHandle)
{
    portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

    if(pdTRUE == xSemaphoreGiveFromISR((SemaphoreHandle_t)*pSemHandle, &xHigherPriorityTaskWoken))
    {
        if(xHigherPriorityTaskWoken )
        {
            taskYIELD ();
	}
        return Semaphore_OK;
    }
    else
    {

        return Semaphore_OK;
    }
}

/****************************************************************************
* Semaphore_pend_handle
****************************************************************************/
int Semaphore_pend_handle(SemaphoreHandle_t* pSemHandle,
 uint32_t timeout)
{
    if(SL_OS_WAIT_FOREVER == timeout)
    {	
        if (pdTRUE == xSemaphoreTake((SemaphoreHandle_t)*pSemHandle, portMAX_DELAY)) 
        {
            return(Semaphore_OK);
	}
	else 
	{
	    return(Semaphore_FAILURE);
	}
    }
    else
    {
        /* usec to ticks */
	if (pdTRUE == xSemaphoreTake((SemaphoreHandle_t)*pSemHandle, \
            ( TickType_t )timeout/ClockP_getSystemTickPeriod()))
        {
            return(Semaphore_OK);
	}
	else 
	{
	    return(Semaphore_TIMEOUT);
	}
    }
}

/****************************************************************************
* Semaphore_get_count
****************************************************************************/
int Semaphore_get_count(SemaphoreHandle_t *pSemHandle, int *value)
{
    UBaseType_t count;

    count = uxSemaphoreGetCount((SemaphoreHandle_t)*pSemHandle);
    *value = (int)count;
    return 0;
}

/****************************************************************************
* Semaphore_pend_handle
****************************************************************************/
int Mutex_create_handle(SemaphoreHandle_t *pMutexHandle)
{
    *pMutexHandle = xSemaphoreCreateMutex();
	
    if(*pMutexHandle != NULL)
    {  
        return Mutex_OK;
    }
    else
    {
        return Mutex_FAILURE;
    }
}

/****************************************************************************
* Semaphore_pend_handle
****************************************************************************/
int Mutex_pend_handle(SemaphoreHandle_t* pMutexHandle,
 uint32_t timeout)
{
    if(SL_OS_WAIT_FOREVER == timeout)
    {	
        if (pdTRUE == xSemaphoreTake((SemaphoreHandle_t)*pMutexHandle, portMAX_DELAY)) 
	{
            return(Mutex_OK);
	}
	else 
	{
	    return(Mutex_FAILURE);
	}
    }
    else
    {
	  	/* usec to ticks */
		if (pdTRUE == xSemaphoreTake((SemaphoreHandle_t)*pMutexHandle, \
		  	( TickType_t )timeout/ClockP_getSystemTickPeriod())) {
        	return(Mutex_OK);
	  	}
	  	else 
		{
			return(Mutex_FAILURE);
	  	}
    }
}