diff options
author | Christian Gromm <christian.gromm@microchip.com> | 2016-06-21 14:14:04 +0200 |
---|---|---|
committer | Christian Gromm <christian.gromm@microchip.com> | 2016-06-21 14:14:04 +0200 |
commit | 860b3c0ccfb2756b8ed77523048952011b74a212 (patch) | |
tree | e0672fb5cf923dcf0a4a48a62a69011e1b72976a /K2LABI/IPC/K2LIPC.h | |
parent | 742bace60b9c0a0f583d8afe1097d029f468fa03 (diff) |
src: can-lin: initial source import
This patch adds the sources needed for the HVAC and iDrive applications.
Change-Id: I53148a5d11c34787dd11295939bbaf8702c64dcb
Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Diffstat (limited to 'K2LABI/IPC/K2LIPC.h')
-rw-r--r-- | K2LABI/IPC/K2LIPC.h | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/K2LABI/IPC/K2LIPC.h b/K2LABI/IPC/K2LIPC.h new file mode 100644 index 0000000..e959dbf --- /dev/null +++ b/K2LABI/IPC/K2LIPC.h @@ -0,0 +1,199 @@ +/*=== K2L GmbH ===============================================================*/ +/** +\file + This file contains the API of the \ref IPC interface. + +\ingroup IPC + +\par COPYRIGHT (c) 2000-2011 by K2L GmbH + All rights reserved. +*/ +/*============================================================================== + Alle Rechte an der Software verbleiben bei der K2L GmbH. + + Die K2L GmbH raeumt dem Lizenznehmer nach vollstaendiger + Bezahlung der Lizenzgebuehr ein nicht ausschliessliches, + unwiderrufliches, nicht uebertragbares, zeitlich und geografisch + nicht beschraenktes Recht zur Nutzung der jeweils + auftragsgegenstaendlichen Software innerhalb des Lizenznehmers ein. + + Die Weitergabe des Nutzungsrechts durch den Lizenznehmer ist auf + dessen Zulieferer beschraenkt. Die Zulieferer sind zu verpflichten, + die Software nur im Rahmen von Projekten fuer den Lizenznehmer + zu verwenden; weitere Rechte der Zulieferer sind auszuschliessen. +===HEADER END=================================================================*/ +//@{ + +#pragma once + +/// \defgroup IPC Interprocess communication +/// The IPC group ... +namespace K2L +{ + namespace Automotive + { + namespace IPC + { + +class IIpc; + +/// Identifies the head of the packet. +#define ABI_IPC_PACKET_HEAD 0x04 + +/// Identifies the IPC channel 7. +#define ABI_IPC_CHANNEL7 0x07 + +/// Identifies the IPC channel 8. +#define ABI_IPC_CHANNEL8 0x08 + +#pragma pack(push, 1) +/// \brief Class holding all informations to create a IPC message. +/// \ingroup IPC +class CIpcPacket +{ +public: + /// The header of the IPC packet. + BYTE m_head; + + /// The channel of the IPC packet. + BYTE m_channel; + + /// The length of the IPC packet. + DWORD m_length; + + /// The error code of the IPC packet. + BYTE m_errorCode; + + /// Checksum of the IPC header. + BYTE m_hdrCrc; +}; +#pragma pack(pop) + +#pragma pack(push, 1) +/// \brief Class holding all informations to create a IPC request. +/// \ingroup IPC +class CRequest +{ +public: + /// Message processing group in the ABI device. + BYTE m_interface; + + /// Function id of the request. + BYTE m_function; + + /// Request Id. + DWORD m_requestId; +}; +#pragma pack(pop) + +/*============================================================================*/ +/// \brief Interface of IPC event listener. +/// \note Abstract base class. So it has to be implemented. +/// \ingroup IPC +/*============================================================================*/ +class K2LABI_API IIPCListener +{ +public: + virtual ~IIPCListener() {} + + /// Called if packet arrived. + /// \param[in] pIpc Pointer to IPC that has occured event. + /// \param[in] pPacket Pointer to data package. + /// \param[in] nLen Length of package. + virtual void OnMessage(IIpc* pIpc, BYTE channel, BYTE errorCode, BYTE* pPacket, int nLen) = 0; + + /// Called if error occured. + /// \param[in] pIpc Pointer to IPC that has occured event. + virtual void OnError(IIpc* pIpc) = 0; + + /// Called if message lost caused by an overflow. + /// \param[in] pIpc Pointer to IPC that has occured event. + virtual void OnMessageLost(IIpc* pIpc) = 0; +}; + +/*============================================================================*/ +/// \brief Interface of interprocess connection. +/// \ingroup IPC +/*============================================================================*/ +class K2LABI_API IIpc +{ +public: + virtual ~IIpc() {} + + /// Initializes IPC connection. + /// \param[in] Device to connect. + /// \param[in] Event listener. + /// \return 0 if operation successful. + /// \return !0 if operation failed. + virtual int Init(IIPCListener* pListener) = 0; + + /// Deinitializes IPC connection. + /// \return 0 if operation successful. + /// \return !0 if operation failed. + virtual int Deinit() = 0; + + /// Sends a request to the device. + /// \param[in] Namespace ID of command. + /// \param[in] Function ID of command. + /// \param[in] Pointer to data that should be send. + /// \param[in] Length of data. + /// \param[out] Length of result. + /// \param[out] Error code of operation. + /// \return Response of request. NULL if no response returned. + virtual int FormatRequest(BYTE channel, BYTE ifaceId, BYTE funId, DWORD dwSenderID, const BYTE *pData, DWORD dataLen, BYTE* pResult, int nResultLen, int* nResultLenNeeded) = 0; + + /// Decodes a IPC message from the buffer. + /// \param[in] pPipe Pipe to check if an overflow occurr. + /// \param[in] pBuffer Pointer to the first byte of message that should be decoded. + /// \param[in] nLen Length of message. + virtual void Decode(BYTE* pBuffer, DWORD nLen) = 0; + + /// Gets a pointer to the registered event listener. + /// \return Pointer to event listener. + virtual IIPCListener* GetListener() = 0; +}; + +/*============================================================================*/ +/// \brief Factory to create IPC connections. +/// \ingroup IPC +/*============================================================================*/ +class K2LABI_API CIpcFactory +{ +public: + /// Create new IPC connection. + /// \return Pointer to new IPC connection. + static IIpc* CreateIpc(); + + /// Destroy IPC connection. + /// \param[in] Pointer to IPC connection that should be destroied. + static void DestroyIpc(IIpc* pIpc); +}; + } + } +} + +/*============================================================================*/ +/* C interface */ +/*============================================================================*/ + +extern "C" +{ +#define IPC_HANDLE HANDLE + +typedef void (*FCT_OnMessageEvent) (IPC_HANDLE, BYTE, BYTE, BYTE*, int); +typedef void (*FCT_OnEvent) (IPC_HANDLE); + +K2LABI_API IPC_HANDLE CreateIPC (); +K2LABI_API void DestroyIPC (IPC_HANDLE hIpc); + +K2LABI_API int IPCInit (IPC_HANDLE hIpc, FCT_OnMessageEvent callback, FCT_OnEvent error, FCT_OnEvent overflow); +K2LABI_API int IPCDeinit (IPC_HANDLE hIpc); +K2LABI_API int IPCFormatRequest (IPC_HANDLE hIpc, BYTE channel, BYTE ifaceId, BYTE funId, DWORD dwSenderID, const BYTE *pReqData, DWORD dataLen, BYTE* pResult, int nResultLen, int* nNeededResultLen); +K2LABI_API void IPCDecode (IPC_HANDLE hIpc, BYTE* pData, int nDataLen); +K2LABI_API void IPCDecodeFlow (IPC_HANDLE hIpc, HANDLE hReaderPipe, BYTE* pData, int nDataLen); +} + +//@} +/*============================================================================*/ +/* END OF FILE */ +/*============================================================================*/ |