Add time and uptime

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3506 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2011-04-15 14:57:53 +00:00
parent b8fd73ec72
commit 32e6941ed7
15 changed files with 377 additions and 54 deletions
+55 -13
View File
@@ -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.
*/
/* Timing constants */
#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 *********************************************************/
#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 */
+24 -25
View File
@@ -1,5 +1,5 @@
/****************************************************************************
* include/nuttx/rtc.h
* include/nuttx/ptimer.h
*
* Copyright(C) 2011 Uros Platise. All rights reserved.
* Author: Uros Platise <uros.platise@isotel.eu>
@@ -33,8 +33,8 @@
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_RTC_H
#define __INCLUDE_NUTTX_RTC_H
#ifndef __INCLUDE_NUTTX_PTIMER_H
#define __INCLUDE_NUTTX_PTIMER_H
/****************************************************************************
* Included Files
@@ -62,32 +62,32 @@
* Public Types
****************************************************************************/
/* The type of the RTC callback function */
/* The type of the periodic timer callback function */
typedef void (*rtc_handler_t)(FAR void *arg);
typedef void (*ptimer_handler_t)(FAR void *arg);
/* The RTC vtable */
/* The periodic timer vtable */
struct rtc_dev_s;
struct rtc_ops_s
struct ptimer_dev_s;
struct ptimer_ops_s
{
int (*trigger)(FAR struct rtc_dev_s *dev, FAR void *arg);
int (*add)(FAR struct rtc_dev_s *dev, FAR void *arg, clock_t period);
int (*set)(FAR struct rtc_dev_s *dev, FAR void *arg, clock_t period);
int (*clear)(FAR struct rtc_dev_s *dev, FAR void *arg);
clock_t (*remainder)(FAR struct rtc_dev_s *dev, FAR void *arg);
clock_t (*overrun)(FAR struct rtc_dev_s *dev, FAR void *arg);
int (*exec)(FAR struct rtc_dev_s *dev, clock_t timeout);
int (*trigger)(FAR struct ptimer_dev_s *dev, FAR void *arg);
int (*add)(FAR struct ptimer_dev_s *dev, FAR void *arg, clock_t period);
int (*set)(FAR struct ptimer_dev_s *dev, FAR void *arg, clock_t period);
int (*clear)(FAR struct ptimer_dev_s *dev, FAR void *arg);
clock_t (*remainder)(FAR struct ptimer_dev_s *dev, FAR void *arg);
clock_t (*overrun)(FAR struct ptimer_dev_s *dev, FAR void *arg);
int (*exec)(FAR struct ptimer_dev_s *dev, clock_t timeout);
};
/* RTC private data. This structure only defines the initial fields of the
/* PTIMER private data. This structure only defines the initial fields of the
* structure visible to the SPI client. The specific implementation may
* add additional, device specific fields
*/
struct rtc_dev_s
struct ptimer_dev_s
{
FAR const struct rtc_ops_s *ops;
FAR const struct ptimer_ops_s *ops;
};
/****************************************************************************
@@ -103,22 +103,21 @@ extern "C" {
#endif
/****************************************************************************
* Name: up_rtcinitialize
* Name: up_ptimerinitialize
*
* Description:
* Initialize the RTC interface. This function may be called to obtain
* multiple instances of the interface
* Initialize the periodic timer interface. This function may be called to
* obtian multiple instances of the interface
*
* Returned Value:
* Valid RTC device structre reference on succcess; a NULL on failure
* Valid peridic timer device structre reference on succcess; a NULL on failure
*
****************************************************************************/
EXTERN FAR struct rtc_dev_s *up_rtcinitialize(void);
EXTERN FAR struct ptimer_dev_s *up_ptimerinitialize(void);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __INCLUDE_NUTTX_RTC_H */
#endif /* __INCLUDE_NUTTX_PTIMER_H */
+11 -5
View File
@@ -135,11 +135,17 @@
#ifndef CONFIG_DISABLE_CLOCK
# define SYS_clock_systimer (__SYS_clock+0)
# define SYS_clock_getres (__SYS_clock+1)
# define SYS_clock_gettime (__SYS_clock+2)
# define SYS_clock_settime (__SYS_clock+3)
# define SYS_gettimeofday (__SYS_clock+4)
# define __SYS_timers (__SYS_clock+5)
# define SYS_clock_uptime (__SYS_clock+1)
# define SYS_clock_getres (__SYS_clock+2)
# define SYS_clock_gettime (__SYS_clock+3)
# define SYS_clock_settime (__SYS_clock+4)
# define SYS_gettimeofday (__SYS_clock+5)
# ifdef CONFIG_UPTIME
# define SYS_clock_uptime (__SYS_clock+6)
# define __SYS_timers (__SYS_clock+7)
# else
# define __SYS_timers (__SYS_clock+6)
#endif
#else
# define __SYS_timers __SYS_clock
#endif