etherlab/plc_etherlab.c
changeset 2032 766078d83e22
parent 2028 5132c497918c
child 2036 7c31fab22c74
equal deleted inserted replaced
2031:c6f32810723e 2032:766078d83e22
     1 /*
     1 /*
     2  * Etherlab Asynchronous execution code
     2  * Etherlab execution code
     3  *
     3  *
     4  * */
     4  * */
     5 
     5 
     6 #include <rtdm/rtdm.h>
     6 #include <rtdm/rtdm.h>
     7 #include <native/task.h>
     7 #include <native/task.h>
    21 
    21 
    22 // Optional features
    22 // Optional features
    23 #define CONFIGURE_PDOS  %(configure_pdos)d
    23 #define CONFIGURE_PDOS  %(configure_pdos)d
    24 
    24 
    25 // process data
    25 // process data
    26 static uint8_t *domain1_pd = NULL;
    26 uint8_t *domain1_pd = NULL;
    27 %(used_pdo_entry_offset_variables_declaration)s
    27 %(used_pdo_entry_offset_variables_declaration)s
    28 
    28 
    29 const static ec_pdo_entry_reg_t domain1_regs[] = {
    29 const static ec_pdo_entry_reg_t domain1_regs[] = {
    30 %(used_pdo_entry_configuration)s
    30 %(used_pdo_entry_configuration)s
    31     {}
    31     {}
    47 %(slaves_declaration)s
    47 %(slaves_declaration)s
    48 
    48 
    49 /* Beremiz plugin functions */
    49 /* Beremiz plugin functions */
    50 int __init_%(location)s(int argc,char **argv)
    50 int __init_%(location)s(int argc,char **argv)
    51 {
    51 {
    52 	int rtstatus;
    52     uint32_t abort_code;
    53 
    53     int rtstatus;
       
    54     
    54 	MstrAttach.masterindex = %(master_number)d;
    55 	MstrAttach.masterindex = %(master_number)d;
    55 
    56 
    56 	master = ecrt_request_master(MstrAttach.masterindex);
    57 	master = ecrt_request_master(MstrAttach.masterindex);
    57 	if (!master) return -1;
    58 	if (!master) return -1;
    58 
    59 
    59 	domain1 = ecrt_master_create_domain(master);
    60 	domain1 = ecrt_master_create_domain(master);
    60 	if (!domain1) return -1;
    61 	if (!domain1) return -1;
    61 
    62 
    62 #if CONFIGURE_PDOS
    63 #if CONFIGURE_PDOS
       
    64     fprintf(stdout, "Configure PDOs...\n");
    63 	%(slaves_configuration)s
    65 	%(slaves_configuration)s
    64 #endif
    66 #endif
    65 
    67 
    66     if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
    68     if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
    67         fprintf(stderr, "PDO entry registration failed!\n");
    69         fprintf(stderr, "PDO entry registration failed!\n");
    68         return -1;
    70         return -1;
    69     }
    71     }
    70 
    72 
       
    73 %(slaves_initialization)s
       
    74 
    71     sprintf(&rt_dev_file[0],"%%s%%u",EC_RTDM_DEV_FILE_NAME,0);
    75     sprintf(&rt_dev_file[0],"%%s%%u",EC_RTDM_DEV_FILE_NAME,0);
    72     rt_fd = rt_dev_open( &rt_dev_file[0], 0);
    76     rt_fd = rt_dev_open( &rt_dev_file[0], 0);
    73     if (rt_fd < 0) {
    77     if (rt_fd < 0) {
    74         printf("Can't open %%s\n", &rt_dev_file[0]);
    78         fprintf(stderr, "Can't open %%s\n", &rt_dev_file[0]);
    75         return -1;
    79         return -1;
    76     }
    80     }
    77 
    81 
    78     // attach the master over rtdm driver
    82     // attach the master over rtdm driver
    79     MstrAttach.domainindex = ecrt_domain_index(domain1);
    83     MstrAttach.domainindex = ecrt_domain_index(domain1);
    80     rtstatus = ecrt_rtdm_master_attach(rt_fd, &MstrAttach);
    84     rtstatus = ecrt_rtdm_master_attach(rt_fd, &MstrAttach);
    81     if (rtstatus < 0) {
    85     if (rtstatus < 0) {
    82         printf("Cannot attach to master over rtdm\n");
    86         fprintf(stderr, "Cannot attach to master over rtdm\n");
    83         return -1;
    87         return -1;
    84     }
    88     }
    85 
    89 
    86     if (ecrt_master_activate(master))
    90     if (ecrt_master_activate(master))
    87         return -1;
    91         return -1;
    90         fprintf(stderr, "domain1_pd:  0x%%.6lx\n", (unsigned long)domain1_pd);
    94         fprintf(stderr, "domain1_pd:  0x%%.6lx\n", (unsigned long)domain1_pd);
    91         return -1;
    95         return -1;
    92     }
    96     }
    93 
    97 
    94     fprintf(stdout, "Master %(master_number)d activated...\n");
    98     fprintf(stdout, "Master %(master_number)d activated...\n");
       
    99      
    95     return 0;
   100     return 0;
    96 }
   101 }
    97 
   102 
    98 void __cleanup_%(location)s(void)
   103 void __cleanup_%(location)s(void)
    99 {
   104 {