master/slave.c
changeset 164 ed85368b2b2e
parent 163 a1eea08070e1
child 175 2e4b18203ade
equal deleted inserted replaced
163:a1eea08070e1 164:ed85368b2b2e
    22 int ec_slave_fetch_strings(ec_slave_t *, const uint8_t *);
    22 int ec_slave_fetch_strings(ec_slave_t *, const uint8_t *);
    23 int ec_slave_fetch_general(ec_slave_t *, const uint8_t *);
    23 int ec_slave_fetch_general(ec_slave_t *, const uint8_t *);
    24 int ec_slave_fetch_sync(ec_slave_t *, const uint8_t *, size_t);
    24 int ec_slave_fetch_sync(ec_slave_t *, const uint8_t *, size_t);
    25 int ec_slave_fetch_pdo(ec_slave_t *, const uint8_t *, size_t, ec_pdo_type_t);
    25 int ec_slave_fetch_pdo(ec_slave_t *, const uint8_t *, size_t, ec_pdo_type_t);
    26 int ec_slave_locate_string(ec_slave_t *, unsigned int, char **);
    26 int ec_slave_locate_string(ec_slave_t *, unsigned int, char **);
       
    27 
       
    28 /*****************************************************************************/
       
    29 
       
    30 const ec_code_msg_t al_status_messages[];
    27 
    31 
    28 /*****************************************************************************/
    32 /*****************************************************************************/
    29 
    33 
    30 /**
    34 /**
    31    EtherCAT-Slave-Konstruktor.
    35    EtherCAT-Slave-Konstruktor.
   760                     slave->ring_position);
   764                     slave->ring_position);
   761             return;
   765             return;
   762         }
   766         }
   763 
   767 
   764         if (unlikely((end - start) >= timeout)) {
   768         if (unlikely((end - start) >= timeout)) {
   765             EC_WARN("Failed to check state acknowledgement 0x%02X on slave %i"
   769             EC_WARN("Failed to acknowledge state 0x%02X on slave %i"
   766                     " - Timeout!\n", state,slave->ring_position);
   770                     " - Timeout!\n", state, slave->ring_position);
   767             return;
   771             return;
   768         }
   772         }
   769     }
   773     }
       
   774 }
       
   775 
       
   776 /*****************************************************************************/
       
   777 
       
   778 /**
       
   779    Reads the AL status code of a slave and displays it.
       
   780 
       
   781    If the AL status code is not supported, or if no error occurred (both
       
   782    resulting in code=0), nothing is displayed.
       
   783 */
       
   784 
       
   785 void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT-Slave */)
       
   786 {
       
   787     ec_command_t *command;
       
   788     uint16_t code;
       
   789     const ec_code_msg_t *al_msg;
       
   790 
       
   791     command = &slave->master->simple_command;
       
   792 
       
   793     if (ec_command_nprd(command, slave->station_address, 0x0134, 2)) return;
       
   794     if (unlikely(ec_master_simple_io(slave->master, command))) {
       
   795         EC_WARN("Failed to read AL status code on slave %i!\n",
       
   796                 slave->ring_position);
       
   797         return;
       
   798     }
       
   799 
       
   800     if (!(code = EC_READ_U16(command->data))) return;
       
   801 
       
   802     for (al_msg = al_status_messages; al_msg->code; al_msg++) {
       
   803         if (al_msg->code == code) {
       
   804             EC_ERR("AL status message 0x%04X: \"%s\".\n",
       
   805                    al_msg->code, al_msg->message);
       
   806             return;
       
   807         }
       
   808     }
       
   809 
       
   810     EC_ERR("Unknown AL status code 0x%04X.\n", code);
   770 }
   811 }
   771 
   812 
   772 /*****************************************************************************/
   813 /*****************************************************************************/
   773 
   814 
   774 /**
   815 /**
   789     command = &slave->master->simple_command;
   830     command = &slave->master->simple_command;
   790 
   831 
   791     if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return -1;
   832     if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return -1;
   792     EC_WRITE_U16(command->data, state);
   833     EC_WRITE_U16(command->data, state);
   793     if (unlikely(ec_master_simple_io(slave->master, command))) {
   834     if (unlikely(ec_master_simple_io(slave->master, command))) {
   794         EC_ERR("Failed to set state %02X on slave %i!\n",
   835         EC_ERR("Failed to set state 0x%02X on slave %i!\n",
   795                state, slave->ring_position);
   836                state, slave->ring_position);
   796         return -1;
   837         return -1;
   797     }
   838     }
   798 
   839 
   799     start = get_cycles();
   840     start = get_cycles();
   804         udelay(100); // Dem Slave etwas Zeit lassen...
   845         udelay(100); // Dem Slave etwas Zeit lassen...
   805 
   846 
   806         if (ec_command_nprd(command, slave->station_address, 0x0130, 2))
   847         if (ec_command_nprd(command, slave->station_address, 0x0130, 2))
   807             return -1;
   848             return -1;
   808         if (unlikely(ec_master_simple_io(slave->master, command))) {
   849         if (unlikely(ec_master_simple_io(slave->master, command))) {
   809             EC_ERR("Failed to check state %02X on slave %i!\n",
   850             EC_ERR("Failed to check state 0x%02X on slave %i!\n",
   810                    state, slave->ring_position);
   851                    state, slave->ring_position);
   811             return -1;
   852             return -1;
   812         }
   853         }
   813 
   854 
   814         end = get_cycles();
   855         end = get_cycles();
   815 
   856 
   816         if (unlikely(EC_READ_U8(command->data) & 0x10)) { // State change error
   857         if (unlikely(EC_READ_U8(command->data) & 0x10)) { // State change error
   817             EC_ERR("Could not set state %02X - Slave %i refused state change"
   858             EC_ERR("Failed to set state 0x%02X - Slave %i refused state change"
   818                    " (code %02X)!\n", state, slave->ring_position,
   859                    " (code 0x%02X)!\n", state, slave->ring_position,
   819                    EC_READ_U8(command->data));
   860                    EC_READ_U8(command->data));
   820             ec_slave_state_ack(slave, EC_READ_U8(command->data) & 0x0F);
   861             state = EC_READ_U8(command->data) & 0x0F;
       
   862             ec_slave_read_al_status_code(slave);
       
   863             ec_slave_state_ack(slave, state);
   821             return -1;
   864             return -1;
   822         }
   865         }
   823 
   866 
   824         if (likely(EC_READ_U8(command->data) == (state & 0x0F))) {
   867         if (likely(EC_READ_U8(command->data) == (state & 0x0F))) {
   825             // State change successful
   868             // State change successful
   826             return 0;
   869             return 0;
   827         }
   870         }
   828 
   871 
   829         if (unlikely((end - start) >= timeout)) {
   872         if (unlikely((end - start) >= timeout)) {
   830             EC_ERR("Could not check state %02X of slave %i - Timeout!\n",
   873             EC_ERR("Failed to check state 0x%02X of slave %i - Timeout!\n",
   831                    state, slave->ring_position);
   874                    state, slave->ring_position);
   832             return -1;
   875             return -1;
   833         }
   876         }
   834     }
   877     }
   835 }
   878 }
  1099     return ec_slave_sii_write16(slave, 0x0004, alias);
  1142     return ec_slave_sii_write16(slave, 0x0004, alias);
  1100 }
  1143 }
  1101 
  1144 
  1102 /*****************************************************************************/
  1145 /*****************************************************************************/
  1103 
  1146 
       
  1147 const ec_code_msg_t al_status_messages[] = {
       
  1148     {0x0001, "Unspecified error"},
       
  1149     {0x0011, "Invalud requested state change"},
       
  1150     {0x0012, "Unknown requested state"},
       
  1151     {0x0013, "Bootstrap not supported"},
       
  1152     {0x0014, "No valid firmware"},
       
  1153     {0x0015, "Invalid mailbox configuration"},
       
  1154     {0x0016, "Invalid mailbox configuration"},
       
  1155     {0x0017, "Invalid sync manager configuration"},
       
  1156     {0x0018, "No valid inputs available"},
       
  1157     {0x0019, "No valid outputs"},
       
  1158     {0x001A, "Synchronisation error"},
       
  1159     {0x001B, "Sync manager watchdog"},
       
  1160     {0x0020, "Slave needs cold start"},
       
  1161     {0x0021, "Slave needs INIT"},
       
  1162     {0x0022, "Slave needs PREOP"},
       
  1163     {0x0023, "Slave needs SAVEOP"},
       
  1164     {}
       
  1165 };
       
  1166 
       
  1167 /*****************************************************************************/
       
  1168 
  1104 EXPORT_SYMBOL(ecrt_slave_write_alias);
  1169 EXPORT_SYMBOL(ecrt_slave_write_alias);
  1105 
  1170 
  1106 /*****************************************************************************/
  1171 /*****************************************************************************/
  1107 
  1172 
  1108 /* Emacs-Konfiguration
  1173 /* Emacs-Konfiguration