Skip to content

Commit

Permalink
Fix #263, selectable eeprom implementation
Browse files Browse the repository at this point in the history
Use the PSP module feature to allow selection/override of EEPROM accessors.
The current code is converted to an "eeprom_direct" module which is included
only on platforms where it is valid (e.g. mcp750, no mmu).
  • Loading branch information
jphickey committed Mar 16, 2021
1 parent 0f39a13 commit 3d15b72
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 9 deletions.
24 changes: 22 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,39 @@ target_include_directories(psp_module_api INTERFACE
$<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
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)
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
#include <stdio.h>

#include "cfe_psp.h"
#include "cfe_psp_module.h"

CFE_PSP_MODULE_DECLARE_SIMPLE(eeprom_direct);

void eeprom_direct_Init(uint32 PspModuleId)
{
/* Inform the user that this module is in use */
printf("CFE_PSP: Using DIRECT memory mapped EEPROM implementation\n");
}

/*
** global memory
Expand Down
6 changes: 5 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,8 @@ 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
7 changes: 7 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,11 @@ 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_ */
22 changes: 18 additions & 4 deletions fsw/shared/src/cfe_psp_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@
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 +75,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
2 changes: 2 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,8 @@

#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 3d15b72

Please sign in to comment.