OpenCores
URL https://opencores.org/ocsvn/tcp_socket/tcp_socket/trunk

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [source/] [user_design.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jondawson
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  CHIPS-2.0 USER DESIGN
4
//
5
//  :Author: Jonathan P Dawson
6
//  :Date: 17/10/2013
7
//  :email: chips@jondawson.org.uk
8
//  :license: MIT
9
//  :Copyright: Copyright (C) Jonathan P Dawson 2013
10
//
11
//  Simple web app demo.
12
//
13
////////////////////////////////////////////////////////////////////////////////
14
 
15
void put_socket(unsigned i){
16
        output_socket(i);
17
}
18
void stdout_put_char(unsigned i){
19
        output_rs232_tx(i);
20
}
21
 
22
#include "print.h"
23
#include "HTTP.h"
24
 
25
int find(unsigned string[], unsigned search, unsigned start, unsigned end){
26
        int value = start;
27
        while(string[value]){
28
               print_decimal(string[value]); print_string("\n");
29
               print_decimal(value); print_string("\n");
30
               if(value == end) return -1;
31
               if(string[value] == search) return value;
32
               value++;
33
        }
34
        return -1;
35
}
36
 
37
void user_design()
38
{
39
        //simple echo application
40
        unsigned length;
41
        unsigned i, index;
42
        unsigned data[1460];
43
        unsigned word;
44
        unsigned switches = 0;
45
        unsigned buttons = 0;
46
        unsigned leds = 0;
47
        unsigned start, end;
48
 
49
        unsigned page[] =
50
"<html>\
51
<head>\
52
<title>Chips-2.0 ATLYS Demo</title>\
53
</head>\
54
<body>\
55
<h1>Chips-2.0 ATLYS Demo</h1>\
56
<p>Welcome to the Chips-2.0 ATLYS Demo!</p>\
57
<p>Switch Status: 00000000</p>\
58
<p>Button Status: 0000</p>\
59
<form>\
60
        <input type=\"checkbox\" name=\"led1\" value=\"A\">led 0</input>\
61
        <input type=\"checkbox\" name=\"led2\" value=\"B\">led 1</input>\
62
        <input type=\"checkbox\" name=\"led3\" value=\"C\">led 2</input>\
63
        <input type=\"checkbox\" name=\"led4\" value=\"D\">led 3</input>\
64
        <input type=\"checkbox\" name=\"led4\" value=\"E\">led 4</input>\
65
        <input type=\"checkbox\" name=\"led4\" value=\"F\">led 5</input>\
66
        <input type=\"checkbox\" name=\"led4\" value=\"G\">led 6</input>\
67
        <input type=\"checkbox\" name=\"led4\" value=\"H\">led 7</input>\
68
        <button type=\"sumbit\" value=\"Submit\">Update LEDs</button>\
69
</form>\
70
<p>This <a href=\"https://github.com/dawsonjon/Chips-Demo\">project</a>\
71 5 jondawson
 is powered by <a href=\"http://pyandchips.org\">Chips-2.0</a>.</p>\
72 3 jondawson
</body>\
73
</html>";
74
 
75
        print_string("Welcome to the Atlys Chips-2.0 demo!\n");
76
        print_string("Connect your web browser to 192.168.1.1\n");
77
        while(1){
78
 
79
                length = input_socket();
80
                index = 0;
81
                for(i=0;i<length;i+=2){
82
                        word = input_socket();
83
                        data[index] = (word >> 8) & 0xff;
84
                        index++;
85
                        data[index] = (word) & 0xff;
86
                        index++;
87
                }
88
 
89
                //Get LED values
90
                //==============
91
 
92
                if(   data[0] == 'G'
93
                   && data[1] == 'E'
94
                   && data[2] == 'T'
95
                   && data[3] == ' '
96
                   && data[4] == '/'
97
                   && (data[5] == '?' || data[5] == ' ')){
98
                        start=5;
99
                        end=find(data, ' ', start, index);
100
                        leds = 0;
101
                        if(find(data, 'A', start, end) != -1) leds |= 1;
102
                        if(find(data, 'B', start, end) != -1) leds |= 2;
103
                        if(find(data, 'C', start, end) != -1) leds |= 4;
104
                        if(find(data, 'D', start, end) != -1) leds |= 8;
105
                        if(find(data, 'E', start, end) != -1) leds |= 16;
106
                        if(find(data, 'F', start, end) != -1) leds |= 32;
107
                        if(find(data, 'G', start, end) != -1) leds |= 64;
108
                        if(find(data, 'H', start, end) != -1) leds |= 128;
109
                        output_leds(leds);
110
 
111
                        //read switch values
112
                        //==================
113
                        switches = ~input_switches();
114
                        //find first ':'
115
                        index = find(page, ':', 0, 1460);
116
                        index+=2;
117
                        //insert switch values
118
                        if(switches & 128) page[index] = '0';
119
                        else page[index] = '1';
120
                        index ++;
121
                        if(switches & 64) page[index] = '0';
122
                        else page[index] = '1';
123
                        index ++;
124
                        if(switches & 32) page[index] = '0';
125
                        else page[index] = '1';
126
                        index ++;
127
                        if(switches & 16) page[index] = '0';
128
                        else page[index] = '1';
129
                        index ++;
130
                        if(switches & 8) page[index] = '0';
131
                        else page[index] = '1';
132
                        index ++;
133
                        if(switches & 4) page[index] = '0';
134
                        else page[index] = '1';
135
                        index ++;
136
                        if(switches & 2) page[index] = '0';
137
                        else page[index] = '1';
138
                        index ++;
139
                        if(switches & 1) page[index] = '0';
140
                        else page[index] = '1';
141
 
142
                        //read button values
143
                        //==================
144
                        buttons = ~input_buttons();
145
                        //find next ':'
146
                        index = find(page, ':', index+1, 1460);
147
                        index+=2;
148
                        //insert button values
149
                        if(buttons & 1) page[index] = '0';
150
                        else page[index] = '1';
151
                        index ++;
152
                        if(buttons & 2) page[index] = '0';
153
                        else page[index] = '1';
154
                        index ++;
155
                        if(buttons & 4) page[index] = '0';
156
                        else page[index] = '1';
157
                        index ++;
158
                        if(buttons & 8) page[index] = '0';
159
                        else page[index] = '1';
160
 
161
                        HTTP_OK(page);
162
                } else {
163
                        HTTP_Not_Found();
164
                }
165
 
166
        }
167
 
168
        //dummy access to peripherals
169
        index = input_rs232_rx();
170
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.