Select one of the symbols to view example projects that use it.
 
Outline
#define _HARDWARE_CLAIM_H
#include "pico.h"
#include "hardware/sync.h"
hw_claim_or_assert(uint8_t *, uint, const char *);
hw_claim_unused_from_range(uint8_t *, bool, uint, uint, const char *);
hw_is_claimed(const uint8_t *, uint);
hw_claim_clear(uint8_t *, uint);
hw_claim_lock();
hw_claim_unlock(uint32_t);
Files
loading...
SourceVuRaspberry Pi Pico SDK and ExamplesPicoSDKsrc/common/hardware_claim/include/hardware/claim.h
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. * * SPDX-License-Identifier: BSD-3-Clause *//* ... */ #ifndef _HARDWARE_CLAIM_H #define _HARDWARE_CLAIM_H #include "pico.h" #include "hardware/sync.h" /** \file claim.h * \defgroup hardware_claim hardware_claim * \brief Lightweight hardware resource management API * * `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: * * 1. Claiming resources (and asserting if they are already claimed) * 2. Freeing (unclaiming) resources * 3. Finding unused resources *//* ... */ #ifdef __cplusplus extern "C" { #endif /*! \brief Atomically claim a resource, panicking if it is already in use * \ingroup hardware_claim * * The resource ownership is indicated by the bit_index bit in an array of bits. * * \param bits pointer to an array of bits (8 bits per byte) * \param bit_index resource to claim (bit index into array of bits) * \param 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_or_assert(uint8_t *bits, uint bit_index, const char *message); /*! \brief Atomically claim one resource out of a range of resources, optionally asserting if none are free * \ingroup hardware_claim * * \param bits pointer to an array of bits (8 bits per byte) * \param required true if this method should panic if the resource is not free * \param bit_lsb the lower bound (inclusive) of the resource range to claim from * \param bit_msb the upper bound (inclusive) of the resource range to claim from * \param message string to display if the bit cannot be claimed * \return the bit index representing the claimed or -1 if none are available in the range, and required = false *//* ... */ int hw_claim_unused_from_range(uint8_t *bits, bool required, uint bit_lsb, uint bit_msb, const char *message); /*! \brief Determine if a resource is claimed at the time of the call * \ingroup hardware_claim * * The resource ownership is indicated by the bit_index bit in an array of bits. * * \param bits pointer to an array of bits (8 bits per byte) * \param bit_index resource to check (bit index into array of bits) * \return true if the resource is claimed *//* ... */ bool hw_is_claimed(const uint8_t *bits, uint bit_index); /*! \brief Atomically unclaim a resource * \ingroup hardware_claim * * The resource ownership is indicated by the bit_index bit in an array of bits. * * \param bits pointer to an array of bits (8 bits per byte) * \param bit_index resource to unclaim (bit index into array of bits) *//* ... */ void hw_claim_clear(uint8_t *bits, uint bit_index); /*! \brief Acquire the runtime mutual exclusion lock provided by the `hardware_claim` library * \ingroup hardware_claim * * 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. * * \note hw_claim_lock() uses a spin lock internally, so disables interrupts on the calling core, and will deadlock * if the calling core already owns the lock. * * \return a token to pass to hw_claim_unlock() *//* ... */ uint32_t hw_claim_lock(void); /*! \brief Release the runtime mutual exclusion lock provided by the `hardware_claim` library * \ingroup hardware_claim * * \note This method MUST be called from the same core that call hw_claim_lock() * * \param token the token returned by the corresponding call to hw_claim_lock() *//* ... */ void hw_claim_unlock(uint32_t token); #ifdef __cplusplus }extern "C" { ... } #endif /* ... */ #endif
Details