// 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\nExperimental firmware starting!\r\n\r\n");	
	
	printf("- Starting Flash initialization -\r\n");
	Flash.Init();
	printf("- Flash initialization done -\r\n");
	
	printf("- Starting hardware initialization -\r\n");
	HW_Device.Init();
	printf("- Hardware initialization done -\r\n");
	
	printf("- Starting display initialization -\r\n");
	Screen.Init();
	printf("- Display initialization done -\r\n");
	
	printf("Ready - press h for help\r\n");
	
	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.DRAWSIGNALS(1);	
	  HW_Device.TransferPlanes();
	  Flash.Write_Config_Flash();
	}
	
	return 0;									// Exit
}

