blob: afd64601a877892463ef84d20ffaf5d5e9e6d0d4 [file] [log] [blame]
Dovhal Artem (CSUKR CSS ICW SW FW 1)f7a3d1b2022-04-01 15:07:37 +00001/* Copyright 2022, Infineon Technologies AG. All rights reserved.
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 */
20
21#ifndef TIMESTAMP_H
22#define TIMESTAMP_H
23
24#include "cy_pdl.h"
25
26#define TIMESTAMP_SOURCE CY_SYSTICK_CLOCK_SOURCE_CLK_LF
27#define TIMESTAMP_DIVIDER (CY_SYSCLK_ILO_FREQ / 1000UL)
28
29/*******************************************************************************
30* Function Name: log_timestamp_get
31****************************************************************************//**
32*
33* \brief Get current timestamp counter value.
34*
35* \return Systic counter as timestamp reference.
36*/
37static inline uint32_t log_timestamp_get(void) {
38 return ((0x1000000UL - Cy_SysTick_GetValue()) / TIMESTAMP_DIVIDER);
39}
40
41/*******************************************************************************
42* Function Name: log_timestamp_reset
43****************************************************************************//**
44*
45* \brief Reset timestamp counter.
46*/
47static inline void log_timestamp_reset(void) {
48 Cy_SysTick_Init(TIMESTAMP_SOURCE, 0xFFFFFFu);
49 Cy_SysTick_DisableInterrupt();
50}
51
52/*******************************************************************************
53* Function Name: log_timestamp_init
54****************************************************************************//**
55*
56* \brief Initializate timestamp counter and SysTick timebase.
57*/
58static inline void log_timestamp_init(void) {
59 log_timestamp_reset();
60 Cy_SysTick_Clear();
61}
62
63/*******************************************************************************
64* Function Name: log_timestamp_deinit
65****************************************************************************//**
66*
67* \brief Deinitializate timestamp counter and SysTick timebase.
68*/
69static inline void log_timestamp_deinit(void) {
70 Cy_SysTick_Disable();
71 Cy_SysTick_Clear();
72}
73
74#endif /* TIMESTAMP_H */