// file: TomCat.cpp

#include <stdio.h>
//#include "nios.h" 

#include "tc_vars.h"
#include "hardware_t.h"
#include "flash_t.h"
#include "display_t.h"

int main(void)										// Main program
{
	Display Screen;
	Hardware HW_Device;
	AMDFlash Flash;
	
	
	//int irq_temp = 1;
	//int irq_temp_old = 1;
	//unsigned long main_loop_cnt = 0;
	
//	np_pio *out_test = na_test_out;	
//	out_test->np_pioedgecapture = 0x00; 						// clear all existing IRQ conditions
//	out_test->np_piodirection = 0x01;						// set all bits to output
//	out_test->np_piodata = 0x00;
//	out_test->np_piodata = 0x01;
//	out_test->np_piodata = 0x00;
	
	printf("\r\nbeta firmware starting!\r\n\r\n");	
	
	printf("- Flash initialization\r");
	Flash.Init();
	printf("- Flash initialization                  - done\r\n");
	
	printf("- Hardware initialization\r");
	HW_Device.Init();
	printf("- Hardware initialization               - done\r\n");
	
	printf("- Display initialization\r");
	Screen.Init();
	printf("- Display initialization                - done\r\n");
	
	printf("Ready - press h for help\r\n");

	HW_Device.Start_Record();		//start sampling
	
	
	while (0 == 0)
	{
		//irq_temp = HW_Device.Read_IRQ();
			
		//HW_Device.Reset_the_Watchdog();						// Reset the WatchDog
	
		HW_Device.Rotary_Interface();		
		HW_Device.Keyboard_Interface();
		HW_Device.Handle_ADC();
		Screen.ProcessSignalData();
		Screen.DrawSignals(1);	
		HW_Device.TransferPlanes();
		HW_Device.Transfer_USB_Data();
		Flash.Write_Config_Flash();
	}
	
	return 0;									// Exit
}

