Skip to content

Commit

Permalink
Merge pull request #9 from SPRESENSE/cherry-pick-from-official-nuttx-…
Browse files Browse the repository at this point in the history
…wk1920

Cherry pick "board_timerhook" function from official NuttX repository
  • Loading branch information
SPRESENSE authored May 16, 2019
2 parents 74a9be9 + bf8f4a9 commit 31c486d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
26 changes: 24 additions & 2 deletions include/nuttx/board.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/board.h
*
* Copyright (C) 2015-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2015-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -235,6 +235,28 @@ int board_reset(int status);
int board_uniqueid(FAR uint8_t *uniqueid);
#endif

/****************************************************************************
* Name: board_timerhook
*
* Description:
* If the system is not configured for Tickless operation, then a system
* timer interrupt will be used. If CONFIG_SYSTEMTICK_HOOK is selected
* then the OS will call out to this user-provided function on every
* timer interrupt. This permits custom actions that may be performed on
* each by boad-specific, OS internal logic.
*
* Input Parameters:
* None
*
* Returned Value:
* None.
*
****************************************************************************/

#ifdef CONFIG_SYSTEMTICK_HOOK
void board_timerhook(void);
#endif

/****************************************************************************
* Name: board_<usbdev>_initialize
*
Expand Down Expand Up @@ -669,7 +691,7 @@ void board_crashdump(uintptr_t currentsp, FAR void *tcb,
#endif

/****************************************************************************
* Name: board_initrngseed
* Name: board_init_rngseed
*
* Description:
* If CONFIG_BOARD_INITRNGSEED is selected then board_init_rngseed is
Expand Down
12 changes: 12 additions & 0 deletions sched/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ config SYSTEMTICK_EXTCLK
to move the scheduling off the processor clock to allow entering low
power states that would disable that clock.

config SYSTEMTICK_HOOK
bool "System timer hook"
default n
---help---
Enable a call to a user-provided, board-level function on each timer
tick. This permits custom actions that may be performed on each
timer tick. The form of the user-provided function is:

void board_timerhook(void);

(prototyped in include/nuttx/board.h).

endif # !SCHED_TICKLESS

config SYSTEM_TIME64
Expand Down
14 changes: 13 additions & 1 deletion sched/sched/sched_processtimer.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_processtimer.c
*
* Copyright (C) 2007, 2009, 2014-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2014-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -46,6 +46,10 @@
# include <nuttx/arch.h>
#endif

#ifdef CONFIG_SYSTEMTICK_HOOK
# include <nuttx/board.h>
#endif

#include "sched/sched.h"
#include "wdog/wdog.h"
#include "clock/clock.h"
Expand Down Expand Up @@ -222,4 +226,12 @@ void sched_process_timer(void)
*/

sched_process_scheduler();

#ifdef CONFIG_SYSTEMTICK_HOOK
/* Call out to a user-provided function in order to perform board-specific,
* custom timer operations.
*/

board_timerhook();
#endif
}

0 comments on commit 31c486d

Please sign in to comment.