int cgi_ng_pld(http_socket *socket) { u32 content_length; char *file; int mph_len; char *pnt; int len; int i; if (socket->content_priv == 0) { uart_puts("CGI: Start loading PLD.\r\n"); pld_init(); for (i = 0; i < 7500; i++) ; pld_load_start(); pnt = 0; for (i = 0; i < 16; i++) { char arg[16]; pnt = http_get_header(socket, pnt); if (pnt == 0) break; if (strncmp(pnt, "Content-Length:", 15) == 0) { pnt += 16; for (i = 0; i < 7; i++) { if ( (*pnt < '0') || (*pnt > '9') ) break; arg[i] = *pnt; pnt++; } arg[i] = 0; content_length = atoi(arg); break; } } pnt = (char *)socket->rx; while(pnt != 0) { if ( (pnt[0] == 0x0d) && (pnt[1] == 0x0a) && (pnt[2] == 0x0d) && (pnt[3] == 0x0a) ) { /* Get a pointer on datas (after multipart header) */ file = (pnt + 4); break; } /* Search the next CR */ pnt = strchr(pnt + 1, 0x0d); } /* Multipart header length */ mph_len = ((u32)file - (u32)socket->rx); /* Received length */ len = socket->rx_len - mph_len; pld_load((const u8 *)file, len); if (len < content_length) socket->state = HTTP_STATE_RECV_MORE; socket->content_priv = (void *)(content_length - mph_len - len); } else { content_length = (u32)socket->content_priv; pld_load((u8 *)socket->rx, socket->rx_len); if (socket->rx_len < content_length) { socket->content_priv = (void *)(content_length - socket->rx_len); } else { uart_puts("CGI: PLD bitstream loaded !\r\n"); pld_load_end(); socket->content_priv = 0; http_send_header(socket, 200, 0); socket->state = HTTP_STATE_SEND; } } return(0); }
int main(void) { dhcp dhcp_session; int dhcp_state; http_server http; http_socket httpsock[4]; http_content httpcontent[4]; char oled_msg[17]; char *pnt; int step; api_init(); uart_puts(" * eCowLogic firmware \r\n"); hw_systick( hw_getfreq() / 1000 ); dhcp_session.socket = 2; dhcp_session.buffer = (u8 *)buffer_dhcp; dhcp_init(&dhcp_session); oled_pos(1, 0); oled_puts("Reseau (DHCP) "); step = 0; while(1) { dhcp_state = dhcp_run(&dhcp_session); if (dhcp_state == DHCP_IP_LEASED) break; step++; oled_pos(1, 13); if (step == 1) oled_puts(". "); if (step == 2) oled_puts(".. "); if (step == 3) oled_puts("..."); if (step == 4) { step = 0; dhcp_session.tick_1s++; uart_putc('.'); oled_puts(" "); } delay(250); } pnt = oled_msg; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[0]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[1]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[2]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[3]); for ( ; pnt < (oled_msg + 16); pnt++) *pnt = ' '; oled_msg[16] = 0; uart_puts("DHCP: LEASED ! "); uart_puts(oled_msg); uart_puts("\r\n"); oled_pos(1, 0); oled_puts(oled_msg); spi_init(); pld_init(); //net_init(); /* Init HTTP content */ strcpy(httpcontent[0].name, "/pld"); httpcontent[0].wildcard = 0; httpcontent[0].cgi = cgi_ng_pld; httpcontent[0].next = &httpcontent[1]; /* Init HTTP content */ strcpy(httpcontent[1].name, "/spi"); httpcontent[1].wildcard = 0; httpcontent[1].cgi = cgi_spi; httpcontent[1].next = &httpcontent[2]; /* Init HTTP content */ strcpy(httpcontent[2].name, "/infos"); httpcontent[2].wildcard = 0; httpcontent[2].cgi = cgi_info; httpcontent[2].next = &httpcontent[3]; /* Init HTTP content */ strcpy(httpcontent[3].name, "/"); httpcontent[3].wildcard = 1; httpcontent[3].cgi = cgi_ng_page; httpcontent[3].next = 0; /* Init HTTP socket */ httpsock[0].id = 4; httpsock[0].state = 0; httpsock[0].server = &http; httpsock[0].next = &httpsock[1]; /* Init HTTP socket */ httpsock[1].id = 5; httpsock[1].state = 0; httpsock[1].server = &http; httpsock[1].next = &httpsock[2]; /* Init HTTP socket */ httpsock[2].id = 6; httpsock[2].state = 0; httpsock[2].server = &http; httpsock[2].next = &httpsock[3]; /* Init HTTP socket */ httpsock[3].id = 7; httpsock[3].state = 0; httpsock[3].server = &http; httpsock[3].next = 0; /* Init the new HTTP layer */ http.port = 80; http.err404 = 0; http.err403 = 0; http.keepalive = 10; http.socks = &httpsock[0]; http.contents = &httpcontent[0]; http_init(&http); while(1) { http_run(&http); } }
/* OpenOCD can't really handle failure of this command. Patches welcome! :-) */ int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { if (argc!=0) return ERROR_COMMAND_SYNTAX_ERROR; int retval; static int initialized=0; if (initialized) return ERROR_OK; initialized=1; atexit(exit_handler); if (target_init(cmd_ctx) != ERROR_OK) return ERROR_FAIL; LOG_DEBUG("target init complete"); if ((retval=jtag_interface_init(cmd_ctx)) != ERROR_OK) { /* we must be able to set up the jtag interface */ return retval; } LOG_DEBUG("jtag interface init complete"); /* Try to initialize & examine the JTAG chain at this point, but * continue startup regardless */ if (jtag_init(cmd_ctx) == ERROR_OK) { LOG_DEBUG("jtag init complete"); if (target_examine() == ERROR_OK) { LOG_DEBUG("jtag examine complete"); } } if (flash_init_drivers(cmd_ctx) != ERROR_OK) return ERROR_FAIL; LOG_DEBUG("flash init complete"); if (mflash_init_drivers(cmd_ctx) != ERROR_OK) return ERROR_FAIL; LOG_DEBUG("mflash init complete"); if (nand_init(cmd_ctx) != ERROR_OK) return ERROR_FAIL; LOG_DEBUG("NAND init complete"); if (pld_init(cmd_ctx) != ERROR_OK) return ERROR_FAIL; LOG_DEBUG("pld init complete"); /* initialize tcp server */ server_init(); /* initialize telnet subsystem */ telnet_init("Open On-Chip Debugger"); gdb_init(); tcl_init(); /* allows tcl to just connect without going thru telnet */ target_register_event_callback(log_target_callback_event_handler, cmd_ctx); return ERROR_OK; }