blob: aa8bdef317cf36cd15a8dc9cdec8790e819c29eb [file] [log] [blame]
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001/****************************************************************************
2
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
5
6 Project: openPOWERLINK
7
8 Description: source file for SDO/Asnd-Protocolabstractionlayer module
9
10 License:
11
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
14 are met:
15
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of SYSTEC electronic GmbH nor the names of its
24 contributors may be used to endorse or promote products derived
25 from this software without prior written permission. For written
26 permission, please contact info@systec-electronic.com.
27
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 POSSIBILITY OF SUCH DAMAGE.
40
41 Severability Clause:
42
43 If a provision of this License is or becomes illegal, invalid or
44 unenforceable in any jurisdiction, that shall not affect:
45 1. the validity or enforceability in that jurisdiction of any other
46 provision of this License; or
47 2. the validity or enforceability in other jurisdictions of that or
48 any other provision of this License.
49
50 -------------------------------------------------------------------------
51
52 $RCSfile: EplSdoAsndu.c,v $
53
54 $Author: D.Krueger $
55
56 $Revision: 1.7 $ $Date: 2008/10/17 15:32:32 $
57
58 $State: Exp $
59
60 Build Environment:
61 GCC V3.4
62
63 -------------------------------------------------------------------------
64
65 Revision History:
66
67 2006/07/07 k.t.: start of the implementation
68
69****************************************************************************/
70
71#include "user/EplSdoAsndu.h"
72#include "user/EplDlluCal.h"
73
74#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDO_ASND)) != 0)
75
76/***************************************************************************/
77/* */
78/* */
79/* G L O B A L D E F I N I T I O N S */
80/* */
81/* */
82/***************************************************************************/
83
84//---------------------------------------------------------------------------
85// const defines
86//---------------------------------------------------------------------------
87
88#ifndef EPL_SDO_MAX_CONNECTION_ASND
89#define EPL_SDO_MAX_CONNECTION_ASND 5
90#endif
91
92//---------------------------------------------------------------------------
93// local types
94//---------------------------------------------------------------------------
95
96// instance table
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -080097typedef struct {
98 unsigned int m_auiSdoAsndConnection[EPL_SDO_MAX_CONNECTION_ASND];
99 tEplSequLayerReceiveCb m_fpSdoAsySeqCb;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800100
101} tEplSdoAsndInstance;
102
103//---------------------------------------------------------------------------
104// modul globale vars
105//---------------------------------------------------------------------------
106
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800107static tEplSdoAsndInstance SdoAsndInstance_g;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800108
109//---------------------------------------------------------------------------
110// local function prototypes
111//---------------------------------------------------------------------------
112
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700113tEplKernel EplSdoAsnduCb(tEplFrameInfo *pFrameInfo_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800114
115/***************************************************************************/
116/* */
117/* */
118/* C L A S S <EPL SDO-Asnd Protocolabstraction layer> */
119/* */
120/* */
121/***************************************************************************/
122//
123// Description: EPL SDO-Asnd Protocolabstraction layer
124//
125//
126/***************************************************************************/
127
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800128//=========================================================================//
129// //
130// P U B L I C F U N C T I O N S //
131// //
132//=========================================================================//
133
134//---------------------------------------------------------------------------
135//
136// Function: EplSdoAsnduInit
137//
138// Description: init first instance of the module
139//
140//
141//
142// Parameters: pReceiveCb_p = functionpointer to Sdo-Sequence layer
143// callback-function
144//
145//
146// Returns: tEplKernel = Errorcode
147//
148//
149// State:
150//
151//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700152tEplKernel EplSdoAsnduInit(tEplSequLayerReceiveCb fpReceiveCb_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800153{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800154 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800155
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800156 Ret = EplSdoAsnduAddInstance(fpReceiveCb_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800157
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800158 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800159}
160
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800161//---------------------------------------------------------------------------
162//
163// Function: EplSdoAsnduAddInstance
164//
165// Description: init additional instance of the module
166//
167//
168//
169// Parameters: pReceiveCb_p = functionpointer to Sdo-Sequence layer
170// callback-function
171//
172//
173// Returns: tEplKernel = Errorcode
174//
175//
176// State:
177//
178//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700179tEplKernel EplSdoAsnduAddInstance(tEplSequLayerReceiveCb fpReceiveCb_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800180{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800181 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800182
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800183 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800184
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800185 // init control structure
186 EPL_MEMSET(&SdoAsndInstance_g, 0x00, sizeof(SdoAsndInstance_g));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800187
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800188 // save pointer to callback-function
189 if (fpReceiveCb_p != NULL) {
190 SdoAsndInstance_g.m_fpSdoAsySeqCb = fpReceiveCb_p;
191 } else {
192 Ret = kEplSdoUdpMissCb;
193 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800194
195#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800196 Ret = EplDlluCalRegAsndService(kEplDllAsndSdo,
197 EplSdoAsnduCb, kEplDllAsndFilterLocal);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800198#endif
199
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800200 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800201}
202
203//---------------------------------------------------------------------------
204//
205// Function: EplSdoAsnduDelInstance
206//
207// Description: del instance of the module
208// del socket and del Listen-Thread
209//
210//
211//
212// Parameters:
213//
214//
215// Returns: tEplKernel = Errorcode
216//
217//
218// State:
219//
220//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700221tEplKernel EplSdoAsnduDelInstance(void)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800222{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800223 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800224
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800225 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800226
227#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800228 // deregister callback function from DLL
229 Ret = EplDlluCalRegAsndService(kEplDllAsndSdo,
230 NULL, kEplDllAsndFilterNone);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800231#endif
232
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800233 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800234}
235
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800236//---------------------------------------------------------------------------
237//
238// Function: EplSdoAsnduInitCon
239//
240// Description: init a new connect
241//
242//
243//
244// Parameters: pSdoConHandle_p = pointer for the new connection handle
245// uiTargetNodeId_p = NodeId of the target node
246//
247//
248// Returns: tEplKernel = Errorcode
249//
250//
251// State:
252//
253//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700254tEplKernel EplSdoAsnduInitCon(tEplSdoConHdl *pSdoConHandle_p,
255 unsigned int uiTargetNodeId_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800256{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800257 tEplKernel Ret;
258 unsigned int uiCount;
259 unsigned int uiFreeCon;
260 unsigned int *puiConnection;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800261
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800262 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800263
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800264 if ((uiTargetNodeId_p == EPL_C_ADR_INVALID)
265 || (uiTargetNodeId_p >= EPL_C_ADR_BROADCAST)) {
266 Ret = kEplSdoAsndInvalidNodeId;
267 goto Exit;
268 }
269 // get free entry in control structure
270 uiCount = 0;
271 uiFreeCon = EPL_SDO_MAX_CONNECTION_ASND;
272 puiConnection = &SdoAsndInstance_g.m_auiSdoAsndConnection[0];
273 while (uiCount < EPL_SDO_MAX_CONNECTION_ASND) {
274 if (*puiConnection == uiTargetNodeId_p) { // existing connection to target node found
275 // save handle for higher layer
276 *pSdoConHandle_p = (uiCount | EPL_SDO_ASND_HANDLE);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800277
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800278 goto Exit;
279 } else if (*puiConnection == 0) { // free entry-> save target nodeId
280 uiFreeCon = uiCount;
281 }
282 uiCount++;
283 puiConnection++;
284 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800285
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800286 if (uiFreeCon == EPL_SDO_MAX_CONNECTION_ASND) {
287 // no free connection
288 Ret = kEplSdoAsndNoFreeHandle;
289 } else {
290 puiConnection =
291 &SdoAsndInstance_g.m_auiSdoAsndConnection[uiFreeCon];
292 *puiConnection = uiTargetNodeId_p;
293 // save handle for higher layer
294 *pSdoConHandle_p = (uiFreeCon | EPL_SDO_ASND_HANDLE);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800295
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800296 goto Exit;
297 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800298
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800299 Exit:
300 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800301}
302
303//---------------------------------------------------------------------------
304//
305// Function: EplSdoAsnduSendData
306//
307// Description: send data using exisiting connection
308//
309//
310//
311// Parameters: SdoConHandle_p = connection handle
312// pSrcData_p = pointer to data
313// dwDataSize_p = number of databyte
314// -> without asnd-header!!!
315//
316// Returns: tEplKernel = Errorcode
317//
318//
319// State:
320//
321//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700322tEplKernel EplSdoAsnduSendData(tEplSdoConHdl SdoConHandle_p,
323 tEplFrame *pSrcData_p,
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -0700324 u32 dwDataSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800325{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800326 tEplKernel Ret;
327 unsigned int uiArray;
328 tEplFrameInfo FrameInfo;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800329
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800330 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800331
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800332 uiArray = (SdoConHandle_p & ~EPL_SDO_ASY_HANDLE_MASK);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800333
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800334 if (uiArray > EPL_SDO_MAX_CONNECTION_ASND) {
335 Ret = kEplSdoAsndInvalidHandle;
336 goto Exit;
337 }
338 // fillout Asnd header
339 // own node id not needed -> filled by DLL
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800340
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800341 // set message type
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700342 AmiSetByteToLe(&pSrcData_p->m_le_bMessageType, (u8) kEplMsgTypeAsnd); // ASnd == 0x06
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800343 // target node id
344 AmiSetByteToLe(&pSrcData_p->m_le_bDstNodeId,
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700345 (u8) SdoAsndInstance_g.
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800346 m_auiSdoAsndConnection[uiArray]);
347 // set source-nodeid (filled by DLL 0)
348 AmiSetByteToLe(&pSrcData_p->m_le_bSrcNodeId, 0x00);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800349
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800350 // calc size
351 dwDataSize_p += EPL_ASND_HEADER_SIZE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800352
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800353 // send function of DLL
354 FrameInfo.m_uiFrameSize = dwDataSize_p;
355 FrameInfo.m_pFrame = pSrcData_p;
356 EPL_MEMSET(&FrameInfo.m_NetTime, 0x00, sizeof(tEplNetTime));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800357#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800358 Ret = EplDlluCalAsyncSend(&FrameInfo, kEplDllAsyncReqPrioGeneric);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800359#endif
360
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800361 Exit:
362 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800363
364}
365
366//---------------------------------------------------------------------------
367//
368// Function: EplSdoAsnduDelCon
369//
370// Description: delete connection from intern structure
371//
372//
373//
374// Parameters: SdoConHandle_p = connection handle
375//
376// Returns: tEplKernel = Errorcode
377//
378//
379// State:
380//
381//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700382tEplKernel EplSdoAsnduDelCon(tEplSdoConHdl SdoConHandle_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800383{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800384 tEplKernel Ret;
385 unsigned int uiArray;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800386
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800387 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800388
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800389 uiArray = (SdoConHandle_p & ~EPL_SDO_ASY_HANDLE_MASK);
390 // check parameter
391 if (uiArray > EPL_SDO_MAX_CONNECTION_ASND) {
392 Ret = kEplSdoAsndInvalidHandle;
393 goto Exit;
394 }
395 // set target nodeId to 0
396 SdoAsndInstance_g.m_auiSdoAsndConnection[uiArray] = 0;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800397
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800398 Exit:
399 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800400}
401
402//=========================================================================//
403// //
404// P R I V A T E F U N C T I O N S //
405// //
406//=========================================================================//
407
408//---------------------------------------------------------------------------
409//
410// Function: EplSdoAsnduCb
411//
412// Description: callback function for SDO ASnd frames
413//
414//
415//
416// Parameters: pFrameInfo_p = Frame with SDO payload
417//
418//
419// Returns: tEplKernel = errorcode
420//
421//
422// State:
423//
424//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700425tEplKernel EplSdoAsnduCb(tEplFrameInfo *pFrameInfo_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800426{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800427 tEplKernel Ret = kEplSuccessful;
428 unsigned int uiCount;
429 unsigned int *puiConnection;
430 unsigned int uiNodeId;
431 unsigned int uiFreeEntry = 0xFFFF;
432 tEplSdoConHdl SdoConHdl;
433 tEplFrame *pFrame;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800434
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800435 pFrame = pFrameInfo_p->m_pFrame;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800436
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800437 uiNodeId = AmiGetByteFromLe(&pFrame->m_le_bSrcNodeId);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800438
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800439 // search corresponding entry in control structure
440 uiCount = 0;
441 puiConnection = &SdoAsndInstance_g.m_auiSdoAsndConnection[0];
442 while (uiCount < EPL_SDO_MAX_CONNECTION_ASND) {
443 if (uiNodeId == *puiConnection) {
444 break;
445 } else if ((*puiConnection == 0)
446 && (uiFreeEntry == 0xFFFF)) { // free entry
447 uiFreeEntry = uiCount;
448 }
449 uiCount++;
450 puiConnection++;
451 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800452
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800453 if (uiCount == EPL_SDO_MAX_CONNECTION_ASND) {
454 if (uiFreeEntry != 0xFFFF) {
455 puiConnection =
456 &SdoAsndInstance_g.
457 m_auiSdoAsndConnection[uiFreeEntry];
458 *puiConnection = uiNodeId;
459 uiCount = uiFreeEntry;
460 } else {
461 EPL_DBGLVL_SDO_TRACE0
462 ("EplSdoAsnduCb(): no free handle\n");
463 goto Exit;
464 }
465 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800466// if (uiNodeId == *puiConnection)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800467 { // entry found or created
468 SdoConHdl = (uiCount | EPL_SDO_ASND_HANDLE);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800469
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800470 SdoAsndInstance_g.m_fpSdoAsySeqCb(SdoConHdl,
471 &pFrame->m_Data.m_Asnd.
472 m_Payload.m_SdoSequenceFrame,
473 (pFrameInfo_p->m_uiFrameSize -
474 18));
475 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800476
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800477 Exit:
478 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800479
480}
481
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800482#endif // end of #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDO_ASND)) != 0)
483// EOF