xref: /nrf52832-nimble/packages/NimBLE-latest/porting/npl/linux/src/os_types.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
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 _NPL_OS_TYPES_H
21 #define _NPL_OS_TYPES_H
22 
23 #include <time.h>
24 #include <signal.h>
25 #include <stdbool.h>
26 #include <pthread.h>
27 #include <semaphore.h>
28 
29 #define BLE_NPL_WAIT_FOREVER (-1)
30 
31 /* The highest and lowest task priorities */
32 #define OS_TASK_PRI_HIGHEST (sched_get_priority_max(SCHED_RR))
33 #define OS_TASK_PRI_LOWEST  (sched_get_priority_min(SCHED_RR))
34 
35 typedef uint32_t ble_npl_time_t;
36 typedef int32_t ble_npl_stime_t;
37 
38 //typedef int os_sr_t;
39 typedef int ble_npl_stack_t;
40 
41 
42 struct ble_npl_event {
43     uint8_t                 ev_queued;
44     ble_npl_event_fn       *ev_cb;
45     void                   *ev_arg;
46 };
47 
48 struct ble_npl_eventq {
49     void               *q;
50 };
51 
52 struct ble_npl_callout {
53     struct ble_npl_event    c_ev;
54     struct ble_npl_eventq  *c_evq;
55     uint32_t                c_ticks;
56     timer_t                 c_timer;
57     bool                    c_active;
58 };
59 
60 struct ble_npl_mutex {
61     pthread_mutex_t         lock;
62 };
63 
64 struct ble_npl_sem {
65     sem_t                   lock;
66 };
67 
68 struct ble_npl_task {
69     pthread_t               handle;
70     const char*             name;
71 };
72 
73 typedef void *(*ble_npl_task_func_t)(void *);
74 
75 int ble_npl_task_init(struct ble_npl_task *t, const char *name, ble_npl_task_func_t func,
76 		 void *arg, uint8_t prio, ble_npl_time_t sanity_itvl,
77 		 ble_npl_stack_t *stack_bottom, uint16_t stack_size);
78 
79 int ble_npl_task_remove(struct ble_npl_task *t);
80 
81 uint8_t ble_npl_task_count(void);
82 
83 void ble_npl_task_yield(void);
84 
85 #endif // _NPL_OS_TYPES_H
86