From b7680650312742436c31572c6db7259ebbaee509 Mon Sep 17 00:00:00 2001 From: Alan Cudmore Date: Wed, 25 Nov 2020 12:59:27 -0500 Subject: [PATCH] Fix #608 - Add RTEMS 5.x support --- src/bsp/pc-rtems/CMakeLists.txt | 7 +++++++ src/bsp/pc-rtems/src/bsp_start.c | 14 +++++++++----- src/bsp/pc-rtems/src/pcrtems_bsp_internal.h | 9 +++++++++ src/os/rtems/inc/os-rtems.h | 14 ++++++++++++++ src/os/rtems/src/os-impl-heap.c | 4 ++-- src/os/rtems/src/os-impl-loader.c | 8 ++++---- 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/bsp/pc-rtems/CMakeLists.txt b/src/bsp/pc-rtems/CMakeLists.txt index 9b5a0af99..c6f6a1b29 100644 --- a/src/bsp/pc-rtems/CMakeLists.txt +++ b/src/bsp/pc-rtems/CMakeLists.txt @@ -9,6 +9,13 @@ add_library(osal_pc-rtems_impl OBJECT src/bsp_console.c ) +# This definition is needed for the gethostname call +# By defining this, it avoids the need to use the -std=gnu99 +# instead of the preferred -std=c99 GCC switch +target_compile_definitions(osal_pc-rtems_impl PUBLIC + _BSD_SOURCE +) + # This BSP only works with "rtems" OS layer. # Confirming this reduces risk of accidental misconfiguration set(OSAL_EXPECTED_OSTYPE "rtems" PARENT_SCOPE) diff --git a/src/bsp/pc-rtems/src/bsp_start.c b/src/bsp/pc-rtems/src/bsp_start.c index 2bbad651b..ce6ef503e 100644 --- a/src/bsp/pc-rtems/src/bsp_start.c +++ b/src/bsp/pc-rtems/src/bsp_start.c @@ -83,10 +83,10 @@ void OS_BSP_Setup(void) cmdlinestr = bsp_cmdline(); printf("\n\n*** RTEMS Info ***\n"); - printf("%s", _Copyright_Notice); - printf("%s\n\n", _RTEMS_version); - printf(" Stack size=%d\n", (int)Configuration.stack_space_size); - printf(" Workspace size=%d\n", (int)Configuration.work_space_size); + printf("%s", OSAL_BSP_COPYRIGHT_NOTICE); + printf("%s\n\n", rtems_get_version_string()); + printf(" Stack size=%d\n", (int)rtems_configuration_get_stack_space_size()); + printf(" Workspace size=%d\n", (int)rtems_configuration_get_work_space_size()); if (cmdlinestr != NULL) { printf(" Bootloader Command Line: %s\n", cmdlinestr); @@ -374,9 +374,13 @@ rtems_task Init(rtems_task_argument ignored) #define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2) #define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 16) #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 4) -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) #define CONFIGURE_MAXIMUM_DRIVERS 10 #define CONFIGURE_MAXIMUM_POSIX_KEYS 4 +#ifdef _RTEMS_5_ + #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) +#else + #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8) +#endif #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER diff --git a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h index 8d3690596..12c04509c 100644 --- a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h +++ b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h @@ -40,6 +40,15 @@ #define RTEMS_MAX_USER_OPTIONS 4 #define RTEMS_MAX_CMDLINE 256 +/* + * Handle the differences between RTEMS 5 and 4.11 copyright notice + */ +#ifdef _RTEMS_5_ + #define OSAL_BSP_COPYRIGHT_NOTICE rtems_get_copyright_notice() +#else + #define OSAL_BSP_COPYRIGHT_NOTICE _Copyright_Notice +#endif + /* * The location which the general purpose file system will be mounted */ diff --git a/src/os/rtems/inc/os-rtems.h b/src/os/rtems/inc/os-rtems.h index c8cf01159..5e37bad1a 100644 --- a/src/os/rtems/inc/os-rtems.h +++ b/src/os/rtems/inc/os-rtems.h @@ -52,6 +52,20 @@ /**************************************************************************************** DEFINES ***************************************************************************************/ +/* + * Handle the data structure and API name changes between RTEMS 4.11 and RTEMS 5.1 + */ +#ifdef _RTEMS_5_ + #define OSAL_HEAP_INFO_BLOCK Heap_Information_block + #define OSAL_UNRESOLV_REC_TYPE rtems_rtl_unresolv_rec + #define OSAL_UNRESOLVED_SYMBOL rtems_rtl_unresolved_symbol + #define OSAL_UNRESOLVED_ITERATE rtems_rtl_unresolved_iterate +#else + #define OSAL_HEAP_INFO_BLOCK region_information_block + #define OSAL_UNRESOLV_REC_TYPE rtems_rtl_unresolv_rec_t + #define OSAL_UNRESOLVED_SYMBOL rtems_rtl_unresolved_name + #define OSAL_UNRESOLVED_ITERATE rtems_rtl_unresolved_interate +#endif /**************************************************************************************** TYPEDEFS diff --git a/src/os/rtems/src/os-impl-heap.c b/src/os/rtems/src/os-impl-heap.c index 17addccc0..4e67125cb 100644 --- a/src/os/rtems/src/os-impl-heap.c +++ b/src/os/rtems/src/os-impl-heap.c @@ -46,8 +46,8 @@ *-----------------------------------------------------------------*/ int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop) { - region_information_block info; - int status; + OSAL_HEAP_INFO_BLOCK info; + int status; status = malloc_info(&info); diff --git a/src/os/rtems/src/os-impl-loader.c b/src/os/rtems/src/os-impl-loader.c index 89fbbedce..3f174080c 100644 --- a/src/os/rtems/src/os-impl-loader.c +++ b/src/os/rtems/src/os-impl-loader.c @@ -73,14 +73,14 @@ int32 OS_Rtems_ModuleAPI_Impl_Init(void) * This could be fine-tuned later. * *-----------------------------------------------------------------*/ -static bool OS_rtems_rtl_check_unresolved(rtems_rtl_unresolv_rec_t *rec, void *data) +static bool OS_rtems_rtl_check_unresolved(OSAL_UNRESOLV_REC_TYPE *rec, void *data) { int32 *status = data; switch (rec->type) { - case rtems_rtl_unresolved_name: - OS_DEBUG("unresolved name: %s\n", rec->rec.name.name); + case OSAL_UNRESOLVED_SYMBOL: + OS_DEBUG("unresolved symbol: %s\n", rec->rec.name.name); *status = OS_ERROR; break; case rtems_rtl_unresolved_reloc: @@ -142,7 +142,7 @@ int32 OS_ModuleLoad_Impl(uint32 module_id, const char *translated_path) OS_DEBUG("module has has unresolved externals\n"); status = OS_SUCCESS; /* note - not final, probably overridden */ - rtems_rtl_unresolved_interate(OS_rtems_rtl_check_unresolved, &status); + OSAL_UNRESOLVED_ITERATE(OS_rtems_rtl_check_unresolved, &status); } else {