Loading...
Searching...
No Matches
os.h
Go to the documentation of this file.
1
28
29#pragma once
30
40
41#include <assert.h>
42#include <stdint.h>
43
44#include "irq.h"
45#include "os/os_types.h"
46#include "os/os_error.h"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
61#ifndef min
62#define min(a, b) ((a)<(b)?(a):(b))
63#endif
64
65#ifndef max
66#define max(a, b) ((a)>(b)?(a):(b))
67#endif
68
69#define OS_ALIGN(__n, __a) ( \
70 (((__n) & ((__a) - 1)) == 0) ? \
71 (__n) : \
72 ((__n) + ((__a) - ((__n) & ((__a) - 1)))) \
73 )
74#define OS_ALIGNMENT (4)
76
80typedef uint32_t os_sr_t;
81
86#define OS_ENTER_CRITICAL(_sr) (_sr = os_hw_enter_critical())
87#define OS_EXIT_CRITICAL(_sr) (os_hw_exit_critical(_sr))
88#define OS_ASSERT_CRITICAL() assert(os_hw_is_in_critical())
90
96static inline uint32_t os_hw_enter_critical(void)
97{
98 uint32_t ctx = irq_disable();
99 return ctx;
100}
101
107static inline void os_hw_exit_critical(uint32_t ctx)
108{
109 irq_restore((unsigned)ctx);
110}
111
117static inline bool os_hw_is_in_critical(void)
118{
119 return (irq_is_in() || !irq_is_enabled());
120}
121
122/* Mynewt components (not abstracted in NPL or DPL) */
123#include "os/endian.h"
124#include "os/os_callout.h"
125#include "os/os_cputime.h"
126#include "os/os_dev.h"
127#include "os/os_eventq.h"
128#include "os/os_mbuf.h"
129#include "os/os_mempool.h"
130#include "os/os_mutex.h"
131#include "os/os_sem.h"
132#include "os/os_task.h"
133#include "os/os_time.h"
134#include "os/os_trace_api.h"
135#include "os/queue.h"
136
137#if IS_USED(MODULE_NIMBLE)
138#include "nimble/nimble_npl.h"
139#endif
140
141#ifdef __cplusplus
142}
143#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:117
static void os_hw_exit_critical(uint32_t ctx)
Restores ISR context.
Definition os.h:107
static uint32_t os_hw_enter_critical(void)
Disable ISRs.
Definition os.h:96
uint32_t os_sr_t
CPU status register.
Definition os.h:80
Abstraction layer for RIOT adaption.
mynewt-core event and event queue abstraction
mynewt-core time abstraction
mynewt-core types