Subversion Repositories shark

Rev

Rev 1190 | Rev 1550 | 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
 
11
#include "modules/sem.h"
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");
31
  sys_end();
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;
1190 giacomo 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;
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);
81
    /*!*/sprintf(msg, "buffer %d   ", bytes);
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);
104
    /*!*/sprintf(msg, "buffer2 %d   ", bytes);
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");
139
    sys_end();
140
    return(err);
141
  }
142
 
143
  sem_init(&m1, 0, 1);
144
 
145
 
146
  if ((handle = tftp_open("test.txt")) == -1) {
147
     cprintf("No slots available. Program aborted...\n");
148
     sys_end();
149
     return(1);
150
  }
151
 
152
  cprintf("Ctrl-A to proceed *** Ctrl-C to stop\n");
153
  wait();
154
  clear();
155
 
156
  cprintf("Handle = %d\n", handle);
157
 
158
  if ((err = tftp_upload(handle, 4096, &m1)) != 0) {
159
     cprintf("Error %d calling tftp_upload(). Program aborted...\n", err);
160
     sys_end();
161
     return(1);
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");
171
     sys_end();
172
     return(1);
173
  }
174
  if (task_activate(p1) == -1) {
175
     cprintf("Error activating test_upload task. Program aborted...\n");
176
     sys_end();
177
     return(1);
178
  }
179
 
180
 
181
  sem_init(&m2, 0, 1);
182
 
183
  if ((handle2 = tftp_open("test2.txt")) == -1) {
184
     cprintf("No second slot available. Program aborted...\n");
185
     sys_end();
186
     return(1);
187
  }
188
 
189
 
190
 
191
  cprintf("Handle2 = %d\n", handle2);
192
 
193
  if ((err = tftp_upload(handle2, 4096, &m2)) != 0) {
194
     cprintf("Error %d calling tftp_upload(). Program aborted...\n", err);
195
     sys_end();
196
     return(1);
197
  }
198
 
199
  /* First we set the sender's task properties...*/
200
  hard_task_default_model(hard_m);
201
  hard_task_def_wcet(hard_m, 10000);
202
  hard_task_def_mit(hard_m, 300000);
203
 
204
  if ((p2 = task_create("test_upload2", test_upload2, &hard_m, NULL)) == NIL) {
205
     cprintf("Error creating test_upload2 task. Program aborted...\n");
206
     sys_end();
207
     return(1);
208
  }
209
  if (task_activate(p2) == -1) {
210
     cprintf("Error activating test_upload2 task. Program aborted...\n");
211
     sys_end();
212
     return(1);
213
  }
214
 
215
 
216
  wait();
217
 
218
  tftp_close(handle, TFTP_STOP_NOW);
219
 
220
  tftp_close(handle2, TFTP_STOP_NOW);
221
 
222
  cprintf("\nProgram terminated correctly.\n");
223
  sys_end();
224
 
225
  return(0);
226
}