/** @file in_out.h
 
   This file is taken from the Windows driver and adapted for Linux.
 
   @par CREATION  
   @author Krauth Julien
   @date   09.10.2006
   
   @par VERSION
   @verbatim
   $LastChangedRevision:$
   $LastChangedDate:$
   @endverbatim   
   
   @par LICENCE
   @verbatim
   Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module.
        
        ADDI-DATA GmbH 
        Dieselstrasse 3 
        D-77833 Ottersweier 
        Tel: +19(0)7223/9493-0 
        Fax: +49(0)7223/9493-92 
        http://www.addi-data-com 
        info@addi-data.com         
   @endverbatim   
 */ 
 
#ifndef _IN_OUT_H_
#define _IN_OUT_H_

   __inline__ void OUTP (pstr_AddressInformation ps_Address, DWORD dw_Offset, BYTE b_ByteValue)
	   {
	   short unsigned int ui_CopyAddress;
	   unsigned char *    pb_Address;

	   if (ps_Address->b_AccessType == 1)
	      {
	      ui_CopyAddress  = (short unsigned int) (ps_Address->ui_Address + dw_Offset);	     	      
	      outb (b_ByteValue, ui_CopyAddress);
	      }
	   else
	      {
	      pb_Address = (unsigned char *) ps_Address->pul_MemoryAddress;
	      pb_Address [dw_Offset] = b_ByteValue;
	      }
	   }

   __inline__ void OUTPW (pstr_AddressInformation ps_Address, DWORD dw_Offset, UINT ui_WordValue)
	   {
	   short unsigned int ui_CopyAddress;
	   short unsigned int ui_WriteValue;
	   unsigned short *   pw_Address;

	   ui_WriteValue  = (short unsigned int) ui_WordValue;
	   ui_CopyAddress = (short unsigned int) (ps_Address->ui_Address + dw_Offset);

	   if (ps_Address->b_AccessType == 1)
	      {
	      outw (ui_WriteValue, ui_CopyAddress);
	      }
	   else
	      {
	      pw_Address = (unsigned short *) ps_Address->pul_MemoryAddress;
	      pw_Address [dw_Offset / 2] = (unsigned short) ui_WordValue;
	      }
	   }

   __inline__ void OUTPDW (pstr_AddressInformation ps_Address, DWORD dw_Offset, ULONG ul_LongValue)
	   {
	   DWORD * pdw_Address;
	   DWORD dw_Address;

	   dw_Address = ps_Address->ui_Address + dw_Offset;


	   if (ps_Address->b_AccessType == 1)
	      {
	      outl (ul_LongValue, dw_Address);
	      }
	   else
	      {
	      pdw_Address = (DWORD *) ps_Address->pul_MemoryAddress;
	      pdw_Address [dw_Offset / 4] = ul_LongValue;
	      }
	   }

   __inline__ BYTE INP (pstr_AddressInformation ps_Address, DWORD dw_Offset)
	   {
	   short unsigned int ui_CopyAddress;
	   BYTE                b_ReadValue;
	   unsigned char *    pb_Address;

	   ui_CopyAddress = (short unsigned int) (ps_Address->ui_Address + dw_Offset);

	   if (ps_Address->b_AccessType == 1)
	      {
	      b_ReadValue = inb (ui_CopyAddress);
	      }
	   else
	      {
	      pb_Address = (unsigned char *) ps_Address->pul_MemoryAddress;
	      b_ReadValue = pb_Address [dw_Offset];
	      }

	   return (b_ReadValue);
	   }

   __inline__ WORD INPW (pstr_AddressInformation ps_Address, DWORD dw_Offset)
	   {
	   short unsigned int ui_CopyAddress;
	   WORD                w_ReadValue;
	   unsigned short *   pw_Address;

	   ui_CopyAddress = (short unsigned int) (ps_Address->ui_Address + dw_Offset);

	   if (ps_Address->b_AccessType == 1)
	      {
	      w_ReadValue = inw (ui_CopyAddress);
	      }
	   else
	      {
	      pw_Address = (unsigned short *) ps_Address->pul_MemoryAddress;
	      w_ReadValue = pw_Address [dw_Offset / 2];
	      }

	   return ((WORD) w_ReadValue);
	   }

   __inline__ DWORD INPDW (pstr_AddressInformation ps_Address, DWORD dw_Offset)
	   {
	   DWORD    ul_ReadValue;
	   DWORD * pdw_Address;
	   DWORD    dw_Address;

	   dw_Address = ps_Address->ui_Address + dw_Offset;

	   if (ps_Address->b_AccessType == 1)
	      {
	      ul_ReadValue = inl (dw_Address);
	      }
	   else
	      {
	      pdw_Address = (DWORD *) ps_Address->pul_MemoryAddress;
	      ul_ReadValue = pdw_Address [dw_Offset / 4];
	      }

	   return (ul_ReadValue);
	   }

#endif //_IN_OUT_H_
