]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - include/data.h
Automatic SDO server added when creating new slave node.
[CanFestival-3.git] / include / data.h
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
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /* declaration of CO_Data type let us include all necessary headers
31  struct struct_CO_Data can then be defined later
32  */
33 typedef struct struct_CO_Data CO_Data;
34
35 #include "applicfg.h"
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 "nmtSlave.h"
46 #include "nmtMaster.h"
47 #include "emcy.h"
48 #ifdef CO_ENABLE_LSS
49 #include "lss.h"
50 #endif
51
52 /* This structurs contains all necessary information for a CanOpen node */
53 struct struct_CO_Data {
54         /* Object dictionary */
55         UNS8 *bDeviceNodeId;
56         const indextable *objdict;
57         s_PDO_status *PDO_status;
58         const quick_index *firstIndex;
59         const quick_index *lastIndex;
60         const UNS16 *ObjdictSize;
61         const UNS8 *iam_a_slave;
62         valueRangeTest_t valueRangeTest;
63         
64         /* SDO */
65         s_transfer transfers[SDO_MAX_SIMULTANEOUS_TRANSFERTS];
66         /* s_sdo_parameter *sdo_parameters; */
67
68         /* State machine */
69         e_nodeState nodeState;
70         s_state_communication CurrentCommunicationState;
71         initialisation_t initialisation;
72         preOperational_t preOperational;
73         operational_t operational;
74         stopped_t stopped;
75      void (*NMT_Slave_Node_Reset_Callback)(CO_Data*);
76      void (*NMT_Slave_Communications_Reset_Callback)(CO_Data*);
77      
78         /* NMT-heartbeat */
79         UNS8 *ConsumerHeartbeatCount;
80         UNS32 *ConsumerHeartbeatEntries;
81         TIMER_HANDLE *ConsumerHeartBeatTimers;
82         UNS16 *ProducerHeartBeatTime;
83         TIMER_HANDLE ProducerHeartBeatTimer;
84         heartbeatError_t heartbeatError;
85         e_nodeState NMTable[NMT_MAX_NODE_ID]; 
86
87         /* SYNC */
88         TIMER_HANDLE syncTimer;
89         UNS32 *COB_ID_Sync;
90         UNS32 *Sync_Cycle_Period;
91         /*UNS32 *Sync_window_length;;*/
92         post_sync_t post_sync;
93         post_TPDO_t post_TPDO;
94         post_SlaveBootup_t post_SlaveBootup;
95         
96         /* General */
97         UNS8 toggle;
98         CAN_PORT canHandle;     
99         scanIndexOD_t scanIndexOD;
100         storeODSubIndex_t storeODSubIndex; 
101         
102         /* DCF concise */
103     const indextable* dcf_odentry;
104         UNS8* dcf_cursor;
105         UNS32 dcf_entries_count;
106         UNS8 dcf_request;
107         
108         /* EMCY */
109         e_errorState error_state;
110         UNS8 error_history_size;
111         UNS8* error_number;
112         UNS32* error_first_element;
113         UNS8* error_register;
114     UNS32* error_cobid;
115         s_errors error_data[EMCY_MAX_ERRORS];
116         post_emcy_t post_emcy;
117         
118 #ifdef CO_ENABLE_LSS
119         /* LSS */
120         lss_transfer_t lss_transfer;
121         lss_StoreConfiguration_t lss_StoreConfiguration;
122 #endif  
123 };
124
125 #define NMTable_Initializer Unknown_state,
126
127 #define s_transfer_Initializer {\
128                 0,          /* nodeId */\
129                 0,          /* wohami */\
130                 SDO_RESET,  /* state */\
131                 0,          /* toggle */\
132                 0,          /* abortCode */\
133                 0,          /* index */\
134                 0,          /* subIndex */\
135                 0,          /* count */\
136                 0,          /* offset */\
137                 {0},        /* data (static use, so that all the table is initialize at 0)*/\
138                 0,          /* dataType */\
139                 -1,         /* timer */\
140                 NULL        /* Callback */\
141           },
142
143 #define ERROR_DATA_INITIALIZER \
144         {\
145         0, /* errCode */\
146         0, /* errRegMask */\
147         0 /* active */\
148         },
149         
150 #ifdef CO_ENABLE_LSS
151
152 #ifdef CO_ENABLE_LSS_FS 
153 #define lss_fs_Initializer \
154                 ,0,                                             /* IDNumber */\
155                 128,                                    /* BitChecked */\
156                 0,                                              /* LSSSub */\
157                 0,                                              /* LSSNext */\
158                 0,                                              /* LSSPos */\
159                 LSS_FS_RESET,                   /* FastScan_SM */\
160                 -1                                              /* timerFS */
161 #else
162 #define lss_fs_Initializer
163 #endif          
164
165 #define lss_Initializer {\
166                 LSS_RESET,                      /* state */\
167                 0,                                              /* command */\
168                 LSS_WAITING_MODE,               /* mode */\
169                 0,                                              /* dat1 */\
170                 0,                                              /* dat2 */\
171                 0,                              /* NodeID */\
172                 0,                              /* addr_sel_match */\
173                 0,                              /* addr_ident_match */\
174                 "none",                         /* BaudRate */\
175                 0,                              /* SwitchDelay */\
176                 SDELAY_OFF,                     /* SwitchDelayState */\
177                 NULL,                                   /* canHandle_t */\
178                 -1,                                             /* TimerMSG */\
179                 -1,                             /* TimerSDELAY */\
180                 NULL,                           /* Callback */\
181                 0                                               /* LSSanswer */\
182                 lss_fs_Initializer              /*FastScan service initialization */\
183           },\
184           NULL  /* _lss_StoreConfiguration*/
185 #else
186 #define lss_Initializer
187 #endif
188
189
190 /* A macro to initialize the data in client app.*/
191 /* CO_Data structure */
192 #define CANOPEN_NODE_DATA_INITIALIZER(NODE_PREFIX) {\
193         /* Object dictionary*/\
194         & NODE_PREFIX ## _bDeviceNodeId,     /* bDeviceNodeId */\
195         NODE_PREFIX ## _objdict,             /* objdict  */\
196         NODE_PREFIX ## _PDO_status,          /* PDO_status */\
197         & NODE_PREFIX ## _firstIndex,        /* firstIndex */\
198         & NODE_PREFIX ## _lastIndex,         /* lastIndex */\
199         & NODE_PREFIX ## _ObjdictSize,       /* ObjdictSize */\
200         & NODE_PREFIX ## _iam_a_slave,       /* iam_a_slave */\
201         NODE_PREFIX ## _valueRangeTest,      /* valueRangeTest */\
202         \
203         /* SDO, structure s_transfer */\
204         {\
205           REPEAT_SDO_MAX_SIMULTANEOUS_TRANSFERTS_TIMES(s_transfer_Initializer)\
206         },\
207         \
208         /* State machine*/\
209         Unknown_state,      /* nodeState */\
210         /* structure s_state_communication */\
211         {\
212                 0,          /* csBoot_Up */\
213                 0,          /* csSDO */\
214                 0,          /* csEmergency */\
215                 0,          /* csSYNC */\
216                 0,          /* csHeartbeat */\
217                 0,           /* csPDO */\
218                 0           /* csLSS */\
219         },\
220         _initialisation,     /* initialisation */\
221         _preOperational,     /* preOperational */\
222         _operational,        /* operational */\
223         _stopped,            /* stopped */\
224         NULL,                /* NMT node reset callback */\
225         NULL,                /* NMT communications reset callback */\
226         \
227         /* NMT-heartbeat */\
228         & NODE_PREFIX ## _highestSubIndex_obj1016, /* ConsumerHeartbeatCount */\
229         NODE_PREFIX ## _obj1016,                   /* ConsumerHeartbeatEntries */\
230         NODE_PREFIX ## _heartBeatTimers,           /* ConsumerHeartBeatTimers  */\
231         & NODE_PREFIX ## _obj1017,                 /* ProducerHeartBeatTime */\
232         TIMER_NONE,                                /* ProducerHeartBeatTimer */\
233         _heartbeatError,           /* heartbeatError */\
234         \
235         {REPEAT_NMT_MAX_NODE_ID_TIMES(NMTable_Initializer)},\
236                                                    /* is  well initialized at "Unknown_state". Is it ok ? (FD)*/\
237         \
238         /* SYNC */\
239         TIMER_NONE,                                /* syncTimer */\
240         & NODE_PREFIX ## _obj1005,                 /* COB_ID_Sync */\
241         & NODE_PREFIX ## _obj1006,                 /* Sync_Cycle_Period */\
242         /*& NODE_PREFIX ## _obj1007, */            /* Sync_window_length */\
243         _post_sync,                 /* post_sync */\
244         _post_TPDO,                 /* post_TPDO */\
245         _post_SlaveBootup,                      /* post_SlaveBootup */\
246         \
247         /* General */\
248         0,                                         /* toggle */\
249         NULL,                   /* canSend */\
250         NODE_PREFIX ## _scanIndexOD,                /* scanIndexOD */\
251         _storeODSubIndex,                /* storeODSubIndex */\
252     /* DCF concise */\
253     NULL,       /*dcf_odentry*/\
254         NULL,           /*dcf_cursor*/\
255         1,              /*dcf_entries_count*/\
256         0,              /* dcf_request*/\
257         \
258         /* EMCY */\
259         Error_free,                      /* error_state */\
260         sizeof(NODE_PREFIX ## _obj1003) / sizeof(NODE_PREFIX ## _obj1003[0]),      /* error_history_size */\
261         & NODE_PREFIX ## _highestSubIndex_obj1003,    /* error_number */\
262         & NODE_PREFIX ## _obj1003[0],    /* error_first_element */\
263         & NODE_PREFIX ## _obj1001,       /* error_register */\
264     & NODE_PREFIX ## _obj1014,       /* error_cobid */\
265         /* error_data: structure s_errors */\
266         {\
267         REPEAT_EMCY_MAX_ERRORS_TIMES(ERROR_DATA_INITIALIZER)\
268         },\
269         _post_emcy,              /* post_emcy */\
270         /* LSS */\
271         lss_Initializer\
272 }
273
274 #ifdef __cplusplus
275 };
276 #endif
277
278 #endif /* __data_h__ */
279
280