[d374492] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @ingroup mpc55xx |
---|
| 5 | * |
---|
| 6 | * @brief Enhanced Modular Input Output Subsystem (eMIOS). |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
[a762dc2] | 10 | * Copyright (c) 2009-2011 embedded brains GmbH. All rights reserved. |
---|
| 11 | * |
---|
| 12 | * embedded brains GmbH |
---|
| 13 | * Obere Lagerstr. 30 |
---|
| 14 | * 82178 Puchheim |
---|
| 15 | * Germany |
---|
| 16 | * <rtems@embedded-brains.de> |
---|
[d374492] | 17 | * |
---|
| 18 | * The license and distribution terms for this file may be |
---|
| 19 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 20 | * http://www.rtems.org/license/LICENSE. |
---|
[d374492] | 21 | */ |
---|
| 22 | |
---|
| 23 | #include <mpc55xx/emios.h> |
---|
| 24 | |
---|
[a762dc2] | 25 | #ifdef MPC55XX_HAS_EMIOS |
---|
[d374492] | 26 | |
---|
| 27 | /** |
---|
| 28 | * @brief Initialize the eMIOS module. |
---|
| 29 | * |
---|
| 30 | * The module is enabled. It is configured to use the internal clock. The |
---|
| 31 | * global prescaler value is set to @a prescaler. If the value is greater than |
---|
| 32 | * the maximum the maxium value will be used instead. A prescaler value of |
---|
| 33 | * zero disables the clock. |
---|
| 34 | * |
---|
| 35 | * @note No protection against concurrent execution. |
---|
| 36 | */ |
---|
| 37 | void mpc55xx_emios_initialize( unsigned prescaler) |
---|
| 38 | { |
---|
| 39 | union EMIOS_MCR_tag mcr = MPC55XX_ZERO_FLAGS; |
---|
| 40 | |
---|
| 41 | /* Enable module */ |
---|
| 42 | mcr.B.MDIS = 0; |
---|
| 43 | |
---|
| 44 | /* Disable debug mode */ |
---|
| 45 | mcr.B.FRZ = 1; |
---|
| 46 | |
---|
| 47 | /* Enable global time base */ |
---|
| 48 | mcr.B.GTBE = 1; |
---|
| 49 | |
---|
| 50 | /* Disable global prescaler (= disable clock) */ |
---|
| 51 | mcr.B.GPREN = 0; |
---|
| 52 | |
---|
| 53 | /* Set MCR */ |
---|
| 54 | EMIOS.MCR.R = mcr.R; |
---|
| 55 | |
---|
| 56 | /* Set OUDR */ |
---|
| 57 | EMIOS.OUDR.R = 0; |
---|
| 58 | |
---|
| 59 | /* Set global prescaler value */ |
---|
| 60 | mpc55xx_emios_set_global_prescaler( prescaler); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * @brief Returns the global prescaler value of the eMIOS module. |
---|
| 65 | */ |
---|
| 66 | unsigned mpc55xx_emios_global_prescaler( void) |
---|
| 67 | { |
---|
| 68 | union EMIOS_MCR_tag mcr = EMIOS.MCR; |
---|
| 69 | |
---|
| 70 | if (mcr.B.GPREN != 0) { |
---|
| 71 | return mcr.B.GPRE + 1; |
---|
| 72 | } else { |
---|
| 73 | return 0; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | * @brief Sets the global prescaler value of the eMIOS module. |
---|
| 79 | * |
---|
| 80 | * The global prescaler value is set to @a prescaler. If the value is greater |
---|
| 81 | * than the maximum the maxium value will be used instead. A prescaler value |
---|
| 82 | * of zero disables the clock. |
---|
| 83 | * |
---|
| 84 | * @note No protection against concurrent execution. |
---|
| 85 | */ |
---|
| 86 | void mpc55xx_emios_set_global_prescaler( unsigned prescaler) |
---|
| 87 | { |
---|
| 88 | union EMIOS_MCR_tag mcr = EMIOS.MCR; |
---|
| 89 | |
---|
| 90 | /* Enable or disable the global prescaler */ |
---|
| 91 | mcr.B.GPREN = prescaler > 0 ? 1 : 0; |
---|
| 92 | |
---|
| 93 | /* Set global prescaler value */ |
---|
| 94 | if (prescaler > 256) { |
---|
| 95 | prescaler = 256; |
---|
| 96 | } else if (prescaler < 1) { |
---|
| 97 | prescaler = 1; |
---|
| 98 | } |
---|
| 99 | mcr.B.GPRE = prescaler - 1; |
---|
| 100 | |
---|
| 101 | /* Set MCR */ |
---|
| 102 | EMIOS.MCR.R = mcr.R; |
---|
| 103 | } |
---|
[a762dc2] | 104 | |
---|
| 105 | #endif /* MPC55XX_HAS_EMIOS */ |
---|