diff --git a/fsw/src/mm_app.c b/fsw/src/mm_app.c index 146a483..c4267de 100644 --- a/fsw/src/mm_app.c +++ b/fsw/src/mm_app.c @@ -170,7 +170,8 @@ CFE_Status_t MM_AppInit(void) Status = CFE_SB_CreatePipe(&MM_AppData.CmdPipe, MM_CMD_PIPE_DEPTH, "MM_CMD_PIPE"); if (Status != CFE_SUCCESS) { - CFE_EVS_SendEvent(MM_CR_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, "Error Creating SB Pipe, RC = 0x%08X", (unsigned int)Status); + CFE_EVS_SendEvent(MM_CR_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, "Error Creating SB Pipe, RC = 0x%08X", + (unsigned int)Status); return Status; } @@ -332,7 +333,7 @@ void MM_AppPipe(const CFE_SB_Buffer_t *BufPtr) } break; - case MM_ENABLE_EEPROM_WRITE_CC: + case MM_ENABLE_EEPROM_WRITE_CC: if (MM_VerifyCmdLength(&BufPtr->Msg, sizeof(MM_EepromWriteEnaCmd_t))) { CmdResult = MM_EepromWriteEnaCmd(BufPtr); @@ -386,15 +387,15 @@ void MM_AppPipe(const CFE_SB_Buffer_t *BufPtr) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void MM_HousekeepingCmd(const CFE_SB_Buffer_t *BufPtr) { - /* - ** Send housekeeping telemetry packet - */ - CFE_SB_TimeStampMsg(&MM_AppData.HkPacket.TlmHeader.Msg); - CFE_SB_TransmitMsg(&MM_AppData.HkPacket.TlmHeader.Msg, true); + /* + ** Send housekeeping telemetry packet + */ + CFE_SB_TimeStampMsg(&MM_AppData.HkPacket.TlmHeader.Msg); + CFE_SB_TransmitMsg(&MM_AppData.HkPacket.TlmHeader.Msg, true); - /* - ** This command does not affect the command execution counter - */ + /* + ** This command does not affect the command execution counter + */ } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -404,12 +405,12 @@ void MM_HousekeepingCmd(const CFE_SB_Buffer_t *BufPtr) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ bool MM_NoopCmd(const CFE_SB_Buffer_t *BufPtr) { - bool Result = false; - MM_AppData.HkPacket.Payload.LastAction = MM_NOOP; - Result = true; + bool Result = false; + MM_AppData.HkPacket.Payload.LastAction = MM_NOOP; + Result = true; - CFE_EVS_SendEvent(MM_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "No-op command. Version %d.%d.%d.%d", - MM_MAJOR_VERSION, MM_MINOR_VERSION, MM_REVISION, MM_MISSION_REV); + CFE_EVS_SendEvent(MM_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "No-op command. Version %d.%d.%d.%d", + MM_MAJOR_VERSION, MM_MINOR_VERSION, MM_REVISION, MM_MISSION_REV); return Result; } @@ -421,13 +422,13 @@ bool MM_NoopCmd(const CFE_SB_Buffer_t *BufPtr) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ bool MM_ResetCmd(const CFE_SB_Buffer_t *BufPtr) { - bool Result = false; - MM_AppData.HkPacket.Payload.LastAction = MM_RESET; - MM_AppData.HkPacket.Payload.CmdCounter = 0; - MM_AppData.HkPacket.Payload.ErrCounter = 0; + bool Result = false; + MM_AppData.HkPacket.Payload.LastAction = MM_RESET; + MM_AppData.HkPacket.Payload.CmdCounter = 0; + MM_AppData.HkPacket.Payload.ErrCounter = 0; - CFE_EVS_SendEvent(MM_RESET_INF_EID, CFE_EVS_EventType_INFORMATION, "Reset counters command received"); - Result = true; + CFE_EVS_SendEvent(MM_RESET_INF_EID, CFE_EVS_EventType_INFORMATION, "Reset counters command received"); + Result = true; return Result; } @@ -441,46 +442,46 @@ bool MM_LookupSymbolCmd(const CFE_SB_Buffer_t *BufPtr) { int32 OS_Status = OS_ERROR; /* Set to error instead of success since we explicitly test for success */ cpuaddr ResolvedAddr = 0; - const MM_LookupSymCmd_t *CmdPtr = NULL; - bool Result = false; + const MM_LookupSymCmd_t *CmdPtr = NULL; + bool Result = false; char SymName[OS_MAX_SYM_LEN]; - CmdPtr = ((MM_LookupSymCmd_t *)BufPtr); + CmdPtr = ((MM_LookupSymCmd_t *)BufPtr); - /* Make sure string is null terminated before attempting to process it */ - CFE_SB_MessageStringGet(SymName, CmdPtr->Payload.SymName, NULL, sizeof(SymName), sizeof(CmdPtr->Payload.SymName)); + /* Make sure string is null terminated before attempting to process it */ + CFE_SB_MessageStringGet(SymName, CmdPtr->Payload.SymName, NULL, sizeof(SymName), sizeof(CmdPtr->Payload.SymName)); + /* + ** Check if the symbol name string is a nul string + */ + if (strlen(SymName) == 0) + { + CFE_EVS_SendEvent(MM_SYMNAME_NUL_ERR_EID, CFE_EVS_EventType_ERROR, + "NUL (empty) string specified as symbol name"); + } + else + { /* - ** Check if the symbol name string is a nul string + ** If symbol name is not an empty string look it up using the OSAL API */ - if (strlen(SymName) == 0) + OS_Status = OS_SymbolLookup(&ResolvedAddr, SymName); + if (OS_Status == OS_SUCCESS) { - CFE_EVS_SendEvent(MM_SYMNAME_NUL_ERR_EID, CFE_EVS_EventType_ERROR, - "NUL (empty) string specified as symbol name"); + /* Update telemetry */ + MM_AppData.HkPacket.Payload.LastAction = MM_SYM_LOOKUP; + MM_AppData.HkPacket.Payload.Address = ResolvedAddr; + + CFE_EVS_SendEvent(MM_SYM_LOOKUP_INF_EID, CFE_EVS_EventType_INFORMATION, + "Symbol Lookup Command: Name = '%s' Addr = %p", SymName, (void *)ResolvedAddr); + Result = true; } else { - /* - ** If symbol name is not an empty string look it up using the OSAL API - */ - OS_Status = OS_SymbolLookup(&ResolvedAddr, SymName); - if (OS_Status == OS_SUCCESS) - { - /* Update telemetry */ - MM_AppData.HkPacket.Payload.LastAction = MM_SYM_LOOKUP; - MM_AppData.HkPacket.Payload.Address = ResolvedAddr; - - CFE_EVS_SendEvent(MM_SYM_LOOKUP_INF_EID, CFE_EVS_EventType_INFORMATION, - "Symbol Lookup Command: Name = '%s' Addr = %p", SymName, (void *)ResolvedAddr); - Result = true; - } - else - { - CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR, - "Symbolic address can't be resolved: Name = '%s'", SymName); - } + CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR, + "Symbolic address can't be resolved: Name = '%s'", SymName); + } - } /* end strlen(CmdPtr->Payload.SymName) == 0 else */ + } /* end strlen(CmdPtr->Payload.SymName) == 0 else */ return Result; } @@ -494,43 +495,44 @@ bool MM_SymTblToFileCmd(const CFE_SB_Buffer_t *BufPtr) { int32 OS_Status = OS_ERROR; /* Set to error instead of success since we explicitly test for success */ char FileName[OS_MAX_PATH_LEN]; - const MM_SymTblToFileCmd_t *CmdPtr = NULL; - bool Result = false; + const MM_SymTblToFileCmd_t *CmdPtr = NULL; + bool Result = false; - CmdPtr = ((MM_SymTblToFileCmd_t *)BufPtr); + CmdPtr = ((MM_SymTblToFileCmd_t *)BufPtr); - /* Make sure string is null terminated before attempting to process it */ - CFE_SB_MessageStringGet(FileName, CmdPtr->Payload.FileName, NULL, sizeof(FileName), sizeof(CmdPtr->Payload.FileName)); + /* Make sure string is null terminated before attempting to process it */ + CFE_SB_MessageStringGet(FileName, CmdPtr->Payload.FileName, NULL, sizeof(FileName), + sizeof(CmdPtr->Payload.FileName)); - /* - ** Check if the filename string is a nul string - */ - if (strlen(FileName) == 0) + /* + ** Check if the filename string is a nul string + */ + if (strlen(FileName) == 0) + { + CFE_EVS_SendEvent(MM_SYMFILENAME_NUL_ERR_EID, CFE_EVS_EventType_ERROR, + "NUL (empty) string specified as symbol dump file name"); + } + else + { + OS_Status = OS_SymbolTableDump(FileName, MM_MAX_DUMP_FILE_DATA_SYMTBL); + if (OS_Status == OS_SUCCESS) { - CFE_EVS_SendEvent(MM_SYMFILENAME_NUL_ERR_EID, CFE_EVS_EventType_ERROR, - "NUL (empty) string specified as symbol dump file name"); + /* Update telemetry */ + MM_AppData.HkPacket.Payload.LastAction = MM_SYMTBL_SAVE; + strncpy(MM_AppData.HkPacket.Payload.FileName, FileName, OS_MAX_PATH_LEN); + + CFE_EVS_SendEvent(MM_SYMTBL_TO_FILE_INF_EID, CFE_EVS_EventType_INFORMATION, + "Symbol Table Dump to File Started: Name = '%s'", FileName); + Result = true; } else { - OS_Status = OS_SymbolTableDump(FileName, MM_MAX_DUMP_FILE_DATA_SYMTBL); - if (OS_Status == OS_SUCCESS) - { - /* Update telemetry */ - MM_AppData.HkPacket.Payload.LastAction = MM_SYMTBL_SAVE; - strncpy(MM_AppData.HkPacket.Payload.FileName, FileName, OS_MAX_PATH_LEN); - - CFE_EVS_SendEvent(MM_SYMTBL_TO_FILE_INF_EID, CFE_EVS_EventType_INFORMATION, - "Symbol Table Dump to File Started: Name = '%s'", FileName); - Result = true; - } - else - { - CFE_EVS_SendEvent(MM_SYMTBL_TO_FILE_FAIL_ERR_EID, CFE_EVS_EventType_ERROR, - "Error dumping symbol table, OS_Status= 0x%X, File='%s'", (unsigned int)OS_Status, - FileName); - } + CFE_EVS_SendEvent(MM_SYMTBL_TO_FILE_FAIL_ERR_EID, CFE_EVS_EventType_ERROR, + "Error dumping symbol table, OS_Status= 0x%X, File='%s'", (unsigned int)OS_Status, + FileName); + } - } /* end strlen(FileName) == 0 else */ + } /* end strlen(FileName) == 0 else */ return Result; } @@ -542,33 +544,33 @@ bool MM_SymTblToFileCmd(const CFE_SB_Buffer_t *BufPtr) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ bool MM_EepromWriteEnaCmd(const CFE_SB_Buffer_t *BufPtr) { - CFE_Status_t cFE_Status = CFE_PSP_ERROR; /* Set to error since we explicitly test for success */ - MM_EepromWriteEnaCmd_t *CmdPtr = NULL; - bool Result = false; + CFE_Status_t cFE_Status = CFE_PSP_ERROR; /* Set to error since we explicitly test for success */ + MM_EepromWriteEnaCmd_t *CmdPtr = NULL; + bool Result = false; - CmdPtr = ((MM_EepromWriteEnaCmd_t *)BufPtr); + CmdPtr = ((MM_EepromWriteEnaCmd_t *)BufPtr); - /* - ** Call the cFE to write-enable the requested bank - */ - cFE_Status = CFE_PSP_EepromWriteEnable(CmdPtr->Payload.Bank); - if (cFE_Status == CFE_PSP_SUCCESS) - { - /* Update telemetry */ - MM_AppData.HkPacket.Payload.LastAction = MM_EEPROMWRITE_ENA; - MM_AppData.HkPacket.Payload.MemType = MM_EEPROM; + /* + ** Call the cFE to write-enable the requested bank + */ + cFE_Status = CFE_PSP_EepromWriteEnable(CmdPtr->Payload.Bank); + if (cFE_Status == CFE_PSP_SUCCESS) + { + /* Update telemetry */ + MM_AppData.HkPacket.Payload.LastAction = MM_EEPROMWRITE_ENA; + MM_AppData.HkPacket.Payload.MemType = MM_EEPROM; - CFE_EVS_SendEvent(MM_EEPROM_WRITE_ENA_INF_EID, CFE_EVS_EventType_INFORMATION, - "EEPROM bank %d write enabled, cFE_Status= 0x%X", (int)CmdPtr->Payload.Bank, - (unsigned int)cFE_Status); - Result = true; - } - else - { - CFE_EVS_SendEvent(MM_EEPROM_WRITE_ENA_ERR_EID, CFE_EVS_EventType_ERROR, - "Error requesting EEPROM bank %d write enable, cFE_Status= 0x%X", (int)CmdPtr->Payload.Bank, - (unsigned int)cFE_Status); - } + CFE_EVS_SendEvent(MM_EEPROM_WRITE_ENA_INF_EID, CFE_EVS_EventType_INFORMATION, + "EEPROM bank %d write enabled, cFE_Status= 0x%X", (int)CmdPtr->Payload.Bank, + (unsigned int)cFE_Status); + Result = true; + } + else + { + CFE_EVS_SendEvent(MM_EEPROM_WRITE_ENA_ERR_EID, CFE_EVS_EventType_ERROR, + "Error requesting EEPROM bank %d write enable, cFE_Status= 0x%X", (int)CmdPtr->Payload.Bank, + (unsigned int)cFE_Status); + } return Result; } @@ -580,32 +582,32 @@ bool MM_EepromWriteEnaCmd(const CFE_SB_Buffer_t *BufPtr) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ bool MM_EepromWriteDisCmd(const CFE_SB_Buffer_t *BufPtr) { - CFE_Status_t cFE_Status = CFE_PSP_ERROR; /* Set to error since we explicitly test for success */ - MM_EepromWriteDisCmd_t *CmdPtr = NULL; - bool Result = false; + CFE_Status_t cFE_Status = CFE_PSP_ERROR; /* Set to error since we explicitly test for success */ + MM_EepromWriteDisCmd_t *CmdPtr = NULL; + bool Result = false; - CmdPtr = ((MM_EepromWriteDisCmd_t *)BufPtr); + CmdPtr = ((MM_EepromWriteDisCmd_t *)BufPtr); - /* - ** Call the cFE to write-enable the requested bank - */ - cFE_Status = CFE_PSP_EepromWriteDisable(CmdPtr->Payload.Bank); - if (cFE_Status == CFE_PSP_SUCCESS) - { - /* Update telemetry */ - MM_AppData.HkPacket.Payload.LastAction = MM_EEPROMWRITE_DIS; - MM_AppData.HkPacket.Payload.MemType = MM_EEPROM; - Result = true; - CFE_EVS_SendEvent(MM_EEPROM_WRITE_DIS_INF_EID, CFE_EVS_EventType_INFORMATION, - "EEPROM bank %d write disabled, cFE_Status= 0x%X", (int)CmdPtr->Payload.Bank, - (unsigned int)cFE_Status); - } - else - { - CFE_EVS_SendEvent(MM_EEPROM_WRITE_DIS_ERR_EID, CFE_EVS_EventType_ERROR, - "Error requesting EEPROM bank %d write disable, cFE_Status= 0x%X", (int)CmdPtr->Payload.Bank, - (unsigned int)cFE_Status); - } + /* + ** Call the cFE to write-enable the requested bank + */ + cFE_Status = CFE_PSP_EepromWriteDisable(CmdPtr->Payload.Bank); + if (cFE_Status == CFE_PSP_SUCCESS) + { + /* Update telemetry */ + MM_AppData.HkPacket.Payload.LastAction = MM_EEPROMWRITE_DIS; + MM_AppData.HkPacket.Payload.MemType = MM_EEPROM; + Result = true; + CFE_EVS_SendEvent(MM_EEPROM_WRITE_DIS_INF_EID, CFE_EVS_EventType_INFORMATION, + "EEPROM bank %d write disabled, cFE_Status= 0x%X", (int)CmdPtr->Payload.Bank, + (unsigned int)cFE_Status); + } + else + { + CFE_EVS_SendEvent(MM_EEPROM_WRITE_DIS_ERR_EID, CFE_EVS_EventType_ERROR, + "Error requesting EEPROM bank %d write disable, cFE_Status= 0x%X", (int)CmdPtr->Payload.Bank, + (unsigned int)cFE_Status); + } return Result; } diff --git a/fsw/src/mm_dump.c b/fsw/src/mm_dump.c index 7676708..cc6bcb6 100644 --- a/fsw/src/mm_dump.c +++ b/fsw/src/mm_dump.c @@ -49,39 +49,39 @@ bool MM_PeekCmd(const CFE_SB_Buffer_t *BufPtr) { bool Valid; const MM_PeekCmd_t *CmdPtr; - cpuaddr SrcAddress = 0; - bool Result = false; + cpuaddr SrcAddress = 0; + bool Result = false; MM_SymAddr_t SrcSymAddress; - CmdPtr = ((MM_PeekCmd_t *)BufPtr); + CmdPtr = ((MM_PeekCmd_t *)BufPtr); - SrcSymAddress = CmdPtr->Payload.SrcSymAddress; + SrcSymAddress = CmdPtr->Payload.SrcSymAddress; - /* Resolve the symbolic address in command message */ - Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress); + /* Resolve the symbolic address in command message */ + Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress); - if (Valid == true) - { - /* Run necessary checks on command parameters */ - Valid = MM_VerifyPeekPokeParams(SrcAddress, CmdPtr->Payload.MemType, CmdPtr->Payload.DataSize); - - /* Check the specified memory type and call the appropriate routine */ - if (Valid == true) - { - /* - ** We use this single peek routine for all memory types - ** (including the optional ones) - */ - Result = MM_PeekMem(CmdPtr, SrcAddress); - } + if (Valid == true) + { + /* Run necessary checks on command parameters */ + Valid = MM_VerifyPeekPokeParams(SrcAddress, CmdPtr->Payload.MemType, CmdPtr->Payload.DataSize); - } /* end MM_ResolveSymAddr if */ - else + /* Check the specified memory type and call the appropriate routine */ + if (Valid == true) { - CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR, - "Symbolic address can't be resolved: Name = '%s'", CmdPtr->Payload.SrcSymAddress.SymName); + /* + ** We use this single peek routine for all memory types + ** (including the optional ones) + */ + Result = MM_PeekMem(CmdPtr, SrcAddress); } + } /* end MM_ResolveSymAddr if */ + else + { + CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR, + "Symbolic address can't be resolved: Name = '%s'", CmdPtr->Payload.SrcSymAddress.SymName); + } + return Result; } @@ -169,8 +169,8 @@ bool MM_PeekMem(const MM_PeekCmd_t *CmdPtr, cpuaddr SrcAddress) else { CFE_EVS_SendEvent(MM_PSP_READ_ERR_EID, CFE_EVS_EventType_ERROR, - "PSP read memory error: RC=%d, Address=%p, MemType=MEM%u", (int)PSP_Status, (void *)SrcAddress, - (unsigned int)DataSize); + "PSP read memory error: RC=%d, Address=%p, MemType=MEM%u", (int)PSP_Status, + (void *)SrcAddress, (unsigned int)DataSize); } return ValidPeek; @@ -193,163 +193,165 @@ bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr) CFE_FS_Header_t CFEFileHeader; MM_LoadDumpFileHeader_t MMFileHeader; - CmdPtr = ((MM_DumpMemToFileCmd_t *)BufPtr); + CmdPtr = ((MM_DumpMemToFileCmd_t *)BufPtr); + + SrcSymAddress = CmdPtr->Payload.SrcSymAddress; - SrcSymAddress = CmdPtr->Payload.SrcSymAddress; + /* Make sure strings are null terminated before attempting to process them */ + CFE_SB_MessageStringGet(FileName, CmdPtr->Payload.FileName, NULL, sizeof(FileName), + sizeof(CmdPtr->Payload.FileName)); - /* Make sure strings are null terminated before attempting to process them */ - CFE_SB_MessageStringGet(FileName, CmdPtr->Payload.FileName, NULL, sizeof(FileName), sizeof(CmdPtr->Payload.FileName)); + /* Resolve the symbolic address in command message */ + Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress); - /* Resolve the symbolic address in command message */ - Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress); + if (Valid == true) + { + /* Run necessary checks on command parameters */ + Valid = + MM_VerifyLoadDumpParams(SrcAddress, CmdPtr->Payload.MemType, CmdPtr->Payload.NumOfBytes, MM_VERIFY_DUMP); if (Valid == true) { - /* Run necessary checks on command parameters */ - Valid = MM_VerifyLoadDumpParams(SrcAddress, CmdPtr->Payload.MemType, CmdPtr->Payload.NumOfBytes, MM_VERIFY_DUMP); - - if (Valid == true) + /* + ** Initialize the cFE primary file header structure + */ + CFE_FS_InitHeader(&CFEFileHeader, MM_CFE_HDR_DESCRIPTION, MM_CFE_HDR_SUBTYPE); + + /* + ** Initialize the MM secondary file header structure + */ + memset(&MMFileHeader, 0, sizeof(MMFileHeader)); + MMFileHeader.SymAddress.SymName[0] = MM_CLEAR_SYMNAME; + + /* + ** Copy command data to file secondary header + */ + MMFileHeader.SymAddress.Offset = SrcAddress; + MMFileHeader.MemType = CmdPtr->Payload.MemType; + MMFileHeader.NumOfBytes = CmdPtr->Payload.NumOfBytes; + + /* + ** Create and open dump file + */ + OS_Status = + OS_OpenCreate(&FileHandle, FileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); + if (OS_Status == OS_SUCCESS) { - /* - ** Initialize the cFE primary file header structure - */ - CFE_FS_InitHeader(&CFEFileHeader, MM_CFE_HDR_DESCRIPTION, MM_CFE_HDR_SUBTYPE); - - /* - ** Initialize the MM secondary file header structure - */ - memset(&MMFileHeader, 0, sizeof(MMFileHeader)); - MMFileHeader.SymAddress.SymName[0] = MM_CLEAR_SYMNAME; - - /* - ** Copy command data to file secondary header - */ - MMFileHeader.SymAddress.Offset = SrcAddress; - MMFileHeader.MemType = CmdPtr->Payload.MemType; - MMFileHeader.NumOfBytes = CmdPtr->Payload.NumOfBytes; - - /* - ** Create and open dump file - */ - OS_Status = - OS_OpenCreate(&FileHandle, FileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE); - if (OS_Status == OS_SUCCESS) + /* Write the file headers */ + Valid = MM_WriteFileHeaders(FileName, FileHandle, &CFEFileHeader, &MMFileHeader); + if (Valid == true) { - /* Write the file headers */ - Valid = MM_WriteFileHeaders(FileName, FileHandle, &CFEFileHeader, &MMFileHeader); - if (Valid == true) + switch (MMFileHeader.MemType) { - switch (MMFileHeader.MemType) - { - case MM_RAM: - case MM_EEPROM: - Valid = MM_DumpMemToFile(FileHandle, FileName, &MMFileHeader); - break; + case MM_RAM: + case MM_EEPROM: + Valid = MM_DumpMemToFile(FileHandle, FileName, &MMFileHeader); + break; #ifdef MM_OPT_CODE_MEM32_MEMTYPE - case MM_MEM32: - Valid = MM_DumpMem32ToFile(FileHandle, FileName, &MMFileHeader); - break; + case MM_MEM32: + Valid = MM_DumpMem32ToFile(FileHandle, FileName, &MMFileHeader); + break; #endif /* MM_OPT_CODE_MEM32_MEMTYPE */ #ifdef MM_OPT_CODE_MEM16_MEMTYPE - case MM_MEM16: - Valid = MM_DumpMem16ToFile(FileHandle, FileName, &MMFileHeader); - break; + case MM_MEM16: + Valid = MM_DumpMem16ToFile(FileHandle, FileName, &MMFileHeader); + break; #endif /* MM_OPT_CODE_MEM16_MEMTYPE */ #ifdef MM_OPT_CODE_MEM8_MEMTYPE - case MM_MEM8: - Valid = MM_DumpMem8ToFile(FileHandle, FileName, &MMFileHeader); - break; + case MM_MEM8: + Valid = MM_DumpMem8ToFile(FileHandle, FileName, &MMFileHeader); + break; #endif /* MM_OPT_CODE_MEM8_MEMTYPE */ - default: - /* This branch will never be executed. MMFileHeader.MemType will always - * be valid value for this switch statement it is verified via - * MM_VerifyFileLoadDumpParams */ - Valid = false; - break; - } + default: + /* This branch will never be executed. MMFileHeader.MemType will always + * be valid value for this switch statement it is verified via + * MM_VerifyFileLoadDumpParams */ + Valid = false; + break; + } - if (Valid == true) + if (Valid == true) + { + /* + ** Compute CRC of dumped data + */ + OS_Status = OS_lseek(FileHandle, (sizeof(CFE_FS_Header_t) + sizeof(MM_LoadDumpFileHeader_t)), + OS_SEEK_SET); + if (OS_Status != (sizeof(CFE_FS_Header_t) + sizeof(MM_LoadDumpFileHeader_t))) { - /* - ** Compute CRC of dumped data - */ - OS_Status = OS_lseek( - FileHandle, (sizeof(CFE_FS_Header_t) + sizeof(MM_LoadDumpFileHeader_t)), OS_SEEK_SET); - if (OS_Status != (sizeof(CFE_FS_Header_t) + sizeof(MM_LoadDumpFileHeader_t))) + Valid = false; + } + else + { + OS_Status = MM_ComputeCRCFromFile(FileHandle, &MMFileHeader.Crc, MM_DUMP_FILE_CRC_TYPE); + if (OS_Status == OS_SUCCESS) { - Valid = false; - } + /* + ** Rewrite the file headers. The subfunctions will take care of moving + ** the file pointer to the beginning of the file so we don't need to do it + ** here. + */ + Valid = MM_WriteFileHeaders(FileName, FileHandle, &CFEFileHeader, &MMFileHeader); + + } /* end MM_ComputeCRCFromFile if */ else { - OS_Status = MM_ComputeCRCFromFile(FileHandle, &MMFileHeader.Crc, MM_DUMP_FILE_CRC_TYPE); - if (OS_Status == OS_SUCCESS) - { - /* - ** Rewrite the file headers. The subfunctions will take care of moving - ** the file pointer to the beginning of the file so we don't need to do it - ** here. - */ - Valid = MM_WriteFileHeaders(FileName, FileHandle, &CFEFileHeader, &MMFileHeader); - - } /* end MM_ComputeCRCFromFile if */ - else - { - Valid = false; - CFE_EVS_SendEvent(MM_COMPUTECRCFROMFILE_ERR_EID, CFE_EVS_EventType_ERROR, - "MM_ComputeCRCFromFile error received: RC = 0x%08X File = '%s'", - (unsigned int)OS_Status, FileName); - } + Valid = false; + CFE_EVS_SendEvent(MM_COMPUTECRCFROMFILE_ERR_EID, CFE_EVS_EventType_ERROR, + "MM_ComputeCRCFromFile error received: RC = 0x%08X File = '%s'", + (unsigned int)OS_Status, FileName); } - - } /* end Valid == true if */ - - if (Valid == true) - { - CFE_EVS_SendEvent( - MM_DMP_MEM_FILE_INF_EID, CFE_EVS_EventType_INFORMATION, - "Dump Memory To File Command: Dumped %d bytes from address %p to file '%s'", - (int)MM_AppData.HkPacket.Payload.BytesProcessed, (void *)SrcAddress, FileName); - /* - ** Update last action statistics - */ - MM_AppData.HkPacket.Payload.LastAction = MM_DUMP_TO_FILE; - strncpy(MM_AppData.HkPacket.Payload.FileName, FileName, OS_MAX_PATH_LEN); - MM_AppData.HkPacket.Payload.MemType = CmdPtr->Payload.MemType; - MM_AppData.HkPacket.Payload.Address = SrcAddress; - MM_AppData.HkPacket.Payload.BytesProcessed = CmdPtr->Payload.NumOfBytes; } - } /* end MM_WriteFileHeaders if */ + } /* end Valid == true if */ - /* Close dump file */ - if ((OS_Status = OS_close(FileHandle)) != OS_SUCCESS) + if (Valid == true) { - Valid = false; - CFE_EVS_SendEvent(MM_OS_CLOSE_ERR_EID, CFE_EVS_EventType_ERROR, - "OS_close error received: RC = 0x%08X File = '%s'", (unsigned int)OS_Status, + CFE_EVS_SendEvent(MM_DMP_MEM_FILE_INF_EID, CFE_EVS_EventType_INFORMATION, + "Dump Memory To File Command: Dumped %d bytes from address %p to file '%s'", + (int)MM_AppData.HkPacket.Payload.BytesProcessed, (void *)SrcAddress, FileName); + /* + ** Update last action statistics + */ + MM_AppData.HkPacket.Payload.LastAction = MM_DUMP_TO_FILE; + strncpy(MM_AppData.HkPacket.Payload.FileName, FileName, OS_MAX_PATH_LEN); + MM_AppData.HkPacket.Payload.MemType = CmdPtr->Payload.MemType; + MM_AppData.HkPacket.Payload.Address = SrcAddress; + MM_AppData.HkPacket.Payload.BytesProcessed = CmdPtr->Payload.NumOfBytes; } - } /* end OS_OpenCreate if */ - else + } /* end MM_WriteFileHeaders if */ + + /* Close dump file */ + if ((OS_Status = OS_close(FileHandle)) != OS_SUCCESS) { Valid = false; - CFE_EVS_SendEvent(MM_OS_CREAT_ERR_EID, CFE_EVS_EventType_ERROR, - "OS_OpenCreate error received: RC = %d File = '%s'", (int)OS_Status, FileName); + CFE_EVS_SendEvent(MM_OS_CLOSE_ERR_EID, CFE_EVS_EventType_ERROR, + "OS_close error received: RC = 0x%08X File = '%s'", (unsigned int)OS_Status, + FileName); } - } /* end MM_VerifyFileLoadDumpParams if */ + } /* end OS_OpenCreate if */ + else + { + Valid = false; + CFE_EVS_SendEvent(MM_OS_CREAT_ERR_EID, CFE_EVS_EventType_ERROR, + "OS_OpenCreate error received: RC = %d File = '%s'", (int)OS_Status, FileName); + } - } /* end MM_ResolveSymAddr if */ - else - { - Valid = false; - CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR, - "Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName); - } + } /* end MM_VerifyFileLoadDumpParams if */ + + } /* end MM_ResolveSymAddr if */ + else + { + Valid = false; + CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR, + "Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName); + } return Valid; } @@ -403,7 +405,7 @@ bool MM_DumpMemToFile(osal_id_t FileHandle, const char *FileName, const MM_LoadD /* Update last action statistics */ if (BytesProcessed == FileHeader->NumOfBytes) { - ValidDump = true; + ValidDump = true; MM_AppData.HkPacket.Payload.LastAction = MM_DUMP_TO_FILE; MM_AppData.HkPacket.Payload.MemType = FileHeader->MemType; MM_AppData.HkPacket.Payload.Address = FileHeader->SymAddress.Offset; @@ -484,72 +486,73 @@ bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr) */ uint32 DumpBuffer[(MM_MAX_DUMP_INEVENT_BYTES + 3) / 4]; - CmdPtr = ((MM_DumpInEventCmd_t *)BufPtr); + CmdPtr = ((MM_DumpInEventCmd_t *)BufPtr); - SrcSymAddress = CmdPtr->Payload.SrcSymAddress; + SrcSymAddress = CmdPtr->Payload.SrcSymAddress; - /* Resolve the symbolic source address in the command message */ - Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress); + /* Resolve the symbolic source address in the command message */ + Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress); + + if (Valid == true) + { + /* Run necessary checks on command parameters */ + Valid = + MM_VerifyLoadDumpParams(SrcAddress, CmdPtr->Payload.MemType, CmdPtr->Payload.NumOfBytes, MM_VERIFY_EVENT); if (Valid == true) { - /* Run necessary checks on command parameters */ - Valid = MM_VerifyLoadDumpParams(SrcAddress, CmdPtr->Payload.MemType, CmdPtr->Payload.NumOfBytes, MM_VERIFY_EVENT); + /* Fill a local data buffer with the dump words */ + Valid = MM_FillDumpInEventBuffer(SrcAddress, CmdPtr, (uint8 *)DumpBuffer); if (Valid == true) { - /* Fill a local data buffer with the dump words */ - Valid = MM_FillDumpInEventBuffer(SrcAddress, CmdPtr, (uint8 *)DumpBuffer); + /* + ** Prepare event message string header + ** 13 characters, not counting NUL terminator + */ + CFE_SB_MessageStringGet(&EventString[EventStringTotalLength], HeaderString, NULL, + sizeof(EventString) - EventStringTotalLength, sizeof(HeaderString)); + EventStringTotalLength = strlen(EventString); - if (Valid == true) + /* + ** Build dump data string + ** Each byte of data requires 5 characters of string space + ** Note this really only allows up to ~15 bytes using default config + */ + BytePtr = (uint8 *)DumpBuffer; + for (i = 0; i < CmdPtr->Payload.NumOfBytes; i++) { - /* - ** Prepare event message string header - ** 13 characters, not counting NUL terminator - */ - CFE_SB_MessageStringGet(&EventString[EventStringTotalLength], HeaderString, NULL, - sizeof(EventString) - EventStringTotalLength, sizeof(HeaderString)); - EventStringTotalLength = strlen(EventString); - - /* - ** Build dump data string - ** Each byte of data requires 5 characters of string space - ** Note this really only allows up to ~15 bytes using default config - */ - BytePtr = (uint8 *)DumpBuffer; - for (i = 0; i < CmdPtr->Payload.NumOfBytes; i++) - { - snprintf(TempString, MM_DUMPINEVENT_TEMP_CHARS, "0x%02X ", *BytePtr); - CFE_SB_MessageStringGet(&EventString[EventStringTotalLength], TempString, NULL, - sizeof(EventString) - EventStringTotalLength, sizeof(TempString)); - EventStringTotalLength = strlen(EventString); - BytePtr++; - } - - /* - ** Append tail - ** This adds up to 33 characters depending on pointer representation including the NUL terminator - */ - snprintf(TempString, MM_DUMPINEVENT_TEMP_CHARS, "from address: %p", (void *)SrcAddress); + snprintf(TempString, MM_DUMPINEVENT_TEMP_CHARS, "0x%02X ", *BytePtr); CFE_SB_MessageStringGet(&EventString[EventStringTotalLength], TempString, NULL, sizeof(EventString) - EventStringTotalLength, sizeof(TempString)); + EventStringTotalLength = strlen(EventString); + BytePtr++; + } - /* Send it out */ - CFE_EVS_SendEvent(MM_DUMP_INEVENT_INF_EID, CFE_EVS_EventType_INFORMATION, "%s", EventString); - - /* Update telemetry */ - MM_AppData.HkPacket.Payload.LastAction = MM_DUMP_INEVENT; - MM_AppData.HkPacket.Payload.MemType = CmdPtr->Payload.MemType; - MM_AppData.HkPacket.Payload.Address = SrcAddress; - MM_AppData.HkPacket.Payload.BytesProcessed = CmdPtr->Payload.NumOfBytes; - } /* end MM_FillDumpInEventBuffer if */ - } /* end MM_VerifyFileLoadDumpParams if */ - } /* end MM_ResolveSymAddr if */ - else - { - CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR, - "Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName); - } + /* + ** Append tail + ** This adds up to 33 characters depending on pointer representation including the NUL terminator + */ + snprintf(TempString, MM_DUMPINEVENT_TEMP_CHARS, "from address: %p", (void *)SrcAddress); + CFE_SB_MessageStringGet(&EventString[EventStringTotalLength], TempString, NULL, + sizeof(EventString) - EventStringTotalLength, sizeof(TempString)); + + /* Send it out */ + CFE_EVS_SendEvent(MM_DUMP_INEVENT_INF_EID, CFE_EVS_EventType_INFORMATION, "%s", EventString); + + /* Update telemetry */ + MM_AppData.HkPacket.Payload.LastAction = MM_DUMP_INEVENT; + MM_AppData.HkPacket.Payload.MemType = CmdPtr->Payload.MemType; + MM_AppData.HkPacket.Payload.Address = SrcAddress; + MM_AppData.HkPacket.Payload.BytesProcessed = CmdPtr->Payload.NumOfBytes; + } /* end MM_FillDumpInEventBuffer if */ + } /* end MM_VerifyFileLoadDumpParams if */ + } /* end MM_ResolveSymAddr if */ + else + { + CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR, + "Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName); + } return Valid; } diff --git a/fsw/src/mm_mem16.c b/fsw/src/mm_mem16.c index 1c5a261..7685017 100644 --- a/fsw/src/mm_mem16.c +++ b/fsw/src/mm_mem16.c @@ -115,7 +115,7 @@ bool MM_LoadMem16FromFile(osal_id_t FileHandle, const char *FileName, const MM_L /* Update last action statistics */ if (BytesProcessed == FileHeader->NumOfBytes) { - Valid = true; + Valid = true; MM_AppData.HkPacket.Payload.LastAction = MM_LOAD_FROM_FILE; MM_AppData.HkPacket.Payload.MemType = MM_MEM16; MM_AppData.HkPacket.Payload.Address = DestAddress; @@ -235,8 +235,8 @@ bool MM_FillMem16(cpuaddr DestAddress, const MM_FillMemCmd_t *CmdPtr) { NewBytesRemaining = BytesRemaining - (BytesRemaining % 2); CFE_EVS_SendEvent(MM_FILL_MEM16_ALIGN_WARN_INF_EID, CFE_EVS_EventType_INFORMATION, - "MM_FillMem16 NumOfBytes not multiple of 2. Reducing from %u to %u.", (unsigned int)BytesRemaining, - (unsigned int)NewBytesRemaining); + "MM_FillMem16 NumOfBytes not multiple of 2. Reducing from %u to %u.", + (unsigned int)BytesRemaining, (unsigned int)NewBytesRemaining); BytesRemaining = NewBytesRemaining; } diff --git a/fsw/src/mm_mem32.c b/fsw/src/mm_mem32.c index 4293843..f67b6ef 100644 --- a/fsw/src/mm_mem32.c +++ b/fsw/src/mm_mem32.c @@ -115,7 +115,7 @@ bool MM_LoadMem32FromFile(osal_id_t FileHandle, const char *FileName, const MM_L /* Update last action statistics */ if (BytesProcessed == FileHeader->NumOfBytes) { - Valid = true; + Valid = true; MM_AppData.HkPacket.Payload.LastAction = MM_LOAD_FROM_FILE; MM_AppData.HkPacket.Payload.MemType = MM_MEM32; MM_AppData.HkPacket.Payload.Address = DestAddress; diff --git a/unit-test/mm_mem16_tests.c b/unit-test/mm_mem16_tests.c index 5539092..706d60e 100644 --- a/unit-test/mm_mem16_tests.c +++ b/unit-test/mm_mem16_tests.c @@ -73,7 +73,8 @@ void MM_LoadMem16FromFile_Test_Nominal(void) UtAssert_True(MM_AppData.HkPacket.Payload.LastAction == MM_LOAD_FROM_FILE, "MM_AppData.HkPacket.Payload.LastAction == MM_LOAD_FROM_FILE"); UtAssert_True(MM_AppData.HkPacket.Payload.MemType == MM_MEM16, "MM_AppData.HkPacket.Payload.MemType == MM_MEM16"); - UtAssert_True(MM_AppData.HkPacket.Payload.Address == DestAddress, "MM_AppData.HkPacket.Payload.Address == DestAddress"); + UtAssert_True(MM_AppData.HkPacket.Payload.Address == DestAddress, + "MM_AppData.HkPacket.Payload.Address == DestAddress"); UtAssert_True(MM_AppData.HkPacket.Payload.BytesProcessed == FileHeader.NumOfBytes, "MM_AppData.HkPacket.Payload.BytesProcessed == FileHeader.NumOfBytes"); UtAssert_True(strncmp(MM_AppData.HkPacket.Payload.FileName, "filename", OS_MAX_PATH_LEN) == 0, @@ -109,7 +110,8 @@ void MM_LoadMem16FromFile_Test_CPUHogging(void) UtAssert_True(MM_AppData.HkPacket.Payload.LastAction == MM_LOAD_FROM_FILE, "MM_AppData.HkPacket.Payload.LastAction == MM_LOAD_FROM_FILE"); UtAssert_True(MM_AppData.HkPacket.Payload.MemType == MM_MEM16, "MM_AppData.HkPacket.Payload.MemType == MM_MEM16"); - UtAssert_True(MM_AppData.HkPacket.Payload.Address == DestAddress, "MM_AppData.HkPacket.Payload.Address == DestAddress"); + UtAssert_True(MM_AppData.HkPacket.Payload.Address == DestAddress, + "MM_AppData.HkPacket.Payload.Address == DestAddress"); UtAssert_True(MM_AppData.HkPacket.Payload.BytesProcessed == FileHeader.NumOfBytes, "MM_AppData.HkPacket.Payload.BytesProcessed == FileHeader.NumOfBytes"); UtAssert_True(strncmp(MM_AppData.HkPacket.Payload.FileName, "filename", OS_MAX_PATH_LEN) == 0, @@ -376,9 +378,11 @@ void MM_FillMem16_Test_Nominal(void) /* Verify results */ UtAssert_True(Result == true, "Result == true"); - UtAssert_True(MM_AppData.HkPacket.Payload.LastAction == MM_FILL, "MM_AppData.HkPacket.Payload.LastAction == MM_FILL"); + UtAssert_True(MM_AppData.HkPacket.Payload.LastAction == MM_FILL, + "MM_AppData.HkPacket.Payload.LastAction == MM_FILL"); UtAssert_True(MM_AppData.HkPacket.Payload.MemType == MM_MEM16, "MM_AppData.HkPacket.Payload.MemType == MM_MEM16"); - UtAssert_True(MM_AppData.HkPacket.Payload.Address == DestAddress, "MM_AppData.HkPacket.Payload.Address == DestAddress"); + UtAssert_True(MM_AppData.HkPacket.Payload.Address == DestAddress, + "MM_AppData.HkPacket.Payload.Address == DestAddress"); UtAssert_True(MM_AppData.HkPacket.Payload.DataValue == CmdPacket.Payload.FillPattern, "MM_AppData.HkPacket.Payload.DataValue == CmdPacket.Payload.FillPattern"); UtAssert_True(MM_AppData.HkPacket.Payload.BytesProcessed == CmdPacket.Payload.NumOfBytes, @@ -408,9 +412,11 @@ void MM_FillMem16_Test_CPUHogging(void) /* Verify results */ UtAssert_True(Result == true, "Result == true"); - UtAssert_True(MM_AppData.HkPacket.Payload.LastAction == MM_FILL, "MM_AppData.HkPacket.Payload.LastAction == MM_FILL"); + UtAssert_True(MM_AppData.HkPacket.Payload.LastAction == MM_FILL, + "MM_AppData.HkPacket.Payload.LastAction == MM_FILL"); UtAssert_True(MM_AppData.HkPacket.Payload.MemType == MM_MEM16, "MM_AppData.HkPacket.Payload.MemType == MM_MEM16"); - UtAssert_True(MM_AppData.HkPacket.Payload.Address == DestAddress, "MM_AppData.HkPacket.Payload.Address == DestAddress"); + UtAssert_True(MM_AppData.HkPacket.Payload.Address == DestAddress, + "MM_AppData.HkPacket.Payload.Address == DestAddress"); UtAssert_True(MM_AppData.HkPacket.Payload.DataValue == CmdPacket.Payload.FillPattern, "MM_AppData.HkPacket.Payload.DataValue == CmdPacket.Payload.FillPattern"); UtAssert_True(MM_AppData.HkPacket.Payload.BytesProcessed == CmdPacket.Payload.NumOfBytes, @@ -470,10 +476,10 @@ void MM_FillMem16_Test_Align(void) { MM_FillMemCmd_t CmdPacket; uint32 DestAddress = 1; - bool Result; + bool Result; - CmdPacket.Payload.NumOfBytes = 3; - CmdPacket.Payload.FillPattern = 3; + CmdPacket.Payload.NumOfBytes = 3; + CmdPacket.Payload.FillPattern = 3; /* Execute the function being tested */ Result = MM_FillMem16(DestAddress, &CmdPacket);