1 /*
2 * @brief LPC15XX System Control functions
3 *
4 * Copyright(C) NXP Semiconductors, 2013
5 * All rights reserved.
6 *
7 * Software that is described herein is for illustrative purposes only
8 * which provides customers with programming information regarding the
9 * LPC products. This software is supplied "AS IS" without any warranties of
10 * any kind, and NXP Semiconductors and its licensor disclaim any and
11 * all warranties, express or implied, including all implied warranties of
12 * merchantability, fitness for a particular purpose and non-infringement of
13 * intellectual property rights. NXP Semiconductors assumes no responsibility
14 * or liability for the use of the software, conveys no license or rights under any
15 * patent, copyright, mask work right, or any other intellectual property rights in
16 * or to any products. NXP Semiconductors reserves the right to make changes
17 * in the software without notification. NXP Semiconductors also makes no
18 * representation or warranty that such application will be suitable for the
19 * specified use without further testing or modification.
20 *
21 * Permission to use, copy, modify, and distribute this software and its
22 * documentation is hereby granted, under NXP Semiconductors' and its
23 * licensor's relevant copyrights in the software, without fee, provided that it
24 * is used in conjunction with NXP Semiconductors microcontrollers. This
25 * copyright, permission, and disclaimer notice must appear in all copies of
26 * this code.
27 */
28
29 #include "chip.h"
30
31 /*****************************************************************************
32 * Private types/enumerations/variables
33 ****************************************************************************/
34
35 /* PDWAKECFG register mask */
36 #define PDWAKEUPUSEMASK 0x00000000
37 #define PDWAKEUPMASKTMP 0x01FFFF78
38
39 /* PDRUNCFG register mask */
40 #define PDRUNCFGUSEMASK 0x00000000
41 #define PDRUNCFGMASKTMP 0x01FFFF78
42
43 /*****************************************************************************
44 * Public types/enumerations/variables
45 ****************************************************************************/
46
47 /*****************************************************************************
48 * Private functions
49 ****************************************************************************/
50
51 /*****************************************************************************
52 * Public functions
53 ****************************************************************************/
54
55 /* Returns the computed value for a frequency measurement cycle */
Chip_SYSCTL_GetCompFreqMeas(uint32_t refClockRate)56 uint32_t Chip_SYSCTL_GetCompFreqMeas(uint32_t refClockRate)
57 {
58 uint32_t capval, clkrate = 0;
59
60 /* Get raw capture value */
61 capval = Chip_SYSCTL_GetRawFreqMeasCapval();
62
63 /* Limit CAPVAL check */
64 if (capval > 2) {
65 clkrate = ((capval - 2) * refClockRate) / 0x4000;
66 }
67
68 return clkrate;
69 }
70
71 /* De-assert reset for a peripheral */
Chip_SYSCTL_AssertPeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph)72 void Chip_SYSCTL_AssertPeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph)
73 {
74 if (periph >= 32) {
75 LPC_SYSCTL->PRESETCTRL[1] |= (1 << ((uint32_t) periph - 32));
76 }
77 else {
78 LPC_SYSCTL->PRESETCTRL[0] |= (1 << (uint32_t) periph);
79 }
80 }
81
82 /* Assert reset for a peripheral */
Chip_SYSCTL_DeassertPeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph)83 void Chip_SYSCTL_DeassertPeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph)
84 {
85 if (periph >= 32) {
86 LPC_SYSCTL->PRESETCTRL[1] &= ~(1 << ((uint32_t) periph - 32));
87 }
88 else {
89 LPC_SYSCTL->PRESETCTRL[0] &= ~(1 << (uint32_t) periph);
90 }
91 }
92
93 /* Setup wakeup behaviour from deep sleep */
Chip_SYSCTL_SetWakeup(uint32_t wakeupmask)94 void Chip_SYSCTL_SetWakeup(uint32_t wakeupmask)
95 {
96 /* Update new value */
97 LPC_SYSCTL->PDWAKECFG = PDWAKEUPUSEMASK | (wakeupmask & PDWAKEUPMASKTMP);
98 }
99
100 /* Power down one or more blocks or peripherals */
Chip_SYSCTL_PowerDown(uint32_t powerdownmask)101 void Chip_SYSCTL_PowerDown(uint32_t powerdownmask)
102 {
103 uint32_t pdrun;
104
105 pdrun = LPC_SYSCTL->PDRUNCFG & PDRUNCFGMASKTMP;
106 pdrun |= (powerdownmask & PDRUNCFGMASKTMP);
107
108 LPC_SYSCTL->PDRUNCFG = (pdrun | PDRUNCFGUSEMASK);
109 }
110
111 /* Power up one or more blocks or peripherals */
Chip_SYSCTL_PowerUp(uint32_t powerupmask)112 void Chip_SYSCTL_PowerUp(uint32_t powerupmask)
113 {
114 uint32_t pdrun;
115
116 pdrun = LPC_SYSCTL->PDRUNCFG & PDRUNCFGMASKTMP;
117 pdrun &= ~(powerupmask & PDRUNCFGMASKTMP);
118
119 LPC_SYSCTL->PDRUNCFG = (pdrun | PDRUNCFGUSEMASK);
120 }
121