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