Mercurial > ecos
changeset 1299:2449d74b1fa7
* cdl/wallclock_synth.cdl:
* src/wallclock_synth.cxx: Implemented set_get mode.
| author | asl |
|---|---|
| date | Sun, 12 Oct 2003 11:29:03 +0000 |
| parents | 3487ed83fe0c |
| children | 4d090a0fb5e5 |
| files | packages/devs/wallclock/synth/current/ChangeLog packages/devs/wallclock/synth/current/cdl/wallclock_synth.cdl packages/devs/wallclock/synth/current/src/wallclock_synth.cxx |
| diffstat | 3 files changed, 72 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/devs/wallclock/synth/current/ChangeLog +++ b/packages/devs/wallclock/synth/current/ChangeLog @@ -1,3 +1,9 @@ +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:
--- a/packages/devs/wallclock/synth/current/cdl/wallclock_synth.cdl +++ b/packages/devs/wallclock/synth/current/cdl/wallclock_synth.cdl @@ -57,15 +57,27 @@ cdl_package CYGPKG_DEVS_WALLCLOCK_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
--- a/packages/devs/wallclock/synth/current/src/wallclock_synth.cxx +++ b/packages/devs/wallclock/synth/current/src/wallclock_synth.cxx @@ -50,6 +50,7 @@ //========================================================================== #include <pkgconf/wallclock.h> +#include <pkgconf/devs_wallclock_synth.h> #include <cyg/hal/hal_io.h> #include <cyg/hal/hal_arch.h> @@ -60,25 +61,53 @@ #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 @@ -87,7 +116,28 @@ Cyg_WallClock::get_hw_seconds(void) 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
