![]() |
|
|||
File indexing completed on 2025-05-11 08:23:02
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup RTEMSDriverClockArmv7MSysTick 0007 * 0008 * @brief This header file provides support for Armv7-M clock drivers. 0009 */ 0010 0011 /* 0012 * Copyright (C) 2024 embedded brains GmbH & Co. KG 0013 * Copyright (C) 2011, 2018 Sebastian Huber 0014 * 0015 * Redistribution and use in source and binary forms, with or without 0016 * modification, are permitted provided that the following conditions 0017 * are met: 0018 * 1. Redistributions of source code must retain the above copyright 0019 * notice, this list of conditions and the following disclaimer. 0020 * 2. Redistributions in binary form must reproduce the above copyright 0021 * notice, this list of conditions and the following disclaimer in the 0022 * documentation and/or other materials provided with the distribution. 0023 * 0024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0027 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0028 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0029 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0030 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0031 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0032 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0033 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0034 * POSSIBILITY OF SUCH DAMAGE. 0035 */ 0036 0037 #ifndef BSP_CLOCK_ARMV7M_H 0038 #define BSP_CLOCK_ARMV7M_H 0039 0040 #include <rtems/score/armv7m.h> 0041 #include <rtems/timecounter.h> 0042 0043 #include <bsp.h> 0044 0045 #ifdef __cplusplus 0046 extern "C" { 0047 #endif /* __cplusplus */ 0048 0049 /** 0050 * @defgroup RTEMSDriverClockArmv7MSysTick Armv7-M SysTick Clock Driver 0051 * 0052 * @ingroup RTEMSDriverClockImpl 0053 * 0054 * @brief This group contains the Armv7-M SysTick support and Clock Driver 0055 * implementation. 0056 * 0057 * @{ 0058 */ 0059 0060 #ifdef ARM_MULTILIB_ARCH_V7M 0061 0062 typedef struct { 0063 struct timecounter base; 0064 uint32_t ticks; 0065 } ARMV7M_Timecounter; 0066 0067 extern ARMV7M_Timecounter _ARMV7M_TC; 0068 0069 static inline uint32_t _ARMV7M_Clock_frequency(void) 0070 { 0071 #ifdef BSP_ARMV7M_SYSTICK_FREQUENCY 0072 return BSP_ARMV7M_SYSTICK_FREQUENCY; 0073 #else 0074 volatile ARMV7M_Systick *systick = _ARMV7M_Systick; 0075 return ARMV7M_SYSTICK_CALIB_TENMS_GET(systick->calib) * 100; 0076 #endif 0077 } 0078 0079 static uint32_t _ARMV7M_Clock_counter(ARMV7M_Timecounter *tc) 0080 { 0081 volatile ARMV7M_Systick *systick; 0082 rtems_interrupt_level level; 0083 uint32_t interval; 0084 uint32_t counter; 0085 uint32_t ticks; 0086 uint32_t csr; 0087 0088 rtems_interrupt_disable(level); 0089 systick = _ARMV7M_Systick; 0090 counter = systick->cvr; 0091 csr = systick->csr; 0092 interval = systick->rvr; 0093 ticks = tc->ticks; 0094 0095 if (RTEMS_PREDICT_FALSE((csr & ARMV7M_SYSTICK_CSR_COUNTFLAG) != 0)) { 0096 counter = systick->cvr; 0097 ticks += interval; 0098 tc->ticks = ticks; 0099 } 0100 0101 counter = interval - counter + ticks; 0102 rtems_interrupt_enable(level); 0103 0104 return counter; 0105 } 0106 0107 #endif /* ARM_MULTILIB_ARCH_V7M */ 0108 0109 /** @} */ 0110 0111 #ifdef __cplusplus 0112 } 0113 #endif /* __cplusplus */ 0114 0115 #endif /* BSP_CLOCK_ARMV7M_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |