mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
POSIX port: some improvements as suggested by stac
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1024 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
15ed310cbd
commit
b13f8296dc
@ -29,7 +29,7 @@
|
|||||||
#define UAVOBJ_ALL_INSTANCES 0xFFFF
|
#define UAVOBJ_ALL_INSTANCES 0xFFFF
|
||||||
#define UAVOBJ_MAX_INSTANCES 1000
|
#define UAVOBJ_MAX_INSTANCES 1000
|
||||||
|
|
||||||
typedef ptrdiff_t UAVObjHandle;
|
typedef void* UAVObjHandle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object update mode, used by multiple modules (e.g. telemetry and logger)
|
* Object update mode, used by multiple modules (e.g. telemetry and logger)
|
||||||
|
@ -148,7 +148,7 @@ void UAVObjClearStats()
|
|||||||
* \param[in] isSettings Is this a settings object
|
* \param[in] isSettings Is this a settings object
|
||||||
* \param[in] numBytes Number of bytes of object data (for one instance)
|
* \param[in] numBytes Number of bytes of object data (for one instance)
|
||||||
* \param[in] initCb Default field and metadata initialization function
|
* \param[in] initCb Default field and metadata initialization function
|
||||||
* \return Object handle, or 0 if failure.
|
* \return Object handle, or NULL if failure.
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName, int32_t isMetaobject,
|
UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName, int32_t isMetaobject,
|
||||||
@ -168,7 +168,7 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
|||||||
{
|
{
|
||||||
// Already registered, ignore
|
// Already registered, ignore
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
|||||||
if (objEntry == NULL)
|
if (objEntry == NULL)
|
||||||
{
|
{
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
objEntry->id = id;
|
objEntry->id = id;
|
||||||
objEntry->name = name;
|
objEntry->name = name;
|
||||||
@ -197,7 +197,7 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
|||||||
if ( instEntry == NULL )
|
if ( instEntry == NULL )
|
||||||
{
|
{
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create metaobject and update linkedObj
|
// Create metaobject and update linkedObj
|
||||||
@ -240,7 +240,7 @@ UAVObjHandle UAVObjRegister(uint32_t id, const char* name, const char* metaName,
|
|||||||
/**
|
/**
|
||||||
* Retrieve an object from the list given its id
|
* Retrieve an object from the list given its id
|
||||||
* \param[in] The object ID
|
* \param[in] The object ID
|
||||||
* \return The object or 0 if not found.
|
* \return The object or NULL if not found.
|
||||||
*/
|
*/
|
||||||
UAVObjHandle UAVObjGetByID(uint32_t id)
|
UAVObjHandle UAVObjGetByID(uint32_t id)
|
||||||
{
|
{
|
||||||
@ -263,13 +263,13 @@ UAVObjHandle UAVObjGetByID(uint32_t id)
|
|||||||
|
|
||||||
// Object not found, release lock and return error
|
// Object not found, release lock and return error
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an object from the list given its name
|
* Retrieve an object from the list given its name
|
||||||
* \param[in] name The name of the object
|
* \param[in] name The name of the object
|
||||||
* \return The object or 0 if not found.
|
* \return The object or NULL if not found.
|
||||||
*/
|
*/
|
||||||
UAVObjHandle UAVObjGetByName(char* name)
|
UAVObjHandle UAVObjGetByName(char* name)
|
||||||
{
|
{
|
||||||
@ -292,7 +292,7 @@ UAVObjHandle UAVObjGetByName(char* name)
|
|||||||
|
|
||||||
// Object not found, release lock and return error
|
// Object not found, release lock and return error
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -529,12 +529,12 @@ int32_t UAVObjSaveToFile(UAVObjHandle obj, uint16_t instId, FILEINFO* file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the object ID
|
// Write the object ID
|
||||||
PIOS_FWRITE(file,&objEntry->id,4,&bytesWritten);
|
PIOS_FWRITE(file,&objEntry->id,sizeof(objEntry->id),&bytesWritten);
|
||||||
|
|
||||||
// Write the instance ID
|
// Write the instance ID
|
||||||
if (!objEntry->isSingleInstance)
|
if (!objEntry->isSingleInstance)
|
||||||
{
|
{
|
||||||
PIOS_FWRITE(file,&instEntry->instId,2,&bytesWritten);
|
PIOS_FWRITE(file,&instEntry->instId,sizeof(instEntry->instId),&bytesWritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the data and check that the write was successful
|
// Write the data and check that the write was successful
|
||||||
@ -605,7 +605,7 @@ int32_t UAVObjSave(UAVObjHandle obj, uint16_t instId)
|
|||||||
/**
|
/**
|
||||||
* Load an object from the file system (SD card).
|
* Load an object from the file system (SD card).
|
||||||
* @param[in] file File to read from
|
* @param[in] file File to read from
|
||||||
* @return The handle of the object loaded or 0 if a failure
|
* @return The handle of the object loaded or NULL if a failure
|
||||||
*/
|
*/
|
||||||
UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
||||||
{
|
{
|
||||||
@ -619,17 +619,17 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
|||||||
// Check for file system availability
|
// Check for file system availability
|
||||||
if ( POIS_SDCARD_IsMounted() == 0 )
|
if ( POIS_SDCARD_IsMounted() == 0 )
|
||||||
{
|
{
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock
|
// Lock
|
||||||
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
|
||||||
|
|
||||||
// Read the object ID
|
// Read the object ID
|
||||||
if ( PIOS_FREAD(file,&objId,4,&bytesRead) )
|
if ( PIOS_FREAD(file,&objId,sizeof(objId),&bytesRead) )
|
||||||
{
|
{
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the object
|
// Get the object
|
||||||
@ -637,7 +637,7 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
|||||||
if ( obj == 0 )
|
if ( obj == 0 )
|
||||||
{
|
{
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
objEntry = (ObjectList*)obj;
|
objEntry = (ObjectList*)obj;
|
||||||
|
|
||||||
@ -645,10 +645,10 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
|||||||
instId = 0;
|
instId = 0;
|
||||||
if ( !objEntry->isSingleInstance )
|
if ( !objEntry->isSingleInstance )
|
||||||
{
|
{
|
||||||
if ( PIOS_FREAD(file,&instId,2,&bytesRead) )
|
if ( PIOS_FREAD(file,&instId,sizeof(instId),&bytesRead) )
|
||||||
{
|
{
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,7 +663,7 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
|||||||
{
|
{
|
||||||
// Error, unlock and return
|
// Error, unlock and return
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,7 +671,7 @@ UAVObjHandle UAVObjLoadFromFile(FILEINFO* file)
|
|||||||
if ( PIOS_FREAD(file,instEntry->data,objEntry->numBytes,&bytesRead) )
|
if ( PIOS_FREAD(file,instEntry->data,objEntry->numBytes,&bytesRead) )
|
||||||
{
|
{
|
||||||
xSemaphoreGiveRecursive(mutex);
|
xSemaphoreGiveRecursive(mutex);
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire event
|
// Fire event
|
||||||
|
@ -26,20 +26,9 @@
|
|||||||
#ifndef PIOS_POSIX_H
|
#ifndef PIOS_POSIX_H
|
||||||
#define PIOS_POSIX_H
|
#define PIOS_POSIX_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef __uint16_t uint16_t;
|
|
||||||
typedef __uint32_t uint32_t;
|
|
||||||
typedef __uint32_t u32;
|
|
||||||
typedef __uint8_t uint8_t;
|
|
||||||
|
|
||||||
typedef __int16_t int16_t;
|
|
||||||
typedef __int32_t int32_t;
|
|
||||||
typedef __int8_t int8_t;
|
|
||||||
|
|
||||||
#define FILEINFO FILE*
|
#define FILEINFO FILE*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ typedef struct {
|
|||||||
uint16_t OEM_AppliID; /* OEM/Application ID */
|
uint16_t OEM_AppliID; /* OEM/Application ID */
|
||||||
char ProdName[6]; /* Product Name */
|
char ProdName[6]; /* Product Name */
|
||||||
uint8_t ProdRev; /* Product Revision */
|
uint8_t ProdRev; /* Product Revision */
|
||||||
u32 ProdSN; /* Product Serial Number */
|
uint32_t ProdSN; /* Product Serial Number */
|
||||||
uint8_t Reserved1; /* Reserved1 */
|
uint8_t Reserved1; /* Reserved1 */
|
||||||
uint16_t ManufactDate; /* Manufacturing Date */
|
uint16_t ManufactDate; /* Manufacturing Date */
|
||||||
uint8_t msd_CRC; /* CRC */
|
uint8_t msd_CRC; /* CRC */
|
||||||
|
Loading…
Reference in New Issue
Block a user