/demos/trunk/network/initfile.c |
---|
0,0 → 1,161 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
* |
* Authors : Mauro Marinoni <mauro.marinoni@unipv.it> |
* (see authors.txt for full list of hartik's authors) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://hartik.sssup.it |
*/ |
/* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
*/ |
#include <kernel/kern.h> |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/intdrive.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include <drivers/shark_linuxc26.h> |
#include <drivers/shark_pci26.h> |
#include <drivers/shark_input26.h> |
#include <drivers/shark_keyb26.h> |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
/*+ Interrupt Server +*/ |
#define INTDRIVE_Q 1000 |
#define INTDRIVE_T 10000 |
#define INTDRIVE_FLAG 0 |
void call_shutdown_task(void *arg); |
int device_drivers_init(); |
int device_drivers_close(); |
void set_shutdown_task(); |
TASK shutdown_task_body(void *arg); |
PID shutdown_task_PID = 1; |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_T, INTDRIVE_FLAG); |
EDF_register_level(EDF_ENABLE_ALL); |
CBS_register_level(CBS_ENABLE_ALL, 1); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
SEM_register_module(); |
return TICK; |
} |
int device_drivers_close() { |
KEYB26_close(); |
INPUT26_close(); |
return 0; |
} |
int device_drivers_init() { |
KEYB_PARMS kparms = BASE_KEYB; |
LINUXC26_register_module(); |
PCI26_init(); |
INPUT26_init(); |
/*keyb_def_map(kparms, KEYMAP_IT);*/ |
keyb_def_ctrlC(kparms, NULL); |
KEYB26_init(&kparms); |
return 0; |
} |
TASK shutdown_task_body(void *arg) { |
device_drivers_close(); |
sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
sys_abort_shutdown(0); |
return NULL; |
} |
#define SHUTDOWN_TIMEOUT_SEC 3 |
void set_shutdown_task() { |
NRT_TASK_MODEL nrt; |
nrt_task_default_model(nrt); |
nrt_task_def_system(nrt); |
shutdown_task_PID = task_create("Shutdown Task", shutdown_task_body, &nrt, NULL); |
if (shutdown_task_PID == NIL) { |
sys_shutdown_message("Error: Cannot create shutdown task\n"); |
sys_end(); |
} |
} |
void call_shutdown_task(void *arg) { |
struct timespec t; |
sys_gettime(&t); |
t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
task_activate(shutdown_task_PID); |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
HARTPORT_init(); |
set_shutdown_task(); |
device_drivers_init(); |
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
__call_main__(mb); |
return (void *)0; |
} |
/demos/trunk/network/net.c |
---|
0,0 → 1,82 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Giacomo Guidi <giacomo@gandalf.sssup.it> |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
#include <kernel/kern.h> |
#include <drivers/udpip.h> |
#include <stdlib.h> |
#include <string.h> |
#include <unistd.h> |
/* Init the network stack */ |
int init_network(char *local_ip) |
{ |
struct net_model m = net_base; |
net_setudpip(m, local_ip, "255.255.255.255"); |
if (net_init(&m) != 1) { |
cprintf("Network: Init Error.\n"); |
return -1; |
} |
return 0; |
} |
int main(int argc, char **argv) |
{ |
UDP_ADDR target, local; |
char local_ip[20], target_ip[20], buff[10]; |
int socket, i; |
IP_ADDR bindlist[5]; |
strcpy(local_ip, "192.168.1.10"); |
strcpy(target_ip, "192.168.1.1"); |
if (init_network(local_ip)) sys_end(); |
/* local IP string to addr */ |
ip_str2addr(local_ip,&(local.s_addr)); |
/* set the source port */ |
local.s_port = 100; |
/* target IP string to addr */ |
ip_str2addr(target_ip,&(bindlist[0])); |
memset(&(bindlist[1]), 0, sizeof(IP_ADDR)); |
/* bind */ |
socket = udp_bind(&local, NULL); |
/* target IP string to addr */ |
ip_str2addr(target_ip,&(target.s_addr)); |
/* target port */ |
target.s_port = 100; |
for (i = 0; i < 5; i++) { |
strcpy(buff, "qwerty\n"); |
cprintf("Send packet: %s\n", buff); |
udp_sendto(socket, buff, strlen(buff), &target); |
sleep(1); |
} |
cprintf("The End.\n"); |
sys_end(); |
return 0; |
} |
/demos/trunk/network/talk.c |
---|
0,0 → 1,215 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Paolo Gai <pj@gandalf.sssup.it> |
* (see the web pages for full authors list) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/* |
* Copyright (C) 2000 Luca Abeni, Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* |
* CVS : $Id: aster1.c,v 1.1 2002/10/28 08:13:37 pj Exp |
This is the talkdx.c Hartik's example. |
File: Talk.C |
Revision: 1.00 |
Author: Luca Abeni |
Simple Netlib demo: nothing of seriously real-time, only another Unix |
Talk clone. |
Read it to see how the UDP/IP layers of the networ library work. |
*/ |
#include <kernel/kern.h> |
#include <string.h> |
#include <drivers/crtwin.h> |
#include <drivers/shark_keyb26.h> |
#include <drivers/udpip.h> |
WIN dbg; |
BYTE esc = FALSE; |
char talk_myipaddr[20]; |
char talk_toipaddr[20]; |
/* |
This non real-time task reads UDP packets from the network and writes |
them in a window |
*/ |
TASK scrittore(void) |
{ |
char str[2000]; |
UDP_ADDR from, local; |
WIN displ; |
int s,n; |
/* Connect on the local port #100 */ |
local.s_port = 100; |
s = udp_bind(&local, NULL); |
/* Open the window */ |
win_init(&displ,0,0,79,6); |
win_frame(&displ,BLACK,WHITE,"Remote",2); |
while (1) { |
/* Clear the buffer for receiving the packet...*/ |
memset(str, 0, 1999); |
/*...and receive the packet (block until a packet arrives */ |
n = udp_recvfrom(s, str, &from); |
win_puts(&displ, str); |
} |
} |
/* |
This non real-time task reads strings from the keyoard and sends them |
to the remote host |
*/ |
TASK write(void) |
{ |
WIN wr; |
UDP_ADDR to,local; |
char str[80],tmp[5],ch; |
int s; |
IP_ADDR bindlist[5]; |
win_init(&wr,0,7,79,6); |
win_frame(&wr,BLACK,WHITE,"Local",2); |
/* Create a socket for transitting */ |
ip_str2addr(talk_myipaddr,&(local.s_addr)); |
local.s_port = 101; |
/* |
If we want the address of the remote host in the ARP table before |
begginning the transmission (to eliminate a possible source of |
unpredictability), we can use the bindlist, otherwise we set the |
second parameter of udp_bind to NULL |
*/ |
ip_str2addr(talk_toipaddr,&(bindlist[0])); |
memset(&(bindlist[1]), 0, sizeof(IP_ADDR)); |
s = udp_bind(&local, /*bindlist*/NULL); |
ip_str2addr(talk_toipaddr,&(to.s_addr)); |
to.s_port = 100; |
sprintf(str,"Local IP address %d.%d.%d.%d\n", local.s_addr.ad[0], |
local.s_addr.ad[1], local.s_addr.ad[2], |
local.s_addr.ad[3]); |
win_puts(&dbg,str); |
sprintf(str,"Talk to %d.%d.%d.%d ",to.s_addr.ad[0],to.s_addr.ad[1], |
to.s_addr.ad[2],to.s_addr.ad[3]); |
win_puts(&dbg,str); |
while (1) { |
/* Get the string...*/ |
while((ch = keyb_getch(BLOCK)) != 13) { |
sprintf(tmp,"%c",ch); |
strcat(str,tmp); |
win_puts(&wr,tmp); |
} |
strcat(str,"\n"); |
/*...and send it!!! */ |
udp_sendto(s,str,strlen(str)+2,&to); |
} |
} |
/* This function is called when the user presses CTRL-C (stops the systems) */ |
void esci(KEY_EVT *k) |
{ |
esc = TRUE; |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
KEY_EVT k; |
struct net_model m = net_base; |
NRT_TASK_MODEL m_nrt; |
k.flag = CNTL_BIT; |
k.scan = KEY_C; |
k.ascii = 'c'; |
k.status = KEY_PRESSED; |
keyb_hook(k,esci,FALSE); |
k.flag = CNTR_BIT; |
k.scan = KEY_C; |
k.ascii = 'c'; |
k.status = KEY_PRESSED; |
keyb_hook(k,esci,FALSE); |
clear(); |
cprintf(" S.Ha.R.K. Talk! Ver. 1.10\n"); |
if (argc != 3) { |
cprintf("S.Ha.R.K. Talk usage: talk fromIP toIP\n"); |
return 0; |
} |
strcpy(talk_myipaddr, argv[1]); |
strcpy(talk_toipaddr, argv[2]); |
/* We want a task for TX mutual exclusion */ |
net_setmode(m, TXTASK); |
/* We use UDP/IP stack */ |
net_setudpip(m, talk_myipaddr, "255.255.255.255"); |
/* OK: let's start the NetLib! */ |
if (net_init(&m) == 1) { |
cprintf("Net Init OK...\n"); |
} else { |
cprintf("Net Init Failed...\n"); |
sys_abort(300); |
} |
//dump_irq(); |
cprintf("\n\n\n\tPress ENTER\n"); |
while (!esc) { |
keyb_getcode(&k,BLOCK); |
if (k.ascii == 13) esc = TRUE; |
} |
esc = FALSE; |
clear(); |
win_init(&dbg,0,20,60,3); |
win_frame(&dbg,BLACK,WHITE,"Debug",2); |
/* Start the sender and receiver tasks...*/ |
nrt_task_default_model(m_nrt); |
task_activate(task_create("aaa",scrittore,&m_nrt,NULL)); |
task_activate(task_create("bbb",write,&m_nrt,NULL)); |
return 0; |
} |
/demos/trunk/network/makefile |
---|
0,0 → 1,18 |
# |
# |
# |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
PROGS = net talk |
include $(BASE)/config/example.mk |
net: |
make -f $(SUBMAKE) BASE=$(BASE) APP=net INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__NEWPCI__ __LINUXC26__ __INPUT__" |
talk: |
make -f $(SUBMAKE) BASE=$(BASE) APP=talk INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__NEWPCI__ __LINUXC26__ __INPUT__" |