NimBLE-Arduino 2.1.3
Loading...
Searching...
No Matches
nimble_npl.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _NIMBLE_NPL_H_
21#define _NIMBLE_NPL_H_
22
23#include <stdbool.h>
24#include <stddef.h>
25#include <stdint.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31struct ble_npl_event;
32typedef void ble_npl_event_fn(struct ble_npl_event *ev);
33
34enum ble_npl_error {
35 BLE_NPL_OK = 0,
36 BLE_NPL_ENOMEM = 1,
37 BLE_NPL_EINVAL = 2,
38 BLE_NPL_INVALID_PARAM = 3,
39 BLE_NPL_MEM_NOT_ALIGNED = 4,
40 BLE_NPL_BAD_MUTEX = 5,
41 BLE_NPL_TIMEOUT = 6,
42 BLE_NPL_ERR_IN_ISR = 7,
43 BLE_NPL_ERR_PRIV = 8,
44 BLE_NPL_OS_NOT_STARTED = 9,
45 BLE_NPL_ENOENT = 10,
46 BLE_NPL_EBUSY = 11,
47 BLE_NPL_ERROR = 12,
48};
49
50typedef enum ble_npl_error ble_npl_error_t;
51
52/* Include OS-specific definitions */
53#include "nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h"
54
55/*
56 * Generic
57 */
58
59bool ble_npl_os_started(void);
60
61void *ble_npl_get_current_task_id(void);
62
63/*
64 * Event queue
65 */
66
67void ble_npl_eventq_init(struct ble_npl_eventq *evq);
68
69void ble_npl_eventq_deinit(struct ble_npl_eventq *evq);
70
71struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq,
72 ble_npl_time_t tmo);
73
74void ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev);
75
76void ble_npl_eventq_remove(struct ble_npl_eventq *evq,
77 struct ble_npl_event *ev);
78
79void ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
80 void *arg);
81
82bool ble_npl_event_is_queued(struct ble_npl_event *ev);
83
84void *ble_npl_event_get_arg(struct ble_npl_event *ev);
85
86void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg);
87
88bool ble_npl_eventq_is_empty(struct ble_npl_eventq *evq);
89
90void ble_npl_event_run(struct ble_npl_event *ev);
91
92/*
93 * Mutexes
94 */
95
96ble_npl_error_t ble_npl_mutex_init(struct ble_npl_mutex *mu);
97
98ble_npl_error_t ble_npl_mutex_pend(struct ble_npl_mutex *mu,
99 ble_npl_time_t timeout);
100
101ble_npl_error_t ble_npl_mutex_release(struct ble_npl_mutex *mu);
102
103ble_npl_error_t ble_npl_mutex_deinit(struct ble_npl_mutex *mu);
104
105/*
106 * Semaphores
107 */
108
109ble_npl_error_t ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens);
110
111ble_npl_error_t ble_npl_sem_pend(struct ble_npl_sem *sem,
112 ble_npl_time_t timeout);
113
114ble_npl_error_t ble_npl_sem_release(struct ble_npl_sem *sem);
115
116ble_npl_error_t ble_npl_sem_deinit(struct ble_npl_sem *sem);
117
118uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem);
119
120/*
121 * Callouts
122 */
123
124int ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
125 ble_npl_event_fn *ev_cb, void *ev_arg);
126
127ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *co,
128 ble_npl_time_t ticks);
129
130void ble_npl_callout_stop(struct ble_npl_callout *co);
131
132bool ble_npl_callout_is_active(struct ble_npl_callout *co);
133
134ble_npl_time_t ble_npl_callout_get_ticks(struct ble_npl_callout *co);
135
136ble_npl_time_t ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
137 ble_npl_time_t time);
138
139void ble_npl_callout_set_arg(struct ble_npl_callout *co,
140 void *arg);
141/*
142 * Time functions
143 */
144
145ble_npl_time_t ble_npl_time_get(void);
146
147ble_npl_error_t ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks);
148
149ble_npl_error_t ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms);
150
151ble_npl_time_t ble_npl_time_ms_to_ticks32(uint32_t ms);
152
153uint32_t ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks);
154
155void ble_npl_time_delay(ble_npl_time_t ticks);
156
157/*
158 * Hardware-specific
159 *
160 * These symbols should be most likely defined by application since they are
161 * specific to hardware, not to OS.
162 */
163
164#if NIMBLE_CFG_CONTROLLER
165
166void ble_npl_hw_set_isr(int irqn, void (*addr)(void));
167
168#endif
169
170uint32_t ble_npl_hw_enter_critical(void);
171
172void ble_npl_hw_exit_critical(uint32_t ctx);
173
174bool ble_npl_hw_is_in_critical(void);
175
176#ifdef __cplusplus
177}
178#endif
179
180#endif /* _NIMBLE_NPL_H_ */