# HG changeset patch # User asl # Date 1065958143 0 # Node ID 2449d74b1fa735555c14855ac4b62f07537178a3 # Parent 3487ed83fe0c55cf05bb24f96e28252a68049f9a * cdl/wallclock_synth.cdl: * src/wallclock_synth.cxx: Implemented set_get mode. diff --git a/packages/devs/wallclock/synth/current/ChangeLog b/packages/devs/wallclock/synth/current/ChangeLog --- a/packages/devs/wallclock/synth/current/ChangeLog +++ b/packages/devs/wallclock/synth/current/ChangeLog @@ -1,3 +1,9 @@ +2003-10-06 Savin Zlobec + + * cdl/wallclock_synth.cdl: + * src/wallclock_synth.cxx: + Implemented set_get mode. + 2003-10-02 Savin Zlobec * cdl/wallclock_synth.cdl: diff --git a/packages/devs/wallclock/synth/current/cdl/wallclock_synth.cdl b/packages/devs/wallclock/synth/current/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 diff --git a/packages/devs/wallclock/synth/current/src/wallclock_synth.cxx b/packages/devs/wallclock/synth/current/src/wallclock_synth.cxx --- 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 +#include #include #include @@ -60,25 +61,53 @@ #include //----------------------------------------------------------------------------- + +#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