[uCsimm] RTEC-0.4: added scheduler

From: Bernhard Kuhn (kuhn@batian.lpr.e-technik.tu-muenchen.de)
Date: Sat Jan 15 2000 - 19:40:30 EST


Hopefully this is the last version of RTEC, because i realy
don't want to reinvent the wheel :-)

Altough RTEC is just a playground for preparing the port of RTL (v1.3)
to uClinux, it should be already usable for some simple realtime
applications, but since there is currently only the xcopilot supported,
it hasn't been tested on real hardware. When the uCsimm arrives,
then i will have a real thing for testing ...

I also will do some more documentation on RTEC in the future, so that
it enables other people to do what is necessary to have real-time
on their platforms (i.e. Liew Eng likes to do a port to StrongARM).


RTEC-0.4 - a RealTime Extention for uClinux version 0.4

Changes since version 0.3:

o Added a full priority scheduler (the core part is
  more or less copy&pasted from RTL2.0)

o Added a rt-task demo in rt_application.c

o Improved Soft-interrupt emulation, so that
  it should be simpler portable


wget http://www.rcs.ei.tum.de/~kuhn/uclinux/uClinux-
(the patch for xcopilot is mandatory)


Have a look at:

API Introduction:

Periodic Task Functions:
void rt_task_create(RT_TASK* new_task,void (*code)(void),
                    int priority,RTIME start,RTIME period);
void rt_task_sleep(void);

Timing Functions:
RTIME rt_gettime(void);

Interrupt Handling Functions:
int rt_irq_request(unsigned int irq, void (*handler)(void));
void rt_irq_free(unsigned int irq);
void rt_softirq_pend(int irq)
void rt_softirq_reset(int irq)

Type Definitions:

Periodic Task Functions:

Currently, there are only two functions related to
periodic tasks, that are interresting for the user:

void rt_task_create(RT_TASK* new_task,void (*code)(void),
                    int priority,RTIME start,RTIME period);

This function will create a periodic task that starts
at "start" and will be woken up after every "period"-time.
Note, that you can only create 32 RT-Tasks in RTEC-0.4

void rt_task_sleep(void);

Give over control to the scheduler, which will
wakeup the next task that needs service.

Note that running tasks can be always preempted
by others with a higher priority.

Timing Functions:

RTIME rt_gettime(void);

In RTEC-0.4, you can only ask how much timer-ticks
have occured since the rt-system was started.
The timer uses the 16.667MHz system clock devided by 16,
so that one tick equals to about one microsecond

Interrupt Handling Functions:

int rt_irq_request(unsigned int irq, void (*handler)(void));

Bind a specific interrupt to a realtime handler-routine.
Note that all interrupts will be disabled when
entering the handler. Consequently it can't be
preempted. Note, that all Interrupts have logicaly the same
priority regardless of the hardwired physical
interrupt priority.

void rt_irq_free(unsigned int irq);

Set the previsously requested interrupt free.

void rt_softirq_pend(int irq)

Do a software interrupt that will be taken into
account by the linux interrupt processing routine.
Just request a linux interrupt handler with
the function request_irq() of the linux kernel.
Note that the number of the softirq has to be greater than
32, but lower than 63. The irq number 63 is already
occupied by the "time keeper task" for
emulating the 100Hz period of the standard linux
scheduler. The time keeper task is necessary because
the 16-bit timer of the 68328 can't be programmed
for long periods: there is a low priority rt-task
that has a period of 10 ms to keep the correct time.
To save a timer, the time keeper task also emulates
the timer-interrupt for the linux-scheduler.

void rt_softirq_reset(int irq)

Use this function within the linux interrupt handler
to reset the pending software-interrupt.

Type Definitions:

RT_TASK is the basic task structure. and looks like this:

typedef struct {
  int stackpointer;
  int priority;
  int state;
  RTIME start;
  RTIME period;
  RTIME resume_time;
  int stack[STACKSIZE];

Note, that the stack is hardcoded into the structure
and has a fixed size defined by STACKSIZE (16000 Byte
in RTEC-0.4). Also note, that you always have to define
a task global, means not within a subroutine, especialy
not within rt_init_app(), since then the structure
will be placed on the stack and overwritten by following

Variables of the type RTIME are 64 bit value for defining
starting and period times of a periodic task.
With the one microsecond resolution of the timer
in RTEC-0.4, it will overflow after about half a million
year. That should be ok for most embedded applications :-)
This message resent by the ucsimm@uclinux.com list server http://www.uClinux.com/

This archive was generated by hypermail 2b30 : Sun Apr 07 2002 - 00:01:34 EST