/****************************************************************************/
/* 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 LPC210x SPI controlle				*/
/*	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~				*/
/*																			*/
/*	2011 Jan	ZK		Generated from the LPC23xx version					*/
/*																			*/
/****************************************************************************/

#ifndef _LPC210x_SPI
#define _LPC210x_SPI

/*
*	LPC2378 SPI controller registers
*/

struct lpc210x_spi {

	unsigned	spcr;				// SPI control regsiter
	unsigned	spsr;				// SPI status register
	unsigned	spdr;				// SPI data register
	unsigned	spccr;				// SPI clock counter register
	unsigned	sptcr;				// SPI test control register
	unsigned	sptsr;				// SPI test status register
	unsigned	_;
	unsigned	spint;				// SPI interrupt flag
};

/*
*	Definitions for the control register
*/

#define	SPI_SPCR_BITE		0x004	// Word length enable (8 bits if 0)
#define	SPI_SPCR_CPHA		0x008	// Clock phase
#define	SPI_SPCR_CPOL		0x010	// Clock polarity
#define	SPI_SPCR_MSTR		0x020	// SPI is in master mode
#define	SPI_SPCR_LSBF		0x040	// Data is transferred LSB first
#define	SPI_SPCR_SPIE		0x080	// SPI interrupt enable
#define	SPI_SPCR_BITS		0xf00	// Bits per word mask
#define	SPI_SPCR_BITS_16	0x000	// Word length is 16 bits
#define	SPI_SPCR_BITS_15	0xf00	// Word length is 15 bits
#define	SPI_SPCR_BITS_14	0xe00	// Word length is 14 bits
#define	SPI_SPCR_BITS_13	0xd00	// Word length is 13 bits
#define	SPI_SPCR_BITS_12	0xc00	// Word length is 12 bits
#define	SPI_SPCR_BITS_11	0xb00	// Word length is 11 bits
#define	SPI_SPCR_BITS_10	0xa00	// Word length is 10 bits
#define	SPI_SPCR_BITS_9		0x900	// Word length is  9 bits
#define	SPI_SPCR_BITS_8		0x800	// Word length is  8 bits

/*
*	Definitions for the status register
*/

#define	SPI_SPSR_ABRT		0x08	// Slave abort error
#define	SPI_SPSR_MODF		0x10	// Mode fault error
#define	SPI_SPSR_ROVR		0x20	// Read overrun error
#define	SPI_SPSR_WCOL		0x40	// Write collision error
#define	SPI_SPSR_SPIF		0x80	// SPI transfer finished

/*
*	Definitions for interrupt flag register
*/

#define	SPI_SPINT_SPIF		0x01	// SPI interrupt is pending

/*
*	SPI instance
*/

static volatile struct lpc210x_spi * const lpc_spi = (void *) 0xe0020000;

#endif

