OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /openrisc/trunk/rtos/ecos-2.0/packages/io/wallclock/v2_0
    from Rev 27 to Rev 174
    Reverse comparison

Rev 27 → Rev 174

/cdl/wallclock.cdl
0,0 → 1,175
# ====================================================================
#
# wallclock.cdl
#
# eCos wallclock configuration data
#
# ====================================================================
#####ECOSGPLCOPYRIGHTBEGIN####
## -------------------------------------------
## This file is part of eCos, the Embedded Configurable Operating System.
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
##
## eCos is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free
## Software Foundation; either version 2 or (at your option) any later version.
##
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
## for more details.
##
## You should have received a copy of the GNU General Public License along
## with eCos; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
##
## As a special exception, if other files instantiate templates or use macros
## or inline functions from this file, or you compile this file and link it
## with other works to produce a work based on this file, this file does not
## by itself cause the resulting work to be covered by the GNU General Public
## License. However the source code for this file must still be made available
## in accordance with section (3) of the GNU General Public License.
##
## This exception does not invalidate any other reasons why a work based on
## this file might be covered by the GNU General Public License.
##
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
## at http://sources.redhat.com/ecos/ecos-license/
## -------------------------------------------
#####ECOSGPLCOPYRIGHTEND####
# ====================================================================
######DESCRIPTIONBEGIN####
#
# Author(s): jskov
# Original data: nickg
# Contributors:
# Date: 1999-07-13
#
#####DESCRIPTIONEND####
#
# ====================================================================
 
cdl_package CYGPKG_IO_WALLCLOCK {
display "Wallclock device"
include_dir cyg/io
 
define_header wallclock.h
description "
The wallclock device provides real time stamps, as opposed
to the eCos kernel timers which typically just count the
number of clock ticks since the hardware was powered up.
Depending on the target platform this device may involve
interacting with a suitable clock chip, or it may be
emulated by using the kernel timers."
 
compile wallclock.cxx
 
cdl_interface CYGINT_WALLCLOCK_HW_IMPLEMENTATIONS {
display "Number of wallclock hardware implementations"
no_define
}
 
cdl_interface CYGINT_WALLCLOCK_IMPLEMENTATIONS {
display "Number of wallclock implementations"
no_define
requires 1 == CYGINT_WALLCLOCK_IMPLEMENTATIONS
}
 
cdl_interface CYGINT_WALLCLOCK_SET_GET_MODE_SUPPORTED {
display "Wallclock driver supports set/get mode"
no_define
}
 
cdl_option CYGSEM_WALLCLOCK_MODE {
display "Wallclock mode"
flavor data
legal_values { "init_get" "set_get" }
default_value { CYGINT_WALLCLOCK_SET_GET_MODE_SUPPORTED ? \
"set_get" : "init_get" }
requires { CYGINT_WALLCLOCK_SET_GET_MODE_SUPPORTED || \
CYGSEM_WALLCLOCK_MODE == "init_get" }
no_define
description "
The wallclock driver can be used in one of two
modes. Set/get mode allows time to be kept during power
off (assuming there's a battery backed clock). Init/get
mode is slightly smaller and can be used when there is no
battery backed clock - in this mode time 0 is the time of
the board power up."
}
 
cdl_option CYGSEM_WALLCLOCK_SET_GET_MODE {
display "Wallclock set/get mode"
calculated { CYGSEM_WALLCLOCK_MODE == "set_get" ? 1 : 0 }
}
 
cdl_component CYGPKG_IO_WALLCLOCK_IMPLEMENTATION {
display "Wallclock implementation"
flavor none
no_define
description "Implementations of the wallclock device."
 
cdl_option CYGPKG_WALLCLOCK_EMULATE {
default_value { 0 == CYGINT_WALLCLOCK_HW_IMPLEMENTATIONS }
display "Wallclock emulator"
implements CYGINT_WALLCLOCK_IMPLEMENTATIONS
compile emulate.cxx
requires CYGPKG_KERNEL
define_proc {
puts $::cdl_header "#undef CYGSEM_WALLCLOCK_SET_GET_MODE"
}
description "
When this option is enabled, a wallclock device will be
emulated using the kernel real-time clock."
}
 
cdl_option CYGIMP_WALLCLOCK_NONE {
display "No wallclock"
default_value { !CYGPKG_KERNEL && 0 == CYGINT_WALLCLOCK_HW_IMPLEMENTATIONS }
implements CYGINT_WALLCLOCK_IMPLEMENTATIONS
description "Disables the wallclock."
}
}
 
cdl_component CYGPKG_IO_WALLCLOCK_OPTIONS {
display "Wallclock build options"
flavor none
description "
Package specific build options including control over
compiler flags used only in building this package,
and details of which tests are built."
 
 
cdl_option CYGPKG_IO_WALLCLOCK_CFLAGS_ADD {
display "Additional compiler flags"
flavor data
no_define
default_value { "" }
description "
This option modifies the set of compiler flags for
building the wallclock device. These flags are used in addition
to the set of global flags."
}
 
cdl_option CYGPKG_IO_WALLCLOCK_CFLAGS_REMOVE {
display "Suppressed compiler flags"
flavor data
no_define
default_value { "" }
description "
This option modifies the set of compiler flags for
building the wallclock device. These flags are removed from
the set of global flags if present."
}
 
cdl_option CYGPKG_IO_WALLCLOCK_TESTS {
display "Wallclock tests"
flavor data
no_define
calculated { CYGPKG_KERNEL ? "tests/wallclock tests/wallclock2" : "" }
description "
This option specifies the set of tests for the
wallclock device."
}
}
}
/tests/wallclock.cxx
0,0 → 1,232
//==========================================================================
//
// wallclock.cxx
//
// WallClock test
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): nickg
// Contributors: nickg
// Date: 1998-07-20
// Description: Tests the Kernel Wall Clock
// This test exercises the WallClock class and checks that it
// keeps time correctly.
//####DESCRIPTIONEND####
// -------------------------------------------------------------------------
 
#include <pkgconf/hal.h>
#include <pkgconf/kernel.h>
 
#include <cyg/kernel/thread.hxx>
#include <cyg/kernel/thread.inl>
#include <cyg/kernel/sched.hxx>
#include <cyg/kernel/mutex.hxx>
#include <cyg/kernel/sema.hxx>
#include <cyg/kernel/clock.hxx>
 
#include <cyg/kernel/diag.h>
 
#include <cyg/io/wallclock.hxx> // The WallClock API
 
#include <cyg/infra/testcase.h>
 
#if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
 
#include <cyg/kernel/sched.inl>
 
// -------------------------------------------------------------------------
// Data for the test
 
#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
#else
#define STACKSIZE (2*1024) // size of thread stack
#endif
 
char thread_stack[STACKSIZE];
 
inline void *operator new(size_t size, void *ptr) { return ptr; };
 
// array of threads.
char thread[sizeof(Cyg_Thread)];
 
Cyg_Thread *th;
 
// MN10300 sim takes 1min15secs to do one loop on 300MHz PII.
#define LOOPS_SIM 2
#define LOOPS_HW 10
 
cyg_int32 loops = LOOPS_HW;
cyg_tick_count one_sec;
 
// -------------------------------------------------------------------------
// Thread body
 
 
void wallclock_thread( CYG_ADDRWORD id )
{
cyg_uint32 base;
cyg_uint32 wtime;
cyg_tick_count ticks;
 
CYG_TEST_INFO("Testing accuracy of wallclock (10 seconds silence)");
 
// Check clock only every other second since the call itself may
// take about a second.
 
// Start by synchronizing to next wallclock increment, then wait for
// a bit to get away from the exact time of the increment (or minor
// inaccuracies in the HW clock will cause failures).
wtime = Cyg_WallClock::wallclock->get_current_time();
do {
base = Cyg_WallClock::wallclock->get_current_time();
} while (base == wtime);
th->delay( one_sec/10 );
 
for( int i = 0; i < loops; i += 2 )
{
// Make a note of the time
ticks = Cyg_Clock::real_time_clock->current_value();
 
wtime = Cyg_WallClock::wallclock->get_current_time();
if(wtime != base+i)
{
diag_printf("offset %d, read %d, expected %d\n", i, wtime, base+i);
CYG_TEST_FAIL_FINISH( "Clock out of sync" );
}
 
// then calculate how much the above took so the delay
// below can be made accurate.
ticks = Cyg_Clock::real_time_clock->current_value() - ticks;
 
th->delay( 2*one_sec - ticks );
}
 
if ( ! cyg_test_is_simulator ) {
CYG_TEST_INFO("Tick output. Two seconds between each output.");
 
// Start by synchronizing to next wallclock increment, then
// wait for a bit to get away from the exact time of the
// increment (or minor inaccuracies in the HW clock will cause
// failures).
wtime = Cyg_WallClock::wallclock->get_current_time();
do {
base = Cyg_WallClock::wallclock->get_current_time();
} while (base == wtime);
th->delay( one_sec/10 );
 
for( int i = 0; i < loops; i += 2 )
{
// Make a note of the time
ticks = Cyg_Clock::real_time_clock->current_value();
wtime = Cyg_WallClock::wallclock->get_current_time();
if(wtime != base+i)
{
diag_printf("wallclock drift: saw %d expected %d\n",
wtime, base+i);
}
CYG_TEST_STILL_ALIVE(i, "2xtick...");
// then calculate how much the above took so the delay
// below can be made accurate.
ticks = Cyg_Clock::real_time_clock->current_value() - ticks;
th->delay( 2*one_sec - ticks );
}
}
 
CYG_TEST_PASS_FINISH("Wallclock OK");
}
 
// -------------------------------------------------------------------------
 
 
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
externC void
cyg_hal_invoke_constructors();
#endif
 
externC void
cyg_start( void )
{
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
cyg_hal_invoke_constructors();
#endif
CYG_TEST_INIT();
 
// Dont run this test if we are in a simulator, it just takes far too long.
if( cyg_test_is_simulator )
CYG_TEST_NA("Wallclock test takes too long in simulators");
CYG_TEST_INFO("Starting wallclock test");
 
Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution();
one_sec = ( res.divisor * 1000000000LL ) / res.dividend ;
th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
wallclock_thread,
0,
"wallclock_thread",
(CYG_ADDRESS)thread_stack,
STACKSIZE
);
 
th->resume();
 
// Get the world going
Cyg_Scheduler::scheduler.start();
 
}
 
#else // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
 
externC void
cyg_start( void )
{
CYG_TEST_INIT();
CYG_TEST_NA("Kernel real-time clock/threads timer disabled");
}
 
#endif // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc...
 
// -------------------------------------------------------------------------
// EOF wallclock.cxx
/tests/wallclock2.cxx
0,0 → 1,129
//==========================================================================
//
// wallclock2.cxx
//
// WallClock battery backed up test
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): jskov
// Contributors: jskov
// Date: 2000-03-29
// Description: Tests the WallClock device.
// Prints wallclock setting (for human verification that time
// matches the expected value). Then tries to set/restore
// clock value, and verifies that the WallClock epoch matches
// that of the libc.
//####DESCRIPTIONEND####
// -------------------------------------------------------------------------
 
#include <pkgconf/system.h>
#include <cyg/infra/testcase.h>
#include <cyg/infra/diag.h>
#ifdef CYGPKG_LIBC_TIME
#include <pkgconf/libc_time.h>
#endif
#ifdef CYGPKG_LIBC_STARTUP
#include <pkgconf/libc_startup.h>
#endif
 
#if !defined(CYGSEM_LIBC_TIME_CLOCK_WORKING)
# define NA_MSG "Requires libc time functions"
#elif !defined(CYGPKG_LIBC_STARTUP)
# define NA_MSG "Requires libc startup package"
#endif
 
#ifndef NA_MSG
#include <time.h>
#include <string.h> // strcmp
#include <cyg/io/wallclock.hxx> // The WallClock API
 
// -------------------------------------------------------------------------
 
 
externC int
main (void )
{
time_t now, test, test2;
 
CYG_TEST_INIT();
 
// make this predictable - independent of the user option
cyg_libc_time_setzoneoffsets(0, 3600);
cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );
 
// Print out current setting so a human can verify that clock state
// was valid.
now = (time_t) Cyg_WallClock::wallclock->get_current_time();
diag_printf("WallClock is set to: %s", ctime(&now));
 
// Check that set/get works
Cyg_WallClock::wallclock->set_current_time( 0 );
test = (time_t) Cyg_WallClock::wallclock->get_current_time();
// 2000.03.01 00:00:00 UTC
Cyg_WallClock::wallclock->set_current_time( 951868800 );
test2 = (time_t) Cyg_WallClock::wallclock->get_current_time();
// Should test 2100 and 2400 leap year calculations as well, but
// these would overflow with today's time_t.
Cyg_WallClock::wallclock->set_current_time( now );
CYG_TEST_PASS_FAIL(2 >= test, // each operation can take one second
"Can set WallClock to epoch");
CYG_TEST_PASS_FAIL(951868800+2 > test2 &&
951868800 <= test2,
"WallClock date conversion Y2K safe");
 
// Test that the wallclock and libc use same epoch.
test = (time_t) 0;
CYG_TEST_PASS_FAIL(!strcmp(ctime(&test), "Thu Jan 01 00:00:00 1970\n"),
"WallClock epoch matches libc epoch");
 
CYG_TEST_FINISH("Finished wallclock battery test");
}
 
#else
 
externC void
cyg_start( void )
{
CYG_TEST_INIT();
CYG_TEST_PASS_FINISH(NA_MSG);
}
 
#endif // NA_MSG
 
// -------------------------------------------------------------------------
// EOF wallclock2.cxx
/include/wallclock.hxx
0,0 → 1,112
#ifndef CYGONCE_IO_WALLCLOCK_HXX
#define CYGONCE_IO_WALLCLOCK_HXX
 
//==========================================================================
//
// wallclock.hxx
//
// Wallclock interface declaration
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): nickg
// Contributors: nickg
// Date: 1999-03-05
// Purpose: Wall Clock declarations
// Description: This file defines the interface to the wall clock device
// that provides real time stamps. Actual implementations of
// this driver can be found in devs/wallclock.
// Usage: #include <cyg/io/wallclock.hxx>
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#include <cyg/infra/cyg_type.h>
 
// -------------------------------------------------------------------------
// Wallclock class
 
class Cyg_WallClock
{
 
public:
 
Cyg_WallClock();
 
// Returns the number of seconds elapsed since 1970-01-01 00:00:00.
// This may involve reading the hardware, so it may take anything
// up to a second to complete.
cyg_uint32 get_current_time();
 
// Sets the clock. Argument is seconds elapsed since 1970-01-01 00:00:00.
// This may involve writing to the hardware, so it may take
// anything up to a second to complete.
void set_current_time( cyg_uint32 time_stamp );
 
// A static pointer to the single system defined wall clock device.
static Cyg_WallClock *wallclock;
 
private:
 
// Functions implemented by the hardware-specific part of the
// driver.
 
// Note: While the API specifies elapsed time since 1970-01-01
// 00:00:00 this is only an actual requirement if the driver is
// used in set-get mode - in init-get mode, the upper layer of the
// driver only needs to know the number of elapsed seconds between
// the init_hw_seconds and get_hw_seconds calls; the hardware
// epoch base is factored out, so the driver can use any base
// desired (see the emulated device).
 
// Called to initialize the hardware clock to a known sane state, or
// simply to make sure it can be accessed in set-get mode.
void init_hw_seconds( void );
 
// Returns the number of seconds elapsed since 1970-01-01 00:00:00.
// (or any desired epoch when in init-get mode)
cyg_uint32 get_hw_seconds( void );
 
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
// Sets the clock. Argument is seconds elapsed since 1970-01-01 00:00:00.
void set_hw_seconds( cyg_uint32 secs );
#endif
};
 
#endif // ifndef CYGONCE_DEVS_WALLCLOCK_HXX
// EOF wallclock.hxx
/include/wallclock/wallclock.inl
0,0 → 1,147
#ifndef CYGONCE_IO_WALLCLOCK_INL
#define CYGONCE_IO_WALLCLOCK_INL
 
//==========================================================================
//
// wallclock.inl
//
// Wallclock internal helper functions
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): jskov
// Contributors: jskov
// Date: 2000-05-26
// Purpose: Wall Clock internal helper functions
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#include <cyg/infra/cyg_type.h>
#include <cyg/infra/cyg_ass.h> // assertions
 
// -------------------------------------------------------------------------
// Some helper functions
 
#define is_leap(_y_) (((0==(_y_)%4 && 0!=(_y_)%100) || 0==(_y_)%400) ? 1 : 0)
#define year_days(_y_) (is_leap(_y_) ? 366 : 365)
 
static cyg_int32 days_per_month[2][12] = {
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
 
#ifndef time_t
#define time_t cyg_uint32
#endif
 
static time_t
_simple_mktime(cyg_uint32 year, cyg_uint32 mon,
cyg_uint32 day, cyg_uint32 hour,
cyg_uint32 min, cyg_uint32 sec)
{
time_t secs;
cyg_uint32 y, m, days;
 
CYG_ASSERT(year <= 3124, "Year is unreasonably large");
CYG_ASSERT(mon <= 12, "Month is invalid");
CYG_ASSERT(day <= 31, "Day is invalid");
CYG_ASSERT(hour <= 23, "Hour is invalid");
CYG_ASSERT(min <= 59, "Minutes is invalid");
CYG_ASSERT(sec <= 61, "Seconds is invalid");
 
// Number of days due to years
days = 0;
for (y = 1970; y < year; y++)
days += year_days(y);
 
// Due to months
for (m = 0; m < mon-1; m++)
days += days_per_month[is_leap(year)][m];
// Add days
days += day - 1;
 
// Add hours, minutes, and seconds
secs = ((days * 24 + hour) * 60 + min) * 60 + sec;
 
return secs;
}
 
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
 
 
static void
_simple_mkdate(time_t time,
cyg_uint32* year, cyg_uint32* mon,
cyg_uint32* day, cyg_uint32* hour,
cyg_uint32* min, cyg_uint32* sec)
{
cyg_int32 days, hms, y, m, *dpm;
 
days = (cyg_int32) (time / (24*60*60));
hms = (cyg_int32) (time % (24*60*60));
 
// Nothing fancy about the time - no leap year magic involved
*sec = hms % 60;
*min = (hms % (60*60)) / 60;
*hour = hms / (60*60);
 
// Find year
for (y = 1970; days >= year_days(y); y++)
days -= year_days(y);
*year = y;
dpm = &days_per_month[is_leap(y)][0];
 
// Find month
for (m = 0; days >= dpm[m]; m++)
days -= dpm[m];
m++;
*mon = m;
 
*day = days+1;
}
 
#endif
 
//-----------------------------------------------------------------------------
// BCD helper macros
#define TO_BCD(x) (((x/10)<<4) | (x%10))
#define TO_DEC(x) (((x>>4)*10) + (x&0xf))
 
#endif // ifndef CYGONCE_DEVS_WALLCLOCK_INL
// EOF wallclock.inl
/src/wallclock.cxx
0,0 → 1,146
//==========================================================================
//
// devs/wallclock/wallclock.cxx
//
// Wallclock base
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): jskov
// Contributors: jskov
// Date: 2000-03-28
// Purpose: Wallclock base driver
// Description: This provides a generic wallclock base driver which
// relies on sub-drivers to provide the interface functions
// to the hardware device (see wallclock.hxx for details).
//
// The driver can be configured to run in one of two modes:
// init-get mode:
// In this mode, the hardware driver only needs to
// implement a function to read the hardware clock
// and a (possibly empty) init function which makes
// sure the hardware clock is properly initialized.
// While the driver in this mode has a smaller memory
// foot-print, it does not support battery-backed up
// clocks.
//
// set-get mode:
// Requires both set and get functions for the hardware
// device. While bigger, it allows support of
// battery-backed up clocks.
//
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#include <pkgconf/wallclock.h> // Wallclock device config
 
#include <cyg/infra/cyg_type.h> // Common type definitions and support
 
#include <cyg/hal/drv_api.h> // Driver API
 
#include <cyg/io/wallclock.hxx> // The WallClock API
 
 
//-----------------------------------------------------------------------------
// Local static variables
 
static Cyg_WallClock wallclock_instance CYGBLD_ATTRIB_INIT_AFTER( CYG_INIT_CLOCK );
 
#ifndef CYGSEM_WALLCLOCK_SET_GET_MODE
static cyg_uint32 epoch_ticks;
static cyg_uint32 epoch_time_stamp;
#endif
 
Cyg_WallClock *Cyg_WallClock::wallclock;
 
//-----------------------------------------------------------------------------
// Constructor
 
Cyg_WallClock::Cyg_WallClock()
{
// install instance pointer
wallclock = &wallclock_instance;
 
// Always allow low-level driver to initialize clock, even though it
// may not be necessary for set-get mode.
init_hw_seconds();
}
 
//-----------------------------------------------------------------------------
// Returns the number of seconds elapsed since 1970-01-01 00:00:00.
// This may involve reading the hardware, so it may take anything up to
// a second to complete.
 
cyg_uint32 Cyg_WallClock::get_current_time()
{
cyg_uint32 res;
 
cyg_drv_dsr_lock();
 
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
res = get_hw_seconds();
#else
res = epoch_time_stamp + get_hw_seconds() - epoch_ticks;
#endif
 
cyg_drv_dsr_unlock();
 
return res;
}
 
//-----------------------------------------------------------------------------
// Sets the clock. Argument is seconds elapsed since 1970-01-01 00:00:00.
// This may involve reading or writing to the hardware, so it may take
// anything up to a second to complete.
void Cyg_WallClock::set_current_time( cyg_uint32 time_stamp )
{
cyg_drv_dsr_lock();
 
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
set_hw_seconds(time_stamp);
#else
epoch_time_stamp = time_stamp;
epoch_ticks = get_hw_seconds();
#endif
 
cyg_drv_dsr_unlock();
}
 
//-----------------------------------------------------------------------------
// End of devs/wallclock/wallclock.cxx
/src/emulate.cxx
0,0 → 1,94
//==========================================================================
//
// io/wallclock/emulate.cxx
//
// Wallclock emulation implementation
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): nickg
// Contributors: nickg
// Date: 1999-03-05
// Purpose: Wallclock emulation
//
//####DESCRIPTIONEND####
//
//==========================================================================
 
#include <pkgconf/wallclock.h> // Wallclock device config
#include <pkgconf/kernel.h> // Kernel config
 
#include <cyg/infra/cyg_type.h> // Common type definitions and support
#include <cyg/kernel/ktypes.h>
 
#include <cyg/io/wallclock.hxx> // The WallClock API
 
#include <cyg/kernel/clock.hxx> // Access to kernel clock
#include <cyg/kernel/clock.inl>
 
 
// Remember the tick count at the time of initialization.
static cyg_tick_count epoch_ticks;
 
//-----------------------------------------------------------------------------
// Called to initialize the hardware clock with a known valid
// time. Which of course isn't required when doing emulation using the
// kernel clock. But we set the private epoch base to "now".
void
Cyg_WallClock::init_hw_seconds( void )
{
// Remember the current clock tick count.
epoch_ticks = Cyg_Clock::real_time_clock->current_value();
}
 
//-----------------------------------------------------------------------------
// Returns the number of seconds elapsed since the init call.
cyg_uint32
Cyg_WallClock::get_hw_seconds( void )
{
Cyg_Clock::cyg_resolution res =
Cyg_Clock::real_time_clock->get_resolution();
cyg_tick_count secs = Cyg_Clock::real_time_clock->current_value()
- epoch_ticks;
 
secs = ( secs * res.dividend ) / ( res.divisor * 1000000000LL ) ;
 
return secs;
}
 
//-----------------------------------------------------------------------------
// End of devs/wallclock/emulate.cxx
/ChangeLog
0,0 → 1,305
2001-07-30 Jesper Skov <jskov@redhat.com>
 
* include/wallclock/wallclock.inl (_simple_mktime): Fix assertion
for leap seconds.
 
2001-07-27 Jesper Skov <jskov@redhat.com>
 
* include/wallclock/wallclock.inl (_simple_mktime): Added some assertions.
(_simple_mktime): Adjust assertions to correct and more sensible
values.
(_simple_mktime): A few more assertion tweaks.
 
2001-06-21 Jonathan Larmour <jlarmour@redhat.com>
 
* tests/wallclock2.cxx: No need to check for CYGINT_LIBC_STARTUP_CONTEXT
as it is required by CYGPKG_LIBC_STARTUP.
 
2001-04-06 Jonathan Larmour <jlarmour@redhat.com>
 
* include/wallclock/wallclock.inl (_simple_mkdate): Fix small
operator precedence bug.
 
2001-04-05 Nick Garnett <nickg@cygnus.co.uk>
 
* tests/wallclock.cxx: Don't run this test in any simulated
environment. It just takes far too long and is always timed out by
the testing infrastructure.
 
2000-11-22 Jesper Skov <jskov@redhat.com>
 
* src/wallclock.cxx: User driver API instead of scheduler lock.
 
* cdl/wallclock.cdl: Emulation requires the kernel, as do the tests.
 
2000-11-09 Jesper Skov <jskov@redhat.com>
 
* tests/wallclock2.cxx: Include string header.
 
2000-10-20 Jonathan Larmour <jlarmour@redhat.com>
 
* tests/wallclock2.cxx: Play better with main() startup configury
 
* tests/wallclock.cxx: Ensure default priority constructors
are called.
 
2000-07-24 Jonathan Larmour <jlarmour@redhat.co.uk>
 
* tests/wallclock2.cxx: Depend on CYGPKG_LIBC_TIME not CYGPKG_LIBC
 
2000-05-30 Jesper Skov <jskov@redhat.com>
 
* include/wallclock/wallclock.inl (_simple_mktime): Replaced
expression with algorithm.
 
* tests/wallclock2.cxx: Test wallclock's conversion functions for
Y2K safety.
 
2000-05-26 Jesper Skov <jskov@redhat.com>
 
* include/wallclock/wallclock.inl:
(_simple_mkdate): Rewritten.
 
* src/wallclock.cxx:
* include/wallclock.hxx: low-level driver may need init call also
in set-get mode. Split helper functions out in new .inl header.
* cdl/wallclock.cdl: Added set-get/init-get option.
 
* tests/wallclock2.cxx: Allow HW calls to take one second.
* tests/wallclock.cxx: Don't set clock.
 
2000-04-19 Jesper Skov <jskov@cygnus.co.uk>
 
* src/wallclock.cxx: Construct after kernel RTC since the
emulation implementation may have to use the RTC.
 
2000-04-13 Jesper Skov <jskov@redhat.com>
 
* tests/wallclock.cxx: Use TEST_NA if N/A.
Split in two separate parts (accuracy & info).
 
2000-04-12 Jesper Skov <jskov@redhat.com>
 
* cdl/wallclock.cdl: Don't let interfaces define anything.
 
2000-04-06 Jonathan Larmour <jlarmour@redhat.co.uk>
 
* tests/wallclock2.cxx: Test correct libc feature CDL
 
2000-04-05 John Dallaway <jld@cygnus.co.uk>
 
* cdl/wallclock.cdl:
 
Implement wallclock implementations as radio buttons.
 
2000-04-05 Jesper Skov <jskov@redhat.com>
 
* tests/wallclock.cxx:
Increase precision of test.
* src/wallclock.cxx:
* src/emulate.cxx:
* tests/wallclock.cxx:
* tests/wallclock2.cxx:
 
* Moved common code, emulation device and tests to io/wallclock.
 
2000-04-04 Jesper Skov <jskov@redhat.com>
 
* tests/wallclock2.cxx: Include testcase.h before conditional NA.
 
2000-03-29 Jesper Skov <jskov@redhat.com>
 
* tests/wallclock2.cxx:
* include/wallclock.hxx:
* src/sh3.cxx:
* src/wallclock.cxx:
* cdl/wallclock.cdl:
Reworked WallClock API. It should now be simpler to add new
wallclock drivers. Added a simple test to print out the current
wallclock value so a human can verify battery backup works.
 
2000-03-17 Jesper Skov <jskov@redhat.com>
 
* cdl/wallclock.cdl:
* src/sh3.cxx:
Added wallclock driver for SH3 RTC module.
 
2000-01-31 Simon FitzMaurice <sdf@cygnus.co.uk>
* cdl/wallclock.cdl:
 
Adjust help URLs in line with new doc layout.
 
2000-01-28 Simon FitzMaurice <sdf@cygnus.co.uk>
* cdl/wallclock.cdl:
 
Adjust help URLs in line with new doc layout.
 
2000-01-19 Hugo Tyson <hmt@cygnus.co.uk>
 
* cdl/*.cdl: Add descriptions to a number of options &c which were
lacking same, also tidied up other typos as noticed en passant.
 
1999-11-03 John Dallaway <jld@cygnus.co.uk>
 
* cdl/wallclock.cdl: Define build options.
 
1999-07-14 Jesper Skov <jskov@cygnus.co.uk>
 
* src/emulate.cxx: Include pkgconf/kernel.h.
 
1999-04-20 Jonathan Larmour <jlarmour@cygnus.co.uk>
 
* tests/wallclock.cxx (cyg_start): Output message to show the test
has started
(wallclock_thread): Add call to CYG_TEST_STILL_ALIVE, so the user
can see that the test is still running.
Fix for PR 19870
 
1999-04-12 John Dallaway <jld@cygnus.co.uk>
 
* include/pkgconf/wallclock.h: Add cdl_package doc attribute.
 
1999-04-07 Jesper Skov <jskov@cygnus.co.uk>
PR 19667
* tests/wallclock.cxx (cyg_start):
Changed to use the new Cyg_Thread constructor.
 
1999-03-22 Hugo Tyson <hmt@cygnus.co.uk>
 
* tests/wallclock.cxx:
Use CYGNUM_HAL_STACK_SIZE_TYPICAL for the stack size instead of
CYGNUM_HAL_MINIMUM_STACK_SIZE.
 
1999-03-12 Hugo Tyson <hmt@cygnus.co.uk>
 
* tests/wallclock.cxx:
Deal with CYGNUM_HAL_MINIMUM_STACK_SIZE requirement.
 
 
1999-03-05 Jonathan Larmour <jlarmour@cygnus.co.uk>
 
* include/wallclock.hxx:
Remove dependency on cyg/kernel/ktypes.h
Tidy
 
* src/emulate.cxx:
Include cyg/kernel/ktypes.h since it isn't included in wallclock.hxx
any more
 
1999-03-04 Gary Thomas <gthomas@cygnus.co.uk>
 
* include/pkgconf/wallclock.h: Make package stand-alone (no "DEVICES").
 
1999-02-02 Jesper Skov <jskov@cygnus.co.uk>
PR 18970
* tests/wallclock.cxx (LOOPS_SIM): Only do two loops on
SIM. MN10300 sim takes 1min15secs to do one loop.
 
1999-01-26 Jesper Skov <jskov@cygnus.co.uk>
(PR 18305)
* tests/wallclock.cxx: Removed MIPS specific hackery. Now
dependent on cyg_test_is_simulator state.
 
1999-01-21 Jesper Skov <jskov@cygnus.co.uk>
PR 18847
* tests/wallclock.cxx (LOOPS_HW): Reduce run-time to 20 seconds.
 
1999-01-19 Nick Garnett <nickg@cygnus.co.uk>
 
* tests/wallclock.cxx: Added test of cyg_test_is_simulator to
reduce time on simulated hardware. PR 18715.
 
1998-12-17 Jesper Skov <jskov@cygnus.co.uk>
 
* tests/wallclock.cxx: Do NOP test if kernel RTC disabled.
 
1998-10-23 Jesper Skov <jskov@cygnus.co.uk>
 
* tests/wallclock.cxx: Reduce test time on TX39 SIM.
 
Tue Oct 20 15:54:09 1998 Jonathan Larmour <jlarmour@cygnus.co.uk>
 
* src/PKGconf.mak:
Remove unnecessary override of PKGCONF_CXXFLAGS
 
1998-09-26 Bart Veer <bartv@cygnus.co.uk>
 
* include/pkgconf/wallclock.h:
PR17501: When using the emulation there is a requirement on the
kernel clock. This has been added to the configuration data.
If real hardware were used then this dependency would disappear,
but currently there is no easy way to express this, and there are
no hardware implementations.
 
1998-09-12 Bart Veer <bartv@cygnus.co.uk>
 
* include/pkgconf/wallclock.h:
Added missing descriptions (PR 17184)
 
1998-09-02 Bart Veer <bartv@cygnus.co.uk>
 
* include/pkgconf/wallclock.h:
Added minimal configuration data.
 
Fri Aug 28 09:40:19 1998 Jonathan Larmour <jlarmour@cygnus.co.uk>
 
* tests/wallclock.cxx:
Rename int main(argc, argv) to void cyg_start( void ) under the
new entry point system. Therefore also remove return code.
Tue Aug 18 16:49:20 1998 Jonathan Larmour <jlarmour@cygnus.co.uk>
 
* tests/wallclock.cxx:
Move inclusion of thread.inl before sched.hxx to prevent inline
warnings
 
1998-07-31 Nick Garnett <nickg@cygnus.co.uk>
 
* include/pkgconf/wallclock.h:
Added this file to contain wallclock confiuration parameters.
* src/emulate.cxx:
Now uses pkgconf/wallclock.h for configuration.
 
Wed Jul 22 21:04:15 1998 Jonathan Larmour <jlarmour@cygnus.co.uk>
 
* src/emulate.cxx:
Remove unnecessary include of <cyg/devs/table.h> and remove an
unused variable (result) from get_current_time()
 
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.