master/pdo.c
changeset 933 618ab9e03321
parent 842 40e27e5a8dce
child 934 96241b092fac
equal deleted inserted replaced
932:dbcc06156a60 933:618ab9e03321
   227 
   227 
   228     return 1;
   228     return 1;
   229 }
   229 }
   230 
   230 
   231 /*****************************************************************************/
   231 /*****************************************************************************/
   232 
       
   233 /** Pdo entry constructor.
       
   234  */
       
   235 void ec_pdo_entry_init(
       
   236         ec_pdo_entry_t *entry /**< Pdo entry. */
       
   237         )
       
   238 {
       
   239     entry->name = NULL;
       
   240 }
       
   241 
       
   242 /*****************************************************************************/
       
   243 
       
   244 /** Pdo entry copy constructor.
       
   245  */
       
   246 int ec_pdo_entry_init_copy(
       
   247         ec_pdo_entry_t *entry, /**< Pdo entry. */
       
   248         const ec_pdo_entry_t *other /**< Pdo entry to copy from. */
       
   249         )
       
   250 {
       
   251     entry->index = other->index;
       
   252     entry->subindex = other->subindex;
       
   253     entry->name = NULL;
       
   254     entry->bit_length = other->bit_length;
       
   255 
       
   256     if (ec_pdo_entry_set_name(entry, other->name))
       
   257         return -1;
       
   258 
       
   259     return 0;
       
   260 }
       
   261 
       
   262 /*****************************************************************************/
       
   263 
       
   264 /** Pdo entry destructor.
       
   265  */
       
   266 void ec_pdo_entry_clear(ec_pdo_entry_t *entry /**< Pdo entry. */)
       
   267 {
       
   268     if (entry->name)
       
   269         kfree(entry->name);
       
   270 }
       
   271 
       
   272 /*****************************************************************************/
       
   273 
       
   274 /** Set Pdo entry name.
       
   275  */
       
   276 int ec_pdo_entry_set_name(
       
   277         ec_pdo_entry_t *entry, /**< Pdo entry. */
       
   278         const char *name /**< New name. */
       
   279         )
       
   280 {
       
   281     unsigned int len;
       
   282 
       
   283     if (entry->name)
       
   284         kfree(entry->name);
       
   285 
       
   286     if (name && (len = strlen(name))) {
       
   287         if (!(entry->name = (char *) kmalloc(len + 1, GFP_KERNEL))) {
       
   288             EC_ERR("Failed to allocate Pdo entry name.\n");
       
   289             return -1;
       
   290         }
       
   291         memcpy(entry->name, name, len + 1);
       
   292     } else {
       
   293         entry->name = NULL;
       
   294     }
       
   295 
       
   296     return 0;
       
   297 }
       
   298 
       
   299 /*****************************************************************************/
       
   300 
       
   301 /** Compares two Pdo entries.
       
   302  *
       
   303  * \retval 1 The entries are equal.
       
   304  * \retval 0 The entries differ.
       
   305  */
       
   306 int ec_pdo_entry_equal(
       
   307         const ec_pdo_entry_t *entry1, /**< First Pdo entry. */
       
   308         const ec_pdo_entry_t *entry2 /**< Second Pdo entry. */
       
   309         )
       
   310 {
       
   311     return entry1->index == entry2->index
       
   312         && entry1->subindex == entry2->subindex
       
   313         && entry1->bit_length == entry2->bit_length;
       
   314 }
       
   315 
       
   316 /*****************************************************************************/