Web server porting 2 Jo, Heeseung
Web 을이용한 LED 제어 Web 을이용한 LED 제어프로그램 web 에서데이터를전송받아타겟보드의 LED 를조작하는프로그램을작성하기위해다음과같은소스파일을생성 2
Web 을이용한 LED 제어 LED 제어프로그램작성 8bitled.html 파일을작성 root@ubuntu:/working/web# vi 8bitled.html ---------------- 다음과같이수정한다 ------------------------ <html> <head><title> 8bit led cgi program</title></head> <body> <form method=get action="cgi-bin/8bitled.cgi"> <p><p><p> 십육진수값을 2 자리로입력하세요 : <input type="text" name="value" maxlength="2" size="2"> <input type="submit" name="button" value="input"></form> </body> </html> ------------------ 저장하고종료한다 ------------------------- 3
Web 을이용한 LED 제어 8bitled.c 파일을작성 root@ubuntu:/working/web# vi 8bitled.c 001: #include <stdio.h> 002: #include <stdlib.h> 003: #include <unistd.h> 004: #include <sys/types.h> 005: #include <sys/mman.h> 006: #include <sys/stat.h> 007: #include <fcntl.h> 008: #include <sys/ioctl.h> 009: #include <termios.h> 010: 011: #define FPGA_BASEADDRESS 0x05000000 012: #define LED_OFFSET 0x20 013: 014: typedef struct { 015: char name[128]; 016: char val[128]; 017: }entry; 018: 4
Web 을이용한 LED 제어 019: void getword(char *word, char *line, char stop) 020: { 021: int x =0, y = 0; 022: 023: for(x=0;((line[x]) && (line[x]!= stop)); x++) word[x] = line[x]; 024: 025: word[x] = '\0'; 026: if(line[x]) ++x; 027: 028: while(line[y++] = line[x++]); 029: } 030: 031: int main() 032: { 033: int fd; 034: unsigned short *addr_fpga, *addr_led; 035: 036: char *cl; 037: unsigned short val; 038: entry entries; 039: 5
Web 을이용한 LED 제어 040: printf("content-type : text/html\n\n"); 041: printf("<html>\n<head><title>8bit LED cgi program</title></head>\n"); 042: printf("<body>\n"); 043: 044: cl = (char *)getenv("query_string"); 045: getword(entries.name,cl,'='); 046: getword(entries.val,cl,'&'); 047: 048: val = (unsigned short)strtol(entries.val,null,16); 049: 050: if(val == 0) { 051: if(!((entries.val[0] == '0' && entries.val[1] == '\0') (entries.val[0] == '0' && entries.val[1] == '0'))) { 052: printf("<p>you entered the wrong value!"); 053: exit(1); 054: } 055: } 056: 057: if((fd=open("/dev/mem",o_rdwr O_SYNC)) < 0) { 058: printf("mem open fail, %d\n", fd); 6
Web 을이용한 LED 제어 059: exit(1); 060: } 061: 062: addr_fpga= (unsigned short *)mmap(null, 4096, PROT_READ PROT_WRITE, MAP_SHARED, fd, FPGA_BASEADDRESS); 063: addr_led = addr_fpga + LED_OFFSET/sizeof(unsigned short); 064: 065: *addr_led = val 0x100; 066: 067: munmap(addr_fpga, 4096); 068: close(fd); 069: 070: printf("<br><center>you entered <b>'0x%x'</b></center>",val); 071: printf("<hr>"); 072: printf("</body>\n</html>"); 073: 074: return 0; 075: } 7
Web 을이용한 LED 제어 LED 제어프로그램컴파일 작성된 LED 제어소스를컴파일 root@ubuntu:/working/web# arm-linux-gcc -o 8bitled.cgi 8bitled.c 타겟보드에 LED 제어프로그램다운로드 타겟보드에 8bitled.html 과 8bitled.cgi 파일을 /web 과 /web/cgi-bin 디렉터리로복사 [root@sm5s4210 ~]# mv 8bitled.html /web/ [root@sm5s4210 ~]# mv 8bitled.cgi /web/cgi-bin/ 8
Web 을이용한 LED 제어 LED 제어페이지실행확인 호스트 PC 의웹브라우저로웹서버에접속 웹브라우저를실행시키고주소창에 http://192.168.0.150/ 8bitled.html 을입력 9
Web 을이용한 LED 제어 LED 제어페이지실행확인 텍스트상자에십육진수두자리를입력하고 input버튼을클릭 결과확인 10
Web 을이용한 7 Segment 제어프로그램 web 에서데이터를전송받아타겟보드의 7 Segment 제어프로그램을작성하기위해다음과같이소스파일을생성 7segment.html 파일을작성 root@ubuntu:/working/web# vi 7segment.html <html> <head><title> 7segment cgi program</title></head> <body> <form method=get action="cgi-bin/7segment.cgi"> <p><p><p>7-segment 에표시할십진수를입력하세요. <input type="text" name="value" maxlength="6" size="6"> <input type="submit" name="button" value="input"> </form> </body> </html> 11
7segment.c 파일작성 root@ubuntu:/working/web# vi 7segment.c 001: -------------------------- 다음과같이수정한다 ------------------------ 002: /********************************************************************** 003: * 7-Segment CGI Program 004: **********************************************************************/ 005: 006: #define FPGA_BASEADDRESS 0x05000000 007: #define SEG_GRID_OFFSET 0x30 008: #define SEG_DATA_OFFSET 0x32 009: 010: typedef struct { 011: char name[128]; 012: char val[128]; 12
013: }entry; 014: 015: void getword(char *word, char *line, char stop) 016: { 017: int x =0, y = 0; 018: 019: for(x=0;((line[x]) && (line[x]!= stop)); x++) word[x] = line[x]; 020: 021: word[x] = '\0'; 022: if(line[x]) ++x; 023: 024: while(line[y++] = line[x++]); 025: } 026: 027: int sizeofword(char *word) 028: { 029: int i=0; 030: for(i=0;i<10;i++) { 031: if(word[i] == '\0') break; 032: } 033: return i; 13
034: } 035: 036: unsigned int Getsegcode(char x) 037: { 038: unsigned int code; 039: switch (x) { 040: case '0' : code = 0xfc; break; 041: case '1' : code = 0x60; break; 042: case '2' : code = 0xda; break; 043: case '3' : code = 0xf2; break; 044: case '4' : code = 0x66; break; 045: case '5' : code = 0xb6; break; 046: case '6' : code = 0xbe; break; 047: case '7' : code = 0xe4; break; 048: case '8' : code = 0xfe; break; 049: case '9' : code = 0xf6; break; 050: case 'a' : 051: case 'A' : code = 0xfa; break; 052: case 'b' : 053: case 'B' : code = 0x3e; break; 054: case 'c' : 055: case 'C' : code = 0x1a; break; 14
056: case 'd' : 057: case 'D' : code = 0x7a; break; 058: case 'e' : 059: case 'E' : code = 0x9e; break; 060: case 'f' : 061: case 'F' : code = 0x8e; break; 062: default : code = 0; break; 063: } 064: return code; 065: } 066: 067: int main() 068: { 069: char *cl; 070: int k; 071: unsigned int low = 0,high = 0; 072: entry entries; 073: unsigned short digit[6] = {0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; 074: unsigned short data[6]; 075: int i,j,m; 076: int fd; 077: unsigned short *addr_fpga; 15
078: unsigned short *addr_grid, *addr_data; 079: 080: printf("content-type: text/html\n\n"); 081: printf("<html>\n<head><title>7-segment cgi program</title></head>\n"); 082: printf("<body>\n"); 083: 084: if((fd=open("/dev/mem",o_rdwr O_SYNC)) < 0) { 085: printf("mem open fail\n"); 086: exit(1); 087: } 088: 089: addr_fpga= (unsigned short *)mmap(null, 4096, PROT_READ PROT_WRITE, MAP_SHARED, fd, FPGA_BASEADDRESS); 090: addr_grid=addr_fpga+seg_grid_offset/sizeof(unsigned short); 091: addr_data=addr_fpga+seg_data_offset/sizeof(unsigned short); 092: 093: if(addr_grid < 0 addr_data < 0) { 094: close(fd); 095: printf("mmap error\n"); 096: exit(1); 097: } 16
098: 099: cl = (char *)getenv("query_string"); 100: getword(entries.name,cl,'='); 101: getword(entries.val,cl,'&'); 102: k = sizeofword(entries.val); 103: 104: for(i=0; i<k; i++) 105: data[(k-i)-1] = Getsegcode(entries.val[i]); 106: 107: for(j=0;j<200;j++) { 108: for(i=0; i<k; i++) { 109: *addr_grid = digit[i]; 110: *addr_data = data[i]; 111: for(m=0;m<65536;m++); 112: } 113: } 114: 115: *addr_grid = ~digit[0]; 116: *addr_data = 0; 117: 17
118: munmap(addr_grid, 4096); 119: munmap(addr_data, 4096); 120: close(fd); 121: 122: if( k!= 0) printf("<br><center>7-segment Done<br></center>"); 123: else printf("<br><center>you entered the wrong value!<br></center>"); 124: 125: printf("<hr>"); 126: printf("</body>\n</html>"); 127: return 0; 128: } 18
7Segment 제어프로그램컴파일 작성된 7Segment.c 를컴파일 root@ubuntu:/working/web# arm-linux-gcc -o 7segment.cgi 7segment.c 타겟보드에 7Segment 제어프로그램다운로드 타겟보드에서 7segment.html 과 7segment.cgi 파일을 /web 과 /web/cgi-bin 디렉터리로복사 [root@sm5s4210 ~]# mv 7segment.html /web/ [root@sm5s4210 ~]# mv 7segment.cgi /web/cgi-bin/ 19
7Segment 제어페이지실행확인 호스트 PC 의웹브라우저로웹서버에접속 웹브라우저를실행시키고주소창에 http://192.168.0.150/ 7segment.html 을입력 20
7Segment 제어페이지실행확인 텍스트상자에십진수 6 자리를입력하고 input버튼을클릭 결과확인 21