--- a/mini/mini.c Tue Apr 25 13:45:00 2006 +0000
+++ b/mini/mini.c Wed Apr 26 10:15:02 2006 +0000
@@ -28,6 +28,8 @@
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/timer.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
#include "../include/ecrt.h" // EtherCAT realtime interface
@@ -41,6 +43,7 @@
// EtherCAT
ec_master_t *master = NULL;
ec_domain_t *domain1 = NULL;
+spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
// data fields
//void *r_ssi_input, *r_ssi_status, *r_4102[3];
@@ -61,6 +64,8 @@
{
static unsigned int counter = 0;
+ spin_lock(&master_lock);
+
#ifdef ASYNC
// receive
ecrt_master_async_receive(master);
@@ -83,6 +88,8 @@
ecrt_master_async_send(master);
#endif
+ spin_unlock(&master_lock);
+
if (counter) {
counter--;
}
@@ -101,13 +108,21 @@
int request_lock(void *data)
{
- return 0;
+ unsigned int tries = 0;
+ while (1) {
+ if (spin_trylock(&master_lock)) {
+ if (tries) printk(KERN_INFO "lock: %i tries needed.\n", tries);
+ return 1;
+ }
+ tries++;
+ }
}
/*****************************************************************************/
void release_lock(void *data)
{
+ spin_unlock(&master_lock);
}
/*****************************************************************************/
@@ -152,13 +167,6 @@
ecrt_master_print(master, 0);
#endif
-#if 1
- if (ecrt_master_start_eoe(master)) {
- printk(KERN_ERR "Failed to start EoE processing!\n");
- goto out_deactivate;
- }
-#endif
-
#if 0
if (!(slave = ecrt_master_get_slave(master, "5"))) {
printk(KERN_ERR "Failed to get slave 5!\n");
@@ -192,6 +200,13 @@
ecrt_master_prepare_async_io(master);
#endif
+#if 1
+ if (ecrt_master_start_eoe(master)) {
+ printk(KERN_ERR "Failed to start EoE processing!\n");
+ goto out_deactivate;
+ }
+#endif
+
printk("Starting cyclic sample thread.\n");
init_timer(&timer);
timer.function = run;