/* example.c */ #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 "tcpTest.h" #include "jtag_player.h" #include "lenval.h" #include "micro.h" //#include "insyst.h" //void insyst_init(); //void insyst_update_status(); unsigned long gcycle,gcmd=0,gcmdarg=0; NIF fec_nif; static unsigned char mac[6] = {0x00, 0x06, 0x70, 0x00, 0x00, 0x01}; /* IP Address */ #define IP1 192 #define IP2 168 #define IP3 0 #define IP4 2 /* Subnet Mask */ #define SM1 255 #define SM2 255 #define SM3 255 #define SM4 0 /* Default Gateway */ #define GW1 192 #define GW2 168 #define GW3 0 #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_tcpTest(); //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 */ extern unsigned char *gstor; SXsvfInfo gxsvfInfo; int jtag_run() { int rc; static char *setir="JTAG_SetIR 12345678\n"; static char *serr="Init\n"); jtag_setFile(gstor); rc=xsvfInitialize( &gxsvfInfo ); gcmd &= ~0x00000010; if(!rc) printl("OK\n"); else {itoa_q(rc,serr+8,8,16); printl(serr);} printl("\n"); sprintf(str,"xsvfRun "); rc=xsvfRun( &gxsvfInfo ); gcmd &= ~0x00000020; if(!rc) printl("OK\n"); else {itoa_q(rc,serr+9,8,16);printl(serr);} } if(gcmd&0x00001000) { rc=xsvfExecute(); gcmd &= ~0x00001000; printl("xsvfExecute "); if(rc) printl("OK\n"); else printl("FAILED\n"); } } /***** Null Task Routine *****/ void example_null_run(void) { #ifdef HAS_OPENTCP /* { */ int16 len; int16 packet_status; mcu_cs3_on(); packet_status = eth_stub_isframe(&fec_nif); 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){ tst0_on(); ProcessTCPIn(&ReceivedIPPacket, len); tst0_off(); }else if(ReceivedIPPacket.protocol == IP_UDP){ ProcessUDPIn(&ReceivedIPPacket, len); } break; default: break; } eth_stub_dumpframe(&fec_nif); } // Run apps //https_run(); //bootpc_run(); //tftps_run(); //smtpc_run(); //pop3c_run(); //arpmanage(); tcpTest_run(); //tcp_poll(); jtag_run(); mcu_cs3_off(); #endif /* } HAS_OPENTCP */ } /***** Example Application *****/ void entry_point1(void *p1, void *p2) { if(gcycle%10 == 0) insyst_update_status(); gcycle++; //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 */