Esempio n. 1
0
///////////////////////////////////////////////////////////////////////////////
// Main entry point.
//
void main(void)
{
    static TICK8 t = 0;
    BYTE i;
    char strBuf[10];

    // Initialize any application specific hardware.
    InitializeBoard();

    // Initialize all stack related components.
    // Following steps must be performed for all applications using
    // PICmicro TCP/IP Stack.
    TickInit();

    // Initialize file system.
    fsysInit();

    // Intialize HTTP Execution unit
    htpexecInit();

    // Initialze serial port
    serInit();
    
    // Initialize Stack and application related NV variables.
    appcfgInit();
    appcfgUSART();        	// Configure the USART

#ifdef SER_USE_INTERRUPT    // Interrupt enabled serial ports have to be enabled
    serEnable();
#endif

    appcfgCpuIO();          // Configure the CPU's I/O port pin directions - input or output
    appcfgCpuIOValues();    // Configure the CPU's I/O port pin default values
    appcfgADC();            // Configure ADC unit
	appcfgPWM();			// Configure PWM unit
	
    // Serial configuration menu - display it for configured time and 
    // allow user to enter configuration menu
    scfInit( appcfgGetc( APPCFG_STARTUP_SER_DLY ) );

    StackInit();

#if defined(STACK_USE_HTTP_SERVER)
    HTTPInit();
#endif


#if defined( STACK_USE_DHCP ) || defined( STACK_USE_IP_GLEANING )
    // If DHCP is NOT enabled
    if ( ( appcfgGetc( APPCFG_NETFLAGS ) & APPCFG_NETFLAGS_DHCP ) == 0 ) {
		// Force IP address display update.
        myDHCPBindCount = 1;
        
#if defined( STACK_USE_DHCP )
        DHCPDisable();
#endif
    }
#endif

#if ( DEBUG_MAIN >= LOG_DEBUG )
        debugPutMsg(1); //@mxd:1:Starting main loop
#endif

	// Init VSCP functionality
	vscp_init();

	bInitialized = FALSE;	// Not initialized
    
#if defined(STACK_USE_NTP_SERVER)    
    // Initialize time 
    hour = 0;
	minute = 0;
	second = 0;
#endif	
	
	appcfgPutc( VSCP_DM_MATRIX_BASE, 0x00 );
 	appcfgPutc( VSCP_DM_MATRIX_BASE+1, 0x00 );
 	appcfgPutc( VSCP_DM_MATRIX_BASE+2, 0x00 );
 	appcfgPutc( VSCP_DM_MATRIX_BASE+3, 0x00 );
    
    
	//
    // Once all items are initialized, go into infinite loop and let
    // stack items execute their tasks.
    // If application needs to perform its own task, it should be
    // done at the end of while loop.
    // Note that this is a "co-operative mult-tasking" mechanism
    // where every task performs its tasks (whether all in one shot
    // or part of it) and returns so that other tasks can do their
    // job.
    // If a task needs very long time to do its job, it must broken
    // down into smaller pieces so that other tasks can have CPU time.
    //
    while ( 1 ) {
	    
	    // Used for initial delay to give stack and chip some time to
	    // initialize. If not used messages sent during this time will 
	    // fail.
        if  ( TickGet() > ( 5 * TICK_SECOND ) ) {
        	bInitialized = TRUE;
        }
	    
	    // We should do the ftp download every three hours
        //if ( TickGetDiff( TickGet(), loadTime ) >= ( 3 * 3600 * TICK_SECOND ) ) {
	    //	loadTime = TickGet();
	    //	bftpLoadWork = TRUE;
	    //}
	    
        // Blink SYSTEM LED every second.
        if ( appcfgGetc( APPCFG_SYSFLAGS ) & APPCFG_SYSFLAGS_BLINKB6 ) {
            if ( TickGetDiff8bit( t ) >= ((TICK8)( TICKS_PER_SECOND / 2 ) ) ) {
                t = TickGet8bit();
                TRISB_RB6 = 0;
                LATB6 ^= 1;
            }
        }

        // This task performs normal stack task including checking for incoming packet,
        // type of packet and calling appropriate stack entity to process it.
        StackTask();

#if defined(STACK_USE_HTTP_SERVER)
        // This is a TCP application.  It listens to TCP port 80
        // with one or more sockets and responds to remote requests.
        HTTPServer();
#endif

#if defined(STACK_USE_FTP_SERVER)
        FTPServer();
#endif

        // Add your application speicifc tasks here.
        ProcessIO();
        
#if defined(VSCP_USE_TCP )        
        // VSCP Task
        if ( bInitialized ) {
        	vscp_tcp_task();
        }
#endif        
        
        if ( bInitialized ) {
        	vscp_main_task();
			process_can_message();
			if ( g_can_error )
			{
				send_can_error_message( g_can_error );
				g_can_error = 0;
			}
        }
        
#if defined(STACK_USE_NTP_SERVER)        
        if ( bInitialized ) {
        	//ntp_task();
        }	
#endif        

        // For DHCP information, display how many times we have renewed the IP
        // configuration since last reset.
        if ( DHCPBindCount != myDHCPBindCount ) {
#if (DEBUG_MAIN >= LOG_INFO)
        	debugPutMsg( 2 ); 		// @mxd:2:DHCP Bind Count = %D
            debugPutByteHex(DHCPBindCount);
#endif
            
            // Display new IP address
#if (DEBUG_MAIN >= LOG_INFO)
            debugPutMsg( 3 ); 	//@mxd:3:DHCP complete, IP = %D.%D.%D.%D
            debugPutByteHex( AppConfig.MyIPAddr.v[ 0 ] );
            debugPutByteHex( AppConfig.MyIPAddr.v[ 1 ] );
            debugPutByteHex( AppConfig.MyIPAddr.v[ 2 ] );
            debugPutByteHex( AppConfig.MyIPAddr.v[ 3 ] );
#endif
            myDHCPBindCount = DHCPBindCount;
        }
    }
}
Esempio n. 2
0
/*
 * Main entry point.
 */
void main(void)
{
    static TICK8 t = 0;
    static TICK8 tmr10ms = 0;
    
    //Initialize any application specific hardware.
    InitializeBoard();

    //Initialize all stack related components. Following steps must
    //be performed for all applications using PICmicro TCP/IP Stack.
    TickInit();

    //Initialize file system.
    fsysInit();

    //Intialize HTTP Execution unit
    htpexecInit();

    //Initialze serial port
    serInit();
    
    //Initialize Stack and application related NV variables.
    appcfgInit();
    appcfgUSART();              //Configure the USART
    #ifdef SER_USE_INTERRUPT    //Interrupt enabled serial ports have to be enabled
    serEnable();
    #endif
    appcfgCpuIO();          //Configure the CPU's I/O port pin directions - input or output
    appcfgCpuIOValues();    //Configure the CPU's I/O port pin default values
    appcfgADC();            //Configure ADC unit
    appcfgPWM();            //Configure PWM Channels

    //Serial configuration menu - display it for configured time and allow user to enter configuration menu
    scfInit(appcfgGetc(APPCFG_STARTUP_SER_DLY));
    
    //LCD Display Initialize
    lcdInit();

    StackInit();

#if defined(STACK_USE_HTTP_SERVER)
    HTTPInit();
#endif

#if defined(STACK_USE_FTP_SERVER)
    FTPInit();
#endif

    //Initializes "UDP Command Port" and "UDP Command Responce Port".
    cmdUdpInit();

#if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING)
    DHCPReset();    //Initialize DHCP module
    
    //If DHCP is NOT enabled
    if ((appcfgGetc(APPCFG_NETFLAGS) & APPCFG_NETFLAGS_DHCP) == 0)
    {
        //Force IP address display update.
        myDHCPBindCount = 1;
        
        #if defined(STACK_USE_DHCP)
        DHCPDisable();
        #endif
    }
#endif

    #if (DEBUG_MAIN >= LOG_DEBUG)
        debugPutMsg(1); //@mxd:1:Starting main loop
    #endif

    /*
     * Once all items are initialized, go into infinite loop and let
     * stack items execute their tasks.
     * If application needs to perform its own task, it should be
     * done at the end of while loop.
     * Note that this is a "co-operative mult-tasking" mechanism
     * where every task performs its tasks (whether all in one shot
     * or part of it) and returns so that other tasks can do their
     * job.
     * If a task needs very long time to do its job, it must broken
     * down into smaller pieces so that other tasks can have CPU time.
     */
    while(1)
    {
        //Clear timer 1 every cycle, can be used to measure events. Has a overflow of 65ms.
        //Get delay in this function with:
        // TMR1L | (TMR1H<<8)
        TMR1H = 0;  //First write to TMR1H buffer!
        TMR1L = 0;  //This write will also update TMR1H with value written above to buffer

        //Blink SYSTEM LED every second.
        if (appcfgGetc(APPCFG_SYSFLAGS) & APPCFG_SYSFLAGS_BLINKB6) {
            if ( TickGetDiff8bit(t) >= ((TICK8)TICKS_PER_SECOND / (TICK8)2) )
            {
                t = TickGet8bit();
                TRISB_RB6 = 0;
                LATB6 ^= 1;
            }
        }
        
        //Enter each 10ms
        if ( TickGetDiff8bit(tmr10ms) >= ((TICK8)TICKS_PER_SECOND / (TICK8)100) )
        {
            tmr10ms = TickGet8bit();
        }
        
        //This task performs normal stack task including checking for incoming packet,
        //type of packet and calling appropriate stack entity to process it.
        StackTask();
        
        //Process "UDP Command Port" and "UDP Command Responce Port"
        cmdProcess();

#if defined(STACK_USE_HTTP_SERVER)
        //This is a TCP application.  It listens to TCP port 80
        //with one or more sockets and responds to remote requests.
        HTTPServer();
#endif

#if defined(STACK_USE_FTP_SERVER)
        FTPServer();
#endif

#if defined(STACK_USE_ANNOUNCE)
        DiscoveryTask();
#endif

#if defined(STACK_USE_NBNS)
        NBNSTask();
#endif

        //Add your application speicifc tasks here.
        ProcessIO();

        //For DHCP information, display how many times we have renewed the IP
        //configuration since last reset.
        if ( DHCPBindCount != myDHCPBindCount )
        {
            #if (DEBUG_MAIN >= LOG_INFO)
                debugPutMsg(2); //@mxd:2:DHCP Bind Count = %D
                debugPutByteHex(DHCPBindCount);
            #endif
            
            //Display new IP address
            #if (DEBUG_MAIN >= LOG_INFO)
                debugPutMsg(3); //@mxd:3:DHCP complete, IP = %D.%D.%D.%D
                debugPutByteHex(AppConfig.MyIPAddr.v[0]);
                debugPutByteHex(AppConfig.MyIPAddr.v[1]);
                debugPutByteHex(AppConfig.MyIPAddr.v[2]);
                debugPutByteHex(AppConfig.MyIPAddr.v[3]);
            #endif
            myDHCPBindCount = DHCPBindCount;
            
            #if defined(STACK_USE_ANNOUNCE)
                AnnounceIP();
            #endif             
        }
    }
}
Esempio n. 3
0
/*
 * Main entry point.
 */
void main(void)
{
    static TICK8 t = 0;
    BYTE i;
    char strBuf[10];

    /*
     * Initialize any application specific hardware.
     */
    InitializeBoard();

    /*
     * Initialize all stack related components.
     * Following steps must be performed for all applications using
     * PICmicro TCP/IP Stack.
     */
    TickInit();

    /*
     * Initialize file system.
     */
    fsysInit();

    //Intialize HTTP Execution unit
    htpexecInit();

    //Initialze serial port
    serInit();
    
    /*
     * Initialize Stack and application related NV variables.
     */
    appcfgInit();
    appcfgUSART();              //Configure the USART
    #ifdef SER_USE_INTERRUPT    //Interrupt enabled serial ports have to be enabled
    serEnable();
    #endif
    appcfgCpuIO();          //Configure the CPU's I/O port pin directions - input or output
    appcfgCpuIOValues();    //Configure the CPU's I/O port pin default values
    appcfgADC();            //Configure ADC unit

    //Serial configuration menu - display it for configured time and allow user to enter configuration menu
    scfInit(appcfgGetc(APPCFG_STARTUP_SER_DLY));

    StackInit();

#if defined(STACK_USE_HTTP_SERVER)
    HTTPInit();
#endif

#if defined(STACK_USE_FTP_SERVER)
    FTPInit();
#endif


#if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING)
    //If DHCP is NOT enabled
    if ((appcfgGetc(APPCFG_NETFLAGS) & APPCFG_NETFLAGS_DHCP) == 0)
    {
        //Force IP address display update.
        myDHCPBindCount = 1;
        
        #if defined(STACK_USE_DHCP)
        DHCPDisable();
        #endif
    }
#endif

    #if (DEBUG_MAIN >= LOG_DEBUG)
        debugPutMsg(1); //@mxd:1:Starting main loop
    #endif

    
    /*
     * Once all items are initialized, go into infinite loop and let
     * stack items execute their tasks.
     * If application needs to perform its own task, it should be
     * done at the end of while loop.
     * Note that this is a "co-operative mult-tasking" mechanism
     * where every task performs its tasks (whether all in one shot
     * or part of it) and returns so that other tasks can do their
     * job.
     * If a task needs very long time to do its job, it must broken
     * down into smaller pieces so that other tasks can have CPU time.
     */
    while(1)
    {
        //Blink SYSTEM LED every second.
        if (appcfgGetc(APPCFG_SYSFLAGS) & APPCFG_SYSFLAGS_BLINKB6) {
            if ( TickGetDiff8bit(t) >= ((TICK8)(TICKS_PER_SECOND/2)) )
            {
                t = TickGet8bit();
                TRISB_RB6 = 0;
                LATB6 ^= 1;
            }
        }

        //This task performs normal stack task including checking for incoming packet,
        //type of packet and calling appropriate stack entity to process it.
        StackTask();

#if defined(STACK_USE_HTTP_SERVER)
        //This is a TCP application.  It listens to TCP port 80
        //with one or more sockets and responds to remote requests.
        HTTPServer();
#endif

#if defined(STACK_USE_FTP_SERVER)
        FTPServer();
#endif

        //Add your application speicifc tasks here.
        ProcessIO();

        //For DHCP information, display how many times we have renewed the IP
        //configuration since last reset.
        if ( DHCPBindCount != myDHCPBindCount )
        {
            #if (DEBUG_MAIN >= LOG_INFO)
                debugPutMsg(2); //@mxd:2:DHCP Bind Count = %D
                debugPutByteHex(DHCPBindCount);
            #endif
            
            //Display new IP address
            #if (DEBUG_MAIN >= LOG_INFO)
                debugPutMsg(3); //@mxd:3:DHCP complete, IP = %D.%D.%D.%D
                debugPutByteHex(AppConfig.MyIPAddr.v[0]);
                debugPutByteHex(AppConfig.MyIPAddr.v[1]);
                debugPutByteHex(AppConfig.MyIPAddr.v[2]);
                debugPutByteHex(AppConfig.MyIPAddr.v[3]);
            #endif
            myDHCPBindCount = DHCPBindCount;
        }
    }
}
Esempio n. 4
0
/*
 * Configure USART with AppConfig data
 */
void appcfgUSART(void) 
{
    WORD w;
    BYTE cfg;
    
    cfg = appcfgGetc(APPCFG_USART1_CFG);

#if defined(__18F452) || defined(_18F452) || defined(__18F458) || defined(_18F458)

    //USART is enabled
    if (cfg & APPCFG_USART_ENABLE) {
        //Initialize USART1 Control registers
        TXSTA = 0b00100100;     //High BRG speed
        RCSTA = 0b10010000;

        #if (CLOCK_FREQ == 20000000)
        //Get USART BAUD rate setting
        switch (appcfgGetc(APPCFG_USART1_BAUD))
        {
        case BAUD_2400:
            TXSTA = 0b00100000;     //Low BRG speed
            SPBRG = 129;    //0.13% Error
            break;
        case BAUD_4800:
            TXSTA = 0b00100000;     //Low BRG speed
            SPBRG = 64; //0.16% Error
            break;
        case BAUD_9600:
            SPBRG = 32; //1.36% Error
            break;
        case BAUD_19200:
            SPBRG = 64; //0.16% Error
            break;
        case BAUD_38400:
            SPBRG = 32; //1.3% Error
            break;
        case BAUD_57600:
            SPBRG = 21; //1.3% Error
            break;
        case BAUD_115200:
            SPBRG = 10; //1.3% Error
            break;
        default:
            SPBRG = 21; //1.3% Error
            break;
        }
        #else
        #error "appcfgUSART() does not support selected clock frequency"
        #endif

        serEnable();   //Enable serial port
    }
    //USART is disbled
    else {
        serDisable();  //Disable serial port
    }
#elif defined(__18F6621) || defined(_18F6621)       \
        || defined(__18F6527) || defined(_18F6527)  \
        || defined(__18F6627) || defined(_18F6627)  \
        || defined(__18F6680) || defined(_18F6680)

    //USART is enabled
    if (cfg & APPCFG_USART_ENABLE) {
        TXSTA_BRGH = 1;     //High baud rate mode
        
        //xxxx 1xxx - 16bit baud rate generator
        BAUDCON = 0b00001000;

        #if (CLOCK_FREQ == 40000000)
        //Get USART BAUD rate setting
        switch (appcfgGetc(APPCFG_USART1_BAUD))
        {
        case BAUD_300:
            w = 33332;
            break;
        case BAUD_1200:
            w = 8332;
            break;
        case BAUD_2400:
            w = 4165;
            break;
        case BAUD_4800:
            w = 2082;
            break;
        case BAUD_9600:
            w = 1040;
            break;
        case BAUD_19200:
            w = 520;
            break;
        case BAUD_38400:
            w = 259;
            break;
        case BAUD_57600:
            w = 172;
            break;
        case BAUD_115200:
            w = 86;
            break;
        default:
            w = 172;
            break;
        }

        SPBRG =  (BYTE)w;
        SPBRGH = (BYTE)(w >> 8);
        #else
        #error "appcfgUSART() does not support selected clock frequency"
        #endif
        
        serEnable();   //Enable serial port
    }