Subversion Repositories shark

Compare Revisions

Regard whitespace Rev 1189 → Rev 1190

/demos/trunk/tftptest/initfile.c
0,0 → 1,114
/*
* 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
*/
 
/*
------------
CVS : $Id: initfile.c,v 1.1 2003-10-02 12:45:43 giacomo Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2003-10-02 12:45:43 $
------------
 
System initialization file
 
This file contains the 2 functions needed to initialize the system.
 
These functions register the following levels:
 
an EDF (Earliest Deadline First) level
a RR (Round Robin) level
a CBS (Costant Bandwidth Server) level
a Dummy level
 
It can accept these task models:
 
HARD_TASK_MODEL (wcet+mit) at level 0
SOFT_TASK_MODEL (met, period) at level 1
NRT_TASK_MODEL at level 2
 
This file is similar to the configuration of kernel/init/hartik3.c
 
TICK is set to 0 (one-shot timer is used)
*/
 
/*
* Copyright (C) 2000 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
*
*/
 
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "modules/rr.h"
#include "modules/dummy.h"
#include "modules/hartport.h"
#include "modules/sem.h"
#include "drivers/keyb.h"
 
/*+ sysyem tick in us +*/
#define TICK 1000
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
EDF_register_level(EDF_ENABLE_ALL);
CBS_register_level(CBS_ENABLE_ALL, 0);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
 
SEM_register_module();
 
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
KEYB_PARMS kparms = BASE_KEYB;
 
HARTPORT_init();
 
keyb_def_ctrlC(kparms, NULL);
keyb_def_map(kparms,itaMap);
KEYB_init(&kparms);
 
__call_main__(mb);
 
return (void *)0;
}
 
/demos/trunk/tftptest/makefile
0,0 → 1,16
#
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
PROGS = tftptest
 
include $(BASE)/config/example.mk
 
tftptest:
make -f $(SUBMAKE) APP=tftptest INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __TFTP__"
 
/demos/trunk/tftptest/tftptest.c
0,0 → 1,224
#include <string.h>
#include <kernel/func.h>
#include <kernel/kern.h>
#include <drivers/keyb.h>
#include <drivers/udpip.h>
#include "tftp.h"
#include "endian.h"
 
#include "modules/sem.h"
 
#include <kernel/kern.h>
#include <drivers/pci.h>
#include <ll/i386/hw-instr.h>
 
 
#define LOCAL_HOST_IP "192.168.0.134"
#define REMOTE_HOST_IP "192.168.0.133"
 
sem_t m1, m2;
int handle, handle2;
 
int prog = 0;
 
/* This function is called when the user presses CTRL-C (stops the systems) */
 
void esci(KEY_EVT *k)
{
cprintf("Exit from the program...\n");
cprintf("Ctrl-C pressed!\n");
sys_abort(500);
}
 
void augprog(KEY_EVT *k)
{
prog = 1;
}
 
void keyb_start(void) {
KEY_EVT k;
 
k.flag = CNTL_BIT;
k.scan = KEY_C;
k.ascii = 'C';
keyb_hook(k, esci);
k.flag = CNTR_BIT;
k.scan = KEY_C;
k.ascii = 'c';
keyb_hook(k, esci);
 
k.flag = CNTL_BIT;
k.scan = KEY_A;
k.ascii = 'A';
keyb_hook(k, augprog);
k.flag = CNTR_BIT;
k.scan = KEY_A;
k.ascii = 'a';
keyb_hook(k, augprog);
}
 
TASK test_upload(void *arg) {
int i;
char msg[200];
int bytes;
 
i = 0;
while (1) {
 
// cprintf("uploader 1\n");
 
sprintf(msg, "tftptest says: i = %5d\n", i);
tftp_put(handle, msg, strlen(msg));
 
// cprintf("uploader 2\n");
 
bytes = tftp_usedbuffer(handle);
/*!*/sprintf(msg, "buffer %d ", bytes);
/*!*/puts_xy(BASE_X, 18, WHITE, msg);
 
// cprintf("uploader 3\n");
i++;
 
task_endcycle();
}
return(0);
}
 
TASK test_upload2(void *arg) {
int i;
char msg[200];
int bytes;
 
i = 0;
while (1) {
 
sprintf(msg, "tftptest says: i = %5d\n", i);
tftp_put(handle2, msg, strlen(msg));
 
bytes = tftp_usedbuffer(handle2);
/*!*/sprintf(msg, "buffer2 %d ", bytes);
/*!*/puts_xy(BASE_X, 38, WHITE, msg);
i++;
 
task_endcycle();
}
return(0);
}
 
void wait() {
char ch;
do {
ch = keyb_getch(NON_BLOCK);
} while(prog == 0);
prog = 0;
}
 
int main(void)
{
int err;
HARD_TASK_MODEL hard_m;
PID p1, p2;
 
keyb_start();
cprintf("main: Keyboard handler started\n");
 
tftp_init();
cprintf("main: Tftp library initialized\n");
 
err = tftp_net_start(LOCAL_HOST_IP, REMOTE_HOST_IP, 1);
cprintf("netval = %d\n", err);
if (err == 1) {
cprintf("Net Init from %s to %s\n", LOCAL_HOST_IP, REMOTE_HOST_IP);
} else {
cprintf("Net Init Failed...\n");
sys_end();
return(err);
}
 
sem_init(&m1, 0, 1);
 
 
if ((handle = tftp_open("test.txt")) == -1) {
cprintf("No slots available. Program aborted...\n");
sys_end();
return(1);
}
 
cprintf("Ctrl-A to proceed *** Ctrl-C to stop\n");
wait();
clear();
 
cprintf("Handle = %d\n", handle);
 
if ((err = tftp_upload(handle, 4096, &m1)) != 0) {
cprintf("Error %d calling tftp_upload(). Program aborted...\n", err);
sys_end();
return(1);
}
 
/* First we set the sender's task properties...*/
hard_task_default_model(hard_m);
hard_task_def_wcet(hard_m, 10000);
hard_task_def_mit(hard_m, 300000);
 
if ((p1 = task_create("test_upload", test_upload, &hard_m, NULL)) == NIL) {
cprintf("Error creating test_upload task. Program aborted...\n");
sys_end();
return(1);
}
if (task_activate(p1) == -1) {
cprintf("Error activating test_upload task. Program aborted...\n");
sys_end();
return(1);
}
 
 
sem_init(&m2, 0, 1);
 
if ((handle2 = tftp_open("test2.txt")) == -1) {
cprintf("No second slot available. Program aborted...\n");
sys_end();
return(1);
}
 
 
 
cprintf("Handle2 = %d\n", handle2);
 
if ((err = tftp_upload(handle2, 4096, &m2)) != 0) {
cprintf("Error %d calling tftp_upload(). Program aborted...\n", err);
sys_end();
return(1);
}
 
/* First we set the sender's task properties...*/
hard_task_default_model(hard_m);
hard_task_def_wcet(hard_m, 10000);
hard_task_def_mit(hard_m, 300000);
 
if ((p2 = task_create("test_upload2", test_upload2, &hard_m, NULL)) == NIL) {
cprintf("Error creating test_upload2 task. Program aborted...\n");
sys_end();
return(1);
}
if (task_activate(p2) == -1) {
cprintf("Error activating test_upload2 task. Program aborted...\n");
sys_end();
return(1);
}
 
 
wait();
 
tftp_close(handle, TFTP_STOP_NOW);
 
 
// wait();
 
tftp_close(handle2, TFTP_STOP_NOW);
 
cprintf("\nProgram terminated correctly.\n");
sys_end();
 
return(0);
}