embox

Форк
0
/
cmsis_systick.c 
66 строк · 1.4 Кб
1
/**
2
 * @file
3
 * @brief Core clocking device in Cortex ARM-M
4
 *
5
 * @date 25.03.2014
6
 * @author Anton Kozlov
7
 */
8

9

10
#include <errno.h>
11
#include <hal/clock.h>
12
#include <hal/system.h>
13
#include <arm/exception.h>
14
#include <kernel/irq.h>
15
#include <kernel/time/clock_source.h>
16
#include <hal/reg.h>
17

18
#include <embox/unit.h>
19

20
#define CLOCK_DIVIDER 1
21

22
#define SYSTICK_IRQ 15
23

24
#include <module/embox/arch/arm/cmsis.h>
25

26
static irq_return_t cmsis_systick_clock_handler(unsigned int irq_nr, void *data) {
27
	struct clock_source *cs = data;
28

29
	clock_tick_handler(data);
30

31
	if (cs->event_device->flags & CLOCK_EVENT_ONESHOT_MODE) {
32
		/* Systick do not support one-shot mode, so we do
33
		 * it by shutting Systick down. */
34
		REG_STORE(SysTick->CTRL, 0);
35
		REG_STORE(SysTick->VAL, 0);
36
	}
37

38
	return IRQ_HANDLED;
39
}
40

41
static int cmsis_systick_set_periodic(struct clock_source *cs) {
42
	int reload = SYS_CLOCK / (CLOCK_DIVIDER * 1000);
43

44
	return 0 == SysTick_Config(reload) ? 0 : -EINVAL;
45
}
46

47
static struct time_event_device cmsis_systick_event = {
48
	.set_periodic = cmsis_systick_set_periodic,
49
	.irq_nr = SYSTICK_IRQ,
50
};
51

52
#if 0
53
static cycle_t this_read(struct clock_source *cs) {
54
	return 0;
55
}
56

57
static struct time_counter_device this_counter = {
58
	.read = this_read,
59
	.cycles_hz = SYS_CLOCK / CLOCK_DIVIDER,
60
};
61
#endif
62

63
CLOCK_SOURCE_DEF(cmsis_systick, NULL, NULL,
64
	&cmsis_systick_event, NULL);
65

66
STATIC_EXC_ATTACH(SYSTICK_IRQ, cmsis_systick_clock_handler,  &CLOCK_SOURCE_NAME(cmsis_systick));
67

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.