etisserant@343: /* etisserant@343: This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@343: etisserant@343: Copyright (C): Jorge Berzosa etisserant@343: etisserant@343: See COPYING file for copyrights details. etisserant@343: etisserant@343: This library is free software; you can redistribute it and/or etisserant@343: modify it under the terms of the GNU Lesser General Public etisserant@343: License as published by the Free Software Foundation; either etisserant@343: version 2.1 of the License, or (at your option) any later version. etisserant@343: etisserant@343: This library is distributed in the hope that it will be useful, etisserant@343: but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@343: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@343: Lesser General Public License for more details. etisserant@343: etisserant@343: You should have received a copy of the GNU Lesser General Public etisserant@343: License along with this library; if not, write to the Free Software etisserant@343: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@343: */ etisserant@343: greg@529: /** @defgroup lss Layer Setting Services Object greg@529: * @brief LSS offers the possibility to inquire and change the settings of certain parameters of the local layers on greg@529: * a CANopen module with LSS Slave capabilities by a CANopen module with LSS Master capabilities via the greg@529: * CAN Network. greg@529: * The following parameters can be inquired and/or changed by the use of LSS: greg@529: * - Node-ID of the CANopen Slave greg@529: * - Bit timing parameters of the physical layer (baud rate) greg@529: * - LSS address (/2/ Identity Object, Index 1018H) greg@528: * @ingroup comobj greg@528: */ greg@528: etisserant@343: #ifndef __LSS_h__ etisserant@343: #define __LSS_h__ etisserant@343: etisserant@343: #define SLSS_ADRESS 0x7E4 etisserant@343: #define MLSS_ADRESS 0x7E5 etisserant@343: etisserant@343: #define SDELAY_OFF 0 etisserant@343: #define SDELAY_FIRST 1 etisserant@343: #define SDELAY_SECOND 2 etisserant@343: etisserant@343: #define LSS_WAITING_MODE 0 etisserant@343: #define LSS_CONFIGURATION_MODE 1 etisserant@343: etisserant@343: /* Switch mode services */ etisserant@343: #define LSS_SM_GLOBAL 4 etisserant@343: #define LSS_SM_SELECTIVE_VENDOR 64 etisserant@343: #define LSS_SM_SELECTIVE_PRODUCT 65 etisserant@343: #define LSS_SM_SELECTIVE_REVISION 66 etisserant@343: #define LSS_SM_SELECTIVE_SERIAL 67 etisserant@343: #define LSS_SM_SELECTIVE_RESP 68 etisserant@343: /* Configuration services */ etisserant@343: #define LSS_CONF_NODE_ID 17 etisserant@343: #define LSS_CONF_BIT_TIMING 19 etisserant@343: #define LSS_CONF_ACT_BIT_TIMING 21 etisserant@343: #define LSS_CONF_STORE 23 etisserant@343: /* Inquire services */ etisserant@343: #define LSS_INQ_VENDOR_ID 90 etisserant@343: #define LSS_INQ_PRODUCT_CODE 91 etisserant@343: #define LSS_INQ_REV_NUMBER 92 etisserant@343: #define LSS_INQ_SERIAL_NUMBER 93 etisserant@343: #define LSS_INQ_NODE_ID 94 etisserant@343: /* Identification services */ etisserant@343: #define LSS_IDENT_REMOTE_VENDOR 70 etisserant@343: #define LSS_IDENT_REMOTE_PRODUCT 71 etisserant@343: #define LSS_IDENT_REMOTE_REV_LOW 72 etisserant@343: #define LSS_IDENT_REMOTE_REV_HIGH 73 etisserant@343: #define LSS_IDENT_REMOTE_SERIAL_LOW 74 etisserant@343: #define LSS_IDENT_REMOTE_SERIAL_HIGH 75 etisserant@343: #define LSS_IDENT_REMOTE_NON_CONF 76 etisserant@343: #define LSS_IDENT_SLAVE 79 etisserant@343: #define LSS_IDENT_NON_CONF_SLAVE 80 etisserant@343: #define LSS_IDENT_FASTSCAN 81 etisserant@343: etisserant@343: /*FastScan State Machine*/ etisserant@343: #define LSS_FS_RESET 0 groke6@361: #define LSS_FS_PROCESSING 1 groke6@361: #define LSS_FS_CONFIRMATION 2 etisserant@343: etisserant@343: etisserant@343: typedef void (*LSSCallback_t)(CO_Data* d, UNS8 command); etisserant@343: groke6@381: typedef void (*lss_StoreConfiguration_t)(CO_Data* d,UNS8*,UNS8*); etisserant@343: //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error); etisserant@343: groke6@384: //typedef void (*lss_ChangeBaudRate_t)(CO_Data* d,char*); etisserant@343: //void _lss_ChangeBaudRate(char *BaudRate); etisserant@343: etisserant@343: etisserant@343: struct struct_lss_transfer; etisserant@343: Edouard@801: //#include "timers.h" etisserant@343: groke6@517: #ifdef CO_ENABLE_LSS_FS groke6@517: struct struct_lss_fs_transfer { groke6@517: UNS32 FS_LSS_ID[4]; groke6@517: UNS8 FS_BitChecked[4]; groke6@517: }; groke6@517: groke6@517: typedef struct struct_lss_fs_transfer lss_fs_transfer_t; groke6@517: #endif groke6@517: etisserant@343: /* The Transfer structure etisserant@343: * Used to store the different fields of the internal state of the LSS etisserant@343: */ etisserant@343: etisserant@343: struct struct_lss_transfer { etisserant@343: UNS8 state; /* state of the transmission : Takes the values LSS_... */ etisserant@343: UNS8 command; /* the LSS command of the transmision */ etisserant@343: UNS8 mode; /* LSS mode */ etisserant@343: etisserant@343: UNS32 dat1; /* the data from the last msg received */ etisserant@343: UNS8 dat2; etisserant@343: etisserant@343: UNS8 nodeID; /* the new nodeid stored to update the nodeid when switching to LSS operational*/ etisserant@343: UNS8 addr_sel_match; /* the matching mask for the LSS Switch Mode Selective service */ etisserant@343: UNS8 addr_ident_match; /* the matching mask for the LSS Identify Remote Slaves service*/ etisserant@343: etisserant@343: char *baudRate; /* the new baudrate stored to update the node baudrate when a Activate Bit etisserant@343: * Timing Parameters is received*/ etisserant@343: UNS16 switchDelay; /* the period of the two delay */ etisserant@343: UNS8 switchDelayState; /* the state machine for the switchDelay */ etisserant@405: CAN_PORT canHandle_t; groke6@381: groke6@381: /* Time counters to implement a timeout in milliseconds.*/ groke6@381: TIMER_HANDLE timerMSG; /* timerMSG is automatically incremented whenever etisserant@343: * the lss state is in LSS_TRANS_IN_PROGRESS, and reseted to 0 etisserant@343: * when the response LSS have been received. groke6@381: */ groke6@381: groke6@381: TIMER_HANDLE timerSDELAY; /* timerSDELAY is automatically incremented whenever etisserant@343: * the lss switchDelayState is in SDELAY_FIRST or SDELAY_SECOND, and reseted to 0 etisserant@343: * when the two periods have been expired. etisserant@343: */ groke6@381: etisserant@343: LSSCallback_t Callback; /* The user callback func to be called at LSS transaction end */ etisserant@343: groke6@361: UNS8 LSSanswer; /* stores if a message has been received during a timer period */ groke6@381: groke6@381: #ifdef CO_ENABLE_LSS_FS groke6@361: UNS32 IDNumber; /* in the master, the LSS address parameter which it currently tries to identify. groke6@361: * in the slave, the LSS address parameter which is being checked (LSS-ID[sub]). */ groke6@361: UNS8 BitChecked; /* bits of the current IDNumber that are currently checked */ groke6@361: UNS8 LSSSub; /* which part of the LSS-ID is currently checked in IDNumber */ groke6@361: UNS8 LSSNext; /* which LSSSub value will be used in the next request */ groke6@361: UNS8 LSSPos; /* in the slave, which part of the LSS-ID is currently processed*/ groke6@361: UNS8 FastScan_SM; /* the state machine for the FastScan protocol */ groke6@381: TIMER_HANDLE timerFS; /* timerFS is automatically incremented when the FastScan service groke6@381: * has been requested and reseted to 0 when the protocol ends. groke6@381: */ groke6@517: #ifdef CO_ENABLE_LSS_FS groke6@517: lss_fs_transfer_t lss_fs_transfer; groke6@517: #endif groke6@517: groke6@381: #endif etisserant@343: }; etisserant@343: etisserant@343: #ifdef CO_ENABLE_LSS etisserant@343: typedef struct struct_lss_transfer lss_transfer_t; etisserant@343: #else etisserant@343: typedef UNS8 lss_transfer_t; etisserant@343: #endif etisserant@343: groke6@517: groke6@517: etisserant@343: void startLSS(CO_Data* d); etisserant@343: void stopLSS(CO_Data* d); etisserant@343: etisserant@343: etisserant@343: /** transmit a LSS message etisserant@343: * command is the LSS command specifier etisserant@343: * dat1 and dat2 are pointers to optional data (depend on command) etisserant@343: * return sendLSSMessage(d,command,dat1,dat2) etisserant@343: */ etisserant@343: UNS8 sendLSS (CO_Data* d, UNS8 command,void *dat1, void *dat2); etisserant@343: etisserant@343: /** transmit a LSS message on CAN bus etisserant@343: * comamnd is the LSS command specifier etisserant@343: * bus_id is MLSS_ADRESS or SLSS_ADRESS depending in d->iam_a_slave. etisserant@343: * dat1 and dat2 are pointers to optional data (depend on command). etisserant@343: * return canSend(bus_id,&m) etisserant@343: */ etisserant@343: etisserant@343: UNS8 sendLSSMessage(CO_Data* d, UNS8 command, void *dat1, void *dat2); etisserant@343: etisserant@343: /** This function is called when the node is receiving a Master LSS message (cob-id = 0x7E5). etisserant@343: * - Check if there is a callback which will take care of the response. If not return 0 but does nothing. etisserant@343: * - Stops the timer so the alarm wont raise an error. etisserant@343: * - return 0 if OK etisserant@343: */ etisserant@343: UNS8 proceedLSS_Master (CO_Data* d, Message* m ); etisserant@343: etisserant@343: /** This function is called when the node is receiving a Slave LSS message (cob-id = 0x7E4). etisserant@343: * - Call the callback function or send the response message depending on the LSS comand within m. etisserant@343: * - return 0 if OK etisserant@343: */ etisserant@343: UNS8 proceedLSS_Slave (CO_Data* d, Message* m ); etisserant@343: etisserant@343: /** Used by the Master application to send a LSS command, WITHOUT response, to the slave. etisserant@343: * command: the LSS command. LSS_... etisserant@343: * dat1 and dat2: pointers to optional data (depend on command). etisserant@343: * return sendLSS(d,command,dat1,dat2) etisserant@343: */ groke6@381: //UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2); etisserant@343: greg@529: /** greg@529: * @ingroup lss greg@529: * @brief Used by the Master application to send a LSS command, WITH response, to the slave. greg@529: * @param *d Pointer on a CAN object data structure greg@529: * @param command greg@529: * @param *dat1 greg@529: * @param *dat2 greg@529: * @param Callback The function Callback, which must be defined in the user code, is called at the etisserant@343: * end of the exchange (on succes or abort) and can be NULL. greg@529: * @return sendLSS(d,command,dat1,dat2) etisserant@343: * The LSS_MSG_TIMER timer is started to control the timeout etisserant@343: */ groke6@381: UNS8 configNetworkNode (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback); etisserant@343: greg@529: /** greg@529: * @ingroup lss greg@529: * @brief Use this function after a configNetworkNode or configNetworkNodeCallBack to get the result. greg@529: * @param *d Pointer on a CAN object data structure greg@529: * @param command The LSS command (unused). greg@529: * @param *dat1 greg@529: * @param *dat2 greg@529: * @return : greg@529: * - LSS_RESET // Transmission not started. Init state. greg@529: * - LSS_FINISHED // data are available greg@529: * - LSS_ABORTED_INTERNAL // Aborted but not because of an abort message. greg@529: * - LSS_TRANS_IN_PROGRESS // Data not yet available greg@529: * @code greg@529: * example: greg@529: * UNS32 dat1; greg@529: * UNS8 dat2; greg@529: * res=configNetworkNodeCallBack(&_Data,LSS_INQ_NODE_ID,0,0,NULL); // inquire the nodeID greg@529: * while (getConfigResultNetworkNode (&_Data, LSS_INQ_NODE_ID, &dat1, &dat2) != LSS_TRANS_IN_PROGRESS); greg@529: * @endcode etisserant@343: */ etisserant@343: UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2); etisserant@343: etisserant@343: #endif