diff --git a/fsw/inc/cfe_psp.h b/fsw/inc/cfe_psp.h index 47202913..025e0295 100644 --- a/fsw/inc/cfe_psp.h +++ b/fsw/inc/cfe_psp.h @@ -157,18 +157,6 @@ ** Type Definitions */ -/* -** Memory table type -*/ -typedef struct -{ - uint32 MemoryType; - uint32 WordSize; - cpuaddr StartAddr; - uint32 Size; - uint32 Attributes; -} CFE_PSP_MemTable_t; - /* ** Function prototypes */ @@ -394,11 +382,11 @@ int32 CFE_PSP_MemWrite32(cpuaddr MemoryAddress, uint32 uint32Value); int32 CFE_PSP_MemCpy(void *dest, const void *src, uint32 n); int32 CFE_PSP_MemSet(void *dest, uint8 value, uint32 n); -int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType); +int32 CFE_PSP_MemValidateRange(cpuaddr Address, size_t Size, uint32 MemoryType); uint32 CFE_PSP_MemRanges(void); -int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, uint32 Size, uint32 WordSize, +int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, size_t Size, size_t WordSize, uint32 Attributes); -int32 CFE_PSP_MemRangeGet(uint32 RangeNum, uint32 *MemoryType, cpuaddr *StartAddr, uint32 *Size, uint32 *WordSize, +int32 CFE_PSP_MemRangeGet(uint32 RangeNum, uint32 *MemoryType, cpuaddr *StartAddr, size_t *Size, size_t *WordSize, uint32 *Attributes); int32 CFE_PSP_EepromWrite8(cpuaddr MemoryAddress, uint8 ByteValue); diff --git a/fsw/inc/cfe_psp_configdata.h b/fsw/inc/cfe_psp_configdata.h index c8c446c0..b61f6291 100644 --- a/fsw/inc/cfe_psp_configdata.h +++ b/fsw/inc/cfe_psp_configdata.h @@ -56,11 +56,9 @@ typedef const struct */ typedef const struct { - uint32 PSP_WatchdogMin; /**< PSP Minimum watchdog in milliseconds */ - uint32 PSP_WatchdogMax; /**< PSP Maximum watchdog in milliseconds */ - uint32 PSP_MemTableSize; /**< Size of PSP memory table */ - uint32 PSP_ExceptionLogSize; /**< Size of PSP exception log */ - CFE_PSP_MemTable_t *PSP_MemoryTable; /**< Pointer to PSP memory table (forward reference) */ + uint32 PSP_WatchdogMin; /**< PSP Minimum watchdog in milliseconds */ + uint32 PSP_WatchdogMax; /**< PSP Maximum watchdog in milliseconds */ + uint32 PSP_ExceptionLogSize; /**< Size of PSP exception log */ /** * Number of EEPROM banks on this platform @@ -77,10 +75,4 @@ typedef const struct */ extern Target_PspConfigData GLOBAL_PSP_CONFIGDATA; -/** - * Extern reference to the psp memory table - * Allows the actual instantiation to be done outside this module - */ -extern CFE_PSP_MemTable_t CFE_PSP_MemoryTable[]; - #endif /* CFE_PSP_CONFIG_H_ */ diff --git a/fsw/mcp750-vxworks/src/cfe_psp_memory.c b/fsw/mcp750-vxworks/src/cfe_psp_memory.c index 6af794c5..4f3c153e 100644 --- a/fsw/mcp750-vxworks/src/cfe_psp_memory.c +++ b/fsw/mcp750-vxworks/src/cfe_psp_memory.c @@ -64,6 +64,11 @@ extern unsigned int GetWrsKernelTextStart(void); extern unsigned int GetWrsKernelTextEnd(void); +/* + * The system memory table is instantiated in a separate file cfe_psp_memtab.c + */ +extern CFE_PSP_MemTable_t MCP750_MemoryTable[]; + /* ** Global variables */ @@ -408,6 +413,12 @@ void CFE_PSP_SetupReservedMemoryMap(void) OS_printf("CFE_PSP: MCP750 Reserved Memory Block at 0x%08lx, Total Size = 0x%lx\n", (unsigned long)MCP750_ReservedMemBlock.BlockPtr, (unsigned long)MCP750_ReservedMemBlock.BlockSize); + + /* + * Set up pointer to system memory table + */ + CFE_PSP_ReservedMemoryMap.SysMemoryTable = MCP750_MemoryTable; + CFE_PSP_ReservedMemoryMap.SysMemoryTableSize = CFE_PSP_MEM_TABLE_SIZE; } /****************************************************************************** diff --git a/fsw/mcp750-vxworks/src/cfe_psp_memtab.c b/fsw/mcp750-vxworks/src/cfe_psp_memtab.c index ca04fab2..763681a8 100644 --- a/fsw/mcp750-vxworks/src/cfe_psp_memtab.c +++ b/fsw/mcp750-vxworks/src/cfe_psp_memtab.c @@ -35,12 +35,13 @@ #include "common_types.h" #include "cfe_psp.h" #include "cfe_psp_config.h" +#include "cfe_psp_memory.h" /* ** Valid memory map for this target. ** If you need to add more entries, increase CFE_PSP_MEM_TABLE_SIZE in the osconfig.h file. */ -CFE_PSP_MemTable_t CFE_PSP_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = { +CFE_PSP_MemTable_t MCP750_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = { {CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, 0x8000000, CFE_PSP_MEM_ATTR_READWRITE}, {CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE}, {CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE}, diff --git a/fsw/pc-linux/src/cfe_psp_memory.c b/fsw/pc-linux/src/cfe_psp_memory.c index 5c9ddc2f..85fc51a6 100644 --- a/fsw/pc-linux/src/cfe_psp_memory.c +++ b/fsw/pc-linux/src/cfe_psp_memory.c @@ -98,6 +98,11 @@ void CFE_PSP_InitUserReservedArea(void); extern unsigned int _init; extern unsigned int _fini; +/* + * The system memory table is instantiated in a separate file cfe_psp_memtab.c + */ +extern CFE_PSP_MemTable_t PcLinux_MemoryTable[]; + /* ** Global variables */ @@ -674,6 +679,12 @@ void CFE_PSP_SetupReservedMemoryMap(void) CFE_PSP_InitResetArea(); CFE_PSP_InitVolatileDiskMem(); CFE_PSP_InitUserReservedArea(); + + /* + * Set up pointer to system memory table + */ + CFE_PSP_ReservedMemoryMap.SysMemoryTable = PcLinux_MemoryTable; + CFE_PSP_ReservedMemoryMap.SysMemoryTableSize = CFE_PSP_MEM_TABLE_SIZE; } int32 CFE_PSP_InitProcessorReservedMemory(uint32 RestartType) diff --git a/fsw/pc-linux/src/cfe_psp_memtab.c b/fsw/pc-linux/src/cfe_psp_memtab.c index af22651b..dde0e1e2 100644 --- a/fsw/pc-linux/src/cfe_psp_memtab.c +++ b/fsw/pc-linux/src/cfe_psp_memtab.c @@ -36,13 +36,14 @@ #include "osapi.h" #include "cfe_psp.h" #include "cfe_psp_config.h" +#include "cfe_psp_memory.h" /* ** Valid memory map for this target. ** If you need to add more entries, increase CFE_PSP_MEM_TABLE_SIZE in the osconfig.h file. */ -CFE_PSP_MemTable_t CFE_PSP_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = { - {CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, 0xFFFFFFFF, CFE_PSP_MEM_ATTR_READWRITE}, +CFE_PSP_MemTable_t PcLinux_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = { + {CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, SIZE_MAX, CFE_PSP_MEM_ATTR_READWRITE}, {CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE}, {CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE}, {CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE}, diff --git a/fsw/pc-rtems/src/cfe_psp_memory.c b/fsw/pc-rtems/src/cfe_psp_memory.c index 559e1a2a..36dfd3a1 100644 --- a/fsw/pc-rtems/src/cfe_psp_memory.c +++ b/fsw/pc-rtems/src/cfe_psp_memory.c @@ -78,6 +78,11 @@ typedef struct ** External Declarations */ +/* + * The system memory table is instantiated in a separate file cfe_psp_memtab.c + */ +extern CFE_PSP_MemTable_t PcRtems_MemoryTable[]; + /* ** Global variables */ @@ -418,6 +423,12 @@ void CFE_PSP_SetupReservedMemoryMap(void) * (prefer this over removing the increment, as it is safer if another block is added) */ OS_printf("CFE_PSP: PSP reserved memory ends at: 0x%08lX\n", (unsigned long)ReservedMemoryAddr); + + /* + * Set up pointer to system memory table + */ + CFE_PSP_ReservedMemoryMap.SysMemoryTable = PcRtems_MemoryTable; + CFE_PSP_ReservedMemoryMap.SysMemoryTableSize = CFE_PSP_MEM_TABLE_SIZE; } /****************************************************************************** diff --git a/fsw/pc-rtems/src/cfe_psp_memtab.c b/fsw/pc-rtems/src/cfe_psp_memtab.c index af22651b..99ddc195 100644 --- a/fsw/pc-rtems/src/cfe_psp_memtab.c +++ b/fsw/pc-rtems/src/cfe_psp_memtab.c @@ -36,13 +36,14 @@ #include "osapi.h" #include "cfe_psp.h" #include "cfe_psp_config.h" +#include "cfe_psp_memory.h" /* ** Valid memory map for this target. ** If you need to add more entries, increase CFE_PSP_MEM_TABLE_SIZE in the osconfig.h file. */ -CFE_PSP_MemTable_t CFE_PSP_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = { - {CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, 0xFFFFFFFF, CFE_PSP_MEM_ATTR_READWRITE}, +CFE_PSP_MemTable_t PcRtems_MemoryTable[CFE_PSP_MEM_TABLE_SIZE] = { + {CFE_PSP_MEM_RAM, CFE_PSP_MEM_SIZE_DWORD, 0, SIZE_MAX, CFE_PSP_MEM_ATTR_READWRITE}, {CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE}, {CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE}, {CFE_PSP_MEM_INVALID, 0, 0, 0, CFE_PSP_MEM_ATTR_READWRITE}, diff --git a/fsw/shared/inc/cfe_psp_memory.h b/fsw/shared/inc/cfe_psp_memory.h index 602340ce..108fbfc3 100644 --- a/fsw/shared/inc/cfe_psp_memory.h +++ b/fsw/shared/inc/cfe_psp_memory.h @@ -42,6 +42,18 @@ #include "cfe_psp_config.h" #include "cfe_psp_exceptionstorage_types.h" +/* +** Memory table type +*/ +typedef struct +{ + uint32 MemoryType; + size_t WordSize; + cpuaddr StartAddr; + size_t Size; + uint32 Attributes; +} CFE_PSP_MemTable_t; + typedef struct { void * BlockPtr; @@ -58,6 +70,16 @@ typedef struct CFE_PSP_MemoryBlock_t VolatileDiskMemory; CFE_PSP_MemoryBlock_t CDSMemory; CFE_PSP_MemoryBlock_t UserReservedMemory; + + /** + * \brief The system memory table + * + * This is the table used for CFE_PSP_MemRangeGet/Set and related ops + * that allow CFE applications to query the general system memory map. + */ + CFE_PSP_MemTable_t *SysMemoryTable; + size_t SysMemoryTableSize; + } CFE_PSP_ReservedMemoryMap_t; /** diff --git a/fsw/shared/src/cfe_psp_configdata.c b/fsw/shared/src/cfe_psp_configdata.c index 4153b588..82f5d322 100644 --- a/fsw/shared/src/cfe_psp_configdata.c +++ b/fsw/shared/src/cfe_psp_configdata.c @@ -38,10 +38,8 @@ * code such as CFE core or apps would not be able to \#include the * PSP cfe_psp_config.h or psp_version.h files */ -Target_PspConfigData GLOBAL_PSP_CONFIGDATA = {.PSP_WatchdogMin = CFE_PSP_WATCHDOG_MIN, - .PSP_WatchdogMax = CFE_PSP_WATCHDOG_MAX, - .PSP_MemTableSize = CFE_PSP_MEM_TABLE_SIZE, - .PSP_MemoryTable = CFE_PSP_MemoryTable, +Target_PspConfigData GLOBAL_PSP_CONFIGDATA = {.PSP_WatchdogMin = CFE_PSP_WATCHDOG_MIN, + .PSP_WatchdogMax = CFE_PSP_WATCHDOG_MAX, .HW_NumEepromBanks = CFE_PSP_NUM_EEPROM_BANKS, diff --git a/fsw/shared/src/cfe_psp_memrange.c b/fsw/shared/src/cfe_psp_memrange.c index 8ddd7800..b8675eb1 100644 --- a/fsw/shared/src/cfe_psp_memrange.c +++ b/fsw/shared/src/cfe_psp_memrange.c @@ -35,12 +35,7 @@ */ #include "cfe_psp.h" - -/* - * The "extern" declaration for the MemRange table is in the configdata header - */ -#include "cfe_psp_config.h" -#include "cfe_psp_configdata.h" +#include "cfe_psp_memory.h" /* ** Name: CFE_PSP_MemValidateRange @@ -68,15 +63,16 @@ ** CFE_PSP_INVALID_MEM_RANGE -- The Memory range associated with the address is not large enough to contain ** Address + Size. */ -int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType) +int32 CFE_PSP_MemValidateRange(cpuaddr Address, size_t Size, uint32 MemoryType) { - cpuaddr StartAddressToTest = Address; - cpuaddr EndAddressToTest = Address + Size - 1; - cpuaddr StartAddressInTable; - cpuaddr EndAddressInTable; - uint32 TypeInTable; - int32 ReturnCode = CFE_PSP_INVALID_MEM_ADDR; - uint32 i; + cpuaddr StartAddressToTest = Address; + cpuaddr EndAddressToTest = Address + Size - 1; + cpuaddr StartAddressInTable; + cpuaddr EndAddressInTable; + uint32 TypeInTable; + int32 ReturnCode = CFE_PSP_INVALID_MEM_ADDR; + size_t i; + CFE_PSP_MemTable_t *SysMemPtr; /* ** Before searching table, do a preliminary parameter validation @@ -91,16 +87,17 @@ int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType) return (CFE_PSP_INVALID_MEM_RANGE); } - for (i = 0; i < CFE_PSP_MEM_TABLE_SIZE; i++) + SysMemPtr = CFE_PSP_ReservedMemoryMap.SysMemoryTable; + for (i = 0; i < CFE_PSP_ReservedMemoryMap.SysMemoryTableSize; ++i) { /* ** Only look at valid memory table entries */ - if (CFE_PSP_MemoryTable[i].MemoryType != CFE_PSP_MEM_INVALID) + if (SysMemPtr->MemoryType != CFE_PSP_MEM_INVALID) { - StartAddressInTable = CFE_PSP_MemoryTable[i].StartAddr; - EndAddressInTable = CFE_PSP_MemoryTable[i].StartAddr + CFE_PSP_MemoryTable[i].Size - 1; - TypeInTable = CFE_PSP_MemoryTable[i].MemoryType; + StartAddressInTable = SysMemPtr->StartAddr; + EndAddressInTable = SysMemPtr->StartAddr + SysMemPtr->Size - 1; + TypeInTable = SysMemPtr->MemoryType; /* ** Step 1: Get the Address to Fit within the range @@ -152,6 +149,8 @@ int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType) } } /* End if MemoryType != CFE_PSP_MEM_INVALID */ + ++SysMemPtr; + } /* End for */ return (ReturnCode); } @@ -176,7 +175,7 @@ int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType) */ uint32 CFE_PSP_MemRanges(void) { - return (CFE_PSP_MEM_TABLE_SIZE); + return (CFE_PSP_ReservedMemoryMap.SysMemoryTableSize); } /* @@ -215,11 +214,12 @@ uint32 CFE_PSP_MemRanges(void) ** CFE_PSP_INVALID_MEM_WORDSIZE -- The WordSIze parameter is not one of the predefined types. ** CFE_PSP_INVALID_MEM_ATTR -- The Attributes parameter is not one of the predefined types. */ -int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, uint32 Size, uint32 WordSize, +int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, size_t Size, size_t WordSize, uint32 Attributes) { + CFE_PSP_MemTable_t *SysMemPtr; - if (RangeNum >= CFE_PSP_MEM_TABLE_SIZE) + if (RangeNum >= CFE_PSP_ReservedMemoryMap.SysMemoryTableSize) { return (CFE_PSP_INVALID_MEM_RANGE); } @@ -244,11 +244,13 @@ int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, /* ** Parameters check out, add the range */ - CFE_PSP_MemoryTable[RangeNum].MemoryType = MemoryType; - CFE_PSP_MemoryTable[RangeNum].StartAddr = StartAddr; - CFE_PSP_MemoryTable[RangeNum].Size = Size; - CFE_PSP_MemoryTable[RangeNum].WordSize = WordSize; - CFE_PSP_MemoryTable[RangeNum].Attributes = Attributes; + SysMemPtr = &CFE_PSP_ReservedMemoryMap.SysMemoryTable[RangeNum]; + + SysMemPtr->MemoryType = MemoryType; + SysMemPtr->StartAddr = StartAddr; + SysMemPtr->Size = Size; + SysMemPtr->WordSize = WordSize; + SysMemPtr->Attributes = Attributes; return (CFE_PSP_SUCCESS); } @@ -284,25 +286,28 @@ int32 CFE_PSP_MemRangeSet(uint32 RangeNum, uint32 MemoryType, cpuaddr StartAddr, ** CFE_PSP_INVALID_POINTER -- Parameter error ** CFE_PSP_INVALID_MEM_RANGE -- The index into the table is invalid */ -int32 CFE_PSP_MemRangeGet(uint32 RangeNum, uint32 *MemoryType, cpuaddr *StartAddr, uint32 *Size, uint32 *WordSize, +int32 CFE_PSP_MemRangeGet(uint32 RangeNum, uint32 *MemoryType, cpuaddr *StartAddr, size_t *Size, size_t *WordSize, uint32 *Attributes) { + CFE_PSP_MemTable_t *SysMemPtr; if (MemoryType == NULL || StartAddr == NULL || Size == NULL || WordSize == NULL || Attributes == NULL) { return (CFE_PSP_INVALID_POINTER); } - if (RangeNum >= CFE_PSP_MEM_TABLE_SIZE) + if (RangeNum >= CFE_PSP_ReservedMemoryMap.SysMemoryTableSize) { return (CFE_PSP_INVALID_MEM_RANGE); } - *MemoryType = CFE_PSP_MemoryTable[RangeNum].MemoryType; - *StartAddr = CFE_PSP_MemoryTable[RangeNum].StartAddr; - *Size = CFE_PSP_MemoryTable[RangeNum].Size; - *WordSize = CFE_PSP_MemoryTable[RangeNum].WordSize; - *Attributes = CFE_PSP_MemoryTable[RangeNum].Attributes; + SysMemPtr = &CFE_PSP_ReservedMemoryMap.SysMemoryTable[RangeNum]; + + *MemoryType = SysMemPtr->MemoryType; + *StartAddr = SysMemPtr->StartAddr; + *Size = SysMemPtr->Size; + *WordSize = SysMemPtr->WordSize; + *Attributes = SysMemPtr->Attributes; return (CFE_PSP_SUCCESS); } diff --git a/ut-stubs/ut_psp_stubs.c b/ut-stubs/ut_psp_stubs.c index b4369008..50b0888a 100644 --- a/ut-stubs/ut_psp_stubs.c +++ b/ut-stubs/ut_psp_stubs.c @@ -625,7 +625,7 @@ int32 CFE_PSP_MemRead8(cpuaddr Address, uint8 *Data) ** Returns either a user-defined status flag or OS_SUCCESS. ** ******************************************************************************/ -int32 CFE_PSP_MemValidateRange(cpuaddr Address, uint32 Size, uint32 MemoryType) +int32 CFE_PSP_MemValidateRange(cpuaddr Address, size_t Size, uint32 MemoryType) { int32 status;