File indexing completed on 2025-05-11 08:23:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include <rtems.h>
0037 #include <rtems/timecounter.h>
0038
0039 #include <bsp/lpc-clock-config.h>
0040 #include <bsp/lpc-timer.h>
0041
0042 #ifdef ARM_MULTILIB_ARCH_V4
0043
0044 static volatile lpc_timer *const lpc_clock =
0045 (volatile lpc_timer *) LPC_CLOCK_TIMER_BASE;
0046
0047 static volatile lpc_timer *const lpc_timecounter =
0048 (volatile lpc_timer *) LPC_CLOCK_TIMECOUNTER_BASE;
0049
0050 static struct timecounter lpc_clock_tc;
0051
0052 static uint32_t lpc_clock_tc_get_timecount(struct timecounter *tc)
0053 {
0054 return lpc_timecounter->tc;
0055 }
0056
0057 static void lpc_clock_at_tick(volatile lpc_timer *regs)
0058 {
0059 regs->ir = LPC_TIMER_IR_MR0;
0060 }
0061
0062 static void lpc_clock_handler_install(rtems_interrupt_handler handler)
0063 {
0064 rtems_status_code sc = RTEMS_SUCCESSFUL;
0065
0066 sc = rtems_interrupt_handler_install(
0067 LPC_CLOCK_INTERRUPT,
0068 "Clock",
0069 RTEMS_INTERRUPT_UNIQUE,
0070 handler,
0071 RTEMS_DEVOLATILE(lpc_timer *, lpc_clock)
0072 );
0073 if (sc != RTEMS_SUCCESSFUL) {
0074 rtems_fatal_error_occurred(0xdeadbeef);
0075 }
0076 }
0077
0078 static void lpc_clock_initialize(void)
0079 {
0080 uint64_t interval = ((uint64_t) LPC_CLOCK_REFERENCE
0081 * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000;
0082
0083
0084 LPC_CLOCK_MODULE_ENABLE();
0085
0086
0087 lpc_clock->tcr = LPC_TIMER_TCR_RST;
0088
0089
0090 lpc_clock->ir = LPC_TIMER_IR_ALL;
0091
0092
0093 lpc_clock->ccr = 0;
0094
0095
0096 lpc_clock->pr = 0;
0097
0098
0099 lpc_clock->mr0 = (uint32_t) interval;
0100
0101
0102 lpc_clock->mcr = LPC_TIMER_MCR_MR0_INTR | LPC_TIMER_MCR_MR0_RST;
0103
0104
0105 lpc_clock->emr = 0x0;
0106
0107
0108 lpc_clock->tcr = LPC_TIMER_TCR_EN;
0109
0110
0111 lpc_clock_tc.tc_get_timecount = lpc_clock_tc_get_timecount;
0112 lpc_clock_tc.tc_counter_mask = 0xffffffff;
0113 lpc_clock_tc.tc_frequency = LPC_CLOCK_REFERENCE;
0114 lpc_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
0115 rtems_timecounter_install(&lpc_clock_tc);
0116 }
0117
0118 #define Clock_driver_support_at_tick(arg) lpc_clock_at_tick(arg)
0119 #define Clock_driver_support_initialize_hardware() lpc_clock_initialize()
0120 #define Clock_driver_support_install_isr(isr) \
0121 lpc_clock_handler_install(isr)
0122
0123
0124 #include "../../../shared/dev/clock/clockimpl.h"
0125
0126 #endif