ChibiOS/RT
2.5.1
HAL Driver
Collaboration diagram for HAL Driver:

Detailed Description

Hardware Abstraction Layer.

The HAL (Hardware Abstraction Layer) driver performs the system initialization and includes the platform support code shared by the other drivers. This driver does contain any API function except for a general initialization function halInit() that must be invoked before any HAL service can be used, usually the HAL initialization should be performed immediately before the kernel initialization.
Some HAL driver implementations also offer a custom early clock setup function that can be invoked before the C runtime initialization in order to accelerate the startup time.

Functions

void halInit (void)
 HAL initialization.
bool_t halIsCounterWithin (halrtcnt_t start, halrtcnt_t end)
 Realtime window test.
void halPolledDelay (halrtcnt_t ticks)
 Polled delay.
void hal_lld_init (void)
 Low level HAL driver initialization.

Time conversion utilities for the realtime counter

#define S2RTT(sec)   (halGetCounterFrequency() * (sec))
 Seconds to realtime ticks.
#define MS2RTT(msec)   (((halGetCounterFrequency() + 999UL) / 1000UL) * (msec))
 Milliseconds to realtime ticks.
#define US2RTT(usec)
 Microseconds to realtime ticks.
#define RTT2S(ticks)   ((ticks) / halGetCounterFrequency())
 Realtime ticks to seconds to.
#define RTT2MS(ticks)   ((ticks) / (halGetCounterFrequency() / 1000UL))
 Realtime ticks to milliseconds.
#define RTT2US(ticks)   ((ticks) / (halGetCounterFrequency() / 1000000UL))
 Realtime ticks to microseconds.

Macro Functions

#define halGetCounterValue()   hal_lld_get_counter_value()
 Returns the current value of the system free running counter.
#define halGetCounterFrequency()   hal_lld_get_counter_frequency()
 Realtime counter frequency.

Defines

#define HAL_IMPLEMENTS_COUNTERS   FALSE
 Defines the support for realtime counters in the HAL.
#define PLATFORM_NAME   "ATmega128"
 Platform name.

Function Documentation

void halInit ( void  )

HAL initialization.

This function invokes the low level initialization code then initializes all the drivers enabled in the HAL. Finally the board-specific initialization is performed by invoking boardInit() (usually defined in board.c).

Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 61 of file hal.c.

References hal_lld_init(), and sdInit().

Here is the call graph for this function:

bool_t halIsCounterWithin ( halrtcnt_t  start,
halrtcnt_t  end 
)

Realtime window test.

This function verifies if the current realtime counter value lies within the specified range or not. The test takes care of the realtime counter wrapping to zero on overflow.

Note:
When start==end then the function returns always true because the whole time range is specified.
This is an optional service that could not be implemented in all HAL implementations.
This function can be called from any context.
Example 1
Example of a guarded loop using the realtime counter. The loop implements a timeout after one second.
   halrtcnt_t start = halGetCounterValue();
   halrtcnt_t timeout  = start + S2RTT(1);
   while (my_condition) {
     if (!halIsCounterWithin(start, timeout)
       return TIMEOUT;
     // Do something.
   }
   // Continue.
Example 2
Example of a loop that lasts exactly 50 microseconds.
   halrtcnt_t start = halGetCounterValue();
   halrtcnt_t timeout  = start + US2RTT(50);
   while (halIsCounterWithin(start, timeout)) {
     // Do something.
   }
   // Continue.
Parameters:
[in]startthe start of the time window (inclusive)
[in]endthe end of the time window (non inclusive)
Return values:
TRUEcurrent time within the specified time window.
FALSEcurrent time not within the specified time window.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 167 of file hal.c.

References halGetCounterValue.

Referenced by halPolledDelay().

void halPolledDelay ( halrtcnt_t  ticks)

Polled delay.

Note:
The real delays is always few cycles in excess of the specified value.
This is an optional service that could not be implemented in all HAL implementations.
This function can be called from any context.
Parameters:
[in]ticksnumber of ticks
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 186 of file hal.c.

References halGetCounterValue, and halIsCounterWithin().

Here is the call graph for this function:

void hal_lld_init ( void  )

Low level HAL driver initialization.

Function Class:
Not an API, this function is for internal use only.

Definition at line 57 of file hal_lld.c.

Referenced by halInit().


Define Documentation

#define S2RTT (   sec)    (halGetCounterFrequency() * (sec))

Seconds to realtime ticks.

Converts from seconds to realtime ticks number.

Note:
The result is rounded upward to the next tick boundary.
Parameters:
[in]secnumber of seconds
Returns:
The number of ticks.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 102 of file hal.h.

#define MS2RTT (   msec)    (((halGetCounterFrequency() + 999UL) / 1000UL) * (msec))

Milliseconds to realtime ticks.

Converts from milliseconds to realtime ticks number.

Note:
The result is rounded upward to the next tick boundary.
Parameters:
[in]msecnumber of milliseconds
Returns:
The number of ticks.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 114 of file hal.h.

#define US2RTT (   usec)
Value:
(((halGetCounterFrequency() + 999999UL) / 1000000UL) * \
                      (usec))

Microseconds to realtime ticks.

Converts from microseconds to realtime ticks number.

Note:
The result is rounded upward to the next tick boundary.
Parameters:
[in]usecnumber of microseconds
Returns:
The number of ticks.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 126 of file hal.h.

#define RTT2S (   ticks)    ((ticks) / halGetCounterFrequency())

Realtime ticks to seconds to.

Converts from realtime ticks number to seconds.

Parameters:
[in]ticksnumber of ticks
Returns:
The number of seconds.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 138 of file hal.h.

#define RTT2MS (   ticks)    ((ticks) / (halGetCounterFrequency() / 1000UL))

Realtime ticks to milliseconds.

Converts from realtime ticks number to milliseconds.

Parameters:
[in]ticksnumber of ticks
Returns:
The number of milliseconds.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 149 of file hal.h.

#define RTT2US (   ticks)    ((ticks) / (halGetCounterFrequency() / 1000000UL))

Realtime ticks to microseconds.

Converts from realtime ticks number to microseconds.

Parameters:
[in]ticksnumber of ticks
Returns:
The number of microseconds.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 160 of file hal.h.

#define halGetCounterValue ( )    hal_lld_get_counter_value()

Returns the current value of the system free running counter.

Note:
This is an optional service that could not be implemented in all HAL implementations.
This function can be called from any context.
Returns:
The value of the system free running counter of type halrtcnt_t.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 178 of file hal.h.

Referenced by halIsCounterWithin(), and halPolledDelay().

#define halGetCounterFrequency ( )    hal_lld_get_counter_frequency()

Realtime counter frequency.

Note:
This is an optional service that could not be implemented in all HAL implementations.
This function can be called from any context.
Returns:
The realtime counter frequency of type halclock_t.
Function Class:
Special function, this function has special requirements see the notes.

Definition at line 190 of file hal.h.

#define HAL_IMPLEMENTS_COUNTERS   FALSE

Defines the support for realtime counters in the HAL.

Definition at line 39 of file hal_lld.h.

#define PLATFORM_NAME   "ATmega128"

Platform name.

Definition at line 44 of file hal_lld.h.