                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                #include "stdafx.h"
#ifdef PCSIM
	#include <windows.h>
#else
	#include <targets/LPC2000.h>
	#include <targets/liblpc2000.h>
	#include <ctl_api.h>
#endif



#include "GLCD.h"
#include "OS.h"
#include "PhysicalLayer.h"
#include "Applications.h"
#include "extra.h"
#include "lBuffer.h"
#include "Drivers.h"
#include "GRAPHICS.h"
#include "GR_commons.h"

int num = 0;





void BootCallback(void)
{
  //SendSerialData(OS_SERIAL,(unsigned char*)"data");
  WifiSendCommand((unsigned char*)"+++");
  return;
}

#ifdef PCSIM
	DWORD WINAPI main(LPVOID lpArg)
#else
	int main(void)
#endif
{
#ifdef PCSIM
	lpArg = lpArg;
#endif
	

#ifdef PCSIM
	initPHY();
#else
	InitDisp();
        
    ctl_start_timer(Scheduler);
    ctl_board_on_button_pressed(BootCallback);
    ctl_enable_touch_irq(ReadTouch);
    InitTouch();
    ctl_global_interrupts_enable();
    InitLeds();
    UART0Initialize(1500000);
    UART3Initialize(baudRates[baudIndex],1,SERIAL_PARITY_NONE);
        
#endif
	adcInit();
    BacklightInit();
    BacklightRequest();  
	LCD_printf((unsigned char*)"Starting...\r");
	initTasks();
	initTimers();
	TimerCreate(&AppClock,CLOCK,1000,PERIODICALY,ACTIVE);
#ifndef PCSIM
    TimerCreate(&DrvTouchScreen,TOUCH_PANEL,5,PERIODICALY,ACTIVE);
    CRSR_init();
    TimerCreate(&updateBattery,BATTERY,5000,PERIODICALY,ACTIVE);
#endif

	TimerCreate(&Backlight,BACKLIGHT,20,PERIODICALY,ACTIVE);
	TimerCreate(&StartUpDriver,DRV_START_UP,10,PERIODICALY,ACTIVE);
	TaskCreate(&AppKeyboard,KEYBOARD,LEAST,RUNNING,RUN_FOREVER,&KBMsgBox);
	TaskCreate(&AppMainMenu,MAIN_MENU,LEAST,RUNNING,RUN_FOREVER,&MMMsgBox);
	TaskCreate(&AppStatusBar,STATUS_BAR,NORMAL,RUNNING,RUN_FOREVER,&SBMsgBox);
	TaskCreate(&AppConsole, CONSOLE,LEAST,RUNNING,RUN_FOREVER,&CMsgBox);
	TaskCreate(&AppDialog, DIALOG,LEAST,RUNNING,RUN_FOREVER,&DWMsgBox);
	TaskCreate(&AppSpecials, SPECIALS,LEAST,RUNNING,RUN_FOREVER,&SPMsgBox);
	TaskCreate(&AppNetSetup, NET_SETUP,LEAST,RUNNING,RUN_FOREVER,&NSMsgBox);
	TaskCreate(&AppNetworkNames, NETWORK_NAMES,LEAST,RUNNING,RUN_FOREVER,&NNMsgBox);
	TaskCreate(&AppConnector, CONNECTOR,LEAST,RUNNING,RUN_FOREVER,&CNMsgBox);
	TaskCreate(&AppDesktop, DESKTOP,LEAST,RUNNING,RUN_FOREVER,&DMsgBox);
	TaskCreate(&AppAbout, ABOUT,LEAST,RUNNING,RUN_FOREVER,&AMsgBox);
	TaskCreate(&AppTimeSetup, TIME_SETUP,LEAST,RUNNING,RUN_FOREVER,&TSMsgBox);
	TaskCreate(&AppSerialSetup, SERIAL_SETUP,LEAST,RUNNING,RUN_FOREVER,&SSMsgBox);
	TaskCreate(&AppBacklightSetup,BACKLIGHT_SETUP,LEAST,RUNNING,RUN_FOREVER,&BSMsgBox);
	TaskCreate(&DrvWifi, DRV_WIFI,LEAST,RUNNING,RUN_FOREVER,0);
	TaskCreate(&DrvSerial, DRV_SERIAL,LEAST,RUNNING,RUN_FOREVER,0);
	RunOS();

	}	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      