source: rtems/c/src/lib/libcpu/powerpc/mpc55xx/emios/emios.c @ d374492

4.104.115
Last change on this file since d374492 was d374492, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 07/21/09 at 08:38:04

Update for MPC55XX changes

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup mpc55xx
5 *
6 * @brief Enhanced Modular Input Output Subsystem (eMIOS).
7 */
8
9/*
10 * Copyright (c) 2009
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
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#include <mpc55xx/regs.h>
23#include <mpc55xx/emios.h>
24#include <mpc55xx/mpc55xx.h>
25
26#include <bsp/irq.h>
27#include <bsp/utility.h>
28
29#define RTEMS_STATUS_CHECKS_USE_PRINTK
30
31#include <rtems/status-checks.h>
32
33/**
34 * @brief Initialize the eMIOS module.
35 *
36 * The module is enabled.  It is configured to use the internal clock.  The
37 * global prescaler value is set to @a prescaler.  If the value is greater than
38 * the maximum the maxium value will be used instead.  A prescaler value of
39 * zero disables the clock.
40 *
41 * @note No protection against concurrent execution.
42 */
43void mpc55xx_emios_initialize( unsigned prescaler)
44{
45  union EMIOS_MCR_tag mcr = MPC55XX_ZERO_FLAGS;
46
47  /* Enable module */
48  mcr.B.MDIS = 0;
49
50  /* Disable debug mode */
51  mcr.B.FRZ = 1;
52
53  /* Enable global time base */
54  mcr.B.GTBE = 1;
55
56  /* Disable global prescaler (= disable clock) */
57  mcr.B.GPREN = 0;
58
59  /* Set MCR */
60  EMIOS.MCR.R = mcr.R;
61
62  /* Set OUDR */
63  EMIOS.OUDR.R = 0;
64
65  /* Set global prescaler value */
66  mpc55xx_emios_set_global_prescaler( prescaler);
67}
68
69/**
70 * @brief Returns the global prescaler value of the eMIOS module.
71 */
72unsigned mpc55xx_emios_global_prescaler( void)
73{
74  union EMIOS_MCR_tag mcr = EMIOS.MCR;
75
76  if (mcr.B.GPREN != 0) {
77    return mcr.B.GPRE + 1;
78  } else {
79    return 0;
80  }
81}
82
83/**
84 * @brief Sets the global prescaler value of the eMIOS module.
85 *
86 * The global prescaler value is set to @a prescaler.  If the value is greater
87 * than the maximum the maxium value will be used instead.  A prescaler value
88 * of zero disables the clock.
89 *
90 * @note No protection against concurrent execution.
91 */
92void mpc55xx_emios_set_global_prescaler( unsigned prescaler)
93{
94  union EMIOS_MCR_tag mcr = EMIOS.MCR;
95
96  /* Enable or disable the global prescaler */
97  mcr.B.GPREN = prescaler > 0 ? 1 : 0;
98
99  /* Set global prescaler value */
100  if (prescaler > 256) {
101    prescaler = 256;
102  } else if (prescaler < 1) {
103    prescaler = 1;
104  }
105  mcr.B.GPRE = prescaler - 1;
106
107  /* Set MCR */
108  EMIOS.MCR.R = mcr.R;
109}
Note: See TracBrowser for help on using the repository browser.