summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authordanicampora <danicampora@gmail.com>2015-02-26 10:54:55 +0100
committerdanicampora <danicampora@gmail.com>2015-02-26 11:18:18 +0100
commit5330d8996f3e64447b48ffe2824f7911337b0d07 (patch)
tree8d0e947460f2b80f6a6ee6ad1f720accd81c172a
parentf3661d4100299a136bc33cfccc7b2cade0d7da21 (diff)
downloadmicropython-5330d8996f3e64447b48ffe2824f7911337b0d07.tar.gz
micropython-5330d8996f3e64447b48ffe2824f7911337b0d07.zip
cc3200: Modify simplelink FreeRTOS OSI layer to only use semaphores.
Before, both mutexes and semaphores were used. Using only the latter and with a bit of cleanup to remove some code bloat, we save ~600 bytes of code.
-rw-r--r--cc3200/FreeRTOS/FreeRTOSConfig.h2
-rw-r--r--cc3200/fatfs/src/option/syscall.c2
-rw-r--r--cc3200/simplelink/oslib/osi.h6
-rw-r--r--cc3200/simplelink/oslib/osi_freertos.c167
4 files changed, 37 insertions, 140 deletions
diff --git a/cc3200/FreeRTOS/FreeRTOSConfig.h b/cc3200/FreeRTOS/FreeRTOSConfig.h
index 0298031ca4..e831b10345 100644
--- a/cc3200/FreeRTOS/FreeRTOSConfig.h
+++ b/cc3200/FreeRTOS/FreeRTOSConfig.h
@@ -90,7 +90,7 @@
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_CO_ROUTINES 0
-#define configUSE_MUTEXES 1
+#define configUSE_MUTEXES 0
#define configUSE_RECURSIVE_MUTEXES 0
#ifdef DEBUG
#define configCHECK_FOR_STACK_OVERFLOW 1
diff --git a/cc3200/fatfs/src/option/syscall.c b/cc3200/fatfs/src/option/syscall.c
index 622022b82d..1bb1ec3798 100644
--- a/cc3200/fatfs/src/option/syscall.c
+++ b/cc3200/fatfs/src/option/syscall.c
@@ -34,7 +34,7 @@ int ff_cre_syncobj ( /* !=0:Function succeeded, ==0:Could not create due to any
// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
// ret = (int)(err == OS_NO_ERR);
- *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
+ vSemaphoreCreateBinary( (*sobj) ); /* FreeRTOS */
ret = (int)(*sobj != NULL);
return ret;
diff --git a/cc3200/simplelink/oslib/osi.h b/cc3200/simplelink/oslib/osi.h
index 637f92eee4..cf2574b1ec 100644
--- a/cc3200/simplelink/oslib/osi.h
+++ b/cc3200/simplelink/oslib/osi.h
@@ -261,7 +261,7 @@ OsiReturnVal_e osi_LockObjCreate(OsiLockObj_t* pLockObj);
\note
\warning
*/
-OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj);
+#define osi_LockObjDelete osi_SyncObjDelete
/*!
\brief This function locks a locking object.
@@ -282,7 +282,7 @@ OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj);
\note
\warning
*/
-OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout);
+#define osi_LockObjLock osi_SyncObjWait
/*!
\brief This function unlock a locking object.
@@ -294,7 +294,7 @@ OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout);
\note
\warning
*/
-OsiReturnVal_e osi_LockObjUnlock(OsiLockObj_t* pLockObj);
+#define osi_LockObjUnlock osi_SyncObjSignal
/*!
diff --git a/cc3200/simplelink/oslib/osi_freertos.c b/cc3200/simplelink/oslib/osi_freertos.c
index 93b5bb4396..8ed75a1302 100644
--- a/cc3200/simplelink/oslib/osi_freertos.c
+++ b/cc3200/simplelink/oslib/osi_freertos.c
@@ -51,6 +51,7 @@
#include "inc/hw_types.h"
#include "interrupt.h"
#include "pybwdt.h"
+#include "debug.h"
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
//Local function definition
@@ -117,23 +118,13 @@ void osi_InterruptDeRegister(int iIntrNum)
*/
OsiReturnVal_e osi_SyncObjCreate(OsiSyncObj_t* pSyncObj)
{
- //Check for NULL
- if(NULL == pSyncObj)
- {
- return OSI_INVALID_PARAMS;
- }
SemaphoreHandle_t *pl_SyncObj = (SemaphoreHandle_t *)pSyncObj;
*pl_SyncObj = xSemaphoreCreateBinary();
- if((SemaphoreHandle_t)(*pSyncObj) != NULL)
- {
- return OSI_OK;
- }
- else
- {
- return OSI_OPERATION_FAILED;
- }
+ ASSERT (*pSyncObj != NULL);
+
+ return OSI_OK;
}
/*!
@@ -148,11 +139,6 @@ OsiReturnVal_e osi_SyncObjCreate(OsiSyncObj_t* pSyncObj)
*/
OsiReturnVal_e osi_SyncObjDelete(OsiSyncObj_t* pSyncObj)
{
- //Check for NULL
- if(NULL == pSyncObj)
- {
- return OSI_INVALID_PARAMS;
- }
vSemaphoreDelete(*pSyncObj );
return OSI_OK;
}
@@ -171,14 +157,7 @@ OsiReturnVal_e osi_SyncObjDelete(OsiSyncObj_t* pSyncObj)
*/
OsiReturnVal_e osi_SyncObjSignal(OsiSyncObj_t* pSyncObj)
{
- //Check for NULL
- if(NULL == pSyncObj)
- {
- return OSI_INVALID_PARAMS;
- }
-
xSemaphoreGive( *pSyncObj );
-
return OSI_OK;
}
/*!
@@ -196,11 +175,6 @@ OsiReturnVal_e osi_SyncObjSignal(OsiSyncObj_t* pSyncObj)
*/
OsiReturnVal_e osi_SyncObjSignalFromISR(OsiSyncObj_t* pSyncObj)
{
- //Check for NULL
- if(NULL == pSyncObj)
- {
- return OSI_INVALID_PARAMS;
- }
xHigherPriorityTaskWoken = pdFALSE;
if(pdTRUE == xSemaphoreGiveFromISR( *pSyncObj, &xHigherPriorityTaskWoken ))
{
@@ -208,14 +182,8 @@ OsiReturnVal_e osi_SyncObjSignalFromISR(OsiSyncObj_t* pSyncObj)
{
taskYIELD ();
}
- return OSI_OK;
- }
- else
- {
- //In case of Semaphore, you are expected to get this if multiple sem
- // give is called before sem take
- return OSI_OK;
}
+ return OSI_OK;
}
/*!
@@ -235,12 +203,7 @@ OsiReturnVal_e osi_SyncObjSignalFromISR(OsiSyncObj_t* pSyncObj)
*/
OsiReturnVal_e osi_SyncObjWait(OsiSyncObj_t* pSyncObj , OsiTime_t Timeout)
{
- //Check for NULL
- if(NULL == pSyncObj)
- {
- return OSI_INVALID_PARAMS;
- }
- if(pdTRUE == xSemaphoreTake( (SemaphoreHandle_t)*pSyncObj, ( TickType_t )(Timeout/portTICK_PERIOD_MS) ))
+ if(pdTRUE == xSemaphoreTake( (SemaphoreHandle_t)*pSyncObj, ( TickType_t )Timeout))
{
return OSI_OK;
}
@@ -262,12 +225,6 @@ OsiReturnVal_e osi_SyncObjWait(OsiSyncObj_t* pSyncObj , OsiTime_t Timeout)
*/
OsiReturnVal_e osi_SyncObjClear(OsiSyncObj_t* pSyncObj)
{
- //Check for NULL
- if(NULL == pSyncObj)
- {
- return OSI_INVALID_PARAMS;
- }
-
if (OSI_OK == osi_SyncObjWait(pSyncObj,0) )
{
return OSI_OK;
@@ -293,20 +250,13 @@ OsiReturnVal_e osi_SyncObjClear(OsiSyncObj_t* pSyncObj)
*/
OsiReturnVal_e osi_LockObjCreate(OsiLockObj_t* pLockObj)
{
- //Check for NULL
- if(NULL == pLockObj)
- {
- return OSI_INVALID_PARAMS;
- }
- *pLockObj = (OsiLockObj_t)xSemaphoreCreateMutex();
- if(pLockObj != NULL)
- {
- return OSI_OK;
- }
- else
- {
- return OSI_OPERATION_FAILED;
- }
+ SemaphoreHandle_t *pl_LockObj = (SemaphoreHandle_t *)pLockObj;
+
+ vSemaphoreCreateBinary(*pl_LockObj);
+
+ ASSERT (*pLockObj != NULL);
+
+ return OSI_OK;
}
/*!
@@ -329,15 +279,11 @@ OsiReturnVal_e osi_TaskCreate(P_OSI_TASK_ENTRY pEntry,const signed char * const
unsigned short usStackDepth, void *pvParameters,
unsigned long uxPriority,OsiTaskHandle* pTaskHandle)
{
- if(pdPASS == xTaskCreate( pEntry, (char const*)pcName,
+ ASSERT (pdPASS == xTaskCreate( pEntry, (char const*)pcName,
(usStackDepth/(sizeof( portSTACK_TYPE ))),
pvParameters,(unsigned portBASE_TYPE)uxPriority,
- (TaskHandle_t*)pTaskHandle ))
- {
- return OSI_OK;
- }
-
- return OSI_OPERATION_FAILED;
+ (TaskHandle_t*)pTaskHandle ));
+ return OSI_OK;
}
@@ -368,7 +314,7 @@ void osi_TaskDelete(OsiTaskHandle* pTaskHandle)
\note
\warning
*/
-OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj)
+OsiReturnVal_e _osi_LockObjDelete(OsiLockObj_t* pLockObj)
{
vSemaphoreDelete((SemaphoreHandle_t)*pLockObj );
return OSI_OK;
@@ -393,15 +339,10 @@ OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj)
\note
\warning
*/
-OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout)
+OsiReturnVal_e _osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout)
{
- //Check for NULL
- if(NULL == pLockObj)
- {
- return OSI_INVALID_PARAMS;
- }
//Take Semaphore
- if(pdTRUE == xSemaphoreTake( *pLockObj, ( TickType_t ) (Timeout/portTICK_PERIOD_MS) ))
+ if(pdTRUE == xSemaphoreTake( *pLockObj, ( TickType_t ) Timeout ))
{
return OSI_OK;
}
@@ -421,13 +362,8 @@ OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout)
\note
\warning
*/
-OsiReturnVal_e osi_LockObjUnlock(OsiLockObj_t* pLockObj)
+OsiReturnVal_e _osi_LockObjUnlock(OsiLockObj_t* pLockObj)
{
- //Check for NULL
- if(NULL == pLockObj)
- {
- return OSI_INVALID_PARAMS;
- }
//Release Semaphore
if(pdTRUE == xSemaphoreGive( *pLockObj ))
{
@@ -472,7 +408,6 @@ OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , unsigned long
{
taskYIELD ();
}
-
return OSI_OK;
}
return OSI_OPERATION_FAILED;
@@ -491,7 +426,7 @@ OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , unsigned long
void vSimpleLinkSpawnTask(void *pvParameters)
{
tSimpleLinkSpawnMsg Msg;
- portBASE_TYPE ret=pdFAIL;
+ portBASE_TYPE ret;
for(;;)
{
@@ -517,17 +452,12 @@ void vSimpleLinkSpawnTask(void *pvParameters)
OsiReturnVal_e VStartSimpleLinkSpawnTask(unsigned portBASE_TYPE uxPriority)
{
xSimpleLinkSpawnQueue = xQueueCreate( slQUEUE_SIZE, sizeof( tSimpleLinkSpawnMsg ) );
- if(0 == xSimpleLinkSpawnQueue)
- {
- return OSI_OPERATION_FAILED;
- }
- if(pdPASS == xTaskCreate( vSimpleLinkSpawnTask, ( portCHAR * ) "SLSPAWN",\
- 768 / sizeof(portSTACK_TYPE), NULL, uxPriority, &xSimpleLinkSpawnTaskHndl ))
- {
- return OSI_OK;
- }
+ ASSERT (xSimpleLinkSpawnQueue != NULL);
+
+ ASSERT (pdPASS == xTaskCreate( vSimpleLinkSpawnTask, ( portCHAR * ) "SLSPAWN",\
+ 768 / sizeof(portSTACK_TYPE), NULL, uxPriority, &xSimpleLinkSpawnTaskHndl ));
- return OSI_OPERATION_FAILED;
+ return OSI_OK;
}
/*!
@@ -541,13 +471,13 @@ OsiReturnVal_e VStartSimpleLinkSpawnTask(unsigned portBASE_TYPE uxPriority)
*/
void VDeleteSimpleLinkSpawnTask( void )
{
- if(0 != xSimpleLinkSpawnTaskHndl)
+ if(xSimpleLinkSpawnTaskHndl)
{
vTaskDelete( xSimpleLinkSpawnTaskHndl );
xSimpleLinkSpawnTaskHndl = 0;
}
- if(0 !=xSimpleLinkSpawnQueue)
+ if(xSimpleLinkSpawnQueue)
{
vQueueDelete( xSimpleLinkSpawnQueue );
xSimpleLinkSpawnQueue = 0;
@@ -571,20 +501,11 @@ OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ ,
unsigned long MsgSize,
unsigned long MaxMsgs)
{
- //Check for NULL
- if(NULL == pMsgQ)
- {
- return OSI_INVALID_PARAMS;
- }
-
- QueueHandle_t handle =0;
+ QueueHandle_t handle;
//Create Queue
handle = xQueueCreate( MaxMsgs, MsgSize );
- if (handle==0)
- {
- return OSI_OPERATION_FAILED;
- }
+ ASSERT (handle != NULL);
*pMsgQ = (OsiMsgQ_t)handle;
return OSI_OK;
@@ -600,11 +521,6 @@ OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ ,
*/
OsiReturnVal_e osi_MsgQDelete(OsiMsgQ_t* pMsgQ)
{
- //Check for NULL
- if(NULL == pMsgQ)
- {
- return OSI_INVALID_PARAMS;
- }
vQueueDelete((QueueHandle_t) *pMsgQ );
return OSI_OK;
}
@@ -622,12 +538,7 @@ OsiReturnVal_e osi_MsgQDelete(OsiMsgQ_t* pMsgQ)
OsiReturnVal_e osi_MsgQWrite(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
{
- //Check for NULL
- if(NULL == pMsgQ)
- {
- return OSI_INVALID_PARAMS;
- }
-
+ xHigherPriorityTaskWoken = pdFALSE;
if(pdPASS == xQueueSendFromISR((QueueHandle_t) *pMsgQ, pMsg, &xHigherPriorityTaskWoken ))
{
taskYIELD ();
@@ -652,17 +563,6 @@ OsiReturnVal_e osi_MsgQWrite(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
OsiReturnVal_e osi_MsgQRead(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
{
- //Check for NULL
- if(NULL == pMsgQ)
- {
- return OSI_INVALID_PARAMS;
- }
-
- if ( Timeout == OSI_WAIT_FOREVER )
- {
- Timeout = portMAX_DELAY ;
- }
-
//Receive Item from Queue
if( pdTRUE == xQueueReceive((QueueHandle_t)*pMsgQ,pMsg,Timeout) )
{
@@ -686,7 +586,6 @@ OsiReturnVal_e osi_MsgQRead(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
void * mem_Malloc(unsigned long Size)
{
-
return ( void * ) pvPortMalloc( (size_t)Size );
}
@@ -717,7 +616,6 @@ void mem_Free(void *pMem)
void mem_set(void *pBuf,int Val,size_t Size)
{
memset( pBuf,Val,Size);
-
}
/*!
@@ -781,8 +679,7 @@ void osi_start()
*/
void osi_Sleep(unsigned int MilliSecs)
{
- TickType_t xDelay = MilliSecs / portTICK_PERIOD_MS;
- vTaskDelay(xDelay);
+ vTaskDelay(MilliSecs);
}