#ifndef __SENSOR_PRV_H__
#define __SENSOR_PRV_H__
/**HEADER********************************************************************
* 
* Copyright (c) 2010 Avnet Japan Co.,Ltd (NIKE Borad Project.)
* All Rights Reserved
*
*************************************************************************** 
*
* $FileName: sensor_prv.h$
* $Version : 0.1.0.0$
* $Date    : Jan-29-2010$
*
* Comments:
*
*   The file contains functions prototype, defines, structure 
*   definitions private to the fdv Ramdisk drivers
*
*END************************************************************************/

/*----------------------------------------------------------------------*/
/*
**                          CONSTANT DEFINITIONS
*/

#ifdef __cplusplus
extern "C" {
#endif

typedef struct sensor_adc_generic {
   uint_16            resolution;
   uint_32            adc_frq;               /* frequency of ADC hardware, usually 1 / Tad */
   SENSOR_ADC_TRIGGER_MASK   triggers_fire;  /* specifies triggers, which were set and there is still attached channel that did not complete conversion */
   _mqx_int           run;                   /* specifies if ADC is running (this is OR operation of all channel's ADC_CHANNEL_RUNNING flag) */
   
} SENSOR_ADC_GENERIC, _PTR_ SENSOR_ADC_GENERIC_PTR;

#define SENSOR_ADC_CHANNEL_RUNNING          (0x01) /* when ADC channel is running, this flag is set */
#define SENSOR_ADC_CHANNEL_RESUMED          (0x02) /* when ADC channel is not paused, this flag is set */

typedef struct sensor_adc_channel_generic {
   _mqx_uint number;    /* number of channel */
   uint_16               source;            /* source copied from initialization structure */
   uint_16               init_flags;        /* flags copied from initialization structure */
   uint_16               runtime_flags;     /* generic flags for ADC driver */
   uint_32               range;             /* output range */
   int_32                offset;            /* offset of time, counter: first this needs to be decremented to zero to start conversion process */
   _mqx_uint             period;            /* time period between 2 samples taken */
   _mqx_uint             time;              /* time to next ADC */
   int_32                samples;           /* samples, counter: this needs to be decremented to zero to invoke any event */
   int_32                samples_preset;    /* constant: specifies predefined number of samples */
   SENSOR_ADC_TRIGGER_MASK      trigger;           /* trigger, that triggers this ADC channel */
   SENSOR_ADC_RESULT_STRUCT_PTR buffer_start;      /* circular result buffer start pointer */
   SENSOR_ADC_RESULT_STRUCT_PTR buffer_end;        /* circular result buffer end pointer */
   SENSOR_ADC_RESULT_STRUCT_PTR buffer_task;       /* circular result buffer - next read pointer for result */
   SENSOR_ADC_RESULT_STRUCT_PTR buffer_driver;     /* circular result buffer - next write pointer for result */
#if MQX_USE_LWEVENTS
   LWEVENT_STRUCT_PTR    complete_event;    /* pointer to event, triggered after counter_samples reaches zero */
#endif
} SENSOR_ADC_CHANNEL_GENERIC, _PTR_ SENSOR_ADC_CHANNEL_GENERIC_PTR;

typedef uint_32 SENSOR_ADC_HW_CHANNEL_MASK;

/*
typedef struct adc_trigger_generic_config {
   uint_32            
} ADC_TRIGGER_GENERIC_CONFIG, _PTR_ ADC_TRIGGER_GENERIC_CONFIG_PTR;
*/


_mqx_int _sensor_open(FILE_PTR, char_ptr, char_ptr);
_mqx_int _sensor_close(FILE_PTR);
_mqx_int _sensor_read (FILE_PTR, char_ptr, _mqx_int);
_mqx_int _sensor_write(FILE_PTR, char_ptr, _mqx_int);
_mqx_int _sensor_ioctl(FILE_PTR, _mqx_uint, pointer);

void _sensor_adc_conv_end(uint_32 *results_buf, SENSOR_ADC_HW_CHANNEL_MASK mask);
void _sensor_adc_scheduler(_mqx_uint time);
void _sensor_intterrupt_adc_scheduler(_mqx_uint time);


#if PSP_MQX_CPU_IS_MCF5222X || PSP_MQX_CPU_IS_MCF5223X || PSP_MQX_CPU_IS_MCF5225X
//#if MQX_CPU == 5225 || MQX_CPU == 5223 || MQX_CPU == 5222
  #include "sensor_mcf522xx_prv.h"
//#elif MQX_CPU == 51128
  //#include "adc_mcf51xx_prv.h"
#else
  #error sensor ADC device driver not supported for processor.
#endif

#ifdef __cplusplus
}
#endif

#endif /* __SENSOR_PRV_H__ */

/* EOF */
