Loading...
Searching...
No Matches
os.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015-2021 The Apache Software Foundation
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
17
18#include <assert.h>
19#include <stdint.h>
20
21#include "irq.h"
22#include "os/os_types.h"
23#include "os/os_error.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
38#ifndef min
39#define min(a, b) ((a)<(b)?(a):(b))
40#endif
41
42#ifndef max
43#define max(a, b) ((a)>(b)?(a):(b))
44#endif
45
46#define OS_ALIGN(__n, __a) ( \
47 (((__n) & ((__a) - 1)) == 0) ? \
48 (__n) : \
49 ((__n) + ((__a) - ((__n) & ((__a) - 1)))) \
50 )
51#define OS_ALIGNMENT (4)
53
57typedef uint32_t os_sr_t;
58
63#define OS_ENTER_CRITICAL(_sr) (_sr = os_hw_enter_critical())
64#define OS_EXIT_CRITICAL(_sr) (os_hw_exit_critical(_sr))
65#define OS_ASSERT_CRITICAL() assert(os_hw_is_in_critical())
67
73static inline uint32_t os_hw_enter_critical(void)
74{
75 uint32_t ctx = irq_disable();
76 return ctx;
77}
78
84static inline void os_hw_exit_critical(uint32_t ctx)
85{
86 irq_restore((unsigned)ctx);
87}
88
94static inline bool os_hw_is_in_critical(void)
95{
96 return (irq_is_in() || !irq_is_enabled());
97}
98
99/* Mynewt components (not abstracted in NPL or DPL) */
100#include "os/endian.h"
101#include "os/os_callout.h"
102#include "os/os_cputime.h"
103#include "os/os_dev.h"
104#include "os/os_eventq.h"
105#include "os/os_mbuf.h"
106#include "os/os_mempool.h"
107#include "os/os_mutex.h"
108#include "os/os_sem.h"
109#include "os/os_task.h"
110#include "os/os_time.h"
111#include "os/os_trace_api.h"
112#include "os/queue.h"
113
114#if IS_USED(MODULE_NIMBLE)
115#include "nimble/nimble_npl.h"
116#endif
117
118#ifdef __cplusplus
119}
120#endif
POSIX.1-2008 compliant version of the assert macro.
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
MAYBE_INLINE bool irq_is_enabled(void)
Test if IRQs are currently enabled.
MAYBE_INLINE bool irq_is_in(void)
Check whether called from interrupt service routine.
IRQ driver interface.
static bool os_hw_is_in_critical(void)
Check if is in critical section.
Definition os.h:94
static void os_hw_exit_critical(uint32_t ctx)
Restores ISR context.
Definition os.h:84
static uint32_t os_hw_enter_critical(void)
Disable ISRs.
Definition os.h:73
uint32_t os_sr_t
CPU status register.
Definition os.h:57
Abstraction layer for RIOT adaption.
mynewt-core event and event queue abstraction
mynewt-core time abstraction
mynewt-core types