1 /****************************************************************************
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
8 Description: source file for DLL Communication Abstraction Layer module in EPL user part
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: EplDlluCal.c,v $
56 $Revision: 1.7 $ $Date: 2008/10/17 15:32:32 $
63 -------------------------------------------------------------------------
67 2006/06/20 d.k.: start of the implementation, version 1.00
69 ****************************************************************************/
71 #include "user/EplDlluCal.h"
72 #include "user/EplEventu.h"
74 #include "EplDllCal.h"
76 // include only if direct call between user- and kernelspace is enabled
77 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
78 #include "kernel/EplDllkCal.h"
81 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
83 /***************************************************************************/
86 /* G L O B A L D E F I N I T I O N S */
89 /***************************************************************************/
91 //---------------------------------------------------------------------------
93 //---------------------------------------------------------------------------
95 //---------------------------------------------------------------------------
97 //---------------------------------------------------------------------------
99 //---------------------------------------------------------------------------
100 // modul globale vars
101 //---------------------------------------------------------------------------
103 //---------------------------------------------------------------------------
104 // local function prototypes
105 //---------------------------------------------------------------------------
107 /***************************************************************************/
110 /* C L A S S EplDlluCal */
113 /***************************************************************************/
118 /***************************************************************************/
120 //=========================================================================//
122 // P R I V A T E D E F I N I T I O N S //
124 //=========================================================================//
126 //---------------------------------------------------------------------------
128 //---------------------------------------------------------------------------
130 //---------------------------------------------------------------------------
132 //---------------------------------------------------------------------------
135 tEplDlluCbAsnd m_apfnDlluCbAsnd[EPL_DLL_MAX_ASND_SERVICE_ID];
137 } tEplDlluCalInstance;
139 //---------------------------------------------------------------------------
141 //---------------------------------------------------------------------------
143 // if no dynamic memory allocation shall be used
144 // define structures statically
145 static tEplDlluCalInstance EplDlluCalInstance_g;
147 //---------------------------------------------------------------------------
148 // local function prototypes
149 //---------------------------------------------------------------------------
151 static tEplKernel EplDlluCalSetAsndServiceIdFilter(tEplDllAsndServiceId
153 tEplDllAsndFilter Filter_p);
155 //=========================================================================//
157 // P U B L I C F U N C T I O N S //
159 //=========================================================================//
161 //---------------------------------------------------------------------------
163 // Function: EplDlluCalAddInstance()
165 // Description: add and initialize new instance of DLL CAL module
169 // Returns: tEplKernel = error code
174 //---------------------------------------------------------------------------
176 tEplKernel EplDlluCalAddInstance(void)
178 tEplKernel Ret = kEplSuccessful;
180 // reset instance structure
181 EPL_MEMSET(&EplDlluCalInstance_g, 0, sizeof(EplDlluCalInstance_g));
186 //---------------------------------------------------------------------------
188 // Function: EplDlluCalDelInstance()
190 // Description: deletes an instance of DLL CAL module
194 // Returns: tEplKernel = error code
199 //---------------------------------------------------------------------------
201 tEplKernel EplDlluCalDelInstance(void)
203 tEplKernel Ret = kEplSuccessful;
205 // reset instance structure
206 EPL_MEMSET(&EplDlluCalInstance_g, 0, sizeof(EplDlluCalInstance_g));
211 //---------------------------------------------------------------------------
213 // Function: EplDlluCalProcess
215 // Description: process the passed asynch frame
217 // Parameters: pEvent_p = event containing frame to be processed
219 // Returns: tEplKernel = error code
224 //---------------------------------------------------------------------------
226 tEplKernel EplDlluCalProcess(tEplEvent * pEvent_p)
228 tEplKernel Ret = kEplSuccessful;
230 unsigned int uiAsndServiceId;
231 tEplFrameInfo FrameInfo;
233 if (pEvent_p->m_EventType == kEplEventTypeAsndRx) {
234 FrameInfo.m_pFrame = (tEplFrame *) pEvent_p->m_pArg;
235 FrameInfo.m_uiFrameSize = pEvent_p->m_uiSize;
237 FrameInfo.m_NetTime = pEvent_p->m_NetTime;
240 (tEplMsgType) AmiGetByteFromLe(&FrameInfo.m_pFrame->
242 if (MsgType != kEplMsgTypeAsnd) {
243 Ret = kEplInvalidOperation;
248 (unsigned int)AmiGetByteFromLe(&FrameInfo.m_pFrame->m_Data.
249 m_Asnd.m_le_bServiceId);
250 if (uiAsndServiceId < EPL_DLL_MAX_ASND_SERVICE_ID) { // ASnd service ID is valid
251 if (EplDlluCalInstance_g.m_apfnDlluCbAsnd[uiAsndServiceId] != NULL) { // handler was registered
253 EplDlluCalInstance_g.
254 m_apfnDlluCbAsnd[uiAsndServiceId]
264 //---------------------------------------------------------------------------
266 // Function: EplDlluCalRegAsndService()
268 // Description: registers the specified handler for the specified
269 // AsndServiceId with the specified node ID filter.
271 // Parameters: ServiceId_p = ASnd Service ID
272 // pfnDlluCbAsnd_p = callback function
273 // Filter_p = node ID filter
275 // Returns: tEplKernel = error code
280 //---------------------------------------------------------------------------
282 tEplKernel EplDlluCalRegAsndService(tEplDllAsndServiceId ServiceId_p,
283 tEplDlluCbAsnd pfnDlluCbAsnd_p,
284 tEplDllAsndFilter Filter_p)
286 tEplKernel Ret = kEplSuccessful;
288 if (ServiceId_p < tabentries(EplDlluCalInstance_g.m_apfnDlluCbAsnd)) {
289 // memorize function pointer
290 EplDlluCalInstance_g.m_apfnDlluCbAsnd[ServiceId_p] =
293 if (pfnDlluCbAsnd_p == NULL) { // close filter
294 Filter_p = kEplDllAsndFilterNone;
296 // set filter in DLL module in kernel part
297 Ret = EplDlluCalSetAsndServiceIdFilter(ServiceId_p, Filter_p);
304 //---------------------------------------------------------------------------
306 // Function: EplDlluCalAsyncSend()
308 // Description: sends the frame with the specified priority.
310 // Parameters: pFrameInfo_p = frame
311 // m_uiFrameSize does not include the
312 // ethernet header (14 bytes)
313 // Priority_p = priority
315 // Returns: tEplKernel = error code
320 //---------------------------------------------------------------------------
322 tEplKernel EplDlluCalAsyncSend(tEplFrameInfo * pFrameInfo_p,
323 tEplDllAsyncReqPriority Priority_p)
325 tEplKernel Ret = kEplSuccessful;
327 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
328 pFrameInfo_p->m_uiFrameSize += 14; // add size of ethernet header
329 Ret = EplDllkCalAsyncSend(pFrameInfo_p, Priority_p);
331 Ret = kEplSuccessful;
337 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
339 //---------------------------------------------------------------------------
341 // Function: EplDlluCalIssueRequest()
343 // Description: issues a StatusRequest or a IdentRequest to the specified node.
345 // Parameters: Service_p = request service ID
346 // uiNodeId_p = node ID
347 // bSoaFlag1_p = flag1 for this node (transmit in SoA and PReq)
348 // If 0xFF this flag is ignored.
350 // Returns: tEplKernel = error code
355 //---------------------------------------------------------------------------
357 tEplKernel EplDlluCalIssueRequest(tEplDllReqServiceId Service_p,
358 unsigned int uiNodeId_p, u8 bSoaFlag1_p)
360 tEplKernel Ret = kEplSuccessful;
362 // add node to appropriate request queue
364 case kEplDllReqServiceIdent:
365 case kEplDllReqServiceStatus:
368 tEplDllCalIssueRequest IssueReq;
370 Event.m_EventSink = kEplEventSinkDllkCal;
371 Event.m_EventType = kEplEventTypeDllkIssueReq;
372 IssueReq.m_Service = Service_p;
373 IssueReq.m_uiNodeId = uiNodeId_p;
374 IssueReq.m_bSoaFlag1 = bSoaFlag1_p;
375 Event.m_pArg = &IssueReq;
376 Event.m_uiSize = sizeof(IssueReq);
378 Ret = EplEventuPost(&Event);
384 Ret = kEplDllInvalidParam;
393 //---------------------------------------------------------------------------
395 // Function: EplDlluCalAddNode()
397 // Description: adds the specified node to the isochronous phase.
399 // Parameters: pNodeInfo_p = pointer of node info structure
401 // Returns: tEplKernel = error code
406 //---------------------------------------------------------------------------
408 tEplKernel EplDlluCalAddNode(tEplDllNodeInfo * pNodeInfo_p)
410 tEplKernel Ret = kEplSuccessful;
413 Event.m_EventSink = kEplEventSinkDllkCal;
414 Event.m_EventType = kEplEventTypeDllkAddNode;
415 Event.m_pArg = pNodeInfo_p;
416 Event.m_uiSize = sizeof(tEplDllNodeInfo);
418 Ret = EplEventuPost(&Event);
423 //---------------------------------------------------------------------------
425 // Function: EplDlluCalDeleteNode()
427 // Description: removes the specified node from the isochronous phase.
429 // Parameters: uiNodeId_p = node ID
431 // Returns: tEplKernel = error code
436 //---------------------------------------------------------------------------
438 tEplKernel EplDlluCalDeleteNode(unsigned int uiNodeId_p)
440 tEplKernel Ret = kEplSuccessful;
443 Event.m_EventSink = kEplEventSinkDllkCal;
444 Event.m_EventType = kEplEventTypeDllkDelNode;
445 Event.m_pArg = &uiNodeId_p;
446 Event.m_uiSize = sizeof(uiNodeId_p);
448 Ret = EplEventuPost(&Event);
453 //---------------------------------------------------------------------------
455 // Function: EplDlluCalSoftDeleteNode()
457 // Description: removes the specified node softly from the isochronous phase.
459 // Parameters: uiNodeId_p = node ID
461 // Returns: tEplKernel = error code
466 //---------------------------------------------------------------------------
468 tEplKernel EplDlluCalSoftDeleteNode(unsigned int uiNodeId_p)
470 tEplKernel Ret = kEplSuccessful;
473 Event.m_EventSink = kEplEventSinkDllkCal;
474 Event.m_EventType = kEplEventTypeDllkSoftDelNode;
475 Event.m_pArg = &uiNodeId_p;
476 Event.m_uiSize = sizeof(uiNodeId_p);
478 Ret = EplEventuPost(&Event);
483 #endif // (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
485 //=========================================================================//
487 // P R I V A T E F U N C T I O N S //
489 //=========================================================================//
491 //---------------------------------------------------------------------------
493 // Function: EplDlluCalSetAsndServiceIdFilter()
495 // Description: forwards call to EplDllkSetAsndServiceIdFilter() in kernel part
497 // Parameters: ServiceId_p = ASnd Service ID
498 // Filter_p = node ID filter
500 // Returns: tEplKernel = error code
505 //---------------------------------------------------------------------------
507 static tEplKernel EplDlluCalSetAsndServiceIdFilter(tEplDllAsndServiceId
509 tEplDllAsndFilter Filter_p)
511 tEplKernel Ret = kEplSuccessful;
513 tEplDllCalAsndServiceIdFilter ServFilter;
515 Event.m_EventSink = kEplEventSinkDllkCal;
516 Event.m_EventType = kEplEventTypeDllkServFilter;
517 ServFilter.m_ServiceId = ServiceId_p;
518 ServFilter.m_Filter = Filter_p;
519 Event.m_pArg = &ServFilter;
520 Event.m_uiSize = sizeof(ServFilter);
522 Ret = EplEventuPost(&Event);
527 #endif // (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)