master/canopen.c
changeset 195 674071846ee3
parent 175 2e4b18203ade
child 197 b9a6e2c22745
child 1618 5cff10efb927
equal deleted inserted replaced
194:c21e7c12dd50 195:674071846ee3
    26 const ec_code_msg_t sdo_abort_messages[];
    26 const ec_code_msg_t sdo_abort_messages[];
    27 
    27 
    28 /*****************************************************************************/
    28 /*****************************************************************************/
    29 
    29 
    30 /**
    30 /**
    31    Liest 32 Bit eines CANopen-SDOs im Expedited-Modus aus einem Slave.
    31    Reads 32 bit of a CANopen SDO in expedited mode.
    32    \return 0 wenn alles ok, < 0 bei Fehler
    32    \return 0 in case of success, else < 0
    33  */
    33  */
    34 
    34 
    35 int ec_slave_sdo_read_exp(ec_slave_t *slave, /**< EtherCAT-Slave */
    35 int ec_slave_sdo_read_exp(ec_slave_t *slave, /**< EtherCAT slave */
    36                           uint16_t sdo_index, /**< SDO-Index */
    36                           uint16_t sdo_index, /**< SDO index */
    37                           uint8_t sdo_subindex, /**< SDO-Subindex */
    37                           uint8_t sdo_subindex, /**< SDO subindex */
    38                           uint8_t *target /**< Speicher für 4 Bytes */
    38                           uint8_t *target /**< 4-byte memory */
    39                           )
    39                           )
    40 {
    40 {
    41     size_t rec_size;
    41     size_t rec_size;
    42     uint8_t *data;
    42     uint8_t *data;
    43 
    43 
    44     if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 6))) return -1;
    44     if (!(data = ec_slave_mbox_prepare_send(slave, 0x03, 6))) return -1;
    45 
    45 
    46     EC_WRITE_U16(data, 0x2 << 12); // SDO request
    46     EC_WRITE_U16(data, 0x2 << 12); // SDO request
    47     EC_WRITE_U8 (data + 2, (0x1 << 1 // expedited transfer
    47     EC_WRITE_U8 (data + 2, (0x1 << 1 // expedited transfer
    48                             | 0x2 << 5));  // initiate upload request
    48                             | 0x2 << 5)); // initiate upload request
    49     EC_WRITE_U16(data + 3, sdo_index);
    49     EC_WRITE_U16(data + 3, sdo_index);
    50     EC_WRITE_U8 (data + 5, sdo_subindex);
    50     EC_WRITE_U8 (data + 5, sdo_subindex);
    51 
    51 
    52     if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
    52     if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
    53 
    53 
    54     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
    54     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
    55         EC_READ_U8 (data + 2) >> 5 == 0x4) { // Abort SDO transfer request
    55         EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
    56         EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n",
    56         EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n",
    57                sdo_index, sdo_subindex, slave->ring_position);
    57                sdo_index, sdo_subindex, slave->ring_position);
    58         ec_canopen_abort_msg(EC_READ_U32(data + 6));
    58         ec_canopen_abort_msg(EC_READ_U32(data + 6));
    59         return -1;
    59         return -1;
    60     }
    60     }
    61 
    61 
    62     if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
    62     if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
    63         EC_READ_U8 (data + 2) >> 5 != 0x2 || // Upload response
    63         EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response
    64         EC_READ_U16(data + 3) != sdo_index || // Index
    64         EC_READ_U16(data + 3) != sdo_index || // index
    65         EC_READ_U8 (data + 5) != sdo_subindex) { // Subindex
    65         EC_READ_U8 (data + 5) != sdo_subindex) { // subindex
    66         EC_ERR("SDO upload 0x%04X:%X failed:\n", sdo_index, sdo_subindex);
    66         EC_ERR("SDO upload 0x%04X:%X failed:\n", sdo_index, sdo_subindex);
    67         EC_ERR("Invalid SDO upload response at slave %i!\n",
    67         EC_ERR("Invalid SDO upload response at slave %i!\n",
    68                slave->ring_position);
    68                slave->ring_position);
    69         ec_print_data(data, rec_size);
    69         ec_print_data(data, rec_size);
    70         return -1;
    70         return -1;
    75 }
    75 }
    76 
    76 
    77 /*****************************************************************************/
    77 /*****************************************************************************/
    78 
    78 
    79 /**
    79 /**
    80    Beschreibt ein CANopen-SDO eines Slaves im Expedited-Modus.
    80    Writes a CANopen SDO using expedited mode.
    81    \return 0 wenn alles ok, < 0 bei Fehler
    81    \return 0 in case of success, else < 0
    82  */
    82  */
    83 
    83 
    84 int ec_slave_sdo_write_exp(ec_slave_t *slave, /**< EtherCAT-Slave */
    84 int ec_slave_sdo_write_exp(ec_slave_t *slave, /**< EtherCAT slave */
    85                            uint16_t sdo_index, /**< SDO-Index */
    85                            uint16_t sdo_index, /**< SDO index */
    86                            uint8_t sdo_subindex, /**< SDO-Subindex */
    86                            uint8_t sdo_subindex, /**< SDO subindex */
    87                            const uint8_t *sdo_data, /**< Neuer Wert */
    87                            const uint8_t *sdo_data, /**< new value */
    88                            size_t size
    88                            size_t size
    89                            )
    89                            )
    90 {
    90 {
    91     uint8_t *data;
    91     uint8_t *data;
    92     size_t rec_size;
    92     size_t rec_size;
   109     if (size < 4) memset(data + 6 + size, 0x00, 4 - size);
   109     if (size < 4) memset(data + 6 + size, 0x00, 4 - size);
   110 
   110 
   111     if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
   111     if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
   112 
   112 
   113     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
   113     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
   114         EC_READ_U8 (data + 2) >> 5 == 0x4) { // Abort SDO transfer request
   114         EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
   115         EC_ERR("SDO download 0x%04X:%X (%i bytes) aborted on slave %i.\n",
   115         EC_ERR("SDO download 0x%04X:%X (%i bytes) aborted on slave %i.\n",
   116                sdo_index, sdo_subindex, size, slave->ring_position);
   116                sdo_index, sdo_subindex, size, slave->ring_position);
   117         ec_canopen_abort_msg(EC_READ_U32(data + 6));
   117         ec_canopen_abort_msg(EC_READ_U32(data + 6));
   118         return -1;
   118         return -1;
   119     }
   119     }
   120 
   120 
   121     if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
   121     if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
   122         EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response
   122         EC_READ_U8 (data + 2) >> 5 != 0x3 || // download response
   123         EC_READ_U16(data + 3) != sdo_index || // Index
   123         EC_READ_U16(data + 3) != sdo_index || // index
   124         EC_READ_U8 (data + 5) != sdo_subindex) { // Subindex
   124         EC_READ_U8 (data + 5) != sdo_subindex) { // subindex
   125         EC_ERR("SDO download 0x%04X:%X (%i bytes) failed:\n",
   125         EC_ERR("SDO download 0x%04X:%X (%i bytes) failed:\n",
   126                sdo_index, sdo_subindex, size);
   126                sdo_index, sdo_subindex, size);
   127         EC_ERR("Invalid SDO download response at slave %i!\n",
   127         EC_ERR("Invalid SDO download response at slave %i!\n",
   128                slave->ring_position);
   128                slave->ring_position);
   129         ec_print_data(data, rec_size);
   129         ec_print_data(data, rec_size);
   134 }
   134 }
   135 
   135 
   136 /*****************************************************************************/
   136 /*****************************************************************************/
   137 
   137 
   138 /**
   138 /**
   139    Liest ein CANopen-SDO im "Normal-Modus" aus einem Slave.
   139    Reads a CANopen SDO in normal mode.
   140    \return 0 wenn alles ok, < 0 bei Fehler
   140    \return 0 in case of success, else < 0
   141  */
   141 
   142 
   142    \todo size
   143 int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT-Slave */
   143  */
   144                         uint16_t sdo_index, /**< SDO-Index */
   144 
   145                         uint8_t sdo_subindex, /**< SDO-Subindex */
   145 int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */
   146                         uint8_t *target, /**< Speicher für gel. Wert */
   146                         uint16_t sdo_index, /**< SDO index */
   147                         size_t *size /**< Größe des Speichers */
   147                         uint8_t sdo_subindex, /**< SDO subindex */
       
   148                         uint8_t *target, /**< memory for value */
       
   149                         size_t *size /**< target memory size */
   148                         )
   150                         )
   149 {
   151 {
   150     uint8_t *data;
   152     uint8_t *data;
   151     size_t rec_size, data_size;
   153     size_t rec_size, data_size;
   152     uint32_t complete_size;
   154     uint32_t complete_size;
   159     EC_WRITE_U8 (data + 5, sdo_subindex);
   161     EC_WRITE_U8 (data + 5, sdo_subindex);
   160 
   162 
   161     if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
   163     if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
   162 
   164 
   163     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
   165     if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
   164         EC_READ_U8 (data + 2) >> 5 == 0x4) { // Abort SDO transfer request
   166         EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
   165         EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n",
   167         EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n",
   166                sdo_index, sdo_subindex, slave->ring_position);
   168                sdo_index, sdo_subindex, slave->ring_position);
   167         ec_canopen_abort_msg(EC_READ_U32(data + 6));
   169         ec_canopen_abort_msg(EC_READ_U32(data + 6));
   168         return -1;
   170         return -1;
   169     }
   171     }
   170 
   172 
   171     if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
   173     if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
   172         EC_READ_U8 (data + 2) >> 5 != 0x2 || // Initiate upload response
   174         EC_READ_U8 (data + 2) >> 5 != 0x2 || // initiate upload response
   173         EC_READ_U16(data + 3) != sdo_index || // Index
   175         EC_READ_U16(data + 3) != sdo_index || // index
   174         EC_READ_U8 (data + 5) != sdo_subindex) { // Subindex
   176         EC_READ_U8 (data + 5) != sdo_subindex) { // subindex
   175         EC_ERR("SDO upload 0x%04X:%X failed:\n", sdo_index, sdo_subindex);
   177         EC_ERR("SDO upload 0x%04X:%X failed:\n", sdo_index, sdo_subindex);
   176         EC_ERR("Invalid SDO upload response at slave %i!\n",
   178         EC_ERR("Invalid SDO upload response at slave %i!\n",
   177                slave->ring_position);
   179                slave->ring_position);
   178         ec_print_data(data, rec_size);
   180         ec_print_data(data, rec_size);
   179         return -1;
   181         return -1;
   203 }
   205 }
   204 
   206 
   205 /*****************************************************************************/
   207 /*****************************************************************************/
   206 
   208 
   207 /**
   209 /**
   208    Lädt das gesamte SDO-Dictionary aus einem Slave.
   210    Fetches the SDO dictionary of a slave.
   209    \return 0, wenn alles ok, sonst < 0
   211    \return 0 in case of success, else < 0
   210 */
   212 */
   211 
   213 
   212 int ec_slave_fetch_sdo_list(ec_slave_t *slave /**< EtherCAT-Slave */)
   214 int ec_slave_fetch_sdo_list(ec_slave_t *slave /**< EtherCAT slave */)
   213 {
   215 {
   214     uint8_t *data;
   216     uint8_t *data;
   215     size_t rec_size;
   217     size_t rec_size;
   216     unsigned int i, sdo_count;
   218     unsigned int i, sdo_count;
   217     ec_sdo_t *sdo;
   219     ec_sdo_t *sdo;
   221 
   223 
   222     EC_WRITE_U16(data, 0x8 << 12); // SDO information
   224     EC_WRITE_U16(data, 0x8 << 12); // SDO information
   223     EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request
   225     EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request
   224     EC_WRITE_U8 (data + 3, 0x00);
   226     EC_WRITE_U8 (data + 3, 0x00);
   225     EC_WRITE_U16(data + 4, 0x0000);
   227     EC_WRITE_U16(data + 4, 0x0000);
   226     EC_WRITE_U16(data + 6, 0x0001); // Deliver all SDOs!
   228     EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs!
   227 
   229 
   228     if (unlikely(ec_master_simple_io(slave->master, &slave->mbox_command))) {
   230     if (unlikely(ec_master_simple_io(slave->master, &slave->mbox_command))) {
   229         EC_ERR("Mailbox checking failed on slave %i!\n", slave->ring_position);
   231         EC_ERR("Mailbox checking failed on slave %i!\n", slave->ring_position);
   230         return -1;
   232         return -1;
   231     }
   233     }
   233     do {
   235     do {
   234         if (!(data = ec_slave_mbox_simple_receive(slave, 0x03, &rec_size)))
   236         if (!(data = ec_slave_mbox_simple_receive(slave, 0x03, &rec_size)))
   235             return -1;
   237             return -1;
   236 
   238 
   237         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
   239         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
   238             (EC_READ_U8(data + 2) & 0x7F) == 0x07) { // Error response
   240             (EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response
   239             EC_ERR("SDO information error response at slave %i!\n",
   241             EC_ERR("SDO information error response at slave %i!\n",
   240                    slave->ring_position);
   242                    slave->ring_position);
   241             ec_canopen_abort_msg(EC_READ_U32(data + 6));
   243             ec_canopen_abort_msg(EC_READ_U32(data + 6));
   242             return -1;
   244             return -1;
   243         }
   245         }
   257         }
   259         }
   258 
   260 
   259         sdo_count = (rec_size - 8) / 2;
   261         sdo_count = (rec_size - 8) / 2;
   260         for (i = 0; i < sdo_count; i++) {
   262         for (i = 0; i < sdo_count; i++) {
   261             sdo_index = EC_READ_U16(data + 8 + i * 2);
   263             sdo_index = EC_READ_U16(data + 8 + i * 2);
   262             if (!sdo_index) continue; // Manchmal ist der Index 0... ???
   264             if (!sdo_index) continue; // sometimes index is 0... ???
   263 
   265 
   264             if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) {
   266             if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) {
   265                 EC_ERR("Failed to allocate memory for SDO!\n");
   267                 EC_ERR("Failed to allocate memory for SDO!\n");
   266                 return -1;
   268                 return -1;
   267             }
   269             }
   276             list_add_tail(&sdo->list, &slave->sdo_dictionary);
   278             list_add_tail(&sdo->list, &slave->sdo_dictionary);
   277         }
   279         }
   278     }
   280     }
   279     while (EC_READ_U8(data + 2) & 0x80);
   281     while (EC_READ_U8(data + 2) & 0x80);
   280 
   282 
   281     // Alle Beschreibungen laden
   283     // Fetch all SDO descriptions
   282     if (ec_slave_fetch_sdo_descriptions(slave)) return -1;
   284     if (ec_slave_fetch_sdo_descriptions(slave)) return -1;
   283 
   285 
   284     return 0;
   286     return 0;
   285 }
   287 }
   286 
   288 
   287 /*****************************************************************************/
   289 /*****************************************************************************/
   288 
   290 
   289 /**
   291 /**
   290    Holt die Beschreibungen zu allen bereits bekannten SDOs.
   292    Fetches the SDO descriptions for the known SDOs.
   291    \return 0, wenn alles ok, sonst < 0
   293    \return 0 in case of success, else < 0
   292 */
   294 */
   293 
   295 
   294 int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave /**< EtherCAT-Slave */)
   296 int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave /**< EtherCAT slave */)
   295 {
   297 {
   296     uint8_t *data;
   298     uint8_t *data;
   297     size_t rec_size, name_size;
   299     size_t rec_size, name_size;
   298     ec_sdo_t *sdo;
   300     ec_sdo_t *sdo;
   299 
   301 
   306         EC_WRITE_U16(data + 6, sdo->index); // SDO index
   308         EC_WRITE_U16(data + 6, sdo->index); // SDO index
   307 
   309 
   308         if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
   310         if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
   309 
   311 
   310         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
   312         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
   311             (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // Error response
   313             (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
   312             EC_ERR("SDO information error response at slave %i while"
   314             EC_ERR("SDO information error response at slave %i while"
   313                    " fetching SDO 0x%04X!\n", slave->ring_position,
   315                    " fetching SDO 0x%04X!\n", slave->ring_position,
   314                    sdo->index);
   316                    sdo->index);
   315             ec_canopen_abort_msg(EC_READ_U32(data + 6));
   317             ec_canopen_abort_msg(EC_READ_U32(data + 6));
   316             return -1;
   318             return -1;
   352         if (EC_READ_U8(data + 2) & 0x80) {
   354         if (EC_READ_U8(data + 2) & 0x80) {
   353             EC_ERR("Fragment follows (not implemented)!\n");
   355             EC_ERR("Fragment follows (not implemented)!\n");
   354             return -1;
   356             return -1;
   355         }
   357         }
   356 
   358 
   357         // Alle Entries (Subindizes) laden
   359         // Fetch all entries (subindices)
   358         if (ec_slave_fetch_sdo_entries(slave, sdo, EC_READ_U8(data + 10)))
   360         if (ec_slave_fetch_sdo_entries(slave, sdo, EC_READ_U8(data + 10)))
   359             return -1;
   361             return -1;
   360     }
   362     }
   361 
   363 
   362     return 0;
   364     return 0;
   363 }
   365 }
   364 
   366 
   365 /*****************************************************************************/
   367 /*****************************************************************************/
   366 
   368 
   367 /**
   369 /**
   368    Lädt alle Entries (Subindizes) zu einem SDO.
   370    Fetches all entries (subindices) to an SDO.
   369    \return 0, wenn alles ok, sonst < 0
   371    \return 0 in case of success, else < 0
   370 */
   372 */
   371 
   373 
   372 int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT-Slave */
   374 int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT slave */
   373                                ec_sdo_t *sdo, /**< SDO */
   375                                ec_sdo_t *sdo, /**< SDO */
   374                                uint8_t subindices /**< Anzahl Subindizes */
   376                                uint8_t subindices /**< number of subindices */
   375                                )
   377                                )
   376 {
   378 {
   377     uint8_t *data;
   379     uint8_t *data;
   378     size_t rec_size, data_size;
   380     size_t rec_size, data_size;
   379     uint8_t i;
   381     uint8_t i;
   392         EC_WRITE_U8 (data + 9, 0x00); // value info (no values)
   394         EC_WRITE_U8 (data + 9, 0x00); // value info (no values)
   393 
   395 
   394         if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
   396         if (!(data = ec_slave_mbox_simple_io(slave, &rec_size))) return -1;
   395 
   397 
   396         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
   398         if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
   397             (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // Error response
   399             (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
   398             EC_ERR("SDO information error response at slave %i while"
   400             EC_ERR("SDO information error response at slave %i while"
   399                    " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
   401                    " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
   400                    sdo->index, i);
   402                    sdo->index, i);
   401             ec_canopen_abort_msg(EC_READ_U32(data + 6));
   403             ec_canopen_abort_msg(EC_READ_U32(data + 6));
   402             return -1;
   404             return -1;
   403         }
   405         }
   404 
   406 
   405         if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
   407         if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
   406             (EC_READ_U8(data + 2) & 0x7F) != 0x06 || // entry descr. response
   408             (EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response
   407             EC_READ_U16(data + 6) != sdo->index || // SDO index
   409             EC_READ_U16(data + 6) != sdo->index || // SDO index
   408             EC_READ_U8(data + 8) != i) { // SDO subindex
   410             EC_READ_U8(data + 8) != i) { // SDO subindex
   409             EC_ERR("Invalid entry description response at slave %i while"
   411             EC_ERR("Invalid entry description response at slave %i while"
   410                    " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
   412                    " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
   411                    sdo->index, i);
   413                    sdo->index, i);
   447 }
   449 }
   448 
   450 
   449 /*****************************************************************************/
   451 /*****************************************************************************/
   450 
   452 
   451 /**
   453 /**
   452    Gibt eine SDO-Abort-Meldung aus.
   454    Outputs an SDO abort message.
   453 */
   455 */
   454 
   456 
   455 void ec_canopen_abort_msg(uint32_t abort_code)
   457 void ec_canopen_abort_msg(uint32_t abort_code)
   456 {
   458 {
   457     const ec_code_msg_t *abort_msg;
   459     const ec_code_msg_t *abort_msg;
   504     {0x08000023, "Object dictionary dynamic generation fails or no object"
   506     {0x08000023, "Object dictionary dynamic generation fails or no object"
   505      " dictionary is present"},
   507      " dictionary is present"},
   506     {}
   508     {}
   507 };
   509 };
   508 
   510 
   509 /*****************************************************************************/
   511 /******************************************************************************
   510 // Echtzeitschnittstelle
   512  *  Realtime interface
   511 
   513  *****************************************************************************/
   512 /*****************************************************************************/
   514 
   513 
   515 /**
   514 /**
   516    Reads an 8-bit SDO in expedited mode.
   515    Liest ein 8-Bit CANopen-SDO im Expedited-Modus aus einem Slave.
   517    See ec_slave_sdo_read_exp()
   516    Siehe ec_slave_sdo_read_exp()
   518    \return 0 in case of success, else < 0
   517    \return 0 wenn alles ok, < 0 bei Fehler
   519  */
   518  */
   520 
   519 
   521 int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   520 int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, /**< EtherCAT-Slave */
   522                              uint16_t sdo_index, /**< SDO index */
   521                              uint16_t sdo_index, /**< SDO-Index */
   523                              uint8_t sdo_subindex, /**< SDO subindex */
   522                              uint8_t sdo_subindex, /**< SDO-Subindex */
   524                              uint8_t *target /**< memory for read value */
   523                              uint8_t *target /**< Speicher für gel. Wert */
       
   524                              )
   525                              )
   525 {
   526 {
   526     uint8_t data[4];
   527     uint8_t data[4];
   527     if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
   528     if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
   528     *target = EC_READ_U8(data);
   529     *target = EC_READ_U8(data);
   530 }
   531 }
   531 
   532 
   532 /*****************************************************************************/
   533 /*****************************************************************************/
   533 
   534 
   534 /**
   535 /**
   535    Liest ein 16-Bit CANopen-SDO im Expedited-Modus aus einem Slave.
   536    Reads a 16-bit SDO in expedited mode.
   536    Siehe ec_slave_sdo_read_exp()
   537    See ec_slave_sdo_read_exp()
   537    \return 0 wenn alles ok, < 0 bei Fehler
   538    \return 0 in case of success, else < 0
   538  */
   539  */
   539 
   540 
   540 int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, /**< EtherCAT-Slave */
   541 int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   541                               uint16_t sdo_index, /**< SDO-Index */
   542                               uint16_t sdo_index, /**< SDO index */
   542                               uint8_t sdo_subindex, /**< SDO-Subindex */
   543                               uint8_t sdo_subindex, /**< SDO subindex */
   543                               uint16_t *target /**< Speicher für gel. Wert */
   544                               uint16_t *target /**< memory for read value */
   544                               )
   545                               )
   545 {
   546 {
   546     uint8_t data[4];
   547     uint8_t data[4];
   547     if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
   548     if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
   548     *target = EC_READ_U16(data);
   549     *target = EC_READ_U16(data);
   550 }
   551 }
   551 
   552 
   552 /*****************************************************************************/
   553 /*****************************************************************************/
   553 
   554 
   554 /**
   555 /**
   555    Liest ein 32-Bit CANopen-SDO im Expedited-Modus aus einem Slave.
   556    Reads a 32-bit SDO in expedited mode.
   556    Siehe ec_slave_sdo_read_exp()
   557    See ec_slave_sdo_read_exp()
   557    \return 0 wenn alles ok, < 0 bei Fehler
   558    \return 0 in case of success, else < 0
   558  */
   559  */
   559 
   560 
   560 int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, /**< EtherCAT-Slave */
   561 int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   561                               uint16_t sdo_index, /**< SDO-Index */
   562                               uint16_t sdo_index, /**< SDO index */
   562                               uint8_t sdo_subindex, /**< SDO-Subindex */
   563                               uint8_t sdo_subindex, /**< SDO subindex */
   563                               uint32_t *target /**< Speicher für gel. Wert */
   564                               uint32_t *target /**< memory for read value */
   564                               )
   565                               )
   565 {
   566 {
   566     uint8_t data[4];
   567     uint8_t data[4];
   567     if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
   568     if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
   568     *target = EC_READ_U32(data);
   569     *target = EC_READ_U32(data);
   570 }
   571 }
   571 
   572 
   572 /*****************************************************************************/
   573 /*****************************************************************************/
   573 
   574 
   574 /**
   575 /**
   575    Beschreibt ein 8-Bit CANopen-SDO eines Slaves im Expedited-Modus.
   576    Writes an 8-bit SDO in expedited mode.
   576    \return 0 wenn alles ok, < 0 bei Fehler
   577    \return 0 in case of success, else < 0
   577  */
   578  */
   578 
   579 
   579 int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, /**< EtherCAT-Slave */
   580 int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, /**< EtherCAT slave */
   580                               uint16_t sdo_index, /**< SDO-Index */
   581                               uint16_t sdo_index, /**< SDO index */
   581                               uint8_t sdo_subindex, /**< SDO-Subindex */
   582                               uint8_t sdo_subindex, /**< SDO subindex */
   582                               uint8_t value /**< Neuer Wert */
   583                               uint8_t value /**< new value */
   583                               )
   584                               )
   584 {
   585 {
   585     return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, &value, 1);
   586     return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, &value, 1);
   586 }
   587 }
   587 
   588 
   588 /*****************************************************************************/
   589 /*****************************************************************************/
   589 
   590 
   590 /**
   591 /**
   591    Beschreibt ein 16-Bit CANopen-SDO eines Slaves im Expedited-Modus.
   592    Writes a 16-bit SDO in expedited mode.
   592    \return 0 wenn alles ok, < 0 bei Fehler
   593    \return 0 in case of success, else < 0
   593  */
   594  */
   594 
   595 
   595 int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, /**< EtherCAT-Slave */
   596 int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, /**< EtherCAT slave */
   596                                uint16_t sdo_index, /**< SDO-Index */
   597                                uint16_t sdo_index, /**< SDO index */
   597                                uint8_t sdo_subindex, /**< SDO-Subindex */
   598                                uint8_t sdo_subindex, /**< SDO subindex */
   598                                uint16_t value /**< Neuer Wert */
   599                                uint16_t value /**< new value */
   599                                )
   600                                )
   600 {
   601 {
   601     uint8_t data[2];
   602     uint8_t data[2];
   602     EC_WRITE_U16(data, value);
   603     EC_WRITE_U16(data, value);
   603     return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 2);
   604     return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 2);
   604 }
   605 }
   605 
   606 
   606 /*****************************************************************************/
   607 /*****************************************************************************/
   607 
   608 
   608 /**
   609 /**
   609    Beschreibt ein 32-Bit CANopen-SDO eines Slaves im Expedited-Modus.
   610    Writes a 32-bit SDO in expedited mode.
   610    \return 0 wenn alles ok, < 0 bei Fehler
   611    \return 0 in case of success, else < 0
   611  */
   612  */
   612 
   613 
   613 int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, /**< EtherCAT-Slave */
   614 int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, /**< EtherCAT slave */
   614                                uint16_t sdo_index, /**< SDO-Index */
   615                                uint16_t sdo_index, /**< SDO index */
   615                                uint8_t sdo_subindex, /**< SDO-Subindex */
   616                                uint8_t sdo_subindex, /**< SDO subindex */
   616                                uint32_t value /**< Neuer Wert */
   617                                uint32_t value /**< new value */
   617                                )
   618                                )
   618 {
   619 {
   619     uint8_t data[4];
   620     uint8_t data[4];
   620     EC_WRITE_U32(data, value);
   621     EC_WRITE_U32(data, value);
   621     return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 4);
   622     return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 4);
   630 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp16);
   631 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp16);
   631 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp32);
   632 EXPORT_SYMBOL(ecrt_slave_sdo_write_exp32);
   632 EXPORT_SYMBOL(ecrt_slave_sdo_read);
   633 EXPORT_SYMBOL(ecrt_slave_sdo_read);
   633 
   634 
   634 /*****************************************************************************/
   635 /*****************************************************************************/
   635 
       
   636 /* Emacs-Konfiguration
       
   637 ;;; Local Variables: ***
       
   638 ;;; c-basic-offset:4 ***
       
   639 ;;; End: ***
       
   640 */