# HG changeset patch # User Florian Pose # Date 1150884576 0 # Node ID 12f48c1cb143d5491c9e24c8078b2baeb57d3b6e # Parent fddcb6d7869d2d6594ffe961c218649b94fcd069 Removed mbox_command out of slave. diff -r fddcb6d7869d -r 12f48c1cb143 master/canopen.c --- a/master/canopen.c Wed Jun 21 10:08:30 2006 +0000 +++ b/master/canopen.c Wed Jun 21 10:09:36 2006 +0000 @@ -48,8 +48,9 @@ /*****************************************************************************/ void ec_canopen_abort_msg(uint32_t); -int ec_slave_fetch_sdo_descriptions(ec_slave_t *); -int ec_slave_fetch_sdo_entries(ec_slave_t *, ec_sdo_t *, uint8_t); +int ec_slave_fetch_sdo_descriptions(ec_slave_t *, ec_command_t *); +int ec_slave_fetch_sdo_entries(ec_slave_t *, ec_command_t *, + ec_sdo_t *, uint8_t); /*****************************************************************************/ @@ -68,10 +69,14 @@ uint8_t *target /**< 4-byte memory */ ) { + ec_command_t command; size_t rec_size; uint8_t *data; - if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 6))) return -1; + ec_command_init(&command); + + if (!(data = ec_slave_mbox_prepare_send(slave, &command, 0x03, 6))) + goto err; EC_WRITE_U16(data, 0x2 << 12); // SDO request EC_WRITE_U8 (data + 2, (0x1 << 1 // expedited transfer @@ -79,14 +84,15 @@ EC_WRITE_U16(data + 3, sdo_index); EC_WRITE_U8 (data + 5, sdo_subindex); - if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1; + if (!(data = ec_slave_mbox_simple_io(slave, &command, &rec_size))) + goto err; if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n", sdo_index, sdo_subindex, slave->ring_position); ec_canopen_abort_msg(EC_READ_U32(data + 6)); - return -1; + goto err; } if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response @@ -97,11 +103,16 @@ EC_ERR("Invalid SDO upload response at slave %i!\n", slave->ring_position); ec_print_data(data, rec_size); - return -1; + goto err; } memcpy(target, data + 6, 4); - return 0; + + ec_command_clear(&command); + return 0; + err: + ec_command_clear(&command); + return -1; } /*****************************************************************************/ @@ -120,13 +131,17 @@ { uint8_t *data; size_t rec_size; + ec_command_t command; + + ec_command_init(&command); if (size == 0 || size > 4) { EC_ERR("Invalid data size!\n"); - return -1; - } - - if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 0x0A))) return -1; + goto err; + } + + if (!(data = ec_slave_mbox_prepare_send(slave, &command, 0x03, 0x0A))) + goto err; EC_WRITE_U16(data, 0x2 << 12); // SDO request EC_WRITE_U8 (data + 2, (0x1 // size specified @@ -138,7 +153,8 @@ memcpy(data + 6, sdo_data, size); if (size < 4) memset(data + 6 + size, 0x00, 4 - size); - if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1; + if (!(data = ec_slave_mbox_simple_io(slave, &command, &rec_size))) + goto err; if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request @@ -160,7 +176,11 @@ return -1; } - return 0; + ec_command_clear(&command); + return 0; + err: + ec_command_clear(&command); + return -1; } /*****************************************************************************/ @@ -182,22 +202,27 @@ uint8_t *data; size_t rec_size, data_size; uint32_t complete_size; - - if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 6))) return -1; + ec_command_t command; + + ec_command_init(&command); + + if (!(data = ec_slave_mbox_prepare_send(slave, &command, 0x03, 6))) + goto err; EC_WRITE_U16(data, 0x2 << 12); // SDO request EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request EC_WRITE_U16(data + 3, sdo_index); EC_WRITE_U8 (data + 5, sdo_subindex); - if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1; + if (!(data = ec_slave_mbox_simple_io(slave, &command, &rec_size))) + goto err; if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n", sdo_index, sdo_subindex, slave->ring_position); ec_canopen_abort_msg(EC_READ_U32(data + 6)); - return -1; + goto err; } if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response @@ -208,30 +233,35 @@ EC_ERR("Invalid SDO upload response at slave %i!\n", slave->ring_position); ec_print_data(data, rec_size); - return -1; + goto err; } if (rec_size < 10) { EC_ERR("Received currupted SDO upload response!\n"); ec_print_data(data, rec_size); - return -1; + goto err; } if ((complete_size = EC_READ_U32(data + 6)) > *size) { EC_ERR("SDO data does not fit into buffer (%i / %i)!\n", complete_size, *size); - return -1; + goto err; } data_size = rec_size - 10; if (data_size != complete_size) { EC_ERR("SDO data incomplete - Fragmenting not implemented.\n"); - return -1; + goto err; } memcpy(target, data + 10, data_size); - return 0; + + ec_command_clear(&command); + return 0; + err: + ec_command_clear(&command); + return -1; } /*****************************************************************************/ @@ -248,8 +278,12 @@ unsigned int i, sdo_count; ec_sdo_t *sdo; uint16_t sdo_index; - - if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 8))) return -1; + ec_command_t command; + + ec_command_init(&command); + + if (!(data = ec_slave_mbox_prepare_send(slave, &command, 0x03, 8))) + goto err; EC_WRITE_U16(data, 0x8 << 12); // SDO information EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request @@ -257,21 +291,22 @@ EC_WRITE_U16(data + 4, 0x0000); EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs! - if (unlikely(ec_master_simple_io(slave->master, &slave->mbox_command))) { + if (unlikely(ec_master_simple_io(slave->master, &command))) { EC_ERR("Mailbox checking failed on slave %i!\n", slave->ring_position); - return -1; + goto err; } do { - if (!(data = ec_slave_mbox_simple_receive(slave, 0x03, &rec_size))) - return -1; + if (!(data = ec_slave_mbox_simple_receive(slave, &command, + 0x03, &rec_size))) + goto err; if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information (EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response EC_ERR("SDO information error response at slave %i!\n", slave->ring_position); ec_canopen_abort_msg(EC_READ_U32(data + 6)); - return -1; + goto err; } if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information @@ -279,13 +314,13 @@ EC_ERR("Invalid SDO list response at slave %i!\n", slave->ring_position); ec_print_data(data, rec_size); - return -1; + goto err; } if (rec_size < 8) { EC_ERR("Invalid data size!\n"); ec_print_data(data, rec_size); - return -1; + goto err; } sdo_count = (rec_size - 8) / 2; @@ -295,7 +330,7 @@ if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) { EC_ERR("Failed to allocate memory for SDO!\n"); - return -1; + goto err; } // Initialize SDO object @@ -311,9 +346,13 @@ while (EC_READ_U8(data + 2) & 0x80); // Fetch all SDO descriptions - if (ec_slave_fetch_sdo_descriptions(slave)) return -1; - - return 0; + if (ec_slave_fetch_sdo_descriptions(slave, &command)) goto err; + + ec_command_clear(&command); + return 0; + err: + ec_command_clear(&command); + return -1; } /*****************************************************************************/ @@ -323,21 +362,25 @@ \return 0 in case of success, else < 0 */ -int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave /**< EtherCAT slave */) +int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave, /**< EtherCAT slave */ + ec_command_t *command /**< command */ + ) { uint8_t *data; size_t rec_size, name_size; ec_sdo_t *sdo; list_for_each_entry(sdo, &slave->sdo_dictionary, list) { - if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 8))) return -1; + if (!(data = ec_slave_mbox_prepare_send(slave, command, 0x03, 8))) + return -1; EC_WRITE_U16(data, 0x8 << 12); // SDO information EC_WRITE_U8 (data + 2, 0x03); // Get object description request EC_WRITE_U8 (data + 3, 0x00); EC_WRITE_U16(data + 4, 0x0000); EC_WRITE_U16(data + 6, sdo->index); // SDO index - if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1; + if (!(data = ec_slave_mbox_simple_io(slave, command, &rec_size))) + return -1; if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response @@ -364,8 +407,10 @@ return -1; } +#if 0 EC_DBG("object desc response:\n"); ec_print_data(data, rec_size); +#endif //sdo->unknown = EC_READ_U16(data + 8); sdo->object_code = EC_READ_U8(data + 11); @@ -387,7 +432,8 @@ } // Fetch all entries (subindices) - if (ec_slave_fetch_sdo_entries(slave, sdo, EC_READ_U8(data + 10))) + if (ec_slave_fetch_sdo_entries(slave, command, sdo, + EC_READ_U8(data + 10))) return -1; } @@ -402,6 +448,7 @@ */ int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT slave */ + ec_command_t *command, /**< command */ ec_sdo_t *sdo, /**< SDO */ uint8_t subindices /**< number of subindices */ ) @@ -412,7 +459,7 @@ ec_sdo_entry_t *entry; for (i = 1; i <= subindices; i++) { - if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 10))) + if (!(data = ec_slave_mbox_prepare_send(slave, command, 0x03, 10))) return -1; EC_WRITE_U16(data, 0x8 << 12); // SDO information @@ -423,7 +470,8 @@ EC_WRITE_U8 (data + 8, i); // SDO subindex EC_WRITE_U8 (data + 9, 0x00); // value info (no values) - if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1; + if (!(data = ec_slave_mbox_simple_io(slave, command, &rec_size))) + return -1; if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response diff -r fddcb6d7869d -r 12f48c1cb143 master/ethernet.c --- a/master/ethernet.c Wed Jun 21 10:08:30 2006 +0000 +++ b/master/ethernet.c Wed Jun 21 10:09:36 2006 +0000 @@ -79,6 +79,7 @@ int result, i; eoe->slave = NULL; + ec_command_init(&eoe->command); eoe->state = ec_eoe_state_rx_start; eoe->opened = 0; eoe->rx_skb = NULL; @@ -159,6 +160,8 @@ } if (eoe->rx_skb) dev_kfree_skb(eoe->rx_skb); + + ec_command_clear(&eoe->command); } /*****************************************************************************/ @@ -235,8 +238,8 @@ printk("\n"); #endif - if (!(data = ec_slave_mbox_prepare_send(eoe->slave, 0x02, - current_size + 4))) + if (!(data = ec_slave_mbox_prepare_send(eoe->slave, &eoe->command, + 0x02, current_size + 4))) return -1; EC_WRITE_U8 (data, 0x00); // eoe fragment req. @@ -246,7 +249,7 @@ (eoe->tx_frame_number & 0x0F) << 12)); memcpy(data + 4, eoe->tx_frame->skb->data + eoe->tx_offset, current_size); - ec_master_queue_command(eoe->slave->master, &eoe->slave->mbox_command); + ec_master_queue_command(eoe->slave->master, &eoe->command); eoe->tx_offset += current_size; eoe->tx_fragment_number++; @@ -310,8 +313,8 @@ if (!eoe->slave->online || !eoe->slave->master->device->link_state) return; - ec_slave_mbox_prepare_check(eoe->slave); - ec_master_queue_command(eoe->slave->master, &eoe->slave->mbox_command); + ec_slave_mbox_prepare_check(eoe->slave, &eoe->command); + ec_master_queue_command(eoe->slave->master, &eoe->command); eoe->state = ec_eoe_state_rx_check; } @@ -325,19 +328,19 @@ void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */) { - if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) { + if (eoe->command.state != EC_CMD_RECEIVED) { eoe->stats.rx_errors++; eoe->state = ec_eoe_state_tx_start; return; } - if (!ec_slave_mbox_check(eoe->slave)) { + if (!ec_slave_mbox_check(&eoe->command)) { eoe->state = ec_eoe_state_tx_start; return; } - ec_slave_mbox_prepare_fetch(eoe->slave); - ec_master_queue_command(eoe->slave->master, &eoe->slave->mbox_command); + ec_slave_mbox_prepare_fetch(eoe->slave, &eoe->command); + ec_master_queue_command(eoe->slave->master, &eoe->command); eoe->state = ec_eoe_state_rx_fetch; } @@ -356,13 +359,14 @@ uint8_t frame_number, fragment_offset, fragment_number; off_t offset; - if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) { + if (eoe->command.state != EC_CMD_RECEIVED) { eoe->stats.rx_errors++; eoe->state = ec_eoe_state_tx_start; return; } - if (!(data = ec_slave_mbox_fetch(eoe->slave, 0x02, &rec_size))) { + if (!(data = ec_slave_mbox_fetch(eoe->slave, &eoe->command, + 0x02, &rec_size))) { eoe->stats.rx_errors++; eoe->state = ec_eoe_state_tx_start; return; @@ -554,13 +558,13 @@ void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */) { - if (eoe->slave->mbox_command.state != EC_CMD_RECEIVED) { + if (eoe->command.state != EC_CMD_RECEIVED) { eoe->stats.tx_errors++; eoe->state = ec_eoe_state_rx_start; return; } - if (eoe->slave->mbox_command.working_counter != 1) { + if (eoe->command.working_counter != 1) { eoe->stats.tx_errors++; eoe->state = ec_eoe_state_rx_start; return; diff -r fddcb6d7869d -r 12f48c1cb143 master/ethernet.h --- a/master/ethernet.h Wed Jun 21 10:08:30 2006 +0000 +++ b/master/ethernet.h Wed Jun 21 10:09:36 2006 +0000 @@ -73,6 +73,7 @@ { struct list_head list; /**< list item */ ec_slave_t *slave; /**< pointer to the corresponding slave */ + ec_command_t command; /**< command */ void (*state)(ec_eoe_t *); /**< state function for the state machine */ struct net_device *dev; /**< net_device for virtual ethernet device */ struct net_device_stats stats; /**< device statistics */ diff -r fddcb6d7869d -r 12f48c1cb143 master/mailbox.c --- a/master/mailbox.c Wed Jun 21 10:08:30 2006 +0000 +++ b/master/mailbox.c Wed Jun 21 10:09:36 2006 +0000 @@ -52,12 +52,12 @@ \return pointer to mailbox command data */ -uint8_t *ec_slave_mbox_prepare_send(ec_slave_t *slave, /**< slave */ +uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *slave, /**< slave */ + ec_command_t *command, /**< command */ uint8_t type, /**< mailbox protocol */ size_t size /**< size of the data */ ) { - ec_command_t *command = &slave->mbox_command; size_t total_size; if (unlikely(!slave->sii_mailbox_protocols)) { @@ -92,10 +92,10 @@ \return 0 in case of success, else < 0 */ -int ec_slave_mbox_prepare_check(ec_slave_t *slave /**< slave */) -{ - ec_command_t *command = &slave->mbox_command; - +int ec_slave_mbox_prepare_check(const ec_slave_t *slave, /**< slave */ + ec_command_t *command /**< command */ + ) +{ // FIXME: second sync manager? if (ec_command_nprd(command, slave->station_address, 0x808, 8)) return -1; @@ -110,9 +110,9 @@ \return 0 in case of success, else < 0 */ -int ec_slave_mbox_check(const ec_slave_t *slave /**< slave */) -{ - return EC_READ_U8(slave->mbox_command.data + 5) & 8 ? 1 : 0; +int ec_slave_mbox_check(const ec_command_t *command /**< command */) +{ + return EC_READ_U8(command->data + 5) & 8 ? 1 : 0; } /*****************************************************************************/ @@ -122,10 +122,10 @@ \return 0 in case of success, else < 0 */ -int ec_slave_mbox_prepare_fetch(ec_slave_t *slave /**< slave */) -{ - ec_command_t *command = &slave->mbox_command; - +int ec_slave_mbox_prepare_fetch(const ec_slave_t *slave, /**< slave */ + ec_command_t *command /**< command */ + ) +{ if (ec_command_nprd(command, slave->station_address, slave->sii_tx_mailbox_offset, slave->sii_tx_mailbox_size)) return -1; @@ -139,12 +139,12 @@ \return pointer to the received data */ -uint8_t *ec_slave_mbox_fetch(ec_slave_t *slave, /**< slave */ +uint8_t *ec_slave_mbox_fetch(const ec_slave_t *slave, /**< slave */ + ec_command_t *command, /**< command */ uint8_t type, /**< expected mailbox protocol */ size_t *size /**< size of the received data */ ) { - ec_command_t *command = &slave->mbox_command; size_t data_size; if ((EC_READ_U8(command->data + 5) & 0x0F) != type) { @@ -171,14 +171,13 @@ \return pointer to the received data */ -uint8_t *ec_slave_mbox_simple_io(ec_slave_t *slave, /**< slave */ +uint8_t *ec_slave_mbox_simple_io(const ec_slave_t *slave, /**< slave */ + ec_command_t *command, /**< command */ size_t *size /**< size of the received data */ ) { uint8_t type; - ec_command_t *command; - - command = &slave->mbox_command; + type = EC_READ_U8(command->data + 5); if (unlikely(ec_master_simple_io(slave->master, command))) { @@ -187,7 +186,7 @@ return NULL; } - return ec_slave_mbox_simple_receive(slave, type, size); + return ec_slave_mbox_simple_receive(slave, command, type, size); } /*****************************************************************************/ @@ -197,21 +196,20 @@ \return pointer to the received data */ -uint8_t *ec_slave_mbox_simple_receive(ec_slave_t *slave, /**< slave */ +uint8_t *ec_slave_mbox_simple_receive(const ec_slave_t *slave, /**< slave */ + ec_command_t *command, /**< command */ uint8_t type, /**< expected protocol */ size_t *size /**< received data size */ ) { cycles_t start, end, timeout; - ec_command_t *command; - - command = &slave->mbox_command; + start = get_cycles(); timeout = (cycles_t) 100 * cpu_khz; // 100ms while (1) { - if (ec_slave_mbox_prepare_check(slave)) return NULL; + if (ec_slave_mbox_prepare_check(slave, command)) return NULL; if (unlikely(ec_master_simple_io(slave->master, command))) { EC_ERR("Mailbox checking failed on slave %i!\n", slave->ring_position); @@ -220,7 +218,7 @@ end = get_cycles(); - if (ec_slave_mbox_check(slave)) + if (ec_slave_mbox_check(command)) break; // proceed with receiving data if ((end - start) >= timeout) { @@ -232,7 +230,7 @@ udelay(100); } - if (ec_slave_mbox_prepare_fetch(slave)) return NULL; + if (ec_slave_mbox_prepare_fetch(slave, command)) return NULL; if (unlikely(ec_master_simple_io(slave->master, command))) { EC_ERR("Mailbox receiving failed on slave %i!\n", slave->ring_position); @@ -243,7 +241,7 @@ EC_DBG("Mailbox receive took %ius.\n", ((u32) (end - start) * 1000 / cpu_khz)); - return ec_slave_mbox_fetch(slave, type, size); -} - -/*****************************************************************************/ + return ec_slave_mbox_fetch(slave, command, type, size); +} + +/*****************************************************************************/ diff -r fddcb6d7869d -r 12f48c1cb143 master/mailbox.h --- a/master/mailbox.h Wed Jun 21 10:08:30 2006 +0000 +++ b/master/mailbox.h Wed Jun 21 10:09:36 2006 +0000 @@ -45,14 +45,17 @@ /*****************************************************************************/ -uint8_t *ec_slave_mbox_prepare_send(ec_slave_t *, uint8_t, size_t); -int ec_slave_mbox_prepare_check(ec_slave_t *); -int ec_slave_mbox_check(const ec_slave_t *); -int ec_slave_mbox_prepare_fetch(ec_slave_t *); -uint8_t *ec_slave_mbox_fetch(ec_slave_t *, uint8_t, size_t *); +uint8_t *ec_slave_mbox_prepare_send(const ec_slave_t *, ec_command_t *, + uint8_t, size_t); +int ec_slave_mbox_prepare_check(const ec_slave_t *, ec_command_t *); +int ec_slave_mbox_check(const ec_command_t *); +int ec_slave_mbox_prepare_fetch(const ec_slave_t *, ec_command_t *); +uint8_t *ec_slave_mbox_fetch(const ec_slave_t *, ec_command_t *, + uint8_t, size_t *); -uint8_t *ec_slave_mbox_simple_io(ec_slave_t *, size_t *); -uint8_t *ec_slave_mbox_simple_receive(ec_slave_t *, uint8_t, size_t *); +uint8_t *ec_slave_mbox_simple_io(const ec_slave_t *, ec_command_t *, size_t *); +uint8_t *ec_slave_mbox_simple_receive(const ec_slave_t *, ec_command_t *, + uint8_t, size_t *); /*****************************************************************************/ diff -r fddcb6d7869d -r 12f48c1cb143 master/slave.c --- a/master/slave.c Wed Jun 21 10:08:30 2006 +0000 +++ b/master/slave.c Wed Jun 21 10:09:36 2006 +0000 @@ -160,8 +160,6 @@ slave->new_eeprom_data = NULL; slave->new_eeprom_size = 0; - ec_command_init(&slave->mbox_command); - INIT_LIST_HEAD(&slave->eeprom_strings); INIT_LIST_HEAD(&slave->eeprom_syncs); INIT_LIST_HEAD(&slave->eeprom_pdos); @@ -250,8 +248,6 @@ if (slave->eeprom_data) kfree(slave->eeprom_data); if (slave->new_eeprom_data) kfree(slave->new_eeprom_data); - - ec_command_clear(&slave->mbox_command); } /*****************************************************************************/ diff -r fddcb6d7869d -r 12f48c1cb143 master/slave.h --- a/master/slave.h Wed Jun 21 10:08:30 2006 +0000 +++ b/master/slave.h Wed Jun 21 10:09:36 2006 +0000 @@ -290,8 +290,6 @@ struct list_head sdo_dictionary; /**< SDO directory list */ - ec_command_t mbox_command; /**< mailbox command */ - ec_slave_state_t requested_state; /**< requested slave state */ ec_slave_state_t current_state; /**< current slave state */ unsigned int state_error; /**< a state error has happened */