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:
parent
b8fd73ec72
commit
32e6941ed7
15 changed files with 377 additions and 54 deletions
4
Makefile
4
Makefile
|
|
@ -414,18 +414,22 @@ pass2: pass2deps
|
||||||
cp -f $(BIN) /tftpboot/$(BIN).${CONFIG_ARCH}; \
|
cp -f $(BIN) /tftpboot/$(BIN).${CONFIG_ARCH}; \
|
||||||
fi
|
fi
|
||||||
ifeq ($(CONFIG_RRLOAD_BINARY),y)
|
ifeq ($(CONFIG_RRLOAD_BINARY),y)
|
||||||
|
@echo "MK: $(BIN).rr"
|
||||||
@$(TOPDIR)/tools/mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr
|
@$(TOPDIR)/tools/mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr
|
||||||
@if [ -w /tftpboot ] ; then \
|
@if [ -w /tftpboot ] ; then \
|
||||||
cp -f $(BIN).rr /tftpboot/$\(BIN).rr.$(CONFIG_ARCH); \
|
cp -f $(BIN).rr /tftpboot/$\(BIN).rr.$(CONFIG_ARCH); \
|
||||||
fi
|
fi
|
||||||
endif
|
endif
|
||||||
ifeq ($(CONFIG_INTELHEX_BINARY),y)
|
ifeq ($(CONFIG_INTELHEX_BINARY),y)
|
||||||
|
@echo "CP: $(BIN).ihx"
|
||||||
@$(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).ihx
|
@$(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).ihx
|
||||||
endif
|
endif
|
||||||
ifeq ($(CONFIG_MOTOROLA_SREC),y)
|
ifeq ($(CONFIG_MOTOROLA_SREC),y)
|
||||||
|
@echo "CP: $(BIN).srec"
|
||||||
@$(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec
|
@$(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec
|
||||||
endif
|
endif
|
||||||
ifeq ($(CONFIG_RAW_BINARY),y)
|
ifeq ($(CONFIG_RAW_BINARY),y)
|
||||||
|
@echo "CP: $(BIN).bin"
|
||||||
@$(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
|
@$(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -332,6 +332,17 @@ must be is one of the following:
|
||||||
This specall make command ('make pass1 pass2') will make the dependencies
|
This specall make command ('make pass1 pass2') will make the dependencies
|
||||||
separately for each pass.
|
separately for each pass.
|
||||||
|
|
||||||
|
At there end of the build, there four files will top-level build
|
||||||
|
directory:
|
||||||
|
|
||||||
|
nuttx_user.elf - The pass1 ELF file
|
||||||
|
nuttx - The pass2 ELF file
|
||||||
|
nuttx_user.ihx - The pass1 Intel HEX format file
|
||||||
|
nuttx.ihx - The pass2 Intel HEX file
|
||||||
|
|
||||||
|
The J-Link program will except files in .hex, .mot, .srec, and .bin
|
||||||
|
formats.
|
||||||
|
|
||||||
nsh:
|
nsh:
|
||||||
Configures the NuttShell (nsh) located at examples/nsh. The
|
Configures the NuttShell (nsh) located at examples/nsh. The
|
||||||
Configuration enables both the serial and telnetd NSH interfaces.
|
Configuration enables both the serial and telnetd NSH interfaces.
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,18 @@ nuttx_user.elf:
|
||||||
$(TOPDIR)/nuttx_user.elf: nuttx_user.elf
|
$(TOPDIR)/nuttx_user.elf: nuttx_user.elf
|
||||||
@echo "LD: nuttx_user.elf"
|
@echo "LD: nuttx_user.elf"
|
||||||
@cp -a nuttx_user.elf $(TOPDIR)/nuttx_user.elf
|
@cp -a nuttx_user.elf $(TOPDIR)/nuttx_user.elf
|
||||||
|
ifeq ($(CONFIG_INTELHEX_BINARY),y)
|
||||||
|
@echo "CP: nuttx_user.ihx"
|
||||||
|
@$(OBJCOPY) $(OBJCOPYARGS) -O ihex nuttx_user.elf $(TOPDIR)/nuttx_user.ihx
|
||||||
|
endif
|
||||||
|
ifeq ($(CONFIG_MOTOROLA_SREC),y)
|
||||||
|
@echo "CP: nuttx_user.srec"
|
||||||
|
@$(OBJCOPY) $(OBJCOPYARGS) -O srec nuttx_user.elf $(TOPDIR)/nuttx_user.srec
|
||||||
|
endif
|
||||||
|
ifeq ($(CONFIG_RAW_BINARY),y)
|
||||||
|
@echo "CP: nuttx_user.bin"
|
||||||
|
@$(OBJCOPY) $(OBJCOPYARGS) -O binary nuttx_user.elf $(TOPDIR)/nuttx_user.bin
|
||||||
|
endif
|
||||||
|
|
||||||
$(TOPDIR)/User.map: nuttx_user.elf
|
$(TOPDIR)/User.map: nuttx_user.elf
|
||||||
@echo "MK: User.map"
|
@echo "MK: User.map"
|
||||||
|
|
|
||||||
|
|
@ -202,9 +202,9 @@ CONFIG_USART3_2STOP=0
|
||||||
# CONFIG_HAVE_LIBM - toolchain supports libm.a
|
# CONFIG_HAVE_LIBM - toolchain supports libm.a
|
||||||
#
|
#
|
||||||
CONFIG_RRLOAD_BINARY=n
|
CONFIG_RRLOAD_BINARY=n
|
||||||
CONFIG_INTELHEX_BINARY=n
|
CONFIG_INTELHEX_BINARY=y
|
||||||
CONFIG_MOTOROLA_SREC=n
|
CONFIG_MOTOROLA_SREC=n
|
||||||
CONFIG_RAW_BINARY=y
|
CONFIG_RAW_BINARY=n
|
||||||
CONFIG_HAVE_LIBM=n
|
CONFIG_HAVE_LIBM=n
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,42 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pro-processor Definitions
|
* 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 NSEC_PER_SEC 1000000000
|
||||||
#define USEC_PER_SEC 1000000
|
#define USEC_PER_SEC 1000000
|
||||||
|
|
@ -100,22 +129,30 @@
|
||||||
* Global Data
|
* Global Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if !defined(CONFIG_DISABLE_CLOCK)
|
||||||
|
|
||||||
/* Access to raw system clock ***********************************************/
|
/* Access to raw system clock ***********************************************/
|
||||||
/* Direct access to the system timer/counter is supported only if (1) the
|
/* Direct access to the system timer/counter is supported only if (1) the
|
||||||
* system clock is not disabled and (2) the executation environement has
|
* system timer counter is available (i.e., we are not configured to use
|
||||||
* direct access to kernel global data.
|
* a hardware periodic timer), and (2) 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_CLOCK) && \
|
#if !defined(CONFIG_PTIMER) && __HAVE_KERNEL_GLOBALS
|
||||||
(!defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__))
|
|
||||||
extern volatile uint32_t g_system_timer;
|
extern volatile uint32_t g_system_timer;
|
||||||
#define clock_systimer() g_system_timer
|
#define clock_systimer() g_system_timer
|
||||||
#endif
|
#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
|
* Global Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
@ -131,18 +168,23 @@ extern "C" {
|
||||||
#define EXTERN extern
|
#define EXTERN extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If direct access to the system timer/counter is not supported (see above),
|
/* Indirect access to the system time is required if (1) we are using a
|
||||||
* then the value can be obtained via clock_systimer through a system call.
|
* hardware periodic timer, OR (2) the execution environment does not have
|
||||||
|
* direct access to kernel global data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_CLOCK) && \
|
#if defined(CONFIG_PTIMER) || !__HAVE_KERNEL_GLOBALS
|
||||||
defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__)
|
|
||||||
EXTERN uint32_t clock_systimer(void);
|
EXTERN uint32_t clock_systimer(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_UPTIME) && !__HAVE_KERNEL_GLOBALS
|
||||||
|
EXTERN time_t clock_uptime(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* !CONFIG_DISABLE_CLOCK */
|
||||||
#endif /* __NUTTX_CLOCK_H */
|
#endif /* __NUTTX_CLOCK_H */
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* include/nuttx/rtc.h
|
* include/nuttx/ptimer.h
|
||||||
*
|
*
|
||||||
* Copyright(C) 2011 Uros Platise. All rights reserved.
|
* Copyright(C) 2011 Uros Platise. All rights reserved.
|
||||||
* Author: Uros Platise <uros.platise@isotel.eu>
|
* Author: Uros Platise <uros.platise@isotel.eu>
|
||||||
|
|
@ -33,8 +33,8 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __INCLUDE_NUTTX_RTC_H
|
#ifndef __INCLUDE_NUTTX_PTIMER_H
|
||||||
#define __INCLUDE_NUTTX_RTC_H
|
#define __INCLUDE_NUTTX_PTIMER_H
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
|
|
@ -62,32 +62,32 @@
|
||||||
* Public Types
|
* 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 ptimer_dev_s;
|
||||||
struct rtc_ops_s
|
struct ptimer_ops_s
|
||||||
{
|
{
|
||||||
int (*trigger)(FAR struct rtc_dev_s *dev, FAR void *arg);
|
int (*trigger)(FAR struct ptimer_dev_s *dev, FAR void *arg);
|
||||||
int (*add)(FAR struct rtc_dev_s *dev, FAR void *arg, clock_t period);
|
int (*add)(FAR struct ptimer_dev_s *dev, FAR void *arg, clock_t period);
|
||||||
int (*set)(FAR struct rtc_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 rtc_dev_s *dev, FAR void *arg);
|
int (*clear)(FAR struct ptimer_dev_s *dev, FAR void *arg);
|
||||||
clock_t (*remainder)(FAR struct rtc_dev_s *dev, FAR void *arg);
|
clock_t (*remainder)(FAR struct ptimer_dev_s *dev, FAR void *arg);
|
||||||
clock_t (*overrun)(FAR struct rtc_dev_s *dev, FAR void *arg);
|
clock_t (*overrun)(FAR struct ptimer_dev_s *dev, FAR void *arg);
|
||||||
int (*exec)(FAR struct rtc_dev_s *dev, clock_t timeout);
|
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
|
* structure visible to the SPI client. The specific implementation may
|
||||||
* add additional, device specific fields
|
* 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
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_rtcinitialize
|
* Name: up_ptimerinitialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize the RTC interface. This function may be called to obtain
|
* Initialize the periodic timer interface. This function may be called to
|
||||||
* multiple instances of the interface
|
* obtian multiple instances of the interface
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* 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
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif /* __INCLUDE_NUTTX_RTC_H */
|
#endif /* __INCLUDE_NUTTX_PTIMER_H */
|
||||||
|
|
@ -135,11 +135,17 @@
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_CLOCK
|
#ifndef CONFIG_DISABLE_CLOCK
|
||||||
# define SYS_clock_systimer (__SYS_clock+0)
|
# define SYS_clock_systimer (__SYS_clock+0)
|
||||||
# define SYS_clock_getres (__SYS_clock+1)
|
# define SYS_clock_uptime (__SYS_clock+1)
|
||||||
# define SYS_clock_gettime (__SYS_clock+2)
|
# define SYS_clock_getres (__SYS_clock+2)
|
||||||
# define SYS_clock_settime (__SYS_clock+3)
|
# define SYS_clock_gettime (__SYS_clock+3)
|
||||||
# define SYS_gettimeofday (__SYS_clock+4)
|
# define SYS_clock_settime (__SYS_clock+4)
|
||||||
# define __SYS_timers (__SYS_clock+5)
|
# 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
|
#else
|
||||||
# define __SYS_timers __SYS_clock
|
# define __SYS_timers __SYS_clock
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
90
lib/time/lib_time.c
Normal file
90
lib/time/lib_time.c
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* lib/time/lib_time.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <nuttx/clock.h>
|
||||||
|
|
||||||
|
#if !defined(CONFIG_DISABLE_CLOCK) && defined(CONFIG_UPTIME)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: time
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Return the current system up-time.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* The tloc argument points to an area where the return value is
|
||||||
|
* also stored. If tloc is a null pointer, no value is stored.
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* The current system up time
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
time_t time(time_t *tloc)
|
||||||
|
{
|
||||||
|
/* Get the current uptime from the system */
|
||||||
|
|
||||||
|
time_t uptime = clock_uptime();
|
||||||
|
|
||||||
|
/* Return the uptime */
|
||||||
|
|
||||||
|
if (tloc)
|
||||||
|
{
|
||||||
|
*tloc = uptime;
|
||||||
|
}
|
||||||
|
return uptime;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !CONFIG_DISABLE_CLOCK && CONFIG_UPTIME */
|
||||||
|
|
@ -82,6 +82,9 @@ CLOCK_SRCS = clock_initialize.c clock_settime.c clock_gettime.c clock_getres.c \
|
||||||
|
|
||||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||||
CLOCK_SRCS += clock_systimer.c
|
CLOCK_SRCS += clock_systimer.c
|
||||||
|
ifeq ($(CONFIG_UPTIME),y)
|
||||||
|
CLOCK_SRCS += clock_uptime.c
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SIGNAL_SRCS = sig_initialize.c \
|
SIGNAL_SRCS = sig_initialize.c \
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/clock.h>
|
||||||
#include <nuttx/time.h>
|
#include <nuttx/time.h>
|
||||||
|
|
||||||
#include "clock_internal.h"
|
#include "clock_internal.h"
|
||||||
|
|
@ -55,6 +57,12 @@
|
||||||
#define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN)
|
#define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN)
|
||||||
#define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR)
|
#define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR)
|
||||||
|
|
||||||
|
#if __HAVE_SYSTEM_COUNTER
|
||||||
|
# define incr_systimer() g_system_timer++
|
||||||
|
#else
|
||||||
|
# define incr_systimer()
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Type Declarations
|
* Private Type Declarations
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
@ -71,14 +79,63 @@
|
||||||
* Public Variables
|
* Public Variables
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
volatile uint32_t g_system_timer = 0;
|
#if __HAVE_SYSTEM_COUNTER
|
||||||
struct timespec g_basetime = {0,0};
|
volatile clock_t g_system_timer = 0;
|
||||||
uint32_t g_tickbias = 0;
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_UPTIME
|
||||||
|
volatile time_t g_uptime = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct timespec g_basetime = {0,0};
|
||||||
|
uint32_t g_tickbias = 0;
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Private Variables
|
* Private Variables
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
/* This variable is used to count ticks and to increment the one-second
|
||||||
|
* uptime variable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if CONFIG_UPTIME
|
||||||
|
#if TICK_PER_SEC > 32767
|
||||||
|
static uint32_t g_tickcount = 0;
|
||||||
|
#elif TICK_PER_SEC > 255
|
||||||
|
static uint16_t g_tickcount = 0;
|
||||||
|
#else
|
||||||
|
static uint8_t g_tickcount = 0;
|
||||||
|
#endif
|
||||||
|
#endif /* CONFIG_UPTIME */
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
**************************************************************************/
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: clock_timer
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function must be called once every time the real
|
||||||
|
* time clock interrupt occurs. The interval of this
|
||||||
|
* clock interrupt must be MSEC_PER_TICK
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if CONFIG_UPTIME
|
||||||
|
static inline void incr_uptime(void)
|
||||||
|
{
|
||||||
|
g_tickcount++;
|
||||||
|
|
||||||
|
if (g_tickcount >= TICK_PER_SEC)
|
||||||
|
{
|
||||||
|
g_uptime++;
|
||||||
|
g_tickcount -= TICK_PER_SEC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define incr_uptime()
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
@ -101,14 +158,20 @@ void clock_initialize(void)
|
||||||
|
|
||||||
/* Initialize the real time close */
|
/* Initialize the real time close */
|
||||||
|
|
||||||
|
#if __HAVE_SYSTEM_COUNTER
|
||||||
g_system_timer = 0;
|
g_system_timer = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Get the EPOCH-relative julian date from the calendar year,
|
/* Get the EPOCH-relative julian date from the calendar year,
|
||||||
* month, and date
|
* month, and date
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef CONFIG_PTIMER
|
||||||
jdn = clock_calendar2utc(CONFIG_START_YEAR, CONFIG_START_MONTH,
|
jdn = clock_calendar2utc(CONFIG_START_YEAR, CONFIG_START_MONTH,
|
||||||
CONFIG_START_DAY);
|
CONFIG_START_DAY);
|
||||||
|
#else /* use UTC as starting date */
|
||||||
|
jdn = clock_calendar2utc(1970, 1, 1);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Set the base time as seconds into this julian day. */
|
/* Set the base time as seconds into this julian day. */
|
||||||
|
|
||||||
|
|
@ -132,5 +195,11 @@ void clock_initialize(void)
|
||||||
|
|
||||||
void clock_timer(void)
|
void clock_timer(void)
|
||||||
{
|
{
|
||||||
g_system_timer++;
|
/* Increment the per-tick system counter */
|
||||||
|
|
||||||
|
incr_systimer();
|
||||||
|
|
||||||
|
/* Increment the per-second uptime counter */
|
||||||
|
|
||||||
|
incr_uptime();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,15 +42,12 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <nuttx/clock.h>
|
#include <nuttx/clock.h>
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_CLOCK) && \
|
#if __HAVE_SYSTEM_COUNTER && !defined(clock_systimer) /* See nuttx/clock.h */
|
||||||
defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__)
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#undef clock_systimer
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
@ -79,5 +76,6 @@ uint32_t clock_systimer(void)
|
||||||
{
|
{
|
||||||
return g_system_timer;
|
return g_system_timer;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
#endif /* __HAVE_SYSTEM_COUNTER */
|
||||||
|
|
||||||
|
|
|
||||||
84
sched/clock_uptime.c
Normal file
84
sched/clock_uptime.c
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* sched/clock_uptime.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <nuttx/clock.h>
|
||||||
|
#include <nuttx/time.h>
|
||||||
|
|
||||||
|
#if !defined(CONFIG_DISABLE_CLOCK) && defined(CONFIG_UPTIME)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#undef clock_uptime
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Function: clock_uptime
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Return the current value of the system timer counter, which is only
|
||||||
|
* enabled when system is in active mode.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* The current value of the system time counter
|
||||||
|
*
|
||||||
|
* Assumptions:
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
time_t clock_uptime(void)
|
||||||
|
{
|
||||||
|
return g_uptime;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_DISABLE_CLOCK && CONFIG_UPTIME */
|
||||||
|
|
@ -112,6 +112,7 @@ extern uintptr_t STUB_clock_getres(uintptr_t parm1, uintptr_t parm2);
|
||||||
extern uintptr_t STUB_clock_gettime(uintptr_t parm1, uintptr_t parm2);
|
extern uintptr_t STUB_clock_gettime(uintptr_t parm1, uintptr_t parm2);
|
||||||
extern uintptr_t STUB_clock_settime(uintptr_t parm1, uintptr_t parm2);
|
extern uintptr_t STUB_clock_settime(uintptr_t parm1, uintptr_t parm2);
|
||||||
extern uintptr_t STUB_gettimeofday(uintptr_t parm1, uintptr_t parm2);
|
extern uintptr_t STUB_gettimeofday(uintptr_t parm1, uintptr_t parm2);
|
||||||
|
extern uintptr_t STUB_clock_uptime(void);
|
||||||
|
|
||||||
/* The following are defined only if POSIX timers are supported */
|
/* The following are defined only if POSIX timers are supported */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,9 @@ STUB_LOOKUP(3, STUB_up_assert_code) /* SYS_up_assert_code */
|
||||||
STUB_LOOKUP(2, STUB_clock_gettime) /* SYS_clock_gettime */
|
STUB_LOOKUP(2, STUB_clock_gettime) /* SYS_clock_gettime */
|
||||||
STUB_LOOKUP(2, STUB_clock_settime) /* SYS_clock_settime */
|
STUB_LOOKUP(2, STUB_clock_settime) /* SYS_clock_settime */
|
||||||
STUB_LOOKUP(2, STUB_gettimeofday) /* SYS_gettimeofday */
|
STUB_LOOKUP(2, STUB_gettimeofday) /* SYS_gettimeofday */
|
||||||
|
# ifdef CONFIG_UPTIME
|
||||||
|
STUB_LOOKUP(0, STUB_clock_uptime) /* SYS_clock_uptime */
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The following are defined only if POSIX timers are supported */
|
/* The following are defined only if POSIX timers are supported */
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
"clock_getres","time.h","!defined(CONFIG_DISABLE_CLOCK)","int","clockid_t","struct timespec*"
|
"clock_getres","time.h","!defined(CONFIG_DISABLE_CLOCK)","int","clockid_t","struct timespec*"
|
||||||
"clock_gettime","time.h","!defined(CONFIG_DISABLE_CLOCK)","int","clockid_t","struct timespec*"
|
"clock_gettime","time.h","!defined(CONFIG_DISABLE_CLOCK)","int","clockid_t","struct timespec*"
|
||||||
"clock_settime","time.h","!defined(CONFIG_DISABLE_CLOCK)","int","clockid_t","const struct timespec*"
|
"clock_settime","time.h","!defined(CONFIG_DISABLE_CLOCK)","int","clockid_t","const struct timespec*"
|
||||||
|
"clock_uptime","nuttx/clock.h","!defined(CONFIG_DISABLE_CLOCK) && defined(CONFIG_UPTIME)","time_t"
|
||||||
"close","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","int","int"
|
"close","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","int","int"
|
||||||
"closedir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR*"
|
"closedir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR*"
|
||||||
"connect","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","FAR const struct sockaddr*","socklen_t"
|
"connect","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","FAR const struct sockaddr*","socklen_t"
|
||||||
|
|
|
||||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
Loading…
Add table
Reference in a new issue