Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
targets/TARGET_NUVOTON/TARGET_M451/TARGET_NUMAKER_PFM_M453/mbed_overrides.c@151:91825d030f9b, 2016-11-14 (annotated)
- Committer:
- DangerousElectrician
- Date:
- Mon Nov 14 04:39:23 2016 +0000
- Revision:
- 151:91825d030f9b
- Parent:
- 149:156823d33999
stuff changed?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| <> | 149:156823d33999 | 1 | /* mbed Microcontroller Library |
| <> | 149:156823d33999 | 2 | * Copyright (c) 2015-2016 Nuvoton |
| <> | 149:156823d33999 | 3 | * |
| <> | 149:156823d33999 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| <> | 149:156823d33999 | 5 | * you may not use this file except in compliance with the License. |
| <> | 149:156823d33999 | 6 | * You may obtain a copy of the License at |
| <> | 149:156823d33999 | 7 | * |
| <> | 149:156823d33999 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| <> | 149:156823d33999 | 9 | * |
| <> | 149:156823d33999 | 10 | * Unless required by applicable law or agreed to in writing, software |
| <> | 149:156823d33999 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| <> | 149:156823d33999 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| <> | 149:156823d33999 | 13 | * See the License for the specific language governing permissions and |
| <> | 149:156823d33999 | 14 | * limitations under the License. |
| <> | 149:156823d33999 | 15 | */ |
| <> | 149:156823d33999 | 16 | |
| <> | 149:156823d33999 | 17 | #include "analogin_api.h" |
| <> | 149:156823d33999 | 18 | |
| <> | 149:156823d33999 | 19 | // NOTE: Ensurce mbed_sdk_init() will get called before C++ global object constructor. |
| <> | 149:156823d33999 | 20 | #if defined(__CC_ARM) || defined(__GNUC__) |
| <> | 149:156823d33999 | 21 | void mbed_sdk_init_forced(void) __attribute__((constructor(101))); |
| <> | 149:156823d33999 | 22 | #elif defined(__ICCARM__) |
| <> | 149:156823d33999 | 23 | // FIXME: How to achieve it in IAR? |
| <> | 149:156823d33999 | 24 | #endif |
| <> | 149:156823d33999 | 25 | |
| <> | 149:156823d33999 | 26 | |
| <> | 149:156823d33999 | 27 | void mbed_sdk_init(void) |
| <> | 149:156823d33999 | 28 | { |
| <> | 149:156823d33999 | 29 | // NOTE: Support singleton semantics to be called from other init functions |
| <> | 149:156823d33999 | 30 | static int inited = 0; |
| <> | 149:156823d33999 | 31 | if (inited) { |
| <> | 149:156823d33999 | 32 | return; |
| <> | 149:156823d33999 | 33 | } |
| <> | 149:156823d33999 | 34 | inited = 1; |
| <> | 149:156823d33999 | 35 | |
| <> | 149:156823d33999 | 36 | /*---------------------------------------------------------------------------------------------------------*/ |
| <> | 149:156823d33999 | 37 | /* Init System Clock */ |
| <> | 149:156823d33999 | 38 | /*---------------------------------------------------------------------------------------------------------*/ |
| <> | 149:156823d33999 | 39 | /* Unlock protected registers */ |
| <> | 149:156823d33999 | 40 | SYS_UnlockReg(); |
| <> | 149:156823d33999 | 41 | |
| <> | 149:156823d33999 | 42 | /* Enable HIRC clock (Internal RC 22.1184MHz) */ |
| <> | 149:156823d33999 | 43 | CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk); |
| <> | 149:156823d33999 | 44 | /* Enable HXT clock (external XTAL 12MHz) */ |
| <> | 149:156823d33999 | 45 | CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk); |
| <> | 149:156823d33999 | 46 | /* Enable LIRC for lp_ticker */ |
| <> | 149:156823d33999 | 47 | CLK_EnableXtalRC(CLK_PWRCTL_LIRCEN_Msk); |
| <> | 149:156823d33999 | 48 | /* Enable LXT for RTC */ |
| <> | 149:156823d33999 | 49 | CLK_EnableXtalRC(CLK_PWRCTL_LXTEN_Msk); |
| <> | 149:156823d33999 | 50 | |
| <> | 149:156823d33999 | 51 | /* Wait for HIRC clock ready */ |
| <> | 149:156823d33999 | 52 | CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk); |
| <> | 149:156823d33999 | 53 | /* Wait for HXT clock ready */ |
| <> | 149:156823d33999 | 54 | CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk); |
| <> | 149:156823d33999 | 55 | /* Wait for LIRC clock ready */ |
| <> | 149:156823d33999 | 56 | CLK_WaitClockReady(CLK_STATUS_LIRCSTB_Msk); |
| <> | 149:156823d33999 | 57 | /* Wait for LXT clock ready */ |
| <> | 149:156823d33999 | 58 | CLK_WaitClockReady(CLK_STATUS_LXTSTB_Msk); |
| <> | 149:156823d33999 | 59 | |
| <> | 149:156823d33999 | 60 | /* Select HCLK clock source as HIRC and HCLK clock divider as 1 */ |
| <> | 149:156823d33999 | 61 | CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1)); |
| <> | 149:156823d33999 | 62 | |
| <> | 149:156823d33999 | 63 | /* Set core clock as 72000000 from PLL */ |
| <> | 149:156823d33999 | 64 | CLK_SetCoreClock(72000000); |
| <> | 149:156823d33999 | 65 | |
| <> | 149:156823d33999 | 66 | #if DEVICE_ANALOGIN |
| <> | 149:156823d33999 | 67 | // FIXME: Check voltage reference for EADC |
| <> | 149:156823d33999 | 68 | /* Vref connect to AVDD */ |
| <> | 149:156823d33999 | 69 | //SYS->VREFCTL = (SYS->VREFCTL & ~SYS_VREFCTL_VREFCTL_Msk) | SYS_VREFCTL_VREF_AVDD; |
| <> | 149:156823d33999 | 70 | #endif |
| <> | 149:156823d33999 | 71 | |
| <> | 149:156823d33999 | 72 | /* Update System Core Clock */ |
| <> | 149:156823d33999 | 73 | /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */ |
| <> | 149:156823d33999 | 74 | SystemCoreClockUpdate(); |
| <> | 149:156823d33999 | 75 | |
| <> | 149:156823d33999 | 76 | /* Lock protected registers */ |
| <> | 149:156823d33999 | 77 | SYS_LockReg(); |
| <> | 149:156823d33999 | 78 | } |
| <> | 149:156823d33999 | 79 | |
| <> | 149:156823d33999 | 80 | void mbed_sdk_init_forced(void) |
| <> | 149:156823d33999 | 81 | { |
| <> | 149:156823d33999 | 82 | mbed_sdk_init(); |
| <> | 149:156823d33999 | 83 | } |
