#ifndef __io_gpio_h__
#define __io_gpio_h__
/**HEADER********************************************************************
* 
* Copyright (c) 2008 Freescale Semiconductor;
* All Rights Reserved
*
*************************************************************************** 
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* $FileName: io_gpio.h$
* $Version : 3.5.37.0$
* $Date    : Jan-4-2010$
*
* Comments:
*
*   The file contains definitions used in user program and/or in other
*   kernel modules to access GPIO pins
*
*END************************************************************************/

#include "ioctl.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef uint_32 GPIO_PIN_STRUCT;
typedef void (* IRQ_FUNC)(pointer);

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


#define GPIO_IOCTL_ADD_PINS         _IO(IO_TYPE_GPIO,0x01)  /* Add pins to the file */
#define GPIO_IOCTL_WRITE_LOG1       _IO(IO_TYPE_GPIO,0x02)  /* Set pins on output port */
#define GPIO_IOCTL_WRITE_LOG0       _IO(IO_TYPE_GPIO,0x03)  /* Clear (set to 0) pins on output port */
#define GPIO_IOCTL_READ             _IO(IO_TYPE_GPIO,0x04)  /* Read data from input port */
#define GPIO_IOCTL_WRITE            _IO(IO_TYPE_GPIO,0x05)  /* Write data to output port */
#define GPIO_IOCTL_SET_IRQ_FUNCTION _IO(IO_TYPE_GPIO,0x06)  /* Set IRQ handler function */
#define GPIO_IOCTL_ENABLE_IRQ       _IO(IO_TYPE_GPIO,0x07)  /* Enable pins opened as IRQ in file */
#define GPIO_IOCTL_DISABLE_IRQ      _IO(IO_TYPE_GPIO,0x08)  /* Disable pins opened as IRQ in file */
#define GPIO_IOCTL_CPU_SPECIFIC     _IO(IO_TYPE_GPIO,0x09)  /* Next commands are specific for CPU */

#define GPIO_LIST_END           0x00000000
#define GPIO_PIN_VALID          0x80000000
#define GPIO_PIN_STATUS         0x40000000
#define GPIO_PIN_STATUS_0       0x00000000
#define GPIO_PIN_STATUS_1       0x40000000
#define GPIO_PIN_IRQ_RISING     0x20000000
#define GPIO_PIN_IRQ_FALLING    0x10000000
#define GPIO_PIN_ADDR           0x00FFFFFF

#define GPIO_PIN_IRQ    GPIO_PIN_IRQ_RISING //support of legacy IRQ pin definition

#define GPIO_PIN0   (0)
#define GPIO_PIN1   (1)
#define GPIO_PIN2   (2)
#define GPIO_PIN3   (3)
#define GPIO_PIN4   (4)
#define GPIO_PIN5   (5)
#define GPIO_PIN6   (6)
#define GPIO_PIN7   (7)
#define GPIO_PIN(x) (x)

/*----------------------------------------------------------------------*/
/*
**                          TYPE DEFINITIONS
*/

/*----------------------------------------------------------------------*/
/*
**                          FUNCTION PROTOTYPES
*/

extern _mqx_uint _io_gpio_install(char_ptr);
pointer _bsp_get_gpio_base_address(void);

/*----------------------------------------------------------------------*/
/*
**                          DEVICE-SPECIFIC DEFINITIONS
*/

#if MQX_CPU == PSP_CPU_MCF5282
  #include "io_gpio_mcf5235.h"
#elif PSP_MQX_CPU_IS_MCF5225X
  #include "io_gpio_mcf5225.h"
#elif PSP_MQX_CPU_IS_MCF5227X
  #include "io_gpio_mcf5227.h"
#elif PSP_MQX_CPU_IS_MCF51CN
  #include "io_gpio_mcf51cn.h"
#elif PSP_MQX_CPU_IS_MCF51EM
  #include "io_gpio_mcf51em.h"
#elif PSP_MQX_CPU_IS_MCF5222X
  #include "io_gpio_mcf5222.h"
#elif PSP_MQX_CPU_IS_MCF5223X
  #include "io_gpio_mcf5223.h"
#elif PSP_MQX_CPU_IS_MCF5441X
  #include "io_gpio_mcf5441.h"
#else
  #error IO_GPIO device driver not supported for processor.
#endif

#ifdef __cplusplus
}
#endif

#endif

/* EOF */
