Sam Grove / Mbed 2 deprecated canopen_masternode

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lss.h Source File

lss.h

00001 /*
00002 This file is part of CanFestival, a library implementing CanOpen Stack. 
00003 
00004 Copyright (C): Jorge Berzosa
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 lss Layer Setting Services Object
00024  * @brief LSS offers the possibility to inquire and change the settings of certain parameters of the local layers on
00025  * a CANopen module with LSS Slave capabilities by a CANopen module with LSS Master capabilities via the
00026  * CAN Network.
00027  * The following parameters can be inquired and/or changed by the use of LSS:
00028  *               - Node-ID of the CANopen Slave
00029  *               - Bit timing parameters of the physical layer (baud rate)
00030  *               - LSS address (/2/ Identity Object, Index 1018H)
00031  *  @ingroup comobj
00032  */
00033                      
00034 #ifndef __LSS_h__
00035 #define __LSS_h__
00036 
00037 #define SLSS_ADRESS    0x7E4
00038 #define MLSS_ADRESS    0x7E5
00039 
00040 #define SDELAY_OFF        0
00041 #define SDELAY_FIRST     1
00042 #define SDELAY_SECOND     2
00043 
00044 #define LSS_WAITING_MODE 0
00045 #define LSS_CONFIGURATION_MODE 1
00046 
00047 /* Switch mode services */
00048 #define LSS_SM_GLOBAL                  4
00049 #define LSS_SM_SELECTIVE_VENDOR     64
00050 #define LSS_SM_SELECTIVE_PRODUCT     65
00051 #define LSS_SM_SELECTIVE_REVISION     66
00052 #define LSS_SM_SELECTIVE_SERIAL     67
00053 #define LSS_SM_SELECTIVE_RESP         68
00054 /* Configuration services */
00055 #define LSS_CONF_NODE_ID             17
00056 #define LSS_CONF_BIT_TIMING         19
00057 #define LSS_CONF_ACT_BIT_TIMING     21
00058 #define LSS_CONF_STORE                 23
00059 /* Inquire services */
00060 #define LSS_INQ_VENDOR_ID         90
00061 #define LSS_INQ_PRODUCT_CODE     91
00062 #define LSS_INQ_REV_NUMBER         92
00063 #define LSS_INQ_SERIAL_NUMBER     93
00064 #define LSS_INQ_NODE_ID         94
00065 /* Identification services */
00066 #define LSS_IDENT_REMOTE_VENDOR         70
00067 #define LSS_IDENT_REMOTE_PRODUCT         71
00068 #define LSS_IDENT_REMOTE_REV_LOW         72
00069 #define LSS_IDENT_REMOTE_REV_HIGH         73
00070 #define LSS_IDENT_REMOTE_SERIAL_LOW     74
00071 #define LSS_IDENT_REMOTE_SERIAL_HIGH     75
00072 #define LSS_IDENT_REMOTE_NON_CONF         76
00073 #define LSS_IDENT_SLAVE                 79
00074 #define LSS_IDENT_NON_CONF_SLAVE         80
00075 #define LSS_IDENT_FASTSCAN                81
00076 
00077 /*FastScan State Machine*/
00078 #define LSS_FS_RESET    0
00079 #define LSS_FS_PROCESSING 1
00080 #define LSS_FS_CONFIRMATION 2
00081 
00082 
00083 typedef void (*LSSCallback_t)(CO_Data* d, UNS8 command); 
00084 
00085 typedef void (*lss_StoreConfiguration_t)(CO_Data* d,UNS8*,UNS8*);
00086 //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error);
00087 
00088 //typedef void (*lss_ChangeBaudRate_t)(CO_Data* d,char*);
00089 //void _lss_ChangeBaudRate(char *BaudRate);
00090 
00091 
00092 struct struct_lss_transfer;
00093 
00094 //#include "timer.h"
00095 
00096 #ifdef CO_ENABLE_LSS_FS
00097 struct struct_lss_fs_transfer {
00098     UNS32 FS_LSS_ID[4];
00099     UNS8 FS_BitChecked[4];
00100 };
00101 
00102 typedef struct struct_lss_fs_transfer lss_fs_transfer_t;
00103 #endif
00104 
00105 /* The Transfer structure
00106 * Used to store the different fields of the internal state of the LSS  
00107 */
00108 
00109 struct struct_lss_transfer {
00110   UNS8          state;      /* state of the transmission : Takes the values LSS_... */
00111   UNS8             command;     /* the LSS command of the transmision */
00112   UNS8            mode;       /* LSS mode */
00113   
00114   UNS32         dat1;        /* the data from the last msg received */
00115   UNS8            dat2; 
00116   
00117   UNS8 nodeID;              /* the new nodeid stored to update the nodeid when switching to LSS operational*/
00118   UNS8 addr_sel_match;        /* the matching mask for the LSS Switch Mode Selective service */
00119   UNS8 addr_ident_match;    /* the matching mask for the LSS Identify Remote Slaves service*/
00120 
00121   char *baudRate;           /* the new baudrate stored to update the node baudrate when a Activate Bit 
00122                                * Timing Parameters is received*/
00123   UNS16 switchDelay;        /* the period of the two delay */
00124   UNS8  switchDelayState;   /* the state machine for the switchDelay */
00125   CAN_PORT canHandle_t;
00126     
00127                               /* Time counters to implement a timeout in milliseconds.*/
00128   TIMER_HANDLE timerMSG;      /* timerMSG is automatically incremented whenever 
00129                               * the lss state is in LSS_TRANS_IN_PROGRESS, and reseted to 0 
00130                               * when the response LSS have been received.
00131                               */
00132                              
00133   TIMER_HANDLE timerSDELAY;      /* timerSDELAY is automatically incremented whenever 
00134                               * the lss switchDelayState is in SDELAY_FIRST or SDELAY_SECOND, and reseted to 0 
00135                               * when the two periods have been expired.
00136                               */
00137                               
00138   LSSCallback_t Callback;   /* The user callback func to be called at LSS transaction end */
00139   
00140   UNS8 LSSanswer;            /* stores if a message has been received during a timer period */
00141 
00142 #ifdef CO_ENABLE_LSS_FS 
00143   UNS32 IDNumber;            /* in the master, the LSS address parameter which it currently tries to identify.
00144                                * in the slave, the LSS address parameter which is being checked (LSS-ID[sub]). */
00145   UNS8 BitChecked;            /* bits of the current IDNumber that are currently checked */
00146   UNS8 LSSSub;                /* which part of the LSS-ID is currently checked in IDNumber */
00147   UNS8 LSSNext;                /* which LSSSub value will be used in the next request */
00148   UNS8 LSSPos;                /* in the slave, which part of the LSS-ID is currently processed*/
00149   UNS8 FastScan_SM;            /* the state machine for the FastScan protocol */
00150   TIMER_HANDLE timerFS;        /* timerFS is automatically incremented when the FastScan service
00151                                * has been requested and reseted to 0 when the protocol ends.
00152                               */
00153 #ifdef CO_ENABLE_LSS_FS
00154   lss_fs_transfer_t lss_fs_transfer;
00155 #endif
00156   
00157 #endif                           
00158 };
00159 
00160 #ifdef CO_ENABLE_LSS
00161 typedef struct struct_lss_transfer lss_transfer_t;
00162 #else
00163 typedef UNS8 lss_transfer_t;
00164 #endif
00165   
00166 
00167 
00168 void startLSS (CO_Data* d);
00169 void stopLSS (CO_Data* d);
00170 
00171 
00172 /** transmit a LSS message 
00173  * command is the LSS command specifier
00174  * dat1 and dat2 are pointers to optional data (depend on command)
00175  * return sendLSSMessage(d,command,dat1,dat2)
00176  */
00177 UNS8 sendLSS (CO_Data* d, UNS8 command,void *dat1, void *dat2);
00178 
00179 /** transmit a LSS message on CAN bus
00180  * comamnd is the LSS command specifier
00181  * bus_id is MLSS_ADRESS or SLSS_ADRESS depending in d->iam_a_slave. 
00182  * dat1 and dat2 are pointers to optional data (depend on command).
00183  * return canSend(bus_id,&m)
00184  */
00185  
00186 UNS8 sendLSSMessage(CO_Data* d, UNS8 command,  void *dat1, void *dat2);
00187 
00188 /** This function is called when the node is receiving a Master LSS message (cob-id = 0x7E5).
00189  *  - Check if there is a callback which will take care of the response. If not return 0 but does nothing.
00190  *  - Stops the timer so the alarm wont raise an error.
00191  *  - return 0 if OK
00192  */
00193 UNS8 proceedLSS_Master (CO_Data* d, Message* m );
00194 
00195 /** This function is called when the node is receiving a Slave LSS message (cob-id = 0x7E4).
00196  *  - Call the callback function or send the response message depending on the LSS comand within m.
00197  *  - return 0 if OK
00198  */
00199 UNS8 proceedLSS_Slave (CO_Data* d, Message* m );
00200 
00201 /** Used by the Master application to send a LSS command, WITHOUT response, to the slave. 
00202  * command: the LSS command. LSS_...
00203  * dat1 and dat2: pointers to optional data (depend on command).
00204  * return sendLSS(d,command,dat1,dat2)
00205  */
00206 //UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2);
00207 
00208 /** 
00209  * @ingroup lss
00210  * @brief Used by the Master application to send a LSS command, WITH response, to the slave. 
00211  * @param *d Pointer on a CAN object data structure
00212  * @param command
00213  * @param *dat1
00214  * @param *dat2
00215  * @param Callback The function Callback, which must be defined in the user code, is called at the
00216  * end of the exchange (on succes or abort) and can be NULL.
00217  * @return sendLSS(d,command,dat1,dat2)
00218  * The LSS_MSG_TIMER timer is started to control the timeout
00219  */
00220 UNS8 configNetworkNode (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback);
00221 
00222 /**
00223  * @ingroup lss 
00224  * @brief Use this function after a configNetworkNode or configNetworkNodeCallBack to get the result.
00225  * @param *d Pointer on a CAN object data structure
00226  * @param command The LSS command (unused).
00227  * @param *dat1
00228  * @param *dat2
00229  * @return : 
00230  *          - LSS_RESET                // Transmission not started. Init state.
00231  *          - LSS_FINISHED            // data are available                           
00232  *          - LSS_ABORTED_INTERNAL    // Aborted but not because of an abort message. 
00233  *          - LSS_TRANS_IN_PROGRESS    // Data not yet available
00234  * @code
00235  * example:
00236  * UNS32 dat1;
00237  * UNS8 dat2;
00238  * res=configNetworkNodeCallBack(&_Data,LSS_INQ_NODE_ID,0,0,NULL); // inquire the nodeID
00239  * while (getConfigResultNetworkNode (&_Data, LSS_INQ_NODE_ID, &dat1, &dat2) != LSS_TRANS_IN_PROGRESS);
00240  * @endcode
00241 */
00242 UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2);
00243 
00244 #endif