/*  Copyright (C) MOXA Inc. All rights reserved.
 
    This software is distributed under the terms of the
    MOXA License.  See the file COPYING-MOXA for details.
*/

/*****************************************************************************/
/**  FILE NAME  : MxGeneralIo.h			                                     */
/**                                                                          */
/**  DESCRIPTION:                                                            */
/**    implementation file of the general IO interface.	                     */
/**    Definition for General Io			                                 */
/**                                                                          */
/**  Copyright (C) 2011 Moxa Inc. All rights reserved.                       */
/*****************************************************************************/

/*****************************************************************************/
/**  REVISION HISTORY   :                                                    */
/**                                                                          */
/**      2011-09-04		Epson												 */
/**						create file											 */
/**                                                                          */
/*****************************************************************************/
#ifndef MXGENERALIO_H
#define MXGENERALIO_H

/*****************************************************************************
 *  Include Section															 *
 ****************************************************************************/
#include "winio_nt.h"

#ifdef __cplusplus 
extern "C" {
#endif

/*****************************************************************************
 *  Definition Section														 *
 ****************************************************************************/
#define IO_TYPE_SUPERIO		0
#define IO_TYPE_IOBASE		1


/*****************************************************************************
 *  Self-defined function													 *
 ****************************************************************************/
/* GeneralIoOpen : Initialize the WinIo
 *
 * Param:
 * 
 * Input:
 *		none
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		status, TRUE for success, FALSE for fail	
 */
BOOL MxGeneralIoOpen();


/* GeneralIoClose : Close the WinIo
 *
 * Param:
 * 
 * Input:
 *		none
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void MxGeneralIoClose();


/* GetGeneralIoVal : get io value from GPIO or SuperIO
 *
 * Param:
 * 
 * Input:
 *		<nIoType> : IO type, GPIO or SuperIO
 *		<wIoAddress> : Port address
 *	
 * Output:
 *		<pdwPortVal> : port value
 *
 * Return Value:
 *		TRUE for success, FALSE for fail	
 */
BOOL MxGetGeneralIoVal(int nIoType,WORD wIoAddress,DWORD *pdwPortVal,BYTE bSize);

BOOL MxGetGeneralIoVal2(int nIoType, UCHAR bLogicDev, WORD wIoAddress, DWORD *dwPortValue,BYTE bSize);

BOOL MxGetGeneralIoValEx(int nIoType,WORD wIoAddress,DWORD *pdwPortVal,BYTE bSize,tagSuperIoStruct SuperIoStruct);

/* SetGeneralIoVal : get io value from GPIO or SuperIO
 *
 * Param:
 * 
 * Input:
 *		<nIoType> : IO type, GPIO or SuperIO
 *		<wIoAddress> : Port address
 *		<dwPortValue> : Port value to set
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		status, TRUE for success, FALSE for fail	
 */
BOOL MxSetGeneralIoVal(int nIoType,WORD wIoAddress, DWORD dwPortValue,BYTE bSize);

/* SetGeneralIoVal : get io value from GPIO or SuperIO
 *
 * Param:
 * 
 * Input:
 *		<nIoType> : IO type, GPIO or SuperIO
 *		<wIoAddress> : Port address
 *		<dwPortValue> : Port value to set
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		status, TRUE for success, FALSE for fail	
 */
BOOL MxSetGeneralIoVal2(int nIoType, int bLogicDev, WORD wIoAddress, DWORD dwPortValue, BYTE bSize);


BOOL MxSetGeneralIoValEx(int nIoType,WORD wIoAddress, DWORD dwPortValue,BYTE bSize,tagSuperIoStruct SuperIoStruct);


/*****************************************************************************
 *  SuperIO operation function												 *
 ****************************************************************************/

/* Superio_Enter_Config : Enter SuperIO
 *
 * Param:
 * 
 * Input:
 *		none
 *		
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void	Superio_Enter_Config(void);

/* Superio_Exit_Config : Exit SuperIO
 *
 * Param:
 * 
 * Input:
 *		none
 *		
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void	Superio_Exit_Config(void);

/* Superio_Set_Reg : get SuperIO port value
 *
 * Param:
 * 
 * Input:
 *		<index> : logic device number
 *		<val> : value to set
 *		
 * Output:
 *		none	
 *
 * Return Value:
 *		Port value, -1 for fail	
 */
void	Superio_Set_Reg(DWORD val,DWORD index);

/* Superio_Get_Reg : get SuperIO port value
 *
 * Param:
 * 
 * Input:
 *		<val> : logic device number
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		Port value, -1 for fail	
 */
DWORD	Superio_Get_Reg(DWORD val);

/* Set_Logic_Device : Select logic device
 *
 * Param:
 * 
 * Input:
 *		<val> : logic device number
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void	Set_Logic_Device(DWORD val);

/* NEWIODELAY : SuperIO operation delay
 *
 * Param:
 * 
 * Input:
 *		none
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void	NEWIODELAY();

#ifdef __cplusplus 
}
#endif

#endif
