source: rtems/bsps/powerpc/include/bsp/tictac.h @ 5810a08

Last change on this file since 5810a08 was 5810a08, checked in by Sebastian Huber <sebastian.huber@…>, on 07/27/22 at 13:20:32

Use asm for standard C compatibility

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSBSPsPowerPCShared
7 *
8 * @brief Header file for tic-tac code.
9 */
10
11/*
12 * Copyright (c) 2008 embedded brains GmbH.  All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35/**
36 * @brief Reset reference ticks for tac().
37 */
38static inline void tic(void)
39{
40        uint32_t tmp;
41        __asm__ volatile (
42                "mftb 0;"
43                "stw 0, ppc_tic_tac@sdarel(13);"
44                : "=r" (tmp)
45        );
46}
47
48/**
49 * @brief Returns number of ticks since last tic().
50 */
51static inline uint32_t tac(void)
52{
53        uint32_t ticks;
54        uint32_t tmp;
55        __asm__ volatile (
56                "mftb %0;"
57                "lwz %1, ppc_tic_tac@sdarel(13);"
58                "subf %0, %1, %0;"
59                : "=r" (ticks), "=r" (tmp)
60        );
61        return ticks;
62}
63
64/**
65 * @brief Reset reference ticks for bam().
66 */
67static inline void boom(void)
68{
69        uint32_t tmp;
70        __asm__ volatile (
71                "mftb 0;"
72                "stw 0, ppc_boom_bam@sdarel(13);"
73                : "=r" (tmp)
74        );
75}
76
77/**
78 * @brief Returns number of ticks since last boom().
79 */
80static inline uint32_t bam(void)
81{
82        uint32_t ticks;
83        uint32_t tmp;
84        __asm__ volatile (
85                "mftb %0;"
86                "lwz %1, ppc_boom_bam@sdarel(13);"
87                "subf %0, %1, %0;"
88                : "=r" (ticks), "=r" (tmp)
89        );
90        return ticks;
91}
Note: See TracBrowser for help on using the repository browser.