#ifndef __EXTERNAL_IO_REGISTERS_H__
#define __EXTERNAL_IO_REGISTERS_H__

#include <stdint.h>
#include "platform.h"
#include "register_bitops.h"

namespace EXTERNAL_IO
{
	static const uint32_t BaseAddress = (KS8695PX_IO_BASE + KS8695PX_EXTERNAL_IO_OFFSET);
	
	enum Registers
	{
		EXTACON0	= 0x0000,		// 0x00	- External IO Access Control Register 0(rw)
		EXTACON1	= 0x0004,		// 0x04 - External IO Access Control Register 1(rw)
		EXTACON2	= 0x0008,		// 0x08 - External IO Access Control Register 2(rw)
		ROMCON0		= 0x0010,		// 0x10 - ROM/SRAM/Flash Control Register 0(rw)
		ROMCON1		= 0x0014,		// 0x14 - ROM/SRAM/Flash Control Register 1(rw)		
		ERGCON		= 0x0020,		// 0x20 - External IO General Control Register(rw)
		SDCON0		= 0x0030,		// 0x30 - SDRAM Control Register 0(rw)		
		SDCON1		= 0x0034,		// 0x34 - SDRAM Control Register 1(rw)	
		SDGCON		= 0x0038,		// 0x38 - SDRAM General Control Register(rw)	
		SDBCON		= 0x003C,		// 0x38 - SDRAM Buffer Control Register(rw)			
		REFTIM		= 0x0040		// 0x40 - SDRAM Refersh Timer Register(rw)
	};
	
	enum EXTACON_BITS
	{
		LAST_ADDRESS					= REGISTER_BIT_DEFINITION(31, 22),
		BASE_ADDRESS					= REGISTER_BIT_DEFINITION(21, 12),
		TIME_OE_OR_WE_IS_ASSERTED		= REGISTER_BIT_DEFINITION(11,  9),	
		CS_HOLD_TIME_AFTER_OE_OR_WE		= REGISTER_BIT_DEFINITION( 8,  6),		
		ADDRESS_SETUP_TIME_BEFORE_CS	= REGISTER_BIT_DEFINITION( 5,  3),
		CS_SETUP_TIME_BEFORE_OE_OR_WE	= REGISTER_BIT_DEFINITION( 2,  0)				
	};
	
	enum ERGCON_BITS
	{
		BUS_CLOCK_MULTIPLIER			= REGISTER_BIT_DEFINITION(29, 28),
		BUS_WIDTH_FOR_EXTERNAL_BANK_2	= REGISTER_BIT_DEFINITION(21, 20),
		BUS_WIDTH_FOR_EXTERNAL_BANK_1	= REGISTER_BIT_DEFINITION(19, 18),		
		BUS_WIDTH_FOR_EXTERNAL_BANK_0	= REGISTER_BIT_DEFINITION(17, 16),
		BUS_WIDTH_FOR_FLASH_BANK_1		= REGISTER_BIT_DEFINITION( 3,  2),
		BUS_WIDTH_FOR_FLASH_BANK_0		= REGISTER_BIT_DEFINITION( 1,  0)				
	};
	
	inline volatile uint32_t *regAddress(Registers reg)
	{
	    return reinterpret_cast<volatile uint32_t*>(BaseAddress + reg);
	}
	
	inline uint32_t regRead(Registers reg)
	{
	    return *regAddress(reg);
	}
	
	inline void regWrite(Registers reg, uint32_t value)
	{
	    *regAddress(reg) = value;
	}

}

#endif // __EXTERNAL_IO_REGISTERS_H__

