Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:47

0001 /*
0002  * Use the last periodic interval timer (PIT2) as the system clock.
0003  */
0004 
0005 #include <rtems.h>
0006 #include <rtems/timecounter.h>
0007 #include <bsp.h>
0008 
0009 /*
0010  * Use INTC0 base
0011  */
0012 #define CLOCK_VECTOR (64+56)
0013 
0014 static rtems_timecounter_simple mcf52235_tc;
0015 
0016 static uint32_t mcf52235_tc_get(rtems_timecounter_simple *tc)
0017 {
0018   return MCF_PIT1_PCNTR;
0019 }
0020 
0021 static bool mcf52235_tc_is_pending(rtems_timecounter_simple *tc)
0022 {
0023   return (MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF) != 0;
0024 }
0025 
0026 static uint32_t mcf52235_tc_get_timecount(struct timecounter *tc)
0027 {
0028   return rtems_timecounter_simple_downcounter_get(
0029     tc,
0030     mcf52235_tc_get,
0031     mcf52235_tc_is_pending
0032   );
0033 }
0034 
0035 static void mcf52235_tc_at_tick(rtems_timecounter_simple *tc)
0036 {
0037   MCF_PIT1_PCSR |= MCF_PIT_PCSR_PIF;
0038 }
0039 
0040 static void mcf52235_tc_tick(void)
0041 {
0042   rtems_timecounter_simple_downcounter_tick(
0043     &mcf52235_tc,
0044     mcf52235_tc_get,
0045     mcf52235_tc_at_tick
0046   );
0047 }
0048 
0049 /*
0050  * Attach clock interrupt handler
0051  */
0052 #define Clock_driver_support_install_isr( _new ) \
0053   set_vector(_new, CLOCK_VECTOR, 1)
0054 
0055 /*
0056  * Set up the clock hardware
0057  *
0058  * We need to have 1 interrupt every rtems_configuration_get_microseconds_per_tick()
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_CPU_clock_speed() >> 1;
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 
0075   MCF_INTC0_ICR56 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL) |
0076     MCF_INTC_ICR_IP(PIT3_IRQ_PRIORITY);
0077   rtems_interrupt_disable(level);
0078   MCF_INTC0_IMRH &= ~MCF_INTC_IMRH_MASK56;
0079   MCF_PIT1_PCSR &= ~MCF_PIT_PCSR_EN;
0080   rtems_interrupt_enable(level);
0081 
0082   MCF_PIT1_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
0083     MCF_PIT_PCSR_OVW | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD;
0084   MCF_PIT1_PMR = pmr;
0085   MCF_PIT1_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
0086     MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN;
0087 
0088   rtems_timecounter_simple_install(
0089     &mcf52235_tc,
0090     clk >> preScaleCode,
0091     pmr,
0092     mcf52235_tc_get_timecount
0093   );
0094 }
0095 
0096 #define Clock_driver_timecounter_tick(arg) mcf52235_tc_tick()
0097 
0098 #include "../../../shared/dev/clock/clockimpl.h"