/*
 *
 *     Module Name: start.c
 *	       Version: 1.00
 *   Original Date: 08/23/99	
 *	        Author: Charles Gordon
 *	      Language: Ansi C
 * Compile Options:
 * Compile defines:
 *	     Libraries:
 *    Link Options:
 *
 *    Entry Points: tx_application_define()
 *
 *  Copyrighted (c) by NETsilicon, Inc.  All Rights Reserved.
 *
 * Description.
 * =======================================================================
 *  tx_application_define() is called just before the ThreadX kernel loads.
 *  It is responsible for creating at least one thread to drive the application.
 *  We create a thread that starts up NET+OS.
 *
 *
 *
 * Edit Date/Ver   Edit Description
 * ==============  =======================================================
 *
 *
 */


#include <tx_api.h>
#include <hservapi.h>
#include <sysAccess.h>
#include <ace_params.h>
#include <boardParams.h>




/*
 * Set this to 1 to run the system POST tests during startup.
 */
const int APP_POST = 0;



/*
 * Set this to 1 to run the manufacturing burn in tests.
 */
int APP_BURN_IN_TEST = 0; 


extern void	printMACAddress(char * M);



// extern devBoardParamsType defaultParams; 


/*
 *
 *  Function: void applicationStart (void)
 *
 *  Description:
 *
 *      This routine is responsible for starting the user application.  It should 
 *      create any threads or other resources the application needs.
 *
 *      ThreadX, the NET+OS device drivers, and the TCP/IP stack will be running
 *      when this function is called.
 *
 *  Parameters:
 *
 *      none
 *
 *  Return Values:
 *
 *      none
 *
 */

void applicationStart (void)

{
	void AppSearchURL (unsigned long, char*);
	void AppPreprocessURL (unsigned long, char*);

	int         result = -1;
	char 		MACAddr[16];
	unsigned long	ip_address, gateway, subnet_mask;

//	aceTest();

	/*
	 * Register the URL search and preprocess functions and start the 
	 * HTTP server
	 */

	printf ("Begin the NAHTTP Server application - with ACE demo mods\n");

	/*  Add Username Netsilicon password sysadm to the System Access Database   */
	NAsetSysAccess (NASYSACC_ADD, "Netsilicon", "sysadm", NASYSACC_LEVEL_HTTP_R1, 0);

	HSRegisterSearchFunction(AppSearchURL, AppPreprocessURL);

	HSStartServer();

	customizeGetMACAddress((BYTE *) &MACAddr[0]);
	customizeGetIPParameters(&ip_address, &subnet_mask, &gateway);
	printf("static IP info: IP = %x gateway = %x mask = %x\n",ip_address, gateway, subnet_mask);
//	printMACAddress(&MACAddr[0]);
	NAWait(1000);

	tx_thread_suspend(tx_thread_identify());


}

/*
 *
 *  Function: void applicationTcpDown (void)
 *
 *  Description:
 *
 *      This routine will be called by the NET+OS root thread once every 
 *      clock tick while it is waiting for the TCP/IP stack to come up.  
 *      This function can increment a counter everytime it's called to 
 *      keep track of how long we've been waiting for the stack to start.
 *      If we've been waiting too long, then this function can do something
 *      to handle the error.  
 *
 *      This function will not be called once the stack has started.
 *
 *  Parameters:
 *
 *      none
 *
 *  Return Values:
 *
 *      none
 *
 */

void applicationTcpDown (void)

{
	static int ticksPassed = 0;

	ticksPassed++;
	/*
	 * Code to handle error condition if the stack doesn't come up goes here.
	 */
}


