source: rtems/c/src/lib/libbsp/m68k/mcf5329/clock/clock.c @ 76ac1ee3

5
Last change on this file since 76ac1ee3 was 76ac1ee3, checked in by Sebastian Huber <sebastian.huber@…>, on 12/23/15 at 06:29:47

score: Fix simple timecounter support

Update #2502.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * Use the last periodic interval timer (PIT2) as the system clock.
3 */
4
5#include <rtems.h>
6#include <rtems/timecounter.h>
7#include <bsp.h>
8
9/*
10 * Use INTC1 base
11 */
12#define CLOCK_VECTOR (128+46)
13
14static rtems_timecounter_simple mcf5329_tc;
15
16static uint32_t mcf5329_tc_get(rtems_timecounter_simple *tc)
17{
18  return MCF_PIT3_PCNTR;
19}
20
21static bool mcf5329_tc_is_pending(rtems_timecounter_simple *tc)
22{
23  return (MCF_PIT3_PCSR & MCF_PIT_PCSR_PIF) != 0;
24}
25
26static uint32_t mcf5329_tc_get_timecount(struct timecounter *tc)
27{
28  return rtems_timecounter_simple_downcounter_get(
29    tc,
30    mcf5329_tc_get,
31    mcf5329_tc_is_pending
32  );
33}
34
35static void mcf5329_tc_at_tick(rtems_timecounter_simple *tc)
36{
37  MCF_PIT3_PCSR |= MCF_PIT_PCSR_PIF;
38}
39
40static void mcf5329_tc_tick(void)
41{
42  rtems_timecounter_simple_downcounter_tick(
43    &mcf5329_tc,
44    mcf5329_tc_get,
45    mcf5329_tc_at_tick
46  );
47}
48
49/*
50 * Attach clock interrupt handler
51 */
52#define Clock_driver_support_install_isr( _new, _old )             \
53    do {                                                           \
54        _old = (rtems_isr_entry)set_vector(_new, CLOCK_VECTOR, 1); \
55    } while(0)
56
57/*
58 * Turn off the clock
59 */
60static void Clock_driver_support_shutdown_hardware(void)
61{
62  MCF_PIT3_PCSR &= ~MCF_PIT_PCSR_EN;
63}
64
65/*
66 * Set up the clock hardware
67 *
68 * We need to have 1 interrupt every rtems_configuration_get_microseconds_per_tick()
69 */
70static void Clock_driver_support_initialize_hardware(void)
71{
72  int level;
73  uint32_t pmr;
74  uint32_t preScaleCode = 0;
75  uint32_t clk = bsp_get_BUS_clock_speed();
76  uint32_t tps = 1000000 / rtems_configuration_get_microseconds_per_tick();
77
78  while (preScaleCode < 15) {
79    pmr = (clk >> preScaleCode) / tps;
80    if (pmr < (1 << 15))
81      break;
82    preScaleCode++;
83  }
84  MCF_INTC1_ICR46 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL);
85
86  rtems_interrupt_disable(level);
87  MCF_INTC1_IMRH &= ~MCF_INTC_IMRH_INT_MASK46;
88  MCF_PIT3_PCSR &= ~MCF_PIT_PCSR_EN;
89  rtems_interrupt_enable(level);
90
91  MCF_PIT3_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
92    MCF_PIT_PCSR_OVW | MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD;
93  MCF_PIT3_PMR = pmr;
94  MCF_PIT3_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) |
95    MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN;
96
97  rtems_timecounter_simple_install(
98    &mcf5329_tc,
99    clk >> preScaleCode,
100    pmr,
101    mcf5329_tc_get_timecount
102  );
103}
104
105#define Clock_driver_timecounter_tick() mcf5329_tc_tick()
106
107#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.