int8 platform_init(void) { int8 ret8; uint32 retu32; uint8 tx_size[8]={2, 2, 2, 2, 2, 2, 2, 2}; // Device default memory setting uint8 rx_size[8]={2, 2, 2, 2, 2, 2, 2, 2}; RCC_Configuration(); // Configure the system clocks GPIO_Configuration(); // Configure GPIO Pin setting NVIC_Configuration(); // Configure the vector table retu32 = SysTick_Config(SystemCoreClock/SYSTICK_HZ); // SysTick Configuration - 1ms if(retu32 != 0) return RET_NOK; ret8 = wizpf_uart_init(WIZ_USART1); if(ret8 != RET_OK) return RET_NOK; ret8 = wizspi_init(WIZ_SPI1); if(ret8 != RET_OK) { ERR("wizspi_init fail"); return RET_NOK; } device_HW_reset(); DEVICE_INIT_WITH_MEMCHK(tx_size, rx_size); wizpf_led_set(WIZ_LED1, VAL_ON); // LED3 and LED4 On by default wizpf_led_set(WIZ_LED2, VAL_ON); return RET_OK; }
void GPIO_Configuration(void) { { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); // Set all as default GPIO_Init(PORTA, &GPIO_InitStructure); GPIO_Init(PORTB, &GPIO_InitStructure); GPIO_Init(PORTC, &GPIO_InitStructure); } #ifdef LED1_PIN wizpf_gpio_init(LED1_PORT, LED1_PIN, GMOD_OUT_PUSHPULL); wizpf_led_set(WIZ_LED1, VAL_OFF); #endif #ifdef LED2_PIN wizpf_gpio_init(LED2_PORT, LED2_PIN, GMOD_OUT_PUSHPULL); wizpf_led_set(WIZ_LED2, VAL_OFF); #endif #ifdef WIZ_RESET_PIN wizpf_gpio_init(WIZ_RESET_PORT, WIZ_RESET_PIN, GMOD_OUT_PUSHPULL); GPIO_SetBits(WIZ_RESET_PORT, WIZ_RESET_PIN); #endif #ifdef WIZ_PWDN_PIN wizpf_gpio_init(WIZ_PWDN_PORT, WIZ_PWDN_PIN, GMOD_OUT_PUSHPULL); GPIO_ResetBits(WIZ_PWDN_PORT, WIZ_PWDN_PIN); #endif #ifdef WIZ_INT_PIN wizpf_gpio_init(WIZ_INT_PORT, WIZ_INT_PIN, GMOD_IN_PULLUP); // For IIN Chip EXTI #endif // ToDo }
void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); // Set all as default GPIO_Init(PORTA, &GPIO_InitStructure); GPIO_Init(PORTB, &GPIO_InitStructure); GPIO_Init(PORTC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = LED1_PIN; GPIO_Init(LED1_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = LED2_PIN; GPIO_Init(LED2_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = WIZ_RESET_PIN; GPIO_Init(WIZ_RESET_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = WIZ_PWDN_PIN; GPIO_Init(WIZ_PWDN_PORT, &GPIO_InitStructure); //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // For IIN Chip EXTI //GPIO_InitStructure.GPIO_Pin = WIZ_INT_PIN; //GPIO_Init(WIZ_INT_PORT, &GPIO_InitStructure); wizpf_led_set(WIZ_LED1, VAL_OFF); wizpf_led_set(WIZ_LED2, VAL_OFF); GPIO_SetBits(WIZ_RESET_PORT, WIZ_RESET_PIN); GPIO_ResetBits(WIZ_PWDN_PORT, WIZ_PWDN_PIN); // ToDo }
static int8 mn_set_led(menu_ctrl mctrl, int8 *mbuf) { if(mctrl == MC_START) { printf("Enter the number [1: ON, 2: OFF]\r\n"); } else if(mctrl == MC_END) { } else if(mctrl == MC_DATA) { if(str_check(isdigit, mbuf) == RET_OK) { uint8 input = atoi((char*)mbuf); if(input == 1) { wizpf_led_set(WIZ_LED1, VAL_ON); wizpf_led_set(WIZ_LED2, VAL_ON); printf("LED On\r\n"); } else if(input == 2) { wizpf_led_set(WIZ_LED1, VAL_OFF); wizpf_led_set(WIZ_LED2, VAL_OFF); printf("LED Off\r\n"); } else { printf("wrong number(%d) - try again\r\n", input); return RET_NOK; } return RET_OK; } else { printf("not digit(%s) - try again\r\n", mbuf); return RET_NOK; } } return RET_NOK; }
void GPIO_Configuration(void) { { GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); // Set all as default GPIO_Init(PORTA, &GPIO_InitStructure); GPIO_Init(PORTB, &GPIO_InitStructure); GPIO_Init(PORTC, &GPIO_InitStructure); } #ifdef LED1_PIN GPIO_INIT_SIMP(GPIO_Mode_Out_PP, LED1_PORT, LED1_PIN); wizpf_led_set(WIZ_LED1, VAL_OFF); #endif #ifdef LED2_PIN GPIO_INIT_SIMP(GPIO_Mode_Out_PP, LED2_PORT, LED2_PIN); wizpf_led_set(WIZ_LED2, VAL_OFF); #endif #ifdef WIZ_RESET_PIN GPIO_INIT_SIMP(GPIO_Mode_Out_PP, WIZ_RESET_PORT, WIZ_RESET_PIN); GPIO_SetBits(WIZ_RESET_PORT, WIZ_RESET_PIN); #endif #ifdef WIZ_PWDN_PIN GPIO_INIT_SIMP(GPIO_Mode_Out_PP, WIZ_PWDN_PORT, WIZ_PWDN_PIN); GPIO_ResetBits(WIZ_PWDN_PORT, WIZ_PWDN_PIN); #endif #ifdef WIZ_INT_PIN GPIO_INIT_SIMP(GPIO_Mode_IPU, WIZ_INT_PORT, WIZ_INT_PIN); // For IIN Chip EXTI #endif // ToDo }
void setWIZnetLed(int32 val) { wiznetLedStatus = val; if ( wiznetLedStatus==0 ) wizpf_led_set(WIZ_LED2, VAL_OFF); // WIZ_LED2(LED4) in the W5200-EVB else wizpf_led_set(WIZ_LED2, VAL_ON); }
void wizpf_led_trap(uint8 repeat) { #ifdef LED1_PIN wizpf_led_set(WIZ_LED1, VAL_OFF); while(1) { Delay_ms(1500); for(uint32 i=0; i<repeat; i++) { wizpf_led_set(WIZ_LED1, VAL_TOG); Delay_ms(200); wizpf_led_set(WIZ_LED1, VAL_TOG); Delay_ms(200); } } #endif }
void USART1_IRQHandler(void) // USART1 ISR { if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(USART1, USART_IT_RXNE); if( (u1rx_wr > u1rx_rd && u1rx_wr-u1rx_rd >= U1RX_BUF_SIZE-1) || (u1rx_wr < u1rx_rd && u1rx_rd == u1rx_wr+1) ) // Buffer Overflow { //USART_ClearITPendingBit(USART1, USART_IT_RXNE); wizpf_led_set(WIZ_LED1, VAL_TOG); wizpf_led_set(WIZ_LED2, VAL_TOG); USART_SendData(USART1, (uint8)'@'); return; } u1rx_buf[u1rx_wr] = (int8)USART_ReceiveData(USART1); if(u1rx_wr < U1RX_BUF_SIZE-1) u1rx_wr++; else u1rx_wr = 0; } }
int32 main(void) { #define TCP_LISTEN_PORT 5000 #define UDP_LISTEN_PORT 5000 int8 ret, root; uint32 tick = 0; ret = platform_init(); if(ret != RET_OK) { goto FAIL_TRAP; } ret = network_init(SOCK_DHCP, NULL, NULL); if(ret != RET_OK) { ERRA("network_init fail - ret(%d)", ret); goto FAIL_TRAP; } printf("\r\n-----------------------------------\r\n"); printf("SMTP Client using W5200\r\n"); printf("-----------------------------------\r\n\r\n"); Delay_tick(2000); menu_init(); root = menu_add("Network setting", 0, NULL); menu_add("Show", root, mn_show_network); menu_add("Static Set", root, mn_set_network); menu_add("Loopback", 0, mn_loopback); menu_add("LED Test", 0, mn_set_led); root = menu_add("App Test", 0, NULL); menu_add("DNS", root, mn_dns); menu_add("BASE64", root, mn_base64); menu_add("eMail", root, mn_email); menu_print_tree(); dhcp_alarm_start(NULL); while(1) { alarm_run(); menu_run(); if(lb_tcp) loopback_tcps(7, (uint16)TCP_LISTEN_PORT); if(lb_udp) loopback_udp(7, (uint16)UDP_LISTEN_PORT); if(wizpf_tick_elapse(tick) > 1000) { // running check wizpf_led_set(WIZ_LED3, VAL_TOG); tick = wizpf_get_systick(); } } FAIL_TRAP: wizpf_led_trap(1); return 0; }
int8 platform_init(usart_param *up) { int8 ret8; uint32 retu32; usart_param up_tmp; uint8 tx_size[8]={2, 2, 2, 2, 2, 2, 2, 2}; // Device default memory setting uint8 rx_size[8]={2, 2, 2, 2, 2, 2, 2, 2}; RCC_Configuration(); // Configure the system clocks GPIO_Configuration(); // Configure GPIO Pin setting NVIC_Configuration(); // Configure the vector table retu32 = SysTick_Config(SystemCoreClock/SYSTICK_HZ); // SysTick Configuration - 1ms if(retu32 != 0) return RET_NOK; if(up == NULL) { WIZPF_USART_SET_PARAM(&up_tmp, UBR_115200, UWL_8, UST_1, UPB_NO, UFC_NO); up = &up_tmp; } ret8 = wizpf_usart_init(WIZ_USART1, up); if(ret8 != RET_OK) return RET_NOK; //ret8 = wizspi_init(WIZ_SPI1); ret8 = wizspi_init(WIZ_SPI2); // For W5500 FPGA board if(ret8 != RET_OK) { ERR("wizspi_init fail"); return RET_NOK; } device_HW_reset(); DEVICE_INIT_WITH_MEMCHK(tx_size, rx_size); wizpf_led_set(WIZ_LED1, VAL_ON); // LED3 and LED4 On by default wizpf_led_set(WIZ_LED2, VAL_ON); return RET_OK; }
int32 main(void) { #define TCP_LISTEN_PORT 5000 #define UDP_LISTEN_PORT 5000 int8 ret, root; uint32 dhcp_renew, dhcp_rebind, dhcp_time; uint32 dhcp_tick, led_tick; ret = platform_init(); if(ret != RET_OK) { goto FAIL_TRAP; } ret = network_init(SOCK_DHCP, NULL, NULL); if(ret != RET_OK) { ERRA("network_init fail - ret(%d)", ret); goto FAIL_TRAP; } printf("\r\n-----------------------------------\r\n"); printf("SMTP Client using W5200\r\n"); printf("-----------------------------------\r\n\r\n"); Delay_tick(2000); do { ret = dhcp_manual(DHCP_ACT_START, NULL, &dhcp_renew, &dhcp_rebind); } while(ret != RET_OK); dhcp_renew = wizpf_tick_conv(FALSE, dhcp_renew); dhcp_rebind = wizpf_tick_conv(FALSE, dhcp_rebind); dhcp_time = dhcp_renew; menu_init(); root = menu_add("Network setting", 0, NULL); menu_add("Show", root, mn_show_network); menu_add("Static Set", root, mn_set_network); menu_add("Loopback", 0, mn_loopback); menu_add("LED Test", 0, mn_set_led); root = menu_add("App Test", 0, NULL); menu_add("DNS", root, mn_dns); menu_add("BASE64", root, mn_base64); menu_add("eMail", root, mn_email); menu_print_tree(); dhcp_tick = led_tick = wizpf_get_systick(); while(1) { if(wizpf_tick_elapse(dhcp_tick) > dhcp_time) { if(dhcp_time==dhcp_renew) DBG("start renew"); else DBG("start rebind"); ret = dhcp_manual(dhcp_time==dhcp_renew? DHCP_ACT_RENEW: DHCP_ACT_REBIND, NULL, &dhcp_renew, &dhcp_rebind); dhcp_tick = wizpf_get_systick(); if(ret == RET_OK) { // renew success dhcp_renew = wizpf_tick_conv(FALSE, dhcp_renew); dhcp_rebind = wizpf_tick_conv(FALSE, dhcp_rebind); dhcp_time = dhcp_renew; } else { if(dhcp_time == dhcp_renew) dhcp_time = dhcp_rebind; // renew fail, so try rebind else dhcp_time = 60000; // retry after 1 min } } menu_run(); if(lb_tcp) loopback_tcps(7, (uint16)TCP_LISTEN_PORT); if(lb_udp) loopback_udp(7, (uint16)UDP_LISTEN_PORT); if(wizpf_tick_elapse(led_tick) > 1000) { wizpf_led_set(WIZ_LED3, VAL_TOG); led_tick = wizpf_get_systick(); } } FAIL_TRAP: wizpf_led_trap(1); return 0; }