// McStar.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "MapIO.hpp"
#include "gpio.h"
#include "ssp.h"
#include "McStar.h"
#include "clk.h"
#include <windows.h>
#include "resource.h"

#define LOOP_COUNTER	0x3ffff

volatile GPIO_REGS		*GpioRegPtr = NULL;
volatile GPDR3_REG		*GPDR3RegPtr = NULL;
volatile GPSR3_REG		*GPSR3RegPtr = NULL;
volatile GPCR3_REG		*GPCR3RegPtr = NULL;
volatile SSP_REGS		*SspRegPtr  = NULL;
volatile CLKMAN_REGS	*v_pClkRegs	= NULL;

int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
	int				testInt;
	unsigned char	Hello[]="ADS NSSP",
					testChar;
	unsigned int	uiValue;

	CFGDATA			configData;

	printf("Hit any key to continue ");
	testInt = 0;
	while( scanf("%c", &testChar) == 0)
		testInt = scanf("%c", &testChar);

	RETAILMSG (1,(TEXT("\r\n* NSSPTest.exe: Sends a test message out the NSSP port.\r\n")));
	RETAILMSG (TRUE, (L"  720020-11693 built %s %s\r\n",TEXT(__DATE__),TEXT(__TIME__))); 

	ReadConfig( configData );
	InitRegisters();
	ToggleGPIO();
//	GetData( configData.numSamples, configData.sampleRate);
	WriteToDisk();

	// Try sending a message on SSP port
	while(1==1)
	{
		RETAILMSG(1,(TEXT("Data received: ")));
		RETAILMSG(1,(TEXT("Waiting for SSP Message\n")));
		SendSSPMessage(Hello,sizeof(Hello));
		uiValue = dwReadSSP();
		RETAILMSG(1,(TEXT("%08x"), uiValue));
		Sleep(1000);
	}

	VirtualFree((PVOID)v_pClkRegs,0,MEM_RELEASE);
	VirtualFree((PVOID)SspRegPtr,0,MEM_RELEASE);
	VirtualFree((PVOID)GpioRegPtr,0,MEM_RELEASE);

	RETAILMSG(1,(L" NSSP: Done \r\n"));

	GoToSleep( configData.sleepPeriod );

	return 0;
}

