void UU_AppMain(void) { int32 Status; int32 Status2; CFE_SB_PipeId_t pipeId; char pipeName[10]; void *TblPointer; CFE_TBL_Handle_t TblHandle; /* ** Register application... */ /* CFE_ES_RegisterApp(); */ /* ** Perform application specific initialize ** including access initial table values. */ UU_AppInit(); TblHandle = 0; /* original was 5 */ /* ** Main process loop (forever)... */ while (TRUE) { /* ** Wait for the next Software Bus message... */ Status = CFE_SB_RcvMsg(&UU_AppData.MsgPtr, UU_AppData.CmdPipe, 4); /* if (Status == CFE_SB_TIME_OUT) */ if (1) { UTF_put_text("CFE_ES_ResetCFE returned %lx\n",CFE_ES_ResetCFE(5)); UTF_put_text("CFE_ES_RegisterApp returned %lx\n",CFE_ES_RegisterApp()); /* This one caused a seg fault */ /*UTF_put_text("CFE_ES_GetAppID returned %d\n",CFE_ES_GetAppID((uint32 *)0x3344beef)); */ UTF_put_text("CFE_ES_GetAppID returned %lx\n",CFE_ES_GetAppID(0)); Status2 = CFE_EVS_SendEvent(UU_INIT_INF_EID, CFE_EVS_INFORMATION, "UU: SendEvent called from UU task's forever loop"); UTF_put_text("CFE_EVS_SendEvent returned %lx\n", Status2); UTF_put_text("CFE_FS_ReadHeader returned %lx\n", CFE_FS_ReadHeader(0,0)); UTF_put_text("CFE_SB_CreatePipe returned %lx\n", CFE_SB_CreatePipe(&pipeId,1,pipeName)); UTF_put_text("CFE_SB_RcvMsg returned %lx\n", Status); UTF_put_text(" CFE_TBL_GetAddress returned %lx\n", CFE_TBL_GetAddress( &TblPointer,TblHandle )); } } } /* End of UU_AppMain() */
/* ** Function: ** CFE_ES_GetMemPoolStats ** ** Purpose: ** */ int32 CFE_ES_GetMemPoolStats(CFE_ES_MemPoolStats_t *BufPtr, CFE_ES_MemHandle_t Handle) { uint32 AppId = 0xFFFFFFFF; Pool_t *PoolPtr; uint32 i; PoolPtr = (Pool_t *)Handle; CFE_ES_GetAppID(&AppId); if (Handle != (CFE_ES_MemHandle_t)PoolPtr->Start) { CFE_ES_WriteToSysLog("CFE_ES:getMemPoolStats err:Bad handle(0x%08X) AppId=%d\n", Handle, AppId); return(CFE_ES_ERR_MEM_HANDLE); } BufPtr->PoolSize = PoolPtr->Size; BufPtr->NumBlocksRequested = PoolPtr->RequestCntr; BufPtr->CheckErrCtr = PoolPtr->CheckErrCntr; BufPtr->NumFreeBytes = PoolPtr->End - ((uint32)PoolPtr->Current); for (i=0; i<CFE_ES_MAX_MEMPOOL_BLOCK_SIZES; i++) { BufPtr->BlockStats[i].BlockSize = PoolPtr->SizeDesc[i].MaxSize; BufPtr->BlockStats[i].NumCreated = PoolPtr->SizeDesc[i].NumCreated; BufPtr->BlockStats[i].NumFree = PoolPtr->SizeDesc[i].NumFree; } return(CFE_SUCCESS); }
/****************************************************************************** ** Function: CFE_FS_UnlockSharedData() ** ** Purpose: ** FS internal function to handle a semaphore give failure for the Shared ** Data Mutex ** ** Arguments: ** FunctionName - the Function containing the code that generated the error. ** ** Return: ** None */ void CFE_FS_UnlockSharedData(const char *FunctionName) { int32 Status; uint32 AppId = 0; Status = OS_MutSemGive(CFE_FS.SharedDataMutexId); if (Status != OS_SUCCESS) { CFE_ES_GetAppID(&AppId); CFE_ES_WriteToSysLog("FS SharedData Mutex Give Err Stat=0x%x,App=%d,Function=%s\n", Status,AppId,FunctionName); }/* end if */ return; }/* end CFE_FS_UnlockSharedData */
/****************************************************************************** ** Function: CFE_SB_UnlockSharedData() ** ** Purpose: ** SB internal function to handle a semaphore give failure for the Shared ** Data Mutex ** ** Arguments: ** FuncName - the function name containing the code that generated the error. ** LineNumber - the line number in the file of the code that generated the error. ** ** Return: ** None */ void CFE_SB_UnlockSharedData(const char *FuncName, int32 LineNumber){ int32 Status; uint32 AppId = 0xFFFFFFFF; Status = OS_MutSemGive(CFE_SB.SharedDataMutexId); if (Status != OS_SUCCESS) { CFE_ES_GetAppID(&AppId); CFE_ES_WriteToSysLog("SB SharedData Mutex Give Err Stat=0x%x,App=%d,Func=%s,Line=%d\n", Status,AppId,FuncName,LineNumber); }/* end if */ return; }/* end CFE_SB_UnlockSharedData */
int32 CFE_ES_CDS_ValidateAppID(uint32 *AppIdPtr) { int32 Status = CFE_ES_GetAppID(AppIdPtr); if (Status == CFE_SUCCESS) { if (*AppIdPtr >= CFE_ES_MAX_APPLICATIONS) { Status = CFE_ES_ERR_APPID; CFE_ES_WriteToSysLog("CFE_CDS:ValidateAppID-AppId=%d > Max Apps (%d)\n", *AppIdPtr, CFE_ES_MAX_APPLICATIONS); } } else { CFE_ES_WriteToSysLog("CFE_CDS:ValidateAppID-GetAppID failed (Stat=0x%08X)\n", Status); } return Status; } /* End of CFE_ES_CDS_ValidateAppID() */
/* ** Test filter registration related calls */ void Test_FilterRegistration (void) { int i; CFE_EVS_BinFilter_t filter[CFE_EVS_MAX_EVENT_FILTERS + 1]; CFE_EVS_EVSBinFilter_t *FilterPtr = NULL; CFE_EVS_Table_t *TablePtr; uint32 AppID; CFE_EVS_BitMaskCmd_t bitmaskcmd; /* TEST: unknown filter */ UT_Report(CFE_EVS_Register(NULL, 0, -1) == CFE_EVS_UNKNOWN_FILTER, "CFE_EVS_Register","illegal filter option"); /* TEST: valid registration with no filters */ UT_Report(CFE_EVS_Register(NULL, 0, CFE_EVS_BINARY_FILTER) == CFE_SUCCESS, "CFE_EVS_Register", "valid w/ no filters"); /* TEST: unregistration with failed ES_putPool */ UT_SetPutPoolFail(1); UT_Report(CFE_EVS_Unregister() < 0, "CFE_EVS_Unregister", "unregistration with failed ES_putPool"); UT_SetPutPoolFail(0); /* Re-register to test valid unregistration */ UT_Report(CFE_EVS_Register(NULL, 0, CFE_EVS_BINARY_FILTER) == CFE_SUCCESS, "CFE_EVS_Register", "valid w/ no filters (re-registration)"); /* TEST: valid unregistration */ UT_Report(CFE_EVS_Unregister() == CFE_SUCCESS, "CFE_EVS_Unregister", "valid call"); /* TEST: valid registration with filter */ filter[0].EventID = 0; filter[0].Mask = 0x0001; UT_Report(CFE_EVS_Register(filter, 1, CFE_EVS_BINARY_FILTER) == CFE_SUCCESS, "CFE_EVS_Register", "valid w/ filter"); /* TEST: multiple valid registration with more than MAX filters */ for (i = 0; i < CFE_EVS_MAX_EVENT_FILTERS + 1; i++){ filter[i].EventID = i; filter[i].Mask = 1; } UT_Report(CFE_EVS_Register(filter, CFE_EVS_MAX_EVENT_FILTERS + 1, CFE_EVS_BINARY_FILTER) == CFE_EVS_APP_FILTER_OVERLOAD, "CFE_EVS_Register", "valid over max filters"); /* TEST: Send 1st information message, should get through */ UT_Report(CFE_EVS_SendEvent(0, CFE_EVS_INFORMATION, "OK") == CFE_SUCCESS, "CFE_EVS_SendEvent", "1st info message should go through"); /* TEST: Send 2nd information message, should be filtered */ UT_Report(CFE_EVS_SendEvent(0, CFE_EVS_INFORMATION, "FAILED") == CFE_SUCCESS, "CFE_EVS_SendEvent", "2nd info message should be filtered"); /* TEST: Send Last information message, which should cause filtering to lock */ CFE_ES_GetAppID(&AppID); TablePtr = CFE_EVS_GlobalData.EVS_TablePtr[AppID].Address; FilterPtr = EVS_FindEventID(0, (CFE_EVS_EVSBinFilter_t *)&TablePtr->BinFilters); FilterPtr->Count = CFE_EVS_MAX_FILTER_COUNT - 1; UT_Report(CFE_EVS_SendEvent(0, CFE_EVS_INFORMATION, "OK") == CFE_SUCCESS, "CFE_EVS_SendEvent", "Last info message should go through"); UT_Report(CFE_EVS_SendEvent(0, CFE_EVS_INFORMATION, "FAILED") == CFE_SUCCESS, "CFE_EVS_SendEvent", "Locked info message should be filtered"); UT_Report(CFE_EVS_SendEvent(0, CFE_EVS_INFORMATION, "FAILED") == CFE_SUCCESS, "CFE_EVS_SendEvent", "Locked info message should still be filtered"); /* Return application to original state, re-register application */ CFE_EVS_Register(NULL, 0, CFE_EVS_BINARY_FILTER); }
/* ** Function Prologue ** ** Function Name: CFE_EVS_SendEvent ** ** Purpose: This routine sends an event message, with message ID containing the current ** processor/box and task ID as well as the eventID. ** ** Assumptions and Notes: */ int32 CFE_EVS_SendEvent (uint16 EventID, uint16 EventType, const char *Spec, ... ) { int32 Status = CFE_SUCCESS; char BigBuf[CFE_EVS_MAX_MESSAGE_LENGTH]; char GTBigBuf[CFE_EVS_MAX_MESSAGE_LENGTH + 2]; va_list Ptr; CFE_EVS_Packet_t EVS_Packet; uint32 AppID = 0xFFFFFFFF; /* Handle Preset Return Code */ if (cfe_evs_api_return_value[CFE_EVS_SENDEVENT_PROC] != UTF_CFE_USE_DEFAULT_RETURN_CODE) { return cfe_evs_api_return_value[CFE_EVS_SENDEVENT_PROC]; } /* Get application identifier */ Status = CFE_ES_GetAppID(&AppID); if (Status == CFE_SUCCESS) { if(UTF_AppID_Registered == FALSE) { char warning_text[120]; strcpy (warning_text,"UTF WARNING: CFE_EVS_SendEvent called by application which is not "); strcat(warning_text,"registered for event services.\n"); /* if the application is not registered for event services do not perform event service */ UTF_put_text(warning_text); } /* Obtain task and system information */ /*EVS_Packet.PacketID.SpacecraftID = OS_BSPGetSpacecraftId();*/ CFE_ES_GetAppName(EVS_Packet.PacketID.AppName, AppID, OS_MAX_API_NAME); /* EVS_Packet.PacketID.ProcessorID = OS_BSPGetProcessorId();*/ EVS_Packet.PacketID.EventID = EventID; EVS_Packet.PacketID.EventType = EventType; /* Copy message to event packet if long format is enabled */ if (UTF_Long_Events_Enabled == TRUE) { va_start(Ptr, Spec); vsnprintf(GTBigBuf, CFE_EVS_MAX_MESSAGE_LENGTH +2, Spec, Ptr); va_end(Ptr); if(strlen(GTBigBuf) > CFE_EVS_MAX_MESSAGE_LENGTH) { UTF_put_text ("Max Event Message Size Exceeded. Permitted %d; Actual %d\n", CFE_EVS_MAX_MESSAGE_LENGTH, strlen(GTBigBuf)); } strncpy(BigBuf,GTBigBuf,CFE_EVS_MAX_MESSAGE_LENGTH); if (EventType == CFE_EVS_DEBUG) UTF_put_text("DEBUG EVENT ID=%d %s\n",EventID, BigBuf); else if (EventType == CFE_EVS_INFORMATION) UTF_put_text("INFO EVENT ID=%d %s\n",EventID, BigBuf); else if (EventType == CFE_EVS_ERROR) UTF_put_text("ERROR EVENT ID=%d %s\n",EventID, BigBuf); else if (EventType == CFE_EVS_CRITICAL) UTF_put_text("CRITICAL EVENT ID=%d %s\n",EventID, BigBuf); else UTF_put_text("Invalid Event Type %d ID=%d %s\n",EventType,EventID, BigBuf); } else { /* Send an empty message if short format is enabled */ strcpy(EVS_Packet.Message, "\0"); } return CFE_SUCCESS; } return Status; } /* End CFE_EVS_SendEvent */
/* ** Function: ** CFE_ES_GetPoolBuf ** ** Purpose: ** CFE_ES_GetPoolBuf allocates a block from the memory pool. */ int32 CFE_ES_GetPoolBuf(uint32 **BufPtr, CFE_ES_MemHandle_t Handle, uint32 Size ) { Pool_t * PoolPtr = (Pool_t *)Handle; uint32 Block; BD_t * BdPtr; uint32 AppId= 0xFFFFFFFF; if (PoolPtr != NULL) { if (Handle != (CFE_ES_MemHandle_t)PoolPtr->Start) { CFE_ES_GetAppID(&AppId); CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Bad handle(0x%08X) AppId=%d\n",Handle,AppId); return(CFE_ES_ERR_MEM_HANDLE); } } else { CFE_ES_GetAppID(&AppId); CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Bad handle(0x%08X) AppId=%d\n",Handle,AppId); return(CFE_ES_ERR_MEM_HANDLE); } if (PoolPtr->UseMutex == CFE_ES_USE_MUTEX) { OS_MutSemTake(PoolPtr->MutexId); } *BufPtr = NULL; Block = CFE_ES_GetBlockSize(PoolPtr, Size); if (Block == 0xFFFFFFFF) { CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:size(%d) > max(%d).\n",Size,PoolPtr->SizeDesc[0].MaxSize); if (PoolPtr->UseMutex == CFE_ES_USE_MUTEX) { OS_MutSemGive(PoolPtr->MutexId); } return(CFE_ES_ERR_MEM_BLOCK_SIZE); } /* ** Check if any of the requested size are available */ if (PoolPtr->SizeDescPtr->Top != NULL) /* Set by GetBlockSize call */ { /* ** Get it off the top on the list */ BdPtr = PoolPtr->SizeDescPtr->Top; BdPtr->CheckBits = CFE_ES_CHECK_PATTERN; BdPtr->Allocated = CFE_ES_MEMORY_ALLOCATED; /* Flag memory block as allocated */ BdPtr->Size = Block; PoolPtr->SizeDescPtr->Top = (BD_t *)BdPtr->Next; PoolPtr->SizeDescPtr->NumFree--; BdPtr->Next = NULL; *BufPtr = (uint32 *)(BdPtr + 1); } else /* go make one */ { BdPtr = (BD_t *)PoolPtr->Current; /* point to new memory block */ if ( ((uint32)BdPtr + sizeof(BD_t) + Block ) >= PoolPtr->End ){ /* can't fit in remaing mem */ CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Request won't fit in remaining memory\n"); if (PoolPtr->UseMutex == CFE_ES_USE_MUTEX) { OS_MutSemGive(PoolPtr->MutexId); } return(CFE_ES_ERR_MEM_BLOCK_SIZE); } PoolPtr->SizeDescPtr->NumCreated++; PoolPtr->RequestCntr++; /* ** create the buffer descriptor at the front of it */ BdPtr->CheckBits = CFE_ES_CHECK_PATTERN; BdPtr->Allocated = CFE_ES_MEMORY_ALLOCATED; /* Flag memory block as allocated */ BdPtr->Size = Block; BdPtr->Next = NULL; *BufPtr = (uint32 *)(BdPtr + 1); /* ** adjust pool current pointer */ PoolPtr->Current = (uint32 *)( (uint8 *)PoolPtr->Current + Block + sizeof(BD_t) ); } if (PoolPtr->UseMutex == CFE_ES_USE_MUTEX) { OS_MutSemGive(PoolPtr->MutexId); } return (int32)Block; }
/* ** Function: ** CFE_ES_GetPoolBuf ** ** Purpose: ** CFE_ES_GetPoolBuf allocates a block from the memory pool. */ int32 CFE_ES_GetPoolBuf(uint32 **BufPtr, CFE_ES_MemHandle_t HandlePtr, uint32 Size ) { Pool_t * PoolPtr = (Pool_t *)HandlePtr; uint32 Block; BD_t * BdPtr; uint32 AppId = 0xFFFFFFFF; /* OS_MutSemTake(PoolPtr->MutexId); */ /* Handle Preset Return Code */ if (cfe_es_api_return_value[CFE_ES_GETPOOLBUF_PROC] != UTF_CFE_USE_DEFAULT_RETURN_CODE) { return cfe_es_api_return_value[CFE_ES_GETPOOLBUF_PROC]; } /* Handle Function Hook */ if (UTF_ES_HookTable.CFE_ES_GetPoolBuf) return(UTF_ES_HookTable.CFE_ES_GetPoolBuf(BufPtr, HandlePtr, Size)); *BufPtr = NULL; CFE_ES_GetAppID(&AppId); if (HandlePtr != (CFE_ES_MemHandle_t)PoolPtr->Start) { CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Bad handle.AppId=%d\n",AppId); /* OS_MutSemGive(PoolPtr->MutexId); */ return(CFE_ES_ERR_MEM_HANDLE); } Block = CFE_ES_GetBlockSize(PoolPtr, Size); if (Block == 0xFFFFFFFF) { CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:size(%d) > max(%d).\n",Size,CFE_ES_MAX_BLOCK_SIZE); /* OS_MutSemGive(PoolPtr->MutexId); */ return(CFE_ES_ERR_MEM_BLOCK_SIZE); } /* ** Check if any of the requested size are available */ if (PoolPtr->SizeDescPtr->Top != NULL) /* Set by CFE_ES_GetBlockSize call */ { /* ** Get it off the top on the list */ BdPtr = PoolPtr->SizeDescPtr->Top; BdPtr->CheckBits = CFE_ES_CHECK_PATTERN; BdPtr->Allocated = CFE_ES_MEMORY_ALLOCATED; /* Flag memory block as allocated */ BdPtr->Size = Block; PoolPtr->SizeDescPtr->Top = (BD_t *)BdPtr->Next; PoolPtr->SizeDescPtr->NumFree--; BdPtr->Next = NULL; *BufPtr = (uint32 *)(BdPtr + 1); } else /* go make one */ { BdPtr = (BD_t *)PoolPtr->Current; /* point to new memory block */ if (((uint32)BdPtr + sizeof(BD_t) + Block) >= PoolPtr->End ) { /* can't fit in remaing mem */ CFE_ES_WriteToSysLog("CFE_ES:getPoolBuf err:Request won't fit in remaining memory\n"); /* OS_MutSemGive(PoolPtr->MutexId); */ return(CFE_ES_ERR_MEM_BLOCK_SIZE); } PoolPtr->SizeDescPtr->NumCreated++; PoolPtr->RequestCntr++; /* ** create the buffer descriptor at the front of it */ BdPtr->CheckBits = CFE_ES_CHECK_PATTERN; BdPtr->Allocated = CFE_ES_MEMORY_ALLOCATED; /* Flag memory block as allocated */ BdPtr->Size = Block; BdPtr->Next = NULL; *BufPtr = (uint32 *)(BdPtr + 1); /* ** adjust pool current pointer */ PoolPtr->Current = (uint32 *)( (uint8 *)PoolPtr->Current + Block + sizeof(BD_t) ); } /* OS_MutSemGive(PoolPtr->MutexId); */ return (int32)Block; }