merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
This commit is contained in:
parent
5d4b915317
commit
40ee89a77f
|
|
@ -146,7 +146,7 @@ int ec_eoe_init(
|
|||
// so the MTU is left on the Ethernet standard value and fragmenting
|
||||
// is done "manually".
|
||||
#if 0
|
||||
eoe->dev->mtu = slave->sii.rx_mailbox_size - ETH_HLEN - 10;
|
||||
eoe->dev->mtu = slave->configured_rx_mailbox_size - ETH_HLEN - 10;
|
||||
#endif
|
||||
|
||||
// connect the net_device to the kernel
|
||||
|
|
@ -232,11 +232,11 @@ int ec_eoe_send(ec_eoe_t *eoe /**< EoE handler */)
|
|||
|
||||
remaining_size = eoe->tx_frame->skb->len - eoe->tx_offset;
|
||||
|
||||
if (remaining_size <= eoe->slave->sii.std_tx_mailbox_size - 10) {
|
||||
if (remaining_size <= eoe->slave->configured_tx_mailbox_size - 10) {
|
||||
current_size = remaining_size;
|
||||
last_fragment = 1;
|
||||
} else {
|
||||
current_size = ((eoe->slave->sii.std_tx_mailbox_size - 10) / 32) * 32;
|
||||
current_size = ((eoe->slave->configured_tx_mailbox_size - 10) / 32) * 32;
|
||||
last_fragment = 0;
|
||||
}
|
||||
|
||||
|
|
@ -698,7 +698,7 @@ int ec_eoedev_tx(struct sk_buff *skb, /**< transmit socket buffer */
|
|||
ec_eoe_frame_t *frame;
|
||||
|
||||
#if 0
|
||||
if (skb->len > eoe->slave->sii.tx_mailbox_size - 10) {
|
||||
if (skb->len > eoe->slave->configured_tx_mailbox_size - 10) {
|
||||
EC_WARN("EoE TX frame (%u octets) exceeds MTU. dropping.\n", skb->len);
|
||||
dev_kfree_skb(skb);
|
||||
eoe->stats.tx_dropped++;
|
||||
|
|
|
|||
|
|
@ -1095,7 +1095,7 @@ void ec_fsm_coe_down_start(ec_fsm_coe_t *fsm /**< finite state machine */)
|
|||
}
|
||||
}
|
||||
else { // request->data_size > 4, use normal transfer type
|
||||
if (slave->sii.std_rx_mailbox_size < 6 + 10 + request->data_size) {
|
||||
if (slave->configured_rx_mailbox_size < 6 + 10 + request->data_size) {
|
||||
EC_ERR("SDO fragmenting not supported yet!\n");
|
||||
fsm->state = ec_fsm_coe_error;
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -214,12 +214,12 @@ int ec_foe_prepare_data_send( ec_fsm_foe_t *fsm ) {
|
|||
|
||||
remaining_size = fsm->tx_buffer_size - fsm->tx_buffer_offset;
|
||||
|
||||
if (remaining_size < fsm->slave->sii.std_tx_mailbox_size
|
||||
if (remaining_size < fsm->slave->configured_tx_mailbox_size
|
||||
- EC_MBOX_HEADER_SIZE - EC_FOE_HEADER_SIZE) {
|
||||
current_size = remaining_size;
|
||||
fsm->tx_last_packet = 1;
|
||||
} else {
|
||||
current_size = fsm->slave->sii.std_tx_mailbox_size
|
||||
current_size = fsm->slave->configured_tx_mailbox_size
|
||||
- EC_MBOX_HEADER_SIZE - EC_FOE_HEADER_SIZE;
|
||||
}
|
||||
|
||||
|
|
@ -789,10 +789,10 @@ void ec_fsm_foe_state_data_read ( ec_fsm_foe_t *fsm ) {
|
|||
|
||||
fsm->rx_last_packet =
|
||||
(rec_size + EC_MBOX_HEADER_SIZE + EC_FOE_HEADER_SIZE
|
||||
!= fsm->slave->sii.std_rx_mailbox_size);
|
||||
!= fsm->slave->configured_rx_mailbox_size);
|
||||
|
||||
if (fsm->rx_last_packet ||
|
||||
(slave->sii.std_rx_mailbox_size - EC_MBOX_HEADER_SIZE
|
||||
(slave->configured_rx_mailbox_size - EC_MBOX_HEADER_SIZE
|
||||
- EC_FOE_HEADER_SIZE + fsm->rx_buffer_offset) <= fsm->rx_buffer_size) {
|
||||
// either it was the last packet or a new packet will fit into the delivered buffer
|
||||
#ifdef myDEBUG
|
||||
|
|
@ -812,7 +812,7 @@ void ec_fsm_foe_state_data_read ( ec_fsm_foe_t *fsm ) {
|
|||
printk (" rx_buffer_size = %d\n", fsm->rx_buffer_size);
|
||||
printk (" rx_buffer_offset= %d\n", fsm->rx_buffer_offset);
|
||||
printk (" rec_size = %d\n", rec_size);
|
||||
printk (" rx_mailbox_size = %d\n", slave->sii.std_rx_mailbox_size);
|
||||
printk (" rx_mailbox_size = %d\n", slave->configured_rx_mailbox_size);
|
||||
printk (" rx_last_packet = %d\n", fsm->rx_last_packet);
|
||||
// fsm->state = ec_fsm_state_wait_next_read;
|
||||
fsm->request->result = FOE_READY;
|
||||
|
|
|
|||
|
|
@ -225,8 +225,8 @@ void ec_fsm_pdo_read_state_pdo_count(
|
|||
if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
|
||||
|
||||
if (!ec_fsm_coe_success(fsm->fsm_coe)) {
|
||||
EC_ERR("Failed to read number of assigned PDOs for SM%u.\n",
|
||||
fsm->sync_index);
|
||||
EC_ERR("Failed to read number of assigned PDOs for SM%u"
|
||||
" of slave %u.\n", fsm->sync_index, fsm->slave->ring_position);
|
||||
fsm->state = ec_fsm_pdo_state_error;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -312,6 +312,10 @@ void ec_fsm_slave_config_enter_mbox_sync(
|
|||
ec_sync_page(&sync, 0, slave->sii.boot_rx_mailbox_size,
|
||||
EC_DIR_INVALID, // use default direction
|
||||
datagram->data);
|
||||
slave->configured_rx_mailbox_offset =
|
||||
slave->sii.boot_rx_mailbox_offset;
|
||||
slave->configured_rx_mailbox_size =
|
||||
slave->sii.boot_rx_mailbox_size;
|
||||
|
||||
ec_sync_init(&sync, slave);
|
||||
sync.physical_start_address = slave->sii.boot_tx_mailbox_offset;
|
||||
|
|
@ -320,6 +324,11 @@ void ec_fsm_slave_config_enter_mbox_sync(
|
|||
ec_sync_page(&sync, 1, slave->sii.boot_tx_mailbox_size,
|
||||
EC_DIR_INVALID, // use default direction
|
||||
datagram->data + EC_SYNC_PAGE_SIZE);
|
||||
slave->configured_tx_mailbox_offset =
|
||||
slave->sii.boot_tx_mailbox_offset;
|
||||
slave->configured_tx_mailbox_size =
|
||||
slave->sii.boot_tx_mailbox_size;
|
||||
|
||||
} else if (slave->sii.sync_count >= 2) { // mailbox configuration provided
|
||||
ec_datagram_fpwr(datagram, slave->station_address, 0x0800,
|
||||
EC_SYNC_PAGE_SIZE * slave->sii.sync_count);
|
||||
|
|
@ -331,6 +340,15 @@ void ec_fsm_slave_config_enter_mbox_sync(
|
|||
EC_DIR_INVALID, // use default direction
|
||||
datagram->data + EC_SYNC_PAGE_SIZE * i);
|
||||
}
|
||||
|
||||
slave->configured_rx_mailbox_offset =
|
||||
slave->sii.syncs[0].physical_start_address;
|
||||
slave->configured_rx_mailbox_size =
|
||||
slave->sii.syncs[0].default_length;
|
||||
slave->configured_tx_mailbox_offset =
|
||||
slave->sii.syncs[1].physical_start_address;
|
||||
slave->configured_tx_mailbox_size =
|
||||
slave->sii.syncs[1].default_length;
|
||||
} else { // no mailbox sync manager configurations provided
|
||||
ec_sync_t sync;
|
||||
|
||||
|
|
@ -350,6 +368,10 @@ void ec_fsm_slave_config_enter_mbox_sync(
|
|||
ec_sync_page(&sync, 0, slave->sii.std_rx_mailbox_size,
|
||||
EC_DIR_INVALID, // use default direction
|
||||
datagram->data);
|
||||
slave->configured_rx_mailbox_offset =
|
||||
slave->sii.std_rx_mailbox_offset;
|
||||
slave->configured_rx_mailbox_size =
|
||||
slave->sii.std_rx_mailbox_size;
|
||||
|
||||
ec_sync_init(&sync, slave);
|
||||
sync.physical_start_address = slave->sii.std_tx_mailbox_offset;
|
||||
|
|
@ -358,6 +380,10 @@ void ec_fsm_slave_config_enter_mbox_sync(
|
|||
ec_sync_page(&sync, 1, slave->sii.std_tx_mailbox_size,
|
||||
EC_DIR_INVALID, // use default direction
|
||||
datagram->data + EC_SYNC_PAGE_SIZE);
|
||||
slave->configured_tx_mailbox_offset =
|
||||
slave->sii.boot_tx_mailbox_offset;
|
||||
slave->configured_tx_mailbox_size =
|
||||
slave->sii.boot_tx_mailbox_size;
|
||||
}
|
||||
|
||||
fsm->retries = EC_FSM_RETRIES;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *);
|
|||
void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *);
|
||||
void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *);
|
||||
void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *);
|
||||
void ec_fsm_slave_scan_state_sync(ec_fsm_slave_scan_t *);
|
||||
void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *);
|
||||
|
||||
void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *);
|
||||
|
|
@ -589,17 +590,33 @@ void ec_fsm_slave_scan_enter_preop(
|
|||
)
|
||||
{
|
||||
ec_slave_t *slave = fsm->slave;
|
||||
uint8_t current_state = slave->current_state & EC_SLAVE_STATE_MASK;
|
||||
|
||||
if (current_state != EC_SLAVE_STATE_PREOP
|
||||
&& current_state != EC_SLAVE_STATE_SAFEOP
|
||||
&& current_state != EC_SLAVE_STATE_OP) {
|
||||
if (slave->master->debug_level) {
|
||||
char str[EC_STATE_STRING_SIZE];
|
||||
ec_state_string(current_state, str, 0);
|
||||
EC_DBG("Slave %u is not in the state to do mailbox com (%s),"
|
||||
" setting to PREOP.\n", slave->ring_position, str);
|
||||
}
|
||||
|
||||
if ((slave->current_state & EC_SLAVE_STATE_MASK) < EC_SLAVE_STATE_PREOP) {
|
||||
if (slave->master->debug_level)
|
||||
EC_DBG("Slave %u is not in the state to do mailbox com, setting"
|
||||
" to PREOP.\n", slave->ring_position);
|
||||
fsm->state = ec_fsm_slave_scan_state_preop;
|
||||
ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
|
||||
ec_fsm_slave_config_start(fsm->fsm_slave_config, slave);
|
||||
ec_fsm_slave_config_exec(fsm->fsm_slave_config);
|
||||
} else {
|
||||
ec_fsm_slave_scan_enter_pdos(fsm);
|
||||
if (slave->master->debug_level)
|
||||
EC_DBG("Reading mailbox syncmanager configuration of slave %u.\n",
|
||||
slave->ring_position);
|
||||
|
||||
/* Scan current sync manager configuration to get configured mailbox
|
||||
* sizes. */
|
||||
ec_datagram_fprd(fsm->datagram, slave->station_address, 0x0800,
|
||||
EC_SYNC_PAGE_SIZE * 2);
|
||||
fsm->retries = EC_FSM_RETRIES;
|
||||
fsm->state = ec_fsm_slave_scan_state_sync;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -624,6 +641,55 @@ void ec_fsm_slave_scan_state_preop(
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Slave scan state: SYNC.
|
||||
*/
|
||||
void ec_fsm_slave_scan_state_sync(
|
||||
ec_fsm_slave_scan_t *fsm /**< slave state machine */
|
||||
)
|
||||
{
|
||||
ec_datagram_t *datagram = fsm->datagram;
|
||||
ec_slave_t *slave = fsm->slave;
|
||||
|
||||
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
|
||||
return;
|
||||
|
||||
if (datagram->state != EC_DATAGRAM_RECEIVED) {
|
||||
fsm->state = ec_fsm_slave_scan_state_error;
|
||||
EC_ERR("Failed to receive sync manager configuration datagram"
|
||||
" from slave %u (datagram state %u).\n",
|
||||
slave->ring_position, datagram->state);
|
||||
return;
|
||||
}
|
||||
|
||||
if (datagram->working_counter != 1) {
|
||||
fsm->slave->error_flag = 1;
|
||||
fsm->state = ec_fsm_slave_scan_state_error;
|
||||
EC_ERR("Failed to read DL status from slave %u: ",
|
||||
slave->ring_position);
|
||||
ec_datagram_print_wc_error(datagram);
|
||||
return;
|
||||
}
|
||||
|
||||
slave->configured_rx_mailbox_offset = EC_READ_U16(datagram->data);
|
||||
slave->configured_rx_mailbox_size = EC_READ_U16(datagram->data + 2);
|
||||
slave->configured_tx_mailbox_offset = EC_READ_U16(datagram->data + 8);
|
||||
slave->configured_tx_mailbox_size = EC_READ_U16(datagram->data + 10);
|
||||
|
||||
if (slave->master->debug_level) {
|
||||
EC_DBG("Mailbox configuration of slave %u:\n", slave->ring_position);
|
||||
EC_DBG(" RX offset=0x%04x size=%u\n",
|
||||
slave->configured_rx_mailbox_offset,
|
||||
slave->configured_rx_mailbox_size);
|
||||
EC_DBG(" TX offset=0x%04x size=%u\n",
|
||||
slave->configured_tx_mailbox_offset,
|
||||
slave->configured_tx_mailbox_size);
|
||||
}
|
||||
|
||||
ec_fsm_slave_scan_enter_pdos(fsm);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Enter slave scan state PDOS.
|
||||
*/
|
||||
void ec_fsm_slave_scan_enter_pdos(
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *slave, /**< slave */
|
|||
{
|
||||
size_t total_size;
|
||||
int ret;
|
||||
uint16_t mailbox_offset, mailbox_size;
|
||||
|
||||
if (unlikely(!slave->sii.mailbox_protocols)) {
|
||||
EC_ERR("Slave %u does not support mailbox communication!\n",
|
||||
|
|
@ -63,21 +62,15 @@ uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *slave, /**< slave */
|
|||
|
||||
total_size = EC_MBOX_HEADER_SIZE + size;
|
||||
|
||||
if (slave->current_state != EC_SLAVE_STATE_BOOT) {
|
||||
mailbox_offset = slave->sii.std_rx_mailbox_offset;
|
||||
mailbox_size = slave->sii.std_rx_mailbox_size;
|
||||
} else {
|
||||
mailbox_offset = slave->sii.boot_rx_mailbox_offset;
|
||||
mailbox_size = slave->sii.boot_rx_mailbox_size;
|
||||
}
|
||||
|
||||
if (unlikely(total_size > mailbox_size)) {
|
||||
EC_ERR("Data size does not fit in mailbox!\n");
|
||||
if (unlikely(total_size > slave->configured_rx_mailbox_size)) {
|
||||
EC_ERR("Data size (%u) does not fit in mailbox (%u)!\n",
|
||||
total_size, slave->configured_rx_mailbox_size);
|
||||
return ERR_PTR(-EOVERFLOW);
|
||||
}
|
||||
|
||||
ret = ec_datagram_fpwr(datagram, slave->station_address,
|
||||
mailbox_offset, mailbox_size);
|
||||
slave->configured_rx_mailbox_offset,
|
||||
slave->configured_rx_mailbox_size);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
|
||||
|
|
@ -132,19 +125,9 @@ int ec_slave_mbox_prepare_fetch(const ec_slave_t *slave, /**< slave */
|
|||
ec_datagram_t *datagram /**< datagram */
|
||||
)
|
||||
{
|
||||
int ret;
|
||||
uint16_t mailbox_offset, mailbox_size;
|
||||
|
||||
if (slave->current_state != EC_SLAVE_STATE_BOOT) {
|
||||
mailbox_offset = slave->sii.std_tx_mailbox_offset;
|
||||
mailbox_size = slave->sii.std_tx_mailbox_size;
|
||||
} else {
|
||||
mailbox_offset = slave->sii.boot_tx_mailbox_offset;
|
||||
mailbox_size = slave->sii.boot_tx_mailbox_size;
|
||||
}
|
||||
|
||||
ret = ec_datagram_fprd(datagram, slave->station_address,
|
||||
mailbox_offset, mailbox_size);
|
||||
int ret = ec_datagram_fprd(datagram, slave->station_address,
|
||||
slave->configured_tx_mailbox_offset,
|
||||
slave->configured_tx_mailbox_size);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
|
@ -183,22 +166,13 @@ uint8_t *ec_slave_mbox_fetch(const ec_slave_t *slave, /**< slave */
|
|||
)
|
||||
{
|
||||
size_t data_size;
|
||||
uint16_t mailbox_offset, mailbox_size;
|
||||
|
||||
if (slave->current_state != EC_SLAVE_STATE_BOOT) {
|
||||
mailbox_offset = slave->sii.std_tx_mailbox_offset;
|
||||
mailbox_size = slave->sii.std_tx_mailbox_size;
|
||||
} else {
|
||||
mailbox_offset = slave->sii.boot_tx_mailbox_offset;
|
||||
mailbox_size = slave->sii.boot_tx_mailbox_size;
|
||||
}
|
||||
|
||||
data_size = EC_READ_U16(datagram->data);
|
||||
|
||||
if (data_size + EC_MBOX_HEADER_SIZE > mailbox_size) {
|
||||
if (data_size + EC_MBOX_HEADER_SIZE > slave->configured_tx_mailbox_size) {
|
||||
EC_ERR("Corrupt mailbox response received from slave %u!\n",
|
||||
slave->ring_position);
|
||||
ec_print_data(datagram->data, mailbox_size);
|
||||
ec_print_data(datagram->data, slave->configured_tx_mailbox_size);
|
||||
return ERR_PTR(-EPROTO);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ void ec_slave_init(
|
|||
slave->current_state = EC_SLAVE_STATE_UNKNOWN;
|
||||
slave->error_flag = 0;
|
||||
slave->force_config = 0;
|
||||
slave->configured_rx_mailbox_offset = 0x0000;
|
||||
slave->configured_rx_mailbox_size = 0x0000;
|
||||
slave->configured_tx_mailbox_offset = 0x0000;
|
||||
slave->configured_tx_mailbox_size = 0x0000;
|
||||
|
||||
slave->base_type = 0;
|
||||
slave->base_revision = 0;
|
||||
|
|
|
|||
|
|
@ -115,6 +115,10 @@ struct ec_slave
|
|||
ec_slave_state_t current_state; /**< Current application state. */
|
||||
unsigned int error_flag; /**< Stop processing after an error. */
|
||||
unsigned int force_config; /**< Force (re-)configuration. */
|
||||
uint16_t configured_rx_mailbox_offset;
|
||||
uint16_t configured_rx_mailbox_size;
|
||||
uint16_t configured_tx_mailbox_offset;
|
||||
uint16_t configured_tx_mailbox_size;
|
||||
|
||||
// base data
|
||||
uint8_t base_type; /**< Slave type. */
|
||||
|
|
|
|||
Loading…
Reference in New Issue