lpc176x: Convert code to use armcm_timer

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-01-31 22:58:01 -05:00
parent 77db1aa379
commit 1096075d9b
4 changed files with 6 additions and 67 deletions

View File

@ -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"

View File

@ -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

View File

@ -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))

View File

@ -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();
}