mini/mini.c
changeset 135 80d493917205
parent 130 69c2645300ee
child 138 7e743a61a991
equal deleted inserted replaced
134:aecc8cb72097 135:80d493917205
    92 int __init init_mini_module(void)
    92 int __init init_mini_module(void)
    93 {
    93 {
    94     printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
    94     printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
    95 
    95 
    96     if ((master = ecrt_request_master(0)) == NULL) {
    96     if ((master = ecrt_request_master(0)) == NULL) {
    97         printk(KERN_ERR "Error requesting master 0!\n");
    97         printk(KERN_ERR "Requesting master 0 failed!\n");
    98         goto out_return;
    98         goto out_return;
    99     }
    99     }
   100 
   100 
   101     ecrt_master_print(master);
   101     ecrt_master_print(master);
   102 
   102 
   103     printk(KERN_INFO "Registering domain...\n");
   103     printk(KERN_INFO "Registering domain...\n");
   104 
   104 
   105     if (!(domain1 = ecrt_master_create_domain(master)))
   105     if (!(domain1 = ecrt_master_create_domain(master)))
   106     {
   106     {
   107         printk(KERN_ERR "EtherCAT: Could not register domain!\n");
   107         printk(KERN_ERR "Domain creation failed!\n");
   108         goto out_release_master;
   108         goto out_release_master;
   109     }
   109     }
   110 
   110 
   111     printk(KERN_INFO "Registering domain fields...\n");
   111     printk(KERN_INFO "Registering domain fields...\n");
   112 
   112 
   113     if (ecrt_domain_register_field_list(domain1, domain1_fields)) {
   113     if (ecrt_domain_register_field_list(domain1, domain1_fields)) {
   114         printk(KERN_ERR "EtherCAT: Could not register field!\n");
   114         printk(KERN_ERR "Field registration failed!\n");
   115         goto out_release_master;
   115         goto out_release_master;
   116     }
   116     }
   117 
   117 
   118     printk(KERN_INFO "Activating master...\n");
   118     printk(KERN_INFO "Activating master...\n");
   119 
   119 
   120     if (ecrt_master_activate(master)) {
   120     if (ecrt_master_activate(master)) {
   121         printk(KERN_ERR "EtherCAT: Could not activate master!\n");
   121         printk(KERN_ERR "Failed to activate master!\n");
   122         goto out_release_master;
   122         goto out_release_master;
       
   123     }
       
   124 
       
   125     if (ecrt_master_fetch_sdo_lists(master)) {
       
   126         printk(KERN_ERR "Failed to fetch SDO lists!\n");
       
   127         goto out_deactivate;
   123     }
   128     }
   124 
   129 
   125     //ecrt_master_debug(master, 2);
   130     //ecrt_master_debug(master, 2);
   126 
   131 
   127 #if 0
   132 #if 0
   132         ecrt_master_sdo_write(master, "1", 0x4067, 0,  4, 1) ||
   137         ecrt_master_sdo_write(master, "1", 0x4067, 0,  4, 1) ||
   133         ecrt_master_sdo_write(master, "1", 0x4068, 0,  0, 1) ||
   138         ecrt_master_sdo_write(master, "1", 0x4068, 0,  0, 1) ||
   134         ecrt_master_sdo_write(master, "1", 0x4069, 0, 25, 1) ||
   139         ecrt_master_sdo_write(master, "1", 0x4069, 0, 25, 1) ||
   135         ecrt_master_sdo_write(master, "1", 0x406A, 0, 25, 1) ||
   140         ecrt_master_sdo_write(master, "1", 0x406A, 0, 25, 1) ||
   136         ecrt_master_sdo_write(master, "1", 0x406B, 0, 50, 1)) {
   141         ecrt_master_sdo_write(master, "1", 0x406B, 0, 50, 1)) {
   137         printk(KERN_ERR "EtherCAT: Failed to configure SSI!\n");
   142         printk(KERN_ERR "Failed to configure SSI slave!\n");
   138         goto out_deactivate;
   143         goto out_deactivate;
   139     }
   144     }
   140 #endif
   145 #endif
   141 
   146 
   142     //ecrt_master_debug(master, 0);
   147     //ecrt_master_debug(master, 0);
   143 
   148 
   144 #if 0
   149 #if 0
   145     printk(KERN_INFO "Writing alias...\n");
   150     printk(KERN_INFO "Writing alias...\n");
   146     if (ecrt_master_write_slave_alias(master, "0", 0xBEEF)) {
   151     if (ecrt_master_write_slave_alias(master, "0", 0xBEEF)) {
   147         printk(KERN_ERR "EtherCAT: Failed to write alias!\n");
   152         printk(KERN_ERR "Failed to write alias!\n");
   148         goto out_deactivate;
   153         goto out_deactivate;
   149     }
   154     }
   150 #endif
   155 #endif
   151 
   156 
   152 #ifdef ASYNC
   157 #ifdef ASYNC
   160     timer.function = run;
   165     timer.function = run;
   161     timer.expires = jiffies + 10; // Das erste Mal sofort feuern
   166     timer.expires = jiffies + 10; // Das erste Mal sofort feuern
   162     add_timer(&timer);
   167     add_timer(&timer);
   163 
   168 
   164     printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
   169     printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
   165 
       
   166     return 0;
   170     return 0;
   167 
   171 
   168 #if 0
       
   169  out_deactivate:
   172  out_deactivate:
   170     ecrt_master_deactivate(master);
   173     ecrt_master_deactivate(master);
   171 #endif
       
   172 
       
   173  out_release_master:
   174  out_release_master:
   174     ecrt_release_master(master);
   175     ecrt_release_master(master);
   175 
       
   176  out_return:
   176  out_return:
   177     return -1;
   177     return -1;
   178 }
   178 }
   179 
   179 
   180 /*****************************************************************************/
   180 /*****************************************************************************/
   181 
   181 
   182 void __exit cleanup_mini_module(void)
   182 void __exit cleanup_mini_module(void)
   183 {
   183 {
   184     printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
   184     printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
   185 
   185 
   186     if (master)
   186     if (master) {
   187     {
       
   188         del_timer_sync(&timer);
   187         del_timer_sync(&timer);
   189 
       
   190         printk(KERN_INFO "Deactivating master...\n");
   188         printk(KERN_INFO "Deactivating master...\n");
   191 
       
   192         ecrt_master_deactivate(master);
   189         ecrt_master_deactivate(master);
   193         ecrt_release_master(master);
   190         ecrt_release_master(master);
   194     }
   191     }
   195 
   192 
   196     printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");
   193     printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");