Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #858, use osal id typedef #868

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions fsw/cfe-core/src/es/cfe_es_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr,
uint32 TaskId;
uint32 ChildTaskId;
uint32 ParentTaskId;
uint32 OsalId;
osal_id_t OsalId;

/*
** Validate some of the arguments
Expand Down Expand Up @@ -974,7 +974,8 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr,
** First, Make sure the Calling Task is a cFE Main task.
** TaskID must be the same as the Parent Task ID.
*/
TaskId = OS_TaskGetId();
OsalId = OS_TaskGetId();
TaskId = CFE_ES_ResourceID_FromOSAL(OsalId);
ParentTaskId = AppRecPtr->TaskInfo.MainTaskId;
if ( TaskId == ParentTaskId )
{
Expand All @@ -997,7 +998,7 @@ int32 CFE_ES_CreateChildTask(uint32 *TaskIdPtr,
*/
if ( Result == OS_SUCCESS )
{
ChildTaskId = OsalId;
ChildTaskId = CFE_ES_ResourceID_FromOSAL(OsalId);
TaskRecPtr = CFE_ES_LocateTaskRecordByID(ChildTaskId);

CFE_ES_TaskRecordSetUsed(TaskRecPtr, ChildTaskId);
Expand Down Expand Up @@ -1091,7 +1092,7 @@ void CFE_ES_IncrementTaskCounter(void)
* Because the global data is not locked, only minimal validation
* is performed.
*/
TaskID = OS_TaskGetId();
TaskID = CFE_ES_ResourceID_FromOSAL(OS_TaskGetId());
TaskRecPtr = CFE_ES_LocateTaskRecordByID(TaskID);
if (TaskRecPtr != NULL)
{
Expand All @@ -1113,6 +1114,7 @@ int32 CFE_ES_DeleteChildTask(uint32 TaskId)
bool TaskIsMain = false;
int32 ReturnCode = CFE_SUCCESS;
int32 OSReturnCode;
osal_id_t OsalId;

/*
** Make sure the task ID is within range
Expand Down Expand Up @@ -1154,7 +1156,8 @@ int32 CFE_ES_DeleteChildTask(uint32 TaskId)
/*
** Can delete the Task
*/
OSReturnCode = OS_TaskDelete(TaskId);
OsalId = CFE_ES_ResourceID_ToOSAL(TaskId);
OSReturnCode = OS_TaskDelete(OsalId);
if ( OSReturnCode == OS_SUCCESS )
{
/*
Expand Down Expand Up @@ -1673,7 +1676,10 @@ int32 CFE_ES_AppID_ToIndex(uint32 AppId, uint32 *Idx)
*/
int32 CFE_ES_TaskID_ToIndex(uint32 TaskID, uint32 *Idx)
{
if (OS_ConvertToArrayIndex(TaskID, Idx) != OS_SUCCESS)
osal_id_t OsalID;

OsalID = CFE_ES_ResourceID_ToOSAL(TaskID);
if (OS_ConvertToArrayIndex(OsalID, Idx) != OS_SUCCESS)
{
return CFE_ES_ERR_TASKID;
}
Expand All @@ -1685,6 +1691,33 @@ int32 CFE_ES_TaskID_ToIndex(uint32 TaskID, uint32 *Idx)
** Private API functions
*/

/**
* Convert a CFE_ES_ResourceID_t type to an OSAL ID type.
*
* This should only be used on ES resource IDs that are known to refer to
* an OSAL resource (e.g. a task ID).
*
* Note this may result in an invalid OSAL ID if the CFE_ES_ResourceID_t did
* not actually refer to an OSAL resource.
*/
osal_id_t CFE_ES_ResourceID_ToOSAL(uint32 id)
{
unsigned long val = (uint32)id; /* type conversion */
return OS_ObjectIdFromInteger(val);
}

/**
* Convert an OSAL ID type to a CFE_ES_ResourceID_t type.
*
* Any OSAL ID can also be represented as a CFE_ES_ResourceID_t
*/
uint32 CFE_ES_ResourceID_FromOSAL(osal_id_t id)
{
unsigned long val = OS_ObjectIdToInteger(id);
return (uint32)val; /* type conversion */
}


/*
* Note - this gets the table entry pointer but does not dereference or
* otherwise check/validate said pointer, as that would have to be done while
Expand Down Expand Up @@ -1741,7 +1774,7 @@ CFE_ES_TaskRecord_t *CFE_ES_GetTaskRecordByContext(void)
/*
** Use the OS task ID to get the ES task record
*/
TaskID = OS_TaskGetId();
TaskID = CFE_ES_ResourceID_FromOSAL(OS_TaskGetId());
TaskRecPtr = CFE_ES_LocateTaskRecordByID(TaskID);

/*
Expand Down
46 changes: 24 additions & 22 deletions fsw/cfe-core/src/es/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
const char *TokenList[CFE_ES_STARTSCRIPT_MAX_TOKENS_PER_LINE];
uint32 NumTokens;
uint32 BuffLen = 0; /* Length of the current buffer */
int32 AppFile = 0;
osal_id_t AppFile;
int32 Status;
char c;
int32 ReadStatus;
bool LineTooLong = false;
bool FileOpened = false;

Expand All @@ -94,13 +94,14 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
/*
** Open the file in the volatile disk.
*/
AppFile = OS_open( CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE, OS_READ_ONLY, 0);
Status = OS_open( CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE, OS_READ_ONLY, 0);

if ( AppFile >= 0 )
if ( Status >= 0 )
{
CFE_ES_WriteToSysLog ("ES Startup: Opened ES App Startup file: %s\n",
CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE);
FileOpened = true;
AppFile = OS_ObjectIdFromInteger(Status);
}
else
{
Expand All @@ -119,17 +120,18 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
/*
** Try to Open the file passed in to the cFE start.
*/
AppFile = OS_open( (const char *)StartFilePath, OS_READ_ONLY, 0);
Status = OS_open( (const char *)StartFilePath, OS_READ_ONLY, 0);

if ( AppFile >= 0 )
if ( Status >= 0 )
{
CFE_ES_WriteToSysLog ("ES Startup: Opened ES App Startup file: %s\n",StartFilePath);
FileOpened = true;
AppFile = OS_ObjectIdFromInteger(Status);
}
else
{
CFE_ES_WriteToSysLog ("ES Startup: Error, Can't Open ES App Startup file: %s EC = 0x%08X\n",
StartFilePath, (unsigned int)AppFile );
StartFilePath, (unsigned int)Status );
FileOpened = false;
}

Expand All @@ -151,13 +153,13 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
*/
while(1)
{
ReadStatus = OS_read(AppFile, &c, 1);
if ( ReadStatus == OS_ERROR )
Status = OS_read(AppFile, &c, 1);
if ( Status < 0 )
{
CFE_ES_WriteToSysLog ("ES Startup: Error Reading Startup file. EC = 0x%08X\n",(unsigned int)ReadStatus);
CFE_ES_WriteToSysLog ("ES Startup: Error Reading Startup file. EC = 0x%08X\n",(unsigned int)Status);
break;
}
else if ( ReadStatus == 0 )
else if ( Status == 0 )
{
/*
** EOF Reached
Expand Down Expand Up @@ -365,8 +367,8 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr,
int32 ReturnCode;
uint32 i;
bool AppSlotFound;
uint32 ModuleId;
uint32 MainTaskId;
osal_id_t ModuleId;
osal_id_t MainTaskId;
CFE_ES_AppRecord_t *AppRecPtr;
CFE_ES_TaskRecord_t *TaskRecPtr;

Expand Down Expand Up @@ -514,7 +516,7 @@ int32 CFE_ES_AppCreate(uint32 *ApplicationIdPtr,
/*
** Record the ES_TaskTable entry
*/
AppRecPtr->TaskInfo.MainTaskId = MainTaskId;
AppRecPtr->TaskInfo.MainTaskId = CFE_ES_ResourceID_FromOSAL(MainTaskId);
TaskRecPtr = CFE_ES_LocateTaskRecordByID(AppRecPtr->TaskInfo.MainTaskId);

if ( CFE_ES_TaskRecordIsUsed(TaskRecPtr) )
Expand Down Expand Up @@ -566,7 +568,7 @@ int32 CFE_ES_LoadLibrary(uint32 *LibraryIdPtr,
size_t StringLength;
int32 Status;
uint32 CheckSlot;
uint32 ModuleId;
osal_id_t ModuleId;
bool IsModuleLoaded;

/*
Expand All @@ -585,7 +587,7 @@ int32 CFE_ES_LoadLibrary(uint32 *LibraryIdPtr,
IsModuleLoaded = false;
LibSlotPtr = NULL;
FunctionPointer = NULL;
ModuleId = 0;
ModuleId = OS_OBJECT_ID_UNDEFINED;
Status = CFE_ES_ERR_LOAD_LIB; /* error that will be returned if no slots found */
CFE_ES_LockSharedData(__func__,__LINE__);
for ( CheckSlot = 0; CheckSlot < CFE_PLATFORM_ES_MAX_LIBRARIES; CheckSlot++ )
Expand Down Expand Up @@ -1175,7 +1177,7 @@ int32 CFE_ES_CleanUpApp(CFE_ES_AppRecord_t *AppRecPtr)
if ( Status == OS_ERROR )
{
CFE_ES_SysLogWrite_Unsync("CFE_ES_CleanUpApp: Module (ID:0x%08lX) Unload failed. RC=0x%08X\n",
(unsigned long)AppRecPtr->StartParams.ModuleId, (unsigned int)Status);
OS_ObjectIdToInteger(AppRecPtr->StartParams.ModuleId), (unsigned int)Status);
ReturnCode = CFE_ES_APP_CLEANUP_ERR;
}
CFE_ES_Global.RegisteredExternalApps--;
Expand Down Expand Up @@ -1213,7 +1215,7 @@ typedef struct
** NOTE: This is called while holding the ES global lock
**---------------------------------------------------------------------------------------
*/
void CFE_ES_CleanupObjectCallback(uint32 ObjectId, void *arg)
void CFE_ES_CleanupObjectCallback(osal_id_t ObjectId, void *arg)
{
CFE_ES_CleanupState_t *CleanState;
int32 Status;
Expand Down Expand Up @@ -1265,8 +1267,8 @@ void CFE_ES_CleanupObjectCallback(uint32 ObjectId, void *arg)
}
else
{
CFE_ES_SysLogWrite_Unsync("Call to OSAL Delete Object (ID:%d) failed. RC=0x%08X\n",
(int)ObjectId, (unsigned int)Status);
CFE_ES_SysLogWrite_Unsync("Call to OSAL Delete Object (ID:%lu) failed. RC=0x%08X\n",
OS_ObjectIdToInteger(ObjectId), (unsigned int)Status);
if (CleanState->OverallStatus == CFE_SUCCESS)
{
/*
Expand Down Expand Up @@ -1316,10 +1318,10 @@ int32 CFE_ES_CleanupTaskResources(uint32 TaskId)
CFE_ES_CleanupState_t CleanState;
int32 Result;
CFE_ES_TaskRecord_t *TaskRecPtr;
uint32 OsalId;
osal_id_t OsalId;

/* Get the Task ID for calling OSAL APIs (convert type) */
OsalId = TaskId;
OsalId = CFE_ES_ResourceID_ToOSAL(TaskId);

/*
** Delete all OSAL resources that belong to this task
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/es/cfe_es_apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ typedef struct

uint32 StackSize;
cpuaddr StartAddress;
uint32 ModuleId;
osal_id_t ModuleId;

uint16 ExceptionAction;
uint16 Priority;
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/es/cfe_es_backgroundtask.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void CFE_ES_BackgroundCleanup(void)
OS_BinSemDelete(CFE_ES_Global.BackgroundTask.WorkSem);

CFE_ES_Global.BackgroundTask.TaskID = 0;
CFE_ES_Global.BackgroundTask.WorkSem = 0;
CFE_ES_Global.BackgroundTask.WorkSem = OS_OBJECT_ID_UNDEFINED;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/es/cfe_es_cds.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ typedef struct

typedef struct
{
uint32 RegistryMutex; /**< \brief Mutex that controls access to CDS Registry */
osal_id_t RegistryMutex; /**< \brief Mutex that controls access to CDS Registry */
uint32 CDSSize; /**< \brief Total size of the CDS as reported by BSP */
uint32 MemPoolSize;
uint32 MaxNumRegEntries; /**< \brief Maximum number of Registry entries */
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/es/cfe_es_cds_mempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef struct {
int32 SizeIndex;
uint16 CheckErrCntr;
uint16 RequestCntr;
uint32 MutexId;
osal_id_t MutexId;
uint32 MinBlockSize;
CFE_ES_CDSBlockSizeDesc_t SizeDesc[CFE_ES_CDS_NUM_BLOCK_SIZES];
} CFE_ES_CDSPool_t;
Expand Down
Loading