/********************************************************************* * Function: void StackApplications(void) * * PreCondition: StackInit() is already called. * * Input: None * * Output: Calls all loaded application modules. * * Side Effects: None * * Note: This function must be called periodically to * ensure timely responses. * ********************************************************************/ void StackApplications(void) { #if defined(STACK_USE_HTTP2_SERVER) HTTPServer(); #endif #if defined(STACK_USE_FTP_SERVER) && defined(STACK_USE_MPFS2) FTPServer(); #endif #if defined(STACK_USE_SNMP_SERVER) SNMPTask(); #endif #if defined(STACK_USE_ANNOUNCE) DiscoveryTask(); #endif #if defined(STACK_USE_NBNS) NBNSTask(); #endif #if defined(STACK_USE_DHCP_SERVER) DHCPServerTask(); #endif #if defined(STACK_USE_DNS_SERVER) DNSServerTask(); #endif #if defined (STACK_USE_DYNAMICDNS_CLIENT) DDNSTask(); #endif #if defined(STACK_USE_TELNET_SERVER) TelnetTask(); #endif #if defined(STACK_USE_REBOOT_SERVER) RebootTask(); #endif #if defined(STACK_USE_SNTP_CLIENT) SNTPClient(); #endif #if defined(STACK_USE_UDP_PERFORMANCE_TEST) UDPPerformanceTask(); #endif #if defined(STACK_USE_TCP_PERFORMANCE_TEST) TCPPerformanceTask(); #endif #if defined(STACK_USE_SMTP_CLIENT) SMTPTask(); #endif #if defined(STACK_USE_UART2TCP_BRIDGE) UART2TCPBridgeTask(); #endif }
/********************************************************************* * Function: void StackApplications(void) * * PreCondition: StackInit() is already called. * * Input: None * * Output: Calls all loaded application modules. * * Side Effects: None * * Note: This function must be called periodically to * ensure timely responses. * ********************************************************************/ void StackApplications(void) { #if defined(STACK_USE_HTTP2_SERVER) HTTPServer(); #endif #if defined(STACK_USE_FTP_SERVER) && defined(STACK_USE_MPFS2) FTPServer(); #endif #if defined(STACK_USE_SNMP_SERVER) SNMPTask(); #endif #if defined(STACK_USE_ANNOUNCE) DiscoveryTask(); #endif #if defined(STACK_USE_NBNS) NBNSTask(); #endif #if defined(STACK_USE_DHCP_SERVER) DHCPServerTask(); #endif #if defined(STACK_USE_DNS_SERVER) DNSServerTask(); #endif #if defined (STACK_USE_DYNAMICDNS_CLIENT) DDNSTask(); #endif #if defined(STACK_USE_TELNET_SERVER) TelnetTask(); #endif #if defined(STACK_USE_REBOOT_SERVER) RebootTask(); #endif #if defined(STACK_USE_SNTP_CLIENT) SNTPClient(); #endif #if defined(STACK_USE_UDP_PERFORMANCE_TEST) UDPPerformanceTask(); #endif #if defined(STACK_USE_TCP_PERFORMANCE_TEST) TCPPerformanceTask(); #endif #if defined(STACK_USE_SMTP_CLIENT) SMTPTask(); #endif #if defined(STACK_USE_UART2TCP_BRIDGE) UART2TCPBridgeTask(); #endif #if defined(STACK_USE_CCS_SMTP) SMTPTask(); #endif #if defined(STACK_USE_CCS_SNTP_CLIENT) NTPTask(); #endif #if defined(STACK_USE_CCS_HTTP1_SERVER) || defined(STACK_USE_CCS_HTTP2_SERVER) HTTPServer(); #endif #if defined(STACK_USE_CCS_TFTP_SERVER) TFTPSTask(); #endif #if defined(STACK_USE_TWITTER) //should be renamed STACK_USE_CCS_TWITTER TwitterTask(); // processes TCP tasks including the Tweet tasks #endif }
/***************************************************************************** FUNCTION TCPIPTask Main function to handle the TCPIP stack RETURNS None PARAMS None *****************************************************************************/ void TCPIPTask() { WFConnection = WF_CUSTOM; ConnectionProfileID = 0; static DWORD dwLastIP = 0; WFStatus = NOT_CONNECTED; dwLastIP = 0; // Function pointers for the callback function of the TCP/IP and WiFi stack #if defined (FLYPORT) FP[1] = cWFConnect; FP[2] = cWFDisconnect; FP[3] = cWFScan; FP[5] = cWFPsPollDisable; FP[6] = cWFPsPollEnable; FP[7] = cWFScanList; FP[10] = cWFStopConnecting; #endif #if defined (FLYPORTETH) FP[1] = cETHRestart; #endif FP[16] = cTCPRxFlush; FP[17] = cTCPpRead; FP[18] = cTCPRemote; FP[19] = cTCPServerDetach; FP[20] = cTCPGenericOpen; FP[21] = cTCPRead; FP[22] = cTCPWrite; FP[23] = cTCPGenericClose; FP[24] = cTCPisConn; FP[25] = cTCPRxLen; #if defined(STACK_USE_SMTP_CLIENT) FP[26] = cSMTPStart; FP[27] = cSMTPSetServer; FP[28] = cSMTPSetMsg; FP[29] = cSMTPSend; FP[30] = cSMTPBusy; FP[31] = cSMTPStop; FP[32] = cSMTPReport; #endif FP[ARP_RESOLVE] = cARPResolveMAC; #if MAX_UDP_SOCKETS_FREERTOS>0 FP[35] = cUDPGenericOpen; FP[36] = cUDPWrite; FP[37] = cUDPGenericClose; #endif // Initialize stack-related hardware components that may be // required by the UART configuration routines // Initialization of tick only at the startup of the device if (hFlyTask == NULL) { TickInit(); } #if defined(STACK_USE_MPFS) || defined(STACK_USE_MPFS2) MPFSInit(); #endif // Initialize Stack and application related NV variables into AppConfig. InitAppConfig(); // Initialize core stack layers (MAC, ARP, TCP, UDP) and application modules (HTTP, SNMP, etc.) StackInit(); if (hFlyTask == NULL) { NETConf[0] = AppConfig; NETConf[1] = AppConfig; } #if defined(WF_CS_TRIS) if (WFStatus == CONNECTION_LOST) WF_Connect(WFConnection); #endif #if defined(STACK_USE_ZEROCONF_LINK_LOCAL) ZeroconfLLInitialize(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSInitialize(MY_DEFAULT_HOST_NAME); mDNSServiceRegister( (const char *) "DemoWebServer", // base name of the service "_http._tcp.local", // type of the service 80, // TCP or UDP port, at which this service is available ((const BYTE *)"path=/index.htm"), // TXT info 1, // auto rename the service when if needed NULL, // no callback function NULL // no application context ); mDNSMulticastFilterRegister(); #endif // INITIALIZING UDP #if MAX_UDP_SOCKETS_FREERTOS>0 #if defined (STACK_USE_UART) UARTWrite(1, "Initializing UDP...\r\n"); #endif UDPInit(); activeUdpSocket=0; while (activeUdpSocket < MAX_UDP_SOCKETS_FREERTOS) { tmp_len[activeUdpSocket]=0; if (activeUdpSocket == 0) { BUFFER_UDP_LEN[0] = BUFFER1_UDP_LEN; udpBuffer[activeUdpSocket] = udpBuffer1; udpSocket[0] = INVALID_UDP_SOCKET; } #if MAX_UDP_SOCKETS_FREERTOS>1 if (activeUdpSocket == 1) { BUFFER_UDP_LEN[1] = BUFFER2_UDP_LEN; udpBuffer[activeUdpSocket] = udpBuffer2; udpSocket[1] = INVALID_UDP_SOCKET; } #endif #if MAX_UDP_SOCKETS_FREERTOS>2 if (activeUdpSocket == 2) { BUFFER_UDP_LEN[2] = BUFFER3_UDP_LEN; udpBuffer[activeUdpSocket] = udpBuffer3; udpSocket[2] = INVALID_UDP_SOCKET; } #endif #if MAX_UDP_SOCKETS_FREERTOS>3 if (activeUdpSocket == 3) { BUFFER_UDP_LEN[3] = BUFFER4_UDP_LEN; udpBuffer[activeUdpSocket] = udpBuffer4; udpSocket[3] = INVALID_UDP_SOCKET; } #endif p_udp_wifiram[activeUdpSocket] = udpBuffer[activeUdpSocket]; p_udp_data[activeUdpSocket] = udpBuffer[activeUdpSocket]; activeUdpSocket++; } #endif if (hFlyTask == NULL) { // Creates the task dedicated to user code xTaskCreate(FlyportTask,(signed char*) "FLY" , (configMINIMAL_STACK_SIZE * 4), NULL, tskIDLE_PRIORITY + 1, &hFlyTask); } //------------------------------------------------------------------------------------------- //| --- COOPERATIVE MULTITASKING LOOP --- | //------------------------------------------------------------------------------------------- while(1) { #if defined (FLYPORT) if (WFStatus != TURNED_OFF) { // Check to verify the connection. If it's lost or failed, the device tries to reconnect if ((WFStatus == CONNECTION_LOST) || (WFStatus == CONNECTION_FAILED)) WF_Connect(WFConnection); #else { #endif // This task performs normal stack task including checking // for incoming packet, type of packet and calling // appropriate stack entity to process it. vTaskSuspendAll(); StackTask(); xTaskResumeAll(); #if defined(STACK_USE_HTTP_SERVER) || defined(STACK_USE_HTTP2_SERVER) vTaskSuspendAll(); HTTPServer(); xTaskResumeAll(); #endif // This tasks invokes each of the core stack application tasks StackApplications(); #if defined(STACK_USE_ZEROCONF_LINK_LOCAL) ZeroconfLLProcess(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSProcess(); // Use this function to exercise service update function // HTTPUpdateRecord(); #endif #if defined(STACK_USE_SNMP_SERVER) && !defined(SNMP_TRAP_DISABLED) //User should use one of the following SNMP demo // This routine demonstrates V1 or V2 trap formats with one variable binding. SNMPTrapDemo(); #if defined(SNMP_STACK_USE_V2_TRAP) //This routine provides V2 format notifications with multiple (3) variable bindings //User should modify this routine to send v2 trap format notifications with the required varbinds. //SNMPV2TrapDemo(); #endif if(gSendTrapFlag) SNMPSendTrap(); #endif #if defined(STACK_USE_BERKELEY_API) BerkeleyTCPClientDemo(); BerkeleyTCPServerDemo(); BerkeleyUDPClientDemo(); #endif // Check on the queue to verify if other task have requested some stack function xStatus = xQueueReceive(xQueue,&Cmd,0); CmdCheck(); // If the local IP address has changed (ex: due to DHCP lease change) // write the new IP address to the LCD display, UART, and Announce // service if(dwLastIP != AppConfig.MyIPAddr.Val) { dwLastIP = AppConfig.MyIPAddr.Val; #if defined(STACK_USE_UART) UARTWrite(1,"\r\nNew IP Address: "); #endif DisplayIPValue(AppConfig.MyIPAddr); #if defined(STACK_USE_UART) UARTWrite(1,"\r\n"); #endif #if defined(STACK_USE_ANNOUNCE) AnnounceIP(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSFillHostRecord(); #endif } } //end check turnoff } }
/* * Main entry point. */ void main(void) { static TICK8 t = 0; #ifdef HEATHERD NODE_INFO tcpServerNode; static TCP_SOCKET tcpSocketUser = INVALID_SOCKET; BYTE c; #endif static BYTE testLED; testLED = 1; //Set SWDTEN bit, this will enable the watch dog timer WDTCON_SWDTEN = 1; aliveCntrMain = 0xff; //Disable alive counter during initialization. Setting to 0xff disables it. //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 buses busInit(); //Initialize serial ports early, because they could be required for debugging if (appcfgGetc(APPCFG_USART1_CFG & APPCFG_USART_ENABLE)) { appcfgUSART(); //Configure the USART1 } if (appcfgGetc(APPCFG_USART2_CFG & APPCFG_USART_ENABLE)) { appcfgUSART2(); //Configure the USART2 } //After initializing all modules that use interrupts, enable global interrupts INTCON_GIEH = 1; INTCON_GIEL = 1; //Initialize file system. fsysInit(); //Intialize HTTP Execution unit htpexecInit(); //Initialize Stack and application related NV variables. appcfgInit(); //First call appcfgCpuIOValues() and then only appcfgCpuIO()!!! This ensures the value are set, before enabling ports. appcfgCpuIOValues(); //Configure the CPU's I/O port pin default values appcfgCpuIO(); //Configure the CPU's I/O port pin directions - input or output 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(); //Initialize expansion board appcfgXboard(); StackInit(); #if defined(STACK_USE_HTTP_SERVER) HTTPInit(); #endif #if defined(STACK_USE_FTP_SERVER) FTPInit(); #endif //Intialise network componet of buses - only call after StackInit()! busNetInit(); //Initializes events. evtInit(); //Initializes "UDP Command Port" and "UDP Even Port". cmdInit(); ioInit(); #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. */ #ifdef HEATHERD //Create a TCP socket that listens on port 54123 tcpSocketUser = TCPListen(HEATHERD); #define HEATHERD_ENABLE (!(appcfgGetc(APPCFG_TRISA) & 1)) #define HEATHERD_WRITE_ENABLE (!(appcfgGetc(APPCFG_TRISA) & 2)) #endif while(1) { aliveCntrMain = 38; //Reset if not services in 52.42ms x 38 = 2 seconds //Blink SYSTEM LED every second. if (appcfgGetc(APPCFG_SYSFLAGS) & APPCFG_SYSFLAGS_BLINKB6) { //Configure RB6 as output, and blink it every 500ms if ( TickGetDiff8bit(t) >= ((TICK8)TICKS_PER_SECOND / (TICK8)2) ) { t = TickGet8bit(); //If B6 is configured as input, change to output if (appcfgGetc(APPCFG_TRISB) & 0x40) { appcfgPutc(APPCFG_TRISB, appcfgGetc(APPCFG_TRISB) & 0b10111111); } TRISB_RB6 = 0; LATB6 ^= 1; //Toggle //Toggle IOR5E LED, if IOR5E is present if (appcfgGetc(APPCFG_XBRD_TYPE) == XBRD_TYPE_IOR5E) { ior5eLatchData.bits.ledPWR ^= 1; // Toggle } } } //This task performs normal stack task including checking for incoming packet, //type of packet and calling appropriate stack entity to process it. StackTask(); //Service LCD display lcdService(); //Process commands cmdTask(); //Process events evtTask(); //Process serial busses busTask(); //I2C Task i2cTask(); #ifdef HEATHERD //Has a remote node made connection with the port we are listening on if ((tcpSocketUser != INVALID_SOCKET) && TCPIsConnected(tcpSocketUser)) { if (HEATHERD_ENABLE) { //Is there any data waiting for us on the TCP socket? //Because of the design of the Modtronix TCP/IP stack we have to //consume all data sent to us as soon as we detect it. while(TCPIsGetReady(tcpSocketUser)) { //We are only interrested in the first byte of the message. TCPGet(tcpSocketUser, &c); if (HEATHERD_WRITE_ENABLE) serPutByte(c); } //Discard the socket buffer. TCPDiscard(tcpSocketUser); while (serIsGetReady() && TCPIsPutReady(tcpSocketUser)) { TCPPut(tcpSocketUser,serGetByte()); } TCPFlush(tcpSocketUser); } else { TCPDisconnect(tcpSocketUser); } } #endif #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 } } }
/* * Main entry point. */ void main(void) { static TICK t = 0; BYTE c, i; /* * 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(); /* * Following steps must be performed for all applications using * PICmicro TCP/IP Stack. */ MPFSInit(); /* * Initialize Stack and application related NV variables. */ InitAppConfig(); /* * Depending on whether internal program memor is used or external * EEPROM is used, keep/remove these block. */ /* * Wait a couple of seconds for user input. * - If something is detected, start config. * - If nothing detected, start main program. */ USARTPutROMString(PressKeyForConfig); for (i = 60; i > 0; --i) //Delay for 50mS x 60 = 3 sec { if ((i % 8) == 0) USARTPut('.'); if (USARTIsGetReady()) { #if defined(APP_USE_LCD) XLCDGoto(1, 0); XLCDPutROMString(SetupMsg); #endif SetConfig(); break; } DelayMs(50); } USARTPut('\r'); USARTPut('\n'); StackInit(); #if defined(STACK_USE_HTTP_SERVER) HTTPInit(); #endif #if defined(STACK_USE_FTP_SERVER) && defined(MPFS_USE_EEPROM) FTPInit(); #endif #if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING) if ( AppConfig.Flags.bIsDHCPEnabled ) { #if defined(APP_USE_LCD) XLCDGoto(1, 0); XLCDPutROMString(DHCPMsg); #endif } else { /* * Force IP address display update. */ myDHCPBindCount = 1; #if defined(STACK_USE_DHCP) DHCPDisable(); #endif } #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) { //Turn off the heater after about 1min to prevent over heating if(heater_started ==1) { if ( TickGetDiff(TickGet(), t) >= 9000 ) { LATB4 = 0; heater_started = 0; } }else { t = TickGet(); } /* * 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) && defined(MPFS_USE_EEPROM) FTPServer(); #endif /* * In future, as new TCP/IP applications are written, it * will be added here as new tasks. */ /* * 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 ) { DisplayIPValue(&AppConfig.MyIPAddr, TRUE); myDHCPBindCount = DHCPBindCount; #if defined(APP_USE_LCD) if ( AppConfig.Flags.bIsDHCPEnabled ) { XLCDGoto(1, 14); if ( myDHCPBindCount < 0x0a ) XLCDPut(myDHCPBindCount + '0'); else XLCDPut(myDHCPBindCount + 'A'); } #endif } } }
/////////////////////////////////////////////////////////////////////////////// // 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; } } }
void main(void) { static TICK t = 0; // Initialize any application specific hardware. InitializeBoard(); canInit(); // Initialize Stack and application related NV variables. InitAppConfig(); StackInit(); #if defined(STACK_USE_HTTP_SERVER) HTTPInit(); #endif #if defined(STACK_USE_SGP_SERVER) SGPInit(); #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 ( tickGet()-t >= TICK_1S/2 ) { t = tickGet(); LED0_IO ^= 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_SGP_SERVER) // This is a TCP application. It listens to TCP port 6666 // with one or more sockets and responds to remote requests. SGPServer(); #endif #if defined(STACK_USE_TIMESYNC) timeSync(); #endif // In future, as new TCP/IP applications are written, it // will be added here as new tasks. // Add your application speicifc tasks here. ProcessIO(); } }
/* * 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; } } }
int main(void) { InitOsc(); InitPorts(); InitUART0(); InitLCD(); TCPLowLevelInit(); //after TCPLowLevelInit() UCLK = ACLK = MCLK/4 = 2 000 000 Hz UART_transmit (CR); UART_transmit (LF); for (i=0; i!=26; i++) UART_transmit (UART_Message[i]); UART_transmit (CR); UART_transmit (LF); for (i=0; i!=32; i++) { SEND_CHAR(LCD_Message[i]); if (i==15) SEND_CMD (DD_RAM_ADDR2); } SEND_CMD(DD_RAM_ADDR); RX_flag=0; cntr = 0; HTTPStatus = 0; // clear HTTP-server's flag register TCPLocalPort = TCP_PORT_HTTP; // set port we want to listen to while (1) // repeat forever { //--------------buttons scan--------------------------------------------------------- if ((B1) == 0) //B1 is pressed { STATUS_LED_ON; //switch on status_led SEND_CMD(CLR_DISP); SEND_CMD(DD_RAM_ADDR); cntr=0; } else STATUS_LED_OFF; //B1 is released if ((B2) == 0) { // time_out = BUTTON_TIME; // while (time_out != 0) // if ((B2) == 0) time_out--; // else time_out = BUTTON_TIME; Delayx100us(50); RELAY1_ON; } else { // time_out = BUTTON_TIME; // while (time_out != 0) // if ((B2) != 0) time_out--; // else time_out = BUTTON_TIME; Delayx100us(50); RELAY1_OFF; } if ((B3) == 0) { Delayx100us(50); RELAY2_ON; //B3 is pressed } else { Delayx100us(50); RELAY2_OFF; //B3 is released } while ((B4) == 0) //B4 is pressed { BUZ1_OFF; BUZ2_ON; Delay(_100us); Delay(_100us); //buzzer with 5 000 Hz BUZ2_OFF; BUZ1_ON; Delay(_100us); } BUZ1_OFF; //B4 is released BUZ2_OFF; //--------UART0 receiv scan------------------------------------------------------------------ if (RX_flag == 1) //new receiv byte { STATUS_LED_ON; if (cntr == 0) { SEND_CMD(CLR_DISP); SEND_CMD(DD_RAM_ADDR); //set address for first row } SEND_CHAR(RXData); if(cntr == 15) SEND_CMD(DD_RAM_ADDR2); //set address for second row if(cntr++ == 31) cntr = 0; RX_flag = 0; STATUS_LED_OFF; } //---------Digital Inputs scan-------------------------------------------------------------- if ((DI1) == 0) for (i=0 ; i != 5; i++)UART_transmit(DI1_Message[i]); if ((DI2) == 0) for (i=0 ; i != 5; i++)UART_transmit(DI2_Message[i]); if ((DI3) == 0) for (i=0 ; i != 5; i++)UART_transmit(DI3_Message[i]); if ((DI4) == 0) for (i=0 ; i != 5; i++)UART_transmit(DI4_Message[i]); //---------DALLAS scan --------------------------------------------------------------------- if ((DALLAS) == 0) { cntr=0; SEND_CMD(CLR_DISP); SEND_CMD(DD_RAM_ADDR); for (i=0 ; i!= 14; i++) SEND_CHAR(DALLAS_Message[i]); } //---------FREQ scan ---------------------------------------------------------------------- if ((FREQ) != 0) { cntr=0; SEND_CMD(CLR_DISP); SEND_CMD(DD_RAM_ADDR); for (i=0 ; i!= 16; i++) SEND_CHAR(FREQ_Message[i]); } //*********************************************************************************** //this is the end of my programm //*********************************************************************************** if (!(SocketStatus & SOCK_ACTIVE)) { TCPPassiveOpen(); // listen for incoming TCP-connection } DoNetworkStuff(); // handle network and easyWEB-stack // events HTTPServer(); } return 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 } } }