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