2 This file is part of CanFestival, a library implementing CanOpen Stack.
4 Copyright (C): Jorge Berzosa
6 See COPYING file for copyrights details.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define SLSS_ADRESS 0x7E4
27 #define MLSS_ADRESS 0x7E5
29 #define LSS_MSG_TIMER 0
30 #define LSS_SWITCH_DELAY_TIMER 1
31 #define LSS_FS_TIMER 2
34 #define SDELAY_FIRST 1
35 #define SDELAY_SECOND 2
37 #define LSS_WAITING_MODE 0
38 #define LSS_CONFIGURATION_MODE 1
40 /* Switch mode services */
41 #define LSS_SM_GLOBAL 4
42 #define LSS_SM_SELECTIVE_VENDOR 64
43 #define LSS_SM_SELECTIVE_PRODUCT 65
44 #define LSS_SM_SELECTIVE_REVISION 66
45 #define LSS_SM_SELECTIVE_SERIAL 67
46 #define LSS_SM_SELECTIVE_RESP 68
47 /* Configuration services */
48 #define LSS_CONF_NODE_ID 17
49 #define LSS_CONF_BIT_TIMING 19
50 #define LSS_CONF_ACT_BIT_TIMING 21
51 #define LSS_CONF_STORE 23
52 /* Inquire services */
53 #define LSS_INQ_VENDOR_ID 90
54 #define LSS_INQ_PRODUCT_CODE 91
55 #define LSS_INQ_REV_NUMBER 92
56 #define LSS_INQ_SERIAL_NUMBER 93
57 #define LSS_INQ_NODE_ID 94
58 /* Identification services */
59 #define LSS_IDENT_REMOTE_VENDOR 70
60 #define LSS_IDENT_REMOTE_PRODUCT 71
61 #define LSS_IDENT_REMOTE_REV_LOW 72
62 #define LSS_IDENT_REMOTE_REV_HIGH 73
63 #define LSS_IDENT_REMOTE_SERIAL_LOW 74
64 #define LSS_IDENT_REMOTE_SERIAL_HIGH 75
65 #define LSS_IDENT_REMOTE_NON_CONF 76
66 #define LSS_IDENT_SLAVE 79
67 #define LSS_IDENT_NON_CONF_SLAVE 80
68 #define LSS_IDENT_FASTSCAN 81
70 /*FastScan State Machine*/
71 #define LSS_FS_RESET 0
72 #define LSS_FS_PROCESSING 1
73 #define LSS_FS_CONFIRMATION 2
76 typedef void (*LSSCallback_t)(CO_Data* d, UNS8 command);
78 typedef void (*lss_StoreConfiguration_t)(UNS8*,UNS8*);
79 //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error);
81 typedef void (*lss_ChangeBaudRate_t)(char*);
82 //void _lss_ChangeBaudRate(char *BaudRate);
85 struct struct_lss_transfer;
89 /* The Transfer structure
90 * Used to store the different fields of the internal state of the LSS
93 struct struct_lss_transfer {
94 UNS8 state; /* state of the transmission : Takes the values LSS_... */
95 UNS8 command; /* the LSS command of the transmision */
96 UNS8 mode; /* LSS mode */
98 UNS32 dat1; /* the data from the last msg received */
101 e_nodeState currentState; /* the state of the node before switching to LSSTimingDelay*/
102 UNS8 nodeID; /* the new nodeid stored to update the nodeid when switching to LSS operational*/
103 UNS8 addr_sel_match; /* the matching mask for the LSS Switch Mode Selective service */
104 UNS8 addr_ident_match; /* the matching mask for the LSS Identify Remote Slaves service*/
106 char *baudRate; /* the new baudrate stored to update the node baudrate when a Activate Bit
107 * Timing Parameters is received*/
108 UNS16 switchDelay; /* the period of the two delay */
109 UNS8 switchDelayState; /* the state machine for the switchDelay */
111 TIMER_HANDLE timers[3]; /* Time counters to implement a timeout in milliseconds.
112 * LSS_MSG_TIMER (index 0) is automatically incremented whenever
113 * the lss state is in LSS_TRANS_IN_PROGRESS, and reseted to 0
114 * when the response LSS have been received.
115 * LSS_SWITCH_DELAY_TIMER (index 1) is automatically incremented whenever
116 * the lss switchDelayState is in SDELAY_FIRST or SDELAY_SECOND, and reseted to 0
117 * when the two periods have been expired.
119 LSSCallback_t Callback; /* The user callback func to be called at LSS transaction end */
121 UNS8 LSSanswer; /* stores if a message has been received during a timer period */
123 UNS32 IDNumber; /* in the master, the LSS address parameter which it currently tries to identify.
124 * in the slave, the LSS address parameter which is being checked (LSS-ID[sub]). */
125 UNS8 BitChecked; /* bits of the current IDNumber that are currently checked */
126 UNS8 LSSSub; /* which part of the LSS-ID is currently checked in IDNumber */
127 UNS8 LSSNext; /* which LSSSub value will be used in the next request */
128 UNS8 LSSPos; /* in the slave, which part of the LSS-ID is currently processed*/
129 UNS8 FastScan_SM; /* the state machine for the FastScan protocol */
133 typedef struct struct_lss_transfer lss_transfer_t;
135 typedef UNS8 lss_transfer_t;
139 void startLSS(CO_Data* d);
140 void stopLSS(CO_Data* d);
143 /** transmit a LSS message
144 * Checks if the msg can be transmited (i.e. we are not in LssTimingDelay state)
145 * command is the LSS command specifier
146 * dat1 and dat2 are pointers to optional data (depend on command)
147 * return sendLSSMessage(d,command,dat1,dat2)
149 UNS8 sendLSS (CO_Data* d, UNS8 command,void *dat1, void *dat2);
151 /** transmit a LSS message on CAN bus
152 * comamnd is the LSS command specifier
153 * bus_id is MLSS_ADRESS or SLSS_ADRESS depending in d->iam_a_slave.
154 * dat1 and dat2 are pointers to optional data (depend on command).
155 * return canSend(bus_id,&m)
158 UNS8 sendLSSMessage(CO_Data* d, UNS8 command, void *dat1, void *dat2);
160 /** This function is called when the node is receiving a Master LSS message (cob-id = 0x7E5).
161 * - Check if there is a callback which will take care of the response. If not return 0 but does nothing.
162 * - Stops the timer so the alarm wont raise an error.
165 UNS8 proceedLSS_Master (CO_Data* d, Message* m );
167 /** This function is called when the node is receiving a Slave LSS message (cob-id = 0x7E4).
168 * - Call the callback function or send the response message depending on the LSS comand within m.
171 UNS8 proceedLSS_Slave (CO_Data* d, Message* m );
173 /** Used by the Master application to send a LSS command, WITHOUT response, to the slave.
174 * command: the LSS command. LSS_...
175 * dat1 and dat2: pointers to optional data (depend on command).
176 * return sendLSS(d,command,dat1,dat2)
178 UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2);
180 /** Used by the Master application to send a LSS command, WITH response, to the slave.
181 * The function Callback, which must be defined in the user code, is called at the
182 * end of the exchange (on succes or abort) and can be NULL.
183 * The LSS_MSG_TIMER timer is started to control the timeout
184 * return sendLSS(d,command,dat1,dat2)
186 UNS8 configNetworkNodeCallBack (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback);
188 /** Use this function after a configNetworkNode or configNetworkNodeCallBack to get the result.
189 Returns : LSS_RESET // Transmission not started. Init state.
190 LSS_FINISHED // data are available
191 LSS_ABORTED_INTERNAL // Aborted but not because of an abort message.
192 LSS_TRANS_IN_PROGRESS // Data not yet available
194 * command: the LSS command (unused).
198 res=configNetworkNodeCallBack(&_Data,LSS_INQ_NODE_ID,0,0,NULL); // inquire the nodeID
199 while (getConfigResultNetworkNode (&_Data, LSS_INQ_NODE_ID, &dat1, &dat2) != LSS_TRANS_IN_PROGRESS);
201 UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2);