sched/sched/sched_processtimer.c: Add a configurable call out to a user-provided function, 'timer hook', on each timer interrupt.

This commit is contained in:
Gregory Nutt 2019-01-30 07:22:44 -06:00
parent d70cb97950
commit 6408857f6d
3 changed files with 45 additions and 3 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/board.h
*
* Copyright (C) 2015-2018 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
@ -257,6 +257,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
*
@ -640,7 +662,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

View File

@ -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

View File

@ -1,7 +1,7 @@
/****************************************************************************
* sched/sched/sched_processtimer.c
*
* Copyright (C) 2007, 2009, 2014-2018 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
@ -222,4 +222,12 @@ void sched_process_timer(void)
/* Process watchdogs */
wd_timer();
#ifdef CONFIG_SYSTEMTICK_HOOK
/* Call out to a user-provided function in order to perform board-specific,
* custom timer operations.
*/
board_timerhook();
#endif
}