BOOL setup_working_nic_pktdrv(void) { BOOL retval; retval = pktdrv_setup(); if(retval){ /* 找到了某网卡的PKT驱动 */ current_nic_init =PKTDRV_DRV.init; current_nic_open =PKTDRV_DRV.open; current_nic_stop =PKTDRV_DRV.stop; current_nic_xmit =PKTDRV_DRV.xmit; current_nic_poll =PKTDRV_DRV.poll; current_nic_control =PKTDRV_DRV.control; current_nic_get_status =PKTDRV_DRV.get_status; current_nic_islink =PKTDRV_DRV.islink; current_nic_watchdog =PKTDRV_DRV.watchdog; nic_driver_type =NIC_DRIVER_TYPE_PKTDRV; CurrentNIC =&PKTDRV_NICS; return nic_init(); } else { /* 没有找到PKT驱动 */ current_nic_init =NULL; current_nic_open =NULL; current_nic_stop =NULL; current_nic_xmit =NULL; current_nic_poll =NULL; current_nic_control =NULL; current_nic_get_status =NULL; current_nic_islink =NULL; current_nic_watchdog =NULL; return fail; } }
/*------------------------------------------------------------------------------------ * 寻找一块可直接支持的网卡(8139), 并将其设为当前网卡 **----------------------------------------------------------------------------------*/ BOOL setup_working_nic_native(void) { INT16S i; NIC_INFO_BLOCK * ptrNIB; CurrentNIC=NULL; for(i=0; i<nr_of_nic; i++){ nic_in_system[i].Supported=NO; ptrNIB=NICS; while(ptrNIB->VendorID!=0x0){ if( nic_in_system[i].VendorID==ptrNIB->VendorID && nic_in_system[i].DeviceID==ptrNIB->DeviceID ){ nic_in_system[i].Supported=YES; /* 支持这个网卡 */ if(CurrentNIC==NULL){ CurrentNIC=ptrNIB; CurrentNIC->NicDriver->VendorID=nic_in_system[i].VendorID; CurrentNIC->NicDriver->DeviceID=nic_in_system[i].DeviceID; CurrentNIC->NicDriver->BusNo =nic_in_system[i].BusNo; CurrentNIC->NicDriver->DeviceFuncNo=nic_in_system[i].DeviceFuncNo; CurrentNIC->NicDriver->NicName=ptrNIB->NicName; } break; } ptrNIB++; } } if(CurrentNIC!=NULL){ /* 找到了一块可用的网卡 */ current_nic_init =CurrentNIC->NicDriver->init; current_nic_open =CurrentNIC->NicDriver->open; current_nic_stop =CurrentNIC->NicDriver->stop; current_nic_xmit =CurrentNIC->NicDriver->xmit; current_nic_poll =CurrentNIC->NicDriver->poll; current_nic_control =CurrentNIC->NicDriver->control; current_nic_get_status =CurrentNIC->NicDriver->get_status; current_nic_islink =CurrentNIC->NicDriver->islink; current_nic_watchdog =CurrentNIC->NicDriver->watchdog; nic_driver_type =NIC_DRIVER_TYPE_NATIVE; return nic_init(); } else { /* 没有找到可用的网卡 */ current_nic_init =NULL; current_nic_open =NULL; current_nic_stop =NULL; current_nic_xmit =NULL; current_nic_poll =NULL; current_nic_control =NULL; current_nic_get_status =NULL; current_nic_islink =NULL; current_nic_watchdog =NULL; return fail; } }
void vNet_Init_M1() { // Init the uIP stack uip_init(); // Init the ARP table uip_arp_init(); // Init the Wifi controller nic_init(); // Connect as per configuration options nic_connect(); }
void TcpIpInit(void) { uint8_t IpAddress[4]; uint8_t NetMask[4]; uint8_t RouterIp[4]; /* Set up the network interface */ UserIoIpSettingsGet(IpAddress, NetMask, RouterIp); nic_init(); uip_init(IpAddress, NetMask, RouterIp); uip_arp_init(); uip_listen(HTONS(ETH_LOC_BUFFER_BUFFER_TCP_PORT)); TcpIpUipTimerCounter = 0; TcpIpUipArpTimerCounter = 0; TCCR0B = (1 << CS01) | (1<<CS00); TIMSK0 |= (1<<TOIE0); }
int main(void) { DDRB |= 0xFF; DDRD |= (1<<5) | (1<<6); PORTD = (1<<6); uint16_t tmp = 512; while(tmp--) { lcd_content[tmp] = 0x00; } spi_init(); soft_spi_init(); enc28j60_init(); nic_init(enc28j60_send_packet, enc28j60_receive_packet, enc28j60_set_mac); dhcp_init(dhcpname); timer_init(); sei(); //char nic_buffer[600]; while(1) { nic_doEvents(nic_buffer); dhcp_doEvents(nic_buffer); } }
/* stops the NIC */ void nic_stop(snic *nic) { unsigned char tmp_buffer[16]; if(!nic || !nic->iobase) return; /* make sure card was initialized */ nic_init(nic,nic->iobase,tmp_buffer,NULL); }
int main(void) { uint8_t i; P5DIR|=BIT1; //P5OUT&=~BIT1; P5OUT|=BIT1; _DINT(); //Disable Interrupts -- For initlization purposes WDTCTL = WDTPW + WDTHOLD; //Stop WDT /* Set System Clock Frequency to (121+1) * 32786 * 2 = 7.995392Mhz This freq. allows for 2400 - 230400 bit rate UART operation with less than 0.86% error */ FLL_CTL0 = (DCOPLUS | XCAP18PF); //Enable Frequency Multiplier (DCO+) and XIN/XOUT caps to 18pF SCFI0 = (FLLD_2 | FN_8); //Set Multiplier to 2, and DCO range to 8MHz nominal SCFQCTL = 121; //7.995392Mhz Operation with No Modulation //setup serial port #if DEBUG_SERIAL debug_serial_init(); printf("asd %i",23244); #endif for(i=0;i<6;i++) uNet_eth_address.addr[i]=_eth_addr[i]; // init NIC device driver #if DEBUG_SERIAL printf("MAC address:%x:%x:%x:%x:%x:%x\r\n",\ (int)_eth_addr[0],(int)_eth_addr[1],(int)_eth_addr[2],\ (int)_eth_addr[3],(int)_eth_addr[4],(int)_eth_addr[5]); printf("Initializing NIC...\r\n"); #endif nic_init(_eth_addr); uip_ipaddr_t ipaddr; uip_setethaddr(uNet_eth_address); #if DEBUG_SERIAL printf("Initializing uIP...\r\n"); #endif //init uIP uip_init(); #if DEBUG_SERIAL printf("Initializing ARP...\r\n"); #endif //init ARP cache uip_arp_init(); #if DEBUG_SERIAL printf("Initializing timer...\r\n"); #endif // init periodic timer clock_init(); //#if DEBUG_SERIAL printf("Initializing webclient...\r\n"); //#endif webclient_init(); _EINT(); // reenable interrupts if(!_enable_dhcp) { #if DEBUG_SERIAL printf("Initializing tcp/ip settings\r\n"); #endif //#if DEBUG_SERIAL printf("IP %i.%i.%i.%i\r\n", (int)_ip_addr[0],(int)_ip_addr[1],(int)_ip_addr[2],(int)_ip_addr[3]); printf("NetMask %i.%i.%i.%i\r\n", (int)_net_mask[0],(int)_net_mask[1],(int)_net_mask[2],(int)_net_mask[3]); printf("Gateway %i.%i.%i.%i\r\n", (int)_gateway[0],(int)_gateway[1],(int)_gateway[2],(int)_gateway[3]); //#endif uip_ipaddr(ipaddr, _ip_addr[0], _ip_addr[1], _ip_addr[2], _ip_addr[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, _net_mask[0], _net_mask[1], _net_mask[2], _net_mask[3]); uip_setnetmask(ipaddr); uip_ipaddr(ipaddr, _gateway[0], _gateway[1], _gateway[2], _gateway[3]); uip_setdraddr(ipaddr); } else { #if DEBUG_SERIAL printf("Going to query DHCP server...\r\n"); #endif uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); uip_setnetmask(ipaddr); uip_setdraddr(ipaddr); } timer_set(&periodic_timer, CLOCK_SECOND * 2 ); timer_set(&arp_timer, CLOCK_SECOND * 10); /* if(_enable_dhcp) { dhcpc_init(&uNet_eth_address.addr[0], 6); dhcpc_request(); } */ /* Initialize Scheduler so that it can be used */ //Scheduler_Init(); /* Initialize USB Subsystem */ //USB_Init(); //Scheduler_SetTaskMode(NetTask, TASK_RUN); /* Scheduling - routine never returns, so put this last in the main function */ //Scheduler_Start(); //#if DEBUG_SERIAL printf("Starting main loop...\r\n"); //#endif while(1) { NetTask(); webclient_get("www", SERVER_PORT,"/"); } }
/*---------------------------------------------------------------------------*/ int main(void) { EEPROM_main(); int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; memcpy (&uip_ethaddr.addr[0], &eeprom.MAC[0], 6); AVR_init(); egpio_init(); clock_init(); mbuf_init(); adlc_init(); GICR = (1 << INT0); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); nic_init(); uip_ipaddr(ipaddr, eeprom.IPAddr[0],eeprom.IPAddr[1],eeprom.IPAddr[2],eeprom.IPAddr[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, eeprom.Gateway[0],eeprom.Gateway[1],eeprom.Gateway[2],eeprom.Gateway[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, eeprom.Subnet[0],eeprom.Subnet[1],eeprom.Subnet[2],eeprom.Subnet[3]); uip_setnetmask(ipaddr); telnetd_init(); aun_init(); internet_init(); egpio_write (EGPIO_STATUS_GREEN); while(1) { // check the econet for complete packets adlc_poller(); aun_poller (); uip_len = nic_poll(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ maybe_send(); } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { nic_send(NULL); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); maybe_send(); } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); maybe_send(); } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }
/***************************************************************************** * Main Control Loop * * *****************************************************************************/ int main(void) { //led PB4 // Pins als Ausgänge definieren: DDRB |= (1 << 4); PORTB |= (0 << 4); //DDRD |= (1 << 7); //PORTD |= (1 << 7); unsigned char i; unsigned char arptimer=0; // init NIC device driver nic_init(); // init uIP uip_init(); // init app services_init(); // init ARP cache uip_arp_init(); // init periodic timer initTimer(); SET_USART_9600(); //PORTB |= (1 << 4); //LED PB4 ein sei(); // if((mca25_stat.init=mca25_init())==0) mca25_stat.init=mca25_configure(); // if(mca25_stat.init) { // print error message?; // } #if USE_MCA25_CAM //DEBUG: MCA25_ERROR_LED_OFF(); MCA25_CLOCK_LED_OFF(); //DDRB = 0xFF; MCA25_STATUS_LED_ON(); mca25_init(); mca25_configure(); MCA25_STATUS_LED_OFF(); MCA25_ERROR_LED_ON(); MCA25_CLOCK_LED_ON(); #endif // #if USE_CLOCK // Start_Clock(); //#endif #if USE_SERVO servo_init(); #endif //PORTD |= (1 << 7); while(1) { // look for a packet uip_len = nic_poll(); if(uip_len == 0) { // if timed out, call periodic function for each connection if(timerCounter > TIMERCOUNTER_PERIODIC_TIMEOUT) { timerCounter = 0; for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); // transmit a packet, if one is ready if(uip_len > 0) { uip_arp_out(); nic_send(); } } /* Call the ARP timer function every 10 seconds. */ if(++arptimer == 20) { uip_arp_timer(); arptimer = 0; } } } else // packet received { // process an IP packet if(BUF->type == htons(UIP_ETHTYPE_IP)) { // add the source to the ARP cache // also correctly set the ethernet packet length before processing uip_arp_ipin(); uip_input(); // transmit a packet, if one is ready if(uip_len > 0) { uip_arp_out(); nic_send(); } } // process an ARP packet else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); // transmit a packet, if one is ready if(uip_len > 0) nic_send(); } } } return 1; }
/***************************************************************************** * Main Control Loop * * *****************************************************************************/ int main(void) { unsigned char i; unsigned char arptimer=0; // PORTB PB5 als Ausgang (in use LED) DDRB=(1<<PB5); PORTB=(1<<PB5); init_sensors(); // init NIC device driver nic_init(); // init uIP uip_init(); // init app example1_init(); // init ARP cache uip_arp_init(); // init periodic timer initTimer(); sei(); // initialisierendes lesen der Temperatur(en) read_temp_sensors(); while(1) { if(minInt==1){ minInt=0; read_temp_sensors(); } // look for a packet uip_len = nic_poll(); if(uip_len == 0) { // if timed out, call periodic function for each connection //if(timerCounter > TIMERCOUNTER_PERIODIC_TIMEOUT) if(tInt) { tInt = 0; //timerCounter = 0; for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); // transmit a packet, if one is ready if(uip_len > 0) { uip_arp_out(); nic_send(); } } /* Call the ARP timer function every 10 seconds. */ if(++arptimer == 20) { uip_arp_timer(); arptimer = 0; } } } else // packet received { // process an IP packet if(BUF->type == htons(UIP_ETHTYPE_IP)) { // add the source to the ARP cache // also correctly set the ethernet packet length before processing uip_arp_ipin(); uip_input(); // transmit a packet, if one is ready if(uip_len > 0) { uip_arp_out(); nic_send(); } } // process an ARP packet else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); // transmit a packet, if one is ready if(uip_len > 0) nic_send(); } } } return 1; }