source: rtems/c/src/lib/libbsp/arm/lpc24xx/misc/system-clocks.c @ ba938b8

4.104.115
Last change on this file since ba938b8 was ba938b8, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on Sep 18, 2009 at 8:05:40 AM

Changes throughout.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc24xx_clocks
5 *
6 * @brief System clocks.
7 */
8
9/*
10 * Copyright (c) 2008
11 * Embedded Brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * rtems@embedded-brains.de
16 *
17 * The license and distribution terms for this file may be found in the file
18 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
19 */
20
21#include <bsp.h>
22#include <bsp/utility.h>
23#include <bsp/lpc24xx.h>
24#include <bsp/system-clocks.h>
25
26/**
27 * @brief Internal RC oscillator frequency in [Hz].
28 */
29#define LPC24XX_OSCILLATOR_INTERNAL 4000000U
30
31#ifndef LPC24XX_OSCILLATOR_MAIN
32  #error "unknown main oscillator frequency"
33#endif
34
35#ifndef LPC24XX_OSCILLATOR_RTC
36  #error "unknown RTC oscillator frequency"
37#endif
38
39void lpc24xx_timer_initialize(void)
40{
41  /* Reset timer */
42  T1TCR = TCR_RST;
43
44  /* Set timer mode */
45  T1CTCR = 0;
46
47  /* Set prescaler to zero */
48  T1PR = 0;
49
50  /* Reset all interrupt flags */
51  T1IR = 0xff;
52
53  /* Do not stop on a match */
54  T1MCR = 0;
55
56  /* No captures */
57  T1CCR = 0;
58
59  /* Start timer */
60  T1TCR = TCR_EN;
61}
62
63void lpc24xx_micro_seconds_delay(unsigned us)
64{
65  unsigned start = lpc24xx_timer();
66  unsigned end = start + us * (lpc24xx_cclk() / 1000000);
67  unsigned now = 0;
68
69  do {
70    now = lpc24xx_timer();
71  } while (now < end);
72}
73
74unsigned lpc24xx_pllclk(void)
75{
76  unsigned clksrc = GET_CLKSRCSEL_CLKSRC(CLKSRCSEL);
77  unsigned pllinclk = 0;
78  unsigned pllclk = 0;
79
80  /* Get PLL input frequency */
81  switch (clksrc) {
82    case 0:
83      pllinclk = LPC24XX_OSCILLATOR_INTERNAL;
84      break;
85    case 1:
86      pllinclk = LPC24XX_OSCILLATOR_MAIN;
87      break;
88    case 2:
89      pllinclk = LPC24XX_OSCILLATOR_RTC;
90      break;
91    default:
92      return 0;
93  }
94
95  /* Get PLL output frequency */
96  if (IS_FLAG_SET(PLLSTAT, PLLSTAT_PLLC)) {
97    uint32_t pllcfg = PLLCFG;
98    unsigned n = GET_PLLCFG_NSEL(pllcfg) + 1;
99    unsigned m = GET_PLLCFG_MSEL(pllcfg) + 1;
100
101    pllclk = (pllinclk / n) * 2 * m;
102  } else {
103    pllclk = pllinclk;
104  }
105
106  return pllclk;
107}
108
109unsigned lpc24xx_cclk(void)
110{
111  /* Get PLL output frequency */
112  unsigned pllclk = lpc24xx_pllclk();
113
114  /* Get CPU frequency */
115  unsigned cclk = pllclk / (GET_CCLKCFG_CCLKSEL(CCLKCFG) + 1);
116
117  return cclk;
118}
Note: See TracBrowser for help on using the repository browser.