Can_open_masternode

Dependencies:   mbed

Committer:
sam_grove
Date:
Wed Sep 26 05:48:14 2012 +0000
Revision:
7:537bae5a6fc6
Parent:
0:9dd7c6129683
Pushing the project into the new repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:9dd7c6129683 1 /*
sam_grove 0:9dd7c6129683 2 This file is part of CanFestival, a library implementing CanOpen Stack.
sam_grove 0:9dd7c6129683 3
sam_grove 0:9dd7c6129683 4 Copyright (C): Jorge Berzosa
sam_grove 0:9dd7c6129683 5
sam_grove 0:9dd7c6129683 6 See COPYING file for copyrights details.
sam_grove 0:9dd7c6129683 7
sam_grove 0:9dd7c6129683 8 This library is free software; you can redistribute it and/or
sam_grove 0:9dd7c6129683 9 modify it under the terms of the GNU Lesser General Public
sam_grove 0:9dd7c6129683 10 License as published by the Free Software Foundation; either
sam_grove 0:9dd7c6129683 11 version 2.1 of the License, or (at your option) any later version.
sam_grove 0:9dd7c6129683 12
sam_grove 0:9dd7c6129683 13 This library is distributed in the hope that it will be useful,
sam_grove 0:9dd7c6129683 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
sam_grove 0:9dd7c6129683 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
sam_grove 0:9dd7c6129683 16 Lesser General Public License for more details.
sam_grove 0:9dd7c6129683 17
sam_grove 0:9dd7c6129683 18 You should have received a copy of the GNU Lesser General Public
sam_grove 0:9dd7c6129683 19 License along with this library; if not, write to the Free Software
sam_grove 0:9dd7c6129683 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
sam_grove 0:9dd7c6129683 21 */
sam_grove 0:9dd7c6129683 22
sam_grove 0:9dd7c6129683 23 /** @defgroup lss Layer Setting Services Object
sam_grove 0:9dd7c6129683 24 * @brief LSS offers the possibility to inquire and change the settings of certain parameters of the local layers on
sam_grove 0:9dd7c6129683 25 * a CANopen module with LSS Slave capabilities by a CANopen module with LSS Master capabilities via the
sam_grove 0:9dd7c6129683 26 * CAN Network.
sam_grove 0:9dd7c6129683 27 * The following parameters can be inquired and/or changed by the use of LSS:
sam_grove 0:9dd7c6129683 28 * - Node-ID of the CANopen Slave
sam_grove 0:9dd7c6129683 29 * - Bit timing parameters of the physical layer (baud rate)
sam_grove 0:9dd7c6129683 30 * - LSS address (/2/ Identity Object, Index 1018H)
sam_grove 0:9dd7c6129683 31 * @ingroup comobj
sam_grove 0:9dd7c6129683 32 */
sam_grove 0:9dd7c6129683 33
sam_grove 0:9dd7c6129683 34 #ifndef __LSS_h__
sam_grove 0:9dd7c6129683 35 #define __LSS_h__
sam_grove 0:9dd7c6129683 36
sam_grove 0:9dd7c6129683 37 #define SLSS_ADRESS 0x7E4
sam_grove 0:9dd7c6129683 38 #define MLSS_ADRESS 0x7E5
sam_grove 0:9dd7c6129683 39
sam_grove 0:9dd7c6129683 40 #define SDELAY_OFF 0
sam_grove 0:9dd7c6129683 41 #define SDELAY_FIRST 1
sam_grove 0:9dd7c6129683 42 #define SDELAY_SECOND 2
sam_grove 0:9dd7c6129683 43
sam_grove 0:9dd7c6129683 44 #define LSS_WAITING_MODE 0
sam_grove 0:9dd7c6129683 45 #define LSS_CONFIGURATION_MODE 1
sam_grove 0:9dd7c6129683 46
sam_grove 0:9dd7c6129683 47 /* Switch mode services */
sam_grove 0:9dd7c6129683 48 #define LSS_SM_GLOBAL 4
sam_grove 0:9dd7c6129683 49 #define LSS_SM_SELECTIVE_VENDOR 64
sam_grove 0:9dd7c6129683 50 #define LSS_SM_SELECTIVE_PRODUCT 65
sam_grove 0:9dd7c6129683 51 #define LSS_SM_SELECTIVE_REVISION 66
sam_grove 0:9dd7c6129683 52 #define LSS_SM_SELECTIVE_SERIAL 67
sam_grove 0:9dd7c6129683 53 #define LSS_SM_SELECTIVE_RESP 68
sam_grove 0:9dd7c6129683 54 /* Configuration services */
sam_grove 0:9dd7c6129683 55 #define LSS_CONF_NODE_ID 17
sam_grove 0:9dd7c6129683 56 #define LSS_CONF_BIT_TIMING 19
sam_grove 0:9dd7c6129683 57 #define LSS_CONF_ACT_BIT_TIMING 21
sam_grove 0:9dd7c6129683 58 #define LSS_CONF_STORE 23
sam_grove 0:9dd7c6129683 59 /* Inquire services */
sam_grove 0:9dd7c6129683 60 #define LSS_INQ_VENDOR_ID 90
sam_grove 0:9dd7c6129683 61 #define LSS_INQ_PRODUCT_CODE 91
sam_grove 0:9dd7c6129683 62 #define LSS_INQ_REV_NUMBER 92
sam_grove 0:9dd7c6129683 63 #define LSS_INQ_SERIAL_NUMBER 93
sam_grove 0:9dd7c6129683 64 #define LSS_INQ_NODE_ID 94
sam_grove 0:9dd7c6129683 65 /* Identification services */
sam_grove 0:9dd7c6129683 66 #define LSS_IDENT_REMOTE_VENDOR 70
sam_grove 0:9dd7c6129683 67 #define LSS_IDENT_REMOTE_PRODUCT 71
sam_grove 0:9dd7c6129683 68 #define LSS_IDENT_REMOTE_REV_LOW 72
sam_grove 0:9dd7c6129683 69 #define LSS_IDENT_REMOTE_REV_HIGH 73
sam_grove 0:9dd7c6129683 70 #define LSS_IDENT_REMOTE_SERIAL_LOW 74
sam_grove 0:9dd7c6129683 71 #define LSS_IDENT_REMOTE_SERIAL_HIGH 75
sam_grove 0:9dd7c6129683 72 #define LSS_IDENT_REMOTE_NON_CONF 76
sam_grove 0:9dd7c6129683 73 #define LSS_IDENT_SLAVE 79
sam_grove 0:9dd7c6129683 74 #define LSS_IDENT_NON_CONF_SLAVE 80
sam_grove 0:9dd7c6129683 75 #define LSS_IDENT_FASTSCAN 81
sam_grove 0:9dd7c6129683 76
sam_grove 0:9dd7c6129683 77 /*FastScan State Machine*/
sam_grove 0:9dd7c6129683 78 #define LSS_FS_RESET 0
sam_grove 0:9dd7c6129683 79 #define LSS_FS_PROCESSING 1
sam_grove 0:9dd7c6129683 80 #define LSS_FS_CONFIRMATION 2
sam_grove 0:9dd7c6129683 81
sam_grove 0:9dd7c6129683 82
sam_grove 0:9dd7c6129683 83 typedef void (*LSSCallback_t)(CO_Data* d, UNS8 command);
sam_grove 0:9dd7c6129683 84
sam_grove 0:9dd7c6129683 85 typedef void (*lss_StoreConfiguration_t)(CO_Data* d,UNS8*,UNS8*);
sam_grove 0:9dd7c6129683 86 //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error);
sam_grove 0:9dd7c6129683 87
sam_grove 0:9dd7c6129683 88 //typedef void (*lss_ChangeBaudRate_t)(CO_Data* d,char*);
sam_grove 0:9dd7c6129683 89 //void _lss_ChangeBaudRate(char *BaudRate);
sam_grove 0:9dd7c6129683 90
sam_grove 0:9dd7c6129683 91
sam_grove 0:9dd7c6129683 92 struct struct_lss_transfer;
sam_grove 0:9dd7c6129683 93
sam_grove 0:9dd7c6129683 94 //#include "timer.h"
sam_grove 0:9dd7c6129683 95
sam_grove 0:9dd7c6129683 96 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:9dd7c6129683 97 struct struct_lss_fs_transfer {
sam_grove 0:9dd7c6129683 98 UNS32 FS_LSS_ID[4];
sam_grove 0:9dd7c6129683 99 UNS8 FS_BitChecked[4];
sam_grove 0:9dd7c6129683 100 };
sam_grove 0:9dd7c6129683 101
sam_grove 0:9dd7c6129683 102 typedef struct struct_lss_fs_transfer lss_fs_transfer_t;
sam_grove 0:9dd7c6129683 103 #endif
sam_grove 0:9dd7c6129683 104
sam_grove 0:9dd7c6129683 105 /* The Transfer structure
sam_grove 0:9dd7c6129683 106 * Used to store the different fields of the internal state of the LSS
sam_grove 0:9dd7c6129683 107 */
sam_grove 0:9dd7c6129683 108
sam_grove 0:9dd7c6129683 109 struct struct_lss_transfer {
sam_grove 0:9dd7c6129683 110 UNS8 state; /* state of the transmission : Takes the values LSS_... */
sam_grove 0:9dd7c6129683 111 UNS8 command; /* the LSS command of the transmision */
sam_grove 0:9dd7c6129683 112 UNS8 mode; /* LSS mode */
sam_grove 0:9dd7c6129683 113
sam_grove 0:9dd7c6129683 114 UNS32 dat1; /* the data from the last msg received */
sam_grove 0:9dd7c6129683 115 UNS8 dat2;
sam_grove 0:9dd7c6129683 116
sam_grove 0:9dd7c6129683 117 UNS8 nodeID; /* the new nodeid stored to update the nodeid when switching to LSS operational*/
sam_grove 0:9dd7c6129683 118 UNS8 addr_sel_match; /* the matching mask for the LSS Switch Mode Selective service */
sam_grove 0:9dd7c6129683 119 UNS8 addr_ident_match; /* the matching mask for the LSS Identify Remote Slaves service*/
sam_grove 0:9dd7c6129683 120
sam_grove 0:9dd7c6129683 121 char *baudRate; /* the new baudrate stored to update the node baudrate when a Activate Bit
sam_grove 0:9dd7c6129683 122 * Timing Parameters is received*/
sam_grove 0:9dd7c6129683 123 UNS16 switchDelay; /* the period of the two delay */
sam_grove 0:9dd7c6129683 124 UNS8 switchDelayState; /* the state machine for the switchDelay */
sam_grove 0:9dd7c6129683 125 CAN_PORT canHandle_t;
sam_grove 0:9dd7c6129683 126
sam_grove 0:9dd7c6129683 127 /* Time counters to implement a timeout in milliseconds.*/
sam_grove 0:9dd7c6129683 128 TIMER_HANDLE timerMSG; /* timerMSG is automatically incremented whenever
sam_grove 0:9dd7c6129683 129 * the lss state is in LSS_TRANS_IN_PROGRESS, and reseted to 0
sam_grove 0:9dd7c6129683 130 * when the response LSS have been received.
sam_grove 0:9dd7c6129683 131 */
sam_grove 0:9dd7c6129683 132
sam_grove 0:9dd7c6129683 133 TIMER_HANDLE timerSDELAY; /* timerSDELAY is automatically incremented whenever
sam_grove 0:9dd7c6129683 134 * the lss switchDelayState is in SDELAY_FIRST or SDELAY_SECOND, and reseted to 0
sam_grove 0:9dd7c6129683 135 * when the two periods have been expired.
sam_grove 0:9dd7c6129683 136 */
sam_grove 0:9dd7c6129683 137
sam_grove 0:9dd7c6129683 138 LSSCallback_t Callback; /* The user callback func to be called at LSS transaction end */
sam_grove 0:9dd7c6129683 139
sam_grove 0:9dd7c6129683 140 UNS8 LSSanswer; /* stores if a message has been received during a timer period */
sam_grove 0:9dd7c6129683 141
sam_grove 0:9dd7c6129683 142 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:9dd7c6129683 143 UNS32 IDNumber; /* in the master, the LSS address parameter which it currently tries to identify.
sam_grove 0:9dd7c6129683 144 * in the slave, the LSS address parameter which is being checked (LSS-ID[sub]). */
sam_grove 0:9dd7c6129683 145 UNS8 BitChecked; /* bits of the current IDNumber that are currently checked */
sam_grove 0:9dd7c6129683 146 UNS8 LSSSub; /* which part of the LSS-ID is currently checked in IDNumber */
sam_grove 0:9dd7c6129683 147 UNS8 LSSNext; /* which LSSSub value will be used in the next request */
sam_grove 0:9dd7c6129683 148 UNS8 LSSPos; /* in the slave, which part of the LSS-ID is currently processed*/
sam_grove 0:9dd7c6129683 149 UNS8 FastScan_SM; /* the state machine for the FastScan protocol */
sam_grove 0:9dd7c6129683 150 TIMER_HANDLE timerFS; /* timerFS is automatically incremented when the FastScan service
sam_grove 0:9dd7c6129683 151 * has been requested and reseted to 0 when the protocol ends.
sam_grove 0:9dd7c6129683 152 */
sam_grove 0:9dd7c6129683 153 #ifdef CO_ENABLE_LSS_FS
sam_grove 0:9dd7c6129683 154 lss_fs_transfer_t lss_fs_transfer;
sam_grove 0:9dd7c6129683 155 #endif
sam_grove 0:9dd7c6129683 156
sam_grove 0:9dd7c6129683 157 #endif
sam_grove 0:9dd7c6129683 158 };
sam_grove 0:9dd7c6129683 159
sam_grove 0:9dd7c6129683 160 #ifdef CO_ENABLE_LSS
sam_grove 0:9dd7c6129683 161 typedef struct struct_lss_transfer lss_transfer_t;
sam_grove 0:9dd7c6129683 162 #else
sam_grove 0:9dd7c6129683 163 typedef UNS8 lss_transfer_t;
sam_grove 0:9dd7c6129683 164 #endif
sam_grove 0:9dd7c6129683 165
sam_grove 0:9dd7c6129683 166
sam_grove 0:9dd7c6129683 167
sam_grove 0:9dd7c6129683 168 void startLSS(CO_Data* d);
sam_grove 0:9dd7c6129683 169 void stopLSS(CO_Data* d);
sam_grove 0:9dd7c6129683 170
sam_grove 0:9dd7c6129683 171
sam_grove 0:9dd7c6129683 172 /** transmit a LSS message
sam_grove 0:9dd7c6129683 173 * command is the LSS command specifier
sam_grove 0:9dd7c6129683 174 * dat1 and dat2 are pointers to optional data (depend on command)
sam_grove 0:9dd7c6129683 175 * return sendLSSMessage(d,command,dat1,dat2)
sam_grove 0:9dd7c6129683 176 */
sam_grove 0:9dd7c6129683 177 UNS8 sendLSS (CO_Data* d, UNS8 command,void *dat1, void *dat2);
sam_grove 0:9dd7c6129683 178
sam_grove 0:9dd7c6129683 179 /** transmit a LSS message on CAN bus
sam_grove 0:9dd7c6129683 180 * comamnd is the LSS command specifier
sam_grove 0:9dd7c6129683 181 * bus_id is MLSS_ADRESS or SLSS_ADRESS depending in d->iam_a_slave.
sam_grove 0:9dd7c6129683 182 * dat1 and dat2 are pointers to optional data (depend on command).
sam_grove 0:9dd7c6129683 183 * return canSend(bus_id,&m)
sam_grove 0:9dd7c6129683 184 */
sam_grove 0:9dd7c6129683 185
sam_grove 0:9dd7c6129683 186 UNS8 sendLSSMessage(CO_Data* d, UNS8 command, void *dat1, void *dat2);
sam_grove 0:9dd7c6129683 187
sam_grove 0:9dd7c6129683 188 /** This function is called when the node is receiving a Master LSS message (cob-id = 0x7E5).
sam_grove 0:9dd7c6129683 189 * - Check if there is a callback which will take care of the response. If not return 0 but does nothing.
sam_grove 0:9dd7c6129683 190 * - Stops the timer so the alarm wont raise an error.
sam_grove 0:9dd7c6129683 191 * - return 0 if OK
sam_grove 0:9dd7c6129683 192 */
sam_grove 0:9dd7c6129683 193 UNS8 proceedLSS_Master (CO_Data* d, Message* m );
sam_grove 0:9dd7c6129683 194
sam_grove 0:9dd7c6129683 195 /** This function is called when the node is receiving a Slave LSS message (cob-id = 0x7E4).
sam_grove 0:9dd7c6129683 196 * - Call the callback function or send the response message depending on the LSS comand within m.
sam_grove 0:9dd7c6129683 197 * - return 0 if OK
sam_grove 0:9dd7c6129683 198 */
sam_grove 0:9dd7c6129683 199 UNS8 proceedLSS_Slave (CO_Data* d, Message* m );
sam_grove 0:9dd7c6129683 200
sam_grove 0:9dd7c6129683 201 /** Used by the Master application to send a LSS command, WITHOUT response, to the slave.
sam_grove 0:9dd7c6129683 202 * command: the LSS command. LSS_...
sam_grove 0:9dd7c6129683 203 * dat1 and dat2: pointers to optional data (depend on command).
sam_grove 0:9dd7c6129683 204 * return sendLSS(d,command,dat1,dat2)
sam_grove 0:9dd7c6129683 205 */
sam_grove 0:9dd7c6129683 206 //UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2);
sam_grove 0:9dd7c6129683 207
sam_grove 0:9dd7c6129683 208 /**
sam_grove 0:9dd7c6129683 209 * @ingroup lss
sam_grove 0:9dd7c6129683 210 * @brief Used by the Master application to send a LSS command, WITH response, to the slave.
sam_grove 0:9dd7c6129683 211 * @param *d Pointer on a CAN object data structure
sam_grove 0:9dd7c6129683 212 * @param command
sam_grove 0:9dd7c6129683 213 * @param *dat1
sam_grove 0:9dd7c6129683 214 * @param *dat2
sam_grove 0:9dd7c6129683 215 * @param Callback The function Callback, which must be defined in the user code, is called at the
sam_grove 0:9dd7c6129683 216 * end of the exchange (on succes or abort) and can be NULL.
sam_grove 0:9dd7c6129683 217 * @return sendLSS(d,command,dat1,dat2)
sam_grove 0:9dd7c6129683 218 * The LSS_MSG_TIMER timer is started to control the timeout
sam_grove 0:9dd7c6129683 219 */
sam_grove 0:9dd7c6129683 220 UNS8 configNetworkNode (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback);
sam_grove 0:9dd7c6129683 221
sam_grove 0:9dd7c6129683 222 /**
sam_grove 0:9dd7c6129683 223 * @ingroup lss
sam_grove 0:9dd7c6129683 224 * @brief Use this function after a configNetworkNode or configNetworkNodeCallBack to get the result.
sam_grove 0:9dd7c6129683 225 * @param *d Pointer on a CAN object data structure
sam_grove 0:9dd7c6129683 226 * @param command The LSS command (unused).
sam_grove 0:9dd7c6129683 227 * @param *dat1
sam_grove 0:9dd7c6129683 228 * @param *dat2
sam_grove 0:9dd7c6129683 229 * @return :
sam_grove 0:9dd7c6129683 230 * - LSS_RESET // Transmission not started. Init state.
sam_grove 0:9dd7c6129683 231 * - LSS_FINISHED // data are available
sam_grove 0:9dd7c6129683 232 * - LSS_ABORTED_INTERNAL // Aborted but not because of an abort message.
sam_grove 0:9dd7c6129683 233 * - LSS_TRANS_IN_PROGRESS // Data not yet available
sam_grove 0:9dd7c6129683 234 * @code
sam_grove 0:9dd7c6129683 235 * example:
sam_grove 0:9dd7c6129683 236 * UNS32 dat1;
sam_grove 0:9dd7c6129683 237 * UNS8 dat2;
sam_grove 0:9dd7c6129683 238 * res=configNetworkNodeCallBack(&_Data,LSS_INQ_NODE_ID,0,0,NULL); // inquire the nodeID
sam_grove 0:9dd7c6129683 239 * while (getConfigResultNetworkNode (&_Data, LSS_INQ_NODE_ID, &dat1, &dat2) != LSS_TRANS_IN_PROGRESS);
sam_grove 0:9dd7c6129683 240 * @endcode
sam_grove 0:9dd7c6129683 241 */
sam_grove 0:9dd7c6129683 242 UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2);
sam_grove 0:9dd7c6129683 243
sam_grove 0:9dd7c6129683 244 #endif