From d6a2322cd50a8c1487d5c73b723bfeaf0fed50d4 Mon Sep 17 00:00:00 2001 From: Thierry Carré Date: Thu, 16 May 2013 14:33:53 +0200 Subject: cesar/hal/phy/maximus: accept to program a timer in the past (less than 1ms) Add some tolerance on timer management. --- cesar/hal/phy/maximus/inc/maximus_defs.h | 4 -- cesar/hal/phy/maximus/src/maximus_phy_ctrl.c | 72 +++++++++++----------------- 2 files changed, 28 insertions(+), 48 deletions(-) (limited to 'cesar/hal') diff --git a/cesar/hal/phy/maximus/inc/maximus_defs.h b/cesar/hal/phy/maximus/inc/maximus_defs.h index f948200b33..2a07753b94 100644 --- a/cesar/hal/phy/maximus/inc/maximus_defs.h +++ b/cesar/hal/phy/maximus/inc/maximus_defs.h @@ -28,10 +28,6 @@ */ #define MAXIMUS_PHY_MPDU_RECEPTION_DELAY_TCK ((5 + 5) * 25) // (5 microseconds + 5 microseconds) * 25 ticks per microsecond -/** Threshold used to determinate if a netclock msg is considered to be programmed in the past. - */ -#define MAXIMUS_PHY_DATE_TOLERANCE 0x10000000 // 2^28 - /** Init value for random library (u32). */ #define MAXIMUS_PHY_LIB_RND_SEED 123 diff --git a/cesar/hal/phy/maximus/src/maximus_phy_ctrl.c b/cesar/hal/phy/maximus/src/maximus_phy_ctrl.c index 6bbf455ab1..f4022f9972 100644 --- a/cesar/hal/phy/maximus/src/maximus_phy_ctrl.c +++ b/cesar/hal/phy/maximus/src/maximus_phy_ctrl.c @@ -28,6 +28,8 @@ #include // for 'time()' #include +#define MAXIMUS_PHY_DATE_TOLERANCE_TCK (1000*25) /* 1000 us. */ + #ifdef ECOS externC void cyg_interrupt_call_pending_DSRs (void); @@ -1837,62 +1839,44 @@ void maximus_phy_rx_activate_cancel (phy_t *ctx) } } - -/** - * Compute schedule tick. - * \param date programmed date - * \return schedule tick if ok, -1 if programmed date is considered to be in the past with errno = EINVAL - */ -tick_t maximus_phy_schedule_tick (u32 date) +tick_t +maximus_phy_schedule_tick (u32 date) { - tick_t schedule_tick = (tick_t)-1; - - const u32 tick_high = my_station.current_tick_tck >> 32; - const u32 tick_low = (u32)my_station.current_tick_tck; - - /* Determinate whether programmed date is considered to be in the past, - * or in the future after tick rollover. */ + tick_t schedule_tick; + const u32 current_tck = my_station.current_tick_tck; - u32 tolerance = tick_low - (u32)MAXIMUS_PHY_DATE_TOLERANCE; + s32 diff_tck = date - current_tck; - if (tick_low > tolerance) + /* Check if the date requested is considered to be in the past. */ + if (diff_tck < 0) { - if (date >= tick_low) - { - // programmed date is in the future - schedule_tick = ((tick_t)tick_high << 32) | (tick_t)date; - } - else if (date < tolerance) - { - // programmed date is considered to be in the future, after tick rollover - schedule_tick = ((tick_t)(tick_high+1) << 32) | (tick_t)date; - } - else + if (diff_tck < -MAXIMUS_PHY_DATE_TOLERANCE_TCK) { - // programmed date is considered to be in the past errno = EINVAL; - station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY, - "%s: errno = %d", __FUNCTION__, errno); - dbg_assert_print(false, "errno = %d because netclock msg programmed in the past", errno); - } - } - else - { - if ((date < tolerance) && (date >= tick_low)) - { - // programmed date is in the future - schedule_tick = ((tick_t)tick_high << 32) | (tick_t)date; + station_log ( + &my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY, + "%s: netclock msg programmed in the past (%d tick)", + __FUNCTION__, diff_tck); + dbg_assert_print (false, "errno = %d because netclock msg " + "programmed in the past", errno); + return -1; } else { - // programmed date is considered to be in the past - errno = EINVAL; - station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY, - "%s: errno = %d", __FUNCTION__, errno); - dbg_assert_print(false, "errno = %d because netclock msg programmed in the past", errno); + /* If the date is a little bit pass, The timer will be program + * with the current date. + * A warning is trig because this isn't a great behavior for a + * simulator. */ + station_log ( + &my_station, STATION_LOG_WARNING, STATION_LOGTYPE_PHY, + "%s: netclock msg programmed a little bit in " + "the past (%d tick)", __FUNCTION__, diff_tck); + diff_tck = 0; } } + schedule_tick = my_station.current_tick_tck + diff_tck; + return schedule_tick; } -- cgit v1.2.3