Lightweight hardware resource management. More...
Functions | |
void | hw_claim_or_assert (uint8_t *bits, uint bit_index, const char *message) |
Atomically claim a resource, panicking if it is already in use. More... | |
int | hw_claim_unused_from_range (uint8_t *bits, bool required, uint bit_lsb, uint bit_msb, const char *message) |
Atomically claim one resource out of a range of resources, optionally asserting if none are free. More... | |
bool | hw_is_claimed (const uint8_t *bits, uint bit_index) |
Determine if a resource is claimed at the time of the call. More... | |
void | hw_claim_clear (uint8_t *bits, uint bit_index) |
Atomically unclaim a resource. More... | |
uint32_t | hw_claim_lock (void) |
Acquire the runtime mutual exclusion lock provided by the hardware_claim library. More... | |
void | hw_claim_unlock (uint32_t token) |
Release the runtime mutual exclusion lock provided by the hardware_claim library. More... | |
Lightweight hardware resource management.
hardware_claim
provides a simple API for management of hardware resources at runtime.
This API is usually called by other hardware specific claiming APIs and provides simple multi-core safe methods to manipulate compact bit-sets representing hardware resources.
This API allows any other library to cooperatively participate in a scheme by which both compile time and runtime allocation of resources can co-exist, and conflicts can be avoided or detected (depending on the use case) without the libraries having any other knowledge of each other.
Facilities are providing for:
void hw_claim_clear | ( | uint8_t * | bits, |
uint | bit_index | ||
) |
Atomically unclaim a resource.
The resource ownership is indicated by the bit_index bit in an array of bits.
bits | pointer to an array of bits (8 bits per byte) |
bit_index | resource to unclaim (bit index into array of bits) |
uint32_t hw_claim_lock | ( | void | ) |
Acquire the runtime mutual exclusion lock provided by the hardware_claim
library.
This method is called automatically by the other hw_claim_
methods, however it is provided as a convenience to code that might want to protect other hardware initialization code from concurrent use.
void hw_claim_or_assert | ( | uint8_t * | bits, |
uint | bit_index, | ||
const char * | message | ||
) |
Atomically claim a resource, panicking if it is already in use.
The resource ownership is indicated by the bit_index bit in an array of bits.
bits | pointer to an array of bits (8 bits per byte) |
bit_index | resource to claim (bit index into array of bits) |
message | string to display if the bit cannot be claimed; note this may have a single printf format "%d" for the bit |
void hw_claim_unlock | ( | uint32_t | token | ) |
Release the runtime mutual exclusion lock provided by the hardware_claim
library.
token | the token returned by the corresponding call to hw_claim_lock() |
int hw_claim_unused_from_range | ( | uint8_t * | bits, |
bool | required, | ||
uint | bit_lsb, | ||
uint | bit_msb, | ||
const char * | message | ||
) |
Atomically claim one resource out of a range of resources, optionally asserting if none are free.
bits | pointer to an array of bits (8 bits per byte) |
required | true if this method should panic if the resource is not free |
bit_lsb | the lower bound (inclusive) of the resource range to claim from |
bit_msb | the upper bound (inclusive) of the resource range to claim from |
message | string to display if the bit cannot be claimed |
|
inline |
Determine if a resource is claimed at the time of the call.
The resource ownership is indicated by the bit_index bit in an array of bits.
bits | pointer to an array of bits (8 bits per byte) |
bit_index | resource to check (bit index into array of bits) |