Comtrol eCos User Manual

Page 346

Advertising
background image

Chapter 11. Porting Guide

Write

hal_interrupt_stack_call_pending_dsrs()

. If this function is defined in

hal_arch.h

then it

should appear here. The purpose of this function is to call DSRs on the interrupt stack rather than the current
thread’s stack. This is not an essential feature, and may be left until later. However it interacts with the stack
switching that goes on in the interrupt VSR, so it may make sense to write these pieces of code at the same
time to ensure consistency.

When this function is implemented it should do the following:

Take a copy of the current SP and then switch to the interrupt stack.

Save the old SP, together with the CPU status register (or whatever register contains the interrupt enable
status) and any other registers that may be corrupted by a function call (such as any link register) to
locations in the interrupt stack.

Enable interrupts.

Call

cyg_interrupt_call_pending_DSRs()

. This is a kernel functions that actually calls any pending

DSRs.

Retrieve saved registers from the interrupt stack and switch back to the current thread stack.

Merge the interrupt enable state recorded in the save CPU status register with the current value of the sta-
tus register to restore the previous enable state. If the status register does not contain any other persistent
state then this can be a simple restore of the register. However if the register contains other state bits that
might have been changed by a DSR, then care must be taken not to disturb these.

Define any data items needed. Typically

vectors.S

may contain definitions for the VSR table, the interrupt

tables and the interrupt stack. Sometimes these are only default definitions that may be overridden by the
variant or platform HALs.

7. Write

context.S

. This file contains the context switch code. See

the Section called Thread Context Switching

in Chapter 9

for details of how these functions operate. This file may also contain the implementation of

hal_setjmp()

and

hal_longjmp()

.

8. Write

hal_misc.c

. This file contains any C data and functions needed by the HAL. These might include:

hal_interrupt_*[]

. In some HALs, if these arrays are not defined in

vectors.S

then they must be

defined here.

cyg_hal_exception_handler()

. This function is called from the exception VSR. It usually does extra

decoding of the exception and invokes any special handlers for things like FPU traps, bus errors or memory
exceptions. If there is nothing special to be done for an exception, then it either calls into the GDB stubs, by
calling

__handle_exception()

, or invokes the kernel by calling

cyg_hal_deliver_exception()

.

hal_arch_default_isr()

. The

hal_interrupt_handlers[]

array is usually initialized with pointers

to

hal_default_isr()

, which is defined in the common HAL. This function handles things like Ctrl-C

processing, but if that is not relevant, then it will call

hal_arch_default_isr()

. Normally this function

should just return zero.

cyg_hal_invoke_constructors()

. This calls the constructors for all static objects before the program

starts. eCos relies on these being called in the correct order for it to function correctly. The exact way
in which constructors are handled may differ between architectures, although most use a simple table of

242

Advertising