Skip to content

Commit

Permalink
Fix nasa#1349, Break up pc-rtems to support generic configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Feb 23, 2024
1 parent 403ebba commit 451486a
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 255 deletions.
41 changes: 34 additions & 7 deletions src/bsp/pc-rtems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,41 @@
#
######################################################################

# Basic set of files
set(OS_BSP_SRCLIST
src/bsp_console.c
src/bsp_start.c
)

# If not dynamic loading, include Init and config
if (NOT RTEMS_DYNAMIC_LOAD)
list(APPEND OS_BSP_SRCLIST
src/bsp_init.c
src/bsp_setupfs.c # TODO move to only if enabled
)

# TODO could add the two flags for FS support vs adding from include

# Link the RTEMS BSP with the "rtemscpu" system library
target_link_libraries(osal_public_api INTERFACE
rtemscpu
)
endif ()

if (RTEMS_NO_SHELL)
list(APPEND OS_BSP_SRCLIST
src/bsp_no_shell.c
)
else ()
list(APPEND OS_BSP_SRCLIST
src/bsp_shell.c
)
endif ()

# TODO add the cmdline if not RTEMS_NO_CMDLINE

add_library(osal_pc-rtems_impl OBJECT
src/bsp_start.c
src/bsp_console.c
${OS_BSP_SRCLIST}
)

# This definition is needed for the gethostname call
Expand All @@ -16,9 +48,4 @@ target_compile_definitions(osal_public_api INTERFACE
_BSD_SOURCE
)

# Link the RTEMS BSP with the "rtemscpu" system library
target_link_libraries(osal_public_api INTERFACE
rtemscpu
)

set_property(TARGET osal_pc-rtems_impl PROPERTY OSAL_EXPECTED_OSTYPE "rtems")
131 changes: 131 additions & 0 deletions src/bsp/pc-rtems/src/bsp_cmdline.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/*
* \file
*
* OSAL BSP command line implementation
*/

/*
** Include Files
*/
/* TODO clean these */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <bsp.h>
#include <rtems.h>
#include <rtems/bdbuf.h>
#include <rtems/blkdev.h>
#include <rtems/diskdevs.h>
#include <rtems/bdpart.h>
#include <rtems/error.h>
#include <rtems/ramdisk.h>
#include <rtems/dosfs.h>
#include <rtems/fsmount.h>

/* TODO remove or refactor? Still needs global */
#include "pcrtems_bsp_internal.h"

void OS_BSP_CmdLine(void)
{
const char *cmdlinestr;
const char *cmdp;
char * cmdi, *cmdo;

cmdlinestr = bsp_cmdline();

/*
* Parse command line string (passed in from bootloader)
*
* Known arguments are handled here, and unknown args are
* saved for the UT application.
*
* Batch mode is intended for non-interactive execution.
*
* It does two things:
* - do not start the shell task
* - when tests are complete, shutdown the executive
*
* The BSP should be configured with these options to
* make this most useful:
* USE_COM1_AS_CONSOLE=1
* BSP_PRESS_KEY_FOR_RESET=0
* BSP_RESET_BOARD_AT_EXIT=1
*
* This way all the test output will be sent to COM1
* and then immediately resets the CPU when done.
*
* When running under QEMU the "-no-reboot" flag is
* also useful to shutdown QEMU rather than resetting.
*/
if (cmdlinestr != NULL)
{
printf(" Bootloader Command Line: %s\n", cmdlinestr);

cmdp = cmdlinestr;
cmdo = NULL;
cmdi = NULL;

while (1)
{
if (isgraph((int)*cmdp))
{
if (cmdo == NULL)
{
cmdo = OS_BSP_PcRtemsGlobal.UserArgBuffer;
}
else
{
++cmdo;
}
if (cmdi == NULL)
{
cmdi = cmdo;
}
*cmdo = *cmdp;
}
else if (cmdi != NULL)
{
++cmdo;
*cmdo = 0;
if (strcmp(cmdi, "--batch-mode") == 0)
{
OS_BSP_PcRtemsGlobal.BatchMode = true;
}
else if (OS_BSP_Global.ArgC < RTEMS_MAX_USER_OPTIONS)
{
/* save other args for app */
OS_BSP_Global.ArgV[OS_BSP_Global.ArgC] = cmdi;
++OS_BSP_Global.ArgC;
}
cmdi = NULL;
}

if (*cmdp == 0)
{
break;
}

++cmdp;
}
}
}
3 changes: 1 addition & 2 deletions src/bsp/pc-rtems/src/bsp_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
************************************************************************/

/*
* File: bsp_console.c
* \file
*
* Purpose:
* OSAL BSP debug console abstraction
*/

Expand Down
98 changes: 98 additions & 0 deletions src/bsp/pc-rtems/src/bsp_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/*
* \file
*
* RTEMS main entry point
* Configures RTEMS and wraps OS_BSPMain for use in a stand alone executable
*/

/*
** Include Files
*/
#include "bsp_start.h"
#include "bsp-impl.h"
#include <rtems.h>

/*
** A simple entry point to start from the loader
*/
rtems_task Init(rtems_task_argument ignored)
{
OS_BSPMain();
}

/* configuration information */

/*
** RTEMS OS Configuration definitions
*/
#define TASK_INTLEVEL 0
#define CONFIGURE_INIT
#define CONFIGURE_INIT_TASK_ATTRIBUTES \
(RTEMS_FLOATING_POINT | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(TASK_INTLEVEL))
#define CONFIGURE_INIT_TASK_STACK_SIZE (20 * 1024)
#define CONFIGURE_INIT_TASK_PRIORITY 10

/*
* Note that these resources are shared with RTEMS itself (e.g. the init task, the shell)
* so they should be allocated slightly higher than the user limits in osconfig.h
*
* Many RTEMS services use tasks internally, including the idle task, BSWP, ATA driver,
* low level console I/O, the shell, TCP/IP network stack, and DHCP (if enabled).
* Many of these also use semaphores for synchronization.
*
* Budgeting for additional:
* 8 internal tasks
* 2 internal timers
* 4 internal queues
* 16 internal semaphores
*
*/
#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 8)
#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_MAXIMUM_DRIVERS 10
#define CONFIGURE_MAXIMUM_POSIX_KEYS 4
#ifdef OS_RTEMS_4_DEPRECATED
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8)
#else
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8)
#endif

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_FILESYSTEM_RFS
#define CONFIGURE_FILESYSTEM_IMFS
#define CONFIGURE_FILESYSTEM_DOSFS
#define CONFIGURE_FILESYSTEM_DEVFS
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK

/* TODO figure out how to switch these if needed
#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER */

#define CONFIGURE_EXECUTIVE_RAM_SIZE (8 * 1024 * 1024)
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 9

#include <rtems/confdefs.h>
36 changes: 36 additions & 0 deletions src/bsp/pc-rtems/src/bsp_no_shell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/

/*
* \file
*
* OSAL BSP no shell implementation
*/

#include <stdio.h>

/* TODO needs the global, but may want to split this up */
#include "pcrtems_bsp_internal.h"

/* TODO add bsp_shell.h */

void OS_BSP_Shell(void)
{
printf("RTEMS_NO_SHELL:TRUE, shell not implemented");
OS_BSP_PcRtemsGlobal.BatchMode = true;
}
Loading

0 comments on commit 451486a

Please sign in to comment.