Skip to content

Commit

Permalink
Fix #261, Consolidate unit test and normal BSP
Browse files Browse the repository at this point in the history
Refactor the OSAL BSP code so that a single BSP implementation
can work for both normal applications as well as unit tests.

This intoduces a new bsp implementation abstraction layer akin
to the low level OS implementation layer.  This handles dealing
with bootloader/command line arguments, and debug console
manipluation.
  • Loading branch information
jphickey committed Apr 10, 2020
1 parent 2f24f3f commit f9b9b85
Show file tree
Hide file tree
Showing 34 changed files with 1,586 additions and 1,702 deletions.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ add_subdirectory(ut_assert)
# The Implementation-Specific BSP subdirectory should define
# an OBJECT target named "osal_${OSAL_SYSTEM_BSPTYPE}_impl"
add_subdirectory(src/bsp/${OSAL_SYSTEM_BSPTYPE} ${OSAL_SYSTEM_BSPTYPE}_impl)
target_include_directories(osal_${OSAL_SYSTEM_BSPTYPE}_impl PRIVATE
${OSAL_SOURCE_DIR}/src/bsp/shared
)

# Propagate the BSP-specific compile definitions and include directories
# Apply these to the directory-scope COMPILE_DEFINITIONS and INCLUDE_DIRECTORIES
Expand All @@ -127,6 +130,10 @@ endif (OSAL_BSP_INCLUDE_DIRECTORIES)

# Define the external "osal_bsp" static library target
add_library(osal_bsp STATIC
src/bsp/shared/osapi-bsp.c
src/bsp/shared/bsp_default_app_run.c
src/bsp/shared/bsp_default_app_startup.c
src/bsp/shared/bsp_default_symtab.c
$<TARGET_OBJECTS:osal_${OSAL_SYSTEM_BSPTYPE}_impl>
)

Expand All @@ -147,6 +154,7 @@ add_subdirectory(src/os/${OSAL_SYSTEM_OSTYPE} ${OSAL_SYSTEM_OSTYPE}_impl)
# be referenced outside the OSAL code
target_include_directories(osal_${OSAL_SYSTEM_OSTYPE}_impl PRIVATE
${OSAL_SOURCE_DIR}/src/os/shared
${OSAL_SOURCE_DIR}/src/bsp/shared
)

# Define the external "osal" static library target
Expand Down Expand Up @@ -182,6 +190,9 @@ target_include_directories(osal INTERFACE
${OSAL_API_INCLUDE_DIRECTORIES}
)

# Link the OSAL with the BSP
target_link_libraries(osal osal_bsp)

# propagate the BSP-specific compile flags to OSAL external library target, if defined
if (OSAL_BSP_COMPILE_DEFINITIONS)
target_compile_definitions(osal INTERFACE
Expand Down Expand Up @@ -218,7 +229,7 @@ if (ENABLE_UNIT_TESTS)
function(add_osal_ut_exe TGTNAME)

add_executable(${TGTNAME} ${ARGN})
target_link_libraries(${TGTNAME} ut_assert ut_bsp osal)
target_link_libraries(${TGTNAME} ut_assert osal)
add_test(${TGTNAME} ${TGTNAME})
foreach(TGT ${INSTALL_TARGET_LIST})
install(TARGETS ${TGTNAME} DESTINATION ${TGT}/${UT_INSTALL_SUBDIR})
Expand Down
9 changes: 2 additions & 7 deletions src/bsp/mcp750-vxworks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#
######################################################################

add_library(osal_mcp750-vxworks_impl OBJECT
add_library(osal_mcp750-vxworks_impl OBJECT
src/bsp_start.c
src/bsp_voltab.c
src/bsp_console.c
)

target_include_directories(osal_mcp750-vxworks_impl PUBLIC
Expand All @@ -22,10 +23,4 @@ target_compile_definitions(osal_mcp750-vxworks_impl PUBLIC
"MCP750"
)

add_library(ut_bsp STATIC EXCLUDE_FROM_ALL
ut-src/bsp_ut.c
ut-src/bsp_ut_voltab.c
)
target_include_directories(ut_bsp PRIVATE ${UT_ASSERT_SOURCE_DIR}/inc)


52 changes: 52 additions & 0 deletions src/bsp/mcp750-vxworks/src/bsp_console.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/******************************************************************************
** File: bsp_console.c
**
**
** This is governed by the NASA Open Source Agreement and may be used,
** distributed and modified only pursuant to the terms of that agreement.
**
** Copyright (c) 2004-2006, United States government as represented by the
** administrator of the National Aeronautics Space Administration.
** All rights reserved.
**
**
** Purpose:
** OSAL BSP debug console abstraction
**
******************************************************************************/

#include <string.h>
#include <unistd.h>
#include <stdio.h>

#include "mcp750_bsp_internal.h"
#include "bsp-impl.h"

/****************************************************************************************
BSP CONSOLE IMPLEMENTATION FUNCTIONS
****************************************************************************************/

/*----------------------------------------------------------------
OS_BSP_ConsoleOutput_Impl
See full description in header
------------------------------------------------------------------*/
void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen)
{
while (DataLen > 0)
{
putchar(*Str);
++Str;
--DataLen;
}
}

/*----------------------------------------------------------------
OS_BSP_ConsoleSetMode_Impl() definition
See full description in header
------------------------------------------------------------------*/
void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits)
{
/* ignored; not implemented */
}


71 changes: 30 additions & 41 deletions src/bsp/mcp750-vxworks/src/bsp_start.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/******************************************************************************
** File: bsp_start.c
**
** This is governed by the NASA Open Source Agreement and may be used,
** distributed and modified only pursuant to the terms of that agreement.
** This is governed by the NASA Open Source Agreement and may be used,
** distributed and modified only pursuant to the terms of that agreement.
**
** Copyright (c) 2004-2006, United States government as represented by the
** administrator of the National Aeronautics Space Administration.
** All rights reserved.
** Copyright (c) 2004-2006, United States government as represented by the
** administrator of the National Aeronautics Space Administration.
** All rights reserved.
**
** Purpose:
**
**
** OSAL main entry point.
**
** History:
Expand All @@ -19,23 +19,10 @@
/*
** Include Files
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "vxWorks.h"
#include "sysLib.h"
#include "taskLib.h"

/*
** OSAL includes
*/
#include "common_types.h"
#include "osapi.h"
#include <string.h>

/*
** External Declarations
*/
void OS_Application_Startup(void);
#include "mcp750_bsp_internal.h"

/******************************************************************************
** Function: OS_BSPMain()
Expand All @@ -47,30 +34,32 @@ void OS_Application_Startup(void);
** (none)
**
** Return:
** (none)
** integer return code, with zero indicating normal exit, nonzero
** indicating an off-nominal condition
*/

void OS_BSPMain( void )
int OS_BSPMain(void)
{
int TicksPerSecond;

/*
** Delay for one second.
*/
TicksPerSecond = sysClkRateGet();
(void) taskDelay( TicksPerSecond );
/*
* Initially clear the global object (this contains return code)
*/
memset(&OS_BSP_Global, 0, sizeof(OS_BSP_Global));

OS_printf("Starting Up OSAPI App.\n");

/*
** Call OSAL entry point.
*/
OS_Application_Startup();
/*
* Call application specific entry point.
* This should set up all user tasks and resources, then return
*/
OS_Application_Startup();

/*
** Exit the main thread.
** in VxWorks we can delete all of the OS tasks if we want.
*/
/*
* OS_Application_Run() implements the background task.
* The user application may provide this, or a default implementation
* is used which just calls OS_IdleLoop().
*/
OS_Application_Run();

/*
* Return to shell with the current status code
*/
return OS_BSP_Global.AppStatus;
}

27 changes: 27 additions & 0 deletions src/bsp/mcp750-vxworks/src/mcp750_bsp_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/******************************************************************************
** File: mcp750_bsp_internal.h
**
**
** This is governed by the NASA Open Source Agreement and may be used,
** distributed and modified only pursuant to the terms of that agreement.
**
** Copyright (c) 2004-2006, United States government as represented by the
** administrator of the National Aeronautics Space Administration.
** All rights reserved.
**
**
** Purpose:
** Header file for internal data to the MCP750 BSP
**
******************************************************************************/

#ifndef _MCP750_BSP_INTERNAL_H_
#define _MCP750_BSP_INTERNAL_H_

/*
** OSAL includes
*/
#include "osapi.h"
#include "bsp-impl.h"

#endif /* _MCP750_BSP_INTERNAL_H_ */
Loading

0 comments on commit f9b9b85

Please sign in to comment.