/* example.c */ #define HAS_OPENTCP #include "rtxcapi.h" #include "rtxcuart.h" #include "kalarm.h" #include "kthread.h" #include "kproject.h" //defines CLKTICK //#include "kcounter.h" #include "util.h" #include "mcu_port.h" #include "sysinit.h" #include "opentcp.h" #include "datasink.h" #include "netconfig.h" #include "netComm.h" #include "n3c.h" #include "example.h" #include "debug.h" #include "jtag.h" #include "cpu.h" #include "cache.h" #include "daq.h" void dprint(uint32); void hprint(uint32); void hprintn(uint32); void wait_shift(int); int hbd_init(void); int hbd_set(int, int); int hbd_run(int); int hbd_stop(void); uint32 data_read(void); NIF fec_nif; int gUserRun=0; // mask of active runs int gJTAG_FF=0; // file format unsigned long gcycle=0; unsigned long gcount_entry1=0; unsigned long gcount_entry4=0; unsigned long gcount_excptn2=0; // ProcessPacket assistance // For fast responce the ProcessPacket() is called in the event loop, // usually it cycles with the rate of 100KHz, but for lengthy processing like // playing the JTAG file it may take several seconds. During that time the TCP // stack will be not resposive. The idea is to call the ProcessPacket also in a // regularly scheduled thread entryPoint1() (2Hz rescheduling interval). // The gProcessPacketAssistance_enabled is a quck and dirty lock to prevent // reentrance to ProcessPacket() int gProcessPacketAssistance_enabled = 0; volatile int iread, istop, ierr; TICKS gstick; int16 reset_timer=0; void example_init(void){ int ii; static char *salarm = "THREADx recycle = 123\n"; static ALARMPROP alarmprop; SYSPROP *sysprop; TS_GetElapsedCounterTicks(TIMEBASE,&gstick);// time mark the program start TS_DefAlarmActionArm(SALARM3, SCHEDULETHREAD, THREAD1); TS_DefAlarmActionArm(SALARM1, SCHEDULETHREAD, THREAD4); /* OpenTCP Timers, 10ms/tick */ TS_GetAlarmProp(SALARM1, &alarmprop); salarm[6] = '4'; itoa_q(alarmprop.recycle,salarm+18,3,10); printl(salarm); TS_GetAlarmProp(SALARM3, &alarmprop); salarm[6] = '1'; itoa_q(alarmprop.recycle,salarm+18,3,10); printl(salarm); //CACHEON; mcu_port_init(); opentcp_init(); insyst_init(); printl("OpenTCP Initialization Complete!\n"); // Do not remove this! Will be useful for testing other boards // Testing Program interrupt counter// //printl("Idling for 10 seconds..."); //IDLE_MS(10000); //printl("Done\n"); //printl("Idling for 10 seconds using IDLE_US..."); //for(ii=10000;ii;--ii) IDLE_US(1000); //printl("Done\n"); } static void opentcp_init(void){ int rc; char *sinithttp="HTTP service for 12 connection\n"; /* Init Opentcp */ eth_stub_init(); init_timerpool(); reset_timer = get_timer(); init_timer(reset_timer, 30*TIMERTIC); arpinit(); tcp_init(); udp_init(); rc=init_http(); itoa_q(rc,sinithttp+17,2,10); printl(sinithttp); datasink_init(); rc=netComm_init(); if(rc<0) printl("netCom_init failed\n"); //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] = MAC0; fec_nif.hwa[1] = MAC1; fec_nif.hwa[2] = MAC2; fec_nif.hwa[3] = MAC3; fec_nif.hwa[4] = MAC4; fec_nif.hwa[5] = MAC5; /* 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] = MAC0; localmachine.localHW[1] = MAC1; localmachine.localHW[2] = MAC2; localmachine.localHW[3] = MAC3; localmachine.localHW[4] = MAC4; localmachine.localHW[5] = MAC5; 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(); // user init daq_init(); #ifdef I2C_ENABLE I2C_init(); OW_searchAll(0); OW_searchAll(1); #endif } void process_packet() { int len; //CACHEOFF_OPENTCP_HACK; /* DBG_PRINTL("Packet status routine\n"); */ switch(otcp_rxframe.protocol){ case PROTOCOL_ARP: /* DBG_PRINTL("Processing ARP\n"); */ Process_ARP(&otcp_rxframe); break; case PROTOCOL_IP: /* DBG_PRINTL("Processing IPin\n"); */ len = ProcessIPIn(&otcp_rxframe); if(len < 0) break; if( ReceivedIPPacket.protocol == IP_ICMP){ /* DBG_PRINTL("Processing ICMPin\n"); */ ProcessICMPIn(&ReceivedIPPacket, len); }else if(ReceivedIPPacket.protocol == IP_TCP){ /* DBG_PRINTL("Processing TCPin\n"); */ ProcessTCPIn(&ReceivedIPPacket, len); }else if(ReceivedIPPacket.protocol == IP_UDP){ /* DBG_PRINTL("Processing UDPin\n"); */ ProcessUDPIn(&ReceivedIPPacket, len); } break; default: break; } eth_stub_dumpframe(&fec_nif); //CACHEON_OPENTCP_HACK; } /***** Null Task Routine *****/ void example_null_run(void){ int16 len; int16 packet_status; int rc; gcycle++; #if 1 if(check_timer(reset_timer) == 0){ //printl("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 packet_status = eth_stub_isframe(&fec_nif); if(packet_status > 0) process_packet(); // Run apps //bootpc_run(); //tftps_run(); //smtpc_run(); //pop3c_run(); //arpmanage(); netComm_run(); datasink_run(); //tcp_poll(); //seems like this isn't really needed. if(gUserRun) { gProcessPacketAssistance_enabled = 1; CACHEON; if(gUserRun & RUN_JTAG) { switch(gJTAG_FF) { case FF_XSVF: printl("XSVF play started\n"); rc = jtag_run_xplay(); break; case FF_JAM: printl("JAM/STAPL play started\n"); rc = jtag_run_splay(); break; case FF_JBC: printl("JBC play started\n"); rc = jtag_run_jplay(); break; } printl("play finished\n"); gUserRun &= ~RUN_JTAG; rc=jtag_play_finished(rc); netComm_eventReturn(rc); } if(gUserRun & RUN_AUTOCONFIG){ jtag_autoconfig("l"); } if(gUserRun & RUN_DAQ) { daq_run(); } CACHEOFF; gProcessPacketAssistance_enabled = 0; } } //int gd0=0,gd1=40; unsigned long glast_cycle=0; void entry_point1(void *p1, void *p2) { // This function is invoked every 1/2 sec regardless of the status of // the null run processing. // int16 packet_status; //if((gcount_entry1%10)==0) printf("cycle:%d:%d \tentry1:%d \tentry4:%d \texception:%d \n", gcycle, gcycle-glast_cycle, gcount_entry1, gcount_entry4, gcount_excptn2); glast_cycle = gcycle; gcount_entry1++; if (gProcessPacketAssistance_enabled) { // The possible long processing in the null run will cause // unaceptable delay in the packet processing // Here we do periodic packet processing irrelevant to // what is happening in the null run. packet_status = eth_stub_isframe(&fec_nif); if(packet_status>0) { //printl("assisted packet processing\n"); process_packet(); } } //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" // All processing, which does not require fast service (less than 1/2 Hz) // should go here https_run(); //&RA/Moved to null run/daq_run(); /* * // test of bitfield function static unsigned char gsrc[32]= { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff }; static char stxt[80]; unsigned char pc[16]; int ii; memset(pc,0,sizeof(pc)); getbits(pc,gsrc+1,gd0,gd1); for(ii=0;ii<8;ii++) itoa_q(pc[ii],stxt+2*ii,2,16); stxt[16]=0; printl(stxt); printl("\n"); */ //,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, if(gUserRun & RUN_DBUG) { // Exit to dBUG monitor printl(">>\n"); // A bug? Without printing at least 2 characters the // trap instruction is not working gUserRun &= ~RUN_DBUG; exit_to_dBUG(); } //Call climb routine. OWD_POTClimbLoop(); } 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); } void entry_point4(void *p1, void *p2){ gcount_entry4++; irqhandler_timer(); } void uexcptn2(void){ gcount_excptn2++; fec_handler(&fec_nif); } /***** Unused Entry Points *****/ void entry_point5(void *p1, void *p2) {} void entry_point6(void *p1, void *p2) {} void uexcptn1(void) {} int hbd_init() { #define aclr_shift 0x4 #define loadconfig_shift 0x5 #define online_shift 0x6 #define nsmrst_shift 0x7 #define cratesel_shift 0x1 #define send_shift 0x2 #define offt_shift 0x3 #define rdfifo_shift 0x1 #define rdstatus_shift 0x2 #define rdcopy_shift 0x3 #define load_pulseh 0x10000 #define load_pulsew 0x20000 #define load_pulsesel_l 0x30000 #define load_pulsesel_h 0x40000 #define load_sd 0x50000 #define load_loaddac 0x60000 #define load_offp 0x70000 #define fem_mod(x) ((x) << 27) #define fem_ch(x) ((x) << 21) #define fem_read 0x100000 #define fem_id(x) ((x) << 16) uint32 i,j,k; uint32 itop; int itime,nsamples,imod,irepeat, ierr; volatile int32 *write_p,*read_p; unsigned char cause = MCF5282_UART0_UISR; char cdata; uint32 testn; write_p=(int32 *) 0x30000000; /* write address pointer */ read_p =(int32 *) 0x31000000; /* read address pointer */ ierr=0; printl("enter HBD electronics init routine"); imod=24; /* set for modules 3 */ irepeat=1; for (i=0; i 9) s[7-ik]=0x41+j-10; i=i/16; } s[8]=0xd; s[9]=0xa; s[10]=0; printl(s); } void hprintn(uint32 iprint) { uint32 i,k,j,ik; char s[9]; i=iprint; for (ik=0; ik< 8; ik++) { j=i%16; s[7-ik]=0x30+j; if(j> 9) s[7-ik]=0x41+j-10; i=i/16; } s[8]=0x20; s[9]=0x0; printl(s); }