91 { |
91 { |
92 const ec_pdo_t *pdo; |
92 const ec_pdo_t *pdo; |
93 const ec_pdo_entry_t *pdo_entry; |
93 const ec_pdo_entry_t *pdo_entry; |
94 unsigned int bit_size, byte_size; |
94 unsigned int bit_size, byte_size; |
95 |
95 |
96 if (sync->length) return sync->length; |
96 // if an estimated length is specified, return it |
97 if (sync->est_length) return sync->est_length; |
97 if (sync->est_length) |
98 |
98 return sync->est_length; |
|
99 |
|
100 // calculate total Pdo size in bit |
99 bit_size = 0; |
101 bit_size = 0; |
100 list_for_each_entry(pdo, &sync->pdos, list) { |
102 list_for_each_entry(pdo, &sync->pdos, list) { |
101 list_for_each_entry(pdo_entry, &pdo->entries, list) { |
103 list_for_each_entry(pdo_entry, &pdo->entries, list) { |
102 bit_size += pdo_entry->bit_length; |
104 bit_size += pdo_entry->bit_length; |
103 } |
105 } |
104 } |
106 } |
105 |
107 |
106 if (bit_size % 8) // round up to full bytes |
108 // bits to bytes |
|
109 if (bit_size % 8) { |
|
110 // round up to full bytes |
107 byte_size = bit_size / 8 + 1; |
111 byte_size = bit_size / 8 + 1; |
108 else |
112 } else { |
109 byte_size = bit_size / 8; |
113 byte_size = bit_size / 8; |
110 |
114 } |
111 return byte_size; |
115 |
|
116 if (byte_size) { |
|
117 // return total Pdo size, if there are Pdos assigned |
|
118 return byte_size; |
|
119 } else { |
|
120 // return sync manager default size, if no Pdos are assigned |
|
121 return sync->length; |
|
122 } |
112 } |
123 } |
113 |
124 |
114 /*****************************************************************************/ |
125 /*****************************************************************************/ |
115 |
126 |
116 /** |
127 /** |
124 ) |
135 ) |
125 { |
136 { |
126 size_t sync_size = ec_sync_size(sync); |
137 size_t sync_size = ec_sync_size(sync); |
127 |
138 |
128 if (sync->slave->master->debug_level) { |
139 if (sync->slave->master->debug_level) { |
129 EC_DBG("SM%i: Addr 0x%04X, Size %3i, Ctrl 0x%02X, En %i\n", |
140 EC_DBG("SM%u: Addr 0x%04X, Size %3u, Ctrl 0x%02X, En %u\n", |
130 sync->index, sync->physical_start_address, |
141 sync->index, sync->physical_start_address, |
131 sync_size, sync->control_register, sync->enable); |
142 sync_size, sync->control_register, sync->enable); |
132 } |
143 } |
133 |
144 |
134 EC_WRITE_U16(data, sync->physical_start_address); |
145 EC_WRITE_U16(data, sync->physical_start_address); |