Can_open_slavenode

Dependencies:   mbed

Committer:
sam_grove
Date:
Mon May 30 07:14:41 2011 +0000
Revision:
0:6219434a0cb5
Initial public release of slave node framework port

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:6219434a0cb5 1 /*
sam_grove 0:6219434a0cb5 2 This file is part of CanFestival, a library implementing CanOpen Stack.
sam_grove 0:6219434a0cb5 3
sam_grove 0:6219434a0cb5 4 Copyright (C): Edouard TISSERANT and Francis DUPIN
sam_grove 0:6219434a0cb5 5
sam_grove 0:6219434a0cb5 6 See COPYING file for copyrights details.
sam_grove 0:6219434a0cb5 7
sam_grove 0:6219434a0cb5 8 This library is free software; you can redistribute it and/or
sam_grove 0:6219434a0cb5 9 modify it under the terms of the GNU Lesser General Public
sam_grove 0:6219434a0cb5 10 License as published by the Free Software Foundation; either
sam_grove 0:6219434a0cb5 11 version 2.1 of the License, or (at your option) any later version.
sam_grove 0:6219434a0cb5 12
sam_grove 0:6219434a0cb5 13 This library is distributed in the hope that it will be useful,
sam_grove 0:6219434a0cb5 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
sam_grove 0:6219434a0cb5 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sam_grove 0:6219434a0cb5 16 Lesser General Public License for more details.
sam_grove 0:6219434a0cb5 17
sam_grove 0:6219434a0cb5 18 You should have received a copy of the GNU Lesser General Public
sam_grove 0:6219434a0cb5 19 License along with this library; if not, write to the Free Software
sam_grove 0:6219434a0cb5 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sam_grove 0:6219434a0cb5 21 */
sam_grove 0:6219434a0cb5 22
sam_grove 0:6219434a0cb5 23 #ifndef __data_h__
sam_grove 0:6219434a0cb5 24 #define __data_h__
sam_grove 0:6219434a0cb5 25
sam_grove 0:6219434a0cb5 26 #ifdef __cplusplus
sam_grove 0:6219434a0cb5 27 extern "C" {
sam_grove 0:6219434a0cb5 28 #endif
sam_grove 0:6219434a0cb5 29
sam_grove 0:6219434a0cb5 30 /* declaration of CO_Data type let us include all necessary headers
sam_grove 0:6219434a0cb5 31 struct struct_CO_Data can then be defined later
sam_grove 0:6219434a0cb5 32 */
sam_grove 0:6219434a0cb5 33 typedef struct struct_CO_Data CO_Data;
sam_grove 0:6219434a0cb5 34
sam_grove 0:6219434a0cb5 35 #include "applicfg.h"
sam_grove 0:6219434a0cb5 36 #include "def.h"
sam_grove 0:6219434a0cb5 37 #include "canopen_can.h"
sam_grove 0:6219434a0cb5 38 #include "objdictdef.h"
sam_grove 0:6219434a0cb5 39 #include "objacces.h"
sam_grove 0:6219434a0cb5 40 #include "sdo.h"
sam_grove 0:6219434a0cb5 41 #include "pdo.h"
sam_grove 0:6219434a0cb5 42 #include "states.h"
sam_grove 0:6219434a0cb5 43 #include "lifegrd.h"
sam_grove 0:6219434a0cb5 44 #include "sync.h"
sam_grove 0:6219434a0cb5 45 #include "nmtSlave.h"
sam_grove 0:6219434a0cb5 46 #include "nmtMaster.h"
sam_grove 0:6219434a0cb5 47 #include "emcy.h"
sam_grove 0:6219434a0cb5 48 #ifdef CO_ENABLE_LSS
sam_grove 0:6219434a0cb5 49 #include "lss.h"
sam_grove 0:6219434a0cb5 50 #endif
sam_grove 0:6219434a0cb5 51
sam_grove 0:6219434a0cb5 52 /**
sam_grove 0:6219434a0cb5 53 * @ingroup od
sam_grove 0:6219434a0cb5 54 * @brief This structure contains all necessary informations to define a CANOpen node
sam_grove 0:6219434a0cb5 55 */
sam_grove 0:6219434a0cb5 56 struct struct_CO_Data {
sam_grove 0:6219434a0cb5 57 /* Object dictionary */
sam_grove 0:6219434a0cb5 58 UNS8 *bDeviceNodeId;
sam_grove 0:6219434a0cb5 59 const indextable *objdict;
sam_grove 0:6219434a0cb5 60 s_PDO_status *PDO_status;
sam_grove 0:6219434a0cb5 61 const quick_index *firstIndex;
sam_grove 0:6219434a0cb5 62 const quick_index *lastIndex;
sam_grove 0:6219434a0cb5 63 const UNS16 *ObjdictSize;
sam_grove 0:6219434a0cb5 64 const UNS8 *iam_a_slave;
sam_grove 0:6219434a0cb5 65 valueRangeTest_t valueRangeTest;
sam_grove 0:6219434a0cb5 66
sam_grove 0:6219434a0cb5 67 /* SDO */
sam_grove 0:6219434a0cb5 68 s_transfer transfers[SDO_MAX_SIMULTANEOUS_TRANSFERTS];
sam_grove 0:6219434a0cb5 69 /* s_sdo_parameter *sdo_parameters; */
sam_grove 0:6219434a0cb5 70
sam_grove 0:6219434a0cb5 71 /* State machine */
sam_grove 0:6219434a0cb5 72 e_nodeState nodeState;
sam_grove 0:6219434a0cb5 73 s_state_communication CurrentCommunicationState;
sam_grove 0:6219434a0cb5 74 initialisation_t initialisation;
sam_grove 0:6219434a0cb5 75 preOperational_t preOperational;
sam_grove 0:6219434a0cb5 76 operational_t operational;
sam_grove 0:6219434a0cb5 77 stopped_t stopped;
sam_grove 0:6219434a0cb5 78 void (*NMT_Slave_Node_Reset_Callback)(CO_Data*);
sam_grove 0:6219434a0cb5 79 void (*NMT_Slave_Communications_Reset_Callback)(CO_Data*);
sam_grove 0:6219434a0cb5 80
sam_grove 0:6219434a0cb5 81 /* NMT-heartbeat */
sam_grove 0:6219434a0cb5 82 UNS8 *ConsumerHeartbeatCount;
sam_grove 0:6219434a0cb5 83 UNS32 *ConsumerHeartbeatEntries;
sam_grove 0:6219434a0cb5 84 TIMER_HANDLE *ConsumerHeartBeatTimers;
sam_grove 0:6219434a0cb5 85 UNS16 *ProducerHeartBeatTime;
sam_grove 0:6219434a0cb5 86 TIMER_HANDLE ProducerHeartBeatTimer;
sam_grove 0:6219434a0cb5 87 heartbeatError_t heartbeatError;
sam_grove 0:6219434a0cb5 88 e_nodeState NMTable[NMT_MAX_NODE_ID];
sam_grove 0:6219434a0cb5 89
sam_grove 0:6219434a0cb5 90 /* SYNC */
sam_grove 0:6219434a0cb5 91 TIMER_HANDLE syncTimer;
sam_grove 0:6219434a0cb5 92 UNS32 *COB_ID_Sync;
sam_grove 0:6219434a0cb5 93 UNS32 *Sync_Cycle_Period;
sam_grove 0:6219434a0cb5 94 /*UNS32 *Sync_window_length;;*/
sam_grove 0:6219434a0cb5 95 post_sync_t post_sync;
sam_grove 0:6219434a0cb5 96 post_TPDO_t post_TPDO;
sam_grove 0:6219434a0cb5 97 post_SlaveBootup_t post_SlaveBootup;
sam_grove 0:6219434a0cb5 98 post_SlaveStateChange_t post_SlaveStateChange;
sam_grove 0:6219434a0cb5 99
sam_grove 0:6219434a0cb5 100 /* General */
sam_grove 0:6219434a0cb5 101 UNS8 toggle;
sam_grove 0:6219434a0cb5 102 CAN_PORT canHandle;
sam_grove 0:6219434a0cb5 103 scanIndexOD_t scanIndexOD;
sam_grove 0:6219434a0cb5 104 storeODSubIndex_t storeODSubIndex;
sam_grove 0:6219434a0cb5 105
sam_grove 0:6219434a0cb5 106 /* DCF concise */
sam_grove 0:6219434a0cb5 107 const indextable* dcf_odentry;
sam_grove 0:6219434a0cb5 108 UNS8* dcf_cursor;
sam_grove 0:6219434a0cb5 109 UNS32 dcf_entries_count;
sam_grove 0:6219434a0cb5 110 UNS8 dcf_request;
sam_grove 0:6219434a0cb5 111
sam_grove 0:6219434a0cb5 112 /* EMCY */
sam_grove 0:6219434a0cb5 113 e_errorState error_state;
sam_grove 0:6219434a0cb5 114 UNS8 error_history_size;
sam_grove 0:6219434a0cb5 115 UNS8* error_number;
sam_grove 0:6219434a0cb5 116 UNS32* error_first_element;
sam_grove 0:6219434a0cb5 117 UNS8* error_register;
sam_grove 0:6219434a0cb5 118 UNS32* error_cobid;
sam_grove 0:6219434a0cb5 119 s_errors error_data[EMCY_MAX_ERRORS];
sam_grove 0:6219434a0cb5 120 post_emcy_t post_emcy;
sam_grove 0:6219434a0cb5 121
sam_grove 0:6219434a0cb5 122 #ifdef CO_ENABLE_LSS
sam_grove 0:6219434a0cb5 123 /* LSS */
sam_grove 0:6219434a0cb5 124 lss_transfer_t lss_transfer;
sam_grove 0:6219434a0cb5 125 lss_StoreConfiguration_t lss_StoreConfiguration;
sam_grove 0:6219434a0cb5 126 #endif
sam_grove 0:6219434a0cb5 127 };
sam_grove 0:6219434a0cb5 128
sam_grove 0:6219434a0cb5 129 #define NMTable_Initializer Unknown_state,
sam_grove 0:6219434a0cb5 130
sam_grove 0:6219434a0cb5 131 #ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
sam_grove 0:6219434a0cb5 132 #define s_transfer_Initializer {\
sam_grove 0:6219434a0cb5 133 0, /* nodeId */\
sam_grove 0:6219434a0cb5 134 0, /* wohami */\
sam_grove 0:6219434a0cb5 135 SDO_RESET, /* state */\
sam_grove 0:6219434a0cb5 136 0, /* toggle */\
sam_grove 0:6219434a0cb5 137 0, /* abortCode */\
sam_grove 0:6219434a0cb5 138 0, /* index */\
sam_grove 0:6219434a0cb5 139 0, /* subIndex */\
sam_grove 0:6219434a0cb5 140 0, /* count */\
sam_grove 0:6219434a0cb5 141 0, /* offset */\
sam_grove 0:6219434a0cb5 142 {0}, /* data (static use, so that all the table is initialize at 0)*/\
sam_grove 0:6219434a0cb5 143 NULL, /* dynamicData */ \
sam_grove 0:6219434a0cb5 144 0, /* dynamicDataSize */ \
sam_grove 0:6219434a0cb5 145 0, /* dataType */\
sam_grove 0:6219434a0cb5 146 -1, /* timer */\
sam_grove 0:6219434a0cb5 147 NULL /* Callback */\
sam_grove 0:6219434a0cb5 148 },
sam_grove 0:6219434a0cb5 149 #else
sam_grove 0:6219434a0cb5 150 #define s_transfer_Initializer {\
sam_grove 0:6219434a0cb5 151 0, /* nodeId */\
sam_grove 0:6219434a0cb5 152 0, /* wohami */\
sam_grove 0:6219434a0cb5 153 SDO_RESET, /* state */\
sam_grove 0:6219434a0cb5 154 0, /* toggle */\
sam_grove 0:6219434a0cb5 155 0, /* abortCode */\
sam_grove 0:6219434a0cb5 156 0, /* index */\
sam_grove 0:6219434a0cb5 157 0, /* subIndex */\
sam_grove 0:6219434a0cb5 158 0, /* count */\
sam_grove 0:6219434a0cb5 159 0, /* offset */\
sam_grove 0:6219434a0cb5 160 {0}, /* data (static use, so that all the table is initialize at 0)*/\
sam_grove 0:6219434a0cb5 161 0, /* dataType */\
sam_grove 0:6219434a0cb5 162 -1, /* timer */\
sam_grove 0:6219434a0cb5 163 NULL /* Callback */\
sam_grove 0:6219434a0cb5 164 },
sam_grove 0:6219434a0cb5 165 #endif //SDO_DYNAMIC_BUFFER_ALLOCATION
sam_grove 0:6219434a0cb5 166
sam_grove 0:6219434a0cb5 167 #define ERROR_DATA_INITIALIZER \
sam_grove 0:6219434a0cb5 168 {\
sam_grove 0:6219434a0cb5 169 0, /* errCode */\
sam_grove 0:6219434a0cb5 170 0, /* errRegMask */\
sam_grove 0:6219434a0cb5 171 0 /* active */\
sam_grove 0:6219434a0cb5 172 },
sam_grove 0:6219434a0cb5 173
sam_grove 0:6219434a0cb5 174 #ifdef CO_ENABLE_LSS
sam_grove 0:6219434a0cb5 175
sam_grove 0:6219434a0cb5 176 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:6219434a0cb5 177 #define lss_fs_Initializer \
sam_grove 0:6219434a0cb5 178 ,0, /* IDNumber */\
sam_grove 0:6219434a0cb5 179 128, /* BitChecked */\
sam_grove 0:6219434a0cb5 180 0, /* LSSSub */\
sam_grove 0:6219434a0cb5 181 0, /* LSSNext */\
sam_grove 0:6219434a0cb5 182 0, /* LSSPos */\
sam_grove 0:6219434a0cb5 183 LSS_FS_RESET, /* FastScan_SM */\
sam_grove 0:6219434a0cb5 184 -1, /* timerFS */\
sam_grove 0:6219434a0cb5 185 {{0,0,0,0},{0,0,0,0}} /* lss_fs_transfer */
sam_grove 0:6219434a0cb5 186 #else
sam_grove 0:6219434a0cb5 187 #define lss_fs_Initializer
sam_grove 0:6219434a0cb5 188 #endif
sam_grove 0:6219434a0cb5 189
sam_grove 0:6219434a0cb5 190 #define lss_Initializer {\
sam_grove 0:6219434a0cb5 191 LSS_RESET, /* state */\
sam_grove 0:6219434a0cb5 192 0, /* command */\
sam_grove 0:6219434a0cb5 193 LSS_WAITING_MODE, /* mode */\
sam_grove 0:6219434a0cb5 194 0, /* dat1 */\
sam_grove 0:6219434a0cb5 195 0, /* dat2 */\
sam_grove 0:6219434a0cb5 196 0, /* NodeID */\
sam_grove 0:6219434a0cb5 197 0, /* addr_sel_match */\
sam_grove 0:6219434a0cb5 198 0, /* addr_ident_match */\
sam_grove 0:6219434a0cb5 199 "none", /* BaudRate */\
sam_grove 0:6219434a0cb5 200 0, /* SwitchDelay */\
sam_grove 0:6219434a0cb5 201 SDELAY_OFF, /* SwitchDelayState */\
sam_grove 0:6219434a0cb5 202 NULL, /* canHandle_t */\
sam_grove 0:6219434a0cb5 203 -1, /* TimerMSG */\
sam_grove 0:6219434a0cb5 204 -1, /* TimerSDELAY */\
sam_grove 0:6219434a0cb5 205 NULL, /* Callback */\
sam_grove 0:6219434a0cb5 206 0 /* LSSanswer */\
sam_grove 0:6219434a0cb5 207 lss_fs_Initializer /*FastScan service initialization */\
sam_grove 0:6219434a0cb5 208 },\
sam_grove 0:6219434a0cb5 209 NULL /* _lss_StoreConfiguration*/
sam_grove 0:6219434a0cb5 210 #else
sam_grove 0:6219434a0cb5 211 #define lss_Initializer
sam_grove 0:6219434a0cb5 212 #endif
sam_grove 0:6219434a0cb5 213
sam_grove 0:6219434a0cb5 214
sam_grove 0:6219434a0cb5 215 /* A macro to initialize the data in client app.*/
sam_grove 0:6219434a0cb5 216 /* CO_Data structure */
sam_grove 0:6219434a0cb5 217 #define CANOPEN_NODE_DATA_INITIALIZER(NODE_PREFIX) {\
sam_grove 0:6219434a0cb5 218 /* Object dictionary*/\
sam_grove 0:6219434a0cb5 219 & NODE_PREFIX ## _bDeviceNodeId, /* bDeviceNodeId */\
sam_grove 0:6219434a0cb5 220 NODE_PREFIX ## _objdict, /* objdict */\
sam_grove 0:6219434a0cb5 221 NODE_PREFIX ## _PDO_status, /* PDO_status */\
sam_grove 0:6219434a0cb5 222 & NODE_PREFIX ## _firstIndex, /* firstIndex */\
sam_grove 0:6219434a0cb5 223 & NODE_PREFIX ## _lastIndex, /* lastIndex */\
sam_grove 0:6219434a0cb5 224 & NODE_PREFIX ## _ObjdictSize, /* ObjdictSize */\
sam_grove 0:6219434a0cb5 225 & NODE_PREFIX ## _iam_a_slave, /* iam_a_slave */\
sam_grove 0:6219434a0cb5 226 NODE_PREFIX ## _valueRangeTest, /* valueRangeTest */\
sam_grove 0:6219434a0cb5 227 \
sam_grove 0:6219434a0cb5 228 /* SDO, structure s_transfer */\
sam_grove 0:6219434a0cb5 229 {\
sam_grove 0:6219434a0cb5 230 REPEAT_SDO_MAX_SIMULTANEOUS_TRANSFERTS_TIMES(s_transfer_Initializer)\
sam_grove 0:6219434a0cb5 231 },\
sam_grove 0:6219434a0cb5 232 \
sam_grove 0:6219434a0cb5 233 /* State machine*/\
sam_grove 0:6219434a0cb5 234 Unknown_state, /* nodeState */\
sam_grove 0:6219434a0cb5 235 /* structure s_state_communication */\
sam_grove 0:6219434a0cb5 236 {\
sam_grove 0:6219434a0cb5 237 0, /* csBoot_Up */\
sam_grove 0:6219434a0cb5 238 0, /* csSDO */\
sam_grove 0:6219434a0cb5 239 0, /* csEmergency */\
sam_grove 0:6219434a0cb5 240 0, /* csSYNC */\
sam_grove 0:6219434a0cb5 241 0, /* csHeartbeat */\
sam_grove 0:6219434a0cb5 242 0, /* csPDO */\
sam_grove 0:6219434a0cb5 243 0 /* csLSS */\
sam_grove 0:6219434a0cb5 244 },\
sam_grove 0:6219434a0cb5 245 _initialisation, /* initialisation */\
sam_grove 0:6219434a0cb5 246 _preOperational, /* preOperational */\
sam_grove 0:6219434a0cb5 247 _operational, /* operational */\
sam_grove 0:6219434a0cb5 248 _stopped, /* stopped */\
sam_grove 0:6219434a0cb5 249 NULL, /* NMT node reset callback */\
sam_grove 0:6219434a0cb5 250 NULL, /* NMT communications reset callback */\
sam_grove 0:6219434a0cb5 251 \
sam_grove 0:6219434a0cb5 252 /* NMT-heartbeat */\
sam_grove 0:6219434a0cb5 253 & NODE_PREFIX ## _highestSubIndex_obj1016, /* ConsumerHeartbeatCount */\
sam_grove 0:6219434a0cb5 254 NODE_PREFIX ## _obj1016, /* ConsumerHeartbeatEntries */\
sam_grove 0:6219434a0cb5 255 NODE_PREFIX ## _heartBeatTimers, /* ConsumerHeartBeatTimers */\
sam_grove 0:6219434a0cb5 256 & NODE_PREFIX ## _obj1017, /* ProducerHeartBeatTime */\
sam_grove 0:6219434a0cb5 257 TIMER_NONE, /* ProducerHeartBeatTimer */\
sam_grove 0:6219434a0cb5 258 _heartbeatError, /* heartbeatError */\
sam_grove 0:6219434a0cb5 259 \
sam_grove 0:6219434a0cb5 260 {REPEAT_NMT_MAX_NODE_ID_TIMES(NMTable_Initializer)},\
sam_grove 0:6219434a0cb5 261 /* is well initialized at "Unknown_state". Is it ok ? (FD)*/\
sam_grove 0:6219434a0cb5 262 \
sam_grove 0:6219434a0cb5 263 /* SYNC */\
sam_grove 0:6219434a0cb5 264 TIMER_NONE, /* syncTimer */\
sam_grove 0:6219434a0cb5 265 & NODE_PREFIX ## _obj1005, /* COB_ID_Sync */\
sam_grove 0:6219434a0cb5 266 & NODE_PREFIX ## _obj1006, /* Sync_Cycle_Period */\
sam_grove 0:6219434a0cb5 267 /*& NODE_PREFIX ## _obj1007, */ /* Sync_window_length */\
sam_grove 0:6219434a0cb5 268 _post_sync, /* post_sync */\
sam_grove 0:6219434a0cb5 269 _post_TPDO, /* post_TPDO */\
sam_grove 0:6219434a0cb5 270 _post_SlaveBootup, /* post_SlaveBootup */\
sam_grove 0:6219434a0cb5 271 _post_SlaveStateChange, /* post_SlaveStateChange */\
sam_grove 0:6219434a0cb5 272 \
sam_grove 0:6219434a0cb5 273 /* General */\
sam_grove 0:6219434a0cb5 274 0, /* toggle */\
sam_grove 0:6219434a0cb5 275 NULL, /* canSend */\
sam_grove 0:6219434a0cb5 276 NODE_PREFIX ## _scanIndexOD, /* scanIndexOD */\
sam_grove 0:6219434a0cb5 277 _storeODSubIndex, /* storeODSubIndex */\
sam_grove 0:6219434a0cb5 278 /* DCF concise */\
sam_grove 0:6219434a0cb5 279 NULL, /*dcf_odentry*/\
sam_grove 0:6219434a0cb5 280 NULL, /*dcf_cursor*/\
sam_grove 0:6219434a0cb5 281 1, /*dcf_entries_count*/\
sam_grove 0:6219434a0cb5 282 0, /* dcf_request*/\
sam_grove 0:6219434a0cb5 283 \
sam_grove 0:6219434a0cb5 284 /* EMCY */\
sam_grove 0:6219434a0cb5 285 Error_free, /* error_state */\
sam_grove 0:6219434a0cb5 286 sizeof(NODE_PREFIX ## _obj1003) / sizeof(NODE_PREFIX ## _obj1003[0]), /* error_history_size */\
sam_grove 0:6219434a0cb5 287 & NODE_PREFIX ## _highestSubIndex_obj1003, /* error_number */\
sam_grove 0:6219434a0cb5 288 & NODE_PREFIX ## _obj1003[0], /* error_first_element */\
sam_grove 0:6219434a0cb5 289 & NODE_PREFIX ## _obj1001, /* error_register */\
sam_grove 0:6219434a0cb5 290 & NODE_PREFIX ## _obj1014, /* error_cobid */\
sam_grove 0:6219434a0cb5 291 /* error_data: structure s_errors */\
sam_grove 0:6219434a0cb5 292 {\
sam_grove 0:6219434a0cb5 293 REPEAT_EMCY_MAX_ERRORS_TIMES(ERROR_DATA_INITIALIZER)\
sam_grove 0:6219434a0cb5 294 },\
sam_grove 0:6219434a0cb5 295 _post_emcy, /* post_emcy */\
sam_grove 0:6219434a0cb5 296 /* LSS */\
sam_grove 0:6219434a0cb5 297 lss_Initializer\
sam_grove 0:6219434a0cb5 298 }
sam_grove 0:6219434a0cb5 299
sam_grove 0:6219434a0cb5 300 #ifdef __cplusplus
sam_grove 0:6219434a0cb5 301 };
sam_grove 0:6219434a0cb5 302 #endif
sam_grove 0:6219434a0cb5 303
sam_grove 0:6219434a0cb5 304 #endif /* __data_h__ */
sam_grove 0:6219434a0cb5 305
sam_grove 0:6219434a0cb5 306