master/datagram.c
branchstable-1.5
changeset 2419 fdb85a806585
parent 2269 1d0711235a61
child 2421 bc2d4bf9cbe5
equal deleted inserted replaced
2417:63bef67e812b 2419:fdb85a806585
    86 /** Constructor.
    86 /** Constructor.
    87  */
    87  */
    88 void ec_datagram_init(ec_datagram_t *datagram /**< EtherCAT datagram. */)
    88 void ec_datagram_init(ec_datagram_t *datagram /**< EtherCAT datagram. */)
    89 {
    89 {
    90     INIT_LIST_HEAD(&datagram->queue); // mark as unqueued
    90     INIT_LIST_HEAD(&datagram->queue); // mark as unqueued
       
    91     datagram->device_index = EC_DEVICE_MAIN;
    91     datagram->type = EC_DATAGRAM_NONE;
    92     datagram->type = EC_DATAGRAM_NONE;
    92     memset(datagram->address, 0x00, EC_ADDR_LEN);
    93     memset(datagram->address, 0x00, EC_ADDR_LEN);
    93     datagram->data = NULL;
    94     datagram->data = NULL;
    94     datagram->data_origin = EC_ORIG_INTERNAL;
    95     datagram->data_origin = EC_ORIG_INTERNAL;
    95     datagram->mem_size = 0;
    96     datagram->mem_size = 0;
   425 
   426 
   426 /*****************************************************************************/
   427 /*****************************************************************************/
   427 
   428 
   428 /** Initializes an EtherCAT LRD datagram.
   429 /** Initializes an EtherCAT LRD datagram.
   429  *
   430  *
       
   431  * \return Return value of ec_datagram_prealloc().
       
   432  */
       
   433 int ec_datagram_lrd(
       
   434         ec_datagram_t *datagram, /**< EtherCAT datagram. */
       
   435         uint32_t offset, /**< Logical address. */
       
   436         size_t data_size /**< Number of bytes to read/write. */
       
   437         )
       
   438 {
       
   439     int ret;
       
   440     EC_FUNC_HEADER;
       
   441     datagram->type = EC_DATAGRAM_LRD;
       
   442     EC_WRITE_U32(datagram->address, offset);
       
   443     EC_FUNC_FOOTER;
       
   444 }
       
   445 
       
   446 /*****************************************************************************/
       
   447 
       
   448 /** Initializes an EtherCAT LWR datagram.
       
   449  *
       
   450  * \return Return value of ec_datagram_prealloc().
       
   451  */
       
   452 int ec_datagram_lwr(
       
   453         ec_datagram_t *datagram, /**< EtherCAT datagram. */
       
   454         uint32_t offset, /**< Logical address. */
       
   455         size_t data_size /**< Number of bytes to read/write. */
       
   456         )
       
   457 {
       
   458     int ret;
       
   459     EC_FUNC_HEADER;
       
   460     datagram->type = EC_DATAGRAM_LWR;
       
   461     EC_WRITE_U32(datagram->address, offset);
       
   462     EC_FUNC_FOOTER;
       
   463 }
       
   464 
       
   465 /*****************************************************************************/
       
   466 
       
   467 /** Initializes an EtherCAT LRW datagram.
       
   468  *
       
   469  * \return Return value of ec_datagram_prealloc().
       
   470  */
       
   471 int ec_datagram_lrw(
       
   472         ec_datagram_t *datagram, /**< EtherCAT datagram. */
       
   473         uint32_t offset, /**< Logical address. */
       
   474         size_t data_size /**< Number of bytes to read/write. */
       
   475         )
       
   476 {
       
   477     int ret;
       
   478     EC_FUNC_HEADER;
       
   479     datagram->type = EC_DATAGRAM_LRW;
       
   480     EC_WRITE_U32(datagram->address, offset);
       
   481     EC_FUNC_FOOTER;
       
   482 }
       
   483 
       
   484 /*****************************************************************************/
       
   485 
       
   486 /** Initializes an EtherCAT LRD datagram with external memory.
       
   487  *
   430  * \attention It is assumed, that the external memory is at least \a data_size
   488  * \attention It is assumed, that the external memory is at least \a data_size
   431  *            bytes large.
   489  *            bytes large.
   432  *
   490  *
   433  * \return Return value of ec_datagram_prealloc().
   491  * \return Return value of ec_datagram_prealloc().
   434  */
   492  */
   435 int ec_datagram_lrd(
   493 int ec_datagram_lrd_ext(
   436         ec_datagram_t *datagram, /**< EtherCAT datagram. */
   494         ec_datagram_t *datagram, /**< EtherCAT datagram. */
   437         uint32_t offset, /**< Logical address. */
   495         uint32_t offset, /**< Logical address. */
   438         size_t data_size, /**< Number of bytes to read/write. */
   496         size_t data_size, /**< Number of bytes to read/write. */
   439         uint8_t *external_memory /**< Pointer to the memory to use. */
   497         uint8_t *external_memory /**< Pointer to the memory to use. */
   440         )
   498         )
   448     EC_FUNC_FOOTER;
   506     EC_FUNC_FOOTER;
   449 }
   507 }
   450 
   508 
   451 /*****************************************************************************/
   509 /*****************************************************************************/
   452 
   510 
   453 /** Initializes an EtherCAT LWR datagram.
   511 /** Initializes an EtherCAT LWR datagram with external memory.
   454  *
   512  *
   455  * \attention It is assumed, that the external memory is at least \a data_size
   513  * \attention It is assumed, that the external memory is at least \a data_size
   456  *            bytes large.
   514  *            bytes large.
   457  *
   515  *
   458  * \return Return value of ec_datagram_prealloc().
   516  * \return Return value of ec_datagram_prealloc().
   459  */
   517  */
   460 int ec_datagram_lwr(
   518 int ec_datagram_lwr_ext(
   461         ec_datagram_t *datagram, /**< EtherCAT datagram. */
   519         ec_datagram_t *datagram, /**< EtherCAT datagram. */
   462         uint32_t offset, /**< Logical address. */
   520         uint32_t offset, /**< Logical address. */
   463         size_t data_size, /**< Number of bytes to read/write. */
   521         size_t data_size, /**< Number of bytes to read/write. */
   464         uint8_t *external_memory /**< Pointer to the memory to use. */
   522         uint8_t *external_memory /**< Pointer to the memory to use. */
   465         )
   523         )
   473     EC_FUNC_FOOTER;
   531     EC_FUNC_FOOTER;
   474 }
   532 }
   475 
   533 
   476 /*****************************************************************************/
   534 /*****************************************************************************/
   477 
   535 
   478 /** Initializes an EtherCAT LRW datagram.
   536 /** Initializes an EtherCAT LRW datagram with external memory.
   479  *
   537  *
   480  * \attention It is assumed, that the external memory is at least \a data_size
   538  * \attention It is assumed, that the external memory is at least \a data_size
   481  *            bytes large.
   539  *            bytes large.
   482  *
   540  *
   483  * \return Return value of ec_datagram_prealloc().
   541  * \return Return value of ec_datagram_prealloc().
   484  */
   542  */
   485 int ec_datagram_lrw(
   543 int ec_datagram_lrw_ext(
   486         ec_datagram_t *datagram, /**< EtherCAT datagram. */
   544         ec_datagram_t *datagram, /**< EtherCAT datagram. */
   487         uint32_t offset, /**< Logical address. */
   545         uint32_t offset, /**< Logical address. */
   488         size_t data_size, /**< Number of bytes to read/write. */
   546         size_t data_size, /**< Number of bytes to read/write. */
   489         uint8_t *external_memory /**< Pointer to the memory to use. */
   547         uint8_t *external_memory /**< Pointer to the memory to use. */
   490         )
   548         )