1 /****************************************************************************
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
8 Description: source file for SDO/Asnd-Protocolabstractionlayer module
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
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.
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.
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.
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.
50 -------------------------------------------------------------------------
52 $RCSfile: EplSdoAsndu.c,v $
56 $Revision: 1.7 $ $Date: 2008/10/17 15:32:32 $
63 -------------------------------------------------------------------------
67 2006/07/07 k.t.: start of the implementation
69 ****************************************************************************/
71 #include "user/EplSdoAsndu.h"
72 #include "user/EplDlluCal.h"
74 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDO_ASND)) != 0)
76 /***************************************************************************/
79 /* G L O B A L D E F I N I T I O N S */
82 /***************************************************************************/
84 //---------------------------------------------------------------------------
86 //---------------------------------------------------------------------------
88 #ifndef EPL_SDO_MAX_CONNECTION_ASND
89 #define EPL_SDO_MAX_CONNECTION_ASND 5
92 //---------------------------------------------------------------------------
94 //---------------------------------------------------------------------------
99 unsigned int m_auiSdoAsndConnection[EPL_SDO_MAX_CONNECTION_ASND];
100 tEplSequLayerReceiveCb m_fpSdoAsySeqCb;
103 } tEplSdoAsndInstance;
105 //---------------------------------------------------------------------------
106 // modul globale vars
107 //---------------------------------------------------------------------------
109 static tEplSdoAsndInstance SdoAsndInstance_g;
111 //---------------------------------------------------------------------------
112 // local function prototypes
113 //---------------------------------------------------------------------------
115 tEplKernel PUBLIC EplSdoAsnduCb(tEplFrameInfo * pFrameInfo_p);
117 /***************************************************************************/
120 /* C L A S S <EPL SDO-Asnd Protocolabstraction layer> */
123 /***************************************************************************/
125 // Description: EPL SDO-Asnd Protocolabstraction layer
128 /***************************************************************************/
132 //=========================================================================//
134 // P U B L I C F U N C T I O N S //
136 //=========================================================================//
138 //---------------------------------------------------------------------------
140 // Function: EplSdoAsnduInit
142 // Description: init first instance of the module
146 // Parameters: pReceiveCb_p = functionpointer to Sdo-Sequence layer
150 // Returns: tEplKernel = Errorcode
155 //---------------------------------------------------------------------------
156 tEplKernel PUBLIC EplSdoAsnduInit(tEplSequLayerReceiveCb fpReceiveCb_p)
161 Ret = EplSdoAsnduAddInstance(fpReceiveCb_p);
167 //---------------------------------------------------------------------------
169 // Function: EplSdoAsnduAddInstance
171 // Description: init additional instance of the module
175 // Parameters: pReceiveCb_p = functionpointer to Sdo-Sequence layer
179 // Returns: tEplKernel = Errorcode
184 //---------------------------------------------------------------------------
185 tEplKernel PUBLIC EplSdoAsnduAddInstance(tEplSequLayerReceiveCb fpReceiveCb_p)
189 Ret = kEplSuccessful;
191 // init control structure
192 EPL_MEMSET(&SdoAsndInstance_g, 0x00, sizeof(SdoAsndInstance_g));
194 // save pointer to callback-function
195 if (fpReceiveCb_p != NULL)
197 SdoAsndInstance_g.m_fpSdoAsySeqCb = fpReceiveCb_p;
201 Ret = kEplSdoUdpMissCb;
204 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
205 Ret = EplDlluCalRegAsndService(kEplDllAsndSdo,
207 kEplDllAsndFilterLocal);
213 //---------------------------------------------------------------------------
215 // Function: EplSdoAsnduDelInstance
217 // Description: del instance of the module
218 // del socket and del Listen-Thread
225 // Returns: tEplKernel = Errorcode
230 //---------------------------------------------------------------------------
231 tEplKernel PUBLIC EplSdoAsnduDelInstance()
235 Ret = kEplSuccessful;
237 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
238 // deregister callback function from DLL
239 Ret = EplDlluCalRegAsndService(kEplDllAsndSdo,
241 kEplDllAsndFilterNone);
248 //---------------------------------------------------------------------------
250 // Function: EplSdoAsnduInitCon
252 // Description: init a new connect
256 // Parameters: pSdoConHandle_p = pointer for the new connection handle
257 // uiTargetNodeId_p = NodeId of the target node
260 // Returns: tEplKernel = Errorcode
265 //---------------------------------------------------------------------------
266 tEplKernel PUBLIC EplSdoAsnduInitCon(tEplSdoConHdl* pSdoConHandle_p,
267 unsigned int uiTargetNodeId_p)
270 unsigned int uiCount;
271 unsigned int uiFreeCon;
272 unsigned int* puiConnection;
274 Ret = kEplSuccessful;
276 if ((uiTargetNodeId_p == EPL_C_ADR_INVALID)
277 || (uiTargetNodeId_p >= EPL_C_ADR_BROADCAST))
279 Ret = kEplSdoAsndInvalidNodeId;
283 // get free entry in control structure
285 uiFreeCon = EPL_SDO_MAX_CONNECTION_ASND;
286 puiConnection = &SdoAsndInstance_g.m_auiSdoAsndConnection[0];
287 while(uiCount < EPL_SDO_MAX_CONNECTION_ASND)
289 if (*puiConnection == uiTargetNodeId_p)
290 { // existing connection to target node found
291 // save handle for higher layer
292 *pSdoConHandle_p = (uiCount | EPL_SDO_ASND_HANDLE );
296 else if (*puiConnection == 0)
297 { // free entry-> save target nodeId
304 if (uiFreeCon == EPL_SDO_MAX_CONNECTION_ASND)
306 // no free connection
307 Ret = kEplSdoAsndNoFreeHandle;
311 puiConnection = &SdoAsndInstance_g.m_auiSdoAsndConnection[uiFreeCon];
312 *puiConnection = uiTargetNodeId_p;
313 // save handle for higher layer
314 *pSdoConHandle_p = (uiFreeCon | EPL_SDO_ASND_HANDLE );
323 //---------------------------------------------------------------------------
325 // Function: EplSdoAsnduSendData
327 // Description: send data using exisiting connection
331 // Parameters: SdoConHandle_p = connection handle
332 // pSrcData_p = pointer to data
333 // dwDataSize_p = number of databyte
334 // -> without asnd-header!!!
336 // Returns: tEplKernel = Errorcode
341 //---------------------------------------------------------------------------
342 tEplKernel PUBLIC EplSdoAsnduSendData(tEplSdoConHdl SdoConHandle_p,
343 tEplFrame * pSrcData_p,
347 unsigned int uiArray;
348 tEplFrameInfo FrameInfo;
350 Ret = kEplSuccessful;
352 uiArray = (SdoConHandle_p & ~EPL_SDO_ASY_HANDLE_MASK);
354 if(uiArray > EPL_SDO_MAX_CONNECTION_ASND)
356 Ret = kEplSdoAsndInvalidHandle;
360 // fillout Asnd header
361 // own node id not needed -> filled by DLL
364 AmiSetByteToLe(&pSrcData_p->m_le_bMessageType, (BYTE)kEplMsgTypeAsnd); // ASnd == 0x06
366 AmiSetByteToLe(&pSrcData_p->m_le_bDstNodeId, (BYTE) SdoAsndInstance_g.m_auiSdoAsndConnection[uiArray]);
367 // set source-nodeid (filled by DLL 0)
368 AmiSetByteToLe(&pSrcData_p->m_le_bSrcNodeId, 0x00);
371 dwDataSize_p += EPL_ASND_HEADER_SIZE;
373 // send function of DLL
374 FrameInfo.m_uiFrameSize = dwDataSize_p;
375 FrameInfo.m_pFrame = pSrcData_p;
376 EPL_MEMSET(&FrameInfo.m_NetTime , 0x00, sizeof(tEplNetTime));
377 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
378 Ret = EplDlluCalAsyncSend(&FrameInfo,kEplDllAsyncReqPrioGeneric);
386 //---------------------------------------------------------------------------
388 // Function: EplSdoAsnduDelCon
390 // Description: delete connection from intern structure
394 // Parameters: SdoConHandle_p = connection handle
396 // Returns: tEplKernel = Errorcode
401 //---------------------------------------------------------------------------
402 tEplKernel PUBLIC EplSdoAsnduDelCon(tEplSdoConHdl SdoConHandle_p)
405 unsigned int uiArray;
407 Ret = kEplSuccessful;
410 uiArray = (SdoConHandle_p & ~EPL_SDO_ASY_HANDLE_MASK);
412 if(uiArray > EPL_SDO_MAX_CONNECTION_ASND)
414 Ret = kEplSdoAsndInvalidHandle;
418 // set target nodeId to 0
419 SdoAsndInstance_g.m_auiSdoAsndConnection[uiArray] = 0;
425 //=========================================================================//
427 // P R I V A T E F U N C T I O N S //
429 //=========================================================================//
431 //---------------------------------------------------------------------------
433 // Function: EplSdoAsnduCb
435 // Description: callback function for SDO ASnd frames
439 // Parameters: pFrameInfo_p = Frame with SDO payload
442 // Returns: tEplKernel = errorcode
447 //---------------------------------------------------------------------------
448 tEplKernel PUBLIC EplSdoAsnduCb(tEplFrameInfo * pFrameInfo_p)
450 tEplKernel Ret = kEplSuccessful;
451 unsigned int uiCount;
452 unsigned int* puiConnection;
453 unsigned int uiNodeId;
454 unsigned int uiFreeEntry = 0xFFFF;
455 tEplSdoConHdl SdoConHdl;
458 pFrame = pFrameInfo_p->m_pFrame;
460 uiNodeId = AmiGetByteFromLe(&pFrame->m_le_bSrcNodeId);
462 // search corresponding entry in control structure
464 puiConnection = &SdoAsndInstance_g.m_auiSdoAsndConnection[0];
465 while (uiCount < EPL_SDO_MAX_CONNECTION_ASND)
467 if (uiNodeId == *puiConnection)
471 else if ((*puiConnection == 0)
472 && (uiFreeEntry == 0xFFFF))
474 uiFreeEntry = uiCount;
480 if (uiCount == EPL_SDO_MAX_CONNECTION_ASND)
482 if (uiFreeEntry != 0xFFFF)
484 puiConnection = &SdoAsndInstance_g.m_auiSdoAsndConnection[uiFreeEntry];
485 *puiConnection = uiNodeId;
486 uiCount = uiFreeEntry;
490 EPL_DBGLVL_SDO_TRACE0("EplSdoAsnduCb(): no free handle\n");
494 // if (uiNodeId == *puiConnection)
495 { // entry found or created
496 SdoConHdl = (uiCount | EPL_SDO_ASND_HANDLE );
498 SdoAsndInstance_g.m_fpSdoAsySeqCb(SdoConHdl, &pFrame->m_Data.m_Asnd.m_Payload.m_SdoSequenceFrame, (pFrameInfo_p->m_uiFrameSize - 18));
507 #endif // end of #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDO_ASND)) != 0)