-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathclock_ev3.c
More file actions
122 lines (94 loc) · 3.18 KB
/
clock_ev3.c
File metadata and controls
122 lines (94 loc) · 3.18 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-License-Identifier: MPL-1.0
// Copyright (c) 2016 Tobias Schießl
// SPDX-License-Identifier: MIT
// Copyright (c) 2024 The Pybricks Authors
#include <pbdrv/config.h>
#if PBDRV_CONFIG_CLOCK_TIAM1808
#include <stdint.h>
#include <contiki.h>
#include <pbio/os.h>
#include <tiam1808/armv5/am1808/interrupt.h>
#include <tiam1808/armv5/cpu.h>
#include <tiam1808/hw/hw_syscfg0_AM1808.h>
#include <tiam1808/hw/soc_AM1808.h>
#include <tiam1808/timer.h>
/**
* The compare value to set for the 16 least significant bits of the hardware timer
*
* This is the value which causes the interrupt to be triggered every millisecond.
*/
#define TMR_PERIOD_LSB32 0x05CC
/*
* The compare value to set for the 16 most significant bits of the hardware timer
*/
#define TMR_PERIOD_MSB32 0x0
/**
* The current tick in milliseconds
*/
volatile uint32_t systick_ms = 0;
/**
* The systick interrupt service routine (ISR) which will be called every millisecond.
*/
void systick_isr_C(void) {
/* Disable the timer interrupt */
TimerIntDisable(SOC_TMR_0_REGS, TMR_INT_TMR34_NON_CAPT_MODE);
/* Clear the interrupt status in AINTC and in timer */
IntSystemStatusClear(SYS_INT_TINT34_0);
TimerIntStatusClear(SOC_TMR_0_REGS, TMR_INT_TMR34_NON_CAPT_MODE);
++systick_ms;
etimer_request_poll();
pbio_os_request_poll();
/* Enable the timer interrupt */
TimerIntEnable(SOC_TMR_0_REGS, TMR_INT_TMR34_NON_CAPT_MODE);
}
/**
* Disable the timer and therefore the systick
*
*/
void systick_suspend(void) {
/* Disable the timer interrupt */
TimerDisable(SOC_TMR_0_REGS, TMR_TIMER34);
}
/**
* Enable the timer and therefore the systick
*/
void systick_resume(void) {
/* Enable the timer interrupt */
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONTRELOAD);
}
/**
* Initialize the systick module, i.e. the hardware timer of the SoC
*
* This function will register the corresponding ISR, enable the timer
* interrupt and configure interrupt channel 2 (normal interrupt) for the
* hardware timer.
*/
void pbdrv_clock_init(void) {
/* Set up the ARM Interrupt Controller for generating timer interrupt */
/* Set up the timer */
TimerConfigure(SOC_TMR_0_REGS, TMR_CFG_32BIT_UNCH_CLK_BOTH_INT);
TimerPeriodSet(SOC_TMR_0_REGS, TMR_TIMER34, TMR_PERIOD_LSB32);
TimerReloadSet(SOC_TMR_0_REGS, TMR_TIMER34, TMR_PERIOD_LSB32);
/* Register the Timer ISR */
IntRegister(SYS_INT_TINT34_0, systick_isr_C);
/* Set the channel number for Timer interrupt, it will map to IRQ */
IntChannelSet(SYS_INT_TINT34_0, 3);
/* Enable timer interrupts in AINTC */
IntSystemEnable(SYS_INT_TINT34_0);
/* Enable the timer interrupt */
TimerIntEnable(SOC_TMR_0_REGS, TMR_INT_TMR34_NON_CAPT_MODE);
/* Start the timer */
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONTRELOAD);
}
uint32_t pbdrv_clock_get_us(void) {
// TODO: TIAM1808 implementation.
return 0;
}
uint32_t pbdrv_clock_get_ms(void) {
return systick_ms;
}
uint32_t pbdrv_clock_get_100us(void) {
// REVISIT: Use actual time since this isn't providing better resolution.
return pbdrv_clock_get_ms() * 10;
}
#endif // PBDRV_CONFIG_CLOCK_TIAM1808