# HG changeset patch # User Florian Pose # Date 1224250603 0 # Node ID 6911450535b7e19ba5dfc7190fdf0f6925ac7e8d # Parent b93ceb5ebe37823aab0ad6cb9b22279aa6b2bed2 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation. diff -r b93ceb5ebe37 -r 6911450535b7 master/master.c --- a/master/master.c Fri Oct 17 13:35:56 2008 +0000 +++ b/master/master.c Fri Oct 17 13:36:43 2008 +0000 @@ -58,6 +58,22 @@ /*****************************************************************************/ +#ifdef EC_HAVE_CYCLES + +/** Frame timeout in cycles. + */ +static cycles_t timeout_cycles; + +#else + +/** Frame timeout in jiffies. + */ +static unsigned long timeout_jiffies; + +#endif + +/*****************************************************************************/ + void ec_master_clear_slave_configs(ec_master_t *); void ec_master_clear_domains(ec_master_t *); static int ec_master_idle_thread(void *); @@ -68,6 +84,20 @@ /*****************************************************************************/ +/** Static variables initializer. +*/ +void ec_master_init_static(void) +{ +#ifdef EC_HAVE_CYCLES + timeout_cycles = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000); +#else + // one jiffy may always elapse between time measurement + timeout_jiffies = max(EC_IO_TIMEOUT * HZ / 1000000, 1); +#endif +} + +/*****************************************************************************/ + /** Master constructor. \return 0 in case of success, else < 0 @@ -1375,33 +1405,21 @@ void ecrt_master_receive(ec_master_t *master) { ec_datagram_t *datagram, *next; -#ifdef EC_HAVE_CYCLES - cycles_t cycles_timeout; -#else - unsigned long diff_ms, timeout_ms; -#endif unsigned int frames_timed_out = 0; // receive datagrams ec_device_poll(&master->main_device); -#ifdef EC_HAVE_CYCLES - cycles_timeout = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000); -#else - timeout_ms = max(EC_IO_TIMEOUT /* us */ / 1000, 2); -#endif - // dequeue all datagrams that timed out list_for_each_entry_safe(datagram, next, &master->datagram_queue, queue) { if (datagram->state != EC_DATAGRAM_SENT) continue; #ifdef EC_HAVE_CYCLES if (master->main_device.cycles_poll - datagram->cycles_sent - > cycles_timeout) { + > timeout_cycles) { #else - diff_ms = (master->main_device.jiffies_poll - - datagram->jiffies_sent) * 1000 / HZ; - if (diff_ms > timeout_ms) { + if (master->main_device.jiffies_poll - datagram->jiffies_sent + > timeout_jiffies) { #endif frames_timed_out = 1; list_del_init(&datagram->queue); @@ -1415,7 +1433,8 @@ time_us = (unsigned int) (master->main_device.cycles_poll - datagram->cycles_sent) * 1000 / cpu_khz; #else - time_us = (unsigned int) (diff_ms * 1000); + time_us = (unsigned int) ((master->main_device.jiffies_poll - + datagram->jiffies_sent) * 1000000 / HZ); #endif EC_DBG("TIMED OUT datagram %08x, index %02X waited %u us.\n", (unsigned int) datagram, datagram->index, time_us); diff -r b93ceb5ebe37 -r 6911450535b7 master/master.h --- a/master/master.h Fri Oct 17 13:35:56 2008 +0000 +++ b/master/master.h Fri Oct 17 13:36:43 2008 +0000 @@ -171,6 +171,9 @@ /*****************************************************************************/ +// static funtions +void ec_master_init_static(void); + // master creation/deletion int ec_master_init(ec_master_t *, unsigned int, const uint8_t *, const uint8_t *, dev_t, struct class *); diff -r b93ceb5ebe37 -r 6911450535b7 master/module.c --- a/master/module.c Fri Oct 17 13:35:56 2008 +0000 +++ b/master/module.c Fri Oct 17 13:36:43 2008 +0000 @@ -133,6 +133,9 @@ goto out_class; } } + + // initialize static master variables + ec_master_init_static(); if (master_count) { if (!(masters = kmalloc(sizeof(ec_master_t) * master_count,