~aleteoryx/muditaos

ref: 660c2211e21f7581fec7b803233436c98e620836 muditaos/module-bsp/board/rt1051/os/fsl_runtimestat_gpt.c -rw-r--r-- 1.3 KiB
660c2211 — Marcin Zieliński [MOS-23] Back button works as save button in Notes 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "fsl_gpt.h"

static inline GPT_Type *vPortGetGptBase(void)
{
    return GPT1;
}

void vConfigureTimerForRunTimeStats(void)
{
    const gpt_config_t GPT1_config = {.clockSource = kGPT_ClockSource_Periph,
                                      // freq = (f_Osc / divider) -> (24 MHz / 2400) = 10 kHz
                                      .divider         = 2400UL,
                                      .enableFreeRun   = false,
                                      .enableRunInWait = true,
                                      .enableRunInStop = true,
                                      .enableRunInDoze = false,
                                      .enableRunInDbg  = false,
                                      .enableMode      = true};

    GPT_Type *pxGptBase = vPortGetGptBase();

    /* GPT device and channels initialization */
    GPT_Init(pxGptBase, &GPT1_config);
    GPT_SetOscClockDivider(pxGptBase, 1);
    /* Enable GPT interrupt sources */
    GPT_EnableInterrupts(pxGptBase, 0);
    /* Start the GPT timer */
    GPT_StartTimer(pxGptBase);
}

uint32_t ulHighFrequencyTimerTicks(void)
{
    return GPT_GetCurrentTimerCount(vPortGetGptBase());
}