]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - include/lss.h
5b08635efad9bf397ab1a3bf93071d67bf14ec7b
[CanFestival-3.git] / include / lss.h
1 /*
2 This file is part of CanFestival, a library implementing CanOpen Stack. 
3
4 Copyright (C): Jorge Berzosa
5
6 See COPYING file for copyrights details.
7
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.
12
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.
17
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
21 */
22
23 #ifndef __LSS_h__
24 #define __LSS_h__
25
26 #define SLSS_ADRESS     0x7E4
27 #define MLSS_ADRESS     0x7E5
28
29 #define SDELAY_OFF              0
30 #define SDELAY_FIRST    1
31 #define SDELAY_SECOND   2
32
33 #define LSS_WAITING_MODE 0
34 #define LSS_CONFIGURATION_MODE 1
35
36 /* Switch mode services */
37 #define LSS_SM_GLOBAL                            4
38 #define LSS_SM_SELECTIVE_VENDOR         64
39 #define LSS_SM_SELECTIVE_PRODUCT        65
40 #define LSS_SM_SELECTIVE_REVISION       66
41 #define LSS_SM_SELECTIVE_SERIAL         67
42 #define LSS_SM_SELECTIVE_RESP           68
43 /* Configuration services */
44 #define LSS_CONF_NODE_ID                        17
45 #define LSS_CONF_BIT_TIMING             19
46 #define LSS_CONF_ACT_BIT_TIMING         21
47 #define LSS_CONF_STORE                          23
48 /* Inquire services */
49 #define LSS_INQ_VENDOR_ID               90
50 #define LSS_INQ_PRODUCT_CODE    91
51 #define LSS_INQ_REV_NUMBER              92
52 #define LSS_INQ_SERIAL_NUMBER   93
53 #define LSS_INQ_NODE_ID                 94
54 /* Identification services */
55 #define LSS_IDENT_REMOTE_VENDOR                 70
56 #define LSS_IDENT_REMOTE_PRODUCT                71
57 #define LSS_IDENT_REMOTE_REV_LOW                72
58 #define LSS_IDENT_REMOTE_REV_HIGH               73
59 #define LSS_IDENT_REMOTE_SERIAL_LOW     74
60 #define LSS_IDENT_REMOTE_SERIAL_HIGH    75
61 #define LSS_IDENT_REMOTE_NON_CONF               76
62 #define LSS_IDENT_SLAVE                                 79
63 #define LSS_IDENT_NON_CONF_SLAVE                80
64 #define LSS_IDENT_FASTSCAN                              81
65
66 /*FastScan State Machine*/
67 #define LSS_FS_RESET    0
68 #define LSS_FS_PROCESSING 1
69 #define LSS_FS_CONFIRMATION 2
70
71
72 typedef void (*LSSCallback_t)(CO_Data* d, UNS8 command); 
73
74 typedef void (*lss_StoreConfiguration_t)(CO_Data* d,UNS8*,UNS8*);
75 //void _lss_StoreConfiguration(UNS8 *error, UNS8 *spec_error);
76
77 //typedef void (*lss_ChangeBaudRate_t)(CO_Data* d,char*);
78 //void _lss_ChangeBaudRate(char *BaudRate);
79
80
81 struct struct_lss_transfer;
82
83 //#include "timer.h"
84
85 #ifdef CO_ENABLE_LSS_FS
86 struct struct_lss_fs_transfer {
87         UNS32 FS_LSS_ID[4];
88         UNS8 FS_BitChecked[4];
89 };
90
91 typedef struct struct_lss_fs_transfer lss_fs_transfer_t;
92 #endif
93
94 /* The Transfer structure
95 * Used to store the different fields of the internal state of the LSS  
96 */
97
98 struct struct_lss_transfer {
99   UNS8          state;      /* state of the transmission : Takes the values LSS_... */
100   UNS8                  command;     /* the LSS command of the transmision */
101   UNS8                  mode;       /* LSS mode */
102   
103   UNS32                 dat1;           /* the data from the last msg received */
104   UNS8                  dat2; 
105   
106   UNS8 nodeID;              /* the new nodeid stored to update the nodeid when switching to LSS operational*/
107   UNS8 addr_sel_match;          /* the matching mask for the LSS Switch Mode Selective service */
108   UNS8 addr_ident_match;    /* the matching mask for the LSS Identify Remote Slaves service*/
109
110   char *baudRate;           /* the new baudrate stored to update the node baudrate when a Activate Bit 
111                                                          * Timing Parameters is received*/
112   UNS16 switchDelay;            /* the period of the two delay */
113   UNS8  switchDelayState;   /* the state machine for the switchDelay */
114   CAN_PORT canHandle_t;
115     
116                               /* Time counters to implement a timeout in milliseconds.*/
117   TIMER_HANDLE timerMSG;          /* timerMSG is automatically incremented whenever 
118                               * the lss state is in LSS_TRANS_IN_PROGRESS, and reseted to 0 
119                               * when the response LSS have been received.
120                               */
121                              
122   TIMER_HANDLE timerSDELAY;       /* timerSDELAY is automatically incremented whenever 
123                               * the lss switchDelayState is in SDELAY_FIRST or SDELAY_SECOND, and reseted to 0 
124                               * when the two periods have been expired.
125                               */
126                               
127   LSSCallback_t Callback;   /* The user callback func to be called at LSS transaction end */
128   
129   UNS8 LSSanswer;                       /* stores if a message has been received during a timer period */
130
131 #ifdef CO_ENABLE_LSS_FS 
132   UNS32 IDNumber;                       /* in the master, the LSS address parameter which it currently tries to identify.
133                                                          * in the slave, the LSS address parameter which is being checked (LSS-ID[sub]). */
134   UNS8 BitChecked;                      /* bits of the current IDNumber that are currently checked */
135   UNS8 LSSSub;                          /* which part of the LSS-ID is currently checked in IDNumber */
136   UNS8 LSSNext;                         /* which LSSSub value will be used in the next request */
137   UNS8 LSSPos;                          /* in the slave, which part of the LSS-ID is currently processed*/
138   UNS8 FastScan_SM;                     /* the state machine for the FastScan protocol */
139   TIMER_HANDLE timerFS;         /* timerFS is automatically incremented when the FastScan service
140                                                          * has been requested and reseted to 0 when the protocol ends.
141                               */
142 #ifdef CO_ENABLE_LSS_FS
143   lss_fs_transfer_t lss_fs_transfer;
144 #endif
145   
146 #endif                           
147 };
148
149 #ifdef CO_ENABLE_LSS
150 typedef struct struct_lss_transfer lss_transfer_t;
151 #else
152 typedef UNS8 lss_transfer_t;
153 #endif
154   
155
156
157 void startLSS(CO_Data* d);
158 void stopLSS(CO_Data* d);
159
160
161 /** transmit a LSS message 
162  * command is the LSS command specifier
163  * dat1 and dat2 are pointers to optional data (depend on command)
164  * return sendLSSMessage(d,command,dat1,dat2)
165  */
166 UNS8 sendLSS (CO_Data* d, UNS8 command,void *dat1, void *dat2);
167
168 /** transmit a LSS message on CAN bus
169  * comamnd is the LSS command specifier
170  * bus_id is MLSS_ADRESS or SLSS_ADRESS depending in d->iam_a_slave. 
171  * dat1 and dat2 are pointers to optional data (depend on command).
172  * return canSend(bus_id,&m)
173  */
174  
175 UNS8 sendLSSMessage(CO_Data* d, UNS8 command,  void *dat1, void *dat2);
176
177 /** This function is called when the node is receiving a Master LSS message (cob-id = 0x7E5).
178  *  - Check if there is a callback which will take care of the response. If not return 0 but does nothing.
179  *  - Stops the timer so the alarm wont raise an error.
180  *  - return 0 if OK
181  */
182 UNS8 proceedLSS_Master (CO_Data* d, Message* m );
183
184 /** This function is called when the node is receiving a Slave LSS message (cob-id = 0x7E4).
185  *  - Call the callback function or send the response message depending on the LSS comand within m.
186  *  - return 0 if OK
187  */
188 UNS8 proceedLSS_Slave (CO_Data* d, Message* m );
189
190 /** Used by the Master application to send a LSS command, WITHOUT response, to the slave. 
191  * command: the LSS command. LSS_...
192  * dat1 and dat2: pointers to optional data (depend on command).
193  * return sendLSS(d,command,dat1,dat2)
194  */
195 //UNS8 configNetworkNode(CO_Data* d, UNS8 command, void *dat1, void* dat2);
196
197 /** Used by the Master application to send a LSS command, WITH response, to the slave. 
198  * The function Callback, which must be defined in the user code, is called at the
199  * end of the exchange (on succes or abort) and can be NULL.
200  * The LSS_MSG_TIMER timer is started to control the timeout
201  * return sendLSS(d,command,dat1,dat2)
202  */
203 UNS8 configNetworkNode (CO_Data* d, UNS8 command, void *dat1, void* dat2, LSSCallback_t Callback);
204
205 /** Use this function after a configNetworkNode or configNetworkNodeCallBack to get the result.
206   Returns : LSS_RESET                           // Transmission not started. Init state.
207                         LSS_FINISHED                    // data are available                           
208                         LSS_ABORTED_INTERNAL    // Aborted but not because of an abort message. 
209                         LSS_TRANS_IN_PROGRESS   // Data not yet available
210
211   * command: the LSS command (unused).
212   * example:
213   * UNS32 dat1;
214   * UNS8 dat2;
215   res=configNetworkNodeCallBack(&_Data,LSS_INQ_NODE_ID,0,0,NULL); // inquire the nodeID
216   while (getConfigResultNetworkNode (&_Data, LSS_INQ_NODE_ID, &dat1, &dat2) != LSS_TRANS_IN_PROGRESS);
217 */
218 UNS8 getConfigResultNetworkNode (CO_Data* d, UNS8 command, UNS32* dat1, UNS8* dat2);
219
220 #endif