]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_MEC17xx_Keil_GCC/peripheral_library/system_internal.c
Add MPU project for multiple MEC17xx devices.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_MEC17xx_Keil_GCC / peripheral_library / system_internal.c
1 /**************************************************************************//**\r
2  * @file     system_internal.c\r
3  * @brief    CMSIS Device System Source File for\r
4  *           Microchip ARMCM4F Device Series\r
5  * @version  V1.09\r
6  * @date     27. August 2014\r
7  *\r
8  * @note\r
9  *\r
10  ******************************************************************************/\r
11 /* Copyright (c) 2011 - 2014 ARM LIMITED\r
12 \r
13    All rights reserved.\r
14    Redistribution and use in source and binary forms, with or without\r
15    modification, are permitted provided that the following conditions are met:\r
16    - Redistributions of source code must retain the above copyright\r
17      notice, this list of conditions and the following disclaimer.\r
18    - Redistributions in binary form must reproduce the above copyright\r
19      notice, this list of conditions and the following disclaimer in the\r
20      documentation and/or other materials provided with the distribution.\r
21    - Neither the name of ARM nor the names of its contributors may be used\r
22      to endorse or promote products derived from this software without\r
23      specific prior written permission.\r
24    *\r
25    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
26    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
27    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
28    ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE\r
29    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
30    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
31    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
32    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
33    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
34    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
35    POSSIBILITY OF SUCH DAMAGE.\r
36    ---------------------------------------------------------------------------*/\r
37 \r
38 \r
39 /*\r
40  * Device CMSIS header file \r
41  */\r
42 #include "common_lib.h"\r
43 #include "MCHP_device_header.h"\r
44 \r
45 \r
46 /*----------------------------------------------------------------------------\r
47   Define clocks\r
48  *----------------------------------------------------------------------------*/\r
49 #define __HSI             ( 48000000UL)\r
50 #define __XTAL            ( 48000000UL)    /* Oscillator frequency             */\r
51 \r
52 /*\r
53  * Core system clock is 48MHz derived from an internal oscillator\r
54  * It may be divided down using the PCR Processor Clock Control register. \r
55  * Supported dividers are: 1, 2, 3, 4, 16, and 48.\r
56  * Power on default is 4.\r
57  */\r
58 #define __SYSTEM_CLOCK    (__XTAL)\r
59 \r
60 /* !!!! Define EC_INIT_CLK_DIV for the clock divider you \r
61  * want the ARM CM4F core to run at !!!!\r
62  */\r
63 #ifndef EC_INIT_CLK_DIV\r
64 #define EC_INIT_CLK_DIV (1u)\r
65 #endif\r
66 \r
67 /*----------------------------------------------------------------------------\r
68   System Core Clock Variable\r
69  *----------------------------------------------------------------------------*/\r
70 uint32_t SystemCoreClock = __SYSTEM_CLOCK;/* System Core Clock Frequency      */\r
71 \r
72 \r
73 /**\r
74  * Update SystemCoreClock variable\r
75  *\r
76  * @param  none\r
77  * @return none\r
78  *\r
79  * @brief  Updates the SystemCoreClock with current core Clock\r
80  *         retrieved from cpu registers.\r
81  * @note Read the EC core clock divider from the PCR block's processor \r
82  * clock control register. Actual EC core frequency is 48MHz / proc_clock_control[7:0].\r
83  */\r
84 void SystemCoreClockUpdate (void)\r
85 {\r
86     uint32_t cpu_clk_div;\r
87     \r
88     SystemCoreClock = __SYSTEM_CLOCK;\r
89     cpu_clk_div = PCR->PROC_CLK_CNTRL;\r
90     if (cpu_clk_div) {\r
91         SystemCoreClock = __SYSTEM_CLOCK / cpu_clk_div;\r
92     }\r
93 }\r
94 \r
95 /**\r
96  * Initialize the system\r
97  *\r
98  * @param  none\r
99  * @return none\r
100  *\r
101  * @brief  Setup the microcontroller system.\r
102  *         Initialize the System.\r
103  * @note SystemInit is usually called from early startup code before \r
104  * C/C++ library initialization. It is used for early hardware initialization \r
105  * such as clocks, FPU, debug hardware, etc.\r
106  */\r
107 void SystemInit (void)\r
108 {\r
109   #if (__FPU_USED == 1)\r
110     SCB->CPACR |= ((3UL << 10*2) |                 /* set CP10 Full Access */\r
111                    (3UL << 11*2)  );               /* set CP11 Full Access */\r
112   #endif\r
113 \r
114 #ifdef UNALIGNED_SUPPORT_DISABLE\r
115   SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk;\r
116 #endif\r
117 \r
118   /* Program device PCR Processor Clock Control divider to set the EC core clock */\r
119   PCR->PROC_CLK_CNTRL = (EC_INIT_CLK_DIV);\r
120   SystemCoreClock = ( __SYSTEM_CLOCK / (EC_INIT_CLK_DIV) );\r
121   \r
122 }\r