/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int main(void) { char AppName[10]; UTF_SymbolTable_t UTF_Symbol; strcpy(AppName, "MM"); /* ** Set up to read in script */ UTF_add_input_file(MM_CMD_PIPE, "mm_utf_cmds.in"); MM_AppData.CmdPipe = MM_CMD_PIPE; /* Hook for application code */ /* ** Set up output file and HK packet handler */ UTF_set_output_filename("mm_utf_test.out"); UTF_set_packet_handler(MM_HK_TLM_MID, (utf_packet_handler)PrintHKPacket); /* ** Set up simulated memory for loads and dumps */ UTF_add_sim_address(SIM_RAM_MEM_ADDR, SIM_RAM_MEM_SIZE, "MM_RAM_ADDRESS_SPACE"); UTF_add_sim_address(SIM_EEPROM_MEM_ADDR, SIM_EEPROM_MEM_SIZE, "MM_EEPROM_ADDRESS_SPACE"); /* ** Add these ranges to the OSAL memory table so the CFE_PSP_MemValidateRange ** routine won't barf on them. We set these ranges much bigger than we're ** going to need so we can test bounds checking in MM and not ** CFE_PSP_MemValidateRange. */ CFE_PSP_MemRangeSet(0, CFE_PSP_MEM_RAM, SIM_RAM_MEM_ADDR, (MM_MAX_LOAD_FILE_DATA_RAM * 2), CFE_PSP_MEM_SIZE_BYTE, CFE_PSP_MEM_ATTR_READWRITE); CFE_PSP_MemRangeSet(1, CFE_PSP_MEM_EEPROM, SIM_EEPROM_MEM_ADDR, (MM_MAX_LOAD_FILE_DATA_EEPROM * 10), CFE_PSP_MEM_SIZE_BYTE, CFE_PSP_MEM_ATTR_READWRITE); /* ** Setup the UTF symbol table structures */ UTF_InitSymbolTable(); strcpy(UTF_Symbol.symbolName, "GoodSymName"); UTF_Symbol.symbolAddr = SIM_RAM_MEM_ADDR; UTF_SetSymbolTableEntry(UTF_Symbol); /* ** Initialize time data structures */ UTF_init_sim_time(0.0); UTF_OSAPI_set_function_hook(OS_GETLOCALTIME_HOOK, TimeHook); /* ** Initialize the PSP EEPROM Write Ena/Dis return status */ UTF_PSP_Set_Api_Return_Code(CFE_PSP_EEPROMWRITEENA_PROC, CFE_PSP_SUCCESS); UTF_PSP_Set_Api_Return_Code(CFE_PSP_EEPROMWRITEDIS_PROC, CFE_PSP_SUCCESS); /* ** Register app MM with executive services. */ UTF_ES_InitAppRecords(); UTF_ES_AddAppRecord("MM",0); CFE_ES_RegisterApp(); CFE_EVS_Register(NULL, 0, CFE_EVS_BINARY_FILTER); /* ** Initialize table services data structures, though we ** don't use any tables for these tests */ CFE_ES_CDS_EarlyInit(); CFE_TBL_EarlyInit(); /* ** Add an entry to the volume table */ UTF_add_volume("/", "ram", FS_BASED, FALSE, FALSE, TRUE, "RAM", "/ram", 0); /* ** Add this hook so we can force a software bus read error ** in our command input file that will make the application exit */ UTF_add_special_command("SET_SB_RETURN_CODE", UTF_SCRIPT_SB_Set_Api_Return_Code); UTF_add_special_command("SET_PSP_RETURN_CODE", UTF_SCRIPT_PSP_Set_Api_Return_Code); /* ** Initialize the CRC value for our test data set */ MM_TestDataSetCRC = CFE_ES_CalculateCRC(MM_TestDataSet, sizeof(MM_TestDataSet), 0, CFE_ES_DEFAULT_CRC); /* ** This is a function stub in cfs_utils.c that does nothing, but ** by calling it here we can increase our coverage statistics, so ** why not? */ CFS_LibInit(); /* ** Call test functions that invoke MM code directly */ printf("***UTF MM DRIVER TESTS START***\n\n"); UTF_put_text("\n"); UTF_put_text("***UTF MM DRIVER TESTS START***"); UTF_put_text("\n\n"); Test_Pokes(); Test_Peeks(); Test_LoadWID(); Test_DumpInEvent(); Test_LoadFromFile(); Test_DumpToFile(); Test_Fill(); Test_SymLookup(); Test_SymTblDump(); printf("***UTF MM DRIVER TESTS END***\n\n"); UTF_put_text("\n"); UTF_put_text("***UTF MM DRIVER TESTS END***"); UTF_put_text("\n\n"); /* ** Call Application Main procedure that will test command ** processing through the software bus command pipe via ** the mm_utf_cmds.in command script */ printf("***UTF MM CMD PIPE TESTS START***\n\n"); UTF_put_text("\n"); UTF_put_text("***UTF MM CMD PIPE TESTS START***"); UTF_put_text("\n\n"); MM_AppMain(); printf("***UTF MM CMD PIPE TESTS END***\n\n"); UTF_put_text("\n"); UTF_put_text("***UTF MM CMD PIPE TESTS END***"); UTF_put_text("\n\n"); /* ** These tests force some CFE api error returns ** during MM initialization. This increases ** the gcov coverage metrics for the app startup ** code. */ printf("***UTF MM APP INIT TESTS START***\n\n"); UTF_put_text("\n"); UTF_put_text("***UTF MM APP INIT TESTS START***"); UTF_put_text("\n\n"); UTF_put_text("\n"); UTF_put_text("Test App Init Error conditions \n"); UTF_put_text("-------------------------------\n"); /* ** Set trigger so CFE_EVS_Register returns something ** other than CFE_SUCCESS (0). Then call app main, this ** should make the app init fail. */ UTF_CFE_EVS_Set_Api_Return_Code(CFE_EVS_REGISTER_PROC, 0xc2000003L); MM_AppMain(); /* Go back to "normal" behavior */ UTF_CFE_EVS_Use_Default_Api_Return_Code(CFE_EVS_REGISTER_PROC); /* ** Set trigger so CFE_SB_CreatePipe returns an error code */ UTF_CFE_SB_Set_Api_Return_Code(CFE_SB_CREATEPIPE_PROC, 0xca000004L); MM_AppMain(); UTF_CFE_SB_Use_Default_Api_Return_Code(CFE_SB_CREATEPIPE_PROC); /* ** Set trigger so CFE_SB_Subscribe returns an error code */ UTF_CFE_SB_Set_Api_Return_Code(CFE_SB_SUBSCRIBE_PROC, 0xca000009L); MM_AppMain(); UTF_CFE_SB_Use_Default_Api_Return_Code(CFE_SB_SUBSCRIBE_PROC); /* ** Hook our own custom function to CFE_SB_Subscribe so we can ** trigger an error return on the SECOND call in MM_AppInit */ UTF_SB_set_function_hook(CFE_SB_SUBSCRIBE_HOOK, (void *)&CFE_SB_SubscribeHook); MM_AppMain(); printf("***UTF MM APP INIT TESTS END***\n\n"); UTF_put_text("\n"); UTF_put_text("***UTF MM APP INIT TESTS END***"); UTF_put_text("\n\n"); return 0; } /* end main */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ boolean CreateBigLoadFile(char FileName[], MM_LoadDumpFileHeader_t *MMFileHdr, int32 NumDataSets) { boolean Success = TRUE; int i; int FileHandle; int BytesWritten; CFE_FS_Header_t CFEFileHdr; uint32 CRCValue = 0; /* ** Calculate the overall CRC value for the number of data sets that ** we are going to write to the file */ for (i = 0; i < NumDataSets; i++) { CRCValue = CFE_ES_CalculateCRC(MM_TestDataSet, sizeof(MM_TestDataSet), CRCValue, CFE_ES_DEFAULT_CRC); } /* Set file header fields accordingly */ MMFileHdr -> NumOfBytes = (sizeof(MM_TestDataSet)* NumDataSets); MMFileHdr -> Crc = CRCValue; /* Open the file */ FileHandle = creat(FileName, 0755); if(FileHandle > -1) { /* ** Write the cFE primary file header, we don't care about the values ** since MM doesn't use them for anything so we zero them out. */ memset(&CFEFileHdr, 0, sizeof(CFE_FS_Header_t)); BytesWritten = write(FileHandle, &CFEFileHdr, sizeof(CFE_FS_Header_t)); if(BytesWritten != sizeof(CFE_FS_Header_t)) { printf("!!ERROR Writing Load File cFE Header, wrote: %d, expected: %d \n", BytesWritten, sizeof(CFE_FS_Header_t)); Success = FALSE; close(FileHandle); } else { /* ** Write the MM secondary file header */ BytesWritten = write(FileHandle, MMFileHdr, sizeof(MM_LoadDumpFileHeader_t)); if(BytesWritten != sizeof(MM_LoadDumpFileHeader_t)) { printf("!!ERROR Writing Load File MM Header, wrote: %d, expected: %d \n", BytesWritten, sizeof(MM_LoadDumpFileHeader_t)); Success = FALSE; close(FileHandle); } else { /* ** Write the data set segments */ for (i = 0; i < NumDataSets; i++) { BytesWritten = write(FileHandle, MM_TestDataSet, sizeof(MM_TestDataSet)); if(BytesWritten != sizeof(MM_TestDataSet)) { printf("!!ERROR Writing Big Load File, segment: %d, wrote: %d, expected: %d \n", i, BytesWritten, sizeof(MM_TestDataSet)); Success = FALSE; close(FileHandle); break; } } /* end for */ close(FileHandle); } /* end BytesWritten != sizeof(MM_LoadDumpFileHeader_t) else */ } /* end BytesWritten != sizeof(CFE_FS_Header_t) else */ } /* end FileHandle > -1 if */ else { printf("!!ERROR <CreateBigLoadFile> Creating Load File, RC: %d \n", FileHandle); Success = FALSE; } return(Success); } /* end CreateBigLoadFile */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 CS_ComputeEepromMemory (CS_Res_EepromMemory_Table_Entry_t * ResultsEntry, uint32 * ComputedCSValue, boolean * DoneWithEntry) { uint32 OffsetIntoCurrEntry = 0; uint32 FirstAddrThisCycle = 0; uint32 NumBytesThisCycle = 0; int32 NumBytesRemainingCycles = 0; uint32 NewChecksumValue = 0; int32 Status = CS_SUCCESS; /* By the time we get here, we know we have an enabled entry */ OffsetIntoCurrEntry = ResultsEntry -> ByteOffset; FirstAddrThisCycle = ResultsEntry -> StartAddress + OffsetIntoCurrEntry; NumBytesRemainingCycles = ResultsEntry -> NumBytesToChecksum - OffsetIntoCurrEntry; NumBytesThisCycle = ( (CS_AppData.MaxBytesPerCycle < NumBytesRemainingCycles) ? CS_AppData.MaxBytesPerCycle : NumBytesRemainingCycles); NewChecksumValue = CFE_ES_CalculateCRC((void *) ((uint8*)FirstAddrThisCycle), NumBytesThisCycle, ResultsEntry -> TempChecksumValue, CS_DEFAULT_ALGORITHM); NumBytesRemainingCycles -= NumBytesThisCycle; if (NumBytesRemainingCycles <= 0) { /* We are finished CS'ing all of the parts for this Entry */ *DoneWithEntry = TRUE; if (ResultsEntry -> ComputedYet == TRUE) { /* This is NOT the first time through this Entry. We have already computed a CS value for this Entry */ if (NewChecksumValue != ResultsEntry -> ComparisonValue) { /* If the just-computed value differ from the saved value */ Status = CS_ERROR; } else { /* The checksum passes the test. */ } } else { /* This is the first time through this Entry */ ResultsEntry -> ComputedYet = TRUE; ResultsEntry -> ComparisonValue = NewChecksumValue; } *ComputedCSValue = NewChecksumValue; ResultsEntry -> ByteOffset = 0; ResultsEntry -> TempChecksumValue = 0; } else { /* We not finished this Entry. Will try to finish during next wakeup */ ResultsEntry -> ByteOffset += NumBytesThisCycle; ResultsEntry -> TempChecksumValue = NewChecksumValue; } return Status; } /* End of CS_ComputeEepromMemory () */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void CS_OneShotChildTask(void) { uint32 NewChecksumValue = 0; int32 Status = -1; /* Init to OS error */ uint32 NumBytesRemainingCycles = 0; uint32 NumBytesThisCycle = 0; uint32 FirstAddrThisCycle = 0; Status = CFE_ES_RegisterChildTask(); if (Status == CFE_SUCCESS) { NewChecksumValue = 0; NumBytesRemainingCycles = CS_AppData.LastOneShotSize; FirstAddrThisCycle = CS_AppData.LastOneShotAddress; while (NumBytesRemainingCycles > 0) { NumBytesThisCycle = ( (CS_AppData.MaxBytesPerCycle < NumBytesRemainingCycles) ? CS_AppData.MaxBytesPerCycle : NumBytesRemainingCycles); NewChecksumValue = CFE_ES_CalculateCRC((void *) ((uint8*)FirstAddrThisCycle), NumBytesThisCycle, NewChecksumValue, CS_DEFAULT_ALGORITHM); /* Update the remainders for the next cycle */ FirstAddrThisCycle += NumBytesThisCycle; NumBytesRemainingCycles -= NumBytesThisCycle; OS_TaskDelay(CS_CHILD_TASK_DELAY); } /*Checksum Calculation is done! */ /* put the new checksum value in the baseline */ CS_AppData.LastOneShotChecksum = NewChecksumValue; /* send event message */ CFE_EVS_SendEvent (CS_ONESHOT_FINISHED_INF_EID, CFE_EVS_INFORMATION, "OneShot checksum on Address: 0x%08X, size %d completed. Checksum = 0x%08X", CS_AppData.LastOneShotAddress, CS_AppData.LastOneShotSize, CS_AppData.LastOneShotChecksum); }/*end if register child task*/ else { /* Can't send event or write to syslog because this task isn't registered with the cFE. */ OS_printf("OneShot Child Task Registration failed!\n"); } CS_AppData.ChildTaskInUse = FALSE; CS_AppData.OneShotTaskInUse = FALSE; CS_AppData.ChildTaskID = 0; CFE_ES_ExitChildTask(); return; }/* end CS_OneShotChildTask */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 CS_ComputeApp (CS_Res_App_Table_Entry_t * ResultsEntry, uint32 * ComputedCSValue, boolean * DoneWithEntry) { uint32 OffsetIntoCurrEntry = 0; uint32 FirstAddrThisCycle = 0; uint32 NumBytesThisCycle = 0; int32 NumBytesRemainingCycles = 0; uint32 NewChecksumValue = 0; int32 Status = CS_SUCCESS; int32 Result; int32 ResultGetAppID = CS_ERROR; int32 ResultGetAppInfo = CS_ERROR; int32 ResultAddressValid = FALSE; /* variables to get applications address */ uint32 AppID = 0; CFE_ES_AppInfo_t AppInfo; /* By the time we get here, we know we have an enabled entry */ /* set the done flag to false originally */ * DoneWithEntry = FALSE; ResultGetAppID = CFE_ES_GetAppIDByName(&AppID, ResultsEntry -> Name); Result = ResultGetAppID; if (Result == CFE_SUCCESS) { /* We got a valid AppID, so get the App info */ ResultGetAppInfo = CFE_ES_GetAppInfo(&AppInfo, AppID); Result = ResultGetAppInfo; } if (Result == CFE_SUCCESS) { /* We got a valid AppID and good App info, so check the for valid addresses */ if (AppInfo.AddressesAreValid == FALSE) { CFE_EVS_SendEvent(CS_COMPUTE_APP_PLATFORM_DBG_EID, CFE_EVS_DEBUG, "CS cannot get a valid address for %s, due to the platform",ResultsEntry -> Name); ResultAddressValid = FALSE; Result = CS_ERROR; } else { /* Push in the data from the module info */ ResultsEntry -> NumBytesToChecksum = AppInfo.CodeSize; ResultsEntry -> StartAddress = AppInfo.CodeAddress; Result = CFE_SUCCESS; ResultAddressValid = TRUE; } } if (Result == CFE_SUCCESS) { /* We got valid AppID, good info, and valid addresses, so run the checksum */ OffsetIntoCurrEntry = ResultsEntry -> ByteOffset; FirstAddrThisCycle = ResultsEntry -> StartAddress + OffsetIntoCurrEntry; NumBytesRemainingCycles = ResultsEntry -> NumBytesToChecksum - OffsetIntoCurrEntry; NumBytesThisCycle = ( (CS_AppData.MaxBytesPerCycle < NumBytesRemainingCycles) ? CS_AppData.MaxBytesPerCycle : NumBytesRemainingCycles); NewChecksumValue = CFE_ES_CalculateCRC((void *) ((uint8*)FirstAddrThisCycle), NumBytesThisCycle, ResultsEntry -> TempChecksumValue, CS_DEFAULT_ALGORITHM); NumBytesRemainingCycles -= NumBytesThisCycle; if (NumBytesRemainingCycles <= 0) { /* We are finished CS'ing all of the parts for this Entry */ *DoneWithEntry = TRUE; if (ResultsEntry -> ComputedYet == TRUE) { /* This is NOT the first time through this Entry. We have already computed a CS value for this Entry */ if (NewChecksumValue != ResultsEntry -> ComparisonValue) { /* If the just-computed value differ from the saved value */ Status = CS_ERROR; } else { /* The checksum passes the test. */ } } else { /* This is the first time through this Entry */ ResultsEntry -> ComputedYet = TRUE; ResultsEntry -> ComparisonValue = NewChecksumValue; } *ComputedCSValue = NewChecksumValue; ResultsEntry -> ByteOffset = 0; ResultsEntry -> TempChecksumValue = 0; } else { /* We have not finished this Entry. Will try to finish during next wakeup */ ResultsEntry -> ByteOffset += NumBytesThisCycle; ResultsEntry -> TempChecksumValue = NewChecksumValue; *ComputedCSValue = NewChecksumValue; } }/* end if got module id ok */ else { /* Something failed -- either invalid AppID, bad App info, or invalid addresses, so notify ground */ CFE_EVS_SendEvent(CS_COMPUTE_APP_ERR_EID, CFE_EVS_ERROR, "CS Apps: Problems getting app %s info, GetAppID: 0x%08X, GetAppInfo: 0x%08X, AddressValid: %d", ResultsEntry -> Name, ResultGetAppID, ResultGetAppInfo, ResultAddressValid); Status = CS_ERR_NOT_FOUND; } return Status; } /* End of CS_ComputeApp () */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 CS_ComputeTables (CS_Res_Tables_Table_Entry_t * ResultsEntry, uint32 * ComputedCSValue, boolean * DoneWithEntry) { uint32 OffsetIntoCurrEntry = 0; uint32 FirstAddrThisCycle = 0; uint32 NumBytesThisCycle = 0; int32 NumBytesRemainingCycles = 0; uint32 NewChecksumValue = 0; int32 Status = CS_SUCCESS; int32 Result = CS_SUCCESS; int32 ResultShare = 0; int32 ResultGetInfo = 0; int32 ResultGetAddress = 0; /* variables to get the table address */ CFE_TBL_Handle_t LocalTblHandle = CFE_TBL_BAD_TABLE_HANDLE; uint32 LocalAddress = 0; CFE_TBL_Info_t TblInfo; /* By the time we get here, we know we have an enabled entry */ /* set the done flag to false originally */ * DoneWithEntry = FALSE; Result = CS_SUCCESS; /* Handshake with Table Services to get address and size of table */ /* if we already have a table handle for this table, don't get a new one */ if (ResultsEntry -> TblHandle == CFE_TBL_BAD_TABLE_HANDLE) { ResultShare = CFE_TBL_Share(&LocalTblHandle, ResultsEntry -> Name); Result = ResultShare; if (Result == CFE_SUCCESS) { ResultsEntry -> TblHandle = LocalTblHandle; } } else { LocalTblHandle = ResultsEntry -> TblHandle; } if (Result == CFE_SUCCESS) { ResultGetInfo = CFE_TBL_GetInfo(&TblInfo, ResultsEntry -> Name); } /* We want to try to to get the address even if the GetInfo fails. This provides the CFE_TBL_UNREGISTERED if the table has gone away */ if (Result == CFE_SUCCESS) { ResultGetAddress = CFE_TBL_GetAddress((void*) &LocalAddress, LocalTblHandle); Result = ResultGetAddress; } /* if the table was never loaded, release the address to prevent the table from being locked by CS, which would prevent the owner app from updating it*/ if ( ResultGetAddress == CFE_TBL_ERR_NEVER_LOADED) { CFE_TBL_ReleaseAddress(LocalTblHandle); } /* The table has dissapeared since the last time CS looked. We are checking to see if the table came back */ if (Result == CFE_TBL_ERR_UNREGISTERED) { /* unregister the old handle */ CFE_TBL_Unregister(LocalTblHandle); /* reset the stored data in the results table since the table went away */ ResultsEntry -> TblHandle = CFE_TBL_BAD_TABLE_HANDLE; ResultsEntry -> ByteOffset = 0; ResultsEntry -> TempChecksumValue = 0; ResultsEntry -> ComputedYet = FALSE; ResultsEntry -> ComparisonValue = 0; ResultsEntry -> StartAddress = 0; ResultsEntry -> NumBytesToChecksum = 0; /* Maybe the table came back, try and reshare it */ ResultShare = CFE_TBL_Share(&LocalTblHandle, ResultsEntry -> Name); if (ResultShare == CFE_SUCCESS) { ResultsEntry -> TblHandle = LocalTblHandle; ResultGetInfo = CFE_TBL_GetInfo(&TblInfo, ResultsEntry -> Name); /* need to try to get the address again */ ResultGetAddress = CFE_TBL_GetAddress((void*) &LocalAddress, LocalTblHandle); Result = ResultGetAddress; /* if the table was never loaded, release the address to prevent the table from being locked by CS, which would prevent the owner app from updating it*/ if ( ResultGetAddress == CFE_TBL_ERR_NEVER_LOADED) { CFE_TBL_ReleaseAddress(LocalTblHandle); } } else /* table was not there on the new share */ { Result = ResultShare; } } if (Result == CFE_SUCCESS || Result == CFE_TBL_INFO_UPDATED) { /* push in the get data from the table info */ ResultsEntry -> NumBytesToChecksum = TblInfo.Size; ResultsEntry -> StartAddress = LocalAddress; /* if the table has been updated since the last time we looked at it, we need to start over again. We can also use the new value as a baseline checksum */ if (Result == CFE_TBL_INFO_UPDATED) { ResultsEntry -> ByteOffset = 0; ResultsEntry -> TempChecksumValue = 0; ResultsEntry -> ComputedYet = FALSE; } OffsetIntoCurrEntry = ResultsEntry -> ByteOffset; FirstAddrThisCycle = ResultsEntry -> StartAddress + OffsetIntoCurrEntry; NumBytesRemainingCycles = ResultsEntry -> NumBytesToChecksum - OffsetIntoCurrEntry; NumBytesThisCycle = ( (CS_AppData.MaxBytesPerCycle < NumBytesRemainingCycles) ? CS_AppData.MaxBytesPerCycle : NumBytesRemainingCycles); NewChecksumValue = CFE_ES_CalculateCRC((void *) ((uint8*)FirstAddrThisCycle), NumBytesThisCycle, ResultsEntry -> TempChecksumValue, CS_DEFAULT_ALGORITHM); NumBytesRemainingCycles -= NumBytesThisCycle; /* Have we finished all of the parts for this Entry */ if (NumBytesRemainingCycles <= 0) { /* Start over if an update occurred after we started the last part */ CFE_TBL_ReleaseAddress(LocalTblHandle); Result = CFE_TBL_GetAddress((void*) &LocalAddress, LocalTblHandle); if (Result == CFE_TBL_INFO_UPDATED) { *ComputedCSValue = 0; ResultsEntry -> ComputedYet = FALSE; ResultsEntry -> ComparisonValue = 0; ResultsEntry -> ByteOffset = 0; ResultsEntry -> TempChecksumValue = 0; } else { /* No last second updates, post the result for this table */ *DoneWithEntry = TRUE; if (ResultsEntry -> ComputedYet == TRUE) { /* This is NOT the first time through this Entry. We have already computed a CS value for this Entry */ if (NewChecksumValue != ResultsEntry -> ComparisonValue) { /* If the just-computed value differ from the saved value */ Status = CS_ERROR; } else { /* The checksum passes the test. */ } } else { /* This is the first time through this Entry */ ResultsEntry -> ComputedYet = TRUE; ResultsEntry -> ComparisonValue = NewChecksumValue; } *ComputedCSValue = NewChecksumValue; ResultsEntry -> ByteOffset = 0; ResultsEntry -> TempChecksumValue = 0; } } else { /* We have not finished this Entry. Will try to finish during next wakeup */ ResultsEntry -> ByteOffset += NumBytesThisCycle; ResultsEntry -> TempChecksumValue = NewChecksumValue; *ComputedCSValue = NewChecksumValue; } /* We are done with the table for this cycle, so we need to release the address */ Result = CFE_TBL_ReleaseAddress(LocalTblHandle); if (Result != CFE_SUCCESS) { CFE_EVS_SendEvent(CS_COMPUTE_TABLES_RELEASE_ERR_EID, CFE_EVS_ERROR, "CS Tables: Could not release addresss for table %s, returned: 0x%08X", ResultsEntry -> Name, Result); } }/* end if tabled was success or updated */ else { CFE_EVS_SendEvent(CS_COMPUTE_TABLES_ERR_EID, CFE_EVS_ERROR, "CS Tables: Problem Getting table %s info Share: 0x%08X, GetInfo: 0x%08X, GetAddress: 0x%08X", ResultsEntry -> Name, ResultShare, ResultGetInfo, ResultGetAddress); Status = CS_ERR_NOT_FOUND; } return Status; } /* End of CS_ComputeTables () */
/* ** Function: ** CFE_ES_CDSBlockRead ** ** Purpose: ** */ int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSBlockHandle_t BlockHandle) { int32 Status = CFE_SUCCESS; uint32 CrcOfCDSData; int32 BinIndex; /* Validate the handle before doing anything */ if ((BlockHandle < sizeof(CFE_ES_Global.CDSVars.ValidityField)) || (BlockHandle > (CFE_ES_CDSMemPool.End - sizeof(CFE_ES_CDSBlockDesc_t) - CFE_ES_CDSMemPool.MinBlockSize - sizeof(CFE_ES_Global.CDSVars.ValidityField)))) { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkRd-Invalid Memory Handle.\n"); return(CFE_ES_ERR_MEM_HANDLE); } OS_MutSemTake(CFE_ES_CDSMemPool.MutexId); /* Get a copy of the block descriptor associated with the specified handle */ /* Read the block descriptor for the first block in the memory pool */ Status = CFE_PSP_ReadFromCDS(&CFE_ES_CDSBlockDesc, BlockHandle, sizeof(CFE_ES_CDSBlockDesc_t)); if (Status == OS_SUCCESS) { /* Validate the block to make sure it is still active and not corrupted */ if ((CFE_ES_CDSBlockDesc.CheckBits != CFE_ES_CDS_CHECK_PATTERN) || (CFE_ES_CDSBlockDesc.AllocatedFlag != CFE_ES_CDS_BLOCK_USED)) { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkRd-Invalid Handle or Block Descriptor.\n"); OS_MutSemGive(CFE_ES_CDSMemPool.MutexId); return(CFE_ES_ERR_MEM_HANDLE); } BinIndex = CFE_ES_CDSGetBinIndex(CFE_ES_CDSBlockDesc.ActualSize); /* Final sanity check on block descriptor, is the Actual size reasonable */ if (BinIndex < 0) { CFE_ES_CDSMemPool.CheckErrCntr++; CFE_ES_WriteToSysLog("CFE_ES:CDSBlkRd-Invalid Block Descriptor\n"); OS_MutSemGive(CFE_ES_CDSMemPool.MutexId); return(CFE_ES_ERR_MEM_HANDLE); } /* Read the old data block */ Status = CFE_PSP_ReadFromCDS(DataRead, (BlockHandle + sizeof(CFE_ES_CDSBlockDesc_t)), CFE_ES_CDSBlockDesc.SizeUsed); if (Status == OS_SUCCESS) { /* Compute the CRC for the data read from the CDS and determine if the data is still valid */ CrcOfCDSData = CFE_ES_CalculateCRC(DataRead, CFE_ES_CDSBlockDesc.SizeUsed, 0, CFE_ES_DEFAULT_CRC); /* If the CRCs do not match, report an error */ if (CrcOfCDSData != CFE_ES_CDSBlockDesc.CRC) { Status = CFE_ES_CDS_BLOCK_CRC_ERR; } else { Status = CFE_SUCCESS; } } else { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkRd-Err reading block from CDS (Stat=0x%08x) @Offset=0x%08x\n", Status, BlockHandle); } } else { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkRd-Err reading from CDS (Stat=0x%08x)\n", Status); } OS_MutSemGive(CFE_ES_CDSMemPool.MutexId); return Status; }
/* ** Function: ** CFE_ES_CDSBlockWrite ** ** Purpose: ** */ int32 CFE_ES_CDSBlockWrite(CFE_ES_CDSBlockHandle_t BlockHandle, void *DataToWrite) { int32 Status = CFE_SUCCESS; int32 BinIndex = 0; /* Validate the handle before doing anything */ if ((BlockHandle < sizeof(CFE_ES_Global.CDSVars.ValidityField)) || (BlockHandle > (CFE_ES_CDSMemPool.End - sizeof(CFE_ES_CDSBlockDesc_t) - CFE_ES_CDSMemPool.MinBlockSize - sizeof(CFE_ES_Global.CDSVars.ValidityField)))) { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkWrite-Invalid Memory Handle.\n"); return(CFE_ES_ERR_MEM_HANDLE); } OS_MutSemTake(CFE_ES_CDSMemPool.MutexId); /* Get a copy of the block descriptor associated with the specified handle */ /* Read the block descriptor for the first block in the memory pool */ Status = CFE_PSP_ReadFromCDS(&CFE_ES_CDSBlockDesc, BlockHandle, sizeof(CFE_ES_CDSBlockDesc_t)); if (Status == OS_SUCCESS) { /* Validate the block to make sure it is still active and not corrupted */ if ((CFE_ES_CDSBlockDesc.CheckBits != CFE_ES_CDS_CHECK_PATTERN) || (CFE_ES_CDSBlockDesc.AllocatedFlag != CFE_ES_CDS_BLOCK_USED)) { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkWrite-Invalid Handle or Block Descriptor.\n"); OS_MutSemGive(CFE_ES_CDSMemPool.MutexId); return(CFE_ES_ERR_MEM_HANDLE); } BinIndex = CFE_ES_CDSGetBinIndex(CFE_ES_CDSBlockDesc.ActualSize); /* Final sanity check on block descriptor, is the Actual size reasonable */ if (BinIndex < 0) { CFE_ES_CDSMemPool.CheckErrCntr++; CFE_ES_WriteToSysLog("CFE_ES:CDSBlkWrite-Invalid Block Descriptor\n"); OS_MutSemGive(CFE_ES_CDSMemPool.MutexId); return(CFE_ES_ERR_MEM_HANDLE); } /* Use the size specified when the CDS was created to compute the CRC */ CFE_ES_CDSBlockDesc.CRC = CFE_ES_CalculateCRC(DataToWrite, CFE_ES_CDSBlockDesc.SizeUsed, 0, CFE_ES_DEFAULT_CRC); /* Write the new block descriptor for the data coming from the Application */ Status = CFE_PSP_WriteToCDS(&CFE_ES_CDSBlockDesc, BlockHandle, sizeof(CFE_ES_CDSBlockDesc_t)); if (Status == OS_SUCCESS) { /* Write the new data coming from the Application to the CDS */ Status = CFE_PSP_WriteToCDS(DataToWrite, (BlockHandle + sizeof(CFE_ES_CDSBlockDesc_t)), CFE_ES_CDSBlockDesc.SizeUsed); if (Status != OS_SUCCESS) { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkWrite-Err writing data to CDS (Stat=0x%08x) @Offset=0x%08x\n", Status, (BlockHandle + sizeof(CFE_ES_CDSBlockDesc_t))); } } else { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkWrite-Err writing BlockDesc to CDS (Stat=0x%08x) @Offset=0x%08x\n", Status, BlockHandle); } } else { CFE_ES_WriteToSysLog("CFE_ES:CDSBlkWrite-Err reading from CDS (Stat=0x%08x)\n", Status); } OS_MutSemGive(CFE_ES_CDSMemPool.MutexId); return Status; }
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void Test_LoadWID(void) { MM_LoadMemWIDCmd_t CmdMsg; uint32 LocalCrc; /* Setup the test message header */ CFE_SB_InitMsg(&CmdMsg, MM_CMD_MID, sizeof(MM_LoadMemWIDCmd_t), TRUE); /* ** Setup the load data array in the command message with the ** maximum amount of data allowed. */ memcpy(CmdMsg.DataArray, MM_TestDataSet, MM_MAX_UNINTERRUPTABLE_DATA); /* Compute the CRC value */ LocalCrc = CFE_ES_CalculateCRC(MM_TestDataSet, MM_MAX_UNINTERRUPTABLE_DATA, 0, CFE_ES_DEFAULT_CRC); UTF_put_text("**********************************************\n"); UTF_put_text("* Memory Load With Interrupts Disabled Tests *\n"); UTF_put_text("**********************************************\n"); UTF_put_text("\n"); /* ** Test bad symbol name */ UTF_put_text("Test Load WID With Bad Symbol Name \n"); UTF_put_text("-----------------------------------\n"); strcpy(CmdMsg.DestSymAddress.SymName, "BadSymName"); CmdMsg.DestSymAddress.Offset = 0; CmdMsg.NumOfBytes = MM_MAX_UNINTERRUPTABLE_DATA; CmdMsg.Crc = LocalCrc; MM_LoadMemWIDCmd((CFE_SB_MsgPtr_t)&CmdMsg); PrintLocalHKVars(); UTF_put_text("\n"); /* ** Test bad address */ UTF_put_text("Test Load WID With Bad Address \n"); UTF_put_text("-------------------------------\n"); CmdMsg.DestSymAddress.SymName[0] = '\0'; CmdMsg.DestSymAddress.Offset = SIM_BAD_MEM_ADDR; CmdMsg.NumOfBytes = MM_MAX_UNINTERRUPTABLE_DATA; CmdMsg.Crc = LocalCrc; MM_LoadMemWIDCmd((CFE_SB_MsgPtr_t)&CmdMsg); PrintLocalHKVars(); UTF_put_text("\n"); /* ** Test bad CRC value */ UTF_put_text("Test Load WID With Bad CRC value \n"); UTF_put_text("---------------------------------\n"); CmdMsg.DestSymAddress.SymName[0] = '\0'; CmdMsg.DestSymAddress.Offset = SIM_RAM_MEM_ADDR; CmdMsg.NumOfBytes = MM_MAX_UNINTERRUPTABLE_DATA; CmdMsg.Crc = LocalCrc ^ 0xF0F0F0F0; MM_LoadMemWIDCmd((CFE_SB_MsgPtr_t)&CmdMsg); PrintLocalHKVars(); UTF_put_text("\n"); /* ** Test data size that exceeds configuration limits */ UTF_put_text("Test Load WID That Exceeds Configuration Limits \n"); UTF_put_text("------------------------------------------------\n"); CmdMsg.DestSymAddress.SymName[0] = '\0'; CmdMsg.DestSymAddress.Offset = SIM_RAM_MEM_ADDR; CmdMsg.NumOfBytes = 0xFF; CmdMsg.Crc = LocalCrc; MM_LoadMemWIDCmd((CFE_SB_MsgPtr_t)&CmdMsg); PrintLocalHKVars(); UTF_put_text("\n"); /* ** Test zero byte load */ UTF_put_text("Test Load WID With Zero Data Specified \n"); UTF_put_text("---------------------------------------\n"); CmdMsg.DestSymAddress.SymName[0] = '\0'; CmdMsg.DestSymAddress.Offset = SIM_RAM_MEM_ADDR; CmdMsg.NumOfBytes = 0; CmdMsg.Crc = 0; MM_LoadMemWIDCmd((CFE_SB_MsgPtr_t)&CmdMsg); PrintLocalHKVars(); UTF_put_text("\n"); /* ** Test valid load of maximum size */ UTF_put_text("Test Valid Load WID of Maximum Size \n"); UTF_put_text("------------------------------------\n"); CmdMsg.DestSymAddress.SymName[0] = '\0'; CmdMsg.DestSymAddress.Offset = SIM_RAM_MEM_ADDR; CmdMsg.NumOfBytes = MM_MAX_UNINTERRUPTABLE_DATA; CmdMsg.Crc = LocalCrc; MM_LoadMemWIDCmd((CFE_SB_MsgPtr_t)&CmdMsg); PrintLocalHKVars(); UTF_put_text("\n"); /* ** Test valid load less than maximum size */ UTF_put_text("Test Valid Load WID Less Than Maximum Size \n"); UTF_put_text("-------------------------------------------\n"); CmdMsg.DestSymAddress.SymName[0] = '\0'; CmdMsg.DestSymAddress.Offset = SIM_RAM_MEM_ADDR; CmdMsg.NumOfBytes = 100; CmdMsg.Crc = CFE_ES_CalculateCRC(MM_TestDataSet, 100, 0, CFE_ES_DEFAULT_CRC); MM_LoadMemWIDCmd((CFE_SB_MsgPtr_t)&CmdMsg); PrintLocalHKVars(); UTF_put_text("\n"); } /* end Test_LoadWID */