aboutsummaryrefslogtreecommitdiff
path: root/src/systick.c
blob: 506f6df1d7f9691fdb4485188c1ff3a87117a0f4 (plain) (blame)
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
#include "systick.h"

#include <stdio.h>

#include "ch573/systick.h"
#include "isr_vector.h"

#define SYSTICK_I CH573_SYSTICK__SYSTICK_T_INTF
#define SYSTICK ch573_systick__systick

void set_systick(uint64_t systick)
{
  SYSTICK_I.reload.set(SYSTICK, systick);
  SYSTICK_I.cfg.st_reload.set(SYSTICK, 1);
  SYSTICK_I.cfg.interrupt_enable.set(SYSTICK, 1);

  SYSTICK_I.cfg.enabled.set(SYSTICK, ENABLED);
}

uint64_t get_systick()
{
  return ((uint64_t)SYSTICK_I.count_high.get(SYSTICK) << 32) |
         SYSTICK_I.count_low.get(SYSTICK);
}

int systick_interrupt()
{
  return SYSTICK_I.counter_interrupt_flag.get(SYSTICK);
}

IRQ(systick)
{
  SYSTICK_I.counter_interrupt_flag.set(SYSTICK, 0);
}