examples/rtai/rtai_sample.c
changeset 233 31d327ce38d3
parent 230 382bdb9138ec
child 246 0bf7c769de06
equal deleted inserted replaced
232:f6594a07cdda 233:31d327ce38d3
    21  *  along with the IgH EtherCAT Master; if not, write to the Free Software
    21  *  along with the IgH EtherCAT Master; if not, write to the Free Software
    22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    23  *
    23  *
    24  *****************************************************************************/
    24  *****************************************************************************/
    25 
    25 
       
    26 // Linux
    26 #include <linux/module.h>
    27 #include <linux/module.h>
    27 #include <linux/delay.h>
       
    28 #include <linux/timer.h>
       
    29 #include <linux/interrupt.h>
       
    30 
    28 
    31 // RTAI
    29 // RTAI
    32 #include "rtai.h"
       
    33 #include "rtai_sched.h"
    30 #include "rtai_sched.h"
    34 #include "rtai_sem.h"
    31 #include "rtai_sem.h"
    35 
    32 
    36 // EtherCAT realtime interface
    33 // EtherCAT
    37 #include "../../include/ecrt.h"
    34 #include "../../include/ecrt.h"
    38 
    35 
    39 /*****************************************************************************/
    36 /*****************************************************************************/
    40 
    37 
    41 // comment this for synchronous IO
    38 // comment this for synchronous IO
    61 // data fields
    58 // data fields
    62 void *r_ssi_input;
    59 void *r_ssi_input;
    63 
    60 
    64 // channels
    61 // channels
    65 uint32_t k_pos;
    62 uint32_t k_pos;
    66 uint8_t k_stat;
       
    67 
    63 
    68 ec_field_init_t domain1_fields[] = {
    64 ec_field_init_t domain1_fields[] = {
    69     {&r_ssi_input, "3", "Beckhoff", "EL5001", "InputValue",   0},
    65     {&r_ssi_input, "3", "Beckhoff", "EL5001", "InputValue",   0},
    70     {NULL,         "2", "Beckhoff", "EL4132", "OutputValue",  0},
    66     {NULL,         "2", "Beckhoff", "EL4132", "OutputValue",  0},
    71     {}
    67     {}
   205 #ifdef ASYNC
   201 #ifdef ASYNC
   206     // send once and wait...
   202     // send once and wait...
   207     ecrt_master_prepare_async_io(master);
   203     ecrt_master_prepare_async_io(master);
   208 #endif
   204 #endif
   209 
   205 
   210 #if 1
       
   211     if (ecrt_master_start_eoe(master)) {
   206     if (ecrt_master_start_eoe(master)) {
   212         printk(KERN_ERR "Failed to start EoE processing!\n");
   207         printk(KERN_ERR "Failed to start EoE processing!\n");
   213         goto out_deactivate;
   208         goto out_deactivate;
   214     }
   209     }
   215 #endif
       
   216 
   210 
   217     printk("Starting cyclic sample thread...\n");
   211     printk("Starting cyclic sample thread...\n");
   218     requested_ticks = nano2count(TIMERTICKS);
   212     requested_ticks = nano2count(TIMERTICKS);
   219     tick_period = start_rt_timer(requested_ticks);
   213     tick_period = start_rt_timer(requested_ticks);
   220     printk(KERN_INFO "RT timer started with %i/%i ticks.\n",
   214     printk(KERN_INFO "RT timer started with %i/%i ticks.\n",
   251 
   245 
   252 void __exit cleanup_mod(void)
   246 void __exit cleanup_mod(void)
   253 {
   247 {
   254     printk(KERN_INFO "=== Stopping EtherCAT RTAI sample module... ===\n");
   248     printk(KERN_INFO "=== Stopping EtherCAT RTAI sample module... ===\n");
   255 
   249 
   256     printk(KERN_INFO "Stopping RT task...\n");
       
   257     rt_task_delete(&task);
   250     rt_task_delete(&task);
   258     stop_rt_timer();
   251     stop_rt_timer();
   259     printk(KERN_INFO "Deactivating EtherCAT master...\n");
       
   260     ecrt_master_deactivate(master);
   252     ecrt_master_deactivate(master);
   261     ecrt_release_master(master);
   253     ecrt_release_master(master);
   262     rt_sem_delete(&master_sem);
   254     rt_sem_delete(&master_sem);
   263 
   255 
   264     printk(KERN_INFO "=== EtherCAT RTAI sample module stopped. ===\n");
   256     printk(KERN_INFO "=== EtherCAT RTAI sample module stopped. ===\n");