summaryrefslogtreecommitdiff
path: root/bsp/tms320c6678/driver/drv_timer.c
blob: 56cc266645ae3afcb62e207184beb07f300ea40b (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright (c) 2021, Shenzhen Academy of Aerospace Technology
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-11-16     Dystopia     the first version
 */

#include "drv_timer.h"
#include "interrupt.h"
#include "common.h"

#include <rthw.h>
#include <rtthread.h>

/**
 * This is the timer interrupt service routine.
 *
 */
void rt_hw_systick_isr(void)
{
    /* enter interrupt */
    rt_interrupt_enter();

    rt_tick_increase();

    /* leave interrupt */
    rt_interrupt_leave();
}

/**
 * The function initial system timer interrupt.
 */
void rt_hw_system_timer_init(void)
{
    // initial system timer interrupt, map local timer interrupt to INT14
    gp_cgem_regs->INTMUX3 = (CSL_GEM_TINTLN << CSL_CGEM_INTMUX3_INTSEL14_SHIFT);
    // enable CPU INT14
    rt_hw_interrupt_umask(1 << 14);

    return ;
}

/**
 * The function initial system timer.
 * Use local timer (== DNUM of a core) to generate a clock on TIMO0,interrupts are generated as well
 *
 */
void rt_hw_system_timer_start(void)
{
    Timer64_Config tmrCfg;

    // select output on TIMO0 from local timer.
    gp_bootcfg_regs->TOUTSEL = (DNUM*2) << CSL_BOOTCFG_TOUTSEL_TOUTSEL0_SHIFT;

    // configure the timer to generate clocks and interrupts
    tmrCfg.timer_num = DNUM;
    tmrCfg.timerMode = TIMER_PERIODIC_CLOCK;
    tmrCfg.period = (unsigned long long) RT_TICK_PER_SECOND * DSP_CORE_SPEED_HZ / 6000;
    tmrCfg.reload_period = 0;

    // initial timer
    timer64_init(&tmrCfg);
}