28 #include "timer.h" |
28 #include "timer.h" |
29 |
29 |
30 typedef void (*SDOCallback_t)(CO_Data* d, UNS8 nodeId); |
30 typedef void (*SDOCallback_t)(CO_Data* d, UNS8 nodeId); |
31 |
31 |
32 /* The Transfer structure |
32 /* The Transfer structure |
33 Used to store the different segments of |
33 Used to store the different segments of |
34 - a SDO received before writing in the dictionary |
34 - a SDO received before writing in the dictionary |
35 - the reading of the dictionary to put on a SDO to transmit |
35 - the reading of the dictionary to put on a SDO to transmit |
36 */ |
36 */ |
37 |
37 |
38 struct struct_s_transfer { |
38 struct struct_s_transfer { |
39 UNS8 nodeId; /*own ID if server, or node ID of the server if client */ |
39 UNS8 nodeId; /*own ID if server, or node ID of the server if client */ |
40 |
40 |
41 UNS8 whoami; /* Takes the values SDO_CLIENT or SDO_SERVER */ |
41 UNS8 whoami; /* Takes the values SDO_CLIENT or SDO_SERVER */ |
42 UNS8 state; /* state of the transmission : Takes the values SDO_... */ |
42 UNS8 state; /* state of the transmission : Takes the values SDO_... */ |
43 UNS8 toggle; |
43 UNS8 toggle; |
44 UNS32 abortCode; /* Sent or received */ |
44 UNS32 abortCode; /* Sent or received */ |
45 /* index and subindex of the dictionary where to store */ |
45 /* index and subindex of the dictionary where to store */ |
46 /* (for a received SDO) or to read (for a transmit SDO) */ |
46 /* (for a received SDO) or to read (for a transmit SDO) */ |
47 UNS16 index; |
47 UNS16 index; |
48 UNS8 subIndex; |
48 UNS8 subIndex; |
49 UNS32 count; /* Number of data received or to be sent. */ |
49 UNS32 count; /* Number of data received or to be sent. */ |
50 UNS32 offset; /* stack pointer of data[] |
50 UNS32 offset; /* stack pointer of data[] |
51 * Used only to tranfer part of a line to or from a SDO. |
51 * Used only to tranfer part of a line to or from a SDO. |
52 * offset is always pointing on the next free cell of data[]. |
52 * offset is always pointing on the next free cell of data[]. |
53 * WARNING s_transfer.data is subject to ENDIANISATION |
53 * WARNING s_transfer.data is subject to ENDIANISATION |
54 * (with respect to CANOPEN_BIG_ENDIAN) |
54 * (with respect to CANOPEN_BIG_ENDIAN) |
55 */ |
55 */ |
56 UNS8 data [SDO_MAX_LENGTH_TRANSFERT]; |
56 UNS8 data [SDO_MAX_LENGTH_TRANSFERT]; |
57 UNS8 dataType; /* Defined in objdictdef.h Value is visible_string |
57 UNS8 dataType; /* Defined in objdictdef.h Value is visible_string |
58 * if it is a string, any other value if it is not a string, |
58 * if it is a string, any other value if it is not a string, |
59 * like 0. In fact, it is used only if client. |
59 * like 0. In fact, it is used only if client. |
60 */ |
60 */ |
61 TIMER_HANDLE timer; /* Time counter to implement a timeout in milliseconds. |
61 TIMER_HANDLE timer; /* Time counter to implement a timeout in milliseconds. |
62 * It is automatically incremented whenever |
62 * It is automatically incremented whenever |
63 * the line state is in SDO_DOWNLOAD_IN_PROGRESS or |
63 * the line state is in SDO_DOWNLOAD_IN_PROGRESS or |
64 * SDO_UPLOAD_IN_PROGRESS, and reseted to 0 |
64 * SDO_UPLOAD_IN_PROGRESS, and reseted to 0 |
65 * when the response SDO have been received. |
65 * when the response SDO have been received. |
66 */ |
66 */ |
67 SDOCallback_t Callback; /* The user callback func to be called at SDO transaction end */ |
67 SDOCallback_t Callback; /* The user callback func to be called at SDO transaction end */ |
68 }; |
68 }; |
69 typedef struct struct_s_transfer s_transfer; |
69 typedef struct struct_s_transfer s_transfer; |
70 |
70 |
71 |
71 |
72 #include "data.h" |
72 #include "data.h" |
73 |
73 |
74 /* The 8 bytes data of the SDO */ |
74 /* The 8 bytes data of the SDO */ |
75 struct BODY{ |
75 struct BODY{ |
83 }; |
83 }; |
84 |
84 |
85 |
85 |
86 typedef struct struct_s_SDO s_SDO; |
86 typedef struct struct_s_SDO s_SDO; |
87 |
87 |
88 /** Reset of a SDO exchange on timeout. |
88 /** Reset of a SDO exchange on timeout. |
89 * Send a SDO abort |
89 * Send a SDO abort |
90 */ |
90 */ |
91 void SDOTimeoutAlarm(CO_Data* d, UNS32 id); |
91 void SDOTimeoutAlarm(CO_Data* d, UNS32 id); |
92 |
92 |
93 /** Reset all sdo buffers |
93 /** Reset all sdo buffers |
94 */ |
94 */ |
95 void resetSDO (CO_Data* d); |
95 void resetSDO (CO_Data* d); |
96 |
96 |
97 |
97 |
98 /** Copy the data received from the SDO line transfert to the object dictionary |
98 /** Copy the data received from the SDO line transfert to the object dictionary |
99 * Returns SDO error code if error. Else, returns 0; |
99 * Returns SDO error code if error. Else, returns 0; |
100 */ |
100 */ |
101 UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line); |
101 UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line); |
102 |
102 |
103 /** Copy the data from the object dictionary to the SDO line for a network transfert. |
103 /** Copy the data from the object dictionary to the SDO line for a network transfert. |
104 * Returns SDO error code if error. Else, returns 0; |
104 * Returns SDO error code if error. Else, returns 0; |
105 */ |
105 */ |
106 UNS32 objdictToSDOline (CO_Data* d, UNS8 line); |
106 UNS32 objdictToSDOline (CO_Data* d, UNS8 line); |
107 |
107 |
108 /** copy data from an existant line in the argument "* data" |
108 /** copy data from an existant line in the argument "* data" |
109 * Returns 0xFF if error. Else, returns 0; |
109 * Returns 0xFF if error. Else, returns 0; |
110 */ |
110 */ |
111 UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data); |
111 UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data); |
112 |
112 |
113 /** Add data to an existant line |
113 /** Add data to an existant line |
114 * Returns 0xFF if error. Else, returns 0; |
114 * Returns 0xFF if error. Else, returns 0; |
115 */ |
115 */ |
116 UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data); |
116 UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8 * data); |
117 |
117 |
118 /** Called when an internal SDO abort occurs. |
118 /** Called when an internal SDO abort occurs. |
119 * Release the line * Only if server * |
119 * Release the line * Only if server * |
120 * If client, the line must be released manually in the core application. |
120 * If client, the line must be released manually in the core application. |
121 * The reason of that is to permit the program to read the transfers[][] structure before its reset, |
121 * The reason of that is to permit the program to read the transfers[][] structure before its reset, |
122 * because many informations are stored on it : index, subindex, data received or trasmited, ... |
122 * because many informations are stored on it : index, subindex, data received or trasmited, ... |
123 * In all cases, sends a SDO abort. |
123 * In all cases, sends a SDO abort. |
124 * Returns 0 |
124 * Returns 0 |
125 */ |
125 */ |
126 UNS8 failedSDO (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS16 index, |
126 UNS8 failedSDO (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS16 index, |
127 UNS8 subIndex, UNS32 abortCode); |
127 UNS8 subIndex, UNS32 abortCode); |
128 |
128 |
129 /** Reset an unused line. |
129 /** Reset an unused line. |
130 * |
130 * |
131 */ |
131 */ |
132 void resetSDOline (CO_Data* d, UNS8 line); |
132 void resetSDOline (CO_Data* d, UNS8 line); |
133 |
133 |
134 /** Initialize some fields of the structure. |
134 /** Initialize some fields of the structure. |
135 * Returns 0 |
135 * Returns 0 |
205 * Count : nb of bytes to write in the dictionnary. |
205 * Count : nb of bytes to write in the dictionnary. |
206 * datatype (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
206 * datatype (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
207 * bus_id is hardware dependant |
207 * bus_id is hardware dependant |
208 * return 0xFF if error, else return 0 |
208 * return 0xFF if error, else return 0 |
209 */ |
209 */ |
210 UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
210 UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
211 UNS8 subIndex, UNS8 count, UNS8 dataType, void *data); |
211 UNS8 subIndex, UNS8 count, UNS8 dataType, void *data); |
212 /** Used to send a SDO request frame to write in a distant node dictionnary. |
212 /** Used to send a SDO request frame to write in a distant node dictionnary. |
213 * The function Callback which must be defined in the user code is called at the |
213 * The function Callback which must be defined in the user code is called at the |
214 * end of the exchange. (on succes or abort). |
214 * end of the exchange. (on succes or abort). |
215 */ |
215 */ |
216 UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index, |
216 UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index, |
217 UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback); |
217 UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback); |
|
218 /** Used to send a SDO request frame to write in a distant node dictionnary. |
|
219 * The function Callback which must be defined in the user code is called at the |
|
220 * end of the exchange. (on succes or abort). First free SDO client parameter is |
|
221 * automatically initialized for specific node if not already defined. |
|
222 */ |
|
223 UNS8 writeNetworkDictCallBackAI (CO_Data* d, UNS8 nodeId, UNS16 index, |
|
224 UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize); |
218 /** Used by the application to send a SDO request frame to read |
225 /** Used by the application to send a SDO request frame to read |
219 * in the dictionary of a server node whose node_id is ID |
226 * in the dictionary of a server node whose node_id is ID |
220 * at the index and subIndex indicated |
227 * at the index and subIndex indicated |
221 * bus_id is hardware dependant |
228 * bus_id is hardware dependant |
222 * datatype (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
229 * datatype (defined in objdictdef.h) : put "visible_string" for strings, 0 for integers or reals or other value. |
223 * return 0xFF if error, else return 0 |
230 * return 0xFF if error, else return 0 |
224 */ |
231 */ |
225 UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
232 UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
226 UNS8 subIndex, UNS8 dataType); |
233 UNS8 subIndex, UNS8 dataType); |
227 |
234 |
228 /** Used to send a SDO request frame to read in a distant node dictionnary. |
235 /** Used to send a SDO request frame to read in a distant node dictionnary. |
229 * The function Callback which must be defined in the user code is called at the |
236 * The function Callback which must be defined in the user code is called at the |
230 * end of the exchange. (on succes or abort). |
237 * end of the exchange. (on succes or abort). |
231 */ |
238 */ |
232 UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback); |
239 UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback); |
|
240 |
|
241 /** Used to send a SDO request frame to read in a distant node dictionnary. |
|
242 * The function Callback which must be defined in the user code is called at the |
|
243 * end of the exchange. (on succes or abort). First free SDO client parameter is |
|
244 * automatically initialized for specific node if not already defined. |
|
245 */ |
|
246 UNS8 readNetworkDictCallbackAI (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback); |
233 |
247 |
234 /** Use this function after a readNetworkDict to get the result. |
248 /** Use this function after a readNetworkDict to get the result. |
235 Returns : SDO_FINISHED // data is available |
249 Returns : SDO_FINISHED // data is available |
236 SDO_ABORTED_RCV // Transfert failed. (abort SDO received) |
250 SDO_ABORTED_RCV // Transfert failed. (abort SDO received) |
237 SDO_ABORTED_INTERNAL // Transfert failed. Internal abort. |
251 SDO_ABORTED_INTERNAL // Transfert failed. Internal abort. |
238 SDO_UPLOAD_IN_PROGRESS // Data not yet available |
252 SDO_UPLOAD_IN_PROGRESS // Data not yet available |
239 SDO_DOWNLOAD_IN_PROGRESS // Should not arrive ! |
253 SDO_DOWNLOAD_IN_PROGRESS // Should not arrive ! |
240 |
254 |
241 dataType (defined in objdictdef.h) : type expected. put "visible_string" for strings, 0 for integers or reals. |
255 dataType (defined in objdictdef.h) : type expected. put "visible_string" for strings, 0 for integers or reals. |
242 abortCode : 0 = not available. Else : SDO abort code. (received if return SDO_ABORTED_RCV) |
256 abortCode : 0 = not available. Else : SDO abort code. (received if return SDO_ABORTED_RCV) |
243 example : |
257 example : |
244 UNS32 data; |
258 UNS32 data; |
245 UNS8 size; |
259 UNS8 size; |
246 readNetworkDict(0, 0x05, 0x1016, 1, 0) // get the data index 1016 subindex 1 of node 5 |
260 readNetworkDict(0, 0x05, 0x1016, 1, 0) // get the data index 1016 subindex 1 of node 5 |
247 while (getReadResultNetworkDict (0, 0x05, &data, &size) != SDO_UPLOAD_IN_PROGRESS); |
261 while (getReadResultNetworkDict (0, 0x05, &data, &size) != SDO_UPLOAD_IN_PROGRESS); |
248 */ |
262 */ |
249 UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, |
263 UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, |
250 UNS8 *size, UNS32 * abortCode); |
264 UNS8 *size, UNS32 * abortCode); |
251 |
265 |
252 /** |
266 /** |
253 Use this function after a writeNetworkDict to get the result of the write |
267 Use this function after a writeNetworkDict to get the result of the write |
254 It is mandatory to call this function because it is releasing the line used for the transfer. |
268 It is mandatory to call this function because it is releasing the line used for the transfer. |
255 Returns : SDO_FINISHED // data is available |
269 Returns : SDO_FINISHED // data is available |
256 SDO_ABORTED_RCV // Transfert failed. (abort SDO received) |
270 SDO_ABORTED_RCV // Transfert failed. (abort SDO received) |
257 SDO_ABORTED_INTERNAL // Transfert failed. Internal abort. |
271 SDO_ABORTED_INTERNAL // Transfert failed. Internal abort. |
258 SDO_DOWNLOAD_IN_PROGRESS // Data not yet available |
272 SDO_DOWNLOAD_IN_PROGRESS // Data not yet available |
259 SDO_UPLOAD_IN_PROGRESS // Should not arrive ! |
273 SDO_UPLOAD_IN_PROGRESS // Should not arrive ! |
260 abortCode : 0 = not available. Else : SDO abort code. (received if return SDO_ABORTED_RCV) |
274 abortCode : 0 = not available. Else : SDO abort code. (received if return SDO_ABORTED_RCV) |
261 example : |
275 example : |
262 UNS32 data = 0x50; |
276 UNS32 data = 0x50; |
263 UNS8 size; |
277 UNS8 size; |
264 UNS32 abortCode; |
278 UNS32 abortCode; |
265 writeNetworkDict(0, 0x05, 0x1016, 1, size, &data) // write the data index 1016 subindex 1 of node 5 |
279 writeNetworkDict(0, 0x05, 0x1016, 1, size, &data) // write the data index 1016 subindex 1 of node 5 |
266 while ( getWriteResultNetworkDict (0, 0x05, &abortCode) != SDO_DOWNLOAD_IN_PROGRESS); |
280 while ( getWriteResultNetworkDict (0, 0x05, &abortCode) != SDO_DOWNLOAD_IN_PROGRESS); |
267 */ |
281 */ |
268 UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode); |
282 UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode); |
269 |
283 |
270 |
284 |
271 |
285 |
272 |
286 |
273 #endif |
287 #endif |