Subversion Repositories shark

Rev

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