]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - include/data.h
Some fixes suggested by Luis Jiménez, plus some minor enhancements in DCF.
[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 "nmtMaster.h"
46 #include "emcy.h"
47
48 /* This structurs contains all necessary information for a CanOpen node */
49 struct struct_CO_Data {
50         /* Object dictionary */
51         UNS8 *bDeviceNodeId;
52         const indextable *objdict;
53         s_PDO_status *PDO_status;
54         quick_index *firstIndex;
55         quick_index *lastIndex;
56         UNS16 *ObjdictSize;
57         const UNS8 *iam_a_slave;
58         valueRangeTest_t valueRangeTest;
59         
60         /* SDO */
61         s_transfer transfers[SDO_MAX_SIMULTANEOUS_TRANSFERTS];
62         /* s_sdo_parameter *sdo_parameters; */
63
64         /* State machine */
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
72         /* NMT-heartbeat */
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
81         /* SYNC */
82         TIMER_HANDLE syncTimer;
83         UNS32 *COB_ID_Sync;
84         UNS32 *Sync_Cycle_Period;
85         /*UNS32 *Sync_window_length;;*/
86         post_sync_t post_sync;
87         post_TPDO_t post_TPDO;
88         
89         /* General */
90         UNS8 toggle;
91         CAN_HANDLE canHandle;   
92         scanIndexOD_t scanIndexOD;
93         storeODSubIndex_t storeODSubIndex; 
94         
95         /* DCF concise */
96     indextable* dcf_odentry;
97         UNS8* dcf_cursor;
98         UNS32 dcf_entries_count;
99         
100         /* EMCY */
101         e_errorState error_state;
102         UNS8 error_history_size;
103         UNS8* error_number;
104         UNS32* error_first_element;
105         UNS8* error_register;
106     UNS32* error_cobid;
107         s_errors error_data[EMCY_MAX_ERRORS];
108         post_emcy_t post_emcy;
109         
110 };
111
112 #define NMTable_Initializer Unknown_state,
113
114 #define s_transfer_Initializer {\
115                 0,          /* nodeId */\
116                 0,          /* wohami */\
117                 SDO_RESET,  /* state */\
118                 0,          /* toggle */\
119                 0,          /* abortCode */\
120                 0,          /* index */\
121                 0,          /* subIndex */\
122                 0,          /* count */\
123                 0,          /* offset */\
124                 {0},        /* data (static use, so that all the table is initialize at 0)*/\
125                 0,          /* dataType */\
126                 -1,         /* timer */\
127                 NULL        /* Callback */\
128           },
129
130 #define ERROR_DATA_INITIALIZER \
131         {\
132         0, /* errCode */\
133         0, /* errRegMask */\
134         0 /* active */\
135         },
136
137 /* A macro to initialize the data in client app.*/
138 /* CO_Data structure */
139 #define CANOPEN_NODE_DATA_INITIALIZER(NODE_PREFIX) {\
140         /* Object dictionary*/\
141         & NODE_PREFIX ## _bDeviceNodeId,     /* bDeviceNodeId */\
142         NODE_PREFIX ## _objdict,             /* objdict  */\
143         NODE_PREFIX ## _PDO_status,          /* PDO_status */\
144         & NODE_PREFIX ## _firstIndex,        /* firstIndex */\
145         & NODE_PREFIX ## _lastIndex,         /* lastIndex */\
146         & NODE_PREFIX ## _ObjdictSize,       /* ObjdictSize */\
147         & NODE_PREFIX ## _iam_a_slave,       /* iam_a_slave */\
148         NODE_PREFIX ## _valueRangeTest,      /* valueRangeTest */\
149         \
150         /* SDO, structure s_transfer */\
151         {\
152           REPEAT_SDO_MAX_SIMULTANEOUS_TRANSFERTS_TIMES(s_transfer_Initializer)\
153         },\
154         \
155         /* State machine*/\
156         Unknown_state,      /* nodeState */\
157         /* structure s_state_communication */\
158         {\
159                 0,          /* csBoot_Up */\
160                 0,          /* csSDO */\
161                 0,          /* csEmergency */\
162                 0,          /* csSYNC */\
163                 0,          /* csHeartbeat */\
164                 0           /* csPDO */\
165         },\
166         _initialisation,     /* initialisation */\
167         _preOperational,     /* preOperational */\
168         _operational,        /* operational */\
169         _stopped,            /* stopped */\
170         \
171         /* NMT-heartbeat */\
172         & NODE_PREFIX ## _highestSubIndex_obj1016, /* ConsumerHeartbeatCount */\
173         NODE_PREFIX ## _obj1016,                   /* ConsumerHeartbeatEntries */\
174         NODE_PREFIX ## _heartBeatTimers,           /* ConsumerHeartBeatTimers  */\
175         & NODE_PREFIX ## _obj1017,                 /* ProducerHeartBeatTime */\
176         TIMER_NONE,                                /* ProducerHeartBeatTimer */\
177         _heartbeatError,           /* heartbeatError */\
178         \
179         {REPEAT_NMT_MAX_NODE_ID_TIMES(NMTable_Initializer)},\
180                                                    /* is  well initialized at "Unknown_state". Is it ok ? (FD)*/\
181         \
182         /* SYNC */\
183         TIMER_NONE,                                /* syncTimer */\
184         & NODE_PREFIX ## _obj1005,                 /* COB_ID_Sync */\
185         & NODE_PREFIX ## _obj1006,                 /* Sync_Cycle_Period */\
186         /*& NODE_PREFIX ## _obj1007, */            /* Sync_window_length */\
187         _post_sync,                 /* post_sync */\
188         _post_TPDO,                 /* post_TPDO */\
189         \
190         /* General */\
191         0,                                         /* toggle */\
192         NULL,                   /* canSend */\
193         NODE_PREFIX ## _scanIndexOD,                /* scanIndexOD */\
194         _storeODSubIndex,                /* storeODSubIndex */\
195     /* DCF concise */\
196     NULL,       /*dcf_odentry*/\
197         NULL,           /*dcf_cursor*/\
198         1,              /*dcf_entries_count*/\
199         \
200         /* EMCY */\
201         Error_free,                      /* error_state */\
202         sizeof(NODE_PREFIX ## _obj1003) / sizeof(NODE_PREFIX ## _obj1003[0]),      /* error_history_size */\
203         & NODE_PREFIX ## _highestSubIndex_obj1003,    /* error_number */\
204         & NODE_PREFIX ## _obj1003[0],    /* error_first_element */\
205         & NODE_PREFIX ## _obj1001,       /* error_register */\
206     & NODE_PREFIX ## _obj1014,       /* error_cobid */\
207         /* error_data: structure s_errors */\
208         {\
209         REPEAT_EMCY_MAX_ERRORS_TIMES(ERROR_DATA_INITIALIZER)\
210         },\
211         _post_emcy              /* post_emcy */\
212 }
213
214 #ifdef __cplusplus
215 };
216 #endif
217
218 #endif /* __data_h__ */
219
220