This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: Synthetic wallclock set_get mode
- From: Savin Zlobec <savin at elatec dot si>
- To: Savin Zlobec <savin at elatec dot si>
- Cc: ecos-patches at sources dot redhat dot com
- Date: Mon, 06 Oct 2003 14:00:43 +0200
- Subject: Re: Synthetic wallclock set_get mode
- References: <3F81494F.5050205@elatec.si>
Attached patch is essentially the same as previous, but with synth
wallclock driver disabled by default.
Because of synthetic target timings the emulated wallclock slightly
differs from the synth one and just
in case something depends on this the emulated wallclock should be left
as default on synthetic target.
savin
Index: current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/wallclock/synth/current/ChangeLog,v
retrieving revision 1.1
diff -u -5 -r1.1 ChangeLog
--- current/ChangeLog 5 Oct 2003 13:49:01 -0000 1.1
+++ current/ChangeLog 6 Oct 2003 11:42:19 -0000
@@ -1,5 +1,11 @@
+2003-10-06 Savin Zlobec <savin@elatec.si>
+
+ * cdl/wallclock_synth.cdl:
+ * src/wallclock_synth.cxx:
+ Implemented set_get mode.
+
2003-10-02 Savin Zlobec <savin@elatec.si>
* cdl/wallclock_synth.cdl:
* src/wallclock_synth.cxx:
Created wallclock driver for synthetic target.
Index: current/cdl/wallclock_synth.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/wallclock/synth/current/cdl/wallclock_synth.cdl,v
retrieving revision 1.1
diff -u -5 -r1.1 wallclock_synth.cdl
--- current/cdl/wallclock_synth.cdl 5 Oct 2003 13:49:02 -0000 1.1
+++ current/cdl/wallclock_synth.cdl 6 Oct 2003 11:42:19 -0000
@@ -55,19 +55,31 @@
display "Synthetic wallclock driver"
requires CYGPKG_HAL_SYNTH
hardware
compile wallclock_synth.cxx
implements CYGINT_WALLCLOCK_HW_IMPLEMENTATIONS
+ implements CYGINT_WALLCLOCK_SET_GET_MODE_SUPPORTED
active_if CYGIMP_WALLCLOCK_HARDWARE
cdl_option CYGIMP_WALLCLOCK_HARDWARE {
parent CYGPKG_IO_WALLCLOCK_IMPLEMENTATION
display "Hardware wallclock"
- default_value 1
+ default_value 0
implements CYGINT_WALLCLOCK_IMPLEMENTATIONS
}
+ cdl_option CYGDAT_DEVS_WALLCLOCK_SYNTH_FILENAME {
+ display "Name of file wich holds system-eCos wallclock offset"
+ flavor data
+ default_value { "\"synth.wallclock\"" }
+ active_if CYGSEM_WALLCLOCK_SET_GET_MODE
+ description "
+ This is the name of the file which holds the difference
+ between system and eCos wallclock. It is read at initialization
+ and written to each time the wallclock it set."
+ }
+
cdl_component CYGPKG_DEVS_WALLCLOCK_SYNTH_OPTIONS {
display "Synthetic wallclock build options"
flavor none
description "
Package specific build options including control over
Index: current/src/wallclock_synth.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/devs/wallclock/synth/current/src/wallclock_synth.cxx,v
retrieving revision 1.1
diff -u -5 -r1.1 wallclock_synth.cxx
--- current/src/wallclock_synth.cxx 5 Oct 2003 13:49:02 -0000 1.1
+++ current/src/wallclock_synth.cxx 6 Oct 2003 11:42:19 -0000
@@ -48,48 +48,98 @@
//####DESCRIPTIONEND####
//
//==========================================================================
#include <pkgconf/wallclock.h>
+#include <pkgconf/devs_wallclock_synth.h>
#include <cyg/hal/hal_io.h>
#include <cyg/hal/hal_arch.h>
#include <cyg/infra/cyg_type.h>
#include <cyg/infra/diag.h>
#include <cyg/io/wallclock.hxx>
//-----------------------------------------------------------------------------
+
+#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
+// Difference between system and eCos wallclock
+static cyg_uint32 epoch_ticks;
+static cyg_uint32 epoch_time_stamp;
+#endif
+
+//-----------------------------------------------------------------------------
// Functions required for the hardware-driver API.
// Initializes the clock
void
Cyg_WallClock::init_hw_seconds(void)
{
- // Nothing here
+#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
+ int fd;
+
+ // Read difference between system and eCos wallclock from file
+ fd = cyg_hal_sys_open(CYGDAT_DEVS_WALLCLOCK_SYNTH_FILENAME,
+ CYG_HAL_SYS_O_RDONLY, 0);
+
+ if (fd > 0)
+ {
+ cyg_hal_sys_read(fd, &epoch_time_stamp, sizeof(epoch_time_stamp));
+ cyg_hal_sys_read(fd, &epoch_ticks, sizeof(epoch_ticks));
+ cyg_hal_sys_close(fd);
+ }
+#endif
}
// Returns the number of seconds elapsed since 1970-01-01 00:00:00
cyg_uint32
Cyg_WallClock::get_hw_seconds(void)
{
+ cyg_uint32 res;
struct cyg_hal_sys_timeval ctv;
struct cyg_hal_sys_timezone ctz;
cyg_hal_sys_gettimeofday(&ctv, &ctz);
- return ctv.hal_tv_sec;
+#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
+ res = epoch_time_stamp + ctv.hal_tv_sec - epoch_ticks;
+#else
+ res = ctv.hal_tv_sec;
+#endif
+
+ return res;
}
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
// Sets the clock. Argument is seconds elapsed since 1970-01-01 00:00:00
void
Cyg_WallClock::set_hw_seconds(cyg_uint32 secs)
{
- // Not supported
+ int fd;
+ struct cyg_hal_sys_timeval ctv;
+ struct cyg_hal_sys_timezone ctz;
+
+ // System wallclock time
+ cyg_hal_sys_gettimeofday(&ctv, &ctz);
+
+ // Set the difference between the system and eCos wallclock
+ epoch_time_stamp = secs;
+ epoch_ticks = ctv.hal_tv_sec;
+
+ // Write difference to file
+ fd = cyg_hal_sys_open(CYGDAT_DEVS_WALLCLOCK_SYNTH_FILENAME,
+ CYG_HAL_SYS_O_WRONLY | CYG_HAL_SYS_O_CREAT,
+ CYG_HAL_SYS_S_IRWXU | CYG_HAL_SYS_S_IRWXG | CYG_HAL_SYS_S_IRWXO);
+
+ if (fd > 0)
+ {
+ cyg_hal_sys_write(fd, &epoch_time_stamp, sizeof(epoch_time_stamp));
+ cyg_hal_sys_write(fd, &epoch_ticks, sizeof(epoch_ticks));
+ cyg_hal_sys_close(fd);
+ }
}
#endif // CYGSEM_WALLCLOCK_SET_GET_MODE
//-----------------------------------------------------------------------------