aboutsummaryrefslogtreecommitdiff
path: root/src/kern/main.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2020-12-09 20:29:31 -0700
committerJosh Rahm <joshuarahm@gmail.com>2020-12-09 20:29:31 -0700
commita5923b21e48fcfe660c1e7d586fe0c6a5b79e421 (patch)
tree8477e2e5088847b5c5e93257681ee19d43394bbd /src/kern/main.c
parent1710871aa1958c2cac38e4b372964ef22032ed4a (diff)
downloadstm32l4-a5923b21e48fcfe660c1e7d586fe0c6a5b79e421.tar.gz
stm32l4-a5923b21e48fcfe660c1e7d586fe0c6a5b79e421.tar.bz2
stm32l4-a5923b21e48fcfe660c1e7d586fe0c6a5b79e421.zip
Got a basic timer to work.
Diffstat (limited to 'src/kern/main.c')
-rw-r--r--src/kern/main.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/kern/main.c b/src/kern/main.c
index 2b97197..082d450 100644
--- a/src/kern/main.c
+++ b/src/kern/main.c
@@ -2,6 +2,7 @@
#include "arch/arm/cortex-m4/mpu.h"
#include "arch/stm32l4xxx/peripherals/clock.h"
#include "arch/stm32l4xxx/peripherals/dma.h"
+#include "arch/stm32l4xxx/peripherals/tim.h"
#include "arch/stm32l4xxx/peripherals/exti.h"
#include "arch/stm32l4xxx/peripherals/irq.h"
#include "arch/stm32l4xxx/peripherals/rcc.h"
@@ -23,6 +24,15 @@
#include "kern/systick/systick_manager.h"
#include "user/syscall.h"
+void on_exti9_5()
+{
+ klogf("Exit Interrupt!\n");
+ klogf("Pending Reg_again: %p\n", EXTI.p_r1);
+ klogf("Write: %p\n", (1 << 6));
+ EXTI.p_r1 |= 1 << 6;
+ klogf("Pending Reg_again: %p\n", EXTI.p_r1);
+}
+
void on_hard_fault()
{
panic("Hard fault encountered!\n");
@@ -81,6 +91,15 @@ static uint32_t bytescale(uint32_t n, uint32_t sc)
return n * sc / 255;
}
+void on_tim2()
+{
+ if (regget(TIM2.s_r, tim_uif)) {
+ regset(TIM2.s_r, tim_uif, 0);
+ }
+
+ klogf("Tim2 Update\n");
+}
+
/* Main function. This gets executed from the interrupt vector defined above. */
int main()
{
@@ -88,6 +107,21 @@ int main()
klogf("Entering main\n");
+ klogf("Enable ir\n");
+ enable_interrupt(IRQ_TIM2);
+ klogf("Enable clock\n");
+ regset(RCC.apb1en1_r, rcc_tim2en, 1);
+ klogf("psc\n");
+ TIM2.psc = 39999; /* Counts every half millisecond. */
+ klogf("ar_r\n");
+ TIM2.ar_r = 1000;
+ klogf("die_r\n");
+ regset(TIM2.die_r, tim_uie, 1);
+ klogf("eg_r\n");
+ regset(TIM2.eg_r, tim_ug, 1);
+ klogf("c_r1\n");
+ regset(TIM2.c_r1, tim_cen, 1);
+
int ec;
gpio_reserved_pin_t sysled = get_sysled();