/* example.c */ /* * RTXC Quadros Version 1.0 * Copyright (c) 1999-2003 * Quadros Systems, Inc. * ALL RIGHTS RESERVED * * THE INFORMATION HEREIN IS CONFIDENTIAL AND PROPRIETARY. * UNAUTHORIZED DISCLOSURE OR DISTRIBUTION IS PROHIBITED. * * * This example application demonstrates the use of the * OpenTCP TCP/IP stack with the RTXC Quadros Single * Stack RTOS. When running this example application, * the M5282LITE target will respond to ping (ICMP) and * HTTP requests. * */ #define HAS_OPENTCP #include "rtxcapi.h" #include "rtxcuart.h" #include "kalarm.h" #include "kthread.h" #include "example.h" #include "util.h" #include "mcu_port.h" #ifdef HAS_OPENTCP /* { */ #include "sysinit.h" #include "opentcp.h" //#include "insyst.h" void insyst_init(); void insyst_update_status(); unsigned long gcycle; NIF fec_nif; static unsigned char mac[6] = {0x00, 0x06, 0x70, 0x00, 0x00, 0x01}; /* IP Address */ #define IP1 192 #define IP2 168 #define IP3 2 #define IP4 123 /* Subnet Mask */ #define SM1 255 #define SM2 255 #define SM3 255 #define SM4 0 /* Default Gateway */ #define GW1 192 #define GW2 168 #define GW3 2 #define GW4 1 static void opentcp_init(void); #endif /* } HAS_OPENTCP */ void example_init(void) { //Initialize ports mcu_port_init(); printl("\n"); TS_DefAlarmActionArm(SALARM3, SCHEDULETHREAD, THREAD1); #ifdef HAS_OPENTCP /* { */ opentcp_init(); insyst_init(); printl("OpenTCP Initialization Complete!\n"); TS_DefAlarmActionArm(SALARM1, SCHEDULETHREAD, THREAD4); /* OpenTCP Timers, 10ms/tick */ #endif /* } HAS_OPENTCP */ } #ifdef HAS_OPENTCP /* { */ static void opentcp_init(void) { /* Init Opentcp */ eth_stub_init(); init_timerpool(); arpinit(); tcp_init(); udp_init(); init_http(); init_bootpc(0); init_tftps(); smtpc_init(); pop3c_init(); MCF5xxx_FEC_INIT; /* Initialize network device */ fec_init(&fec_nif); /* Write ethernet address in the NIF structure */ fec_nif.hwa[0] = mac[0]; fec_nif.hwa[1] = mac[1]; fec_nif.hwa[2] = mac[2]; fec_nif.hwa[3] = mac[3]; fec_nif.hwa[4] = mac[4]; fec_nif.hwa[5] = mac[5]; /* Initialize Network Buffers */ nbuf_init(); /* Register protocol handlers */ nif_bind_protocol(&fec_nif, FRAME_IP, opentcp_fechandler, "IP PROTOCOL"); nif_bind_protocol(&fec_nif, FRAME_ARP, opentcp_fechandler, "ARP PROTOCOL"); /* Start ethernet */ fec_nif.reset(&fec_nif); fec_nif.start(&fec_nif); /* Set OpenTCP localmachine */ localmachine.localip = ((UINT32)IP1)<<24 | ((UINT32)IP2)<<16 | ((UINT32)IP3)<<8 | IP4; localmachine.localHW[0] = mac[0]; localmachine.localHW[1] = mac[1]; localmachine.localHW[2] = mac[2]; localmachine.localHW[3] = mac[3]; localmachine.localHW[4] = mac[4]; localmachine.localHW[5] = mac[5]; localmachine.defgw = ((UINT32)GW1)<<24 | ((UINT32)GW2)<<16 | ((UINT32)GW3)<<8 | GW4; localmachine.netmask = ((UINT32)SM1)<<24 | ((UINT32)SM2)<<16 | ((UINT32)SM3)<<8 | SM4; localmachine.tos = 0; /* Enable some apps */ bootpc_enable(); } #endif /* } HAS_OPENTCP */ /***** Null Task Routine *****/ void example_null_run(void) { #ifdef HAS_OPENTCP /* { */ int16 len; int16 reset_timer; int16 packet_status; reset_timer = get_timer(); init_timer(reset_timer, 30*TIMERTIC); packet_status = eth_stub_isframe(&fec_nif); #if 0 if(check_timer(reset_timer) == 0) { DEBUGOUT("Resetting FEC\n"); fec_nif.reset(&fec_nif); nbuf_init(); eth_stub_init(); fec_nif.start(&fec_nif); init_timer(reset_timer, 30*TIMERTIC); } #endif mcu_cs1_on(); if(packet_status > 0) { switch(otcp_rxframe.protocol) { case PROTOCOL_ARP: Process_ARP(&otcp_rxframe); break; case PROTOCOL_IP: len = ProcessIPIn(&otcp_rxframe); if(len < 0) break; if( ReceivedIPPacket.protocol == IP_ICMP) ProcessICMPIn(&ReceivedIPPacket, len); else if(ReceivedIPPacket.protocol == IP_TCP) ProcessTCPIn(&ReceivedIPPacket, len); else if(ReceivedIPPacket.protocol == IP_UDP) ProcessUDPIn(&ReceivedIPPacket, len); break; default: break; } eth_stub_dumpframe(&fec_nif); } jtag_tms_off(); /* Run apps */ https_run(); /* bootpc_run(); */ tftps_run(); smtpc_run(); pop3c_run(); arpmanage(); tcp_poll(); jtag_tms_on(); #endif /* } HAS_OPENTCP */ } /***** Example Application *****/ void entry_point1(void *p1, void *p2) { #define SLEN 8 char string[SLEN+1]; gcycle++; if(gcycle%100 == 0) { itoa(gcycle,string,SLEN,10); insyst_update_status(); } print_thread_id_message(); /* Thread: THREAD1 */ print_state_message(1); /* State: 1 */ TS_DefThreadEntry(SELFTHREAD, entry_point2); } void entry_point2(void *p1, void *p2) { print_thread_id_message(); /* Thread: THREAD1 */ print_state_message(2); /* State: 2 */ TS_DefThreadEntry(SELFTHREAD, entry_point3); } void entry_point3(void *p1, void *p2) { print_thread_id_message(); /* Thread: THREAD1 */ print_state_message(3); /* State: 3 */ TS_DefThreadEntry(SELFTHREAD, entry_point1); } #ifdef HAS_OPENTCP /* { */ void entry_point4(void *p1, void *p2) { irqhandler_timer(); } void uexcptn2(void) { fec_handler(&fec_nif); } #else void entry_point4(void *p1, void *p2) {} void uexcptn2(void) {} #endif /* } HAS_OPENTCP */ /***** Unused Entry Points *****/ void entry_point5(void *p1, void *p2) {} void entry_point6(void *p1, void *p2) {} void uexcptn1(void) {} /* end of file - example.c */