From 1096075d9b2d10302abd42cfdeef155f145f64e1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 31 Jan 2019 22:58:01 -0500 Subject: [PATCH] lpc176x: Convert code to use armcm_timer Signed-off-by: Kevin O'Connor --- src/lpc176x/Kconfig | 4 +-- src/lpc176x/Makefile | 4 +-- src/lpc176x/internal.h | 2 ++ src/lpc176x/timer.c | 63 ------------------------------------------ 4 files changed, 6 insertions(+), 67 deletions(-) delete mode 100644 src/lpc176x/timer.c diff --git a/src/lpc176x/Kconfig b/src/lpc176x/Kconfig index 82fb200a4..9bd5c6d2c 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 0abbc8f43..406a6d976 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 bd3e9c01d..5dcf99a46 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 69add9c36..000000000 --- a/src/lpc176x/timer.c +++ /dev/null @@ -1,63 +0,0 @@ -// lpc176x timer interrupt scheduling -// -// Copyright (C) 2018 Kevin O'Connor -// -// 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(); -}