Skip to content

Commit

Permalink
Merge pull request #465 from jphickey/fix-457-bsp-shutdown-handler
Browse files Browse the repository at this point in the history
Fix #457, provide BSP shutdown handler
  • Loading branch information
astrogeco authored May 26, 2020
2 parents bc24490 + 042db6b commit f5a7224
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
11 changes: 11 additions & 0 deletions src/bsp/mcp750-vxworks/src/bsp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@

#include "mcp750_bsp_internal.h"

/* ---------------------------------------------------------
OS_BSP_Shutdown_Impl()
Helper function to abort the running task
--------------------------------------------------------- */
void OS_BSP_Shutdown_Impl(void)
{
abort();
}


/******************************************************************************
** Function: OS_BSPMain()
**
Expand Down
11 changes: 11 additions & 0 deletions src/bsp/pc-linux/src/bsp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ int OS_BSP_GetReturnStatus(void)
return retcode;
}

/* ---------------------------------------------------------
OS_BSP_Shutdown_Impl()
Helper function to abort the running task
--------------------------------------------------------- */
void OS_BSP_Shutdown_Impl(void)
{
abort();
}


/******************************************************************************
** Function: main()
**
Expand Down
41 changes: 28 additions & 13 deletions src/bsp/pc-rtems/src/bsp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,30 @@ rtems_status_code OS_BSP_GetReturnStatus(void)
return retcode;
}

/* ---------------------------------------------------------
OS_BSP_Shutdown_Impl()
Helper function to abort the running task
--------------------------------------------------------- */
void OS_BSP_Shutdown_Impl(void)
{
/*
* Not calling exit() under RTEMS, this simply shuts down the executive,
* forcing the user to reboot the system.
*
* Calling suspend causes execution to get stuck here, but the RTEMS
* shell thread will still be active so the user can poke around, read results,
* then use a shell command to reboot when ready.
*/
while (!OS_BSP_PcRtemsGlobal.BatchMode)
{
printf("\n\nInit thread idle.\nPress <enter> for shell or reset machine...\n\n");
rtems_task_suspend(rtems_task_self());
}

rtems_shutdown_executive(OS_BSP_GetReturnStatus());
}

/*
** A simple entry point to start from the loader
*/
Expand Down Expand Up @@ -332,20 +356,11 @@ rtems_task Init(rtems_task_argument ignored)
OS_Application_Run();

/*
* Not calling exit() under RTEMS, this simply shuts down the executive,
* forcing the user to reboot the system.
*
* Calling suspend causes execution to get stuck here, but the RTEMS
* shell thread will still be active so the user can poke around, read results,
* then use a shell command to reboot when ready.
* Enter the BSP default shutdown mode
* depending on config, this may reset/reboot or suspend
* so the operator can use the shell.
*/
while (!OS_BSP_PcRtemsGlobal.BatchMode)
{
printf("\n\nInit thread idle.\nPress <enter> for shell or reset machine...\n\n");
rtems_task_suspend(rtems_task_self());
}

rtems_shutdown_executive(OS_BSP_GetReturnStatus());
OS_BSP_Shutdown_Impl();
}

/* configuration information */
Expand Down
10 changes: 10 additions & 0 deletions src/bsp/shared/inc/bsp-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen);
------------------------------------------------------------------*/
void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits);

/*----------------------------------------------------------------
Function: OS_BSP_Shutdown_Impl
Purpose: Causes the calling task to abort in a BSP-safe way.
This may map to the abort() system call, but on some systems
that causes a reboot or undesirable side effect. The
BSP may implement this call in a different manner.
------------------------------------------------------------------*/
void OS_BSP_Shutdown_Impl(void);

/*********************
END bsp-impl.h
*********************/
Expand Down
4 changes: 2 additions & 2 deletions ut_assert/src/utbsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ void UT_BSP_DoText(uint8 MessageType, const char *OutputMessage)

/*
* If any ABORT (major failure) message is thrown,
* then actually call abort() to stop the test and dump a core
* then call a BSP-provided routine to stop the test and possibly dump a core
*/
if (MessageType == UTASSERT_CASETYPE_ABORT)
{
abort();
OS_BSP_Shutdown_Impl();
}
}

Expand Down

0 comments on commit f5a7224

Please sign in to comment.