主函数如下:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
loop_cnt++;
//HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);
if(13 == ((loop_cnt >> 4) & 0x0f))
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
else if (15 == ((loop_cnt >> 4) & 0x0f))
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
HAL_IWDG_Refresh(&hiwdg);
if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_13))
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_RESET);
}
else
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_SET);
}
//print_log("w5500 link STA %d\r\n", (Read_W5500_1Byte(PHYCFGR)&LINK));
#if 1
if((getPHYCFGR() & 0x01) != link_state)
{
link_state = (getPHYCFGR() & 0x01);
if((getPHYCFGR() & 0x01) == 0)
{
beep_voice(1, 200);
close(2);
S_State[2] = 0;
close(3);
S_State[3] = 0;
close(4);
S_State[4] = 0;
close(5);
S_State[5] = 0;
}
else
{
beep_voice(2, 50);
print_log("w5500 link\r\n");
}
}
else if(memcmp(gSystemParam.deviceIp, gSystemParam.gateway, 3) == 0) // check gateway
{
//tmpTciks = g64msTicks;
// handle webserver
do_http(0);
//print_log("do_http %lld\r\n", g64msTicks - tmpTciks);
//tmpTciks = g64msTicks;
// handle NTP services
//ntpServices();
//print_log("ntpServices %lld\r\n", g64msTicks - tmpTciks);
//tmpTciks = g64msTicks;
netAppServices();
//read_net_app();
//print_log("netAppServices %lld\r\n", g64msTicks - tmpTciks);
}
// handle uart message, include uart1 uart2 uart3
cmdMachine();
#endif
}
在注释掉do_http(0)后程序无法启动,请问是什么问题?
do_http的函数定义如下:
char rx_buf[MAX_URI_SIZE] = {0};
void do_http(uint8_t sn)
{
unsigned short len;
st_http_request *http_request;
memset(rx_buf,0x00,MAX_URI_SIZE);
http_request = (st_http_request*)rx_buf; // struct of http request
/* http service start */
switch(getSn_SR(sn))
{
case SOCK_INIT:
//listen(sn);
break;
case SOCK_LISTEN:
break;
case SOCK_ESTABLISHED:
//case SOCK_CLOSE_WAIT:
if(getSn_IR(sn) & Sn_IR_CON)
{
setSn_IR(sn, Sn_IR_CON);
}
if ((len = getSn_RX_RSR(sn)) > 0)
{
len = recv(sn, (unsigned char*)http_request, len);
*(((unsigned char*)http_request)+len) = 0;
//proc_http(sn, (unsigned char*)http_request); // request is processed
disconnect(sn);
//printf("SOCK_ESTABLISHED %04x\r\n", len);
}
break;
case SOCK_CLOSE_WAIT:
if ((len = getSn_RX_RSR(sn)) > 0)
{
//printf("close wait: %d\r\n",len);
len = recv(sn, (unsigned char*)http_request, len);
*(((unsigned char*)http_request)+len) = 0;
//proc_http(sn, (unsigned char*)http_request); // request is processed
//printf("SOCK_CLOSE_WAIT %04x\r\n", len);
}
disconnect(sn);
break;
case SOCK_CLOSED:
len = gSystemParam.webServerPort[1];
len *= 256;
len += gSystemParam.webServerPort[0];
socket(sn, Sn_MR_TCP, len, 0x00); /* reinitialize the socket */
break;
default:
break;
}// end of switch
}