Skip to content

Commit

Permalink
Fix nasa#263, basic proof of concept for selectable eeprom implementa…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
jphickey committed Mar 9, 2021
1 parent 0ccebed commit f3defa1
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 9 deletions.
25 changes: 23 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,44 @@ target_compile_definitions(psp_module_api INTERFACE
target_include_directories(psp_module_api INTERFACE
fsw/inc # public API
fsw/shared/inc # all PSP shared headers
${CMAKE_CURRENT_LIST_DIR}/fsw/${CFE_PSP_TARGETNAME}/inc # platform-specific headers
${CFE_SOURCE_DIR}/cmake/target/inc # for sysconfig
$<TARGET_PROPERTY:osal,INTERFACE_INCLUDE_DIRECTORIES> # use headers from OSAL
)

# Translate the CFE_PSP_TARGETNAME to a set of additional modules to build
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/fsw/${CFE_PSP_TARGETNAME}/psp_module_list.cmake" PSP_TARGET_MODULE_LIST REGEX "^[a-zA-Z]")

# The PSP is currently built in two parts, consisting of a fully platform-specific
# module combined with a shared component which is built for multiple targets.
# The PSP is currently built in modular parts, consisting of a platform-specific
# module(s) combined with a shared component which is built for multiple targets.
# The "shared" component is compiled using headers from the platform-specific module
# so it is still ultimately a platform-specific binary, and it all gets wrapped into
# a single PSP static library target.
add_subdirectory(fsw/${CFE_PSP_TARGETNAME} ${CFE_PSP_TARGETNAME}-impl)
add_subdirectory(fsw/shared ${CFE_PSP_TARGETNAME}-shared)

# Generate a list of PSP modules along with a pointer to its API structure/entry point
set(GENERATED_EXTERNS)
set(GENERATED_KEYVALS)
foreach(PSPMOD ${PSP_TARGET_MODULE_LIST})
add_subdirectory(fsw/modules/${PSPMOD} ${PSPMOD}-${CFE_PSP_TARGETNAME}-impl)
list(APPEND GENERATED_EXTERNS "extern CFE_PSP_ModuleApi_t CFE_PSP_${PSPMOD}_API;\n")
list(APPEND GENERATED_KEYVALS "{ .Name = \"${PSPMOD}\", .Api = &CFE_PSP_${PSPMOD}_API },\n")
endforeach()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/module_list.c.in ${CMAKE_CURRENT_BINARY_DIR}/${CFE_PSP_TARGETNAME}_module_list.c @ONLY)

add_library(psp-${CFE_PSP_TARGETNAME} STATIC
${CMAKE_CURRENT_BINARY_DIR}/${CFE_PSP_TARGETNAME}_module_list.c
$<TARGET_OBJECTS:psp-${CFE_PSP_TARGETNAME}-shared>
$<TARGET_OBJECTS:psp-${CFE_PSP_TARGETNAME}-impl>
)
target_link_libraries(psp-${CFE_PSP_TARGETNAME} PUBLIC
${PSP_TARGET_MODULE_LIST}
)
target_link_libraries(psp-${CFE_PSP_TARGETNAME} PRIVATE
psp_module_api
)

target_include_directories(psp-${CFE_PSP_TARGETNAME} INTERFACE
fsw/inc
Expand Down
37 changes: 37 additions & 0 deletions arch_build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
###########################################################
#
# CFE arch/platform build setup
#
# This file is evaluated as part of the "prepare" stage
# and can be used to set up prerequisites for the build,
# such as generating header files
#
###########################################################

## Check that PSPNAME is set properly for this arch
#if (NOT CFE_SYSTEM_PSPNAME)
# if (CMAKE_CROSSCOMPILING)
# message(FATAL_ERROR "Cross-compile toolchain ${CMAKE_TOOLCHAIN_FILE} must define CFE_SYSTEM_PSPNAME")
# elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR
# "${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
# # Export the variables determined here up to the parent scope
# SET(CFE_SYSTEM_PSPNAME "pc-linux")
# else ()
# # Not cross compiling and host system is not recognized
# message(FATAL_ERROR "Do not know how to set CFE_SYSTEM_PSPNAME on ${CMAKE_SYSTEM_NAME} system")
# endif()
#endif (NOT CFE_SYSTEM_PSPNAME)
#
## Translate the CFE_SYSTEM_PSPNAME to a set of modules
#file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/cfe_pspdef_${CFE_SYSTEM_PSPNAME}.cmake" PSP_BASE_MODULE_LIST REGEX "^[a-zA-Z]")
#
## PREPEND the fixed module list to the user-specified module list for every CPU that shares this PSP
## Note the user may have listed extra modules in their targets.cmake, and order is important.
## JPHFIX - cleanup
#message("PSP_MODULE_LIST=${PSP_BASE_MODULE_LIST}")
#foreach(TGTNAME ${TGTSYS_${TARGETSYSTEM}})
# message("${TGTNAME}_PSP_MODULELIST (orig)=${${TGTNAME}_PSP_MODULELIST}")
# set(${TGTNAME}_PSP_MODULELIST ${PSP_BASE_MODULE_LIST} ${${TGTNAME}_PSP_MODULELIST})
# message("${TGTNAME}_PSP_MODULELIST (fixed)=${${TGTNAME}_PSP_MODULELIST}")
#endforeach()

12 changes: 12 additions & 0 deletions cmake/module_list.c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* This file is generated via CMake - do not edit in place */
#include "cfe_psp_module.h"

@GENERATED_EXTERNS@

CFE_StaticModuleLoadEntry_t CFE_PSP_BASE_MODULE_LIST[] =
{
@GENERATED_KEYVALS@
{ NULL }
};

/* END OF FILE */
4 changes: 4 additions & 0 deletions fsw/mcp750-vxworks/psp_module_list.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a list of modules that is included as a fixed/base set
# when this PSP is selected. They must exist under fsw/modules

eeprom_direct
3 changes: 3 additions & 0 deletions fsw/modules/eeprom_direct/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Create the module
add_psp_module(eeprom_direct cfe_psp_eeprom_direct.c)
File renamed without changes.
5 changes: 4 additions & 1 deletion fsw/modules/eeprom_mmap_file/cfe_psp_eeprom_mmap_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ void eeprom_mmap_file_Init(uint32 PspModuleId)
cpuaddr eeprom_address;
uint32 eeprom_size;

/* Inform the user that this module is in use */
printf("CFE_PSP: Using MMAP simulated EEPROM implementation\n");

/*
** Create the simulated EEPROM segment by mapping a memory segment to a file.
** Since the file will be saved, the "EEPROM" contents will be preserved.
Expand All @@ -187,7 +190,7 @@ void eeprom_mmap_file_Init(uint32 PspModuleId)
/*
** Install the 2nd memory range as the mapped file ( EEPROM )
*/
Status = CFE_PSP_MemRangeSet(1, CFE_PSP_MEM_EEPROM, eeprom_address, eeprom_size, CFE_PSP_MEM_SIZE_DWORD, 0);
Status = CFE_PSP_MemRangeSet(1, CFE_PSP_MEM_EEPROM, eeprom_address, eeprom_size, CFE_PSP_MEM_SIZE_DWORD, CFE_PSP_MEM_ATTR_READWRITE);
OS_printf("CFE_PSP: EEPROM Range (2) created: Start Address = %08lX, Size = %08X Status = %d\n",
(unsigned long)eeprom_address, (unsigned int)eeprom_size, Status);
}
Expand Down
3 changes: 2 additions & 1 deletion fsw/modules/eeprom_stub/cfe_psp_eeprom_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ CFE_PSP_MODULE_DECLARE_SIMPLE(eeprom_stub);

void eeprom_stub_Init(uint32 PspModuleId)
{
/* Nothing to init */
/* Inform the user that this module is in use */
printf("CFE_PSP: Using STUB EEPROM implementation\n");
}

int32 CFE_PSP_EepromWrite32(cpuaddr MemoryAddress, uint32 uint32Value)
Expand Down
4 changes: 4 additions & 0 deletions fsw/pc-linux/psp_module_list.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a list of modules that is included as a fixed/base set
# when this PSP is selected. They must exist under fsw/modules

eeprom_mmap_file
4 changes: 4 additions & 0 deletions fsw/pc-rtems/psp_module_list.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a list of modules that is included as a fixed/base set
# when this PSP is selected. They must exist under fsw/modules

eeprom_stub
1 change: 0 additions & 1 deletion fsw/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# Build the shared implementation as a library
add_library(psp-${CFE_PSP_TARGETNAME}-shared OBJECT
src/cfe_psp_configdata.c
src/cfe_psp_eeprom.c
src/cfe_psp_exceptionstorage.c
src/cfe_psp_memrange.c
src/cfe_psp_memutils.c
Expand Down
8 changes: 8 additions & 0 deletions fsw/shared/inc/cfe_psp_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ int32 CFE_PSP_Module_FindByName(const char *ModuleName, uint32 *PspModuleId);
*/
int32 CFE_PSP_Module_GetAPIEntry(uint32 PspModuleId, CFE_PSP_ModuleApi_t **API);


/**
* \brief A list of fixed/base modules associated with the PSP
*
* This list should be generated by the build system based on the user-selected PSP
*/
extern CFE_StaticModuleLoadEntry_t CFE_PSP_BASE_MODULE_LIST[];

#endif /* CFE_PSP_MODULE_H_ */
23 changes: 19 additions & 4 deletions fsw/shared/src/cfe_psp_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@

static uint32 CFE_PSP_ModuleCount = 0;


/***************************************************
* Function Name: CFE_PSP_ModuleInit
* Function Name: CFE_PSP_ModuleInitList
*
* See prototype for full description
* Helper function to initalize a list of modules (not externally called)
*/
void CFE_PSP_ModuleInit(void)
void CFE_PSP_ModuleInitList(CFE_StaticModuleLoadEntry_t *ListPtr)
{
CFE_StaticModuleLoadEntry_t *Entry;
CFE_PSP_ModuleApi_t * ApiPtr;

/*
* Call the init function for all statically linked modules
*/
Entry = GLOBAL_CONFIGDATA.PspModuleList;
Entry = ListPtr;
if (Entry != NULL)
{
while (Entry->Name != NULL)
Expand All @@ -75,6 +76,20 @@ void CFE_PSP_ModuleInit(void)
}
}

/***************************************************
* Function Name: CFE_PSP_ModuleInit
*
* See prototype for full description
*/
void CFE_PSP_ModuleInit(void)
{
/* First initialize the fixed set of modules for this PSP */
CFE_PSP_ModuleInitList(CFE_PSP_BASE_MODULE_LIST);

/* Then initialize any user-selected extension modules */
CFE_PSP_ModuleInitList(GLOBAL_CONFIGDATA.PspModuleList);
}

/***************************************************
* Function Name: CFE_PSP_Module_GetAPIEntry
*
Expand Down
5 changes: 5 additions & 0 deletions unit-test-coverage/ut-stubs/src/cfe-configdata-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

#include <PCS_cfe_configdata.h>

CFE_StaticModuleLoadEntry_t CFE_PSP_BASE_MODULE_LIST[] =
{
{ NULL }
};

Target_CfeConfigData GLOBAL_CFE_CONFIGDATA = {

/**
Expand Down

0 comments on commit f3defa1

Please sign in to comment.