1 /* |
1 /* |
2 This file is part of CanFestival, a library implementing CanOpen Stack. |
2 This file is part of CanFestival, a library implementing CanOpen |
|
3 Stack. |
3 |
4 |
4 Copyright (C): Edouard TISSERANT and Francis DUPIN |
5 Copyright (C): Edouard TISSERANT and Francis DUPIN |
5 |
6 |
6 See COPYING file for copyrights details. |
7 See COPYING file for copyrights details. |
7 |
8 |
8 This library is free software; you can redistribute it and/or |
9 This library is free software; you can redistribute it and/or |
9 modify it under the terms of the GNU Lesser General Public |
10 modify it under the terms of the GNU Lesser General Public |
10 License as published by the Free Software Foundation; either |
11 License as published by the Free Software Foundation; either |
11 version 2.1 of the License, or (at your option) any later version. |
12 version 2.1 of the License, or (at your option) any later version. |
12 |
13 |
13 This library is distributed in the hope that it will be useful, |
14 This library is distributed in the hope that it will be useful, |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 Lesser General Public License for more details. |
17 Lesser General Public License for more details. |
17 |
18 |
18 You should have received a copy of the GNU Lesser General Public |
19 You should have received a copy of the GNU Lesser General Public |
19 License along with this library; if not, write to the Free Software |
20 License along with this library; if not, write to the Free Software |
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
22 USA |
21 */ |
23 */ |
22 |
24 /*! |
|
25 ** @file nmtMaster.c |
|
26 ** @author Edouard TISSERANT and Francis DUPIN |
|
27 ** @date Tue Jun 5 08:47:18 2007 |
|
28 ** |
|
29 ** @brief |
|
30 ** |
|
31 ** |
|
32 */ |
23 #include "nmtMaster.h" |
33 #include "nmtMaster.h" |
24 #include "canfestival.h" |
34 #include "canfestival.h" |
25 |
35 |
26 /******************************************************************************/ |
36 /*! |
|
37 ** |
|
38 ** |
|
39 ** @param d |
|
40 ** @param Node_ID |
|
41 ** @param cs |
|
42 ** |
|
43 ** @return |
|
44 **/ |
27 UNS8 masterSendNMTstateChange(CO_Data* d, UNS8 Node_ID, UNS8 cs) |
45 UNS8 masterSendNMTstateChange(CO_Data* d, UNS8 Node_ID, UNS8 cs) |
28 { |
46 { |
29 Message m; |
47 Message m; |
30 |
48 |
31 MSG_WAR(0x3501, "Send_NMT cs : ", cs); |
49 MSG_WAR(0x3501, "Send_NMT cs : ", cs); |
32 MSG_WAR(0x3502, " to node : ", Node_ID); |
50 MSG_WAR(0x3502, " to node : ", Node_ID); |
33 /* message configuration */ |
51 /*! message configuration */ |
34 m.cob_id.w = 0x0000; /*(NMT) << 7*/ |
52 m.cob_id.w = 0x0000; /*(NMT) << 7*/ |
35 m.rtr = NOT_A_REQUEST; |
53 m.rtr = NOT_A_REQUEST; |
36 m.len = 2; |
54 m.len = 2; |
37 m.data[0] = cs; |
55 m.data[0] = cs; |
38 m.data[1] = Node_ID; |
56 m.data[1] = Node_ID; |
39 |
57 |
40 return canSend(d->canHandle,&m); |
58 return canSend(d->canHandle,&m); |
41 } |
59 } |
42 |
60 |
43 |
61 |
44 /****************************************************************************/ |
62 /*! |
|
63 ** |
|
64 ** |
|
65 ** @param d |
|
66 ** @param nodeId |
|
67 ** |
|
68 ** @return |
|
69 **/ |
45 UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId) |
70 UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId) |
46 { |
71 { |
47 Message m; |
72 Message m; |
48 |
73 |
49 MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId); |
74 MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId); |
50 |
75 |
51 /* message configuration */ |
76 /* message configuration */ |
52 m.cob_id.w = nodeId | (NODE_GUARD << 7); |
77 m.cob_id.w = nodeId | (NODE_GUARD << 7); |
53 m.rtr = REQUEST; |
78 m.rtr = REQUEST; |
54 m.len = 1; |
79 m.len = 1; |
55 |
80 |
56 return canSend(d->canHandle,&m); |
81 return canSend(d->canHandle,&m); |
57 } |
82 } |
58 |
83 |
59 /******************************************************************************/ |
84 /*! |
|
85 ** |
|
86 ** |
|
87 ** @param d |
|
88 ** @param nodeId |
|
89 **/ |
60 void masterRequestNodeState(CO_Data* d, UNS8 nodeId) |
90 void masterRequestNodeState(CO_Data* d, UNS8 nodeId) |
61 { |
91 { |
62 /* FIXME: should warn for bad toggle bit. */ |
92 /*! FIXME: should warn for bad toggle bit. */ |
63 |
93 |
64 /* NMTable configuration to indicate that the master is waiting |
94 /*! NMTable configuration to indicate that the master is waiting |
65 * for a Node_Guard frame from the slave whose node_id is ID */ |
95 for a Node_Guard frame from the slave whose node_id is ID |
66 d->NMTable[nodeId] = Unknown_state; /* A state that does not exist */ |
96 */ |
|
97 d->NMTable[nodeId] = Unknown_state; /*! A state that does not exist |
|
98 */ |
67 |
99 |
68 if (nodeId == 0) { /* NMT broadcast */ |
100 if (nodeId == 0) { /*! NMT broadcast */ |
69 UNS8 i = 0; |
101 UNS8 i = 0; |
70 for (i = 0 ; i < NMT_MAX_NODE_ID ; i++) { |
102 for (i = 0 ; i < NMT_MAX_NODE_ID ; i++) { |
71 d->NMTable[i] = Unknown_state; |
103 d->NMTable[i] = Unknown_state; |
72 } |
104 } |
73 } |
105 } |
74 masterSendNMTnodeguard(d,nodeId); |
106 masterSendNMTnodeguard(d,nodeId); |
75 } |
107 } |
76 |
108 |
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|