 /* @file apci2016.h
  * 
  * @brief Define the public API for the apci2016 ADDI-DATA board. 
  * 
  *
  */

/** @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
 
 This library is free software; you can redistribute it and/or modify it under 
 the terms of the GNU Lesser General Public License as published by the 
 Free Software Foundation; either version 2.1 of the License, 
 or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful, 
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 or FITNESS FOR A PARTICULAR PURPOSE. 
 See the GNU Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public License 
 along with this library; if not, write to the Free Software Foundation, 
 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 
 You also shoud find the complete LGPL in the LGPL.txt file accompanying 
 this source code.
 
 @endverbatim
**/

#ifndef __APCI2016_H__
#define __APCI2016_H__

#define APCI2016_DRIVER_VERSION_MAJOR 2026
#define APCI2016_DRIVER_VERSION_MINOR 06
#define APCI2016_DRIVER_VERSION_PATCH 1

#include <apci.h>

//GENERAL DEFINE

#define APCI2016_BOARD_NAME                      "APCI2016"
#define APCI2016_BOARD_VENDOR_ID                 0x15B8
#define APCI2016_BOARD_DEVICE_ID                 0x1002

/* value used for CMD_APCI2016_CheckAndGetPCISlotNumber ! DEPRECATED ! */
#ifndef CONFIG_APCI2016_MAX_BOARD_NBR
#define CONFIG_APCI2016_MAX_BOARD_NBR                   (3)
#endif // CONFIG_APCI2016_MAX_BOARD_NBR

// for compatibility with older driver (deprecated)
#define APCI2016_MAX_BOARD_NBR CONFIG_APCI2016_MAX_BOARD_NBR

// IOCTL define part
#define APCI2016_MAGIC (char) 'A'

/**
 * @param (char*) area of size CONFIG_APCI2016_MAX_BOARD_NBR+1
 * 
 * @deprecated
 * 
 */
#define CMD_APCI2016_CheckAndGetPCISlotNumber   _IOR(APCI2016_MAGIC, 1,char*)
#define CMD_APCI2016_SetBoardInformation        _IOW(APCI2016_MAGIC, 2,USHORT)
/* deprecated */
#define CMD_APCI2016_GetHardwareInformation     _IOR(APCI2016_MAGIC, 3,str_BaseInformations*)
/** Activates the digital output memory.
 * 
 * @param arg (Use NULL)
 * 
 *  After calling up this function, the outputs you have previously activated 
 * with the function "i_ADDIDATA_SetXDigitalOutputOn" * are not reset. You can 
 * reset them with the function "i_ADDIDATA_SetXDigitalOutputOff".
 * 
 */
#define CMD_APCI2016_SetDigitalOutputMemoryOn	_IOW(APCI2016_MAGIC, 4,long)
/** Deactivates the digital output memory.
 * 
 * @param arg (Use NULL)
 */
#define CMD_APCI2016_SetDigitalOutputMemoryOff	_IOW(APCI2016_MAGIC, 5,long)
/** Sets the given output.
 * 
 * @param arg (unsigned long) Number of the channel to set (from 1 to 16 included)
 * 
 * @return 0 or -EINVAL
 * 
 * Setting one output means setting the output to "High".
 * If you have switched on the digital ouput memory (ON), the selected outputs 
 * channels are set to "1". The other channels hold their state.
 * If you have switched off the digital output memory (OFF), the selected 
 * outputs are set to "1". The other channels are reset.
 * 
 */
#define CMD_APCI2016_Set1DigitalOutputOn		_IOW(APCI2016_MAGIC, 6,unsigned long)

/** Resets the given output.
 * 
 * @param arg (uint32_t) Map of the output to set
 * 
 * @return 0 or -EINVAL
 * 
 * Resetting an output means setting this output to "Low". The other channels 
 * hold their state.
 * 
 * @warning You can use this function only if the digital output memory is ON. See 
 * function b_ADDIDATA_SetDigitalOutputMemoryOn (..).
 * 
 * 
 */
#define CMD_APCI2016_Set1DigitalOutputOff		_IOW(APCI2016_MAGIC, 7,uint32_t)

/** Sets the given outputs.
 * 
 * @param arg (uint16_t) Map of the output to set
 * 
 * @return 0 or -EINVAL
 * 
 * Setting one output means setting the output to "High".
 * If you have switched on the digital ouput memory (ON), the selected outputs 
 * channels are set to "1". The other channels hold their state.
 * If you have switched off the digital output memory (OFF), the selected 
 * outputs are set to "1". The other channels are reset.
 * 
 */
#define CMD_APCI2016_Set16DigitalOutputsOn		_IOW(APCI2016_MAGIC, 8,uint16_t)

/** Resets one or several outputs of a port.
 * 
 * 
 * @param arg (uint16_t) Map of the output to reset
 * 
 * @return 0 or -EINVAL
 * 
 * Resetting an output means setting this output to "Low". The other channels 
 * hold their state.
 * 
 * @warning You can use this function only if the digital output memory is ON. See 
 * function b_ADDIDATA_SetDigitalOutputMemoryOn (..).
 * 
 * 
 */
#define CMD_APCI2016_Set16DigitalOutputsOff		_IOW(APCI2016_MAGIC, 9,uint16_t)

/** Returns the status of a 1-bit output.
 * @param arg (unsigned int*) address of the integer where to store the status
 * 
 * @return 0 if success, -EFAULT if address is invalid 
 * 
*/
#define CMD_APCI2016_Get1DigitalOutputStatus	_IOR(APCI2016_MAGIC, 10,unsigned int*)

/** Returns the status of a 32-bit port.
 * @param arg (uint16_t*) address of the 16 bits field to store the status
 * 
 * @return 0 if success, -EFAULT if address is invalid 
 * 
*/
#define CMD_APCI2016_Get16DigitalOutputStatus	_IOR(APCI2016_MAGIC, 11,uint16_t*)


/** Initialises the watchdog.
 * 
 * @param arg (uint32_t) dw_Delayvalue (= reload value)
 * 
 * dw_Delayvalue in milliseconds steps  (Min.: 20 ms Max.: 5100 ms )
 * The Delay Value is divided by 20 to compute the reload value.
 *  
 * ex: 1 second: 1000
 * 
 * 
 * @return 0 or -EINVAL
 * 
 * 
 * 
 * The watchdog is not started by this function.
 * If it was previously running, the watchdog is stopped.
 * Use CMD_APCI2016_StartWatchdog to start the watchdog
 * 
 */

#define CMD_APCI2016_InitWatchdog				_IOR(APCI2016_MAGIC, 12,uint32_t)

/* Enable the watchdog.
 * 
 * @param arg (use NULL)
 * 
 * @return 0 or -ENODEV (watchdog not configured)
 * 
 * @warning Use CMD_APCI2016_InitWatchdog before starting the watchdog
 * 
 * This function just enable the watchdog. It doesn't really "start" it. 
 * To start the count-down, either do a software trigger or perform an output.
 * 
 * @note When started the watchdog can no more be stoped, unless timed-out
 * 
 */
#define CMD_APCI2016_StartWatchdog				_IOR(APCI2016_MAGIC, 14,unsigned long)

/* Software trigger of the watchdog.
 * 
 * @param arg (use NULL)
 * 
 * @return 0 or -ENODEV (watchdog not configured)
 * 
 * @warning Use CMD_APCI2016_InitWatchdog before 
 */
#define CMD_APCI2016_TriggerWatchdog			_IOR(APCI2016_MAGIC, 15,unsigned long)

/* use that to parse waatchdog's status 
 * 
 * APCI2016_WATCHDOG_TIMEDOUT : watchdog has timed out (internal counter overflow) 
 * when this bit is set, all outputs are set to "down"
 * APCI2016_WATCHDOG_TRIGGERED : the watchdog has been previously triggered
 * 
 * */
#define APCI2016_WATCHDOG_TIMEDOUT				0x1
#define APCI2016_WATCHDOG_TRIGGERED				0x2

/* Returns the state of the watchdog
 *  
 * @param (unsigned int*) address of the field to store the status
 * @return 
 * 
 * The status can be 0, APCI2016_WATCHDOG_TIMEDOUT, APCI2016_WATCHDOG_TRIGGERED 
 * or APCI2016_WATCHDOG_TIMEDOUT | APCI2016_WATCHDOG_TRIGGERED
 * 
 * @note These bits are cleared by the board after reading
 * 
 */

#define CMD_APCI2016_ReadWatchdogStatus 		_IOR(APCI2016_MAGIC, 17,unsigned long)


#endif // __APCI2016_H__
