Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

/opentcp/demo/main_demo.c

Go to the documentation of this file.
00001 
00016 #include <inet/debug.h>
00017 #include <inet/debug.h>
00018 #include <inet/arch/config.h>
00019 #include <inet/datatypes.h>
00020 #include <inet/timers.h>
00021 #include <inet/system.h>
00022 #include <inet/ethernet.h>
00023 #include <inet/ip.h>
00024 #include <inet/tcp_ip.h>
00025 
00026 /* Network Interface definition. Must be somewhere so why not here? :-)*/
00027 struct netif localmachine;
00028 
00029 /* main stuff */
00030 void main(void)
00031 {
00032         UINT16 len;
00033         
00034         /* initialize processor-dependant stuff (I/O ports, timers...).
00035          * This will normally be some function under the arch/xxxMCU dir. Most
00036          * important things to do in this function as far as the TCP/IP stack
00037          * is concerned is to:
00038          *  - initialize some timer so it executes decrement_timers
00039          *      on every 10ms (TODO: Throw out this dependency from several files
00040          *      so that frequency can be adjusted more freely!!!)
00041          *  - not mess too much with ports allocated for Ethernet controller
00042          */
00043         init();
00044          
00045         /* Set our network information. This is for static configuration.
00046         * if using BOOTP or DHCP this will be a bit different.
00047         */
00048         
00049         /* IP address */
00050         localmachine.localip = 0xAC1006E9;      /* 172.16.6.233 */
00051         /* Default gateway */
00052         localmachine.defgw =    0xAC100101;
00053         /* Subnet mask */
00054         localmachine.netmask = 0xFFFF0000;
00055         /* Ethernet (MAC) address */
00056         localmachine.localHW[5] = 0x00;
00057         localmachine.localHW[4] = 0x06;
00058         localmachine.localHW[3] = 0x70;
00059         localmachine.localHW[2] = 0xBA;
00060         localmachine.localHW[1] = 0xBE;
00061         localmachine.localHW[0] = 0xEE;
00062         
00063 
00064         /* Init system services         */    
00065         timer_pool_init();
00066                 
00067         /*interrupts can be enabled AFTER timer pool has been initialized */
00068         
00069         /* Initialize all network layers        */
00070         NE2000Init(&localmachine.localHW[0]);
00071         arp_init();
00072         udp_init();
00073         tcp_init();
00074 
00075         /* Initialize applications      */
00076         udp_demo_init();
00077         tpcc_demo_init();
00078         tcps_demo_init();
00079     
00080 
00081         DEBUGOUT(">>>>>>>>>Entering to MAIN LOOP>>>>>>>>>\n\r");
00082   
00083         /***    MAIN LOOP       ***/
00084     
00085         while(1) {
00086                 /* take care of watchdog stuff */
00087                         
00088                 /* do some stuff here
00089                 * .........
00090                 */
00091          
00092              
00093                 /* Try to receive Ethernet Frame        */
00094         
00095                 if( NETWORK_CHECK_IF_RECEIVED() == TRUE )       {
00096                                 
00097                         switch( received_frame.protocol) {
00098                         
00099                                 case PROTOCOL_ARP:
00100                                         process_arp(&received_frame);   
00101                                         break;
00102                         
00103                         
00104                                 case PROTOCOL_IP:                       
00105                                         len = process_ip_in(&received_frame);
00106                                 
00107                                         if(len < 0)
00108                                                 break;
00109                                 
00110                                         switch(received_ip_packet.protocol){
00111                                                 case IP_ICMP:
00112                                                         process_icmp_in (&received_ip_packet, len);                                     
00113                                                         break;
00114                                                 case IP_UDP:
00115                                                         process_udp_in (&received_ip_packet,len);
00116                                                         break;
00117                                                 case IP_TCP:
00118                                                         process_tcp_in (&received_ip_packet, len);                              
00119                                                         break;
00120                                                 default:
00121                                                         break;
00122                                         }
00123                         break;
00124 
00125                         default:
00126                         
00127                                 break;
00128                 }
00129                 
00130                 /* discard received frame */                    
00131                 NETWORK_RECEIVE_END();
00132         }
00133          
00134         /* Application main loops */
00135         /* Do not forget this!!! These don't get invoked magically :-) */
00136         udp_demo_run();
00137         tcpc_demo_run();
00138         tcps_demo_run();
00139         
00140 
00141         /* TCP/IP stack Periodic tasks  */
00142         /* Check possible overflow in Ethernet controller */
00143         NE2000CheckOverFlow();
00144         /* manage arp cache tables */
00145         arp_manage();
00146         /* manage opened TCP connections (retransmissions, timeouts,...)*/
00147         tcp_poll();
00148     }
00149     
00150 }
00151 

Generated on Sun Aug 3 20:32:59 2003 for OpenTCP by doxygen1.2.18