Subversion Repositories shark

Rev

Rev 1600 | Details | Compare with Previous | Last modification | View Log | RSS feed

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