1 //------------------------------------------------------------------------------
2 // Copyright 2012 (c) Silicon Laboratories Inc.
3 //
4 // SPDX-License-Identifier: Zlib
5 //
6 // This siHAL software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 //    claim that you wrote the original software. If you use this software
16 //    in a product, an acknowledgment in the product documentation would be
17 //    appreciated but is not required.
18 // 2. Altered source versions must be plainly marked as such, and must not be
19 //    misrepresented as being the original software.
20 // 3. This notice may not be removed or altered from any source distribution.
21 //------------------------------------------------------------------------------
22 
23 #include "sim3u1xx.h"
24 
25 //------------------------------------------------------------------------------
26 // boot oscillator is 20MHz
27 uint32_t SystemCoreClock = 20000000;
28 
29 //------------------------------------------------------------------------------
SystemInit(void)30 void SystemInit(void)
31 {
32   // To disable the pin reset delay described below, make sure the preprocessor
33   // symbol si32HalOption_disable_pin_reset_delay is defined by your toolchain.
34 # if !defined(si32HalOption_disable_pin_reset_delay)
35   // If the reset pin was the source of the last reset, delay for 500 msec.
36   // Firmware can disable the debug port by inadvertantly setting the AHB
37   // clock source to a disabled clock. If this happens too quickly after a
38   // reset, it is not possible for a debug agent to gain control and thus
39   // not possible to reprogram the on-chip flash. Adding a delay here gives
40   // a debug agent sufficient time to connect.
41   if ((SI32_RSTSRC_0->RESETFLAG.PINRF == 1)
42   &&  (SI32_RSTSRC_0->RESETFLAG.PORRF == 0)
43   &&  (SI32_RSTSRC_0->RESETFLAG.VMONRF == 0))
44   {
45     // Set the SysTick timer to count down 10M ticks @ 20MHz (~500 msec)
46     SysTick->LOAD = 0xA00000;
47     SysTick->VAL  = 0;
48     SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
49 
50     // Wait for the count down to complete
51     while (0 == (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)) {}
52 
53     // Set the SysTick timer to reset values
54     SysTick->CTRL = 0;
55     SysTick->LOAD = 0;
56     SysTick->VAL  = 0;
57   }
58 # endif
59 
60   // invoke the application's system initialization.
61   mySystemInit();
62 }
63 
64 //------------------------------------------------------------------------------
SystemCoreClockUpdate(void)65 void SystemCoreClockUpdate(void)
66 {
67   // TBD - examine the clock registers and compute the system core clock value.
68 }
69 
70 //-eof--------------------------------------------------------------------------
71