libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
systemcontrol.c
Go to the documentation of this file.
1/** @defgroup systemcontrol_file System Control
2 *
3 * @ingroup MSP432E4xx
4 *
5 * @brief libopencm3 MSP432E4xx System Control
6 *
7 * @version 1.0.0
8 *
9 * @date 22 July 2018
10 *
11 * LGPL License Terms @ref lgpl_license
12 */
13
14/*
15 * This file is part of the libopencm3 project.
16 *
17 * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
18 * Copyright (C) 2018 Dmitry Rezvanov <dmitry.rezvanov@yandex.ru>
19 *
20 * This library is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with this library. If not, see <http://www.gnu.org/licenses/>.
32 */
33
35#include <stdbool.h>
36
37#define _SYSCTL_REG(base, i) MMIO32((base) + ((i) >> 5))
38#define _SYSCTL_BIT(i) (1 << ((i) & 0x1f))
39
40/*----------------------------------------------------------------------------*/
41/** @brief System Control Enable Peripheral Clock
42 *
43 * @param[in] clock_mode ::msp432_clock_mode Clock mode
44 * @param[in] periph ::msp432_periph Peripheral block
45 */
47 enum msp432_periph periph)
48{
49 _SYSCTL_REG(SYSCTL_BASE + clock_mode, periph) |= _SYSCTL_BIT(periph);
50}
51
52/*----------------------------------------------------------------------------*/
53/** @brief System Control Disable Peripheral Clock
54 *
55 * @param[in] clock_mode ::msp432_clock_mode Clock mode
56 * @param[in] periph ::msp432_periph Peripheral block
57 */
59 enum msp432_periph periph)
60{
61 _SYSCTL_REG(SYSCTL_BASE + clock_mode, periph) &= ~_SYSCTL_BIT(periph);
62}
63
64/*----------------------------------------------------------------------------*/
65/** @brief System Control Peripheral Software Reset
66 *
67 * @param[in] periph ::msp432_periph Peripheral block
68 */
70{
71 _SYSCTL_REG((uint32_t) &SYSCTL_SRWD, periph) |= _SYSCTL_BIT(periph);
72}
73
74/*----------------------------------------------------------------------------*/
75/** @brief System Control Peripheral Clear Software Reset
76 *
77 * @param[in] periph ::msp432_periph Peripheral block
78 */
80{
81 _SYSCTL_REG((uint32_t) &SYSCTL_SRWD, periph) &= ~_SYSCTL_BIT(periph);
82}
83
84/*----------------------------------------------------------------------------*/
85/** @brief System Control Peripheral Is Present
86 *
87 * @param[in] periph ::msp432_periph Peripheral block
88 */
90{
91 uint32_t reg32 = _SYSCTL_REG((uint32_t) &SYSCTL_PPWD, periph);
92 uint32_t mask = _SYSCTL_BIT(periph);
93
94 return((reg32 & mask) != 0);
95}
96
97/*----------------------------------------------------------------------------*/
98/** @brief System Control Peripheral Is Ready
99 *
100 * @param[in] periph ::msp432_periph Peripheral block
101 */
103{
104 uint32_t reg32 = _SYSCTL_REG((uint32_t) &SYSCTL_PRWD, periph);
105 uint32_t mask = _SYSCTL_BIT(periph);
106
107 return((reg32 & mask) != 0);
108}
109
110/*----------------------------------------------------------------------------*/
111/** @brief System Control Peripheral Set Power State
112 *
113 * @param[in] power_mode ::msp432_power_mode Power mode
114 * @param[in] periph ::msp432_periph Peripheral block
115 *
116 * @note If the module is in run, sleep or deep-sleep mode - the module
117 * is powered and receives a clock regardless of the value of power mode.
118 */
120 enum msp432_periph periph)
121{
122 if (power_mode == POWER_ENABLE) {
123 _SYSCTL_REG((uint32_t) &SYSCTL_PCWD, periph) |= _SYSCTL_BIT(periph);
124 } else {
125 _SYSCTL_REG((uint32_t) &SYSCTL_PCWD, periph) &= ~_SYSCTL_BIT(periph);
126 }
127}
128
129#undef _SYSCTL_REG
130#undef _SYSCTL_BIT
#define SYSCTL_BASE
System Control Base Address.
#define SYSCTL_PPWD
Watchdog Timer Peripheral Present.
#define SYSCTL_PRWD
Watchdog Timer Peripheral Ready.
#define SYSCTL_PCWD
Watchdog Timer Power Control.
#define SYSCTL_SRWD
Watchdog Timer Software Reset.
void sysctl_periph_set_power_state(enum msp432_power_mode power_mode, enum msp432_periph periph)
System Control Peripheral Set Power State.
bool sysctl_periph_is_ready(enum msp432_periph periph)
System Control Peripheral Is Ready.
msp432_power_mode
Power mode definitions.
void sysctl_periph_clock_disable(enum msp432_clock_mode clock_mode, enum msp432_periph periph)
System Control Disable Peripheral Clock.
Definition: systemcontrol.c:58
void sysctl_periph_clock_enable(enum msp432_clock_mode clock_mode, enum msp432_periph periph)
System Control Enable Peripheral Clock.
Definition: systemcontrol.c:46
void sysctl_periph_reset(enum msp432_periph periph)
System Control Peripheral Software Reset.
Definition: systemcontrol.c:69
msp432_clock_mode
Clock mode definitions The definitions are specified in the form offset from SYSCTL_BASE.
msp432_periph
Peripheral list definitions The definitions are specified in the form 31:5 register offset from first...
void sysctl_periph_clear_reset(enum msp432_periph periph)
System Control Peripheral Clear Software Reset.
Definition: systemcontrol.c:79
bool sysctl_periph_is_present(enum msp432_periph periph)
System Control Peripheral Is Present.
Definition: systemcontrol.c:89
@ POWER_ENABLE
#define _SYSCTL_BIT(i)
Definition: systemcontrol.c:38
#define _SYSCTL_REG(base, i)
Definition: systemcontrol.c:37