From c9e8fc62c9542e0b2587080d2e1961cff7b832f8 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Fri, 17 Mar 2006 16:25:02 +0000 Subject: [PATCH] =?UTF-8?q?ecrt=5Fmaster=5Fprepare=5Fasync=5Fio()=20hinzug?= =?UTF-8?q?ef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/ecrt.h | 1 + master/master.c | 34 +++++++++++++++++++++++++++++++++- master/master.h | 1 + mini/mini.c | 7 +++---- rt/msr_module.c | 8 +++----- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/include/ecrt.h b/include/ecrt.h index 39bf82ca..b2739f19 100644 --- a/include/ecrt.h +++ b/include/ecrt.h @@ -49,6 +49,7 @@ void ecrt_master_deactivate(ec_master_t *master); void ecrt_master_sync_io(ec_master_t *master); void ecrt_master_async_send(ec_master_t *master); void ecrt_master_async_receive(ec_master_t *master); +void ecrt_master_prepare_async_io(ec_master_t *master); void ecrt_master_debug(ec_master_t *master, int level); void ecrt_master_print(const ec_master_t *master); int ecrt_master_sdo_write(ec_master_t *master, diff --git a/master/master.c b/master/master.c index 4212f59f..68dcdce5 100644 --- a/master/master.c +++ b/master/master.c @@ -100,6 +100,7 @@ void ec_master_reset(ec_master_t *master master->command_index = 0; master->debug_level = 0; + master->timeout = 100; // us master->stats.timeouts = 0; master->stats.delayed = 0; master->stats.corrupted = 0; @@ -857,7 +858,7 @@ void ecrt_master_sync_io(ec_master_t *master) ec_master_send_commands(master); t_start = get_cycles(); // Sendezeit nehmen - t_timeout = 100 * cpu_khz / 1000; // 100us + t_timeout = master->timeout * cpu_khz / 1000; do { ec_device_call_isr(master->device); @@ -959,6 +960,37 @@ void ecrt_master_async_receive(ec_master_t *master) /*****************************************************************************/ +/** + Bereitet Synchronen Datenverkehr vor. + + Fürgt einmal die Kommandos aller Domains zur Warteschlange hinzu, sendet + diese ab und wartet so lange, bis diese anschließend problemlos empfangen + werden können. +*/ + +void ecrt_master_prepare_async_io(ec_master_t *master) +{ + ec_domain_t *domain; + cycles_t t_start, t_end, t_timeout; + + // Alle empfangenen Kommandos aus der Liste entfernen + list_for_each_entry(domain, &master->domains, list) + ecrt_domain_queue(domain); + + ecrt_master_async_send(master); + + t_start = get_cycles(); // Sendezeit nehmen + t_timeout = master->timeout * cpu_khz / 1000; + + // Aktiv warten! + do { + t_end = get_cycles(); + } + while (t_end - t_start < t_timeout); +} + +/*****************************************************************************/ + /** Setzt die Debug-Ebene des Masters. diff --git a/master/master.h b/master/master.h index bfe248a8..0af61143 100644 --- a/master/master.h +++ b/master/master.h @@ -52,6 +52,7 @@ struct ec_master struct list_head domains; /**< Liste der Prozessdatendomänen */ int debug_level; /**< Debug-Level im Master-Code */ ec_stats_t stats; /**< Rahmen-Statistiken */ + unsigned int timeout; /**< Timeout für synchronen Datenaustausch */ }; /*****************************************************************************/ diff --git a/mini/mini.c b/mini/mini.c index 71fdee6e..f1f351f2 100644 --- a/mini/mini.c +++ b/mini/mini.c @@ -14,7 +14,7 @@ #include "../include/ecrt.h" // Echtzeitschnittstelle -//#define ASYNC +#define ASYNC /*****************************************************************************/ @@ -115,9 +115,8 @@ int __init init_mini_module(void) } #ifdef ASYNC - ecrt_domain_queue(domain1); - ecrt_master_async_send(master); - udelay(100); + // Einmal senden und warten... + ecrt_master_prepare_async_io(master); #endif printk("Starting cyclic sample thread.\n"); diff --git a/rt/msr_module.c b/rt/msr_module.c index 3872f224..617ad768 100644 --- a/rt/msr_module.c +++ b/rt/msr_module.c @@ -37,7 +37,7 @@ // EtherCAT #include "../include/ecrt.h" -//#define ASYNC +#define ASYNC // Defines/Makros #define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ) @@ -229,10 +229,8 @@ int __init init_rt_module(void) #endif #ifdef ASYNC - ecrt_domain_queue(domain1); - ecrt_domain_queue(domain2); - ecrt_master_async_send(master); - udelay(100); + // Einmal senden und warten... + ecrt_master_prepare_async_io(master); #endif ipipe_init_attr(&attr);