void main() { SCB->VTOR = 0x08000000; // set clock source as HSI / 2 * (PLL) 4 RCC->CFGR |= RCC_CFGR_PLLMULL8 | RCC_CFGR_PLLXTPRE_HSE_Div2 /*| RCC_CFGR_PLLSRC*/; RCC->CR |= RCC_CR_PLLON; while (!(RCC->CR & RCC_CR_PLLRDY)); RCC->CFGR |= RCC_CFGR_SW_PLL; while (!(RCC->CFGR & RCC_CFGR_SWS_PLL)); // enable peripherals RCC->APB1ENR = RCC_APB1ENR_TIM2EN; RCC->APB2ENR = RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_ADC1EN | RCC_APB2ENR_USART1EN | RCC_APB2ENR_AFIOEN; AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE; // configure USART IO_ALT_PUSH_PULL(UART_TX); USART1->BRR = USART_BRR(230400); USART1->CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE; ENABLE_INTERRUPT(USART1_IRQn); // enable systick SysTick->LOAD = SysTick->VAL = (F_CPU / 1000) / 8; SysTick->CTRL = /*SysTick_CTRL_CLKSOURCE |*/ SysTick_CTRL_ENABLE | SysTick_CTRL_TICKINT; _delay_init(); IO_PUSH_PULL(LED); IO_HIGH(LED); #ifndef ETHERNET_MODULE OW_UART_init(); tempInit(); ioInit(); irInit(); #endif #ifdef ETHERNET ethInit(); #endif uint8_t b; uint32_t lastCheck = 0; for (;;) { // if (IO_IS_LOW(IN1)) dodump = 1; // else dodump = 0; // dodump=1; #ifndef ETHERNET_MODULE ioProcess(); tempProcess(); irProcess(); #endif provTmr(); #ifdef ETHERNET ethProcess(); #endif } }
/** * \brief Initialize Delay driver */ void delay_init(void *const hw) { _delay_init(hardware = hw); }
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(); } } } }