Clock control, Microsecond delay, Hal i/o – Comtrol eCos User Manual

Page 290: Register address

Advertising
background image

Chapter 9. HAL Interfaces

Clock control

HAL_CLOCK_INITIALIZE( period )

HAL_CLOCK_RESET( vector, period )

HAL_CLOCK_READ( pvalue )

These macros provide control over a clock or timer device that may be used by the kernel to provide time-out, delay
and scheduling services. The clock is assumed to be implemented by some form of counter that is incremented or
decremented by some external source and which raises an interrupt when it reaches a predetermined value.

HAL_CLOCK_INITIALIZE()

initializes the timer device to interrupt at the given period. The period is essentially

the value used to initialize the timer counter and must be calculated from the timer frequency and the desired
interrupt rate. The timer device should generate an interrupt every

period

cycles.

HAL_CLOCK_RESET()

re-initializes the timer to provoke the next interrupt. This macro is only really necessary

when the timer device needs to be reset in some way after each interrupt.

HAL_CLOCK_READ()

reads the current value of the timer counter and puts the value in the location pointed to by

pvalue

. The value stored will always be the number of timer cycles since the last interrupt, and hence ranges

between zero and the initial period value. If this is a count-down cyclic timer, some arithmetic may be necessary to
generate this value.

Microsecond Delay

HAL_DELAY_US(us)

This is an optional definition. If defined the macro implements a busy loop delay for the given number of microsec-
onds. This is usually implemented by waiting for the required number of hardware timer ticks to pass.

This operation should normally be used when a very short delay is needed when controlling hardware, program-
ming FLASH devices and similar situations where a wait/timeout loop would otherwise be used. Since it may
disable interrupts, and is implemented by busy waiting, it should not be used in code that is sensitive to interrupt
or context switch latencies.

HAL I/O

This section contains definitions for supporting access to device control registers in an architecture neutral fashion.

These definitions are normally found in the header file

cyg/hal/hal_io.h

. This file itself contains macros that

are generic to the architecture. If there are variant or platform specific IO access macros then these will be found in

cyg/hal/var_io.h

and

cyg/hal/plf_io.h

in the variant or platform HALs respectively. These files are include

automatically by this header, so need not be included explicitly.

This header (or more likely

cyg/hal/plf_io.h

) also defines the PCI access macros. For more information on

these see

the Section called PCI Library reference in Chapter 30

.

186

Advertising