uC/OS port to hitachi SH1 processor.

This port was done using the Hitachi SH1-LCEVB (Part no: us7032evb1)
evaluation board. The evaluation kit comes with the Cygnus
gnu toolchain and cost 99.00. ( How could you beat that? )

The source code for the kernel can be found in

    "uC/OC The Real Time Kernel" by Jean J. Labrosse
    R & D Publications
    1601 West 23rd Street, Suite 200
    Lawrence, Kansas 66046-0127

This is an excellent book and provides a good starting point for learning
how realtime kernels operate, and how to utilize them.

In addition to the files that are included with this port, you
will need ucos.c and ucos.h from the book. You will have to make one
modification to ucos.c, see the section on interrupts.
I believe that an older version of these files can be found
online through various other ports, although I highly recommend the book.

Notes about this port:

Interupt Vector Table:
I have included a crt0.s file that includes code to copy the interrupt
vector table from the boot rom into ram. This is accomplished through
creating an array of pointers to functions 256 elements long and putting
this array in a section called "vects" ( see vects.c and sh.lnk ).
Doing this, copies the monitor interrupt vectors so that gdb will still
operate. Although I put pointers to interrupt service routines in this array,
they get written over by crt0.s. Use the function set_vector to place a
pointer into the new vector table ( see test.c and int.c ).


Interrupts:
Sh_c.c is used to initialize the the task stack and the Task Control Block.
Tasks are initialized with the interrupt level bits of the status register
set to 0. This enables all interrupts when tasks are started. Interupts
in the sh1 will alter these bits, setting them so that higher priority
interrupts will continue to run. This presents a problem in that the
interrupte level needs to be saved and restored every time interrupts
get disabled and enabled. The functions which perform this task can be
found in int.c.

You can use set_interrupt_level AFTER tasking has started to alter the
interrupt priority bits. Be carefull doing this. Any task that alters the
level may be preempted by another task which has a different priority
level saved in its sr.

I have only tested the kernel setting the level to 0 and letting the
interupts manage themselves. This functions due to the fact that
inside an interrupt, the level gets set by the processor, interrupt
code runs, OS calls set the level to 15 and back to the level of the
interrupt, then when the interupt is exiting through the scheduler,
the interrupt level gets restored back to 0.

Modification to UCOS.C:
There is a bug in the original tick.asm ( x86 ) file. The STI instruction
is executed before OSIntEnter is called. This reenables interrupts
of a higher priority before OSIntNesting gets incremented. If a higher
priority int happens in between the STI instruction and OSIntNesting,
that interrupt could cause a higher priority ( because the scheduler thinks
all interrupts are done ) task to get scheduled, leaving the first interrupt
hanging until the first interrupted task runs again. In the SH1, Ints
have to be disabled immediatly so that OSIntNesting can be incremented.
This port does NOT use OSIntEnter. Instead I have written a macro called
interrupt_enter that will perform the above function. ( see tick.s in this
port ) In order for this to work, you will have to make OSIntNesting
( in ucos.c ) a NON static global so that the interrupt_enter macro can
access it.

Macros:
The file inlines.inc contains three macros, one to save the context,
one to restore the context and the interrupt_enter macro. Files that
include these macros need to be pre processed with the gasp assembly
language preprocessor ( see makefile ). These macros will save many
hours of troubleshooting interrupt routines. ( believe me. The sh1
context is BIG and restoring registers out of order will reak untold
havock on your application ).

GDB seems to work for break points set in tasks. Sometimes
it takes a long time ( 30 seconds ) to fully break out and display
source. The same thing can happen if you depress the NMI switch,
which will break and return you to the gdb prompt. You will need
to depress the reset switch prior to starting gdb each time. I think
this is because the sp is messed up?

Here is an example sequence of running the test application:

    (Reset the target board!)
    gdb
    file test.x
    target remote com2   ( set to your com port )
    load test.x
    continue

The light on the target should be blinking once per second if everything
is working.

You can Email me at 72154.366@compuserve.com if you run into problems.
Michael C. Garrett





















