Rev 1552 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1190 | giacomo | 1 | #include <string.h> |
2 | #include <kernel/func.h> |
||
3 | #include <kernel/kern.h> |
||
1463 | giacomo | 4 | |
5 | #include <drivers/shark_keyb26.h> |
||
1190 | giacomo | 6 | #include <drivers/udpip.h> |
1463 | giacomo | 7 | |
1190 | giacomo | 8 | #include "tftp.h" |
9 | #include "endian.h" |
||
10 | |||
1552 | pj | 11 | #include "sem/sem/sem.h" |
1190 | giacomo | 12 | |
13 | #include <kernel/kern.h> |
||
14 | #include <ll/i386/hw-instr.h> |
||
15 | |||
16 | |||
17 | #define LOCAL_HOST_IP "192.168.0.134" |
||
18 | #define REMOTE_HOST_IP "192.168.0.133" |
||
19 | |||
20 | sem_t m1, m2; |
||
21 | int handle, handle2; |
||
22 | |||
23 | int prog = 0; |
||
24 | |||
25 | /* This function is called when the user presses CTRL-C (stops the systems) */ |
||
26 | |||
27 | void esci(KEY_EVT *k) |
||
28 | { |
||
1463 | giacomo | 29 | sys_shutdown_message("Exit from the program...\n"); |
30 | sys_shutdown_message("Ctrl-C pressed!\n"); |
||
1550 | pj | 31 | exit(1); |
1190 | giacomo | 32 | } |
33 | |||
34 | void augprog(KEY_EVT *k) |
||
35 | { |
||
36 | prog = 1; |
||
37 | } |
||
38 | |||
39 | void keyb_start(void) { |
||
40 | KEY_EVT k; |
||
41 | |||
42 | k.flag = CNTL_BIT; |
||
43 | k.scan = KEY_C; |
||
1463 | giacomo | 44 | k.status = KEY_PRESSED; |
1600 | tullio | 45 | k.ascii = 'c'; |
1463 | giacomo | 46 | keyb_hook(k, esci,FALSE); |
1190 | giacomo | 47 | k.flag = CNTR_BIT; |
48 | k.scan = KEY_C; |
||
49 | k.ascii = 'c'; |
||
1463 | giacomo | 50 | k.status = KEY_PRESSED; |
51 | keyb_hook(k, esci,FALSE); |
||
1190 | giacomo | 52 | |
53 | k.flag = CNTL_BIT; |
||
54 | k.scan = KEY_A; |
||
1600 | tullio | 55 | k.ascii = 'a'; |
1463 | giacomo | 56 | k.status = KEY_PRESSED; |
57 | keyb_hook(k, augprog,FALSE); |
||
1190 | giacomo | 58 | k.flag = CNTR_BIT; |
59 | k.scan = KEY_A; |
||
60 | k.ascii = 'a'; |
||
1463 | giacomo | 61 | k.status = KEY_PRESSED; |
62 | keyb_hook(k, augprog,FALSE); |
||
1190 | giacomo | 63 | } |
64 | |||
65 | TASK test_upload(void *arg) { |
||
66 | int i; |
||
67 | char msg[200]; |
||
68 | int bytes; |
||
69 | |||
70 | i = 0; |
||
71 | while (1) { |
||
72 | |||
73 | // cprintf("uploader 1\n"); |
||
74 | |||
75 | sprintf(msg, "tftptest says: i = %5d\n", i); |
||
76 | tftp_put(handle, msg, strlen(msg)); |
||
77 | |||
78 | // cprintf("uploader 2\n"); |
||
79 | |||
80 | bytes = tftp_usedbuffer(handle); |
||
1600 | tullio | 81 | /*!*/sprintf(msg, "buffer %5d ", bytes); |
1190 | giacomo | 82 | /*!*/puts_xy(BASE_X, 18, WHITE, msg); |
83 | |||
84 | // cprintf("uploader 3\n"); |
||
85 | i++; |
||
86 | |||
87 | task_endcycle(); |
||
88 | } |
||
89 | return(0); |
||
90 | } |
||
91 | |||
92 | TASK test_upload2(void *arg) { |
||
93 | int i; |
||
94 | char msg[200]; |
||
95 | int bytes; |
||
96 | |||
97 | i = 0; |
||
98 | while (1) { |
||
99 | |||
100 | sprintf(msg, "tftptest says: i = %5d\n", i); |
||
101 | tftp_put(handle2, msg, strlen(msg)); |
||
102 | |||
103 | bytes = tftp_usedbuffer(handle2); |
||
1600 | tullio | 104 | /*!*/sprintf(msg, "buffer2 %5d ", bytes); |
1190 | giacomo | 105 | /*!*/puts_xy(BASE_X, 38, WHITE, msg); |
106 | i++; |
||
107 | |||
108 | task_endcycle(); |
||
109 | } |
||
110 | return(0); |
||
111 | } |
||
112 | |||
113 | void wait() { |
||
114 | char ch; |
||
115 | do { |
||
116 | ch = keyb_getch(NON_BLOCK); |
||
117 | } while(prog == 0); |
||
118 | prog = 0; |
||
119 | } |
||
120 | |||
121 | int main(void) |
||
122 | { |
||
123 | int err; |
||
124 | HARD_TASK_MODEL hard_m; |
||
125 | PID p1, p2; |
||
126 | |||
127 | keyb_start(); |
||
128 | cprintf("main: Keyboard handler started\n"); |
||
129 | |||
130 | tftp_init(); |
||
131 | cprintf("main: Tftp library initialized\n"); |
||
132 | |||
133 | err = tftp_net_start(LOCAL_HOST_IP, REMOTE_HOST_IP, 1); |
||
134 | cprintf("netval = %d\n", err); |
||
135 | if (err == 1) { |
||
136 | cprintf("Net Init from %s to %s\n", LOCAL_HOST_IP, REMOTE_HOST_IP); |
||
137 | } else { |
||
138 | cprintf("Net Init Failed...\n"); |
||
1550 | pj | 139 | exit(1); |
1190 | giacomo | 140 | } |
141 | |||
142 | sem_init(&m1, 0, 1); |
||
143 | |||
144 | |||
145 | if ((handle = tftp_open("test.txt")) == -1) { |
||
146 | cprintf("No slots available. Program aborted...\n"); |
||
1550 | pj | 147 | exit(1); |
1190 | giacomo | 148 | } |
149 | |||
1600 | tullio | 150 | cprintf("NOTE: if you use a Linux TFTP server, remember that the two files\n"); |
151 | cprintf(" to be written MUST exists on the server,\n"); |
||
152 | cprintf(" and must have the right permissions\n"); |
||
1190 | giacomo | 153 | cprintf("Ctrl-A to proceed *** Ctrl-C to stop\n"); |
154 | wait(); |
||
155 | clear(); |
||
156 | |||
157 | cprintf("Handle = %d\n", handle); |
||
158 | |||
159 | if ((err = tftp_upload(handle, 4096, &m1)) != 0) { |
||
160 | cprintf("Error %d calling tftp_upload(). Program aborted...\n", err); |
||
1550 | pj | 161 | exit(1); |
1190 | giacomo | 162 | } |
163 | |||
164 | /* First we set the sender's task properties...*/ |
||
165 | hard_task_default_model(hard_m); |
||
166 | hard_task_def_wcet(hard_m, 10000); |
||
167 | hard_task_def_mit(hard_m, 300000); |
||
168 | |||
169 | if ((p1 = task_create("test_upload", test_upload, &hard_m, NULL)) == NIL) { |
||
170 | cprintf("Error creating test_upload task. Program aborted...\n"); |
||
1550 | pj | 171 | exit(1); |
1190 | giacomo | 172 | } |
173 | if (task_activate(p1) == -1) { |
||
174 | cprintf("Error activating test_upload task. Program aborted...\n"); |
||
1550 | pj | 175 | exit(1); |
1190 | giacomo | 176 | } |
177 | |||
178 | |||
179 | sem_init(&m2, 0, 1); |
||
180 | |||
181 | if ((handle2 = tftp_open("test2.txt")) == -1) { |
||
182 | cprintf("No second slot available. Program aborted...\n"); |
||
1550 | pj | 183 | exit(1); |
1190 | giacomo | 184 | } |
185 | |||
186 | |||
187 | |||
188 | cprintf("Handle2 = %d\n", handle2); |
||
189 | |||
190 | if ((err = tftp_upload(handle2, 4096, &m2)) != 0) { |
||
191 | cprintf("Error %d calling tftp_upload(). Program aborted...\n", err); |
||
1550 | pj | 192 | exit(1); |
1190 | giacomo | 193 | } |
194 | |||
195 | /* First we set the sender's task properties...*/ |
||
196 | hard_task_default_model(hard_m); |
||
197 | hard_task_def_wcet(hard_m, 10000); |
||
198 | hard_task_def_mit(hard_m, 300000); |
||
199 | |||
200 | if ((p2 = task_create("test_upload2", test_upload2, &hard_m, NULL)) == NIL) { |
||
201 | cprintf("Error creating test_upload2 task. Program aborted...\n"); |
||
1550 | pj | 202 | exit(1); |
1190 | giacomo | 203 | } |
204 | if (task_activate(p2) == -1) { |
||
205 | cprintf("Error activating test_upload2 task. Program aborted...\n"); |
||
1550 | pj | 206 | exit(1); |
1190 | giacomo | 207 | } |
208 | |||
209 | |||
210 | wait(); |
||
211 | |||
212 | tftp_close(handle, TFTP_STOP_NOW); |
||
213 | |||
214 | tftp_close(handle2, TFTP_STOP_NOW); |
||
215 | |||
216 | cprintf("\nProgram terminated correctly.\n"); |
||
217 | |||
1550 | pj | 218 | exit(0); |
219 | |||
1190 | giacomo | 220 | return(0); |
221 | } |