int main(void) { /* Wiznet options*/ unsigned char mac_addr[] = {0x00, 0x16, 0x36, 0xDE, 0x58, 0xF6}; unsigned char ip_addr[] = {192, 168, 52, 41}; unsigned char sub_mask[] = {255, 255, 255, 192}; unsigned char gtw_addr[] = {192, 168, 52, 62}; DDRD = 0xFF; PORTD = 0x00; SPI_DDR = (1 << PORTB3) | (1 << PORTB5) | (1 << PORTB2); SPI_PORT |= (1 << SPI_CS); SPCR = (1 << SPE) | (1 << MSTR); SPSR |= (1 << SPI2X); W5100_Init(ip_addr, sub_mask, gtw_addr, mac_addr); for (;;) { W5100_poll(); } return 0; }
void main(void){ int socket0status; //ledmode=0; digitalWrite(0,LOW); cmdip[0]=0; pagehits=0; delay(100); printf("\nOlduino Web Server v5.1\n"); W5100_Init(); //initialize the wiznet chip while(1){ // Loop forever socket0status=SPI_Read(S0_SR); //printf("s0s=%x ",socket0status); switch (socket0status){ case SOCK_CLOSED: //initial condition socket0_init(); //initialize socket 0 break; case SOCK_ESTABLISHED: //someone wants to talk to the server handlesession(); break; //following are cases where we have to reset and reopen the socket case SOCK_FIN_WAIT: case SOCK_CLOSING: case SOCK_TIME_WAIT: case SOCK_CLOSE_WAIT: case SOCK_LAST_ACK: close0(); break; } delay(100); } }
void APP_Run(void) { cardMounted = FALSE; SHELL_Init(); W5100_Init(); SOCK_Init(); if (FRTOS1_xTaskCreate( Task1, /* pointer to the task */ (signed char *)"Task1", /* task name for kernel awareness debugging */ configMINIMAL_STACK_SIZE+100, /* task stack size */ (void*)NULL, /* optional task startup argument */ tskIDLE_PRIORITY, /* initial priority */ (xTaskHandle*)NULL /* optional task handle to create */ ) != pdPASS) { /*lint -e527 */ for(;;){}; /* error! probably out of memory */ /*lint +e527 */ } FRTOS1_vTaskStartScheduler(); }
int main(void) { RCC_ClocksTypeDef RCC_Clocks; UART_STRUCT US; /* Setup the microcontroller system. Initialize the Embedded Flash Interface, initialize the PLL and update the SystemFrequency variable. */ SystemInit(); // ------------------------------------------------------------------------ /* GPIO clock enable */ RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOE |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); /* CAN1 Periph clock enable */ // RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5 | RCC_APB1Periph_USB, ENABLE); // ------------------------------------------------------------------------ /* Setup SysTick Timer for 10 msec interrupts */ RCC_GetClocksFreq(&RCC_Clocks); if (SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100)) { /* Capture error */ while (1); } /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000); LED_init(); W5100_Delay_ms(1000); /* ------- ѕј–јћ≈“–џ ------------------------------ */ // IP ip_addr[0] = *((__IO uint8_t*)IP1Address); ip_addr[1] = *((__IO uint8_t*)IP2Address); ip_addr[2] = *((__IO uint8_t*)IP3Address); ip_addr[3] = *((__IO uint8_t*)IP4Address); // IP адрес не определен if ( (ip_addr[0] == 0xFF && ip_addr[1] == 0xFF && ip_addr[2] == 0xFF && ip_addr[3] == 0xFF) || (ip_addr[0] == 0x00 && ip_addr[1] == 0x00 && ip_addr[2] == 0x00 && ip_addr[3] == 0x00) ) { ip_addr[0] = 192; ip_addr[1] = 168; ip_addr[2] = 1; ip_addr[3] = 10; ip_addr32 = ip_addr[0] + (ip_addr[1]<<8) + (ip_addr[2]<<16) + (ip_addr[3]<<24); ui8ParSave = 1; } // ѕќ–“ port = *((__IO uint16_t*)PortAddress); // порт не определен if (port == 0xFFFF) { port = 30001; ui8ParSave = 1; } // — ќ–ќ—“№ rate = *((__IO uint32_t*)RateAddress); // скорость не определена if (rate != 9600 && rate != 14400 && rate != 19200 && rate != 38400 && rate != 57600 && rate != 115200) { rate = 38400; ui8ParSave = 1; } // —“ќѕ Ѕ»“џ stop_bits = *((__IO uint16_t*)SBAddress); // стоп биты не определены if (stop_bits != USART_StopBits_1 && stop_bits != USART_StopBits_2) { stop_bits = USART_StopBits_2; ui8ParSave = 1; } // „≈“Ќќ—“№ parity = *((__IO uint16_t*)ParityAddress); // четность не определена if (parity != USART_Parity_No && parity != USART_Parity_Even && parity != USART_Parity_Odd) { parity = USART_Parity_No; ui8ParSave = 1; } // таймаут timeout = *((__IO uint16_t*)TimeoutAddress); // таймаут не определен if (timeout > 1000) { timeout = 50; ui8ParSave = 1; } if (ui8ParSave) { ui8ParSave = 0; // Unlock the internal flash FLASH_Unlock(); __disable_interrupt(); // стираем страницу FLASH_ErasePage(IP1Address); FLASH_ProgramWord(IP1Address, ip_addr32); FLASH_ProgramHalfWord(PortAddress, port); FLASH_ProgramWord(RateAddress, rate); FLASH_ProgramHalfWord(SBAddress, stop_bits); FLASH_ProgramHalfWord(ParityAddress, parity); FLASH_ProgramHalfWord(TimeoutAddress, timeout); __enable_interrupt(); } // TIMERS Timer_100us_Init(); Timer_100ms_Init(); // ETHERNET W5100_InitLines(); PARAM_STRUCT par; par.ui8Mode[0] = MR_TCP; par.ui8Mode[1] = MR_TCP; par.ui8Mode[2] = MR_UDP; par.ip_addr[0] = ip_addr[0]; par.ip_addr[1] = ip_addr[1]; par.ip_addr[2] = ip_addr[2]; par.ip_addr[3] = ip_addr[3]; par.sub_mask[0] = 255; par.sub_mask[1] = 255; par.sub_mask[2] = 255; par.sub_mask[3] = 0; par.gtw_addr[0] = 192; par.gtw_addr[1] = 168; par.gtw_addr[2] = 10; par.gtw_addr[3] = 1; W5100_Init(&par); // RS-485 MODBUS US.ui32Rate = rate; US.ui16StopBits = stop_bits; US.ui16Parity = parity; US.ui16Timeout = timeout; RS485_InitLines(&US); // param reset pin init Param_Reset_init(); GPIO_WriteBit(GPIOD,GPIO_Pin_13,Bit_SET); while (1) { if (ui8ResetFlag == 0) { if (GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7) == Bit_SET) { ui8ResetFlag = 1; uiResetTimer = 10; GPIO_WriteBit(GPIOD,GPIO_Pin_13,Bit_RESET); } } else { if (uiResetTimer == 0 && GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7) == Bit_RESET) { ui8ParSave = 1; GPIO_WriteBit(GPIOD,GPIO_Pin_13,Bit_SET); W5100_Delay_ms(1000); ip_addr[0] = 192; ip_addr[1] = 168; ip_addr[2] = 1; ip_addr[3] = 10; } } if (ui8ParSave) { ui8ParSave = 0; ui8ResetFlag = 0; // Unlock the internal flash FLASH_Unlock(); __disable_interrupt(); // стираем страницу FLASH_ErasePage(IP1Address); ip_addr32 = ip_addr[0] + (ip_addr[1]<<8) + (ip_addr[2]<<16) + (ip_addr[3]<<24); FLASH_ProgramWord(IP1Address, ip_addr32); FLASH_ProgramHalfWord(PortAddress, port); FLASH_ProgramWord(RateAddress, rate); FLASH_ProgramHalfWord(SBAddress, stop_bits); FLASH_ProgramHalfWord(ParityAddress, parity); FLASH_ProgramHalfWord(TimeoutAddress, timeout); __enable_interrupt(); ip_addr[0] = *((__IO uint8_t*)IP1Address); ip_addr[1] = *((__IO uint8_t*)IP2Address); ip_addr[2] = *((__IO uint8_t*)IP3Address); ip_addr[3] = *((__IO uint8_t*)IP4Address); port = *((__IO uint16_t*)PortAddress); rate = *((__IO uint32_t*)RateAddress); stop_bits = *((__IO uint16_t*)SBAddress); parity = *((__IO uint16_t*)ParityAddress); timeout = *((__IO uint16_t*)TimeoutAddress); // запуск watch dog IWDG_Enable(); // вываливаемс¤ из приложени¤ while (1); } UDP_Process_handler(); TCP_Process_handler1(); }; }
int main(void) { /* Ledstrips inits */ /* W5100 defines */ unsigned char sockstat; unsigned int rsize; char radiostat0[10], radiostat1[10]; int postidx, getidx; /* Initial variable used */ sockreg = 0; tempvalue = 0; ledmode = 0; Init_timer1(); Init_timers(); /*Init_shift();*/ OSCTUN = 21; PLLFBD = 38; /* M=40 */ CLKDIVbits.PLLPOST = 0; /* N1=2 */ CLKDIVbits.PLLPRE = 0; /* N2=2 */ /* Eraseleds();*/ /* even ledstrips have to be mirrored */ /* Mirror(patt); */ /* LCD inits */ Init_mcp(); Init_LCD(); Write_LCD(startup); /* W5100 inits */ Init_pin_SPI(); Init_SPI(); W5100_Init(gtw_addr,mac_addr,sub_mask,ip_addr); T_SPI_CS; SPI_CS = 1; Init_UART(); for (;;) { sockstat = SPI_Read(S0_SR); switch (sockstat) { case SOCK_CLOSED: if (socket(sockreg, MR_TCP, TCP_PORT) > 0) { /* Listen to Socket 0 */ if (listen(sockreg) <= 0) Delayms(1); } break; case SOCK_ESTABLISHED: /* Get the client request size */ rsize = recv_size(); if (rsize > 0) { /* Now read the client Request */ if (recv(sockreg, buf, rsize) <= 0) break; Putstr(buf); /* printf("%s",buf);*/ /* Check the Request Header */ getidx = strindex((char *) buf, "GET /"); postidx = strindex((char *) buf, "POST /"); if (getidx >= 0 || postidx >= 0) { /* Now check the Radio Button for POST request */ if (postidx >= 0) { if (strindex((char *) buf, "uBoard new color") > 0) ledmode++; } /* Create the HTTP Response Header */ strncpy((char *)buf,("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" "<body style=\"background-color:FFFFFF;\">\r\n"),96); strcat((char *)buf,("[\n" " {\n" " \"id\": \"1\",\n" " \"name\": \"uBoard webboard\",\n" " \"ipaddr\": \"192.168.0.102\",\n" " \"subnetmask\": \"255.255.255.0\",\n" " \"gateway\": \"192.168.0.1\",\n" " \"adjustSpeedOfPattern\": \"int\",\n" " \"turnLedsOnOff\": \"boolean\"\n" " }\n" "]\n")); /* Now Send the HTTP Response */ if (send(sockreg,buf,strlen((char *)buf)) <= 0) break; /* TODO: add status */ LCD_Clear(); LCD_PutByte(ledmode); if (ledmode == 1) { strncpy(radiostat0,"",0); strncpy(radiostat1,("checked"),7); } else { strncpy(radiostat0,("checked"),7); strncpy(radiostat1,"",0); } /* Create the HTTP Radio Button Response */ strncpy((char *)buf,("<p><input type=\"radio\" name=\"radio\" value=\"0\" "),52); strcat((char *)buf,radiostat0); strcat((char *)buf,(">Turn off\r\n")); strcat((char *)buf,("<br><input type=\"radio\" name=\"radio\" value=\"1\" ")); strcat((char *)buf,radiostat1); strcat((char *)buf,(">Lounge mode\r\n")); strcat((char *)buf,("</strong><p>\r\n")); strcat((char *)buf,("<input type=\"submit\">\r\n")); strcat((char *)buf,("</form></span></body></html>\r\n")); /* Now Send the HTTP Remaining Response */ if (send(sockreg,buf,strlen((char *)buf)) <= 0) break; } /* Disconnect the socket */ disconnect(sockreg); } else Delayms(1); /* Wait for request */ break; case SOCK_FIN_WAIT: case SOCK_CLOSING: case SOCK_TIME_WAIT: case SOCK_CLOSE_WAIT: case SOCK_LAST_ACK: /* Force to close the socket */ close(sockreg); break; } } return 0; }