void BSP_Init(void) { RCC_Configuration(); GPIO_Config(); //液晶屏初始化 LCD_Init(); //CAN总线 CanBus_Init(); ELV_Port_Init(); Uart4_Init(38400); //驱动硬件初始化 Hard_Ware_Init(); //全局变量初始化 G_Var_Init(); //电机参数CAN M_PID_Init(); NVIC_Configuration(); }
int32_t main(void) { uint32_t u32Index; uint8_t mac_def[6]; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; volatile int32_t ax88796c_isr; Board_Init(); Uart4_Init(); _delay_init(); // Setup scheduler and tasks Scheduler_Init(); Scheduler_AddTask(Task_SetLEDs, 0, 100); Scheduler_AddTask(Task_ProcessSwitches, 0, 50); Scheduler_AddTask(Task_Adconverter, 500, 100); Scheduler_AddTask(Task_SerialTerminalOutput, 0, 1000); Scheduler_Start(); // Configure uIP timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); mac_def[0] = UIP_ETHADDR0; mac_def[1] = UIP_ETHADDR1; mac_def[2] = UIP_ETHADDR2; mac_def[3] = UIP_ETHADDR3; mac_def[4] = UIP_ETHADDR4; mac_def[5] = UIP_ETHADDR5; ax88796c_init(mac_def); uip_init(); init_uip_clock_time(); uip_ipaddr(ipaddr, UIP_IPADDR0,UIP_IPADDR1,UIP_IPADDR2,UIP_IPADDR3); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, UIP_DRIPADDR0,UIP_DRIPADDR1,UIP_DRIPADDR2,UIP_DRIPADDR3); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, UIP_NETMASK0,UIP_NETMASK1,UIP_NETMASK2,UIP_NETMASK3); uip_setnetmask(ipaddr); httpd_init(); /* hello_world_init(); */ /* telnetd_init(); */ /*{ dhcpc_init(&mac_def, 6); }*/ /* uip_ipaddr(ipaddr, 127,0,0,1); smtp_configure("localhost", ipaddr); SMTP_SEND("*****@*****.**", "", "*****@*****.**", "Testing SMTP from uIP", "Test message sent by uIP\r\n"); */ /* webclient_init(); resolv_init(); uip_ipaddr(ipaddr, 168,95,1,1); resolv_conf(ipaddr); resolv_query("www.sics.se"); */ while(1){ Scheduler_DispatchTasks(); ax88796c_isr = ax88796c_check_int(); if(ax88796c_isr & ISR_LINK){ if(!ax88796c_check_media()){ printf ("Link down.\n"); }else{ uint16_t bmcr; bmcr = ax88796c_mdio_read(PHY_ID, MII_BMCR); printf("Link up, %sMbps, %s-duplex\n",(bmcr & BMCR_SPEED100) ? "100" : "10", \ (bmcr & BMCR_FULLDPLX) ? "full" : "half"); } } if(ax88796c_isr & ISR_RXPCT){ uip_len = ax88796c_packet_receive(uip_buf); }else{ uip_len = 0; } ax88796c_clear_int(ax88796c_isr); if(uip_len > 0) { if(UipBuf->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. */ if(uip_len > 0) { uip_arp_out(); ax88796c_packet_send(uip_buf,uip_len); } } else if(UipBuf->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) { ax88796c_packet_send(uip_buf,uip_len); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(u32Index = 0; u32Index < UIP_CONNS; u32Index++) { uip_periodic(u32Index); /* 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) { uip_arp_out(); ax88796c_packet_send(uip_buf,uip_len); } } #if UIP_UDP for(u32Index = 0; u32Index < UIP_UDP_CONNS; u32Index++) { uip_udp_periodic(u32Index); /* 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) { uip_arp_out(); ax88796c_packet_send(uip_buf,uip_len); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }