Christina Quast | 2d18f17 | 2014-11-22 19:48:48 +0100 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------------
|
| 2 | * ATMEL Microcontroller Software Support
|
| 3 | * ----------------------------------------------------------------------------
|
| 4 | * Copyright (c) 2009, Atmel Corporation
|
| 5 | *
|
| 6 | * All rights reserved.
|
| 7 | *
|
| 8 | * Redistribution and use in source and binary forms, with or without
|
| 9 | * modification, are permitted provided that the following conditions are met:
|
| 10 | *
|
| 11 | * - Redistributions of source code must retain the above copyright notice,
|
| 12 | * this list of conditions and the disclaimer below.
|
| 13 | *
|
| 14 | * Atmel's name may not be used to endorse or promote products derived from
|
| 15 | * this software without specific prior written permission.
|
| 16 | *
|
| 17 | * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
| 20 | * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
| 23 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
| 26 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 | * ----------------------------------------------------------------------------
|
| 28 | */
|
| 29 |
|
| 30 | /*----------------------------------------------------------------------------
|
| 31 | * Headers
|
| 32 | *----------------------------------------------------------------------------*/
|
| 33 |
|
| 34 | #include "include/chip.h"
|
| 35 |
|
| 36 | //#include <//assert.h>
|
| 37 |
|
| 38 | /*----------------------------------------------------------------------------
|
| 39 | * Local definitions
|
| 40 | *----------------------------------------------------------------------------*/
|
| 41 |
|
| 42 | #define MASK_STATUS0 0xFFFFFFFC
|
| 43 | #define MASK_STATUS1 0xFFFFFFFF
|
| 44 |
|
| 45 | /*----------------------------------------------------------------------------
|
| 46 | * Exported functions
|
| 47 | *----------------------------------------------------------------------------*/
|
| 48 |
|
| 49 | /**
|
| 50 | * \brief Enables the clock of a peripheral. The peripheral ID is used
|
| 51 | * to identify which peripheral is targetted.
|
| 52 | *
|
| 53 | * \note The ID must NOT be shifted (i.e. 1 << ID_xxx).
|
| 54 | *
|
| 55 | * \param id Peripheral ID (ID_xxx).
|
| 56 | */
|
| 57 | extern void PMC_EnablePeripheral( uint32_t dwId )
|
| 58 | {
|
| 59 | //assert( dwId < 35 ) ;
|
| 60 |
|
| 61 | if ( dwId < 32 )
|
| 62 | {
|
| 63 | if ( (PMC->PMC_PCSR0 & ((uint32_t)1 << dwId)) == ((uint32_t)1 << dwId) )
|
| 64 | {
|
| 65 | }
|
| 66 | else
|
| 67 | {
|
| 68 | PMC->PMC_PCER0 = 1 << dwId ;
|
| 69 | }
|
| 70 | }
|
| 71 | else
|
| 72 | {
|
| 73 | dwId -= 32;
|
| 74 | if ((PMC->PMC_PCSR1 & ((uint32_t)1 << dwId)) == ((uint32_t)1 << dwId))
|
| 75 | {
|
| 76 | }
|
| 77 | else
|
| 78 | {
|
| 79 | PMC->PMC_PCER1 = 1 << dwId ;
|
| 80 | }
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | /**
|
| 85 | * \brief Disables the clock of a peripheral. The peripheral ID is used
|
| 86 | * to identify which peripheral is targetted.
|
| 87 | *
|
| 88 | * \note The ID must NOT be shifted (i.e. 1 << ID_xxx).
|
| 89 | *
|
| 90 | * \param id Peripheral ID (ID_xxx).
|
| 91 | */
|
| 92 | extern void PMC_DisablePeripheral( uint32_t dwId )
|
| 93 | {
|
| 94 | //assert( dwId < 35 ) ;
|
| 95 |
|
| 96 | if ( dwId < 32 )
|
| 97 | {
|
| 98 | if ( (PMC->PMC_PCSR0 & ((uint32_t)1 << dwId)) != ((uint32_t)1 << dwId) )
|
| 99 | {
|
| 100 | }
|
| 101 | else
|
| 102 | {
|
| 103 | PMC->PMC_PCDR0 = 1 << dwId ;
|
| 104 | }
|
| 105 | }
|
| 106 | else
|
| 107 | {
|
| 108 | dwId -= 32 ;
|
| 109 | if ( (PMC->PMC_PCSR1 & ((uint32_t)1 << dwId)) != ((uint32_t)1 << dwId) )
|
| 110 | {
|
| 111 | }
|
| 112 | else
|
| 113 | {
|
| 114 | PMC->PMC_PCDR1 = 1 << dwId ;
|
| 115 | }
|
| 116 | }
|
| 117 | }
|
| 118 |
|
| 119 | /**
|
| 120 | * \brief Enable all the periph clock via PMC.
|
| 121 | */
|
| 122 | extern void PMC_EnableAllPeripherals( void )
|
| 123 | {
|
| 124 | PMC->PMC_PCER0 = MASK_STATUS0 ;
|
| 125 | while ( (PMC->PMC_PCSR0 & MASK_STATUS0) != MASK_STATUS0 ) ;
|
| 126 |
|
| 127 | PMC->PMC_PCER1 = MASK_STATUS1 ;
|
| 128 | while ( (PMC->PMC_PCSR1 & MASK_STATUS1) != MASK_STATUS1 ) ;
|
| 129 |
|
| 130 | }
|
| 131 |
|
| 132 | /**
|
| 133 | * \brief Disable all the periph clock via PMC.
|
| 134 | */
|
| 135 | extern void PMC_DisableAllPeripherals( void )
|
| 136 | {
|
| 137 | PMC->PMC_PCDR0 = MASK_STATUS0 ;
|
| 138 | while ( (PMC->PMC_PCSR0 & MASK_STATUS0) != 0 ) ;
|
| 139 |
|
| 140 | PMC->PMC_PCDR1 = MASK_STATUS1 ;
|
| 141 | while ( (PMC->PMC_PCSR1 & MASK_STATUS1) != 0 ) ;
|
| 142 |
|
| 143 | }
|
| 144 |
|
| 145 | /**
|
| 146 | * \brief Get Periph Status for the given peripheral ID.
|
| 147 | *
|
| 148 | * \param id Peripheral ID (ID_xxx).
|
| 149 | */
|
| 150 | extern uint32_t PMC_IsPeriphEnabled( uint32_t dwId )
|
| 151 | {
|
| 152 | //assert( dwId < 35 ) ;
|
| 153 |
|
| 154 | if ( dwId < 32 )
|
| 155 | {
|
| 156 | return ( PMC->PMC_PCSR0 & (1 << dwId) ) ;
|
| 157 | }
|
| 158 | else {
|
| 159 | return ( PMC->PMC_PCSR1 & (1 << (dwId - 32)) ) ;
|
| 160 | }
|
| 161 | }
|