#ifndef APCI3600ANALOGINPUT_H_
#define APCI3600ANALOGINPUT_H_

//-------------------------------------------------------------------------------------------------------------------
/* InitAnalogInputModule */

/**
@retval 0 : success
@retval -1 : system error
@retval 1 : The handle parameter of the board is wrong
@retval 2 : Wrong module number
@retval 3 : Wrong Single/Diff Mode selection
@retval 4 : Wrong coupling selection
@retval 5 : Wrong Current source flag
@retval 6 : Wrong gain selection
@retval 7 : Wrong clock selection
@retval 8 : wrong Speed mode parameter
@retval 9 : The board is not initialised
@retval 10: Speed mode not available 
@retval 11: The current source are only available on the 2 first module 
@retval 12: When the current source is used, the configuration of the channel must be Sinlge-Ended and AC
@retval 13: The module is already initialised by another process
@retval 14: Initialisation Error 
*/

typedef struct 
{
	uint8_t pb_SingleDiffMode[2]; /**< Single-Ended / Differential mode of each channel [0] : Left [1] : Right  - 0 : Single-Ended 1 : Differential */
	uint8_t pb_Coupling[2]; /**< Coupling mode of each channel [0] : Left [1] : Right channel - 0 : DC 1 : AC */
	uint8_t pb_EnableCurrentSource[2]; /**< Enable/Disable the current source [0] : Left channel [1] : Right channel - 0 : Disable 1 : Enable - Available for analog input module 0 and 1. */
	uint8_t pb_GainSelection[2]; /**< Gain selection [0] : Left [1] : Right - 0 : Gain 1 , 1 : Gain 10 */
	uint8_t b_SamplingClockSelection; /**< Clock selection for the analog input module - 0 : Sampling Clock 1 , 1 : Sampling Clock 2 */
	uint8_t b_SpeedMode; /**< ADC Speed mode selection - 0 : Single speed mode (2KHz - 50KHz), 1 : Double speed mode (50KHz - 100KHz), 2 : Quadruple speed mode (100KHz - 200KHz) */
} str_InitAnalogInputModuleArg_t;
#define CMD_APCI3600_InitAnalogInputModule									_IOW(APCI3600_MAGIC, 1, str_InitAnalogInputModuleArg_t *)

//-------------------------------------------------------------------------------------------------------------------
typedef struct
{
 		/*  Define the mode used
		0: AUTO-STOP Mode In this mode, the On board buffer is filled with value.
		When the On board buffer is full, the acquisition is stopped and an interrupt occur.
		1 : RING Buffer Mode In this mode, the on board buffer is always filled with value.
		In both modes: Each time the number of the value in the buffer reach the dw_CompareValue, an interrupt occur to permit to the software to read the value from the buffer.*/
 		uint32_t dw_Mode;
 		uint32_t dw_OnBoardBufferSize; /**< Size (in nbr of bytes : 1024 * 2 dw_OnBoardBufferSize ) of the On-board buffer (in the on-board RAM) to used for the analogue input module. */
 		/**< Defines the number of acquisition to have in the on-board Buffer to generate an interrupt for start a DMA transfer.
		The compare value cannot be :
			- greater that the size of the on board buffer in Auto Stop mode                            
			- greater or equal that the size of the on board buffer in Ring Buffer mode                 
			- null                                                                                      
		*/
 		uint32_t dw_CompareValue;
 } str_InitAnalogInputModuleCyclicAcquisitionArg_t;
 
#define CMD_APCI3600_InitAnalogInputModuleCyclicAcquisition					_IOW(APCI3600_MAGIC, 2,str_InitAnalogInputModuleCyclicAcquisitionArg_t *)

//-------------------------------------------------------------------------------------------------------------------
/* no parameter */
#define CMD_APCI3600_StartAnalogInputModuleCyclicAcquisition				_IOW(APCI3600_MAGIC, 3,unsigned long)
//-------------------------------------------------------------------------------------------------------------------
/* no parameter */
#define CMD_APCI3600_ReleaseAnalogInputModuleCyclicAcquisition				_IOW(APCI3600_MAGIC, 4,unsigned long)
//-------------------------------------------------------------------------------------------------------------------
/* no parameter */
#define CMD_APCI3600_ReleaseAnalogInputModule								_IOW(APCI3600_MAGIC, 5,unsigned long)
//-------------------------------------------------------------------------------------------------------------------
/* no parameter */
#define CMD_APCI3600_StopAnalogInputModuleCyclicAcquisition					_IOW(APCI3600_MAGIC, 6,unsigned long)
//-------------------------------------------------------------------------------------------------------------------

typedef struct 
{
 uint8_t b_Status; /* status 0: not started 1: started */
 uint32_t dw_NbrOfValue; /* Number of value in the buffer in the on-board RAM for the module. */
	
} GetAnalogInputModuleCyclicAcquisitionStatus_t;

#define CMD_APCI3600_GetAnalogInputModuleCyclicAcquisitionStatus			_IOWR(APCI3600_MAGIC, 7,GetAnalogInputModuleCyclicAcquisitionStatus_t *)

//-------------------------------------------------------------------------------------------------------------------

/** Gets the status of the calibration of the analogue input module. 
 * 
 * @param[out] uint8_t Status of the calibration ( 1 : Calibration is running, 0 : End of the calibration : the module is ready)  
 * 
 */
#define CMD_APCI3600_GetAnalogInputModuleCalibrationStatus					_IOWR(APCI3600_MAGIC, 8, uint8_t*)

//-------------------------------------------------------------------------------------------------------------------
/* AnalogInput_EnableDisableDigitalInputExternalTrigger */

/** Enables/disables the digital input external trigger (digital input 0) for the analogue input module  */
 
/**< parameter: 0 : Disable 1 : Enable */
 
#define CMD_APCI3600_AnalogInput_EnableDisableDigitalInputExternalTrigger 	_IOW(APCI3600_MAGIC, 9, unsigned long)

//-------------------------------------------------------------------------------------------------------------------
/* Digital Input Master Trigger */

/** Enables/disables the digital input external trigger (digital input 0) for the analogue input module.  */

/**< parameter: action: 0 : Disable 1 : Enable */ 
#define CMD_APCI3600_AnalogInput_EnableDisableMasterTrigger 	_IOW(APCI3600_MAGIC, 10, unsigned long)

#define __APCI3600_ANALOG_INPUT_UPPER_IOCTL_CMD 10

#endif /*APCI3600ANALOGINPUT_H_*/
