⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2cecp_stub.c.inc

📁 用于DRX3973或DRX39系列的芯片的控制
💻 INC
字号:
/******************************************************************************
 * FILENAME: $Id: i2cecp_stub.c.inc,v 1.6 2005/12/02 11:08:54 martins Exp $
 *
 * DESCRIPTION:
 * Functions to link to Micronas I2CECP driver DLL on Windows platforms.
 * C version
 *
 * USAGE:
 * Compile to lib.
 *
 * NOTES:
 * $(c) 2003-2005 Micronas GmbH. All rights reserved.
 *
 * This software and related documentation (the 'Software') are intellectual
 * property owned by Micronas and are copyright of Micronas, unless specifically
 * noted otherwise.
 *
 * Any use of the Software is permitted only pursuant to the terms of the
 * license agreement, if any, which accompanies, is included with or applicable
 * to the Software ('License Agreement') or upon express written consent of
 * Micronas. Any copying, reproduction or redistribution of the Software in
 * whole or in part by any means not in accordance with the License Agreement
 * or as agreed in writing by Micronas is expressly prohibited.
 *
 * THE SOFTWARE IS WARRANTED, IF AT ALL, ONLY ACCORDING TO THE TERMS OF THE
 * LICENSE AGREEMENT. EXCEPT AS WARRANTED IN THE LICENSE AGREEMENT THE SOFTWARE
 * IS DELIVERED 'AS IS' AND MICRONAS HEREBY DISCLAIMS ALL WARRANTIES AND
 * CONDITIONS WITH REGARD TO THE SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
 * AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIT
 * ENJOYMENT, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL
 * PROPERTY OR OTHER RIGHTS WHICH MAY RESULT FROM THE USE OR THE INABILITY
 * TO USE THE SOFTWARE.
 *
 * IN NO EVENT SHALL MICRONAS BE LIABLE FOR INDIRECT, INCIDENTAL, CONSEQUENTIAL,
 * PUNITIVE, SPECIAL OR OTHER DAMAGES WHATSOEVER INCLUDING WITHOUT LIMITATION,
 * DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
 * INFORMATION, AND THE LIKE, ARISING OUT OF OR RELATING TO THE USE OF OR THE
 * INABILITY TO USE THE SOFTWARE, EVEN IF MICRONAS HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES, EXCEPT PERSONAL INJURY OR DEATH RESULTING FROM
 * MICRONAS' NEGLIGENCE.                                                        $
 *
 * AUTHOR:
 * Martin Sinot
 *
 * HISTORY:
 ******************************************************************************/

/*
 * Now follows the stub to all functions.
 * They look up the name and then pass it on to the DLL.
 */

#include <windows.h>
#include "i2cecp.h"

HINSTANCE G_I2CECPModule = NULL;

/*
 * Template stub function.
 * Has five parameters, as follows:
 * __type     Return type of function
 * __name     Name of function
 * __proto    Parameter prototype, between parentheses. Must contain variable names
 * __param    Variables, between parentheses. Must match prototype variable names.
 * __retval   Return value if failure
 */
#define STUBFUNC(__type,__name,__proto,__param,__retval) \
__type WINAPI __name __proto \
{ \
    if (G_I2CECPModule) \
    { \
        void *funcptr = (void *) GetProcAddress (G_I2CECPModule, #__name); \
        if (funcptr) \
        { \
            return ((__type (WINAPI *) __proto) funcptr) __param; \
        } \
    } \
    return __retval; \
}


/*
 * Template stub function returning void
 * Has three parameters, as follows:
 * __name     Name of function
 * __proto    Parameter prototype, between parentheses. Must contain variable names
 * __param    Variables, between parentheses. Must match prototype variable names.
 */
#define STUBFUNCVOID(__name,__proto,__param) \
void WINAPI __name __proto \
{ \
    if (G_I2CECPModule) \
    { \
        void *funcptr = (void *) GetProcAddress (G_I2CECPModule, #__name); \
        if (funcptr) \
        { \
            ((void (WINAPI *) __proto) funcptr) __param; \
        } \
    } \
}


/*
 * Initialises I2C library
 * Returns zero if initialising failed.
 */
BOOL I2CECP_Init (void)
{
    if (!G_I2CECPModule)
    {
        G_I2CECPModule = LoadLibrary ("I2CECP");
    }
    return !!G_I2CECPModule;
}


/*
 * Release I2C library
 */
void I2CECP_Terminate (void)
{
    if (G_I2CECPModule)
    {
        FreeLibrary (G_I2CECPModule);
        G_I2CECPModule = NULL;
    }
}


/* Administrative functions */
STUBFUNC(BOOL    , I2CECP_IsPresent           , (void), (), FALSE)
STUBFUNC(int     , I2CECP_GetVersion          , (void), (), 0)
STUBFUNC(int     , I2CECP_Config              , (void), (), 0)
STUBFUNC(int     , I2CECP_GetMode             , (void), (), 0)
STUBFUNC(int     , I2CECP_GetNrInt            , (void), (), 0)
STUBFUNC(int     , I2CECP_WaitForInterrupt    , (void), (), 0)
STUBFUNC(int     , I2CECP_Lock                , (void), (), 0)
STUBFUNC(int     , I2CECP_Unlock              , (void), (), 0)

/* I2C functions  */
STUBFUNC(int     , I2CECP_SendI2C             , (LPBYTE bI2CCommand, unsigned uSize), (bI2CCommand, uSize), 0)
STUBFUNC(int     , I2CECP_ReceiveI2C          , (LPBYTE bI2CBuffer , unsigned uSize), (bI2CBuffer , uSize), 0)
STUBFUNC(int     , I2CECP_I2C                 , (LPBYTE bI2CCommand, unsigned uCmdSize,
                                                 LPBYTE bI2CResult, unsigned uResultSize),
                                                (bI2CCommand, uCmdSize, bI2CResult, uResultSize), 0)
STUBFUNCVOID(I2CECP_ResetI2C, (void), ())
STUBFUNC(int     , I2CECP_SendI2CPulse        , (LPBYTE bI2CPulse, unsigned uSize), (bI2CPulse, uSize), 0)
STUBFUNC(int     , I2CECP_SendI2CPulseN       , (LPBYTE bI2CPulse, unsigned uSize), (bI2CPulse, uSize), 0)
STUBFUNC(int     , I2CECP_SendRecBytes        , (LPBYTE bOutBytes, unsigned nOutBytes, LPBYTE bInBytes, unsigned nInBytes),
                                                (bOutBytes, nOutBytes, bInBytes, nInBytes), -1)


/* ECP functions  */
STUBFUNC(int     , I2CECP_OpenECP             , (void), (), 0)
STUBFUNC(int     , I2CECP_CloseECP            , (void), (), 0)
STUBFUNC(int     , I2CECP_AbortECP            , (void), (), 0)
STUBFUNC(int     , I2CECP_GetECP              , (LPBYTE bBuffer, unsigned uSize,
                                                 HANDLE* uHandle, unsigned uTimeout),
                                                (bBuffer, uSize, uHandle, uTimeout), 0)
STUBFUNC(int     , I2CECP_WaitECP             , (HANDLE uHandle, unsigned uTimeout), (uHandle, uTimeout), 0)


/*  Miscellaneous */
STUBFUNC(unsigned, I2CECP_GetCalibrate        , (void), (), 0)
STUBFUNC(unsigned, I2CECP_GetDelay            , (void), (), 0)
STUBFUNC(unsigned, I2CECP_SetDelay            , (unsigned uTimeout), (uTimeout), 0)
STUBFUNC(int     , I2CECP_FakeInt             , (void), (), 0)
STUBFUNC(char*   , I2CECP_GetVersionString    , (void), (), NULL)
STUBFUNC(int     , I2CECP_StartDriver         , (void), (), 0)
STUBFUNC(int     , I2CECP_StopDriver          , (void), (), 0)
STUBFUNC(int     , I2CECP_GetDriverConfig     , (I2CECPDriverConfigData* data), (data), 0)
STUBFUNC(int     , I2CECP_SetDriverConfig     , (I2CECPDriverConfigData* data), (data), 0)
STUBFUNC(int     , I2CECP_GetDelayClockFreq   , (void), (), -1)
STUBFUNC(int     , I2CECP_SetDelayClockFreq   , (int iFreq), (iFreq), -1)
STUBFUNC(int     , I2CECP_GetDelayClockTimeout, (void), (), -1)
STUBFUNC(int     , I2CECP_SetDelayClockTimeout, (int iTimeout), (iTimeout), -1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -