summaryrefslogtreecommitdiffstats
path: root/drivers/staging/epl/EplSdoComu.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/epl/EplSdoComu.c')
-rw-r--r--drivers/staging/epl/EplSdoComu.c3345
1 files changed, 0 insertions, 3345 deletions
diff --git a/drivers/staging/epl/EplSdoComu.c b/drivers/staging/epl/EplSdoComu.c
deleted file mode 100644
index bf35afab152d..000000000000
--- a/drivers/staging/epl/EplSdoComu.c
+++ /dev/null
@@ -1,3345 +0,0 @@
-/****************************************************************************
-
- (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
- www.systec-electronic.com
-
- Project: openPOWERLINK
-
- Description: source file for SDO Command Layer 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: EplSdoComu.c,v $
-
- $Author: D.Krueger $
-
- $Revision: 1.14 $ $Date: 2008/10/17 15:32:32 $
-
- $State: Exp $
-
- Build Environment:
- GCC V3.4
-
- -------------------------------------------------------------------------
-
- Revision History:
-
- 2006/06/26 k.t.: start of the implementation
-
-****************************************************************************/
-
-#include "user/EplSdoComu.h"
-
-#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) == 0) &&\
- (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) == 0) )
-
-#error 'ERROR: At least SDO Server or SDO Client should be activate!'
-
-#endif
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) == 0) && (EPL_OBD_USE_KERNEL == FALSE)
-
-#error 'ERROR: SDO Server needs OBDu module!'
-
-#endif
-
-#endif
-
-/***************************************************************************/
-/* */
-/* */
-/* G L O B A L D E F I N I T I O N S */
-/* */
-/* */
-/***************************************************************************/
-
-//---------------------------------------------------------------------------
-// const defines
-//---------------------------------------------------------------------------
-
-#ifndef EPL_MAX_SDO_COM_CON
-#define EPL_MAX_SDO_COM_CON 5
-#endif
-
-//---------------------------------------------------------------------------
-// local types
-//---------------------------------------------------------------------------
-
-// intern events
-typedef enum {
- kEplSdoComConEventSendFirst = 0x00, // first frame to send
- kEplSdoComConEventRec = 0x01, // frame received
- kEplSdoComConEventConEstablished = 0x02, // connection established
- kEplSdoComConEventConClosed = 0x03, // connection closed
- kEplSdoComConEventAckReceived = 0x04, // acknowledge received by lower layer
- // -> continue sending
- kEplSdoComConEventFrameSended = 0x05, // lower has send a frame
- kEplSdoComConEventInitError = 0x06, // error duringinitialisiation
- // of the connection
- kEplSdoComConEventTimeout = 0x07 // timeout in lower layer
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
- ,
-
- kEplSdoComConEventInitCon = 0x08, // init connection (only client)
- kEplSdoComConEventAbort = 0x09 // abort sdo transfer (only client)
-#endif
-} tEplSdoComConEvent;
-
-typedef enum {
- kEplSdoComSendTypeReq = 0x00, // send a request
- kEplSdoComSendTypeAckRes = 0x01, // send a resonse without data
- kEplSdoComSendTypeRes = 0x02, // send response with data
- kEplSdoComSendTypeAbort = 0x03 // send abort
-} tEplSdoComSendType;
-
-// state of the state maschine
-typedef enum {
- // General State
- kEplSdoComStateIdle = 0x00, // idle state
-
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
- // Server States
- kEplSdoComStateServerSegmTrans = 0x01, // send following frames
-#endif
-
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
- // Client States
- kEplSdoComStateClientWaitInit = 0x10, // wait for init connection
- // on lower layer
- kEplSdoComStateClientConnected = 0x11, // connection established
- kEplSdoComStateClientSegmTrans = 0x12 // send following frames
-#endif
-} tEplSdoComState;
-
-// control structure for transaction
-typedef struct {
- tEplSdoSeqConHdl m_SdoSeqConHdl; // if != 0 -> entry used
- tEplSdoComState m_SdoComState;
- u8 m_bTransactionId;
- unsigned int m_uiNodeId; // NodeId of the target
- // -> needed to reinit connection
- // after timeout
- tEplSdoTransType m_SdoTransType; // Auto, Expedited, Segmented
- tEplSdoServiceType m_SdoServiceType; // WriteByIndex, ReadByIndex
- tEplSdoType m_SdoProtType; // protocol layer: Auto, Udp, Asnd, Pdo
- u8 *m_pData; // pointer to data
- unsigned int m_uiTransSize; // number of bytes
- // to transfer
- unsigned int m_uiTransferredByte; // number of bytes
- // already transferred
- tEplSdoFinishedCb m_pfnTransferFinished; // callback function of the
- // application
- // -> called in the end of
- // the SDO transfer
- void *m_pUserArg; // user definable argument pointer
-
- u32 m_dwLastAbortCode; // save the last abort code
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
- // only for client
- unsigned int m_uiTargetIndex; // index to access
- unsigned int m_uiTargetSubIndex; // subiondex to access
-
- // for future use
- unsigned int m_uiTimeout; // timeout for this connection
-
-#endif
-
-} tEplSdoComCon;
-
-// instance table
-typedef struct {
- tEplSdoComCon m_SdoComCon[EPL_MAX_SDO_COM_CON];
-
-#if defined(WIN32) || defined(_WIN32)
- LPCRITICAL_SECTION m_pCriticalSection;
- CRITICAL_SECTION m_CriticalSection;
-#endif
-
-} tEplSdoComInstance;
-
-//---------------------------------------------------------------------------
-// modul globale vars
-//---------------------------------------------------------------------------
-static tEplSdoComInstance SdoComInstance_g;
-//---------------------------------------------------------------------------
-// local function prototypes
-//---------------------------------------------------------------------------
-tEplKernel EplSdoComReceiveCb(tEplSdoSeqConHdl SdoSeqConHdl_p,
- tEplAsySdoCom *pAsySdoCom_p,
- unsigned int uiDataSize_p);
-
-tEplKernel EplSdoComConCb(tEplSdoSeqConHdl SdoSeqConHdl_p,
- tEplAsySdoConState AsySdoConState_p);
-
-static tEplKernel EplSdoComSearchConIntern(tEplSdoSeqConHdl SdoSeqConHdl_p,
- tEplSdoComConEvent SdoComConEvent_p,
- tEplAsySdoCom * pAsySdoCom_p);
-
-static tEplKernel EplSdoComProcessIntern(tEplSdoComConHdl SdoComCon_p,
- tEplSdoComConEvent SdoComConEvent_p,
- tEplAsySdoCom * pAsySdoCom_p);
-
-static tEplKernel EplSdoComTransferFinished(tEplSdoComConHdl SdoComCon_p,
- tEplSdoComCon * pSdoComCon_p,
- tEplSdoComConState
- SdoComConState_p);
-
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
-static tEplKernel EplSdoComServerInitReadByIndex(tEplSdoComCon * pSdoComCon_p,
- tEplAsySdoCom * pAsySdoCom_p);
-
-static tEplKernel EplSdoComServerSendFrameIntern(tEplSdoComCon * pSdoComCon_p,
- unsigned int uiIndex_p,
- unsigned int uiSubIndex_p,
- tEplSdoComSendType SendType_p);
-
-static tEplKernel EplSdoComServerInitWriteByIndex(tEplSdoComCon * pSdoComCon_p,
- tEplAsySdoCom * pAsySdoCom_p);
-#endif
-
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
-
-static tEplKernel EplSdoComClientSend(tEplSdoComCon * pSdoComCon_p);
-
-static tEplKernel EplSdoComClientProcessFrame(tEplSdoComConHdl SdoComCon_p,
- tEplAsySdoCom * pAsySdoCom_p);
-
-static tEplKernel EplSdoComClientSendAbort(tEplSdoComCon * pSdoComCon_p,
- u32 dwAbortCode_p);
-#endif
-
-/***************************************************************************/
-/* */
-/* */
-/* C L A S S <SDO Command Layer> */
-/* */
-/* */
-/***************************************************************************/
-//
-// Description: SDO Command layer Modul
-//
-//
-/***************************************************************************/
-
-//=========================================================================//
-// //
-// P U B L I C F U N C T I O N S //
-// //
-//=========================================================================//
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComInit
-//
-// Description: Init first instance of the module
-//
-//
-//
-// Parameters:
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-tEplKernel EplSdoComInit(void)
-{
- tEplKernel Ret;
-
- Ret = EplSdoComAddInstance();
-
- return Ret;
-
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComAddInstance
-//
-// Description: Init additional instance of the module
-//
-//
-//
-// Parameters:
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-tEplKernel EplSdoComAddInstance(void)
-{
- tEplKernel Ret;
-
- Ret = kEplSuccessful;
-
- // init controll structure
- EPL_MEMSET(&SdoComInstance_g, 0x00, sizeof(SdoComInstance_g));
-
- // init instance of lower layer
- Ret = EplSdoAsySeqAddInstance(EplSdoComReceiveCb, EplSdoComConCb);
- if (Ret != kEplSuccessful) {
- goto Exit;
- }
-#if defined(WIN32) || defined(_WIN32)
- // create critical section for process function
- SdoComInstance_g.m_pCriticalSection =
- &SdoComInstance_g.m_CriticalSection;
- InitializeCriticalSection(SdoComInstance_g.m_pCriticalSection);
-#endif
-
- Exit:
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComDelInstance
-//
-// Description: delete instance of the module
-//
-//
-//
-// Parameters:
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-tEplKernel EplSdoComDelInstance(void)
-{
- tEplKernel Ret;
-
- Ret = kEplSuccessful;
-
-#if defined(WIN32) || defined(_WIN32)
- // delete critical section for process function
- DeleteCriticalSection(SdoComInstance_g.m_pCriticalSection);
-#endif
-
- Ret = EplSdoAsySeqDelInstance();
- if (Ret != kEplSuccessful) {
- goto Exit;
- }
-
- Exit:
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComDefineCon
-//
-// Description: function defines a SDO connection to another node
-// -> init lower layer and returns a handle for the connection.
-// Two client connections to the same node via the same protocol
-// are not allowed. If this function detects such a situation
-// it will return kEplSdoComHandleExists and the handle of
-// the existing connection in pSdoComConHdl_p.
-// Using of existing server connections is possible.
-//
-// Parameters: pSdoComConHdl_p = pointer to the buffer of the handle
-// uiTargetNodeId_p = NodeId of the targetnode
-// ProtType_p = type of protocol to use for connection
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
-tEplKernel EplSdoComDefineCon(tEplSdoComConHdl *pSdoComConHdl_p,
- unsigned int uiTargetNodeId_p,
- tEplSdoType ProtType_p)
-{
- tEplKernel Ret;
- unsigned int uiCount;
- unsigned int uiFreeHdl;
- tEplSdoComCon *pSdoComCon;
-
- // check Parameter
- ASSERT(pSdoComConHdl_p != NULL);
-
- // check NodeId
- if ((uiTargetNodeId_p == EPL_C_ADR_INVALID)
- || (uiTargetNodeId_p >= EPL_C_ADR_BROADCAST)) {
- Ret = kEplInvalidNodeId;
-
- }
- // search free control structure
- pSdoComCon = &SdoComInstance_g.m_SdoComCon[0];
- uiCount = 0;
- uiFreeHdl = EPL_MAX_SDO_COM_CON;
- while (uiCount < EPL_MAX_SDO_COM_CON) {
- if (pSdoComCon->m_SdoSeqConHdl == 0) { // free entry
- uiFreeHdl = uiCount;
- } else if ((pSdoComCon->m_uiNodeId == uiTargetNodeId_p)
- && (pSdoComCon->m_SdoProtType == ProtType_p)) { // existing client connection with same node ID and same protocol type
- *pSdoComConHdl_p = uiCount;
- Ret = kEplSdoComHandleExists;
- goto Exit;
- }
- uiCount++;
- pSdoComCon++;
- }
-
- if (uiFreeHdl == EPL_MAX_SDO_COM_CON) {
- Ret = kEplSdoComNoFreeHandle;
- goto Exit;
- }
-
- pSdoComCon = &SdoComInstance_g.m_SdoComCon[uiFreeHdl];
- // save handle for application
- *pSdoComConHdl_p = uiFreeHdl;
- // save parameters
- pSdoComCon->m_SdoProtType = ProtType_p;
- pSdoComCon->m_uiNodeId = uiTargetNodeId_p;
-
- // set Transaction Id
- pSdoComCon->m_bTransactionId = 0;
-
- // check protocol
- switch (ProtType_p) {
- // udp
- case kEplSdoTypeUdp:
- {
- // call connection int function of lower layer
- Ret = EplSdoAsySeqInitCon(&pSdoComCon->m_SdoSeqConHdl,
- pSdoComCon->m_uiNodeId,
- kEplSdoTypeUdp);
- if (Ret != kEplSuccessful) {
- goto Exit;
- }
- break;
- }
-
- // Asend
- case kEplSdoTypeAsnd:
- {
- // call connection int function of lower layer
- Ret = EplSdoAsySeqInitCon(&pSdoComCon->m_SdoSeqConHdl,
- pSdoComCon->m_uiNodeId,
- kEplSdoTypeAsnd);
- if (Ret != kEplSuccessful) {
- goto Exit;
- }
- break;
- }
-
- // Pdo -> not supported
- case kEplSdoTypePdo:
- default:
- {
- Ret = kEplSdoComUnsupportedProt;
- goto Exit;
- }
- } // end of switch(m_ProtType_p)
-
- // call process function
- Ret = EplSdoComProcessIntern(uiFreeHdl,
- kEplSdoComConEventInitCon, NULL);
-
- Exit:
- return Ret;
-}
-#endif
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComInitTransferByIndex
-//
-// Description: function init SDO Transfer for a defined connection
-//
-//
-//
-// Parameters: SdoComTransParam_p = Structure with parameters for connection
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
-tEplKernel EplSdoComInitTransferByIndex(tEplSdoComTransParamByIndex *pSdoComTransParam_p)
-{
- tEplKernel Ret;
- tEplSdoComCon *pSdoComCon;
-
- // check parameter
- if ((pSdoComTransParam_p->m_uiSubindex >= 0xFF)
- || (pSdoComTransParam_p->m_uiIndex == 0)
- || (pSdoComTransParam_p->m_uiIndex > 0xFFFF)
- || (pSdoComTransParam_p->m_pData == NULL)
- || (pSdoComTransParam_p->m_uiDataSize == 0)) {
- Ret = kEplSdoComInvalidParam;
- goto Exit;
- }
-
- if (pSdoComTransParam_p->m_SdoComConHdl >= EPL_MAX_SDO_COM_CON) {
- Ret = kEplSdoComInvalidHandle;
- goto Exit;
- }
- // get pointer to control structure of connection
- pSdoComCon =
- &SdoComInstance_g.m_SdoComCon[pSdoComTransParam_p->m_SdoComConHdl];
-
- // check if handle ok
- if (pSdoComCon->m_SdoSeqConHdl == 0) {
- Ret = kEplSdoComInvalidHandle;
- goto Exit;
- }
- // check if command layer is idle
- if ((pSdoComCon->m_uiTransferredByte + pSdoComCon->m_uiTransSize) > 0) { // handle is not idle
- Ret = kEplSdoComHandleBusy;
- goto Exit;
- }
- // save parameter
- // callback function for end of transfer
- pSdoComCon->m_pfnTransferFinished =
- pSdoComTransParam_p->m_pfnSdoFinishedCb;
- pSdoComCon->m_pUserArg = pSdoComTransParam_p->m_pUserArg;
-
- // set type of SDO command
- if (pSdoComTransParam_p->m_SdoAccessType == kEplSdoAccessTypeRead) {
- pSdoComCon->m_SdoServiceType = kEplSdoServiceReadByIndex;
- } else {
- pSdoComCon->m_SdoServiceType = kEplSdoServiceWriteByIndex;
-
- }
- // save pointer to data
- pSdoComCon->m_pData = pSdoComTransParam_p->m_pData;
- // maximal bytes to transfer
- pSdoComCon->m_uiTransSize = pSdoComTransParam_p->m_uiDataSize;
- // bytes already transfered
- pSdoComCon->m_uiTransferredByte = 0;
-
- // reset parts of control structure
- pSdoComCon->m_dwLastAbortCode = 0;
- pSdoComCon->m_SdoTransType = kEplSdoTransAuto;
- // save timeout
- //pSdoComCon->m_uiTimeout = SdoComTransParam_p.m_uiTimeout;
-
- // save index and subindex
- pSdoComCon->m_uiTargetIndex = pSdoComTransParam_p->m_uiIndex;
- pSdoComCon->m_uiTargetSubIndex = pSdoComTransParam_p->m_uiSubindex;
-
- // call process function
- Ret = EplSdoComProcessIntern(pSdoComTransParam_p->m_SdoComConHdl, kEplSdoComConEventSendFirst, // event to start transfer
- NULL);
-
- Exit:
- return Ret;
-
-}
-#endif
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComUndefineCon
-//
-// Description: function undefine a SDO connection
-//
-//
-//
-// Parameters: SdoComConHdl_p = handle for the connection
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
-tEplKernel EplSdoComUndefineCon(tEplSdoComConHdl SdoComConHdl_p)
-{
- tEplKernel Ret;
- tEplSdoComCon *pSdoComCon;
-
- Ret = kEplSuccessful;
-
- if (SdoComConHdl_p >= EPL_MAX_SDO_COM_CON) {
- Ret = kEplSdoComInvalidHandle;
- goto Exit;
- }
- // get pointer to control structure
- pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComConHdl_p];
-
- // $$$ d.k. abort a running transfer before closing the sequence layer
-
- if (((pSdoComCon->m_SdoSeqConHdl & ~EPL_SDO_SEQ_HANDLE_MASK) !=
- EPL_SDO_SEQ_INVALID_HDL)
- && (pSdoComCon->m_SdoSeqConHdl != 0)) {
- // close connection in lower layer
- switch (pSdoComCon->m_SdoProtType) {
- case kEplSdoTypeAsnd:
- case kEplSdoTypeUdp:
- {
- Ret =
- EplSdoAsySeqDelCon(pSdoComCon->
- m_SdoSeqConHdl);
- break;
- }
-
- case kEplSdoTypePdo:
- case kEplSdoTypeAuto:
- default:
- {
- Ret = kEplSdoComUnsupportedProt;
- goto Exit;
- }
-
- } // end of switch(pSdoComCon->m_SdoProtType)
- }
-
- // clean controll structure
- EPL_MEMSET(pSdoComCon, 0x00, sizeof(tEplSdoComCon));
- Exit:
- return Ret;
-}
-#endif
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComGetState
-//
-// Description: function returns the state fo the connection
-//
-//
-//
-// Parameters: SdoComConHdl_p = handle for the connection
-// pSdoComFinished_p = pointer to structur for sdo state
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
-tEplKernel EplSdoComGetState(tEplSdoComConHdl SdoComConHdl_p,
- tEplSdoComFinished *pSdoComFinished_p)
-{
- tEplKernel Ret;
- tEplSdoComCon *pSdoComCon;
-
- Ret = kEplSuccessful;
-
- if (SdoComConHdl_p >= EPL_MAX_SDO_COM_CON) {
- Ret = kEplSdoComInvalidHandle;
- goto Exit;
- }
- // get pointer to control structure
- pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComConHdl_p];
-
- // check if handle ok
- if (pSdoComCon->m_SdoSeqConHdl == 0) {
- Ret = kEplSdoComInvalidHandle;
- goto Exit;
- }
-
- pSdoComFinished_p->m_pUserArg = pSdoComCon->m_pUserArg;
- pSdoComFinished_p->m_uiNodeId = pSdoComCon->m_uiNodeId;
- pSdoComFinished_p->m_uiTargetIndex = pSdoComCon->m_uiTargetIndex;
- pSdoComFinished_p->m_uiTargetSubIndex = pSdoComCon->m_uiTargetSubIndex;
- pSdoComFinished_p->m_uiTransferredByte =
- pSdoComCon->m_uiTransferredByte;
- pSdoComFinished_p->m_dwAbortCode = pSdoComCon->m_dwLastAbortCode;
- pSdoComFinished_p->m_SdoComConHdl = SdoComConHdl_p;
- if (pSdoComCon->m_SdoServiceType == kEplSdoServiceWriteByIndex) {
- pSdoComFinished_p->m_SdoAccessType = kEplSdoAccessTypeWrite;
- } else {
- pSdoComFinished_p->m_SdoAccessType = kEplSdoAccessTypeRead;
- }
-
- if (pSdoComCon->m_dwLastAbortCode != 0) { // sdo abort
- pSdoComFinished_p->m_SdoComConState =
- kEplSdoComTransferRxAborted;
-
- // delete abort code
- pSdoComCon->m_dwLastAbortCode = 0;
-
- } else if ((pSdoComCon->m_SdoSeqConHdl & ~EPL_SDO_SEQ_HANDLE_MASK) == EPL_SDO_SEQ_INVALID_HDL) { // check state
- pSdoComFinished_p->m_SdoComConState =
- kEplSdoComTransferLowerLayerAbort;
- } else if (pSdoComCon->m_SdoComState == kEplSdoComStateClientWaitInit) {
- // finished
- pSdoComFinished_p->m_SdoComConState =
- kEplSdoComTransferNotActive;
- } else if (pSdoComCon->m_uiTransSize == 0) { // finished
- pSdoComFinished_p->m_SdoComConState =
- kEplSdoComTransferFinished;
- }
-
- Exit:
- return Ret;
-
-}
-#endif
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComSdoAbort
-//
-// Description: function abort a sdo transfer
-//
-//
-//
-// Parameters: SdoComConHdl_p = handle for the connection
-// dwAbortCode_p = abort code
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
-tEplKernel EplSdoComSdoAbort(tEplSdoComConHdl SdoComConHdl_p,
- u32 dwAbortCode_p)
-{
- tEplKernel Ret;
- tEplSdoComCon *pSdoComCon;
-
- if (SdoComConHdl_p >= EPL_MAX_SDO_COM_CON) {
- Ret = kEplSdoComInvalidHandle;
- goto Exit;
- }
- // get pointer to control structure of connection
- pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComConHdl_p];
-
- // check if handle ok
- if (pSdoComCon->m_SdoSeqConHdl == 0) {
- Ret = kEplSdoComInvalidHandle;
- goto Exit;
- }
- // save pointer to abort code
- pSdoComCon->m_pData = (u8 *) & dwAbortCode_p;
-
- Ret = EplSdoComProcessIntern(SdoComConHdl_p,
- kEplSdoComConEventAbort,
- (tEplAsySdoCom *) NULL);
-
- Exit:
- return Ret;
-}
-#endif
-
-//=========================================================================//
-// //
-// P R I V A T E F U N C T I O N S //
-// //
-//=========================================================================//
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComReceiveCb
-//
-// Description: callback function for SDO Sequence Layer
-// -> indicates new data
-//
-//
-//
-// Parameters: SdoSeqConHdl_p = Handle for connection
-// pAsySdoCom_p = pointer to data
-// uiDataSize_p = size of data ($$$ not used yet, but it should)
-//
-//
-// Returns:
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-tEplKernel EplSdoComReceiveCb(tEplSdoSeqConHdl SdoSeqConHdl_p,
- tEplAsySdoCom *pAsySdoCom_p,
- unsigned int uiDataSize_p)
-{
- tEplKernel Ret;
-
- // search connection internally
- Ret = EplSdoComSearchConIntern(SdoSeqConHdl_p,
- kEplSdoComConEventRec, pAsySdoCom_p);
-
- EPL_DBGLVL_SDO_TRACE3
- ("EplSdoComReceiveCb SdoSeqConHdl: 0x%X, First Byte of pAsySdoCom_p: 0x%02X, uiDataSize_p: 0x%04X\n",
- SdoSeqConHdl_p, (u16) pAsySdoCom_p->m_le_abCommandData[0],
- uiDataSize_p);
-
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComConCb
-//
-// Description: callback function called by SDO Sequence Layer to inform
-// command layer about state change of connection
-//
-//
-//
-// Parameters: SdoSeqConHdl_p = Handle of the connection
-// AsySdoConState_p = Event of the connection
-//
-//
-// Returns: tEplKernel = Errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-tEplKernel EplSdoComConCb(tEplSdoSeqConHdl SdoSeqConHdl_p,
- tEplAsySdoConState AsySdoConState_p)
-{
- tEplKernel Ret;
- tEplSdoComConEvent SdoComConEvent = kEplSdoComConEventSendFirst;
-
- Ret = kEplSuccessful;
-
- // check state
- switch (AsySdoConState_p) {
- case kAsySdoConStateConnected:
- {
- EPL_DBGLVL_SDO_TRACE0("Connection established\n");
- SdoComConEvent = kEplSdoComConEventConEstablished;
- // start transmission if needed
- break;
- }
-
- case kAsySdoConStateInitError:
- {
- EPL_DBGLVL_SDO_TRACE0("Error during initialisation\n");
- SdoComConEvent = kEplSdoComConEventInitError;
- // inform app about error and close sequence layer handle
- break;
- }
-
- case kAsySdoConStateConClosed:
- {
- EPL_DBGLVL_SDO_TRACE0("Connection closed\n");
- SdoComConEvent = kEplSdoComConEventConClosed;
- // close sequence layer handle
- break;
- }
-
- case kAsySdoConStateAckReceived:
- {
- EPL_DBGLVL_SDO_TRACE0("Acknowlage received\n");
- SdoComConEvent = kEplSdoComConEventAckReceived;
- // continue transmission
- break;
- }
-
- case kAsySdoConStateFrameSended:
- {
- EPL_DBGLVL_SDO_TRACE0("One Frame sent\n");
- SdoComConEvent = kEplSdoComConEventFrameSended;
- // to continue transmission
- break;
-
- }
-
- case kAsySdoConStateTimeout:
- {
- EPL_DBGLVL_SDO_TRACE0("Timeout\n");
- SdoComConEvent = kEplSdoComConEventTimeout;
- // close sequence layer handle
- break;
-
- }
- } // end of switch(AsySdoConState_p)
-
- Ret = EplSdoComSearchConIntern(SdoSeqConHdl_p,
- SdoComConEvent, (tEplAsySdoCom *) NULL);
-
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComSearchConIntern
-//
-// Description: search a Sdo Sequence Layer connection handle in the
-// control structure of the Command Layer
-//
-// Parameters: SdoSeqConHdl_p = Handle to search
-// SdoComConEvent_p = event to process
-// pAsySdoCom_p = pointer to received frame
-//
-// Returns: tEplKernel
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-static tEplKernel EplSdoComSearchConIntern(tEplSdoSeqConHdl SdoSeqConHdl_p,
- tEplSdoComConEvent SdoComConEvent_p,
- tEplAsySdoCom * pAsySdoCom_p)
-{
- tEplKernel Ret;
- tEplSdoComCon *pSdoComCon;
- tEplSdoComConHdl HdlCount;
- tEplSdoComConHdl HdlFree;
-
- Ret = kEplSdoComNotResponsible;
-
- // get pointer to first element of the array
- pSdoComCon = &SdoComInstance_g.m_SdoComCon[0];
- HdlCount = 0;
- HdlFree = 0xFFFF;
- while (HdlCount < EPL_MAX_SDO_COM_CON) {
- if (pSdoComCon->m_SdoSeqConHdl == SdoSeqConHdl_p) { // matching command layer handle found
- Ret = EplSdoComProcessIntern(HdlCount,
- SdoComConEvent_p,
- pAsySdoCom_p);
- } else if ((pSdoComCon->m_SdoSeqConHdl == 0)
- && (HdlFree == 0xFFFF)) {
- HdlFree = HdlCount;
- }
-
- pSdoComCon++;
- HdlCount++;
- }
-
- if (Ret == kEplSdoComNotResponsible) { // no responsible command layer handle found
- if (HdlFree == 0xFFFF) { // no free handle
- // delete connection immediately
- // 2008/04/14 m.u./d.k. This connection actually does not exist.
- // pSdoComCon is invalid.
- // Ret = EplSdoAsySeqDelCon(pSdoComCon->m_SdoSeqConHdl);
- Ret = kEplSdoComNoFreeHandle;
- } else { // create new handle
- HdlCount = HdlFree;
- pSdoComCon = &SdoComInstance_g.m_SdoComCon[HdlCount];
- pSdoComCon->m_SdoSeqConHdl = SdoSeqConHdl_p;
- Ret = EplSdoComProcessIntern(HdlCount,
- SdoComConEvent_p,
- pAsySdoCom_p);
- }
- }
-
- return Ret;
-
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplSdoComProcessIntern
-//
-// Description: search a Sdo Sequence Layer connection handle in the
-// control structer of the Command Layer
-//
-//
-//
-// Parameters: SdoComCon_p = index of control structure of connection
-// SdoComConEvent_p = event to process
-// pAsySdoCom_p = pointer to received frame
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-static tEplKernel EplSdoComProcessIntern(tEplSdoComConHdl SdoComCon_p,
- tEplSdoComConEvent SdoComConEvent_p,
- tEplAsySdoCom * pAsySdoCom_p)
-{
- tEplKernel Ret;
- tEplSdoComCon *pSdoComCon;
- u8 bFlag;
-
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
- u32 dwAbortCode;
- unsigned int uiSize;
-#endif
-
-#if defined(WIN32) || defined(_WIN32)
- // enter critical section for process function
- EnterCriticalSection(SdoComInstance_g.m_pCriticalSection);
- EPL_DBGLVL_SDO_TRACE0
- ("\n\tEnterCiticalSection EplSdoComProcessIntern\n\n");
-#endif
-
- Ret = kEplSuccessful;
-
- // get pointer to control structure
- pSdoComCon = &SdoComInstance_g.m_SdoComCon[SdoComCon_p];
-
- // process state maschine
- switch (pSdoComCon->m_SdoComState) {
- // idle state
- case kEplSdoComStateIdle:
- {
- // check events
- switch (SdoComConEvent_p) {
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
- // init con for client
- case kEplSdoComConEventInitCon:
- {
-
- // call of the init function already
- // processed in EplSdoComDefineCon()
- // only change state to kEplSdoComStateClientWaitInit
- pSdoComCon->m_SdoComState =
- kEplSdoComStateClientWaitInit;
- break;
- }
-#endif
-
- // int con for server
- case kEplSdoComConEventRec:
- {
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0)
- // check if init of an transfer and no SDO abort
- if ((pAsySdoCom_p->m_le_bFlags & 0x80) == 0) { // SDO request
- if ((pAsySdoCom_p->m_le_bFlags & 0x40) == 0) { // no SDO abort
- // save tansaction id
- pSdoComCon->
- m_bTransactionId =
- AmiGetByteFromLe
- (&pAsySdoCom_p->
- m_le_bTransactionId);
- // check command
- switch (pAsySdoCom_p->
- m_le_bCommandId)
- {
- case kEplSdoServiceNIL:
- { // simply acknowlegde NIL command on sequence layer
-
- Ret =
- EplSdoAsySeqSendData
- (pSdoComCon->
- m_SdoSeqConHdl,
- 0,
- (tEplFrame
- *)
- NULL);
-
- break;
- }
-
- case kEplSdoServiceReadByIndex:
- { // read by index
-
- // search entry an start transfer
- EplSdoComServerInitReadByIndex
- (pSdoComCon,
- pAsySdoCom_p);
- // check next state
- if (pSdoComCon->m_uiTransSize == 0) { // ready -> stay idle
- pSdoComCon->
- m_SdoComState
- =
- kEplSdoComStateIdle;
- // reset abort code
- pSdoComCon->
- m_dwLastAbortCode
- =
- 0;
- } else { // segmented transfer
- pSdoComCon->
- m_SdoComState
- =
- kEplSdoComStateServerSegmTrans;
- }
-
- break;
- }
-
- case kEplSdoServiceWriteByIndex:
- {
-
- // search entry an start write
- EplSdoComServerInitWriteByIndex
- (pSdoComCon,
- pAsySdoCom_p);
- // check next state
- if (pSdoComCon->m_uiTransSize == 0) { // already -> stay idle
- pSdoComCon->
- m_SdoComState
- =
- kEplSdoComStateIdle;
- // reset abort code
- pSdoComCon->
- m_dwLastAbortCode
- =
- 0;
- } else { // segmented transfer
- pSdoComCon->
- m_SdoComState
- =
- kEplSdoComStateServerSegmTrans;
- }
-
- break;
- }
-
- default:
- {
- // unsupported command