# HG changeset patch # User Florian Pose # Date 1144245776 0 # Node ID ed85368b2b2ebefa5cbba1220b6661095c65a93b # Parent a1eea08070e1cadf38eb714096c182d726101d67 AL status code reading after failed state transition. diff -r a1eea08070e1 -r ed85368b2b2e master/canopen.c --- a/master/canopen.c Wed Apr 05 13:57:01 2006 +0000 +++ b/master/canopen.c Wed Apr 05 14:02:56 2006 +0000 @@ -23,18 +23,7 @@ /*****************************************************************************/ -/** - SDO Abort Code Messages -*/ - -typedef struct -{ - uint32_t code; - const char *message; -} -ec_sdo_abort_message_t; - -const ec_sdo_abort_message_t sdo_abort_messages[]; +const ec_code_msg_t sdo_abort_messages[]; /*****************************************************************************/ @@ -462,7 +451,7 @@ void ec_canopen_abort_msg(uint32_t abort_code) { - const ec_sdo_abort_message_t *abort_msg; + const ec_code_msg_t *abort_msg; for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) { if (abort_msg->code == abort_code) { @@ -477,7 +466,7 @@ /*****************************************************************************/ -const ec_sdo_abort_message_t sdo_abort_messages[] = { +const ec_code_msg_t sdo_abort_messages[] = { {0x05030000, "Toggle bit not changed"}, {0x05040000, "SDO protocol timeout"}, {0x05040001, "Client/Server command specifier not valid or unknown"}, diff -r a1eea08070e1 -r ed85368b2b2e master/globals.h --- a/master/globals.h Wed Apr 05 13:57:01 2006 +0000 +++ b/master/globals.h Wed Apr 05 14:02:56 2006 +0000 @@ -50,6 +50,22 @@ /*****************************************************************************/ +/** + Code - Message Pair. + + Some EtherCAT commands support reading a status code to display a certain + message. This type allows to map a code to a message string. +*/ + +typedef struct +{ + uint32_t code; /**< Code */ + const char *message; /**< Message belonging to \a code */ +} +ec_code_msg_t; + +/*****************************************************************************/ + #endif /* Emacs-Konfiguration diff -r a1eea08070e1 -r ed85368b2b2e master/master.c --- a/master/master.c Wed Apr 05 13:57:01 2006 +0000 +++ b/master/master.c Wed Apr 05 14:02:56 2006 +0000 @@ -807,8 +807,7 @@ } // Slaves aktivieren - for (i = 0; i < master->slave_count; i++) - { + for (i = 0; i < master->slave_count; i++) { slave = master->slaves + i; // Change state to INIT @@ -852,8 +851,7 @@ // Known slave type, take type's SM information if (type) { - for (j = 0; type->sync_managers[j] && j < EC_MAX_SYNC; j++) - { + for (j = 0; type->sync_managers[j] && j < EC_MAX_SYNC; j++) { sync = type->sync_managers[j]; if (ec_command_npwr(command, slave->station_address, 0x0800 + j * EC_SYNC_SIZE, EC_SYNC_SIZE)) @@ -936,8 +934,7 @@ } // Set FMMUs - for (j = 0; j < slave->fmmu_count; j++) - { + for (j = 0; j < slave->fmmu_count; j++) { fmmu = &slave->fmmus[j]; if (ec_command_npwr(command, slave->station_address, 0x0600 + j * EC_FMMU_SIZE, EC_FMMU_SIZE)) diff -r a1eea08070e1 -r ed85368b2b2e master/slave.c --- a/master/slave.c Wed Apr 05 13:57:01 2006 +0000 +++ b/master/slave.c Wed Apr 05 14:02:56 2006 +0000 @@ -27,6 +27,10 @@ /*****************************************************************************/ +const ec_code_msg_t al_status_messages[]; + +/*****************************************************************************/ + /** EtherCAT-Slave-Konstruktor. */ @@ -762,8 +766,8 @@ } if (unlikely((end - start) >= timeout)) { - EC_WARN("Failed to check state acknowledgement 0x%02X on slave %i" - " - Timeout!\n", state,slave->ring_position); + EC_WARN("Failed to acknowledge state 0x%02X on slave %i" + " - Timeout!\n", state, slave->ring_position); return; } } @@ -772,6 +776,43 @@ /*****************************************************************************/ /** + Reads the AL status code of a slave and displays it. + + If the AL status code is not supported, or if no error occurred (both + resulting in code=0), nothing is displayed. +*/ + +void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT-Slave */) +{ + ec_command_t *command; + uint16_t code; + const ec_code_msg_t *al_msg; + + command = &slave->master->simple_command; + + if (ec_command_nprd(command, slave->station_address, 0x0134, 2)) return; + if (unlikely(ec_master_simple_io(slave->master, command))) { + EC_WARN("Failed to read AL status code on slave %i!\n", + slave->ring_position); + return; + } + + if (!(code = EC_READ_U16(command->data))) return; + + for (al_msg = al_status_messages; al_msg->code; al_msg++) { + if (al_msg->code == code) { + EC_ERR("AL status message 0x%04X: \"%s\".\n", + al_msg->code, al_msg->message); + return; + } + } + + EC_ERR("Unknown AL status code 0x%04X.\n", code); +} + +/*****************************************************************************/ + +/** Ändert den Zustand eines Slaves. \return 0 bei Erfolg, sonst < 0 @@ -791,7 +832,7 @@ if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return -1; EC_WRITE_U16(command->data, state); if (unlikely(ec_master_simple_io(slave->master, command))) { - EC_ERR("Failed to set state %02X on slave %i!\n", + EC_ERR("Failed to set state 0x%02X on slave %i!\n", state, slave->ring_position); return -1; } @@ -806,7 +847,7 @@ if (ec_command_nprd(command, slave->station_address, 0x0130, 2)) return -1; if (unlikely(ec_master_simple_io(slave->master, command))) { - EC_ERR("Failed to check state %02X on slave %i!\n", + EC_ERR("Failed to check state 0x%02X on slave %i!\n", state, slave->ring_position); return -1; } @@ -814,10 +855,12 @@ end = get_cycles(); if (unlikely(EC_READ_U8(command->data) & 0x10)) { // State change error - EC_ERR("Could not set state %02X - Slave %i refused state change" - " (code %02X)!\n", state, slave->ring_position, + EC_ERR("Failed to set state 0x%02X - Slave %i refused state change" + " (code 0x%02X)!\n", state, slave->ring_position, EC_READ_U8(command->data)); - ec_slave_state_ack(slave, EC_READ_U8(command->data) & 0x0F); + state = EC_READ_U8(command->data) & 0x0F; + ec_slave_read_al_status_code(slave); + ec_slave_state_ack(slave, state); return -1; } @@ -827,7 +870,7 @@ } if (unlikely((end - start) >= timeout)) { - EC_ERR("Could not check state %02X of slave %i - Timeout!\n", + EC_ERR("Failed to check state 0x%02X of slave %i - Timeout!\n", state, slave->ring_position); return -1; } @@ -1101,6 +1144,28 @@ /*****************************************************************************/ +const ec_code_msg_t al_status_messages[] = { + {0x0001, "Unspecified error"}, + {0x0011, "Invalud requested state change"}, + {0x0012, "Unknown requested state"}, + {0x0013, "Bootstrap not supported"}, + {0x0014, "No valid firmware"}, + {0x0015, "Invalid mailbox configuration"}, + {0x0016, "Invalid mailbox configuration"}, + {0x0017, "Invalid sync manager configuration"}, + {0x0018, "No valid inputs available"}, + {0x0019, "No valid outputs"}, + {0x001A, "Synchronisation error"}, + {0x001B, "Sync manager watchdog"}, + {0x0020, "Slave needs cold start"}, + {0x0021, "Slave needs INIT"}, + {0x0022, "Slave needs PREOP"}, + {0x0023, "Slave needs SAVEOP"}, + {} +}; + +/*****************************************************************************/ + EXPORT_SYMBOL(ecrt_slave_write_alias); /*****************************************************************************/