From c1d7cdfbed631c95fb88767a41fcc4852b2fd9d7 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 9 Jun 2007 15:49:44 +0000 Subject: [PATCH] Add support for custom system timer frequency git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@274 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/ChangeLog | 4 +++- nuttx/Documentation/NuttX.html | 6 +++-- nuttx/Documentation/NuttxPortingGuide.html | 6 +++++ nuttx/TODO | 4 ---- nuttx/configs/README.txt | 5 ++++ nuttx/configs/c5471evm/defconfig | 5 ++++ nuttx/configs/m68332evb/defconfig | 5 ++++ nuttx/configs/mcu123-lpc214x/defconfig | 5 ++++ nuttx/configs/ntosd-dm320/defconfig | 5 ++++ nuttx/configs/pjrc-8051/defconfig | 5 ++++ nuttx/configs/sim/defconfig | 5 ++++ nuttx/include/limits.h | 20 ++++++++++++++-- nuttx/include/time.h | 11 +++++++-- nuttx/sched/clock_internal.h | 28 +++++++++++++++++----- 14 files changed, 97 insertions(+), 17 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 416f47873..4280c0b61 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -161,6 +161,8 @@ * sched/usleep.c: Fixed nsec calculation * lib/lib_strcspn.c: Function incorrectly named strspn(). * examples/ostest/main.c: Errors in SDCC version of a memcpy() call - * examples/ostest/sighandl.c: Don't call fflush() if streams are disabled + * examples/ostest/sighand.c: Don't call fflush() if streams are disabled + * include/limits.h, include/time.h, sched/clock_internal.h: A support for + using selectable system timer frequency. * Started m68322 diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index c68001742..6b5d03248 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@

NuttX RTOS

-

Last Updated: May 26, 2007

+

Last Updated: June 9, 2007

@@ -595,7 +595,9 @@ Other memory: * sched/usleep.c: Fixed nsec calculation * lib/lib_strcspn.c: Function incorrectly named strspn(). * examples/ostest/main.c: Errors in SDCC version of a memcpy() call - * examples/ostest/sighandl.c: Don't call fflush() if streams are disabled + * examples/ostest/sighand.c: Don't call fflush() if streams are disabled + * include/limits.h, include/time.h, sched/clock_internal.h: A support for + using selectable system timer frequency. * Started m68322 diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index 8cd9d06e3..38ab0c31e 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -1163,6 +1163,12 @@ The system can be re-made subsequently by just typing make. number of memory regions that the memory manager must handle and enables the API mm_addregion(start, end); +
  • + CONFIG_TICKS_PER_MSEC: The default system timer is 100Hz + or TICKS_PER_MSEC=10. This setting may be defined to inform NuttX + that the processor hardware is providing system timer interrupts at some interrupt + interval other than 10 msec. +
  • CONFIG_RR_INTERVAL: The round robin timeslice will be set this number of milliseconds; Round robin scheduling can diff --git a/nuttx/TODO b/nuttx/TODO index 0f16e150f..3c5a1e83e 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -7,10 +7,6 @@ o Task/Scheduler - Implement sys/mman.h and functions - Implement sys/wait.h and functions - Implement priority inheritance -- Make the system timer frequency configurable via defconfig. See: - _POSIX_CLOCKRES_MIN in limits.h - CLK_TCK in time.h - MSEC_PER_TICK in sched/clock_internal.h - Consider implementing wait, waitpid, waitid. At present, a parent has no information about child tasks. - Several APIs do not set errno. Need to review all APIs. diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index 77d41e131..a123a1f01 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -132,6 +132,11 @@ defconfig -- This is a configuration file similar to the Linux regions of memory to allocate from, this specifies the number of memory regions that the memory manager must handle and enables the API mm_addregion(start, end); + CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz + or TICKS_PER_MSEC=10. This setting may be defined to + inform NuttX that the processor hardware is providing + system timer interrupts at some interrupt interval other + than 10 msec. CONFIG_RR_INTERVAL - The round robin timeslice will be set this number of milliseconds; Round robin scheduling can be disabled by setting this value to zero. diff --git a/nuttx/configs/c5471evm/defconfig b/nuttx/configs/c5471evm/defconfig index a534ae283..e247d9e87 100644 --- a/nuttx/configs/c5471evm/defconfig +++ b/nuttx/configs/c5471evm/defconfig @@ -109,6 +109,11 @@ CONFIG_UART_MODEM_2STOP=0 # handle and enables the API mm_addregion(start, end); # CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot # time console output +# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz +# or TICKS_PER_MSEC=10. This setting may be defined to +# inform NuttX that the processor hardware is providing +# system timer interrupts at some interrupt interval other +# than 10 msec. # CONFIG_RR_INTERVAL - The round robin timeslice will be set # this number of milliseconds; Round robin scheduling can # be disabled by setting this value to zero. diff --git a/nuttx/configs/m68332evb/defconfig b/nuttx/configs/m68332evb/defconfig index 2df6f2e51..2185e760a 100644 --- a/nuttx/configs/m68332evb/defconfig +++ b/nuttx/configs/m68332evb/defconfig @@ -98,6 +98,11 @@ CONFIG_UART1_2STOP=0 # handle and enables the API mm_addregion(start, end); # CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot # time console output +# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz +# or TICKS_PER_MSEC=10. This setting may be defined to +# inform NuttX that the processor hardware is providing +# system timer interrupts at some interrupt interval other +# than 10 msec. # CONFIG_RR_INTERVAL - The round robin timeslice will be set # this number of milliseconds; Round robin scheduling can # be disabled by setting this value to zero. diff --git a/nuttx/configs/mcu123-lpc214x/defconfig b/nuttx/configs/mcu123-lpc214x/defconfig index e9e97326b..ca0c9a153 100644 --- a/nuttx/configs/mcu123-lpc214x/defconfig +++ b/nuttx/configs/mcu123-lpc214x/defconfig @@ -122,6 +122,11 @@ CONFIG_UART1_2STOP=0 # handle and enables the API mm_addregion(start, end); # CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot # time console output +# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz +# or TICKS_PER_MSEC=10. This setting may be defined to +# inform NuttX that the processor hardware is providing +# system timer interrupts at some interrupt interval other +# than 10 msec. # CONFIG_RR_INTERVAL - The round robin timeslice will be set # this number of milliseconds; Round robin scheduling can # be disabled by setting this value to zero. diff --git a/nuttx/configs/ntosd-dm320/defconfig b/nuttx/configs/ntosd-dm320/defconfig index aa6270250..640783cf1 100644 --- a/nuttx/configs/ntosd-dm320/defconfig +++ b/nuttx/configs/ntosd-dm320/defconfig @@ -107,6 +107,11 @@ CONFIG_UART1_2STOP=0 # handle and enables the API mm_addregion(start, end); # CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot # time console output +# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz +# or TICKS_PER_MSEC=10. This setting may be defined to +# inform NuttX that the processor hardware is providing +# system timer interrupts at some interrupt interval other +# than 10 msec. # CONFIG_RR_INTERVAL - The round robin timeslice will be set # this number of milliseconds; Round robin scheduling can # be disabled by setting this value to zero. diff --git a/nuttx/configs/pjrc-8051/defconfig b/nuttx/configs/pjrc-8051/defconfig index bc6084f0b..c9b8a481a 100644 --- a/nuttx/configs/pjrc-8051/defconfig +++ b/nuttx/configs/pjrc-8051/defconfig @@ -95,6 +95,11 @@ CONFIG_LED_DEBUG=n # handle and enables the API mm_addregion(start, end); # CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot # time console output +# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz +# or TICKS_PER_MSEC=10. This setting may be defined to +# inform NuttX that the processor hardware is providing +# system timer interrupts at some interrupt interval other +# than 10 msec. # CONFIG_RR_INTERVAL - The round robin timeslice will be set # this number of milliseconds; Round robin scheduling can # be disabled by setting this value to zero. diff --git a/nuttx/configs/sim/defconfig b/nuttx/configs/sim/defconfig index 59f05d4ac..e5940848e 100644 --- a/nuttx/configs/sim/defconfig +++ b/nuttx/configs/sim/defconfig @@ -63,6 +63,11 @@ CONFIG_ARCH_BOARD_SIM=y # handle and enables the API mm_addregion(start, end); # CONFIG_HAVE_LOWPUTC - architecture supports low-level, boot # time console output +# CONFIG_TICKS_PER_MSEC - The default system timer is 100Hz +# or TICKS_PER_MSEC=10. This setting may be defined to +# inform NuttX that the processor hardware is providing +# system timer interrupts at some interrupt interval other +# than 10 msec. # CONFIG_RR_INTERVAL - The round robin timeslice will be set # this number of milliseconds; Round robin scheduling can # be disabled by setting this value to zero. diff --git a/nuttx/include/limits.h b/nuttx/include/limits.h index 285eea684..d32c7177a 100644 --- a/nuttx/include/limits.h +++ b/nuttx/include/limits.h @@ -114,11 +114,27 @@ #define _POSIX_RTSIG_MAX 31 #define _POSIX_SIGQUEUE_MAX 32 -/* Required for POSIX timers */ +/* Required for POSIX timers. + * + * _POSIX_DELAYTIMER_MAX is the number of timer expiration overruns. + * + * _POSIX_TIMER_MAX is the per-process number of timers. + * + * _POSIX_CLOCKRES_MIN is the resolution of the CLOCK_REALTIME clock in nanoseconds. + * CLOCK_REALTIME is controlled by the NuttX system time. The default value is the + * system timer which has a resolution of 10 milliseconds. This default setting can + * be overridden by defining the clock interval in milliseconds as CONFIG_MSEC_PER_TICK + * in the board configuration file. + */ #define _POSIX_DELAYTIMER_MAX 32 #define _POSIX_TIMER_MAX 32 -#define _POSIX_CLOCKRES_MIN 10000000 + +#ifdef CONFIG_MSEC_PER_TICK +# define _POSIX_CLOCKRES_MIN ((CONFIG_MSEC_PER_TICK)*1000000) +#else +# define _POSIX_CLOCKRES_MIN (10*1000000) +#endif /* Required for asynchronous I/O */ diff --git a/nuttx/include/time.h b/nuttx/include/time.h index 7a9731423..92b849fbe 100644 --- a/nuttx/include/time.h +++ b/nuttx/include/time.h @@ -51,9 +51,16 @@ * Definitions ********************************************************************************/ -/* Clock tick of the system */ +/* Clock tick of the system (frequency Hz). The default value is 100Hz, but this + * default setting can be overridden by defining the clock interval in + * milliseconds as CONFIG_MSEC_PER_TICK in the board configuration file. + */ -#define CLK_TCK 100 +#ifdef CONFIG_MSEC_PER_TICK +# define CLK_TCK (1000/CONFIG_MSEC_PER_TICK) +#else +# define CLK_TCK (100) +#endif /* This is the only clock_id supported by the "Clock and Timer * Functions." diff --git a/nuttx/sched/clock_internal.h b/nuttx/sched/clock_internal.h index 85cb13f06..2f7a9c783 100644 --- a/nuttx/sched/clock_internal.h +++ b/nuttx/sched/clock_internal.h @@ -40,6 +40,7 @@ * Included Files ********************************************************************************/ +#include #include #include @@ -56,7 +57,20 @@ #define USEC_PER_MSEC 1000 #define NSEC_PER_USEC 1000 -#define MSEC_PER_TICK 10 +/* The interrupt interval of the system timer is given by MSEC_PER_TICK. This + * is the expected number of milliseconds between calls from the processor- + * specific logic to sched_process_timer(). The default value of MSEC_PER_TICK + * is 10 milliseconds (100KHz). However, this default setting can be overridden + * by defining the interval in milliseconds as CONFIG_MSEC_PER_TICK in the board + * configuration file. + */ + +#ifdef CONFIG_MSEC_PER_TICK +# define MSEC_PER_TICK (CONFIG_MSEC_PER_TICK) +#else +# define MSEC_PER_TICK (10) +#endif + #define USEC_PER_TICK (MSEC_PER_TICK * USEC_PER_MSEC) #define NSEC_PER_TICK (MSEC_PER_TICK * NSEC_PER_MSEC) #define TICK_PER_SEC (MSEC_PER_SEC / MSEC_PER_TICK) @@ -64,13 +78,15 @@ #define MSEC2TICK(msec) (((msec)+(MSEC_PER_TICK/2))/MSEC_PER_TICK) #define USEC2TICK(usec) (((usec)+(USEC_PER_TICK/2))/USEC_PER_TICK) -#define JD_OF_EPOCH 2440588 /* Julian Date of noon, J1970 */ +#define JD_OF_EPOCH 2440588 /* Julian Date of noon, J1970 */ #ifdef CONFIG_JULIAN_TIME -# define GREG_DUTC -141427 /* Default is October 15, 1582 */ -# define GREG_YEAR 1582 -# define GREG_MONTH 10 -# define GREG_DAY 15 + +# define GREG_DUTC -141427 /* Default is October 15, 1582 */ +# define GREG_YEAR 1582 +# define GREG_MONTH 10 +# define GREG_DAY 15 + #endif /* CONFIG_JULIAN_TIME */ /********************************************************************************