45 int __init_%(location)s(int argc,char **argv) |
45 int __init_%(location)s(int argc,char **argv) |
46 { |
46 { |
47 uint32_t abort_code; |
47 uint32_t abort_code; |
48 size_t result_size; |
48 size_t result_size; |
49 |
49 |
50 master = ecrt_request_master(%(master_number)d); |
50 master = ecrt_request_master(%(master_number)d); |
51 if (!master) return -1; |
51 if (!master) { |
|
52 SLOGF(LOG_CRITICAL, "EtherCAT master request failed!"); |
|
53 return -1; |
|
54 } |
52 |
55 |
53 domain1 = ecrt_master_create_domain(master); |
56 if(!(domain1 = ecrt_master_create_domain(master))){ |
54 if (!domain1) return -1; |
57 SLOGF(LOG_CRITICAL, "EtherCAT Domain Creation failed!"); |
|
58 goto ecat_failed; |
|
59 } |
55 |
60 |
56 // slaves PDO configuration |
61 // slaves PDO configuration |
57 %(slaves_configuration)s |
62 %(slaves_configuration)s |
58 |
63 |
59 if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { |
64 if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { |
60 SLOGF(LOG_CRITICAL, "PDO entry registration failed!\n"); |
65 SLOGF(LOG_CRITICAL, "EtherCAT PDO registration failed!"); |
61 return -1; |
66 goto ecat_failed; |
62 } |
67 } |
63 |
68 |
64 ecrt_master_set_send_interval(master, common_ticktime__); |
69 ecrt_master_set_send_interval(master, common_ticktime__); |
65 |
70 |
66 // slaves initialization |
71 // slaves initialization |
67 %(slaves_initialization)s |
72 %(slaves_initialization)s |
68 |
73 |
69 // extracting default value for not mapped entry in output PDOs |
74 // extracting default value for not mapped entry in output PDOs |
70 %(slaves_output_pdos_default_values_extraction)s |
75 %(slaves_output_pdos_default_values_extraction)s |
71 |
76 |
72 if (ecrt_master_activate(master)) |
77 if (ecrt_master_activate(master)){ |
73 return -1; |
78 SLOGF(LOG_CRITICAL, "EtherCAT Master activation failed"); |
|
79 goto ecat_failed; |
|
80 } |
74 |
81 |
75 if (!(domain1_pd = ecrt_domain_data(domain1))) { |
82 if (!(domain1_pd = ecrt_domain_data(domain1))) { |
76 SLOGF(LOG_CRITICAL, "domain1_pd: 0x%%.6lx\n", (unsigned long)domain1_pd); |
83 SLOGF(LOG_CRITICAL, "Failed to map EtherCAT process data"); |
77 return -1; |
84 goto ecat_failed; |
78 } |
85 } |
79 |
86 |
80 SLOGF(LOG_INFO, "Master %(master_number)d activated...\n"); |
87 SLOGF(LOG_INFO, "Master %(master_number)d activated."); |
81 |
88 |
82 first_sent = 0; |
89 first_sent = 0; |
83 |
90 |
84 return 0; |
91 return 0; |
|
92 |
|
93 ecat_failed: |
|
94 ecrt_release_master(master); |
|
95 return -1; |
|
96 |
85 } |
97 } |
86 |
98 |
87 void __cleanup_%(location)s(void) |
99 void __cleanup_%(location)s(void) |
88 { |
100 { |
89 //release master |
101 //release master |
90 ecrt_release_master(master); |
102 ecrt_release_master(master); |
91 first_sent = 0; |
103 first_sent = 0; |
92 } |
104 } |
93 |
105 |
94 void __retrieve_%(location)s(void) |
106 void __retrieve_%(location)s(void) |
95 { |
107 { |