--- a/examples/mini/mini.c Fri Feb 22 17:30:50 2008 +0000
+++ b/examples/mini/mini.c Fri Feb 22 17:31:00 2008 +0000
@@ -39,16 +39,16 @@
#include "../../include/ecrt.h" // EtherCAT realtime interface
#include "../../include/ecdb.h" // EtherCAT slave database
-#define PFX "ec_mini: "
-
+/*****************************************************************************/
+
+// module parameters
#define FREQUENCY 100
-
#define CONFIGURE_MAPPING
#define EXTERNAL_MEMORY
-/*****************************************************************************/
-
-static struct timer_list timer;
+#define PFX "ec_mini: "
+
+/*****************************************************************************/
// EtherCAT
static ec_master_t *master = NULL;
@@ -58,6 +58,27 @@
static ec_domain_t *domain1 = NULL;
static ec_domain_state_t domain1_state = {};
+static struct timer_list timer;
+static unsigned int counter = 0;
+
+/*****************************************************************************/
+
+// process data
+static uint8_t *domain1_pd; // process data memory
+
+static unsigned int off_ana_in; // offsets for Pdo entries
+static unsigned int off_dig_out;
+
+static unsigned int blink = 0;
+
+const static ec_pdo_entry_reg_t domain1_regs[] = {
+ {0, 1, Beckhoff_EL3162, 0x3101, 2, &off_ana_in},
+ {0, 3, Beckhoff_EL2004, 0x3001, 1, &off_dig_out},
+ {}
+};
+
+/*****************************************************************************/
+
#ifdef CONFIGURE_MAPPING
const ec_pdo_entry_info_t el3162_channel1[] = {
{0x3101, 1, 8}, // status
@@ -89,16 +110,6 @@
};
#endif
-static uint8_t *pd; /**< Process data. */
-static unsigned int off_ana_in;
-static unsigned int off_dig_out;
-
-const static ec_pdo_entry_reg_t domain1_regs[] = {
- {0, 1, Beckhoff_EL3162, 0x3101, 2, &off_ana_in},
- {0, 3, Beckhoff_EL2004, 0x3001, 1, &off_dig_out},
- {}
-};
-
/*****************************************************************************/
void check_domain1_state(void)
@@ -144,11 +155,8 @@
/*****************************************************************************/
-void run(unsigned long data)
-{
- static unsigned int counter = 0;
- static unsigned int blink = 0;
-
+void cyclic_task(unsigned long data)
+{
// receive process data
spin_lock(&master_lock);
ecrt_master_receive(master);
@@ -171,7 +179,7 @@
}
// write process data
- EC_WRITE_U8(pd + off_dig_out, blink ? 0x0F : 0x00);
+ EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x0F : 0x00);
// send process data
spin_lock(&master_lock);
@@ -256,12 +264,12 @@
#ifdef EXTERNAL_MEMORY
if ((size = ecrt_domain_size(domain1))) {
- if (!(pd = (uint8_t *) kmalloc(size, GFP_KERNEL))) {
+ if (!(domain1_pd = (uint8_t *) kmalloc(size, GFP_KERNEL))) {
printk(KERN_ERR PFX "Failed to allocate %u bytes of process data"
" memory!\n", size);
goto out_release_master;
}
- ecrt_domain_external_memory(domain1, pd);
+ ecrt_domain_external_memory(domain1, domain1_pd);
}
#endif
@@ -277,12 +285,12 @@
#ifndef EXTERNAL_MEMORY
// Get internal process data for domain
- pd = ecrt_domain_data(domain1);
+ domain1_pd = ecrt_domain_data(domain1);
#endif
printk(KERN_INFO PFX "Starting cyclic sample thread.\n");
init_timer(&timer);
- timer.function = run;
+ timer.function = cyclic_task;
timer.expires = jiffies + 10;
add_timer(&timer);
@@ -291,7 +299,7 @@
#ifdef EXTERNAL_MEMORY
out_free_process_data:
- kfree(pd);
+ kfree(domain1_pd);
#endif
out_release_master:
printk(KERN_ERR PFX "Releasing master...\n");
@@ -310,7 +318,7 @@
del_timer_sync(&timer);
#ifdef EXTERNAL_MEMORY
- kfree(pd);
+ kfree(domain1_pd);
#endif
printk(KERN_INFO PFX "Releasing master...\n");