author | luis |
Thu, 29 Nov 2007 11:58:02 +0100 | |
changeset 319 | 4b331759169a |
parent 314 | 68e83c3ffbb5 |
child 320 | f82e758840bd |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
This file is part of CanFestival, a library implementing CanOpen Stack. |
|
3 |
||
4 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
|
5 |
||
6 |
See COPYING file for copyrights details. |
|
7 |
||
8 |
This library is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU Lesser General Public |
|
10 |
License as published by the Free Software Foundation; either |
|
11 |
version 2.1 of the License, or (at your option) any later version. |
|
12 |
||
13 |
This library is distributed in the hope that it will be useful, |
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
Lesser General Public License for more details. |
|
17 |
||
18 |
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 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 |
*/ |
|
22 |
||
23 |
#ifndef __data_h__ |
|
24 |
#define __data_h__ |
|
25 |
||
251 | 26 |
#ifdef __cplusplus |
27 |
extern "C" { |
|
28 |
#endif |
|
29 |
||
71 | 30 |
/* declaration of CO_Data type let us include all necessary headers |
31 |
struct struct_CO_Data can then be defined later |
|
32 |
*/ |
|
0 | 33 |
typedef struct struct_CO_Data CO_Data; |
34 |
||
145
e747d2e26af0
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents:
91
diff
changeset
|
35 |
#include "applicfg.h" |
0 | 36 |
#include "def.h" |
37 |
#include "can.h" |
|
38 |
#include "objdictdef.h" |
|
39 |
#include "objacces.h" |
|
40 |
#include "sdo.h" |
|
41 |
#include "pdo.h" |
|
42 |
#include "states.h" |
|
43 |
#include "lifegrd.h" |
|
44 |
#include "sync.h" |
|
45 |
#include "nmtMaster.h" |
|
284 | 46 |
#include "emcy.h" |
0 | 47 |
|
71 | 48 |
/* This structurs contains all necessary information for a CanOpen node */ |
0 | 49 |
struct struct_CO_Data { |
71 | 50 |
/* Object dictionary */ |
0 | 51 |
UNS8 *bDeviceNodeId; |
52 |
const indextable *objdict; |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
204
diff
changeset
|
53 |
s_PDO_status *PDO_status; |
0 | 54 |
quick_index *firstIndex; |
55 |
quick_index *lastIndex; |
|
56 |
UNS16 *ObjdictSize; |
|
57 |
const UNS8 *iam_a_slave; |
|
58 |
valueRangeTest_t valueRangeTest; |
|
59 |
||
71 | 60 |
/* SDO */ |
0 | 61 |
s_transfer transfers[SDO_MAX_SIMULTANEOUS_TRANSFERTS]; |
71 | 62 |
/* s_sdo_parameter *sdo_parameters; */ |
0 | 63 |
|
71 | 64 |
/* State machine */ |
0 | 65 |
e_nodeState nodeState; |
66 |
s_state_communication CurrentCommunicationState; |
|
67 |
initialisation_t initialisation; |
|
68 |
preOperational_t preOperational; |
|
69 |
operational_t operational; |
|
70 |
stopped_t stopped; |
|
71 |
||
71 | 72 |
/* NMT-heartbeat */ |
0 | 73 |
UNS8 *ConsumerHeartbeatCount; |
74 |
UNS32 *ConsumerHeartbeatEntries; |
|
75 |
TIMER_HANDLE *ConsumerHeartBeatTimers; |
|
76 |
UNS16 *ProducerHeartBeatTime; |
|
77 |
TIMER_HANDLE ProducerHeartBeatTimer; |
|
78 |
heartbeatError_t heartbeatError; |
|
79 |
e_nodeState NMTable[NMT_MAX_NODE_ID]; |
|
80 |
||
71 | 81 |
/* SYNC */ |
0 | 82 |
TIMER_HANDLE syncTimer; |
83 |
UNS32 *COB_ID_Sync; |
|
84 |
UNS32 *Sync_Cycle_Period; |
|
71 | 85 |
/*UNS32 *Sync_window_length;;*/ |
0 | 86 |
post_sync_t post_sync; |
87 |
post_TPDO_t post_TPDO; |
|
88 |
||
71 | 89 |
/* General */ |
0 | 90 |
UNS8 toggle; |
149 | 91 |
CAN_HANDLE canHandle; |
0 | 92 |
scanIndexOD_t scanIndexOD; |
161
c4908cc776a9
SetODEntry now call CO_data->storeODSubEntry(Index,SubIndex) for variables to be Stored (when column Save==True in GUI)
etisserant
parents:
149
diff
changeset
|
93 |
storeODSubIndex_t storeODSubIndex; |
178 | 94 |
|
95 |
/* DCF concise */ |
|
204
44ce74232ccb
Some fixes for visual studio C compiler compatiblity.
etisserant
parents:
178
diff
changeset
|
96 |
UNS8* dcf_cursor; |
178 | 97 |
UNS32 dcf_count_targets; |
98 |
||
284 | 99 |
/* EMCY */ |
100 |
e_errorState error_state; |
|
101 |
UNS8 error_history_size; |
|
102 |
UNS8* error_number; |
|
103 |
UNS32* error_first_element; |
|
104 |
UNS8* error_register; |
|
314
68e83c3ffbb5
Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents:
284
diff
changeset
|
105 |
UNS32* error_cobid; |
284 | 106 |
s_errors error_data[EMCY_MAX_ERRORS]; |
107 |
post_emcy_t post_emcy; |
|
108 |
||
0 | 109 |
}; |
110 |
||
91
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
111 |
#define NMTable_Initializer Unknown_state, |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
112 |
|
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
113 |
#define s_transfer_Initializer {\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
114 |
0, /* nodeId */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
115 |
0, /* wohami */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
116 |
SDO_RESET, /* state */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
117 |
0, /* toggle */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
118 |
0, /* abortCode */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
119 |
0, /* index */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
120 |
0, /* subIndex */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
121 |
0, /* count */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
122 |
0, /* offset */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
123 |
{0}, /* data (static use, so that all the table is initialize at 0)*/\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
124 |
0, /* dataType */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
125 |
-1, /* timer */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
126 |
NULL /* Callback */\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
127 |
}, |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
128 |
|
284 | 129 |
#define ERROR_DATA_INITIALIZER \ |
130 |
{\ |
|
131 |
0, /* errCode */\ |
|
132 |
0, /* errRegMask */\ |
|
133 |
0 /* active */\ |
|
134 |
}, |
|
135 |
||
71 | 136 |
/* A macro to initialize the data in client app.*/ |
78 | 137 |
/* CO_Data structure */ |
0 | 138 |
#define CANOPEN_NODE_DATA_INITIALIZER(NODE_PREFIX) {\ |
139 |
/* Object dictionary*/\ |
|
78 | 140 |
& NODE_PREFIX ## _bDeviceNodeId, /* bDeviceNodeId */\ |
141 |
NODE_PREFIX ## _objdict, /* objdict */\ |
|
235
f812bf6b7237
Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents:
204
diff
changeset
|
142 |
NODE_PREFIX ## _PDO_status, /* PDO_status */\ |
78 | 143 |
& NODE_PREFIX ## _firstIndex, /* firstIndex */\ |
144 |
& NODE_PREFIX ## _lastIndex, /* lastIndex */\ |
|
145 |
& NODE_PREFIX ## _ObjdictSize, /* ObjdictSize */\ |
|
146 |
& NODE_PREFIX ## _iam_a_slave, /* iam_a_slave */\ |
|
147 |
NODE_PREFIX ## _valueRangeTest, /* valueRangeTest */\ |
|
0 | 148 |
\ |
78 | 149 |
/* SDO, structure s_transfer */\ |
91
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
150 |
{\ |
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
151 |
REPEAT_SDO_MAX_SIMULTANEOUS_TRANSFERTS_TIMES(s_transfer_Initializer)\ |
78 | 152 |
},\ |
0 | 153 |
\ |
78 | 154 |
/* State machine*/\ |
155 |
Unknown_state, /* nodeState */\ |
|
156 |
/* structure s_state_communication */\ |
|
157 |
{\ |
|
158 |
0, /* csBoot_Up */\ |
|
159 |
0, /* csSDO */\ |
|
160 |
0, /* csEmergency */\ |
|
161 |
0, /* csSYNC */\ |
|
162 |
0, /* csHeartbeat */\ |
|
163 |
0 /* csPDO */\ |
|
164 |
},\ |
|
167 | 165 |
_initialisation, /* initialisation */\ |
166 |
_preOperational, /* preOperational */\ |
|
167 |
_operational, /* operational */\ |
|
168 |
_stopped, /* stopped */\ |
|
0 | 169 |
\ |
170 |
/* NMT-heartbeat */\ |
|
78 | 171 |
& NODE_PREFIX ## _highestSubIndex_obj1016, /* ConsumerHeartbeatCount */\ |
172 |
NODE_PREFIX ## _obj1016, /* ConsumerHeartbeatEntries */\ |
|
173 |
NODE_PREFIX ## _heartBeatTimers, /* ConsumerHeartBeatTimers */\ |
|
174 |
& NODE_PREFIX ## _obj1017, /* ProducerHeartBeatTime */\ |
|
175 |
TIMER_NONE, /* ProducerHeartBeatTimer */\ |
|
167 | 176 |
_heartbeatError, /* heartbeatError */\ |
78 | 177 |
\ |
91
ed2612282988
- Better array initialization in data.h CANOPEN_NODE_DATA_INITIALIZER macro. Use a little hack with configure and config.h to create the "pure Ansi C" initializer.
etisserant
parents:
78
diff
changeset
|
178 |
{REPEAT_NMT_MAX_NODE_ID_TIMES(NMTable_Initializer)},\ |
78 | 179 |
/* is well initialized at "Unknown_state". Is it ok ? (FD)*/\ |
0 | 180 |
\ |
181 |
/* SYNC */\ |
|
78 | 182 |
TIMER_NONE, /* syncTimer */\ |
183 |
& NODE_PREFIX ## _obj1005, /* COB_ID_Sync */\ |
|
184 |
& NODE_PREFIX ## _obj1006, /* Sync_Cycle_Period */\ |
|
185 |
/*& NODE_PREFIX ## _obj1007, */ /* Sync_window_length */\ |
|
167 | 186 |
_post_sync, /* post_sync */\ |
187 |
_post_TPDO, /* post_TPDO */\ |
|
0 | 188 |
\ |
189 |
/* General */\ |
|
78 | 190 |
0, /* toggle */\ |
167 | 191 |
NULL, /* canSend */\ |
161
c4908cc776a9
SetODEntry now call CO_data->storeODSubEntry(Index,SubIndex) for variables to be Stored (when column Save==True in GUI)
etisserant
parents:
149
diff
changeset
|
192 |
NODE_PREFIX ## _scanIndexOD, /* scanIndexOD */\ |
178 | 193 |
_storeODSubIndex, /* storeODSubIndex */\ |
194 |
NULL, /*dcf_cursor*/\ |
|
284 | 195 |
1, /*dcf_count_targets*/\ |
196 |
\ |
|
197 |
/* EMCY */\ |
|
198 |
Error_free, /* error_state */\ |
|
199 |
sizeof(NODE_PREFIX ## _obj1003) / sizeof(NODE_PREFIX ## _obj1003[0]), /* error_history_size */\ |
|
200 |
& NODE_PREFIX ## _highestSubIndex_obj1003, /* error_number */\ |
|
201 |
& NODE_PREFIX ## _obj1003[0], /* error_first_element */\ |
|
202 |
& NODE_PREFIX ## _obj1001, /* error_register */\ |
|
314
68e83c3ffbb5
Better EMCY support. Now EMCY COB-ID depend on OD 1014h entry, as told in DS-301.
etisserant
parents:
284
diff
changeset
|
203 |
& NODE_PREFIX ## _obj1014, /* error_cobid */\ |
284 | 204 |
/* error_data: structure s_errors */\ |
205 |
{\ |
|
206 |
REPEAT_EMCY_MAX_ERRORS_TIMES(ERROR_DATA_INITIALIZER)\ |
|
207 |
},\ |
|
208 |
_post_emcy /* post_emcy */\ |
|
0 | 209 |
} |
210 |
||
251 | 211 |
#ifdef __cplusplus |
212 |
}; |
|
213 |
#endif |
|
214 |
||
71 | 215 |
#endif /* __data_h__ */ |
0 | 216 |
|
217 |