/****************************************************************************/
/* Copyright 2010, © Bendor Research Pty. Ltd. All rights reserved.			*/
/* Permission is granted to use this software for any purpose whatsoever	*/
/* as long as this copyright notice is preserved. The code is provided		*/
/* "as is", with no explicit, implicit or implied warranty or guarantee		*/
/* of any kind and Bendor Research Pty. Ltd. can not be held liable for		*/
/* any loss or damages arising out of the use of this software.				*/
/****************************************************************************/
/*																			*/
/*	Include file describing the Philips LPC23xx parallel I/O system			*/
/*	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~			*/
/*																			*/
/*	2010 Mar	ZK		Original											*/
/*	2010 May	ZK		Modified to match NXP's names						*/
/*																			*/
/****************************************************************************/

#ifndef _LPC23XX_PIO
#define _LPC23XX_PIO

/*
*	Legacy access to port 0 and port 1 pins
*/

struct pio_apb {

	unsigned pin;					// Pin status / state
	unsigned set;					// Set pins to 1
	unsigned dir;					// Pin direction (1:out)
	unsigned clr;					// Clear pins to 0

};

/*
*	Interrupt control for port 0 and port 2
*/

struct pio_int {

	unsigned statr;					// Rising edge status bits
	unsigned statf;					// Falling edge status bits
	unsigned clr;					// Interrupt clear
	unsigned enr;					// Rising edge interrupt enables
	unsigned enf;					// Falling edge interrupt enables
};

/*
*	Fast port access to all ports
*/

struct pio_ahb {

	unsigned dir;					// Pin direction (1:out)
	unsigned _[3];
	unsigned mask;					// Pin/set/clr mask
	unsigned pin;					// Pin status and state control
	unsigned set;					// Set pins to 1
	unsigned clr;					// Clear pins to 0
};

/*
*	APB access to ports
*/

struct lpc23xx_pio {

	struct pio_apb	 p[ 2 ];			// Port 0/1 control registers
	unsigned 		_1[24];
	unsigned 		int_stat;			// Interrupt status
	struct pio_int	 int0;				// Interrupt control 0
	unsigned 		_2[3];
	struct pio_int	 int2;				// Interrupt control 2
};

/*
*	AHB access to ports
*/

struct	lpc23xx_fio {

	struct pio_ahb	p[ 5 ];				// Port control	registers
};

/*
*	Definitions for the interrupt status register
*/

#define	PIO_INT_STAT_P0		0x01	// Interrupt is pending on port 0
#define	PIO_INT_STAT_P2		0x04	// Interrupt is pending on port 2

/*
*	Parallel port instances
*/

static volatile struct lpc23xx_pio * const lpc_pio = (void *) 0xe0028000;
static volatile struct lpc23xx_fio * const lpc_fio = (void *) 0x3fffc000;

#endif

