# HG changeset patch # User Florian Pose # Date 1168245130 0 # Node ID 24292123d174c6fdf95587531c072d4712d8b42a # Parent 73fb3c35e53d5ed68b6bd96430ea04df74c271f2 Shorter critical sections in examples. diff -r 73fb3c35e53d -r 24292123d174 examples/mini/mini.c --- a/examples/mini/mini.c Mon Jan 08 08:23:18 2007 +0000 +++ b/examples/mini/mini.c Mon Jan 08 08:32:10 2007 +0000 @@ -32,7 +32,6 @@ *****************************************************************************/ #include -#include #include #include #include @@ -73,35 +72,36 @@ void run(unsigned long data) { static unsigned int counter = 0; - static unsigned int einaus = 0; - + static unsigned int blink = 0; + + // receive spin_lock(&master_lock); - - // receive ecrt_master_receive(master); ecrt_domain_process(domain1); + spin_unlock(&master_lock); // process data - //k_pos = EC_READ_U32(r_ssi); + // k_pos = EC_READ_U32(r_ssi); + + if (counter) { + counter--; + } + else { + counter = FREQUENCY; + blink = !blink; + } + #ifdef KBUS - EC_WRITE_U8(r_outputs + 2, einaus ? 0xFF : 0x00); -#endif - + EC_WRITE_U8(r_outputs + 2, blink ? 0xFF : 0x00); +#endif + // send + spin_lock(&master_lock); ecrt_domain_queue(domain1); ecrt_master_run(master); ecrt_master_send(master); - spin_unlock(&master_lock); - if (counter) { - counter--; - } - else { - counter = FREQUENCY; - einaus = !einaus; - } - // restart timer timer.expires += HZ / FREQUENCY; add_timer(&timer); @@ -211,8 +211,8 @@ /*****************************************************************************/ MODULE_LICENSE("GPL"); -MODULE_AUTHOR ("Florian Pose "); -MODULE_DESCRIPTION ("EtherCAT minimal test environment"); +MODULE_AUTHOR("Florian Pose "); +MODULE_DESCRIPTION("EtherCAT minimal test environment"); module_init(init_mini_module); module_exit(cleanup_mini_module); diff -r 73fb3c35e53d -r 24292123d174 examples/msr/msr_sample.c --- a/examples/msr/msr_sample.c Mon Jan 08 08:23:18 2007 +0000 +++ b/examples/msr/msr_sample.c Mon Jan 08 08:32:10 2007 +0000 @@ -66,7 +66,7 @@ // raw process data void *r_ana_out; -// Channels +// channels double k_ana_out; ec_pdo_reg_t domain1_pdos[] = { @@ -78,20 +78,20 @@ void msr_controller_run(void) { + // receive rt_sem_wait(&master_sem); - - // receive ecrt_master_receive(master); ecrt_domain_process(domain1); + rt_sem_signal(&master_sem); // Process data EC_WRITE_S16(r_ana_out, k_ana_out / 10.0 * 0x7FFF); // Send + rt_sem_wait(&master_sem); ecrt_domain_queue(domain1); ecrt_master_run(master); ecrt_master_send(master); - rt_sem_signal(&master_sem); msr_write_kanal_list(); @@ -221,8 +221,8 @@ /*****************************************************************************/ MODULE_LICENSE("GPL"); -MODULE_AUTHOR ("Florian Pose "); -MODULE_DESCRIPTION ("EtherCAT RTAI MSR sample module"); +MODULE_AUTHOR("Florian Pose "); +MODULE_DESCRIPTION("EtherCAT RTAI MSR sample module"); module_init(init_mod); module_exit(cleanup_mod); diff -r 73fb3c35e53d -r 24292123d174 examples/rtai/rtai_sample.c --- a/examples/rtai/rtai_sample.c Mon Jan 08 08:23:18 2007 +0000 +++ b/examples/rtai/rtai_sample.c Mon Jan 08 08:32:10 2007 +0000 @@ -46,12 +46,6 @@ /*****************************************************************************/ -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Florian Pose "); -MODULE_DESCRIPTION("EtherCAT RTAI sample module"); - -/*****************************************************************************/ - // RTAI task frequency in Hz #define FREQUENCY 10000 #define INHIBIT_TIME 20 @@ -84,22 +78,23 @@ void run(long data) { - while (1) - { + while (1) { t_last_cycle = get_cycles(); + rt_sem_wait(&master_sem); - ecrt_master_receive(master); ecrt_domain_process(domain1); + rt_sem_signal(&master_sem); // process data //k_pos = EC_READ_U32(r_ssi_input); + rt_sem_wait(&master_sem); ecrt_domain_queue(domain1); ecrt_master_run(master); ecrt_master_send(master); - rt_sem_signal(&master_sem); + rt_task_wait_period(); } } @@ -108,7 +103,7 @@ int request_lock(void *data) { - // too close to the next RT cycle: deny access... + // too close to the next real time cycle: deny access... if (get_cycles() - t_last_cycle > t_critical) return -1; // allow access @@ -142,7 +137,7 @@ ecrt_master_callbacks(master, request_lock, release_lock, NULL); - printk(KERN_INFO "Registering domain...\n"); + printk(KERN_INFO "Creating domain...\n"); if (!(domain1 = ecrt_master_create_domain(master))) { printk(KERN_ERR "Domain creation failed!\n"); goto out_release_master; @@ -207,8 +202,11 @@ /*****************************************************************************/ +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Florian Pose "); +MODULE_DESCRIPTION("EtherCAT RTAI sample module"); + module_init(init_mod); module_exit(cleanup_mod); /*****************************************************************************/ -