1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

Replace malloc with FreeRTOS built-in functions

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@358 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
vassilis 2010-03-21 14:19:38 +00:00 committed by vassilis
parent a608c73470
commit 20f29b40e4
4 changed files with 10 additions and 12 deletions

View File

@ -129,7 +129,7 @@ int32_t EventPeriodicCreate(UAVObjEvent* ev, UAVObjEventCallback cb, int32_t per
} }
} }
// Create handle // Create handle
objEntry = (PeriodicObjectList*)malloc(sizeof(PeriodicObjectList)); objEntry = (PeriodicObjectList*)pvPortMalloc(sizeof(PeriodicObjectList));
if (objEntry == NULL) return -1; if (objEntry == NULL) return -1;
memcpy(&objEntry->evInfo.ev, ev, sizeof(UAVObjEvent)); memcpy(&objEntry->evInfo.ev, ev, sizeof(UAVObjEvent));
objEntry->updatePeriodMs = periodMs; objEntry->updatePeriodMs = periodMs;
@ -189,7 +189,7 @@ int32_t EventPeriodicDelete(UAVObjEvent* ev, UAVObjEventCallback cb)
{ {
// Object found, remove from list // Object found, remove from list
LL_DELETE(objList, objEntry); LL_DELETE(objList, objEntry);
free(objEntry); vPortFree(objEntry);
xSemaphoreGiveRecursive(mutex); xSemaphoreGiveRecursive(mutex);
return 0; return 0;
} }

View File

@ -38,8 +38,8 @@
#define $(NAMEUC)_NUMBYTES sizeof($(NAME)Data) #define $(NAMEUC)_NUMBYTES sizeof($(NAME)Data)
// Data access macros // Data access macros
#define $(NAMEUC)_GET(dataOut) UAVObjGetData($(NAME)GetHandle(), dataOut) #define $(NAME)Get(dataOut) UAVObjGetData($(NAME)GetHandle(), dataOut)
#define $(NAMEUC)_SET(dataIn) UAVObjGetData($(NAME)GetHandle(), dataIn) #define $(NAME)Set(dataIn) UAVObjSetData($(NAME)GetHandle(), dataIn)
// Object data // Object data
typedef struct { typedef struct {

View File

@ -144,7 +144,7 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, int32_t isMetaobject,
} }
// Create and append entry // Create and append entry
objEntry = (ObjectList*)malloc(sizeof(ObjectList)); objEntry = (ObjectList*)pvPortMalloc(sizeof(ObjectList));
if (objEntry == NULL) if (objEntry == NULL)
{ {
xSemaphoreGiveRecursive(mutex); xSemaphoreGiveRecursive(mutex);
@ -164,7 +164,7 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, int32_t isMetaobject,
else else
{ {
objEntry->numInstances = 1; objEntry->numInstances = 1;
objEntry->data.instance = malloc(numBytes); objEntry->data.instance = pvPortMalloc(numBytes);
if (objEntry->data.instance == NULL) if (objEntry->data.instance == NULL)
{ {
xSemaphoreGiveRecursive(mutex); xSemaphoreGiveRecursive(mutex);
@ -838,9 +838,9 @@ int32_t createInstance(ObjectList* obj, uint16_t instId)
// Create new instance // Create new instance
if (!obj->isSingleInstance && instId < UAVOBJ_MAX_INSTANCES) if (!obj->isSingleInstance && instId < UAVOBJ_MAX_INSTANCES)
{ {
elemEntry = (ObjectInstList*)malloc(sizeof(ObjectInstList)); elemEntry = (ObjectInstList*)pvPortMalloc(sizeof(ObjectInstList));
if (elemEntry == NULL) return -1; if (elemEntry == NULL) return -1;
elemEntry->data = malloc(obj->numBytes); elemEntry->data = pvPortMalloc(obj->numBytes);
if (elemEntry->data == NULL) return -1; if (elemEntry->data == NULL) return -1;
memset(elemEntry->data, 0, obj->numBytes); memset(elemEntry->data, 0, obj->numBytes);
elemEntry->instId = instId; elemEntry->instId = instId;
@ -908,7 +908,7 @@ int32_t connectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCallback cb,
} }
// Add queue to list // Add queue to list
queueEntry = (ObjectQueueList*)malloc(sizeof(ObjectQueueList)); queueEntry = (ObjectQueueList*)pvPortMalloc(sizeof(ObjectQueueList));
if (queueEntry == NULL) if (queueEntry == NULL)
{ {
return -1; return -1;
@ -941,7 +941,7 @@ int32_t disconnectObj(UAVObjHandle obj, xQueueHandle queue, UAVObjEventCallback
if ( ( queueEntry->queue == queue && queueEntry->cb == cb ) ) if ( ( queueEntry->queue == queue && queueEntry->cb == cb ) )
{ {
LL_DELETE(objEntry->queues, queueEntry); LL_DELETE(objEntry->queues, queueEntry);
free(queueEntry); vPortFree(queueEntry);
return 0; return 0;
} }
} }

View File

@ -28,8 +28,6 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#define $(METAOBJECT)
#include "openpilot.h" #include "openpilot.h"
#include "$(NAMELC).h" #include "$(NAMELC).h"