CANfestival - an open source CANopen framework

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 /** @defgroup statemachine State Machine
sam_grove 0:6219434a0cb5 24 * @ingroup userapi
sam_grove 0:6219434a0cb5 25 */
sam_grove 0:6219434a0cb5 26
sam_grove 0:6219434a0cb5 27 #ifndef __states_h__
sam_grove 0:6219434a0cb5 28 #define __states_h__
sam_grove 0:6219434a0cb5 29
sam_grove 0:6219434a0cb5 30 #include <applicfg.h>
sam_grove 0:6219434a0cb5 31
sam_grove 0:6219434a0cb5 32 /* The nodes states
sam_grove 0:6219434a0cb5 33 * -----------------
sam_grove 0:6219434a0cb5 34 * values are choosen so, that they can be sent directly
sam_grove 0:6219434a0cb5 35 * for heartbeat messages...
sam_grove 0:6219434a0cb5 36 * Must be coded on 7 bits only
sam_grove 0:6219434a0cb5 37 * */
sam_grove 0:6219434a0cb5 38 /* Should not be modified */
sam_grove 0:6219434a0cb5 39 enum enum_nodeState {
sam_grove 0:6219434a0cb5 40 Initialisation = 0x00,
sam_grove 0:6219434a0cb5 41 Disconnected = 0x01,
sam_grove 0:6219434a0cb5 42 Connecting = 0x02,
sam_grove 0:6219434a0cb5 43 Preparing = 0x02,
sam_grove 0:6219434a0cb5 44 Stopped = 0x04,
sam_grove 0:6219434a0cb5 45 Operational = 0x05,
sam_grove 0:6219434a0cb5 46 Pre_operational = 0x7F,
sam_grove 0:6219434a0cb5 47 Unknown_state = 0x0F
sam_grove 0:6219434a0cb5 48 };
sam_grove 0:6219434a0cb5 49
sam_grove 0:6219434a0cb5 50 typedef enum enum_nodeState e_nodeState;
sam_grove 0:6219434a0cb5 51
sam_grove 0:6219434a0cb5 52 typedef struct
sam_grove 0:6219434a0cb5 53 {
sam_grove 0:6219434a0cb5 54 INTEGER8 csBoot_Up;
sam_grove 0:6219434a0cb5 55 INTEGER8 csSDO;
sam_grove 0:6219434a0cb5 56 INTEGER8 csEmergency;
sam_grove 0:6219434a0cb5 57 INTEGER8 csSYNC;
sam_grove 0:6219434a0cb5 58 INTEGER8 csHeartbeat;
sam_grove 0:6219434a0cb5 59 INTEGER8 csPDO;
sam_grove 0:6219434a0cb5 60 INTEGER8 csLSS;
sam_grove 0:6219434a0cb5 61 } s_state_communication;
sam_grove 0:6219434a0cb5 62
sam_grove 0:6219434a0cb5 63 /**
sam_grove 0:6219434a0cb5 64 * @brief Function that user app can overload
sam_grove 0:6219434a0cb5 65 * @ingroup statemachine
sam_grove 0:6219434a0cb5 66 */
sam_grove 0:6219434a0cb5 67 typedef void (*initialisation_t)(CO_Data*);
sam_grove 0:6219434a0cb5 68 typedef void (*preOperational_t)(CO_Data*);
sam_grove 0:6219434a0cb5 69 typedef void (*operational_t)(CO_Data*);
sam_grove 0:6219434a0cb5 70 typedef void (*stopped_t)(CO_Data*);
sam_grove 0:6219434a0cb5 71
sam_grove 0:6219434a0cb5 72 /**
sam_grove 0:6219434a0cb5 73 * @ingroup statemachine
sam_grove 0:6219434a0cb5 74 * @brief Function that user app can overload
sam_grove 0:6219434a0cb5 75 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 76 */
sam_grove 0:6219434a0cb5 77 void _initialisation(CO_Data* d);
sam_grove 0:6219434a0cb5 78
sam_grove 0:6219434a0cb5 79 /**
sam_grove 0:6219434a0cb5 80 * @ingroup statemachine
sam_grove 0:6219434a0cb5 81 * @brief Function that user app can overload
sam_grove 0:6219434a0cb5 82 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 83 */
sam_grove 0:6219434a0cb5 84 void _preOperational(CO_Data* d);
sam_grove 0:6219434a0cb5 85
sam_grove 0:6219434a0cb5 86 /**
sam_grove 0:6219434a0cb5 87 * @ingroup statemachine
sam_grove 0:6219434a0cb5 88 * @brief Function that user app can overload
sam_grove 0:6219434a0cb5 89 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 90 */
sam_grove 0:6219434a0cb5 91 void _operational(CO_Data* d);
sam_grove 0:6219434a0cb5 92
sam_grove 0:6219434a0cb5 93 /**
sam_grove 0:6219434a0cb5 94 * @ingroup statemachine
sam_grove 0:6219434a0cb5 95 * @brief Function that user app can overload
sam_grove 0:6219434a0cb5 96 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 97 */
sam_grove 0:6219434a0cb5 98 void _stopped(CO_Data* d);
sam_grove 0:6219434a0cb5 99
sam_grove 0:6219434a0cb5 100 #include "data.h"
sam_grove 0:6219434a0cb5 101
sam_grove 0:6219434a0cb5 102 /************************* prototypes ******************************/
sam_grove 0:6219434a0cb5 103
sam_grove 0:6219434a0cb5 104 /**
sam_grove 0:6219434a0cb5 105 * @brief Called by driver/app when receiving messages
sam_grove 0:6219434a0cb5 106 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 107 * @param *m Pointer on a CAN message structure
sam_grove 0:6219434a0cb5 108 */
sam_grove 0:6219434a0cb5 109 void canDispatch(CO_Data* d, Message *m);
sam_grove 0:6219434a0cb5 110
sam_grove 0:6219434a0cb5 111 /**
sam_grove 0:6219434a0cb5 112 * @ingroup statemachine
sam_grove 0:6219434a0cb5 113 * @brief Returns the state of the node
sam_grove 0:6219434a0cb5 114 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 115 * @return The node state
sam_grove 0:6219434a0cb5 116 */
sam_grove 0:6219434a0cb5 117 e_nodeState getState (CO_Data* d);
sam_grove 0:6219434a0cb5 118
sam_grove 0:6219434a0cb5 119 /**
sam_grove 0:6219434a0cb5 120 * @ingroup statemachine
sam_grove 0:6219434a0cb5 121 * @brief Change the state of the node
sam_grove 0:6219434a0cb5 122 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 123 * @param newState The state to assign
sam_grove 0:6219434a0cb5 124 * @return
sam_grove 0:6219434a0cb5 125 */
sam_grove 0:6219434a0cb5 126 UNS8 setState (CO_Data* d, e_nodeState newState);
sam_grove 0:6219434a0cb5 127
sam_grove 0:6219434a0cb5 128 /**
sam_grove 0:6219434a0cb5 129 * @ingroup statemachine
sam_grove 0:6219434a0cb5 130 * @brief Returns the nodId
sam_grove 0:6219434a0cb5 131 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 132 * @return
sam_grove 0:6219434a0cb5 133 */
sam_grove 0:6219434a0cb5 134 UNS8 getNodeId (CO_Data* d);
sam_grove 0:6219434a0cb5 135
sam_grove 0:6219434a0cb5 136 /**
sam_grove 0:6219434a0cb5 137 * @ingroup statemachine
sam_grove 0:6219434a0cb5 138 * @brief Define the node ID. Initialize the object dictionary
sam_grove 0:6219434a0cb5 139 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 140 * @param nodeId The node ID to assign
sam_grove 0:6219434a0cb5 141 */
sam_grove 0:6219434a0cb5 142 void setNodeId (CO_Data* d, UNS8 nodeId);
sam_grove 0:6219434a0cb5 143
sam_grove 0:6219434a0cb5 144 /**
sam_grove 0:6219434a0cb5 145 * @brief Some stuff to do when the node enter in pre-operational mode
sam_grove 0:6219434a0cb5 146 * @param *d Pointer on a CAN object data structure
sam_grove 0:6219434a0cb5 147 */
sam_grove 0:6219434a0cb5 148 void initPreOperationalMode (CO_Data* d);
sam_grove 0:6219434a0cb5 149
sam_grove 0:6219434a0cb5 150 #endif