Subversion Repositories shark

Rev

Rev 1550 | Rev 1600 | 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;
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");
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
 
150
  cprintf("Ctrl-A to proceed *** Ctrl-C to stop\n");
151
  wait();
152
  clear();
153
 
154
  cprintf("Handle = %d\n", handle);
155
 
156
  if ((err = tftp_upload(handle, 4096, &m1)) != 0) {
157
     cprintf("Error %d calling tftp_upload(). Program aborted...\n", err);
1550 pj 158
     exit(1);
1190 giacomo 159
  }
160
 
161
  /* First we set the sender's task properties...*/
162
  hard_task_default_model(hard_m);
163
  hard_task_def_wcet(hard_m, 10000);
164
  hard_task_def_mit(hard_m, 300000);
165
 
166
  if ((p1 = task_create("test_upload", test_upload, &hard_m, NULL)) == NIL) {
167
     cprintf("Error creating test_upload task. Program aborted...\n");
1550 pj 168
     exit(1);
1190 giacomo 169
  }
170
  if (task_activate(p1) == -1) {
171
     cprintf("Error activating test_upload task. Program aborted...\n");
1550 pj 172
     exit(1);
1190 giacomo 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");
1550 pj 180
     exit(1);
1190 giacomo 181
  }
182
 
183
 
184
 
185
  cprintf("Handle2 = %d\n", handle2);
186
 
187
  if ((err = tftp_upload(handle2, 4096, &m2)) != 0) {
188
     cprintf("Error %d calling tftp_upload(). Program aborted...\n", err);
1550 pj 189
     exit(1);
1190 giacomo 190
  }
191
 
192
  /* First we set the sender's task properties...*/
193
  hard_task_default_model(hard_m);
194
  hard_task_def_wcet(hard_m, 10000);
195
  hard_task_def_mit(hard_m, 300000);
196
 
197
  if ((p2 = task_create("test_upload2", test_upload2, &hard_m, NULL)) == NIL) {
198
     cprintf("Error creating test_upload2 task. Program aborted...\n");
1550 pj 199
     exit(1);
1190 giacomo 200
  }
201
  if (task_activate(p2) == -1) {
202
     cprintf("Error activating test_upload2 task. Program aborted...\n");
1550 pj 203
     exit(1);
1190 giacomo 204
  }
205
 
206
 
207
  wait();
208
 
209
  tftp_close(handle, TFTP_STOP_NOW);
210
 
211
  tftp_close(handle2, TFTP_STOP_NOW);
212
 
213
  cprintf("\nProgram terminated correctly.\n");
214
 
1550 pj 215
  exit(0);
216
 
1190 giacomo 217
  return(0);
218
}