Skip to content

Commit 5330d89

Browse files
committed
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.
1 parent f3661d4 commit 5330d89

4 files changed

Lines changed: 37 additions & 140 deletions

File tree

cc3200/FreeRTOS/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
#define configUSE_16_BIT_TICKS 0
9191
#define configIDLE_SHOULD_YIELD 1
9292
#define configUSE_CO_ROUTINES 0
93-
#define configUSE_MUTEXES 1
93+
#define configUSE_MUTEXES 0
9494
#define configUSE_RECURSIVE_MUTEXES 0
9595
#ifdef DEBUG
9696
#define configCHECK_FOR_STACK_OVERFLOW 1

cc3200/fatfs/src/option/syscall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int ff_cre_syncobj ( /* !=0:Function succeeded, ==0:Could not create due to any
3434
// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
3535
// ret = (int)(err == OS_NO_ERR);
3636

37-
*sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
37+
vSemaphoreCreateBinary( (*sobj) ); /* FreeRTOS */
3838
ret = (int)(*sobj != NULL);
3939

4040
return ret;

cc3200/simplelink/oslib/osi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ OsiReturnVal_e osi_LockObjCreate(OsiLockObj_t* pLockObj);
261261
\note
262262
\warning
263263
*/
264-
OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj);
264+
#define osi_LockObjDelete osi_SyncObjDelete
265265

266266
/*!
267267
\brief This function locks a locking object.
@@ -282,7 +282,7 @@ OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj);
282282
\note
283283
\warning
284284
*/
285-
OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout);
285+
#define osi_LockObjLock osi_SyncObjWait
286286

287287
/*!
288288
\brief This function unlock a locking object.
@@ -294,7 +294,7 @@ OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout);
294294
\note
295295
\warning
296296
*/
297-
OsiReturnVal_e osi_LockObjUnlock(OsiLockObj_t* pLockObj);
297+
#define osi_LockObjUnlock osi_SyncObjSignal
298298

299299

300300
/*!

cc3200/simplelink/oslib/osi_freertos.c

Lines changed: 32 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "inc/hw_types.h"
5252
#include "interrupt.h"
5353
#include "pybwdt.h"
54+
#include "debug.h"
5455

5556
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
5657
//Local function definition
@@ -117,23 +118,13 @@ void osi_InterruptDeRegister(int iIntrNum)
117118
*/
118119
OsiReturnVal_e osi_SyncObjCreate(OsiSyncObj_t* pSyncObj)
119120
{
120-
//Check for NULL
121-
if(NULL == pSyncObj)
122-
{
123-
return OSI_INVALID_PARAMS;
124-
}
125121
SemaphoreHandle_t *pl_SyncObj = (SemaphoreHandle_t *)pSyncObj;
126122

127123
*pl_SyncObj = xSemaphoreCreateBinary();
128124

129-
if((SemaphoreHandle_t)(*pSyncObj) != NULL)
130-
{
131-
return OSI_OK;
132-
}
133-
else
134-
{
135-
return OSI_OPERATION_FAILED;
136-
}
125+
ASSERT (*pSyncObj != NULL);
126+
127+
return OSI_OK;
137128
}
138129

139130
/*!
@@ -148,11 +139,6 @@ OsiReturnVal_e osi_SyncObjCreate(OsiSyncObj_t* pSyncObj)
148139
*/
149140
OsiReturnVal_e osi_SyncObjDelete(OsiSyncObj_t* pSyncObj)
150141
{
151-
//Check for NULL
152-
if(NULL == pSyncObj)
153-
{
154-
return OSI_INVALID_PARAMS;
155-
}
156142
vSemaphoreDelete(*pSyncObj );
157143
return OSI_OK;
158144
}
@@ -171,14 +157,7 @@ OsiReturnVal_e osi_SyncObjDelete(OsiSyncObj_t* pSyncObj)
171157
*/
172158
OsiReturnVal_e osi_SyncObjSignal(OsiSyncObj_t* pSyncObj)
173159
{
174-
//Check for NULL
175-
if(NULL == pSyncObj)
176-
{
177-
return OSI_INVALID_PARAMS;
178-
}
179-
180160
xSemaphoreGive( *pSyncObj );
181-
182161
return OSI_OK;
183162
}
184163
/*!
@@ -196,26 +175,15 @@ OsiReturnVal_e osi_SyncObjSignal(OsiSyncObj_t* pSyncObj)
196175
*/
197176
OsiReturnVal_e osi_SyncObjSignalFromISR(OsiSyncObj_t* pSyncObj)
198177
{
199-
//Check for NULL
200-
if(NULL == pSyncObj)
201-
{
202-
return OSI_INVALID_PARAMS;
203-
}
204178
xHigherPriorityTaskWoken = pdFALSE;
205179
if(pdTRUE == xSemaphoreGiveFromISR( *pSyncObj, &xHigherPriorityTaskWoken ))
206180
{
207181
if( xHigherPriorityTaskWoken )
208182
{
209183
taskYIELD ();
210184
}
211-
return OSI_OK;
212-
}
213-
else
214-
{
215-
//In case of Semaphore, you are expected to get this if multiple sem
216-
// give is called before sem take
217-
return OSI_OK;
218185
}
186+
return OSI_OK;
219187
}
220188

221189
/*!
@@ -235,12 +203,7 @@ OsiReturnVal_e osi_SyncObjSignalFromISR(OsiSyncObj_t* pSyncObj)
235203
*/
236204
OsiReturnVal_e osi_SyncObjWait(OsiSyncObj_t* pSyncObj , OsiTime_t Timeout)
237205
{
238-
//Check for NULL
239-
if(NULL == pSyncObj)
240-
{
241-
return OSI_INVALID_PARAMS;
242-
}
243-
if(pdTRUE == xSemaphoreTake( (SemaphoreHandle_t)*pSyncObj, ( TickType_t )(Timeout/portTICK_PERIOD_MS) ))
206+
if(pdTRUE == xSemaphoreTake( (SemaphoreHandle_t)*pSyncObj, ( TickType_t )Timeout))
244207
{
245208
return OSI_OK;
246209
}
@@ -262,12 +225,6 @@ OsiReturnVal_e osi_SyncObjWait(OsiSyncObj_t* pSyncObj , OsiTime_t Timeout)
262225
*/
263226
OsiReturnVal_e osi_SyncObjClear(OsiSyncObj_t* pSyncObj)
264227
{
265-
//Check for NULL
266-
if(NULL == pSyncObj)
267-
{
268-
return OSI_INVALID_PARAMS;
269-
}
270-
271228
if (OSI_OK == osi_SyncObjWait(pSyncObj,0) )
272229
{
273230
return OSI_OK;
@@ -293,20 +250,13 @@ OsiReturnVal_e osi_SyncObjClear(OsiSyncObj_t* pSyncObj)
293250
*/
294251
OsiReturnVal_e osi_LockObjCreate(OsiLockObj_t* pLockObj)
295252
{
296-
//Check for NULL
297-
if(NULL == pLockObj)
298-
{
299-
return OSI_INVALID_PARAMS;
300-
}
301-
*pLockObj = (OsiLockObj_t)xSemaphoreCreateMutex();
302-
if(pLockObj != NULL)
303-
{
304-
return OSI_OK;
305-
}
306-
else
307-
{
308-
return OSI_OPERATION_FAILED;
309-
}
253+
SemaphoreHandle_t *pl_LockObj = (SemaphoreHandle_t *)pLockObj;
254+
255+
vSemaphoreCreateBinary(*pl_LockObj);
256+
257+
ASSERT (*pLockObj != NULL);
258+
259+
return OSI_OK;
310260
}
311261

312262
/*!
@@ -329,15 +279,11 @@ OsiReturnVal_e osi_TaskCreate(P_OSI_TASK_ENTRY pEntry,const signed char * const
329279
unsigned short usStackDepth, void *pvParameters,
330280
unsigned long uxPriority,OsiTaskHandle* pTaskHandle)
331281
{
332-
if(pdPASS == xTaskCreate( pEntry, (char const*)pcName,
282+
ASSERT (pdPASS == xTaskCreate( pEntry, (char const*)pcName,
333283
(usStackDepth/(sizeof( portSTACK_TYPE ))),
334284
pvParameters,(unsigned portBASE_TYPE)uxPriority,
335-
(TaskHandle_t*)pTaskHandle ))
336-
{
337-
return OSI_OK;
338-
}
339-
340-
return OSI_OPERATION_FAILED;
285+
(TaskHandle_t*)pTaskHandle ));
286+
return OSI_OK;
341287
}
342288

343289

@@ -368,7 +314,7 @@ void osi_TaskDelete(OsiTaskHandle* pTaskHandle)
368314
\note
369315
\warning
370316
*/
371-
OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj)
317+
OsiReturnVal_e _osi_LockObjDelete(OsiLockObj_t* pLockObj)
372318
{
373319
vSemaphoreDelete((SemaphoreHandle_t)*pLockObj );
374320
return OSI_OK;
@@ -393,15 +339,10 @@ OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj)
393339
\note
394340
\warning
395341
*/
396-
OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout)
342+
OsiReturnVal_e _osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout)
397343
{
398-
//Check for NULL
399-
if(NULL == pLockObj)
400-
{
401-
return OSI_INVALID_PARAMS;
402-
}
403344
//Take Semaphore
404-
if(pdTRUE == xSemaphoreTake( *pLockObj, ( TickType_t ) (Timeout/portTICK_PERIOD_MS) ))
345+
if(pdTRUE == xSemaphoreTake( *pLockObj, ( TickType_t ) Timeout ))
405346
{
406347
return OSI_OK;
407348
}
@@ -421,13 +362,8 @@ OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout)
421362
\note
422363
\warning
423364
*/
424-
OsiReturnVal_e osi_LockObjUnlock(OsiLockObj_t* pLockObj)
365+
OsiReturnVal_e _osi_LockObjUnlock(OsiLockObj_t* pLockObj)
425366
{
426-
//Check for NULL
427-
if(NULL == pLockObj)
428-
{
429-
return OSI_INVALID_PARAMS;
430-
}
431367
//Release Semaphore
432368
if(pdTRUE == xSemaphoreGive( *pLockObj ))
433369
{
@@ -472,7 +408,6 @@ OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , unsigned long
472408
{
473409
taskYIELD ();
474410
}
475-
476411
return OSI_OK;
477412
}
478413
return OSI_OPERATION_FAILED;
@@ -491,7 +426,7 @@ OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , unsigned long
491426
void vSimpleLinkSpawnTask(void *pvParameters)
492427
{
493428
tSimpleLinkSpawnMsg Msg;
494-
portBASE_TYPE ret=pdFAIL;
429+
portBASE_TYPE ret;
495430

496431
for(;;)
497432
{
@@ -517,17 +452,12 @@ void vSimpleLinkSpawnTask(void *pvParameters)
517452
OsiReturnVal_e VStartSimpleLinkSpawnTask(unsigned portBASE_TYPE uxPriority)
518453
{
519454
xSimpleLinkSpawnQueue = xQueueCreate( slQUEUE_SIZE, sizeof( tSimpleLinkSpawnMsg ) );
520-
if(0 == xSimpleLinkSpawnQueue)
521-
{
522-
return OSI_OPERATION_FAILED;
523-
}
524-
if(pdPASS == xTaskCreate( vSimpleLinkSpawnTask, ( portCHAR * ) "SLSPAWN",\
525-
768 / sizeof(portSTACK_TYPE), NULL, uxPriority, &xSimpleLinkSpawnTaskHndl ))
526-
{
527-
return OSI_OK;
528-
}
455+
ASSERT (xSimpleLinkSpawnQueue != NULL);
456+
457+
ASSERT (pdPASS == xTaskCreate( vSimpleLinkSpawnTask, ( portCHAR * ) "SLSPAWN",\
458+
768 / sizeof(portSTACK_TYPE), NULL, uxPriority, &xSimpleLinkSpawnTaskHndl ));
529459

530-
return OSI_OPERATION_FAILED;
460+
return OSI_OK;
531461
}
532462

533463
/*!
@@ -541,13 +471,13 @@ OsiReturnVal_e VStartSimpleLinkSpawnTask(unsigned portBASE_TYPE uxPriority)
541471
*/
542472
void VDeleteSimpleLinkSpawnTask( void )
543473
{
544-
if(0 != xSimpleLinkSpawnTaskHndl)
474+
if(xSimpleLinkSpawnTaskHndl)
545475
{
546476
vTaskDelete( xSimpleLinkSpawnTaskHndl );
547477
xSimpleLinkSpawnTaskHndl = 0;
548478
}
549479

550-
if(0 !=xSimpleLinkSpawnQueue)
480+
if(xSimpleLinkSpawnQueue)
551481
{
552482
vQueueDelete( xSimpleLinkSpawnQueue );
553483
xSimpleLinkSpawnQueue = 0;
@@ -571,20 +501,11 @@ OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ ,
571501
unsigned long MsgSize,
572502
unsigned long MaxMsgs)
573503
{
574-
//Check for NULL
575-
if(NULL == pMsgQ)
576-
{
577-
return OSI_INVALID_PARAMS;
578-
}
579-
580-
QueueHandle_t handle =0;
504+
QueueHandle_t handle;
581505

582506
//Create Queue
583507
handle = xQueueCreate( MaxMsgs, MsgSize );
584-
if (handle==0)
585-
{
586-
return OSI_OPERATION_FAILED;
587-
}
508+
ASSERT (handle != NULL);
588509

589510
*pMsgQ = (OsiMsgQ_t)handle;
590511
return OSI_OK;
@@ -600,11 +521,6 @@ OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t* pMsgQ ,
600521
*/
601522
OsiReturnVal_e osi_MsgQDelete(OsiMsgQ_t* pMsgQ)
602523
{
603-
//Check for NULL
604-
if(NULL == pMsgQ)
605-
{
606-
return OSI_INVALID_PARAMS;
607-
}
608524
vQueueDelete((QueueHandle_t) *pMsgQ );
609525
return OSI_OK;
610526
}
@@ -622,12 +538,7 @@ OsiReturnVal_e osi_MsgQDelete(OsiMsgQ_t* pMsgQ)
622538

623539
OsiReturnVal_e osi_MsgQWrite(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
624540
{
625-
//Check for NULL
626-
if(NULL == pMsgQ)
627-
{
628-
return OSI_INVALID_PARAMS;
629-
}
630-
541+
xHigherPriorityTaskWoken = pdFALSE;
631542
if(pdPASS == xQueueSendFromISR((QueueHandle_t) *pMsgQ, pMsg, &xHigherPriorityTaskWoken ))
632543
{
633544
taskYIELD ();
@@ -652,17 +563,6 @@ OsiReturnVal_e osi_MsgQWrite(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
652563

653564
OsiReturnVal_e osi_MsgQRead(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
654565
{
655-
//Check for NULL
656-
if(NULL == pMsgQ)
657-
{
658-
return OSI_INVALID_PARAMS;
659-
}
660-
661-
if ( Timeout == OSI_WAIT_FOREVER )
662-
{
663-
Timeout = portMAX_DELAY ;
664-
}
665-
666566
//Receive Item from Queue
667567
if( pdTRUE == xQueueReceive((QueueHandle_t)*pMsgQ,pMsg,Timeout) )
668568
{
@@ -686,7 +586,6 @@ OsiReturnVal_e osi_MsgQRead(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout)
686586

687587
void * mem_Malloc(unsigned long Size)
688588
{
689-
690589
return ( void * ) pvPortMalloc( (size_t)Size );
691590
}
692591

@@ -717,7 +616,6 @@ void mem_Free(void *pMem)
717616
void mem_set(void *pBuf,int Val,size_t Size)
718617
{
719618
memset( pBuf,Val,Size);
720-
721619
}
722620

723621
/*!
@@ -781,8 +679,7 @@ void osi_start()
781679
*/
782680
void osi_Sleep(unsigned int MilliSecs)
783681
{
784-
TickType_t xDelay = MilliSecs / portTICK_PERIOD_MS;
785-
vTaskDelay(xDelay);
682+
vTaskDelay(MilliSecs);
786683
}
787684

788685

0 commit comments

Comments
 (0)