1 /* 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * Copyright 2016-2017 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 #ifndef _FSL_TSTMR_H_ 9 #define _FSL_TSTMR_H_ 10 11 #include "fsl_common.h" 12 13 /*! 14 * @addtogroup tstmr_driver 15 * @{ 16 */ 17 18 /******************************************************************************* 19 * Definitions 20 ******************************************************************************/ 21 22 /*! @name Driver version */ 23 /*@{*/ 24 #define FSL_TSTMR_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */ 25 /*@}*/ 26 27 /******************************************************************************* 28 * API 29 ******************************************************************************/ 30 31 #if defined(__cplusplus) 32 extern "C" { 33 #endif 34 35 /*! 36 * @brief Reads the time stamp. 37 * 38 * This function reads the low and high registers and returns the 56-bit free running 39 * counter value. This can be read by software at any time to determine the software ticks. 40 * 41 * @param base TSTMR peripheral base address. 42 * 43 * @return The 56-bit time stamp value. 44 */ TSTMR_ReadTimeStamp(TSTMR_Type * base)45static inline uint64_t TSTMR_ReadTimeStamp(TSTMR_Type* base) 46 { 47 return *(volatile uint64_t*)(base); 48 } 49 50 /*! 51 * @brief Delays for a specified number of microseconds. 52 * 53 * This function repeatedly reads the timestamp register and waits for the user-specified 54 * delay value. 55 * 56 * @param base TSTMR peripheral base address. 57 * @param delayInUs Delay value in microseconds. 58 */ TSTMR_DelayUs(TSTMR_Type * base,uint32_t delayInUs)59static inline void TSTMR_DelayUs(TSTMR_Type* base, uint32_t delayInUs) 60 { 61 uint64_t startTime = TSTMR_ReadTimeStamp(base); 62 #if defined(FSL_FEATURE_TSTMR_CLOCK_FREQUENCY_1MHZ) && FSL_FEATURE_TSTMR_CLOCK_FREQUENCY_1MHZ 63 while (TSTMR_ReadTimeStamp(base) - startTime < delayInUs) 64 #elif defined(FSL_FEATURE_TSTMR_CLOCK_FREQUENCY_8MHZ) && FSL_FEATURE_TSTMR_CLOCK_FREQUENCY_8MHZ 65 while (TSTMR_ReadTimeStamp(base) - startTime < 8 * delayInUs) 66 #else 67 assert(0); 68 #endif 69 { 70 } 71 } 72 73 #if defined(__cplusplus) 74 } 75 #endif 76 77 /*! @}*/ 78 79 #endif /* _FSL_TSTMR_H_ */ 80