File indexing completed on 2025-05-11 08:23:47
0001
0002
0003
0004
0005 #include <rtems.h>
0006 #include <rtems/timecounter.h>
0007 #include <bsp.h>
0008
0009
0010
0011
0012 #define CLOCK_VECTOR (128+46)
0013
0014 static rtems_timecounter_simple mcf5329_tc;
0015
0016 static uint32_t mcf5329_tc_get(rtems_timecounter_simple *tc)
0017 {
0018 return MCF_PIT3_PCNTR;
0019 }
0020
0021 static bool mcf5329_tc_is_pending(rtems_timecounter_simple *tc)
0022 {
0023 return (MCF_PIT3_PCSR & MCF_PIT_PCSR_PIF) != 0;
0024 }
0025
0026 static uint32_t mcf5329_tc_get_timecount(struct timecounter *tc)
0027 {
0028 return rtems_timecounter_simple_downcounter_get(
0029 tc,
0030 mcf5329_tc_get,
0031 mcf5329_tc_is_pending
0032 );
0033 }
0034
0035 static void mcf5329_tc_at_tick(rtems_timecounter_simple *tc)
0036 {
0037 MCF_PIT3_PCSR |= MCF_PIT_PCSR_PIF;
0038 }
0039
0040 static void mcf5329_tc_tick(void)
0041 {
0042 rtems_timecounter_simple_downcounter_tick(
0043 &mcf5329_tc,
0044 mcf5329_tc_get,
0045 mcf5329_tc_at_tick
0046 );
0047 }
0048
0049
0050
0051
0052 #define Clock_driver_support_install_isr( _new ) \
0053 set_vector(_new, CLOCK_VECTOR, 1)
0054
0055
0056
0057
0058
0059
0060 static void Clock_driver_support_initialize_hardware(void)
0061 {
0062 int level;
0063 uint32_t pmr;
0064 uint32_t preScaleCode = 0;
0065 uint32_t clk = bsp_get_BUS_clock_speed();
0066 uint32_t tps = 1000000 / rtems_configuration_get_microseconds_per_tick();
0067
0068 while (preScaleCode < 15) {
0069 pmr = (clk >> preScaleCode) / tps;
0070 if (pmr < (1 << 15))
0071 break;
0072 preScaleCode++;
0073 }
0074 MCF_INTC1_ICR46 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL);
0075
0076 rtems_interrupt_disable(level);
0077 MCF_INTC1_IMRH &= ~MCF_INTC_IMRH_INT_MASK46;
0078 MCF_PIT3_PCSR &= ~MCF_PIT_PCSR_EN;
0079 rtems_interrupt_enable(level);
0080
0081 MCF_PIT3_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
0082 MCF_PIT_PCSR_OVW | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD;
0083 MCF_PIT3_PMR = pmr;
0084 MCF_PIT3_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
0085 MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN;
0086
0087 rtems_timecounter_simple_install(
0088 &mcf5329_tc,
0089 clk >> preScaleCode,
0090 pmr,
0091 mcf5329_tc_get_timecount
0092 );
0093 }
0094
0095 #define Clock_driver_timecounter_tick(arg) mcf5329_tc_tick()
0096
0097 #include "../../../shared/dev/clock/clockimpl.h"