diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-04-15 14:57:53 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-04-15 14:57:53 +0000 |
commit | f1893cbaf513c7f0fbca77240fc59707ad039734 (patch) | |
tree | 4a5128533aa866afa19719584a764f0f83b9d165 /nuttx/include/nuttx/clock.h | |
parent | c548df2a3788bfe7527f7fef439d1365cb095e7c (diff) | |
download | nuttx-f1893cbaf513c7f0fbca77240fc59707ad039734.tar.gz nuttx-f1893cbaf513c7f0fbca77240fc59707ad039734.tar.bz2 nuttx-f1893cbaf513c7f0fbca77240fc59707ad039734.zip |
Add time and uptime
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3506 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/include/nuttx/clock.h')
-rw-r--r-- | nuttx/include/nuttx/clock.h | 68 |
1 files changed, 55 insertions, 13 deletions
diff --git a/nuttx/include/nuttx/clock.h b/nuttx/include/nuttx/clock.h index 9a9523a2e..e06d2c0dd 100644 --- a/nuttx/include/nuttx/clock.h +++ b/nuttx/include/nuttx/clock.h @@ -41,13 +41,42 @@ ****************************************************************************/ #include <nuttx/config.h> + #include <stdint.h> +#include <time.h> /**************************************************************************** * Pro-processor Definitions ****************************************************************************/ +/* Configuration ************************************************************/ +/* Access to raw system clock ***********************************************/ +/* The system timer/counter is supported only if (1) the system clock is not + * disabled and (2) we are not configured to use a hardware periodic timer + * for system time. + */ + +#undef __HAVE_SYSTEM_COUNTER +#if !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_PTIMER) +# define __HAVE_SYSTEM_COUNTER 1 +#else +# define __HAVE_SYSTEM_COUNTER 0 +#endif + +/* Efficient, direct access to OS global timer variables will be supported + * if the execution environment has direct access to kernel global data. + * The code in this execution context can access the kernel global data + * directly if: (1) this is an un-protected, non-kernel build, or (2) + * this code is being built for execution within the kernel. + */ + +#undef __HAVE_KERNEL_GLOBALS +#if !defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__) +# define __HAVE_KERNEL_GLOBALS 1 +#else +# define __HAVE_KERNEL_GLOBALS 0 +#endif -/* Timing constants */ +/* Timing constants *********************************************************/ #define NSEC_PER_SEC 1000000000 #define USEC_PER_SEC 1000000 @@ -100,22 +129,30 @@ * Global Data ****************************************************************************/ +#if !defined(CONFIG_DISABLE_CLOCK) + /* Access to raw system clock ***********************************************/ /* Direct access to the system timer/counter is supported only if (1) the - * system clock is not disabled and (2) the executation environement has - * direct access to kernel global data. - * - * The code in this execution context can access the kernel global data - * directly if: (1) this is an un-protected, non-kernel build, or (2) - * this code is being built for execution within the kernel. + * system timer counter is available (i.e., we are not configured to use + * a hardware periodic timer), and (2) the execution environment has direct + * access to kernel global data */ -#if !defined(CONFIG_DISABLE_CLOCK) && \ - (!defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__)) +#if !defined(CONFIG_PTIMER) && __HAVE_KERNEL_GLOBALS extern volatile uint32_t g_system_timer; #define clock_systimer() g_system_timer #endif +/* System uptime (in seconds) is only supported by periodic timer hardware */ + +#if defined(CONFIG_UPTIME) +extern volatile uint32_t g_uptime; + +#if __HAVE_KERNEL_GLOBALS +# define clock_uptime() g_uptime +#endif +#endif + /**************************************************************************** * Global Function Prototypes ****************************************************************************/ @@ -131,18 +168,23 @@ extern "C" { #define EXTERN extern #endif -/* If direct access to the system timer/counter is not supported (see above), - * then the value can be obtained via clock_systimer through a system call. +/* Indirect access to the system time is required if (1) we are using a + * hardware periodic timer, OR (2) the execution environment does not have + * direct access to kernel global data */ -#if !defined(CONFIG_DISABLE_CLOCK) && \ - defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) +#if defined(CONFIG_PTIMER) || !__HAVE_KERNEL_GLOBALS EXTERN uint32_t clock_systimer(void); #endif +#if defined(CONFIG_UPTIME) && !__HAVE_KERNEL_GLOBALS +EXTERN time_t clock_uptime(void); +#endif + #undef EXTERN #ifdef __cplusplus } #endif +#endif /* !CONFIG_DISABLE_CLOCK */ #endif /* __NUTTX_CLOCK_H */ |