Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1100 → Rev 1101

/demos/trunk/parport/initfile.c
0,0 → 1,120
/*
*
* Project:
* Parallel Port S.Ha.R.K. Project
*
* Module:
* Initfile.c
*
* Description:
* System initialization file
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors:
* Andrea Battistotti <btandrea@libero.it>
* Armando Leggio <a_leggio@hotmail.com>
*
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*
 
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/sem.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
 
#include "drivers/keyb.h"
 
 
/*+ sysyem tick in us +*/
#define TICK 0
/* #define TICK 100 */
 
/*+ 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();
 
CABS_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/parport/ppdemo.c
0,0 → 1,532
/*
*
* Project:
* Parallel Port S.Ha.R.K. Project
*
* Module:
* ppDemo.c
*
* Description:
* file contents description
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors:
* Andrea Battistotti <btandrea@libero.it>
* Armando Leggio <a_leggio@hotmail.com>
*
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*
*/
 
/**
------------
CVS : $Id: ppdemo.c,v 1.1 2002-10-28 08:18:27 pj Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2002-10-28 08:18:27 $
------------
**/
 
/*
* Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo
*
* 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
*
*/
 
/****************************************************************/
/* PERIODIC PROCESS TEST */
/****************************************************************/
 
 
#include <drivers/parport.h>
 
 
#define TSK_PERIOD 250000 /*400000 ok for debug...*/
#define TSK_WCET 70000
 
#define YMENU 10 /* menu level */
#define XMIN 10
#define XMAX 630
#define YMIN 10
#define YMAX 470
#define ESC 27 /* ASCII code of ESCAPE key */
#define X0
#define GRXWND_COLS 33
#define GRXWND_LINS 15
 
 
 
void ppInitGrxWnd(void)
{
/* graphic preparation */
/* graphic card Initialization */
if (grx_init() < 1) {
sys_abort(1);
}
if (grx_open(640, 480, 8) < 0) {
kern_printf("GRX Err\n");
sys_abort(1);
}
kern_printf("Video card ok!\n");
/* The scenario */
 
// Background
grx_clear(6);
 
// Frame
grx_rect(XMIN-1, YMIN-1, XMAX+1, YMAX+1, 0);
 
// Window 1
grx_box(XMIN+14,YMIN+14,XMAX-317,YMAX-235,7); //window
grx_box(XMIN+17,YMIN+17,XMAX-320,YMAX-427,1); //bar
grx_box(XMIN+17,YMIN+42,XMAX- 320,YMAX-238,0); //workspace
grx_box(XMIN+286,YMIN+19,XMAX-322,YMAX-429,7);//button
grx_text("PPDemo", XMIN+30, YMIN+21, 15, 1); //title
grx_text("**********************************", XMIN+25, YMIN+55, 10, 0);
grx_text("* PARALLEL PORT DEMONSTRATION *", XMIN+25, YMIN+70, 10, 0);
grx_text("**********************************", XMIN+25, YMIN+85, 10, 0);
grx_text("Press ALT X to exit", XMIN+25, YMIN+115, 10, 0);
grx_text("other keys to communicate with", XMIN+25, YMIN+130, 10, 0);
grx_text("remote terminal", XMIN+25, YMIN+145, 10, 0);
grx_text("(c) Copyright 2002", XMIN+25, YMIN+190, 10, 0);
grx_text("Andrea Battistotti, Armando Leggio", XMIN+25, YMIN+205, 10, 0);
// Window 2
grx_box(XMIN+317,YMIN+14,XMAX-14,YMAX-235,7);
grx_box(XMIN+320,YMIN+17,XMAX-17,YMAX-427,1);
grx_box(XMIN+320,YMIN+42,XMAX-17,YMAX-238,0);
grx_box(XMIN+589,YMIN+19,XMAX-19,YMAX-429,7);
grx_text("Statistics", XMIN+333, YMIN+21, 15, 1);
 
}
 
 
void ppInitGrxWnd_b(void)
{
// Window 3
grx_box(XMIN+14,YMIN+243,XMAX-317,YMAX-6,7);
grx_box(XMIN+17,YMIN+246,XMAX-320,YMAX-198,1);
grx_box(XMIN+17,YMIN+271,XMAX-320,YMAX-9,0);
grx_box(XMIN+286,YMIN+248,XMAX-322,YMAX-200,7);
grx_text("Local Terminal", XMIN+30, YMIN+250, 15, 1);
 
// Window 4
grx_box(XMIN+317,YMIN+243,XMAX-14,YMAX-6,7);
grx_box(XMIN+320,YMIN+246,XMAX-17,YMAX-198,1);
grx_box(XMIN+320,YMIN+271,XMAX-17,YMAX-9,0);
grx_box(XMIN+589,YMIN+248,XMAX-19,YMAX-200,7);
grx_text("Remote Terminal", XMIN+333, YMIN+250, 15, 1);
 
}
 
 
void ppGrxWnd2(char *c) /* sys msg wind */
{
static int i,j;
static char sysmsg[GRXWND_LINS+1][GRXWND_COLS+1];
char s[2];
 
s[1]='\0';
 
while ((s[0]=*c++)) // *c != 0
{
sysmsg[i][j]=s[0] ;
switch (s[0])
{
case '\r': case '\n':
j=0;i++;
break;
 
case '\b':
if (j>0)
{
j--;s[0]=' ';
grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0);
//statistics grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0);
//statistics
}
break;
 
default:
grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0); //statistics
j++;
break;
 
}
if (j>=GRXWND_COLS)
{i++;
j=0;}
if (i>=GRXWND_LINS) {
s[0]=' ';
for (i=0;i<GRXWND_LINS;i++){
for (j=0;j<GRXWND_COLS;j++){
grx_text(s, XMIN+330+8*j, YMIN+49+10*i,10,0); //statistics
};
};
i=0; j=0;
};
} // end while
}
 
 
void ppGrxWnd3(char c)
{
static int i,j;
char talk[GRXWND_LINS+1][GRXWND_COLS+1];
char s[2];
s[1]='\0';
 
talk[i][j]=c;
s[0] = c;
switch (c)
{
case '\r': case '\n':
j=0;i++;
break;
 
 
case '\b':
if (j>0)
{
j--;s[0]=' ';
grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0); //local term
 
}
break;
 
default:
grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0); //local term
j++;
break;
 
}
if(j==GRXWND_COLS) {i++; j=0;};
if(i==GRXWND_LINS) {
s[0]=' ';
for (i=0;i<GRXWND_LINS;i++){
for (j=0;j<GRXWND_COLS;j++){
grx_text(s, XMIN+27+8*j, YMIN+278+10*i,10,0); //local term
};
};
i=0; j=0;
}
}
 
void ppGrxWnd4(char c)
{
static int i,j;
char talk[GRXWND_LINS][GRXWND_COLS];
char s[2];
s[1]='\0';
 
talk[i][j]=c;
s[0] = c;
switch (c)
{
case '\r': case '\n':
j=0;i++;break;
 
case '\b':
if (j>0)
{
j--;s[0]=' ';
grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term
}
break;
default:
grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term
j++;
break;
}
 
if(j==GRXWND_COLS) {i++; j=0;}
if(i==GRXWND_LINS) {
s[0]=' ';
for (i=0;i<GRXWND_LINS;i++){
for (j=0;j<GRXWND_COLS;j++){
grx_text(s, XMIN+330+8*j, YMIN+278+10*i,10,0); //remote term
};
};
i=0; j=0;
}
}
 
 
/***************************************************************/
 
TASK ppChat(void *arg)
{
char sysmsg[SYS_MSG_COLS+1];
long xposTx;
KEY_EVT k;
BYTE b;
k.ascii = 0;
xposTx=9430 ; // any 16 bit test value...
 
task_endcycle();
 
while (1) {
#if PP_DEBUG == 1
//kern_printf("ppchat \n");
#endif
/* read char buffer */
if (keyb_getcode(&k,NON_BLOCK))
{
/* if any send it to ppDrv ...*/
b=k.ascii;
#if PP_DEBUG == 1
kern_printf("Send char: %i , %c \n",b,b);
#endif
//kern_printf("--- Transmit value for xposTx: %d \n",xposTx);
//ppTxBytes( (BYTE *) &xposTx, sizeof(xposTx) );
ppGrxWnd3(b);
ppTxOneByte(b);
}
 
if (ppRxOneByte(&b)==PP_COMM_OK)
//if (ppRxBytes((BYTE *) &xposRx, sizeof(xposRx))==PP_COMM_OK)
{
ppGrxWnd4(b);
//kern_printf("%c",b);
//kern_printf("--- Received value for xposRx: %d \n", xposRx);
}
if (ppReadSysMsg(sysmsg)==PP_SYSMSG_OK) ppGrxWnd2(sysmsg);
 
/* ..and show it in upper screen..*/
task_endcycle();
}
}
 
 
/****************************************************************/
 
/* This is the exception handler. It is called when an exception
is raised.
It exits from the graphical mode, then it prints a message and
shutdown the kernel using sys_abort()
*/
 
void demo_exc_handler(int signo, siginfo_t *info, void *extra)
{
struct timespec t;
 
grx_close();
 
/* Default action for an kern exception is */
kern_cli();
ll_gettime(TIME_EXACT, &t),
kern_printf("\nS.Ha.R.K. Exception raised!!!"
"\nTime (s:ns) :%ld:%ld"
"\nException number:%d (numbers in include/bits/errno.h)"
"\nPID :%d\n",
t.tv_sec, t.tv_nsec, info->si_value.sival_int,
info->si_task);
sys_abort(1);
}
 
/******************************************************************/
 
/* This function is called when Alt-X is pressed.
It simply shutdown the system using sys_end.
Note that the byebye() function is called only if we exit from
the system using sys_end()!!!!
*/
void my_end(KEY_EVT* e)
{
 
sys_end();
}
 
/******************************************************************/
 
/* This function is called when the system exit correctly after Alt-X.
It exits from the graphic mode and then it prints a small greeting.
Note that:
- The function calls grx_exit, so it must be registered using
RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because
at that point the kernel is already returned in real mode!!!)
- When an exception is raised, the exception handler is called.
Since the exception handler already exits from the graphic mode,
this funcion has not to be called. For this reason:
. we registered byebye using the flag NO_AT_ABORT
. the exception handler exits using sys_abort; in that way byebye is
NOT called
*/
 
void byebye(void *arg)
{
grx_close();
kern_printf("Bye Bye!\n");
}
 
/****************************** MAIN ******************************/
 
int main(int argc, char **argv)
{
PID pid2, pid;
KEY_EVT emerg;
 
HARD_TASK_MODEL m2;
SOFT_TASK_MODEL mp;
 
struct sigaction action;
 
 
/* Init the standard S.Ha.R.K. exception handler */
action.sa_flags = SA_SIGINFO; /* Set the signal action */
action.sa_sigaction = demo_exc_handler;
action.sa_handler = 0;
sigfillset(&action.sa_mask); /* we block all the other signals... */
 
if (sigaction(SIGHEXC, &action, NULL) == -1) { /* set the signal */
perror("Error initializing signals..."); sys_end();}
 
/* Set the closing function */
sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT|NO_AT_ABORT);
 
 
keyb_set_map(itaMap);
/* set the keyboard handler to exit correctly */
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTL_BIT;
keyb_hook(emerg,my_end);
emerg.ascii = 'x';
emerg.scan = KEY_X;
emerg.flag = ALTR_BIT;
keyb_hook(emerg,my_end);
 
/* a small banner */
kern_printf("ppChat Demo\n");
kern_printf("Press Alt-X to exit\n");
 
/* graphics */
ppInitGrxWnd();
 
/* graphic card Initialization */
//kern_printf("Video card ok!\n");
 
 
/* ppDrv creation */
ppGrxWnd2("Initing Drv...\n");
ppInitDrv(ppGrxWnd2); /* pass output fnc for init debug...*/
 
ppInitGrxWnd_b();
 
 
/* MODEL TASK EXAMPLES */
soft_task_default_model(mp);
soft_task_def_level(mp,1);
soft_task_def_ctrl_jet(mp);
soft_task_def_arg(mp, (void *)0);
soft_task_def_group(mp, 1);
soft_task_def_met(mp, PPDRV_WCET);
soft_task_def_period(mp,PPDRV_PERIOD);
soft_task_def_usemath(mp);
pid = task_create("ppDrv", ppPollingSvr, &mp, NULL);
if (pid != NIL) task_activate(pid);
/**/
//hard_task_default_model(m1);
//hard_task_def_ctrl_jet (m1);
//hard_task_def_arg (m1, (void *)0);
//hard_task_def_wcet (m1, PPDRV_WCET);
//hard_task_def_mit (m1, PPDRV_PERIOD);
//hard_task_def_group (m1,1);
//pid1 = task_create("ppDrv", ppPollingSvr, &m1, NULL);
//if (pid1 == NIL) {/*grx_close();*/ perror("Could not create task <ppDrv>");sys_abort(1);}
//if(task_activate(pid1)==-1) {/*grx_close();*/ perror("Could not create task <ppDrv>");sys_abort(1);};
//(" Task ppDrv Activate...PID: %i\n",pid1);
// kern_printf("---------------------\n");
 
/* ppChat creation */
hard_task_default_model(m2);
hard_task_def_ctrl_jet (m2);
hard_task_def_arg (m2, (void *)1);
hard_task_def_wcet (m2, TSK_WCET);
hard_task_def_mit (m2, TSK_PERIOD);
hard_task_def_group (m2,2);
pid2 = task_create("ppChat", ppChat, &m2, NULL);
if (pid2 == NIL) {/*grx_close();*/ perror("Could not create task <ppChat>");sys_abort(1);}
task_activate(pid2);
//kern_printf("Task Chat Activate...PID: %i\n",pid2);
//kern_printf("---------------------\n");
 
 
/*
now the task main ends, but the system does not shutdown because
there are the three task ego1, ego2, and ego3 running.
The demo will finish if a Alt-X key is pressed.
*/
 
return 0;
}
 
/* MODEL TASK EXAMPLES (from jumpball demo)
 
SOFT_TASK_MODEL mp;
soft_task_default_model(mp);
soft_task_def_level(mp,1);
soft_task_def_ctrl_jet(mp);
soft_task_def_arg(mp, (void *)rgb16(r,g,b));
soft_task_def_group(mp, BALL_GROUP);
soft_task_def_met(mp, WCET_BALL);
soft_task_def_period(mp,PERIOD_BALL);
soft_task_def_usemath(mp);
pid = task_create(palla_str, palla, &mp, NULL);
 
if (pid != NIL) task_activate(pid);
 
 
HARD TASK EXAMPLES
 
HARD_TASK_MODEL mp;
 
hard_task_default_model(mp);
hard_task_def_ctrl_jet(mp);
hard_task_def_arg(mp, (void *)rgb16(r,g,b));
hard_task_def_wcet(mp, 380);
hard_task_def_mit(mp,PERIOD_BALL);
hard_task_def_usemath(mp);
pid = task_create("pallaEDF", palla, &mp, NULL);
if (pid != NIL) task_activate(pid);
*/
/demos/trunk/parport/readme.txt
0,0 → 1,27
Hi,
 
This directory contains a small demo that uses the Shark Parallel Port driver.
 
Full documentation is available on the Shark Web Page.
 
PJ
 
PS: The following text is the original text made by the authors.
------------------------------------------------------------------------------
 
Universita' degli Studi di Pavia
Facoltà di Ingegneria
Dipartimento di Informatica e Sistemistica
 
-------------------------------------------------------------
PARALLEL PORT SHARK PROJECT
COMUNICAZIONE TRA PERSONAL COMPUTER TRAMITE PORTA PARALLELA
-------------------------------------------------------------
Corso: Informatica Industriale - A.A. 2001/2002
Docente: Prof. Giorgio Buttazzo
Responsabili: Prof. Giorgio Buttazzo - Ing. Paolo Gai
 
Progetto: Parallel Port Shark Project
Autori: Andrea Battistotti, Armando Leggio
 
(C) Copyright 2002 Andrea Battistotti & Armando Leggio
/demos/trunk/parport/makefile
0,0 → 1,16
#
#
#
 
ifndef BASE
BASE=../..
endif
include $(BASE)/config/config.mk
 
PROGS= ppdemo
 
include $(BASE)/config/example.mk
 
ppdemo:
make -f $(SUBMAKE) APP=ppdemo INIT= OTHEROBJS="initfile.o" OTHERINCL=