summaryrefslogtreecommitdiffstats
path: root/drivers/staging/epl/EplDllk.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/epl/EplDllk.c')
-rw-r--r--drivers/staging/epl/EplDllk.c4052
1 files changed, 0 insertions, 4052 deletions
diff --git a/drivers/staging/epl/EplDllk.c b/drivers/staging/epl/EplDllk.c
deleted file mode 100644
index 0572c3d0aefd..000000000000
--- a/drivers/staging/epl/EplDllk.c
+++ /dev/null
@@ -1,4052 +0,0 @@
-/****************************************************************************
-
- (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
- www.systec-electronic.com
-
- Project: openPOWERLINK
-
- Description: source file for kernel DLL module
-
- License:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of SYSTEC electronic GmbH nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without prior written permission. For written
- permission, please contact info@systec-electronic.com.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
- Severability Clause:
-
- If a provision of this License is or becomes illegal, invalid or
- unenforceable in any jurisdiction, that shall not affect:
- 1. the validity or enforceability in that jurisdiction of any other
- provision of this License; or
- 2. the validity or enforceability in other jurisdictions of that or
- any other provision of this License.
-
- -------------------------------------------------------------------------
-
- $RCSfile: EplDllk.c,v $
-
- $Author: D.Krueger $
-
- $Revision: 1.21 $ $Date: 2008/11/13 17:13:09 $
-
- $State: Exp $
-
- Build Environment:
- GCC V3.4
-
- -------------------------------------------------------------------------
-
- Revision History:
-
- 2006/06/12 d.k.: start of the implementation, version 1.00
-
-****************************************************************************/
-
-#include "kernel/EplDllk.h"
-#include "kernel/EplDllkCal.h"
-#include "kernel/EplEventk.h"
-#include "kernel/EplNmtk.h"
-#include "edrv.h"
-#include "Benchmark.h"
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
-#include "kernel/EplPdok.h"
-#endif
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_VETH)) != 0)
-#include "kernel/VirtualEthernet.h"
-#endif
-
-//#if EPL_TIMER_USE_HIGHRES != FALSE
-#include "kernel/EplTimerHighResk.h"
-//#endif
-
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
-
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) == 0)
-#error "EPL module DLLK needs EPL module NMTK!"
-#endif
-
-#if (EPL_DLL_PRES_READY_AFTER_SOA != FALSE) && (EPL_DLL_PRES_READY_AFTER_SOC != FALSE)
-#error "EPL module DLLK: select only one of EPL_DLL_PRES_READY_AFTER_SOA and EPL_DLL_PRES_READY_AFTER_SOC."
-#endif
-
-#if ((EPL_DLL_PRES_READY_AFTER_SOA != FALSE) || (EPL_DLL_PRES_READY_AFTER_SOC != FALSE)) \
- && (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) == 0)
-#error "EPL module DLLK: currently, EPL_DLL_PRES_READY_AFTER_* is not supported if EPL_MODULE_NMT_MN is enabled."
-#endif
-
-#if (EDRV_FAST_TXFRAMES == FALSE) && \
- ((EPL_DLL_PRES_READY_AFTER_SOA != FALSE) || (EPL_DLL_PRES_READY_AFTER_SOC != FALSE))
-#error "EPL module DLLK: EPL_DLL_PRES_READY_AFTER_* is enabled, but not EDRV_FAST_TXFRAMES."
-#endif
-
-/***************************************************************************/
-/* */
-/* */
-/* G L O B A L D E F I N I T I O N S */
-/* */
-/* */
-/***************************************************************************/
-
-//---------------------------------------------------------------------------
-// const defines
-//---------------------------------------------------------------------------
-
-// TracePoint support for realtime-debugging
-#ifdef _DBG_TRACE_POINTS_
-void TgtDbgSignalTracePoint(u8 bTracePointNumber_p);
-void TgtDbgPostTraceValue(u32 dwTraceValue_p);
-#define TGT_DBG_SIGNAL_TRACE_POINT(p) TgtDbgSignalTracePoint(p)
-#define TGT_DBG_POST_TRACE_VALUE(v) TgtDbgPostTraceValue(v)
-#else
-#define TGT_DBG_SIGNAL_TRACE_POINT(p)
-#define TGT_DBG_POST_TRACE_VALUE(v)
-#endif
-#define EPL_DLLK_DBG_POST_TRACE_VALUE(Event_p, uiNodeId_p, wErrorCode_p) \
- TGT_DBG_POST_TRACE_VALUE((kEplEventSinkDllk << 28) | (Event_p << 24) \
- | (uiNodeId_p << 16) | wErrorCode_p)
-
-/***************************************************************************/
-/* */
-/* */
-/* C L A S S EplDllk */
-/* */
-/* */
-/***************************************************************************/
-//
-// Description:
-//
-//
-/***************************************************************************/
-
-//=========================================================================//
-// //
-// P R I V A T E D E F I N I T I O N S //
-// //
-//=========================================================================//
-
-//---------------------------------------------------------------------------
-// const defines
-//---------------------------------------------------------------------------
-
-// defines for indexes of tEplDllInstance.m_pTxFrameInfo
-#define EPL_DLLK_TXFRAME_IDENTRES 0 // IdentResponse on CN / MN
-#define EPL_DLLK_TXFRAME_STATUSRES 1 // StatusResponse on CN / MN
-#define EPL_DLLK_TXFRAME_NMTREQ 2 // NMT Request from FIFO on CN / MN
-#define EPL_DLLK_TXFRAME_NONEPL 3 // non-EPL frame from FIFO on CN / MN
-#define EPL_DLLK_TXFRAME_PRES 4 // PRes on CN / MN
-#define EPL_DLLK_TXFRAME_SOC 5 // SoC on MN
-#define EPL_DLLK_TXFRAME_SOA 6 // SoA on MN
-#define EPL_DLLK_TXFRAME_PREQ 7 // PReq on MN
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
-#define EPL_DLLK_TXFRAME_COUNT (7 + EPL_D_NMT_MaxCNNumber_U8 + 2) // on MN: 7 + MaxPReq of regular CNs + 1 Diag + 1 Router
-#else
-#define EPL_DLLK_TXFRAME_COUNT 5 // on CN: 5
-#endif
-
-#define EPL_DLLK_BUFLEN_EMPTY 0 // buffer is empty
-#define EPL_DLLK_BUFLEN_FILLING 1 // just the buffer is being filled
-#define EPL_DLLK_BUFLEN_MIN 60 // minimum ethernet frame length
-
-//---------------------------------------------------------------------------
-// local types
-//---------------------------------------------------------------------------
-
-typedef enum {
- kEplDllGsInit = 0x00, // MN/CN: initialisation (< PreOp2)
- kEplDllCsWaitPreq = 0x01, // CN: wait for PReq frame
- kEplDllCsWaitSoc = 0x02, // CN: wait for SoC frame
- kEplDllCsWaitSoa = 0x03, // CN: wait for SoA frame
- kEplDllMsNonCyclic = 0x04, // MN: reduced EPL cycle (PreOp1)
- kEplDllMsWaitSocTrig = 0x05, // MN: wait for SoC trigger (cycle timer)
- kEplDllMsWaitPreqTrig = 0x06, // MN: wait for (first) PReq trigger (WaitSoCPReq_U32)
- kEplDllMsWaitPres = 0x07, // MN: wait for PRes frame from CN
- kEplDllMsWaitSoaTrig = 0x08, // MN: wait for SoA trigger (PRes transmitted)
- kEplDllMsWaitAsndTrig = 0x09, // MN: wait for ASnd trigger (SoA transmitted)
- kEplDllMsWaitAsnd = 0x0A, // MN: wait for ASnd frame if SoA contained invitation
-
-} tEplDllState;
-
-typedef struct {
- u8 m_be_abSrcMac[6];
- tEdrvTxBuffer *m_pTxBuffer; // Buffers for Tx-Frames
- unsigned int m_uiMaxTxFrames;
- u8 m_bFlag1; // Flag 1 with EN, EC for PRes, StatusRes
- u8 m_bMnFlag1; // Flag 1 with EA, ER from PReq, SoA of MN
- u8 m_bFlag2; // Flag 2 with PR and RS for PRes, StatusRes, IdentRes
- tEplDllConfigParam m_DllConfigParam;
- tEplDllIdentParam m_DllIdentParam;
- tEplDllState m_DllState;
- tEplDllkCbAsync m_pfnCbAsync;
- tEplDllAsndFilter m_aAsndFilter[EPL_DLL_MAX_ASND_SERVICE_ID];
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
- tEplDllkNodeInfo *m_pFirstNodeInfo;
- tEplDllkNodeInfo *m_pCurNodeInfo;
- tEplDllkNodeInfo m_aNodeInfo[EPL_NMT_MAX_NODE_ID];
- tEplDllReqServiceId m_LastReqServiceId;
- unsigned int m_uiLastTargetNodeId;
-#endif
-
-#if EPL_TIMER_USE_HIGHRES != FALSE
- tEplTimerHdl m_TimerHdlCycle; // used for EPL cycle monitoring on CN and generation on MN
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
- tEplTimerHdl m_TimerHdlResponse; // used for CN response monitoring
-#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
-#endif
-
- unsigned int m_uiCycleCount; // cycle counter (needed for multiplexed cycle support)
- unsigned long long m_ullFrameTimeout; // frame timeout (cycle length + loss of frame tolerance)
-
-} tEplDllkInstance;
-
-//---------------------------------------------------------------------------
-// local vars
-//---------------------------------------------------------------------------
-
-// if no dynamic memory allocation shall be used
-// define structures statically
-static tEplDllkInstance EplDllkInstance_g;
-
-static tEdrvTxBuffer aEplDllkTxBuffer_l[EPL_DLLK_TXFRAME_COUNT];
-
-//---------------------------------------------------------------------------
-// local function prototypes
-//---------------------------------------------------------------------------
-
-// change DLL state on event
-static tEplKernel EplDllkChangeState(tEplNmtEvent NmtEvent_p,
- tEplNmtState NmtState_p);
-
-// called from EdrvInterruptHandler()
-static void EplDllkCbFrameReceived(tEdrvRxBuffer * pRxBuffer_p);
-
-// called from EdrvInterruptHandler()
-static void EplDllkCbFrameTransmitted(tEdrvTxBuffer * pTxBuffer_p);
-
-// check frame and set missing information
-static tEplKernel EplDllkCheckFrame(tEplFrame * pFrame_p,
- unsigned int uiFrameSize_p);
-
-// called by high resolution timer module to monitor EPL cycle as CN
-#if EPL_TIMER_USE_HIGHRES != FALSE
-static tEplKernel EplDllkCbCnTimer(tEplTimerEventArg *pEventArg_p);
-#endif
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
-// MN: returns internal node info structure
-static tEplDllkNodeInfo *EplDllkGetNodeInfo(unsigned int uiNodeId_p);
-
-// transmit SoA
-static tEplKernel EplDllkMnSendSoa(tEplNmtState NmtState_p,
- tEplDllState * pDllStateProposed_p,
- BOOL fEnableInvitation_p);
-
-static tEplKernel EplDllkMnSendSoc(void);
-
-static tEplKernel EplDllkMnSendPreq(tEplNmtState NmtState_p,
- tEplDllState * pDllStateProposed_p);
-
-static tEplKernel EplDllkAsyncFrameNotReceived(tEplDllReqServiceId
- ReqServiceId_p,
- unsigned int uiNodeId_p);
-
-static tEplKernel EplDllkCbMnTimerCycle(tEplTimerEventArg *pEventArg_p);
-
-static tEplKernel EplDllkCbMnTimerResponse(tEplTimerEventArg *pEventArg_p);
-
-#endif
-
-//=========================================================================//
-// //
-// P U B L I C F U N C T I O N S //
-// //
-//=========================================================================//
-
-//---------------------------------------------------------------------------
-//
-// Function: EplDllkAddInstance()
-//
-// Description: add and initialize new instance of EPL stack
-//
-// Parameters: pInitParam_p = initialisation parameters like MAC address
-//
-// Returns: tEplKernel = error code
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplDllkAddInstance(tEplDllkInitParam * pInitParam_p)
-{
- tEplKernel Ret = kEplSuccessful;
- unsigned int uiIndex;
- tEdrvInitParam EdrvInitParam;
-
- // reset instance structure
- EPL_MEMSET(&EplDllkInstance_g, 0, sizeof(EplDllkInstance_g));
-
-#if EPL_TIMER_USE_HIGHRES != FALSE
- Ret = EplTimerHighReskInit();
- if (Ret != kEplSuccessful) { // error occured while initializing high resolution timer module
- goto Exit;
- }
-#endif
-
- // if dynamic memory allocation available
- // allocate instance structure
- // allocate TPDO and RPDO table with default size
-
- // initialize and link pointers in instance structure to frame tables
- EplDllkInstance_g.m_pTxBuffer = aEplDllkTxBuffer_l;
- EplDllkInstance_g.m_uiMaxTxFrames =
- ARRAY_SIZE(aEplDllkTxBuffer_l);
-
- // initialize state
- EplDllkInstance_g.m_DllState = kEplDllGsInit;
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
- // set up node info structure
- for (uiIndex = 0; uiIndex < tabentries(EplDllkInstance_g.m_aNodeInfo);
- uiIndex++) {
- EplDllkInstance_g.m_aNodeInfo[uiIndex].m_uiNodeId = uiIndex + 1;
- EplDllkInstance_g.m_aNodeInfo[uiIndex].m_wPresPayloadLimit =
- 0xFFFF;
- }
-#endif
-
- // initialize Edrv
- EPL_MEMCPY(EdrvInitParam.m_abMyMacAddr, pInitParam_p->m_be_abSrcMac, 6);
- EdrvInitParam.m_pfnRxHandler = EplDllkCbFrameReceived;
- EdrvInitParam.m_pfnTxHandler = EplDllkCbFrameTransmitted;
- Ret = EdrvInit(&EdrvInitParam);
- if (Ret != kEplSuccessful) { // error occured while initializing ethernet driver
- goto Exit;
- }
- // copy local MAC address from Ethernet driver back to local instance structure
- // because Ethernet driver may have read it from controller EEPROM
- EPL_MEMCPY(EplDllkInstance_g.m_be_abSrcMac, EdrvInitParam.m_abMyMacAddr,
- 6);
- EPL_MEMCPY(pInitParam_p->m_be_abSrcMac, EdrvInitParam.m_abMyMacAddr, 6);
-
- // initialize TxBuffer array
- for (uiIndex = 0; uiIndex < EplDllkInstance_g.m_uiMaxTxFrames;
- uiIndex++) {
- EplDllkInstance_g.m_pTxBuffer[uiIndex].m_pbBuffer = NULL;
- }
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_VETH)) != 0)
- Ret = VEthAddInstance(pInitParam_p);
-#endif
-
- Exit:
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplDllkDelInstance()
-//
-// Description: deletes an instance of EPL stack
-//
-// Parameters: (none)
-//
-// Returns: tEplKernel = error code
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplDllkDelInstance(void)
-{
- tEplKernel Ret = kEplSuccessful;
-
- // reset state
- EplDllkInstance_g.m_DllState = kEplDllGsInit;
-
-#if EPL_TIMER_USE_HIGHRES != FALSE
- Ret = EplTimerHighReskDelInstance();
-#endif
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_VETH)) != 0)
- Ret = VEthDelInstance();
-#endif
-
- Ret = EdrvShutdown();
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplDllkCreateTxFrame
-//
-// Description: creates the buffer for a Tx frame and registers it to the
-// ethernet driver
-//
-// Parameters: puiHandle_p = OUT: handle to frame buffer
-// ppFrame_p = OUT: pointer to pointer of EPL frame
-// puiFrameSize_p = IN/OUT: pointer to size of frame
-// returned size is always equal or larger than
-// requested size, if that is not possible
-// an error will be returned
-// MsgType_p = EPL message type
-// ServiceId_p = Service ID in case of ASnd frame, otherwise
-// kEplDllAsndNotDefined
-//
-// Returns: tEplKernel = error code
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplDllkCreateTxFrame(unsigned int *puiHandle_p,
- tEplFrame ** ppFrame_p,
- unsigned int *puiFrameSize_p,
- tEplMsgType MsgType_p,
- tEplDllAsndServiceId ServiceId_p)
-{
- tEplKernel Ret = kEplSuccessful;
- tEplFrame *pTxFrame;
- unsigned int uiHandle = EplDllkInstance_g.m_uiMaxTxFrames;
- tEdrvTxBuffer *pTxBuffer = NULL;
-
- if (MsgType_p == kEplMsgTypeAsnd) {
- // search for fixed Tx buffers
- if (ServiceId_p == kEplDllAsndIdentResponse) {
- uiHandle = EPL_DLLK_TXFRAME_IDENTRES;
- } else if (ServiceId_p == kEplDllAsndStatusResponse) {
- uiHandle = EPL_DLLK_TXFRAME_STATUSRES;
- } else if ((ServiceId_p == kEplDllAsndNmtRequest)
- || (ServiceId_p == kEplDllAsndNmtCommand)) {
- uiHandle = EPL_DLLK_TXFRAME_NMTREQ;
- }
-
- if (uiHandle >= EplDllkInstance_g.m_uiMaxTxFrames) { // look for free entry
- uiHandle = EPL_DLLK_TXFRAME_PREQ;
- pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[uiHandle];
- for (; uiHandle < EplDllkInstance_g.m_uiMaxTxFrames;
- uiHandle++, pTxBuffer++) {
- if (pTxBuffer->m_pbBuffer == NULL) { // free entry found
- break;
- }
- }
- }
- } else if (MsgType_p == kEplMsgTypeNonEpl) {
- uiHandle = EPL_DLLK_TXFRAME_NONEPL;
- } else if (MsgType_p == kEplMsgTypePres) {
- uiHandle = EPL_DLLK_TXFRAME_PRES;
- } else if (MsgType_p == kEplMsgTypeSoc) {
- uiHandle = EPL_DLLK_TXFRAME_SOC;
- } else if (MsgType_p == kEplMsgTypeSoa) {
- uiHandle = EPL_DLLK_TXFRAME_SOA;
- } else { // look for free entry
- uiHandle = EPL_DLLK_TXFRAME_PREQ;
- pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[uiHandle];
- for (; uiHandle < EplDllkInstance_g.m_uiMaxTxFrames;
- uiHandle++, pTxBuffer++) {
- if (pTxBuffer->m_pbBuffer == NULL) { // free entry found
- break;
- }
- }
- if (pTxBuffer->m_pbBuffer != NULL) {
- Ret = kEplEdrvNoFreeBufEntry;
- goto Exit;
- }
- }
-
- // test if requested entry is free
- pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[uiHandle];
- if (pTxBuffer->m_pbBuffer != NULL) { // entry is not free
- Ret = kEplEdrvNoFreeBufEntry;
- goto Exit;
- }
- // setup Tx buffer
- pTxBuffer->m_EplMsgType = MsgType_p;
- pTxBuffer->m_uiMaxBufferLen = *puiFrameSize_p;
-
- Ret = EdrvAllocTxMsgBuffer(pTxBuffer);
- if (Ret != kEplSuccessful) { // error occured while registering Tx frame
- goto Exit;
- }
- // because buffer size may be larger than requested
- // memorize real length of frame
- pTxBuffer->m_uiTxMsgLen = *puiFrameSize_p;
-
- // fill whole frame with 0
- EPL_MEMSET(pTxBuffer->m_pbBuffer, 0, pTxBuffer->m_uiMaxBufferLen);
-
- pTxFrame = (tEplFrame *) pTxBuffer->m_pbBuffer;
-
- if (MsgType_p != kEplMsgTypeNonEpl) { // fill out Frame only if it is an EPL frame
- // ethertype
- AmiSetWordToBe(&pTxFrame->m_be_wEtherType,
- EPL_C_DLL_ETHERTYPE_EPL);
- // source node ID
- AmiSetByteToLe(&pTxFrame->m_le_bSrcNodeId,
- (u8) EplDllkInstance_g.m_DllConfigParam.
- m_uiNodeId);
- // source MAC address
- EPL_MEMCPY(&pTxFrame->m_be_abSrcMac[0],
- &EplDllkInstance_g.m_be_abSrcMac[0], 6);
- switch (MsgType_p) {
- case kEplMsgTypeAsnd:
- // destination MAC address
- AmiSetQword48ToBe(&pTxFrame->m_be_abDstMac[0],
- EPL_C_DLL_MULTICAST_ASND);
- // destination node ID
- switch (ServiceId_p) {
- case kEplDllAsndIdentResponse:
- case kEplDllAsndStatusResponse:
- { // IdentResponses and StatusResponses are Broadcast
- AmiSetByteToLe(&pTxFrame->
- m_le_bDstNodeId,
- (u8)
- EPL_C_ADR_BROADCAST);
- break;
- }
-
- default:
- break;
- }
- // ASnd Service ID
- AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.m_le_bServiceId,
- ServiceId_p);
- break;
-
- case kEplMsgTypeSoc:
- // destination MAC address
- AmiSetQword48ToBe(&pTxFrame->m_be_abDstMac[0],
- EPL_C_DLL_MULTICAST_SOC);
- // destination node ID
- AmiSetByteToLe(&pTxFrame->m_le_bDstNodeId,
- (u8) EPL_C_ADR_BROADCAST);
- // reset Flags
- //AmiSetByteToLe(&pTxFrame->m_Data.m_Soc.m_le_bFlag1, (u8) 0);
- //AmiSetByteToLe(&pTxFrame->m_Data.m_Soc.m_le_bFlag2, (u8) 0);
- break;
-
- case kEplMsgTypeSoa:
- // destination MAC address
- AmiSetQword48ToBe(&pTxFrame->m_be_abDstMac[0],
- EPL_C_DLL_MULTICAST_SOA);
- // destination node ID
- AmiSetByteToLe(&pTxFrame->m_le_bDstNodeId,
- (u8) EPL_C_ADR_BROADCAST);
- // reset Flags
- //AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.m_le_bFlag1, (u8) 0);
- //AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.m_le_bFlag2, (u8) 0);
- // EPL profile version
- AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.m_le_bEplVersion,
- (u8) EPL_SPEC_VERSION);
- break;
-
- case kEplMsgTypePres:
- // destination MAC address
- AmiSetQword48ToBe(&pTxFrame->m_be_abDstMac[0],
- EPL_C_DLL_MULTICAST_PRES);
- // destination node ID
- AmiSetByteToLe(&pTxFrame->m_le_bDstNodeId,
- (u8) EPL_C_ADR_BROADCAST);
- // reset Flags
- //AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.m_le_bFlag1, (u8) 0);
- //AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.m_le_bFlag2, (u8) 0);
- // PDO size
- //AmiSetWordToLe(&pTxFrame->m_Data.m_Pres.m_le_wSize, 0);
- break;
-
- case kEplMsgTypePreq:
- // reset Flags
- //AmiSetByteToLe(&pTxFrame->m_Data.m_Preq.m_le_bFlag1, (u8) 0);
- //AmiSetByteToLe(&pTxFrame->m_Data.m_Preq.m_le_bFlag2, (u8) 0);
- // PDO size
- //AmiSetWordToLe(&pTxFrame->m_Data.m_Preq.m_le_wSize, 0);
- break;
-
- default:
- break;
- }
- // EPL message type
- AmiSetByteToLe(&pTxFrame->m_le_bMessageType, (u8) MsgType_p);
- }
-
- *ppFrame_p = pTxFrame;
- *puiFrameSize_p = pTxBuffer->m_uiMaxBufferLen;
- *puiHandle_p = uiHandle;
-
- Exit:
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplDllkDeleteTxFrame
-//
-// Description: deletes the buffer for a Tx frame and frees it in the
-// ethernet driver
-//
-// Parameters: uiHandle_p = IN: handle to frame buffer
-//
-// Returns: tEplKernel = error code
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplDllkDeleteTxFrame(unsigned int uiHandle_p)
-{
- tEplKernel Ret = kEplSuccessful;
- tEdrvTxBuffer *pTxBuffer = NULL;
-
- if (uiHandle_p >= EplDllkInstance_g.m_uiMaxTxFrames) { // handle is not valid
- Ret = kEplDllIllegalHdl;
- goto Exit;
- }
-
- pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[uiHandle_p];
-
- // mark buffer as free so that frame will not be send in future anymore
- // $$$ d.k. What's up with running transmissions?
- pTxBuffer->m_uiTxMsgLen = EPL_DLLK_BUFLEN_EMPTY;
- pTxBuffer->m_pbBuffer = NULL;
-
- // delete Tx buffer
- Ret = EdrvReleaseTxMsgBuffer(pTxBuffer);
- if (Ret != kEplSuccessful) { // error occured while releasing Tx frame
- goto Exit;
- }
-
- Exit:
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplDllkProcess
-//
-// Description: process the passed event
-//
-// Parameters: pEvent_p = event to be processed
-//
-// Returns: tEplKernel = error code
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplDllkProcess(tEplEvent * pEvent_p)
-{
- tEplKernel Ret = kEplSuccessful;
- tEplFrame *pTxFrame;
- tEdrvTxBuffer *pTxBuffer;
- unsigned int uiHandle;
- unsigned int uiFrameSize;
- u8 abMulticastMac[6];
- tEplDllAsyncReqPriority AsyncReqPriority;
- unsigned int uiFrameCount;
- tEplNmtState NmtState;
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
- tEplFrameInfo FrameInfo;
-#endif
-
- switch (pEvent_p->m_EventType) {
- case kEplEventTypeDllkCreate:
- {
- // $$$ reset ethernet driver
-
- NmtState = *((tEplNmtState *) pEvent_p->m_pArg);
-
- // initialize flags for PRes and StatusRes
- EplDllkInstance_g.m_bFlag1 = EPL_FRAME_FLAG1_EC;
- EplDllkInstance_g.m_bMnFlag1 = 0;
- EplDllkInstance_g.m_bFlag2 = 0;
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
- // initialize linked node list
- EplDllkInstance_g.m_pFirstNodeInfo = NULL;
-#endif
-
- // register TxFrames in Edrv
-
- // IdentResponse
- uiFrameSize = EPL_C_DLL_MINSIZE_IDENTRES;
- Ret =
- EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
- &uiFrameSize, kEplMsgTypeAsnd,
- kEplDllAsndIdentResponse);
- if (Ret != kEplSuccessful) { // error occured while registering Tx frame
- goto Exit;
- }
- // EPL profile version
- AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_bEplProfileVersion,
- (u8) EPL_SPEC_VERSION);
- // FeatureFlags
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwFeatureFlags,
- EplDllkInstance_g.m_DllConfigParam.
- m_dwFeatureFlags);
- // MTU
- AmiSetWordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_wMtu,
- (u16) EplDllkInstance_g.
- m_DllConfigParam.m_uiAsyncMtu);
- // PollInSize
- AmiSetWordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_wPollInSize,
- (u16) EplDllkInstance_g.
- m_DllConfigParam.
- m_uiPreqActPayloadLimit);
- // PollOutSize
- AmiSetWordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_wPollOutSize,
- (u16) EplDllkInstance_g.
- m_DllConfigParam.
- m_uiPresActPayloadLimit);
- // ResponseTime / PresMaxLatency
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwResponseTime,
- EplDllkInstance_g.m_DllConfigParam.
- m_dwPresMaxLatency);
- // DeviceType
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwDeviceType,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwDeviceType);
- // VendorId
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwVendorId,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwVendorId);
- // ProductCode
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwProductCode,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwProductCode);
- // RevisionNumber
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwRevisionNumber,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwRevisionNumber);
- // SerialNumber
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwSerialNumber,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwSerialNumber);
- // VendorSpecificExt1
- AmiSetQword64ToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.
- m_le_qwVendorSpecificExt1,
- EplDllkInstance_g.m_DllIdentParam.
- m_qwVendorSpecificExt1);
- // VerifyConfigurationDate
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.
- m_le_dwVerifyConfigurationDate,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwVerifyConfigurationDate);
- // VerifyConfigurationTime
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.
- m_le_dwVerifyConfigurationTime,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwVerifyConfigurationTime);
- // ApplicationSwDate
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.
- m_le_dwApplicationSwDate,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwApplicationSwDate);
- // ApplicationSwTime
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.
- m_le_dwApplicationSwTime,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwApplicationSwTime);
- // IPAddress
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwIpAddress,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwIpAddress);
- // SubnetMask
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwSubnetMask,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwSubnetMask);
- // DefaultGateway
- AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_dwDefaultGateway,
- EplDllkInstance_g.m_DllIdentParam.
- m_dwDefaultGateway);
- // HostName
- EPL_MEMCPY(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_sHostname[0],
- &EplDllkInstance_g.m_DllIdentParam.
- m_sHostname[0],
- sizeof(EplDllkInstance_g.m_DllIdentParam.
- m_sHostname));
- // VendorSpecificExt2
- EPL_MEMCPY(&pTxFrame->m_Data.m_Asnd.m_Payload.
- m_IdentResponse.m_le_abVendorSpecificExt2[0],
- &EplDllkInstance_g.m_DllIdentParam.
- m_abVendorSpecificExt2[0],
- sizeof(EplDllkInstance_g.m_DllIdentParam.
- m_abVendorSpecificExt2));
-
- // StatusResponse
- uiFrameSize = EPL_C_DLL_MINSIZE_STATUSRES;
- Ret =
- EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
- &uiFrameSize, kEplMsgTypeAsnd,
- kEplDllAsndStatusResponse);
- if (Ret != kEplSuccessful) { // error occured while registering Tx frame
- goto Exit;
- }
- // PRes $$$ maybe move this to PDO module
- if ((EplDllkInstance_g.m_DllConfigParam.m_fAsyncOnly ==
- FALSE)
- && (EplDllkInstance_g.m_DllConfigParam.m_uiPresActPayloadLimit >= 36)) { // it is not configured as async-only CN,
- // so take part in isochronous phase and register PRes frame
- uiFrameSize =
- EplDllkInstance_g.m_DllConfigParam.
- m_uiPresActPayloadLimit + 24;
- Ret =
- EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
- &uiFrameSize,
- kEplMsgTypePres,
- kEplDllAsndNotDefined);
- if (Ret != kEplSuccessful) { // error occured while registering Tx frame
- goto Exit;
- }
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
- // initially encode TPDO -> inform PDO module
- FrameInfo.m_pFrame = pTxFrame;
- FrameInfo.m_uiFrameSize = uiFrameSize;
- Ret = EplPdokCbPdoTransmitted(&FrameInfo);
-#endif
- // reset cycle counter
- EplDllkInstance_g.m_uiCycleCount = 0;
- } else { // it is an async-only CN
- // fool EplDllkChangeState() to think that PRes was not expected
- EplDllkInstance_g.m_uiCycleCount = 1;
- }
-
- // NMT request
- uiFrameSize = EPL_C_IP_MAX_MTU;
- Ret =
- EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
- &uiFrameSize, kEplMsgTypeAsnd,
- kEplDllAsndNmtRequest);
- if (Ret != kEplSuccessful) { // error occured while registering Tx frame
- goto Exit;
- }
- // mark Tx buffer as empty
- EplDllkInstance_g.m_pTxBuffer[uiHandle].m_uiTxMsgLen =
- EPL_DLLK_BUFLEN_EMPTY;
-
- // non-EPL frame
- uiFrameSize = EPL_C_IP_MAX_MTU;
- Ret =
- EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
- &uiFrameSize,
- kEplMsgTypeNonEpl,
- kEplDllAsndNotDefined);
- if (Ret != kEplSuccessful) { // error occured while registering Tx frame
- goto Exit;
- }
- // mark Tx buffer as empty
- EplDllkInstance_g.m_pTxBuffer[uiHandle].m_uiTxMsgLen =
- EPL_DLLK_BUFLEN_EMPTY;
-
- // register multicast MACs in ethernet driver
- AmiSetQword48ToBe(&abMulticastMac[0],
- EPL_C_DLL_MULTICAST_SOC);
- Ret = EdrvDefineRxMacAddrEntry(abMulticastMac);
- AmiSetQword48ToBe(&abMulticastMac[0],
- EPL_C_DLL_MULTICAST_SOA);
- Ret = EdrvDefineRxMacAddrEntry(abMulticastMac);
- AmiSetQword48ToBe(&abMulticastMac[0],
- EPL_C_DLL_MULTICAST_PRES);
- Ret = EdrvDefineRxMacAddrEntry(abMulticastMac);
- AmiSetQword48ToBe(&abMulticastMac[0],
- EPL_C_DLL_MULTICAST_ASND);
- Ret = EdrvDefineRxMacAddrEntry(abMulticastMac);
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
- if (NmtState >= kEplNmtMsNotActive) { // local node is MN
- unsigned int uiIndex;
-
- // SoC
- uiFrameSize = EPL_C_DLL_MINSIZE_SOC;
- Ret =
- EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
- &uiFrameSize,
- kEplMsgTypeSoc,
- kEplDllAsndNotDefined);
- if (Ret != kEplSuccessful) { // error occured while registering Tx frame
- goto Exit;
- }
- // SoA
- uiFrameSize = EPL_C_DLL_MINSIZE_SOA;
- Ret =
- EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
- &uiFrameSize,
- kEplMsgTypeSoa,
- kEplDllAsndNotDefined);
- if (Ret != kEplSuccessful) { // error occured while registering Tx frame
- goto Exit;
- }
-
- for (uiIndex = 0;
- uiIndex <
- tabentries(EplDllkInstance_g.m_aNodeInfo);
- uiIndex++) {
-// EplDllkInstance_g.m_aNodeInfo[uiIndex].m_uiNodeId = uiIndex + 1;
- EplDllkInstance_g.m_aNodeInfo[uiIndex].
- m_wPresPayloadLimit =
- (u16) EplDllkInstance_g.
- m_DllConfigParam.
- m_uiIsochrRxMaxPayload;
- }
-
- // calculate cycle length
- EplDllkInstance_g.m_ullFrameTimeout = 1000LL
- *
- ((unsigned long long)EplDllkInstance_g.
- m_DllConfigParam.m_dwCycleLen);
- }
-#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
-
- Ret = EplDllkCalAsyncClearBuffer();
-
- break;
- }
-
- case kEplEventTypeDllkDestroy:
- {
- // destroy all data structures
-
- NmtState = *((tEplNmtState *) pEvent_p->m_pArg);
-
- // delete Tx frames
- Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_IDENTRES);
- if (Ret != kEplSuccessful) { // error occured while deregistering Tx frame
- goto Exit;
- }
-
- Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_STATUSRES);
- if (Ret != kEplSuccessful) { // error occured while deregistering Tx frame
- goto Exit;
- }
-
- Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_PRES);
- if (Ret != kEplSuccessful) { // error occured while deregistering Tx frame
- goto Exit;
- }
-
- Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_NMTREQ);
- if (Ret != kEplSuccessful) { // error occured while deregistering Tx frame
- goto Exit;
- }
-
- Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_NONEPL);
- if (Ret != kEplSuccessful) { // error occured while deregistering Tx frame
- goto Exit;
- }
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
- if (NmtState >= kEplNmtMsNotActive) { // local node was MN
- unsigned int uiIndex;
-
- Ret =
- EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_SOC);
- if (Ret != kEplSuccessful) { // error occured while deregistering Tx frame
- goto Exit;
- }
-
- Ret =
- EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_SOA);
- if (Ret != kEplSuccessful) { // error occured while deregistering Tx frame
- goto Exit;
- }
-
- for (uiIndex = 0;
- uiIndex <
- tabentries(EplDllkInstance_g.m_aNodeInfo);
- uiIndex++) {
- if (EplDllkInstance_g.
- m_aNodeInfo[uiIndex].
- m_pPreqTxBuffer != NULL) {
- uiHandle =
- EplDllkInstance_g.
- m_aNodeInfo[uiIndex].
- m_pPreqTxBuffer -
- EplDllkInstance_g.
- m_pTxBuffer;
- EplDllkInstance_g.
- m_aNodeInfo[uiIndex].
- m_pPreqTxBuffer = NULL;
- Ret =
- EplDllkDeleteTxFrame
- (uiHandle);
- if (Ret != kEplSuccessful) { // error occured while deregistering Tx frame
- goto Exit;
- }
-
- }
- EplDllkInstance_g.m_aNodeInfo[uiIndex].
- m_wPresPayloadLimit = 0xFFFF;
- }
- }
-#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
-