mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-15 09:33:50 +01:00
sys/ztimer: add periph_ptp backend
This commit is contained in:
parent
28e6544748
commit
b1aaa974bd
54
sys/include/ztimer/periph_ptp.h
Normal file
54
sys/include/ztimer/periph_ptp.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
2021 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup sys_ztimer_periph_ptp ztimer periph/ptp backend
|
||||
* @ingroup sys_ztimer
|
||||
* @brief ztimer periph/ptp backend
|
||||
*
|
||||
* This ztimer module implements a ztimer virtual clock on top of periph/ptp.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief ztimer periph/ptp backend API
|
||||
*
|
||||
* @author Jana Eisoldt <jana.eisoldt@ovgu.de>
|
||||
*/
|
||||
|
||||
#ifndef ZTIMER_PERIPH_PTP_H
|
||||
#define ZTIMER_PERIPH_PTP_H
|
||||
|
||||
#include "ztimer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief ztimer_periph_ptp structure definition
|
||||
*
|
||||
* The periph/ptp backend has no private fields, thus this is just a typedef
|
||||
* to ztimer_clock_t.
|
||||
*/
|
||||
typedef ztimer_clock_t ztimer_periph_ptp_t;
|
||||
|
||||
/**
|
||||
* @brief ztimer periph/ptp backend initialization function
|
||||
*
|
||||
* @param[in, out] clock ztimer_periph_ptp object to initialize
|
||||
*/
|
||||
void ztimer_periph_ptp_init(ztimer_periph_ptp_t *clock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZTIMER_PERIPH_PTP_H */
|
||||
/** @} */
|
||||
@ -28,6 +28,11 @@ config MODULE_ZTIMER_PERIPH_RTT
|
||||
select MODULE_PERIPH_RTT
|
||||
default y if !MODULE_ZTIMER_PERIPH_TIMER
|
||||
|
||||
config MODULE_ZTIMER_PERIPH_PTP
|
||||
bool "PTP peripheral"
|
||||
depends on HAS_PERIPH_PTP_TIMER
|
||||
select MODULE_PERIPH_PTP_TIMER
|
||||
|
||||
config MODULE_ZTIMER_PERIPH_TIMER
|
||||
bool "Timer peripheral"
|
||||
depends on HAS_PERIPH_TIMER
|
||||
|
||||
@ -70,6 +70,10 @@ ifneq (,$(filter ztimer_periph_rtt,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_rtt
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ztimer_periph_ptp,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_ptp_timer
|
||||
endif
|
||||
|
||||
ifneq (,$(filter ztimer_convert_frac,$(USEMODULE)))
|
||||
USEMODULE += frac
|
||||
endif
|
||||
|
||||
68
sys/ztimer/periph_ptp.c
Normal file
68
sys/ztimer/periph_ptp.c
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
2021 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 sys_ztimer_periph_ptp
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief ztimer periph/ptp implementation
|
||||
*
|
||||
* @author Jana Eisoldt <jana.eisoldt@ovgu.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
#include "assert.h"
|
||||
|
||||
#include "irq.h"
|
||||
#include "periph/ptp.h"
|
||||
#include "ztimer/periph_ptp.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
|
||||
static ztimer_clock_t *clock_timer;
|
||||
|
||||
void ptp_timer_cb(void)
|
||||
{
|
||||
ztimer_handler(clock_timer);
|
||||
}
|
||||
|
||||
static void _ztimer_periph_ptp_set(ztimer_clock_t *clock, uint32_t val)
|
||||
{
|
||||
(void)clock;
|
||||
ptp_timer_set_u64(val);
|
||||
}
|
||||
|
||||
static uint32_t _ztimer_periph_ptp_now(ztimer_clock_t *clock)
|
||||
{
|
||||
(void)clock;
|
||||
return (uint32_t)ptp_clock_read_u64();
|
||||
}
|
||||
|
||||
static void _ztimer_periph_ptp_cancel(ztimer_clock_t *clock)
|
||||
{
|
||||
(void)clock;
|
||||
ptp_timer_clear();
|
||||
}
|
||||
|
||||
static const ztimer_ops_t _ztimer_periph_ptp_ops = {
|
||||
.set = _ztimer_periph_ptp_set,
|
||||
.now = _ztimer_periph_ptp_now,
|
||||
.cancel = _ztimer_periph_ptp_cancel,
|
||||
};
|
||||
|
||||
void ztimer_periph_ptp_init(ztimer_periph_ptp_t *clock)
|
||||
{
|
||||
clock->ops = &_ztimer_periph_ptp_ops;
|
||||
clock->max_value = UINT32_MAX;
|
||||
clock_timer = clock;
|
||||
|
||||
ztimer_init_extend(clock);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user