fp@627: /****************************************************************************** fp@627: * fp@627: * $Id$ fp@627: * fp@627: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@627: * fp@627: * This file is part of the IgH EtherCAT Master. fp@627: * fp@627: * The IgH EtherCAT Master is free software; you can redistribute it fp@627: * and/or modify it under the terms of the GNU General Public License fp@627: * as published by the Free Software Foundation; either version 2 of the fp@627: * License, or (at your option) any later version. fp@627: * fp@627: * The IgH EtherCAT Master is distributed in the hope that it will be fp@627: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@627: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@627: * GNU General Public License for more details. fp@627: * fp@627: * You should have received a copy of the GNU General Public License fp@627: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@627: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@627: * fp@627: * The right to use EtherCAT Technology is granted and comes free of fp@627: * charge under condition of compatibility of product made by fp@627: * Licensee. People intending to distribute/sell products based on the fp@627: * code, have to sign an agreement to guarantee that products using fp@627: * software based on IgH EtherCAT master stay compatible with the actual fp@627: * EtherCAT specification (which are released themselves as an open fp@627: * standard) as the (only) precondition to have the right to use EtherCAT fp@627: * Technology, IP and trade marks. fp@627: * fp@627: *****************************************************************************/ fp@627: fp@627: /** fp@627: \file fp@627: EtherCAT process data object methods. fp@627: */ fp@627: fp@627: /*****************************************************************************/ fp@627: fp@627: #include fp@627: fp@627: #include "pdo.h" fp@627: fp@627: /*****************************************************************************/ fp@627: fp@627: /** fp@627: * PDO constructor. fp@627: */ fp@627: fp@627: void ec_pdo_init(ec_pdo_t *pdo /**< EtherCAT PDO */) fp@627: { fp@627: pdo->name = NULL; fp@627: INIT_LIST_HEAD(&pdo->entries); fp@627: } fp@627: fp@627: /*****************************************************************************/ fp@627: fp@627: /** fp@627: * PDO destructor. fp@627: */ fp@627: fp@627: void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT PDO */) fp@627: { fp@627: ec_pdo_entry_t *entry, *next; fp@627: fp@627: // free all PDO entries fp@627: list_for_each_entry_safe(entry, next, &pdo->entries, list) { fp@627: list_del(&entry->list); fp@627: kfree(entry); fp@627: } fp@627: } fp@627: fp@627: /*****************************************************************************/ fp@627: fp@627: /** fp@627: * Makes a deep copy of a PDO. fp@627: */ fp@627: fp@627: int ec_pdo_copy(ec_pdo_t *pdo, const ec_pdo_t *other_pdo) fp@627: { fp@627: ec_pdo_entry_t *entry, *other_entry, *next; fp@627: fp@627: // make flat copy fp@627: *pdo = *other_pdo; fp@627: fp@627: INIT_LIST_HEAD(&pdo->entries); fp@627: list_for_each_entry(other_entry, &other_pdo->entries, list) { fp@627: if (!(entry = (ec_pdo_entry_t *) fp@627: kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { fp@627: EC_ERR("Failed to allocate memory for PDO entry copy.\n"); fp@627: goto out_free; fp@627: } fp@627: fp@627: *entry = *other_entry; // flat copy is sufficient fp@627: list_add_tail(&entry->list, &pdo->entries); fp@627: } fp@627: fp@627: return 0; fp@627: fp@627: out_free: fp@627: list_for_each_entry_safe(entry, next, &pdo->entries, list) { fp@627: list_del(&entry->list); fp@627: kfree(entry); fp@627: } fp@627: return -1; fp@627: } fp@627: fp@627: /*****************************************************************************/