aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-01-31 22:58:01 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-02-06 22:03:09 -0500
commit1096075d9b2d10302abd42cfdeef155f145f64e1 (patch)
treed23fa67f0a3aec0c02833edca141fe243b1eb775 /src
parent77db1aa379f7fc4ca23a0f7884f9219ca2db38d5 (diff)
downloadkutter-1096075d9b2d10302abd42cfdeef155f145f64e1.tar.gz
kutter-1096075d9b2d10302abd42cfdeef155f145f64e1.tar.xz
kutter-1096075d9b2d10302abd42cfdeef155f145f64e1.zip
lpc176x: Convert code to use armcm_timer
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/lpc176x/Kconfig4
-rw-r--r--src/lpc176x/Makefile4
-rw-r--r--src/lpc176x/internal.h2
-rw-r--r--src/lpc176x/timer.c63
4 files changed, 6 insertions, 67 deletions
diff --git a/src/lpc176x/Kconfig b/src/lpc176x/Kconfig
index 82fb200a..9bd5c6d2 100644
--- a/src/lpc176x/Kconfig
+++ b/src/lpc176x/Kconfig
@@ -25,8 +25,8 @@ endchoice
config CLOCK_FREQ
int
- default 25000000 if MACH_LPC1768 # 100000000 / 4
- default 30000000 if MACH_LPC1769 # 120000000 / 4
+ default 100000000 if MACH_LPC1768
+ default 120000000 if MACH_LPC1769
config SMOOTHIEWARE_BOOTLOADER
bool "Target board uses Smoothieware bootloader"
diff --git a/src/lpc176x/Makefile b/src/lpc176x/Makefile
index 0abbc8f4..406a6d97 100644
--- a/src/lpc176x/Makefile
+++ b/src/lpc176x/Makefile
@@ -13,12 +13,12 @@ CFLAGS_klipper.elf += -T $(OUT)LPC1768.ld
CFLAGS_klipper.elf += --specs=nano.specs --specs=nosys.specs
# Add source files
-src-y += lpc176x/main.c lpc176x/timer.c lpc176x/gpio.c
+src-y += lpc176x/main.c lpc176x/gpio.c
src-$(CONFIG_HAVE_GPIO_ADC) += lpc176x/adc.c
src-$(CONFIG_HAVE_GPIO_I2C) += lpc176x/i2c.c
src-$(CONFIG_HAVE_GPIO_SPI) += lpc176x/spi.c
src-y += generic/crc16_ccitt.c generic/alloc.c
-src-y += generic/armcm_irq.c generic/timer_irq.c
+src-y += generic/armcm_irq.c generic/armcm_timer.c
src-y += ../lib/lpc176x/device/system_LPC17xx.c
src-$(CONFIG_USBSERIAL) += lpc176x/usbserial.c generic/usb_cdc.c
src-$(CONFIG_SERIAL) += lpc176x/serial.c generic/serial_irq.c
diff --git a/src/lpc176x/internal.h b/src/lpc176x/internal.h
index bd3e9c01..5dcf99a4 100644
--- a/src/lpc176x/internal.h
+++ b/src/lpc176x/internal.h
@@ -2,6 +2,8 @@
#define __LPC176X_INTERNAL_H
// Local definitions for lpc176x code
+#include "LPC17xx.h"
+
#define GPIO(PORT, NUM) ((PORT) * 32 + (NUM))
#define GPIO2PORT(PIN) ((PIN) / 32)
#define GPIO2BIT(PIN) (1<<((PIN) % 32))
diff --git a/src/lpc176x/timer.c b/src/lpc176x/timer.c
deleted file mode 100644
index 69add9c3..00000000
--- a/src/lpc176x/timer.c
+++ /dev/null
@@ -1,63 +0,0 @@
-// lpc176x timer interrupt scheduling
-//
-// Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
-//
-// This file may be distributed under the terms of the GNU GPLv3 license.
-
-#include "LPC17xx.h" // LPC_TIM0
-#include "board/irq.h" // irq_disable
-#include "board/misc.h" // timer_read_time
-#include "board/timer_irq.h" // timer_dispatch_many
-#include "internal.h" // enable_pclock
-#include "sched.h" // DECL_INIT
-
-// Set the next irq time
-static void
-timer_set(uint32_t value)
-{
- LPC_TIM0->MR0 = value;
- LPC_TIM0->IR = 0x01;
-}
-
-// Return the current time (in absolute clock ticks).
-uint32_t
-timer_read_time(void)
-{
- return LPC_TIM0->TC;
-}
-
-// Activate timer dispatch as soon as possible
-void
-timer_kick(void)
-{
- timer_set(timer_read_time() + 50);
-}
-
-void
-timer_init(void)
-{
- // Disable timer
- LPC_TIM0->TCR = 0x02;
- // Setup clock and prescaler (divide sys clock by 4)
- enable_pclock(PCLK_TIMER0);
- LPC_TIM0->PR = 3;
- // Enable interrupts
- NVIC_SetPriority(TIMER0_IRQn, 2);
- NVIC_EnableIRQ(TIMER0_IRQn);
- LPC_TIM0->MCR = 0x01;
- // Clear counter value
- LPC_TIM0->TC = 0;
- timer_kick();
- // Start timer
- LPC_TIM0->TCR = 0x01;
-}
-DECL_INIT(timer_init);
-
-void __visible __aligned(16) // aligning helps stabilize perf benchmarks
-TIMER0_IRQHandler(void)
-{
- irq_disable();
- uint32_t next = timer_dispatch_many();
- timer_set(next);
- irq_enable();
-}