Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
8c90b102
Commit
8c90b102
authored
8 years ago
by
Joakim Nohlgård
Browse files
Options
Downloads
Patches
Plain Diff
xtimer: Split header into API and implementation
parent
9bb61f5a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/include/xtimer.h
+2
-121
2 additions, 121 deletions
sys/include/xtimer.h
sys/include/xtimer/implementation.h
+160
-0
160 additions, 0 deletions
sys/include/xtimer/implementation.h
with
162 additions
and
121 deletions
sys/include/xtimer.h
+
2
−
121
View file @
8c90b102
...
...
@@ -29,20 +29,12 @@
#define XTIMER_H
#include
<stdint.h>
#include
"msg.h"
#include
"periph/timer.h"
#include
"timex.h"
#include
"msg.h"
#include
"board.h"
#include
"periph_conf.h"
/**
* @brief internal define to allow using variables instead of defines
*/
#ifdef XTIMER_TRACE
#include
"xtimer_trace.h"
#endif
#ifdef __cplusplus
extern
"C"
{
#endif
...
...
@@ -349,14 +341,6 @@ int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t us);
#define XTIMER_SHIFT (0)
#endif
#if (XTIMER_SHIFT < 0)
#define XTIMER_USEC_TO_TICKS(value) ( (value) << -XTIMER_SHIFT )
#define XTIMER_TICKS_TO_USEC(value) ( (value) >> -XTIMER_SHIFT )
#else
#define XTIMER_USEC_TO_TICKS(value) ( (value) >> XTIMER_SHIFT )
#define XTIMER_TICKS_TO_USEC(value) ( (value) << XTIMER_SHIFT )
#endif
/*
* Default xtimer configuration
*/
...
...
@@ -405,110 +389,7 @@ int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t us);
#define XTIMER_MASK_SHIFTED XTIMER_TICKS_TO_USEC(XTIMER_MASK)
#if XTIMER_MASK
extern
volatile
uint32_t
_high_cnt
;
#endif
/**
* @brief IPC message type for xtimer msg callback
*/
#define MSG_XTIMER 12345
/**
* @brief returns the (masked) low-level timer counter value.
*/
static
inline
uint32_t
_lltimer_now
(
void
)
{
#if XTIMER_SHIFT
return
XTIMER_TICKS_TO_USEC
((
uint32_t
)
timer_read
(
XTIMER
));
#else
return
timer_read
(
XTIMER
);
#endif
}
/**
* @brief drop bits of a value that don't fit into the low-level timer.
*/
static
inline
uint32_t
_lltimer_mask
(
uint32_t
val
)
{
return
val
&
~
XTIMER_MASK_SHIFTED
;
}
/**
* @{
* @brief xtimer internal stuff
* @internal
*/
int
_xtimer_set_absolute
(
xtimer_t
*
timer
,
uint32_t
target
);
void
_xtimer_set64
(
xtimer_t
*
timer
,
uint32_t
offset
,
uint32_t
long_offset
);
void
_xtimer_sleep
(
uint32_t
offset
,
uint32_t
long_offset
);
static
inline
void
xtimer_spin_until
(
uint32_t
value
);
/** @} */
#ifndef XTIMER_MIN_SPIN
/**
* @brief Minimal value xtimer_spin() can spin
*/
#define XTIMER_MIN_SPIN XTIMER_TICKS_TO_USEC(1)
#endif
static
inline
uint32_t
xtimer_now
(
void
)
{
#if XTIMER_MASK
uint32_t
latched_high_cnt
,
now
;
/* _high_cnt can change at any time, so check the value before
* and after reading the low-level timer. If it hasn't changed,
* then it can be safely applied to the timer count. */
do
{
latched_high_cnt
=
_high_cnt
;
now
=
_lltimer_now
();
}
while
(
_high_cnt
!=
latched_high_cnt
);
return
latched_high_cnt
|
now
;
#else
return
_lltimer_now
();
#endif
}
static
inline
void
xtimer_spin_until
(
uint32_t
target
)
{
#if XTIMER_MASK
target
=
_lltimer_mask
(
target
);
#endif
while
(
_lltimer_now
()
>
target
);
while
(
_lltimer_now
()
<
target
);
}
static
inline
void
xtimer_spin
(
uint32_t
offset
)
{
uint32_t
start
=
_lltimer_now
();
#if XTIMER_MASK
offset
=
_lltimer_mask
(
offset
);
while
(
_lltimer_mask
(
_lltimer_now
()
-
start
)
<
offset
);
#else
while
((
_lltimer_now
()
-
start
)
<
offset
);
#endif
}
static
inline
void
xtimer_usleep
(
uint32_t
microseconds
)
{
_xtimer_sleep
(
microseconds
,
0
);
}
static
inline
void
xtimer_usleep64
(
uint64_t
microseconds
)
{
_xtimer_sleep
((
uint32_t
)
microseconds
,
(
uint32_t
)
(
microseconds
>>
32
));
}
static
inline
void
xtimer_sleep
(
uint32_t
seconds
)
{
xtimer_usleep64
((
uint64_t
)
seconds
*
SEC_IN_USEC
);
}
static
inline
void
xtimer_nanosleep
(
uint32_t
nanoseconds
)
{
_xtimer_sleep
(
nanoseconds
/
USEC_IN_NS
,
0
);
}
#include
"xtimer/implementation.h"
#ifdef __cplusplus
}
...
...
This diff is collapsed.
Click to expand it.
sys/include/xtimer/implementation.h
0 → 100644
+
160
−
0
View file @
8c90b102
/*
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
* Copyright (C) 2016 Eistec AB
*
* 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_xtimer
* @{
* @file
* @brief xtimer implementation
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
*/
#ifndef XTIMER_IMPLEMENTATION_H_
#define XTIMER_IMPLEMENTATION_H_
#ifndef XTIMER_H
#error "Do not include this file directly! Use xtimer.h instead"
#endif
#include
"periph/timer.h"
/**
* @brief internal define to allow using variables instead of defines
*/
#ifdef XTIMER_TRACE
#include
"xtimer_trace.h"
#endif
#ifdef __cplusplus
extern
"C"
{
#endif
#if XTIMER_MASK
extern
volatile
uint32_t
_high_cnt
;
#endif
#if (XTIMER_SHIFT < 0)
#define XTIMER_USEC_TO_TICKS(value) ( (value) << -XTIMER_SHIFT )
#define XTIMER_TICKS_TO_USEC(value) ( (value) >> -XTIMER_SHIFT )
#else
#define XTIMER_USEC_TO_TICKS(value) ( (value) >> XTIMER_SHIFT )
#define XTIMER_TICKS_TO_USEC(value) ( (value) << XTIMER_SHIFT )
#endif
/**
* @brief IPC message type for xtimer msg callback
*/
#define MSG_XTIMER 12345
/**
* @brief returns the (masked) low-level timer counter value.
*/
static
inline
uint32_t
_lltimer_now
(
void
)
{
#if XTIMER_SHIFT
return
XTIMER_TICKS_TO_USEC
((
uint32_t
)
timer_read
(
XTIMER
));
#else
return
timer_read
(
XTIMER
);
#endif
}
/**
* @brief drop bits of a value that don't fit into the low-level timer.
*/
static
inline
uint32_t
_lltimer_mask
(
uint32_t
val
)
{
return
val
&
~
XTIMER_MASK_SHIFTED
;
}
/**
* @{
* @brief xtimer internal stuff
* @internal
*/
int
_xtimer_set_absolute
(
xtimer_t
*
timer
,
uint32_t
target
);
void
_xtimer_set64
(
xtimer_t
*
timer
,
uint32_t
offset
,
uint32_t
long_offset
);
void
_xtimer_sleep
(
uint32_t
offset
,
uint32_t
long_offset
);
/** @} */
#ifndef XTIMER_MIN_SPIN
/**
* @brief Minimal value xtimer_spin() can spin
*/
#define XTIMER_MIN_SPIN XTIMER_TICKS_TO_USEC(1)
#endif
#ifndef DOXYGEN
/* Doxygen warns that these are undocumented, but the documentation can be found in xtimer.h */
static
inline
uint32_t
xtimer_now
(
void
)
{
#if XTIMER_MASK
uint32_t
latched_high_cnt
,
now
;
/* _high_cnt can change at any time, so check the value before
* and after reading the low-level timer. If it hasn't changed,
* then it can be safely applied to the timer count. */
do
{
latched_high_cnt
=
_high_cnt
;
now
=
_lltimer_now
();
}
while
(
_high_cnt
!=
latched_high_cnt
);
return
latched_high_cnt
|
now
;
#else
return
_lltimer_now
();
#endif
}
static
inline
void
xtimer_spin_until
(
uint32_t
target
)
{
#if XTIMER_MASK
target
=
_lltimer_mask
(
target
);
#endif
while
(
_lltimer_now
()
>
target
);
while
(
_lltimer_now
()
<
target
);
}
static
inline
void
xtimer_spin
(
uint32_t
offset
)
{
uint32_t
start
=
_lltimer_now
();
#if XTIMER_MASK
offset
=
_lltimer_mask
(
offset
);
while
(
_lltimer_mask
(
_lltimer_now
()
-
start
)
<
offset
);
#else
while
((
_lltimer_now
()
-
start
)
<
offset
);
#endif
}
static
inline
void
xtimer_usleep
(
uint32_t
microseconds
)
{
_xtimer_sleep
(
microseconds
,
0
);
}
static
inline
void
xtimer_usleep64
(
uint64_t
microseconds
)
{
_xtimer_sleep
((
uint32_t
)
microseconds
,
(
uint32_t
)
(
microseconds
>>
32
));
}
static
inline
void
xtimer_sleep
(
uint32_t
seconds
)
{
xtimer_usleep64
((
uint64_t
)
seconds
*
SEC_IN_USEC
);
}
static
inline
void
xtimer_nanosleep
(
uint32_t
nanoseconds
)
{
_xtimer_sleep
(
nanoseconds
/
USEC_IN_NS
,
0
);
}
#endif
/* !defined(DOXYGEN) */
#ifdef __cplusplus
}
#endif
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment