Subversion Repositories shark

Rev

Rev 1191 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1097 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/*
22
 * Copyright (C) 2000 Massimiliano Giorgi
23
 * Copyright (C) 2002 Paolo Gai
24
 *
25
 * This program is free software; you can redistribute it and/or modify
26
 * it under the terms of the GNU General Public License as published by
27
 * the Free Software Foundation; either version 2 of the License, or
28
 * (at your option) any later version.
29
 *
30
 * This program is distributed in the hope that it will be useful,
31
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
 * GNU General Public License for more details.
34
 *
35
 * You should have received a copy of the GNU General Public License
36
 * along with this program; if not, write to the Free Software
37
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38
 *
39
 * CVS :        $Id: udptrace.c,v 1.1 2002-10-28 08:10:11 pj Exp $
40
 */
41
 
42
/*
43
 * Example of tracer initialization.
44
 */
45
 
46
#include <ll/i386/cons.h>
47
 
48
#include <kernel/func.h>
49
#include <kernel/trace.h>
50
 
51
#include <fs/bdevinit.h>
52
#include <fs/fsinit.h>
53
#include <fs/bdev.h>
54
 
55
#include <drivers/keyb.h>
56
#include <drivers/udpip.h>
57
 
58
#include <trace/trace.h>
59
#include <trace/queues.h>
60
 
61
#include <sys/mount.h>
62
#include <stddef.h>
63
#include <string.h>
64
 
65
char myipaddr[15], toipaddr[15];
66
 
67
void mytracer_prologue(void)
68
{
69
  int myqueue;
70
  TRC_PARMS p;
71
  TRC_UDP_PARMS u;
72
  UDP_ADDR local, remote;
73
 
74
  /* these are the IP numbers of my home PCs ;-) */
75
  strcpy(myipaddr, "192.168.1.2");
76
  strcpy(toipaddr, "192.168.1.1");
77
 
78
  clear();
79
 
80
  ip_str2addr(toipaddr,&(remote.s_addr));
81
  remote.s_port = 20000; // htons is done automatically;
82
  ip_str2addr(myipaddr,&(local.s_addr));
83
  local.s_port = 20000;  // htons is done automatically;
84
 
85
  trc_default_parms(p);
86
  trc_def_path(p,"");
87
 
88
  trc_udp_default_parms(u,local,remote);
89
 
90
  /* Tracer Initialization */
91
  /* the first functions to call... parameters can be passed */
92
  TRC_init_phase1(&p);
93
 
94
  /* all the tracer queue types must be registered */
95
  trc_register_udp_queue();
96
 
97
  /* then, we create all the queues we need */
98
  myqueue = trc_create_queue(TRC_UDP_QUEUE,&u);
99
 
100
  /* Then, we say that events must be sent to a particular queue */
101
  trc_trace_class(TRC_CLASS_SYSTEM);
102
  trc_assign_class_to_queue(TRC_CLASS_SYSTEM, myqueue);
103
}
104
 
105
void mytracer_epilogue(void)
106
{
107
  struct net_model m = net_base;
108
 
109
 
110
  /* We want a task for TX mutual exclusion */
111
  net_setmode(m, TXTASK);
112
  /* We use UDP/IP stack */
113
  net_setudpip(m, myipaddr);
114
  /* OK: let's start the NetLib! */
115
  if (net_init(&m) == 1) {
116
    cprintf("udptrace: Net Init OK...\n");
117
  } else {
118
    cprintf("udptrace: Net Init Failed...\n");
119
    sys_abort(300);
120
  }
121
 
122
  TRC_init_phase2();
123
}
124
 
125
void ctrlc_exit(KEY_EVT *k)
126
{
127
  sys_end();
128
}
129
 
130
void *mytask(void *arg)
131
{
132
  int i;
133
 
134
  for(i=0; i<10; i++) {
135
    cprintf("%d\n", i);
136
    task_endcycle();
137
  }
138
 
139
  return 0;
140
}
141
 
142
int main(int argc,char *argv[])
143
{
144
  SOFT_TASK_MODEL mp;
145
 
146
  PID pid;
147
 
148
  soft_task_default_model(mp);
149
  soft_task_def_met(mp, 10000);
150
  soft_task_def_period(mp,50000);
151
  soft_task_def_usemath(mp);
152
 
153
  cprintf("\nHello, world!\n");
154
 
155
  pid = task_create("mytask", mytask, &mp, NULL);
156
 
157
  if (pid != NIL) task_activate(pid);
158
 
159
  return 0;
160
}