mini/mini.c
changeset 195 674071846ee3
parent 156 43d7d714679f
child 197 b9a6e2c22745
equal deleted inserted replaced
194:c21e7c12dd50 195:674071846ee3
     1 /******************************************************************************
     1 /******************************************************************************
     2  *
     2  *
     3  *  m i n i . c
     3  *  m i n i . c
     4  *
     4  *
     5  *  Minimalmodul für EtherCAT
     5  *  Minimal module for EtherCAT.
     6  *
     6  *
     7  *  $Id$
     7  *  $Id$
     8  *
     8  *
     9  *****************************************************************************/
     9  *****************************************************************************/
    10 
    10 
    11 #include <linux/module.h>
    11 #include <linux/module.h>
    12 #include <linux/delay.h>
    12 #include <linux/delay.h>
    13 #include <linux/timer.h>
    13 #include <linux/timer.h>
    14 
    14 
    15 #include "../include/ecrt.h" // Echtzeitschnittstelle
    15 #include "../include/ecrt.h" // EtherCAT realtime interface
    16 
    16 
    17 #define ASYNC
    17 #define ASYNC
    18 
    18 #define FREQUENCY 100
    19 /*****************************************************************************/
    19 
    20 
    20 /*****************************************************************************/
    21 #define ABTASTFREQUENZ 100
       
    22 
    21 
    23 struct timer_list timer;
    22 struct timer_list timer;
    24 
       
    25 /*****************************************************************************/
       
    26 
    23 
    27 // EtherCAT
    24 // EtherCAT
    28 ec_master_t *master = NULL;
    25 ec_master_t *master = NULL;
    29 ec_domain_t *domain1 = NULL;
    26 ec_domain_t *domain1 = NULL;
    30 
    27 
    31 // Datenfelder
    28 // data fields
    32 //void *r_ssi_input, *r_ssi_status, *r_4102[3];
    29 //void *r_ssi_input, *r_ssi_status, *r_4102[3];
    33 
    30 
    34 // Kanäle
    31 // channels
    35 uint32_t k_pos;
    32 uint32_t k_pos;
    36 uint8_t k_stat;
    33 uint8_t k_stat;
    37 
    34 
    38 ec_field_init_t domain1_fields[] = {
    35 ec_field_init_t domain1_fields[] = {
    39     {NULL, "1", "Beckhoff", "EL5001", "InputValue", 0},
    36     {NULL, "1", "Beckhoff", "EL5001", "InputValue",   0},
    40     {NULL, "2", "Beckhoff", "EL4132", "OutputValue",  0},
    37     {NULL, "2", "Beckhoff", "EL4132", "OutputValue",  0},
    41     {}
    38     {}
    42 };
    39 };
    43 
    40 
    44 /*****************************************************************************/
    41 /*****************************************************************************/
    46 void run(unsigned long data)
    43 void run(unsigned long data)
    47 {
    44 {
    48     static unsigned int counter = 0;
    45     static unsigned int counter = 0;
    49 
    46 
    50 #ifdef ASYNC
    47 #ifdef ASYNC
    51     // Empfangen
    48     // receive
    52     ecrt_master_async_receive(master);
    49     ecrt_master_async_receive(master);
    53     ecrt_domain_process(domain1);
    50     ecrt_domain_process(domain1);
    54 #else
    51 #else
    55     // Senden und empfangen
    52     // send and receive
    56     ecrt_domain_queue(domain1);
    53     ecrt_domain_queue(domain1);
    57     ecrt_master_run(master);
    54     ecrt_master_run(master);
    58     ecrt_master_sync_io(master);
    55     ecrt_master_sync_io(master);
    59     ecrt_domain_process(domain1);
    56     ecrt_domain_process(domain1);
    60 #endif
    57 #endif
    61 
    58 
    62     // Prozessdaten verarbeiten
    59     // process data
    63     //k_pos = EC_READ_U32(r_ssi);
    60     //k_pos = EC_READ_U32(r_ssi);
    64 
    61 
    65 #ifdef ASYNC
    62 #ifdef ASYNC
    66     // Senden
    63     // send
    67     ecrt_domain_queue(domain1);
    64     ecrt_domain_queue(domain1);
    68     ecrt_master_run(master);
    65     ecrt_master_run(master);
    69     ecrt_master_async_send(master);
    66     ecrt_master_async_send(master);
    70 #endif
    67 #endif
    71 
    68 
    72     if (counter) {
    69     if (counter) {
    73         counter--;
    70         counter--;
    74     }
    71     }
    75     else {
    72     else {
    76         counter = ABTASTFREQUENZ;
    73         counter = FREQUENCY;
    77         //printk(KERN_INFO "k_pos    = %i\n", k_pos);
    74         //printk(KERN_INFO "k_pos    = %i\n", k_pos);
    78         //printk(KERN_INFO "k_stat   = 0x%02X\n", k_stat);
    75         //printk(KERN_INFO "k_stat   = 0x%02X\n", k_stat);
    79     }
    76     }
    80 
    77 
    81     // Timer neu starten
    78     // restart timer
    82     timer.expires += HZ / ABTASTFREQUENZ;
    79     timer.expires += HZ / FREQUENCY;
    83     add_timer(&timer);
    80     add_timer(&timer);
    84 }
    81 }
    85 
    82 
    86 /*****************************************************************************/
    83 /*****************************************************************************/
    87 
    84 
   151         goto out_deactivate;
   148         goto out_deactivate;
   152     }
   149     }
   153 #endif
   150 #endif
   154 
   151 
   155 #ifdef ASYNC
   152 #ifdef ASYNC
   156     // Einmal senden und warten...
   153     // send once and wait...
   157     ecrt_master_prepare_async_io(master);
   154     ecrt_master_prepare_async_io(master);
   158 #endif
   155 #endif
   159 
   156 
   160     printk("Starting cyclic sample thread.\n");
   157     printk("Starting cyclic sample thread.\n");
   161     init_timer(&timer);
   158     init_timer(&timer);
   162     timer.function = run;
   159     timer.function = run;
   163     timer.expires = jiffies + 10; // Das erste Mal sofort feuern
   160     timer.expires = jiffies + 10;
   164     add_timer(&timer);
   161     add_timer(&timer);
   165 
   162 
   166     printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
   163     printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
   167     return 0;
   164     return 0;
   168 
   165 
   201 module_init(init_mini_module);
   198 module_init(init_mini_module);
   202 module_exit(cleanup_mini_module);
   199 module_exit(cleanup_mini_module);
   203 
   200 
   204 /*****************************************************************************/
   201 /*****************************************************************************/
   205 
   202 
   206 /* Emacs-Konfiguration
       
   207 ;;; Local Variables: ***
       
   208 ;;; c-basic-offset:4 ***
       
   209 ;;; End: ***
       
   210 */