Blame | Last modification | View Log | RSS feed
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Paolo Gai <pj@hartik.sssup.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
*/
/*
* 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 "mymod.h"
#include <ll/string.h>
#include <kernel/model.h>
#include <kernel/descr.h>
#include <kernel/var.h>
#include <kernel/func.h>
// other include files if needed
// NOTE: NO GLOBAL OR STATIC VARIABLES!!!
// (put them inside the level descriptor!)
/* Statuses used in the level */
#define MYMOD_READY MODULE_STATUS_BASE
#define MYMOD_WAIT MODULE_STATUS_BASE+3
#define MYMOD_IDLE MODULE_STATUS_BASE+4
/* the level redefinition for the Module */
typedef struct {
level_des l; /* the standard level descriptor */
int myvar[100]; /* other local (private) variables of the module */
} MYMOD_level_des;
// example of OSLib event
static void MYMOD_timer_deadline(void *par)
{
// usually the void *par is a pointer to a structure or a PID
// if it is a PID, you can do that to retrieve it and the correspondent
// level descriptor
PID p = (PID) par;
MYMOD_level_des *lev;
lev = (MYMOD_level_des *)level_table[proc_table[p].task_level];
// now you know the PID of the task and the level descriptor
// ... so, you know all the things you need
}
static int MYMOD_level_accept_task_model(LEVEL l, TASK_MODEL *m)
{
// your code here
return 0; // dummy number
}
static int MYMOD_level_accept_guest_model(LEVEL l, TASK_MODEL *m)
{
// your code here
return 0; // dummy number
}
static void MYMOD_level_status(LEVEL l)
{
}
/* The scheduler only gets the first task in the queue */
static PID MYMOD_level_scheduler(LEVEL l)
{
return 0; // dummy number
}
/* The on-line guarantee is enabled only if the appropriate flag is set... */
static int MYMOD_level_guarantee(LEVEL l, bandwidth_t *freebandwidth)
{
return 0; // dummy number
}
static int MYMOD_task_create(LEVEL l, PID p, TASK_MODEL *m)
{
return 0; // dummy number
}
static void MYMOD_task_detach(LEVEL l, PID p)
{
}
static int MYMOD_task_eligible(LEVEL l, PID p)
{
return 0; // dummy number
}
static void MYMOD_task_dispatch(LEVEL l, PID p, int nostop)
{
}
static void MYMOD_task_epilogue(LEVEL l, PID p)
{
}
static void MYMOD_task_activate(LEVEL l, PID p)
{
}
static void MYMOD_task_insert(LEVEL l, PID p)
{
}
static void MYMOD_task_extract(LEVEL l, PID p)
{
}
static void MYMOD_task_endcycle(LEVEL l, PID p)
{
}
static void MYMOD_task_end(LEVEL l, PID p)
{
}
static void MYMOD_task_sleep(LEVEL l, PID p)
{
}
static void MYMOD_task_delay(LEVEL l, PID p, TIME usdelay)
{
}
static int MYMOD_guest_create(LEVEL l, PID p, TASK_MODEL *m)
{
return 0; // dummy number
}
static void MYMOD_guest_detach(LEVEL l, PID p)
{
}
static void MYMOD_guest_dispatch(LEVEL l, PID p, int nostop)
{
}
static void MYMOD_guest_epilogue(LEVEL l, PID p)
{
}
static void MYMOD_guest_activate(LEVEL l, PID p)
{
}
static void MYMOD_guest_insert(LEVEL l, PID p)
{
}
static void MYMOD_guest_extract(LEVEL l, PID p)
{
}
static void MYMOD_guest_endcycle(LEVEL l, PID p)
{
}
static void MYMOD_guest_end(LEVEL l, PID p)
{
}
static void MYMOD_guest_sleep(LEVEL l, PID p)
{
}
static void MYMOD_guest_delay(LEVEL l, PID p, TIME usdelay)
{
}
/* Registration functions */
/*+ Registration function:
int flags the init flags ... see MYMOD.h +*/
void MYMOD_register_level(int flags)
{
LEVEL l; /* the level that we register */
MYMOD_level_des *lev; /* for readableness only */
PID i; /* a counter */
/* request an entry in the level_table */
l = level_alloc_descriptor();
/* alloc the space needed for the MYMOD_level_des */
lev = (MYMOD_level_des *)kern_alloc(sizeof(MYMOD_level_des));
/* update the level_table with the new entry */
level_table[l] = (level_des *)lev;
/* fill the standard descriptor */
strncpy(lev->l.level_name, MYMOD_LEVELNAME, MAX_LEVELNAME);
lev->l.level_code = MYMOD_LEVEL_CODE;
lev->l.level_version = MYMOD_LEVEL_VERSION;
lev->l.level_accept_task_model = MYMOD_level_accept_task_model;
lev->l.level_accept_guest_model = MYMOD_level_accept_guest_model;
lev->l.level_status = MYMOD_level_status;
lev->l.level_scheduler = MYMOD_level_scheduler;
lev->l.level_guarantee = MYMOD_level_guarantee;
lev->l.task_create = MYMOD_task_create;
lev->l.task_detach = MYMOD_task_detach;
lev->l.task_eligible = MYMOD_task_eligible;
lev->l.task_dispatch = MYMOD_task_dispatch;
lev->l.task_epilogue = MYMOD_task_epilogue;
lev->l.task_activate = MYMOD_task_activate;
lev->l.task_insert = MYMOD_task_insert;
lev->l.task_extract = MYMOD_task_extract;
lev->l.task_endcycle = MYMOD_task_endcycle;
lev->l.task_end = MYMOD_task_end;
lev->l.task_sleep = MYMOD_task_sleep;
lev->l.task_delay = MYMOD_task_delay;
lev->l.guest_create = MYMOD_guest_create;
lev->l.guest_detach = MYMOD_guest_detach;
lev->l.guest_dispatch = MYMOD_guest_dispatch;
lev->l.guest_epilogue = MYMOD_guest_epilogue;
lev->l.guest_activate = MYMOD_guest_activate;
lev->l.guest_insert = MYMOD_guest_insert;
lev->l.guest_extract = MYMOD_guest_extract;
lev->l.guest_endcycle = MYMOD_guest_endcycle;
lev->l.guest_end = MYMOD_guest_end;
lev->l.guest_sleep = MYMOD_guest_sleep;
lev->l.guest_delay = MYMOD_guest_delay;
/* fill the MYMOD descriptor part */
for (i=0; i<100; i++)
lev->myvar[i] = 0;
}
// put here the other interface functions added