Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/wait: add module for backend agnostic waits #19719

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpu/arm7_common/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ endif

# Make calls to malloc and friends thread-safe
USEMODULE += malloc_thread_safe

ifneq (,$(filter delay_us_spinning,$(USEMODULE)))
USEMODULE += ztimer_usec
endif
42 changes: 42 additions & 0 deletions cpu/arm7_common/include/wait_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup cpu_arm7_common
* @{
*
* @file
* @brief ARM7 specific busy wait
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
*
*/

#ifndef WAIT_ARCH_H
#define WAIT_ARCH_H

#include <stdint.h>

#include "board.h"
#include "periph_conf.h"

#ifdef __cplusplus
extern "C" {
#endif
#ifndef DOXYGEN

/* ARM7 uses ztimer_spin for busy wait */

#endif

#ifdef __cplusplus
}
#endif
Comment on lines +28 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to provide this dummy file if you use

#if __has_include("wait_arch.h")
#include "wait_arch.h"
#endif 


/** @} */
#endif /* WAIT_ARCH_H */
50 changes: 50 additions & 0 deletions cpu/avr8_common/include/wait_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup cpu_avr8_common
* @{
*
* @file
* @brief AVR specific busy wait
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
*
*/

#ifndef WAIT_ARCH_H
#define WAIT_ARCH_H

#include <stdint.h>

#include "board.h"
#include "periph_conf.h"
#include "time_units.h"

#ifdef __cplusplus
extern "C" {
#endif
#ifndef DOXYGEN

#define HAS_WAIT_US_SPINNING

static inline void wait_us_spinning(uint32_t usecs)
{
uint32_t cycles = usecs * (uint64_t)CLOCK_CORECLOCK / US_PER_SEC;

__builtin_avr_delay_cycles(cycles);
}

#endif

#ifdef __cplusplus
}
#endif

/** @} */
#endif /* WAIT_ARCH_H */
4 changes: 4 additions & 0 deletions cpu/cortexm_common/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ USEMODULE += malloc_thread_safe

# CMSIS headers are fetched using a package
USEPKG += cmsis

ifneq (,$(filter delay_us_spinning,$(USEMODULE)))
USEMODULE += ztimer_usec
endif
50 changes: 50 additions & 0 deletions cpu/cortexm_common/include/wait_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup cpu_cortexm_common
* @{
*
* @file
* @brief Cortex-M specific busy wait
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
*
*/

#ifndef WAIT_ARCH_H
#define WAIT_ARCH_H

#include <stdint.h>

#include "board.h"
#include "periph_conf.h"

#ifdef __cplusplus
extern "C" {
#endif
#ifndef DOXYGEN

#if defined(CPU_CORE_CORTEX_M4) || defined(CPU_CORE_CORTEX_M4F)
# define CPU_CYCLES_PER_WAIT_LOOP_ITERATION 4U
#endif

#if defined(CPU_CORE_CORTEX_M3)
# define CPU_CYCLES_PER_WAIT_LOOP_ITERATION 7U
#endif

/* Cortex M uses ztimer_spin for busy wait */

#endif

#ifdef __cplusplus
}
#endif

/** @} */
#endif /* WAIT_ARCH_H */
4 changes: 4 additions & 0 deletions cpu/esp32/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,7 @@ endif
ifneq (,$(filter usbus_cdc_acm tinyusb_class_cdc,$(USEMODULE)))
USEMODULE += usb_board_reset
endif

ifneq (,$(filter delay_us_spinning,$(USEMODULE)))
USEMODULE += ztimer_usec
endif
42 changes: 42 additions & 0 deletions cpu/esp32/include/wait_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup cpu_esp32
* @{
*
* @file
* @brief ESP32 specific busy wait
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
*
*/

#ifndef WAIT_ARCH_H
#define WAIT_ARCH_H

#include <stdint.h>

#include "board.h"
#include "periph_conf.h"

#ifdef __cplusplus
extern "C" {
#endif
#ifndef DOXYGEN

/* ESP32 uses ztimer_spin for busy wait */

#endif

#ifdef __cplusplus
}
#endif

/** @} */
#endif /* WAIT_ARCH_H */
4 changes: 4 additions & 0 deletions cpu/esp8266/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ ifneq (,$(filter esp_wifi_any,$(USEMODULE)))
# avoid that ztimer_periph_rtt is used as backend
USEMODULE += ztimer_no_periph_rtt
endif

ifneq (,$(filter delay_us_spinning,$(USEMODULE)))
USEMODULE += ztimer_usec
endif
42 changes: 42 additions & 0 deletions cpu/esp8266/include/wait_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup cpu_esp8266
* @{
*
* @file
* @brief ESP8266 specific busy wait
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
*
*/

#ifndef WAIT_ARCH_H
#define WAIT_ARCH_H

#include <stdint.h>

#include "board.h"
#include "periph_conf.h"

#ifdef __cplusplus
extern "C" {
#endif
#ifndef DOXYGEN

/* ESP8266 uses ztimer_spin for busy wait */

#endif

#ifdef __cplusplus
}
#endif

/** @} */
#endif /* WAIT_ARCH_H */
4 changes: 4 additions & 0 deletions cpu/msp430_common/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ endif

# Make calls to malloc and friends thread-safe
USEMODULE += malloc_thread_safe

ifneq (,$(filter delay_us_spinning,$(USEMODULE)))
USEMODULE += ztimer_usec
endif
42 changes: 42 additions & 0 deletions cpu/msp430_common/include/wait_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup cpu_msp430_common
* @{
*
* @file
* @brief MSP430 specific busy wait
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
*
*/

#ifndef WAIT_ARCH_H
#define WAIT_ARCH_H

#include <stdint.h>

#include "board.h"
#include "periph_conf.h"

#ifdef __cplusplus
extern "C" {
#endif
#ifndef DOXYGEN

/* MSP430 uses ztimer_spin for busy wait */

#endif

#ifdef __cplusplus
}
#endif

/** @} */
#endif /* WAIT_ARCH_H */
42 changes: 42 additions & 0 deletions cpu/native/include/wait_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup cpu_native
* @{
*
* @file
* @brief "native" specific busy wait
*
* @author Marian Buschsieweke <marian.buschsieweke@posteo.net>
*
*/

#ifndef WAIT_ARCH_H
#define WAIT_ARCH_H

#include <stdint.h>

#include "board.h"
#include "periph_conf.h"

#ifdef __cplusplus
extern "C" {
#endif
#ifndef DOXYGEN

/* ARM7 uses ztimer_spin for busy wait */

#endif

#ifdef __cplusplus
}
#endif

/** @} */
#endif /* WAIT_ARCH_H */
4 changes: 4 additions & 0 deletions cpu/riscv_common/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ USEMODULE += riscv_common_periph

# Make calls to malloc and friends thread-safe
USEMODULE += malloc_thread_safe

ifneq (,$(filter delay_us_spinning,$(USEMODULE)))
USEMODULE += ztimer_usec
endif
Loading