/*-------------------------------------------------------------------------*/
/*!
 * \file	test.c
 * \brief	This sample code demonstrates how to map hardware registers.
 */
/* © Copyright 2005, Logic Product Development, Inc. All Rights Reserved.
 */
/*-------------------------------------------------------------------------*/
#include <windows.h>
#include <ceddk.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	volatile unsigned short *cpld_spi_data_reg;
	PHYSICAL_ADDRESS phy_addr;

	/* Place the physical address of the register in the low part. */
	phy_addr.LowPart  = 0x70600000;
	phy_addr.HighPart = 0;

	/* Call the CEDDK MmMapIoSpace function to retrieve a virtual address */
	cpld_spi_data_reg = (volatile unsigned short *)MmMapIoSpace(phy_addr, sizeof(*cpld_spi_data_reg), FALSE);

	/* verify that the physical address was successfully mapped to a virtual address */
	if(NULL == cpld_spi_data_reg)
	{
		RETAILMSG(1,(TEXT("Error, couldn't map cpld_spi_data_reg.\r\n")));
	}
	else
	{
		RETAILMSG(1,(TEXT("Mapped cpld_spi_data_reg at 0x%x to 0x%x.\r\n"), phy_addr.LowPart, cpld_spi_data_reg));
	}

	/* Unmap the virtual address when it is no longer needed */
	if(NULL != cpld_spi_data_reg)
	{
		MmUnmapIoSpace((void*)cpld_spi_data_reg, sizeof(*cpld_spi_data_reg));
	}

	return 0;

} /* end WinMain() */


/* end file test.cpp */
