1 /*
2 * @brief CLKOUT example
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2014
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "board.h"
33 #include <stdio.h>
34
35 /*****************************************************************************
36 * Private types/enumerations/variables
37 ****************************************************************************/
38
39 static volatile uint32_t ticks100;
40
41 #if defined(BOARD_NXP_LPCXPRESSO_1549)
42 /* Use this pin for clockout */
43 #define CLKOUT_PORT 1
44 #define CLKOUT_PIN 0
45
46 #else
47 #error "No port/pin defined for the LPC15xx CLKOUT example"
48 #endif
49
50 /*****************************************************************************
51 * Public types/enumerations/variables
52 ****************************************************************************/
53
54 /*****************************************************************************
55 * Private functions
56 ****************************************************************************/
57
58 /*****************************************************************************
59 * Public functions
60 ****************************************************************************/
61
62 /**
63 * @brief Handle interrupt from SysTick timer
64 * @return Nothing
65 */
SysTick_Handler(void)66 void SysTick_Handler(void)
67 {
68 ticks100++;
69 if ((ticks100 % 100) == 0) {
70 Board_LED_Toggle(0);
71 }
72 }
73
74 /**
75 * @brief main routine for CLKOUT example
76 * @return Function should not exit.
77 */
main(void)78 int main(void)
79 {
80 CHIP_SYSCTL_CLKOUTSRC_T clkoutClks;
81
82 SystemCoreClockUpdate();
83 Board_Init();
84
85 Board_LED_Set(0, false);
86
87 /* Enable and setup SysTick Timer at a 100Hz rate */
88 SysTick_Config(Chip_Clock_GetSysTickClockRate() / 100);
89
90 /* Enable the power to the WDT */
91 Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_WDTOSC_PD);
92 /* Setup SCT PLL */
93 Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_SCTPLL_PD);
94 Chip_Clock_SetSCTPLLSource(SYSCTL_PLLCLKSRC_MAINOSC);
95 Chip_Clock_SetupSCTPLL(5, 2);
96 Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SCTPLL_PD);
97 /* Wait for PLL to lock */
98 while (!Chip_Clock_IsSCTPLLLocked()) {}
99 /* Enable RTC Oscillator */
100 Chip_Clock_EnableRTCOsc();
101
102 /* Enable SWM clocking prior to switch matrix operations */
103 Chip_SWM_Init();
104 Chip_GPIO_Init(LPC_GPIO);
105
106 /* Setup pin as CLKOUT */
107 Chip_SWM_MovablePortPinAssign(SWM_CLK_OUT_O, CLKOUT_PORT, CLKOUT_PIN);
108
109 /* Configure as a digital pin with no pullups/pulldowns */
110 Chip_IOCON_PinMuxSet(LPC_IOCON, CLKOUT_PORT, CLKOUT_PIN,
111 (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
112
113 /* Cycle through all clock sources for the CLKOUT pin */
114 while (1) {
115 for (clkoutClks = SYSCTL_CLKOUTSRC_IRC;
116 clkoutClks <= SYSCTL_CLKOUTSRC_RTC32K; clkoutClks++) {
117
118 /* Setup CLKOUT pin for specific clock with a divider of 1 */
119 Chip_Clock_SetCLKOUTSource(clkoutClks, 1);
120
121 /* Wait 5 seconds */
122 ticks100 = 0;
123 while (ticks100 < 500) {
124 __WFI();
125 }
126 }
127 }
128
129 /* Disable CLKOUT pin by setting divider to 0 */
130 Chip_Clock_SetCLKOUTSource(SYSCTL_CLKOUTSRC_MAINSYSCLK, 0);
131
132 return 0;
133 }
134