author | etisserant |
Mon, 16 Mar 2009 23:04:39 +0100 | |
changeset 538 | 49f6d796b692 |
parent 478 | 4306e851d95c |
child 587 | c175351a6994 |
permissions | -rw-r--r-- |
178 | 1 |
/* |
207 | 2 |
This file is part of CanFestival, a library implementing CanOpen |
3 |
Stack. |
|
178 | 4 |
|
207 | 5 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
178 | 6 |
|
207 | 7 |
See COPYING file for copyrights details. |
178 | 8 |
|
207 | 9 |
This library is free software; you can redistribute it and/or |
10 |
modify it under the terms of the GNU Lesser General Public |
|
11 |
License as published by the Free Software Foundation; either |
|
12 |
version 2.1 of the License, or (at your option) any later version. |
|
178 | 13 |
|
207 | 14 |
This library is distributed in the hope that it will be useful, |
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
Lesser General Public License for more details. |
|
178 | 18 |
|
207 | 19 |
You should have received a copy of the GNU Lesser General Public |
20 |
License along with this library; if not, write to the Free Software |
|
21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
22 |
USA |
|
178 | 23 |
*/ |
24 |
||
210 | 25 |
|
208 | 26 |
/** |
207 | 27 |
** @file dcf.c |
28 |
** @author Edouard TISSERANT and Francis DUPIN |
|
29 |
** @date Mon Jun 4 17:06:12 2007 |
|
30 |
** |
|
208 | 31 |
** @brief EXEMPLE OF SOMMARY |
207 | 32 |
** |
33 |
** |
|
34 |
*/ |
|
215 | 35 |
|
36 |
||
378
d2abf6c8c27b
As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents:
368
diff
changeset
|
37 |
#include "data.h" |
200 | 38 |
#include "sysdep.h" |
178 | 39 |
|
207 | 40 |
extern UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
41 |
UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize); |
|
204
44ce74232ccb
Some fixes for visual studio C compiler compatiblity.
etisserant
parents:
202
diff
changeset
|
42 |
|
178 | 43 |
|
349 | 44 |
static void send_consise_dcf_loop(CO_Data* d,UNS8 nodeId); |
45 |
||
478 | 46 |
/* Seek to next NodeID's DCF */ |
47 |
#define SEEK_NEXT_DCF() \ |
|
48 |
nodeId=(nodeId+1) % d->dcf_odentry->bSubCount; \ |
|
49 |
if(nodeId==0) nodeId=1; \ |
|
50 |
d->dcf_cursor = NULL; |
|
51 |
||
208 | 52 |
/** |
207 | 53 |
** |
54 |
** |
|
55 |
** @param d |
|
56 |
** @param nodeId |
|
208 | 57 |
*/ |
178 | 58 |
static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId) |
59 |
{ |
|
478 | 60 |
UNS32 abortCode = 0; |
191 | 61 |
|
207 | 62 |
if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED) |
63 |
{ |
|
64 |
MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode); |
|
65 |
MSG_WAR(0x2A02, "server node : ", nodeId); |
|
66 |
} |
|
67 |
||
68 |
closeSDOtransfer(d, nodeId, SDO_CLIENT); |
|
478 | 69 |
/* Timedout ? */ |
70 |
if(abortCode == SDOABT_TIMED_OUT){ |
|
71 |
/* Node may not be ready, try another one */ |
|
72 |
/* Warning, this might leed to endless attempts */ |
|
73 |
/* if node does never answer */ |
|
74 |
SEEK_NEXT_DCF() |
|
75 |
} |
|
349 | 76 |
send_consise_dcf_loop(d,nodeId); |
178 | 77 |
} |
78 |
||
349 | 79 |
|
208 | 80 |
/** |
207 | 81 |
** |
82 |
** |
|
83 |
** @param d |
|
84 |
** @param nodeId |
|
85 |
** |
|
86 |
** @return |
|
208 | 87 |
*/ |
349 | 88 |
UNS8 send_consise_dcf(CO_Data* d,UNS8 nodeId) |
178 | 89 |
{ |
361 | 90 |
UNS8 szData; |
320
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
91 |
/* Fetch DCF OD entry, if not already done */ |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
92 |
if(!d->dcf_odentry) |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
93 |
{ |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
94 |
UNS32 errorCode; |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
95 |
ODCallback_t *Callback; |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
96 |
d->dcf_odentry = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback); |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
97 |
/* If DCF entry do not exist... Nothing to do.*/ |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
98 |
if (errorCode != OD_SUCCESSFUL) goto DCF_finish; |
f82e758840bd
Some fixes suggested by Luis Jim?nez, plus some minor enhancements in DCF.
etisserant
parents:
251
diff
changeset
|
99 |
} |
178 | 100 |
|
361 | 101 |
szData = d->dcf_odentry->pSubindex[nodeId].size; |
102 |
||
349 | 103 |
/* if the entry for the nodeId is not empty. */ |
104 |
if(szData!=0){ |
|
105 |
/* if the entry for the nodeId is already been processing, quit.*/ |
|
106 |
if(d->dcf_odentry->pSubindex[nodeId].bAccessType & DCF_TO_SEND) return 1; |
|
107 |
||
108 |
d->dcf_odentry->pSubindex[nodeId].bAccessType|=DCF_TO_SEND; |
|
109 |
d->dcf_request++; |
|
110 |
if(d->dcf_request==1) |
|
111 |
send_consise_dcf_loop(d,nodeId); |
|
112 |
return 1; |
|
113 |
} |
|
114 |
||
115 |
DCF_finish: |
|
116 |
return 0; |
|
117 |
} |
|
178 | 118 |
|
349 | 119 |
static void send_consise_dcf_loop(CO_Data* d,UNS8 nodeId) |
120 |
{ |
|
121 |
/* Loop on all DCF subindexes, corresponding to node ID until there is no request*/ |
|
122 |
//while (nodeId < d->dcf_odentry->bSubCount){ |
|
123 |
while (d->dcf_request>0){ |
|
124 |
if(d->dcf_odentry->pSubindex[nodeId].bAccessType & DCF_TO_SEND){ |
|
368
7b51757bfc81
changed order of declaration/initialization of variables to prevent some warnings
etisserant
parents:
361
diff
changeset
|
125 |
UNS8* dcfend; |
349 | 126 |
UNS32 nb_entries; |
368
7b51757bfc81
changed order of declaration/initialization of variables to prevent some warnings
etisserant
parents:
361
diff
changeset
|
127 |
UNS8 szData = d->dcf_odentry->pSubindex[nodeId].size; |
349 | 128 |
|
129 |
{ |
|
130 |
UNS8* dcf = *((UNS8**)d->dcf_odentry->pSubindex[nodeId].pObject); |
|
131 |
dcfend = dcf + szData; |
|
132 |
if (!d->dcf_cursor){ |
|
133 |
d->dcf_cursor = (UNS8*)dcf + 4; |
|
134 |
d->dcf_entries_count = 0; |
|
135 |
} |
|
136 |
nb_entries = UNS32_LE(*((UNS32*)dcf)); |
|
137 |
} |
|
207 | 138 |
|
349 | 139 |
/* condition on consise DCF string for NodeID, if big enough */ |
140 |
if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_entries_count < nb_entries){ |
|
141 |
||
142 |
UNS16 target_Index; |
|
143 |
UNS8 target_Subindex; |
|
144 |
UNS32 target_Size; |
|
207 | 145 |
|
474
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
146 |
/* DCF data may not be 32/16b aligned, |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
147 |
* we cannot directly dereference d->dcf_cursor |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
148 |
* as UNS16 or UNS32 |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
149 |
* Do it byte per byte taking care on endianess*/ |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
150 |
#ifdef CANOPEN_BIG_ENDIAN |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
151 |
target_Index = *(d->dcf_cursor++) << 8 | |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
152 |
*(d->dcf_cursor++); |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
153 |
#else |
476 | 154 |
memcpy(&target_Index, d->dcf_cursor,2); |
474
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
155 |
d->dcf_cursor+=2; |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
156 |
#endif |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
157 |
|
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
158 |
target_Subindex = *(d->dcf_cursor++); |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
159 |
|
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
160 |
#ifdef CANOPEN_BIG_ENDIAN |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
161 |
target_Size = *(d->dcf_cursor++) << 24 | |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
162 |
*(d->dcf_cursor++) << 16 | |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
163 |
*(d->dcf_cursor++) << 8 | |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
164 |
*(d->dcf_cursor++); |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
165 |
#else |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
166 |
memcpy(&target_Size, d->dcf_cursor,4); |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
167 |
d->dcf_cursor+=4; |
09c8c4b6c7df
Fixed alignments problems on some 32bit target such as ARM or Xscale.
etisserant
parents:
378
diff
changeset
|
168 |
#endif |
349 | 169 |
|
170 |
_writeNetworkDict(d, /* CO_Data* d*/ |
|
215 | 171 |
nodeId, /* UNS8 nodeId*/ |
172 |
target_Index, /* UNS16 index*/ |
|
173 |
target_Subindex, /* UNS8 subindex*/ |
|
174 |
target_Size, /* UNS8 count*/ |
|
175 |
0, /* UNS8 dataType*/ |
|
176 |
d->dcf_cursor,/* void *data*/ |
|
177 |
CheckSDOAndContinue,/* SDOCallback_t |
|
207 | 178 |
Callback*/ |
215 | 179 |
0); /* no endianize*/ |
349 | 180 |
/* Push d->dcf_cursor to the end of data*/ |
207 | 181 |
|
349 | 182 |
d->dcf_cursor += target_Size; |
183 |
d->dcf_entries_count++; |
|
207 | 184 |
|
349 | 185 |
/* send_consise_dcf_loop will be called by CheckSDOAndContinue for next DCF entry*/ |
186 |
return; |
|
187 |
} |
|
188 |
else |
|
189 |
{ |
|
190 |
/* We have finished with the dcf entry. Change the flag, decrement the request |
|
191 |
* and execute the bootup callback. */ |
|
192 |
d->dcf_odentry->pSubindex[nodeId].bAccessType&=~DCF_TO_SEND; |
|
193 |
d->dcf_request--; |
|
378
d2abf6c8c27b
As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents:
368
diff
changeset
|
194 |
(*d->post_SlaveBootup)(d, nodeId); |
349 | 195 |
} |
196 |
} |
|
353 | 197 |
|
478 | 198 |
SEEK_NEXT_DCF() |
207 | 199 |
} |
378
d2abf6c8c27b
As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents:
368
diff
changeset
|
200 |
|
178 | 201 |
} |