master/pdo_entry.c
branchstable-1.4
changeset 1686 e206f4485f60
parent 1685 399ef727bf62
equal deleted inserted replaced
1685:399ef727bf62 1686:e206f4485f60
    35 
    35 
    36 #include "pdo_entry.h"
    36 #include "pdo_entry.h"
    37 
    37 
    38 /*****************************************************************************/
    38 /*****************************************************************************/
    39 
    39 
    40 /** Pdo entry constructor.
    40 /** PDO entry constructor.
    41  */
    41  */
    42 void ec_pdo_entry_init(
    42 void ec_pdo_entry_init(
    43         ec_pdo_entry_t *entry /**< Pdo entry. */
    43         ec_pdo_entry_t *entry /**< PDO entry. */
    44         )
    44         )
    45 {
    45 {
    46     entry->name = NULL;
    46     entry->name = NULL;
    47 }
    47 }
    48 
    48 
    49 /*****************************************************************************/
    49 /*****************************************************************************/
    50 
    50 
    51 /** Pdo entry copy constructor.
    51 /** PDO entry copy constructor.
    52  */
    52  */
    53 int ec_pdo_entry_init_copy(
    53 int ec_pdo_entry_init_copy(
    54         ec_pdo_entry_t *entry, /**< Pdo entry. */
    54         ec_pdo_entry_t *entry, /**< PDO entry. */
    55         const ec_pdo_entry_t *other /**< Pdo entry to copy from. */
    55         const ec_pdo_entry_t *other /**< PDO entry to copy from. */
    56         )
    56         )
    57 {
    57 {
    58     entry->index = other->index;
    58     entry->index = other->index;
    59     entry->subindex = other->subindex;
    59     entry->subindex = other->subindex;
    60     entry->name = NULL;
    60     entry->name = NULL;
    66     return 0;
    66     return 0;
    67 }
    67 }
    68 
    68 
    69 /*****************************************************************************/
    69 /*****************************************************************************/
    70 
    70 
    71 /** Pdo entry destructor.
    71 /** PDO entry destructor.
    72  */
    72  */
    73 void ec_pdo_entry_clear(ec_pdo_entry_t *entry /**< Pdo entry. */)
    73 void ec_pdo_entry_clear(ec_pdo_entry_t *entry /**< PDO entry. */)
    74 {
    74 {
    75     if (entry->name)
    75     if (entry->name)
    76         kfree(entry->name);
    76         kfree(entry->name);
    77 }
    77 }
    78 
    78 
    79 /*****************************************************************************/
    79 /*****************************************************************************/
    80 
    80 
    81 /** Set Pdo entry name.
    81 /** Set PDO entry name.
    82  */
    82  */
    83 int ec_pdo_entry_set_name(
    83 int ec_pdo_entry_set_name(
    84         ec_pdo_entry_t *entry, /**< Pdo entry. */
    84         ec_pdo_entry_t *entry, /**< PDO entry. */
    85         const char *name /**< New name. */
    85         const char *name /**< New name. */
    86         )
    86         )
    87 {
    87 {
    88     unsigned int len;
    88     unsigned int len;
    89 
    89 
    93     if (entry->name)
    93     if (entry->name)
    94         kfree(entry->name);
    94         kfree(entry->name);
    95 
    95 
    96     if (name && (len = strlen(name))) {
    96     if (name && (len = strlen(name))) {
    97         if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
    97         if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
    98             EC_ERR("Failed to allocate Pdo entry name.\n");
    98             EC_ERR("Failed to allocate PDO entry name.\n");
    99             return -1;
    99             return -1;
   100         }
   100         }
   101         memcpy(entry->name, name, len + 1);
   101         memcpy(entry->name, name, len + 1);
   102     } else {
   102     } else {
   103         entry->name = NULL;
   103         entry->name = NULL;
   106     return 0;
   106     return 0;
   107 }
   107 }
   108 
   108 
   109 /*****************************************************************************/
   109 /*****************************************************************************/
   110 
   110 
   111 /** Compares two Pdo entries.
   111 /** Compares two PDO entries.
   112  *
   112  *
   113  * \retval 1 The entries are equal.
   113  * \retval 1 The entries are equal.
   114  * \retval 0 The entries differ.
   114  * \retval 0 The entries differ.
   115  */
   115  */
   116 int ec_pdo_entry_equal(
   116 int ec_pdo_entry_equal(
   117         const ec_pdo_entry_t *entry1, /**< First Pdo entry. */
   117         const ec_pdo_entry_t *entry1, /**< First PDO entry. */
   118         const ec_pdo_entry_t *entry2 /**< Second Pdo entry. */
   118         const ec_pdo_entry_t *entry2 /**< Second PDO entry. */
   119         )
   119         )
   120 {
   120 {
   121     return entry1->index == entry2->index
   121     return entry1->index == entry2->index
   122         && entry1->subindex == entry2->subindex
   122         && entry1->subindex == entry2->subindex
   123         && entry1->bit_length == entry2->bit_length;
   123         && entry1->bit_length == entry2->bit_length;