Sam Grove / Mbed 2 deprecated canopen_masternode

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers states.h Source File

states.h

00001 /*
00002 This file is part of CanFestival, a library implementing CanOpen Stack. 
00003 
00004 Copyright (C): Edouard TISSERANT and Francis DUPIN
00005 
00006 See COPYING file for copyrights details.
00007 
00008 This library is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU Lesser General Public
00010 License as published by the Free Software Foundation; either
00011 version 2.1 of the License, or (at your option) any later version.
00012 
00013 This library is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 Lesser General Public License for more details.
00017 
00018 You should have received a copy of the GNU Lesser General Public
00019 License along with this library; if not, write to the Free Software
00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 /** @defgroup statemachine State Machine
00024  *  @ingroup userapi
00025  */
00026  
00027 #ifndef __states_h__
00028 #define __states_h__
00029 
00030 #include <applicfg.h>
00031 
00032 /* The nodes states 
00033  * -----------------
00034  * values are choosen so, that they can be sent directly
00035  * for heartbeat messages...
00036  * Must be coded on 7 bits only
00037  * */
00038 /* Should not be modified */
00039 enum enum_nodeState {
00040   Initialisation  = 0x00, 
00041   Disconnected    = 0x01,
00042   Connecting      = 0x02,
00043   Preparing       = 0x02,
00044   Stopped         = 0x04,
00045   Operational     = 0x05,
00046   Pre_operational = 0x7F,
00047   Unknown_state   = 0x0F
00048 };
00049 
00050 typedef enum enum_nodeState e_nodeState;
00051 
00052 typedef struct
00053 {
00054     INTEGER8 csBoot_Up;
00055     INTEGER8 csSDO;
00056     INTEGER8 csEmergency;
00057     INTEGER8 csSYNC;
00058     INTEGER8 csHeartbeat;
00059     INTEGER8 csPDO;
00060     INTEGER8 csLSS;
00061 } s_state_communication;
00062 
00063 /** 
00064  * @brief Function that user app can overload
00065  * @ingroup statemachine
00066  */
00067 typedef void (*initialisation_t)(CO_Data*);
00068 typedef void (*preOperational_t)(CO_Data*);
00069 typedef void (*operational_t)(CO_Data*);
00070 typedef void (*stopped_t)(CO_Data*);
00071 
00072 /** 
00073  * @ingroup statemachine
00074  * @brief Function that user app can overload
00075  * @param *d Pointer on a CAN object data structure
00076  */
00077 void _initialisation(CO_Data* d);
00078 
00079 /** 
00080  * @ingroup statemachine
00081  * @brief Function that user app can overload
00082  * @param *d Pointer on a CAN object data structure
00083  */
00084 void _preOperational(CO_Data* d);
00085 
00086 /**
00087  * @ingroup statemachine 
00088  * @brief Function that user app can overload
00089  * @param *d Pointer on a CAN object data structure
00090  */
00091 void _operational(CO_Data* d);
00092 
00093 /** 
00094  * @ingroup statemachine
00095  * @brief Function that user app can overload
00096  * @param *d Pointer on a CAN object data structure
00097  */
00098 void _stopped(CO_Data* d);
00099 
00100 #include "data.h"
00101 
00102 /************************* prototypes ******************************/
00103 
00104 /** 
00105  * @brief Called by driver/app when receiving messages
00106  * @param *d Pointer on a CAN object data structure
00107  * @param *m Pointer on a CAN message structure
00108  */
00109 void canDispatch(CO_Data* d, Message *m);
00110 
00111 /** 
00112  * @ingroup statemachine
00113  * @brief Returns the state of the node
00114  * @param *d Pointer on a CAN object data structure
00115  * @return The node state
00116  */
00117 e_nodeState getState (CO_Data* d);
00118 
00119 /** 
00120  * @ingroup statemachine
00121  * @brief Change the state of the node 
00122  * @param *d Pointer on a CAN object data structure
00123  * @param newState The state to assign
00124  * @return 
00125  */
00126 UNS8 setState (CO_Data* d, e_nodeState newState);
00127 
00128 /**
00129  * @ingroup statemachine 
00130  * @brief Returns the nodId 
00131  * @param *d Pointer on a CAN object data structure
00132  * @return
00133  */
00134 UNS8 getNodeId (CO_Data* d);
00135 
00136 /** 
00137  * @ingroup statemachine
00138  * @brief Define the node ID. Initialize the object dictionary
00139  * @param *d Pointer on a CAN object data structure
00140  * @param nodeId The node ID to assign
00141  */
00142 void setNodeId (CO_Data* d, UNS8 nodeId);
00143 
00144 /** 
00145  * @brief Some stuff to do when the node enter in pre-operational mode
00146  * @param *d Pointer on a CAN object data structure
00147  */
00148 void initPreOperationalMode (CO_Data* d);
00149 
00150 #endif