1 /****************************************************************************** |
1 /****************************************************************************** |
2 * |
2 * |
3 * c o m m a n d . c |
|
4 * |
|
5 * Methods of an EtherCAT command. |
|
6 * |
|
7 * $Id$ |
3 * $Id$ |
8 * |
4 * |
|
5 * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
|
6 * |
|
7 * This file is part of the IgH EtherCAT Master. |
|
8 * |
|
9 * The IgH EtherCAT Master is free software; you can redistribute it |
|
10 * and/or modify it under the terms of the GNU General Public License |
|
11 * as published by the Free Software Foundation; version 2 of the License. |
|
12 * |
|
13 * The IgH EtherCAT Master is distributed in the hope that it will be |
|
14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 * GNU General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with the IgH EtherCAT Master; if not, write to the Free Software |
|
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 * |
9 *****************************************************************************/ |
22 *****************************************************************************/ |
|
23 |
|
24 /** |
|
25 \file |
|
26 Methods of an EtherCAT command. |
|
27 */ |
|
28 |
|
29 /*****************************************************************************/ |
10 |
30 |
11 #include <linux/slab.h> |
31 #include <linux/slab.h> |
12 #include <linux/delay.h> |
32 #include <linux/delay.h> |
13 |
33 |
14 #include "command.h" |
34 #include "command.h" |
15 #include "master.h" |
35 #include "master.h" |
16 |
36 |
17 /*****************************************************************************/ |
37 /*****************************************************************************/ |
|
38 |
|
39 /** \cond */ |
18 |
40 |
19 #define EC_FUNC_HEADER \ |
41 #define EC_FUNC_HEADER \ |
20 if (unlikely(ec_command_prealloc(command, data_size))) \ |
42 if (unlikely(ec_command_prealloc(command, data_size))) \ |
21 return -1; \ |
43 return -1; \ |
22 command->index = 0; \ |
44 command->index = 0; \ |
26 #define EC_FUNC_FOOTER \ |
48 #define EC_FUNC_FOOTER \ |
27 command->data_size = data_size; \ |
49 command->data_size = data_size; \ |
28 memset(command->data, 0x00, data_size); \ |
50 memset(command->data, 0x00, data_size); \ |
29 return 0; |
51 return 0; |
30 |
52 |
|
53 /** \endcond */ |
|
54 |
31 /*****************************************************************************/ |
55 /*****************************************************************************/ |
32 |
56 |
33 /** |
57 /** |
34 Command constructor. |
58 Command constructor. |
35 */ |
59 */ |
36 |
60 |
37 void ec_command_init(ec_command_t *command) |
61 void ec_command_init(ec_command_t *command /**< EtherCAT command */) |
38 { |
62 { |
39 command->type = EC_CMD_NONE; |
63 command->type = EC_CMD_NONE; |
40 command->address.logical = 0x00000000; |
64 command->address.logical = 0x00000000; |
41 command->data = NULL; |
65 command->data = NULL; |
42 command->mem_size = 0; |
66 command->mem_size = 0; |
50 |
74 |
51 /** |
75 /** |
52 Command destructor. |
76 Command destructor. |
53 */ |
77 */ |
54 |
78 |
55 void ec_command_clear(ec_command_t *command) |
79 void ec_command_clear(ec_command_t *command /**< EtherCAT command */) |
56 { |
80 { |
57 if (command->data) kfree(command->data); |
81 if (command->data) kfree(command->data); |
58 } |
82 } |
59 |
83 |
60 /*****************************************************************************/ |
84 /*****************************************************************************/ |
61 |
85 |
62 /** |
86 /** |
63 Allocates command data memory. |
87 Allocates command data memory. |
64 \return 0 in case of success, else < 0 |
88 If the allocated memory is already larger than requested, nothing ist done. |
65 */ |
89 \return 0 in case of success, else < 0 |
66 |
90 */ |
67 int ec_command_prealloc(ec_command_t *command, size_t size) |
91 |
|
92 int ec_command_prealloc(ec_command_t *command, /**< EtherCAT command */ |
|
93 size_t size /**< New size in bytes */ |
|
94 ) |
68 { |
95 { |
69 if (size <= command->mem_size) return 0; |
96 if (size <= command->mem_size) return 0; |
70 |
97 |
71 if (command->data) { |
98 if (command->data) { |
72 kfree(command->data); |
99 kfree(command->data); |