|
ChibiOS/RT
2.5.1 |
|
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. | |
| 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).
Definition at line 61 of file hal.c.
References hal_lld_init(), and sdInit().

| 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.
halrtcnt_t start = halGetCounterValue(); halrtcnt_t timeout = start + S2RTT(1); while (my_condition) { if (!halIsCounterWithin(start, timeout) return TIMEOUT; // Do something. } // Continue.
halrtcnt_t start = halGetCounterValue(); halrtcnt_t timeout = start + US2RTT(50); while (halIsCounterWithin(start, timeout)) { // Do something. } // Continue.
| [in] | start | the start of the time window (inclusive) |
| [in] | end | the end of the time window (non inclusive) |
| TRUE | current time within the specified time window. |
| FALSE | current time not within the specified time window. |
Definition at line 167 of file hal.c.
References halGetCounterValue.
Referenced by halPolledDelay().
| void halPolledDelay | ( | halrtcnt_t | ticks | ) |
Polled delay.
| [in] | ticks | number of ticks |
Definition at line 186 of file hal.c.
References halGetCounterValue, and halIsCounterWithin().

| void hal_lld_init | ( | void | ) |
| #define S2RTT | ( | sec | ) | (halGetCounterFrequency() * (sec)) |
Seconds to realtime ticks.
Converts from seconds to realtime ticks number.
| [in] | sec | number of seconds |
| #define MS2RTT | ( | msec | ) | (((halGetCounterFrequency() + 999UL) / 1000UL) * (msec)) |
Milliseconds to realtime ticks.
Converts from milliseconds to realtime ticks number.
| [in] | msec | number of milliseconds |
| #define US2RTT | ( | usec | ) |
(((halGetCounterFrequency() + 999999UL) / 1000000UL) * \ (usec))
Microseconds to realtime ticks.
Converts from microseconds to realtime ticks number.
| [in] | usec | number of microseconds |
| #define RTT2S | ( | ticks | ) | ((ticks) / halGetCounterFrequency()) |
| #define RTT2MS | ( | ticks | ) | ((ticks) / (halGetCounterFrequency() / 1000UL)) |
Realtime ticks to milliseconds.
Converts from realtime ticks number to milliseconds.
| [in] | ticks | number of ticks |
| #define RTT2US | ( | ticks | ) | ((ticks) / (halGetCounterFrequency() / 1000000UL)) |
Realtime ticks to microseconds.
Converts from realtime ticks number to microseconds.
| [in] | ticks | number of ticks |
| #define halGetCounterValue | ( | ) | hal_lld_get_counter_value() |
Returns the current value of the system free running counter.
Definition at line 178 of file hal.h.
Referenced by halIsCounterWithin(), and halPolledDelay().
| #define halGetCounterFrequency | ( | ) | hal_lld_get_counter_frequency() |
Realtime counter frequency.
| #define HAL_IMPLEMENTS_COUNTERS FALSE |