Welcome to mirror list, hosted at ThFree Co, Russian Federation.

systemcontrol.c « e4 « msp432 « lib - github.com/thirdpin/libopencm3.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01a20739711ad9b83bdbeb9ff95ecb3d65079d67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/** @defgroup systemcontrol_file System Control
 *
 * @ingroup MSP432E4xx
 *
 * @brief libopencm3 MSP432E4xx System Control
 *
 * @version 1.0.0
 *
 * @date 22 July 2018
 *
 * LGPL License Terms @ref lgpl_license
 */

/*
 * This file is part of the libopencm3 project.
 *
 * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
 * Copyright (C) 2018 Dmitry Rezvanov <dmitry.rezvanov@yandex.ru>
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <libopencm3/msp432/e4/systemcontrol.h>
#include <stdbool.h>

#define _SYSCTL_REG(base, i)     MMIO32((base) + ((i) >> 5))
#define _SYSCTL_BIT(i)           (1 << ((i) & 0x1f))

/*----------------------------------------------------------------------------*/
/** @brief System Control Enable Peripheral Clock
 *
 * @param[in] clock_mode ::msp432_clock_mode Clock mode
 * @param[in] periph ::msp432_periph Peripheral block
 */
void sysctl_periph_clock_enable(enum msp432_clock_mode clock_mode,
	enum msp432_periph periph)
{
	_SYSCTL_REG(SYSCTL_BASE + clock_mode, periph) |= _SYSCTL_BIT(periph);
}

/*----------------------------------------------------------------------------*/
/** @brief System Control Disable Peripheral Clock
 *
 * @param[in] clock_mode ::msp432_clock_mode Clock mode
 * @param[in] periph ::msp432_periph Peripheral block
 */
void sysctl_periph_clock_disable(enum msp432_clock_mode clock_mode,
	enum msp432_periph periph)
{
	_SYSCTL_REG(SYSCTL_BASE + clock_mode, periph) &= ~_SYSCTL_BIT(periph);
}

/*----------------------------------------------------------------------------*/
/** @brief System Control Peripheral Software Reset
 *
 * @param[in] periph ::msp432_periph Peripheral block
 */
void sysctl_periph_reset(enum msp432_periph periph)
{
	_SYSCTL_REG((uint32_t) &SYSCTL_SRWD, periph) |= _SYSCTL_BIT(periph);
}

/*----------------------------------------------------------------------------*/
/** @brief System Control Peripheral Clear Software Reset
 *
 * @param[in] periph ::msp432_periph Peripheral block
 */
void sysctl_periph_clear_reset(enum msp432_periph periph)
{
	_SYSCTL_REG((uint32_t) &SYSCTL_SRWD, periph) &= ~_SYSCTL_BIT(periph);
}

/*----------------------------------------------------------------------------*/
/** @brief System Control Peripheral Is Present
 *
 * @param[in] periph ::msp432_periph Peripheral block
 */
bool sysctl_periph_is_present(enum msp432_periph periph)
{
	uint32_t reg32 = _SYSCTL_REG((uint32_t) &SYSCTL_PPWD, periph);
	uint32_t mask = _SYSCTL_BIT(periph);

	return((reg32 & mask) != 0);
}

/*----------------------------------------------------------------------------*/
/** @brief System Control Peripheral Is Ready
 *
 * @param[in] periph ::msp432_periph Peripheral block
 */
bool sysctl_periph_is_ready(enum msp432_periph periph)
{
	uint32_t reg32 = _SYSCTL_REG((uint32_t) &SYSCTL_PRWD, periph);
	uint32_t mask = _SYSCTL_BIT(periph);

	return((reg32 & mask) != 0);
}

/*----------------------------------------------------------------------------*/
/** @brief System Control Peripheral Set Power State
 *
 * @param[in] power_mode ::msp432_power_mode Power mode
 * @param[in] periph ::msp432_periph Peripheral block
 *
 * @note If the module is in run, sleep or deep-sleep mode - the module
 * is powered and receives a clock regardless of the value of power mode.
 */
void sysctl_periph_set_power_state(enum msp432_power_mode power_mode,
	enum msp432_periph periph)
{
	if (power_mode == POWER_ENABLE) {
		_SYSCTL_REG((uint32_t) &SYSCTL_PCWD, periph) |= _SYSCTL_BIT(periph);
	} else {
		_SYSCTL_REG((uint32_t) &SYSCTL_PCWD, periph) &= ~_SYSCTL_BIT(periph);
	}
}

#undef _SYSCTL_REG
#undef _SYSCTL_BIT