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
|
/*
* Copyright (c) 2012 Sebastian Huber. All rights reserved.
*
* embedded brains GmbH
* Obere Lagerstr. 30
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*/
#include <bsp/rcc.h>
#include <bsp/io.h>
#include <rtems.h>
static void rcc_set(
stm32f4_rcc_index index,
bool set,
volatile uint32_t *regs
)
{
int reg = index >> 5;
uint32_t one = 1;
uint32_t bit = one << (index & 0x1f);
rtems_interrupt_level level;
uint32_t val;
rtems_interrupt_disable(level);
val = regs [reg];
if (set) {
val |= bit;
} else {
val &= ~bit;
}
regs [reg] = val;
rtems_interrupt_enable(level);
}
void stm32f4_rcc_reset(stm32f4_rcc_index index, bool set)
{
volatile stm32f4_rcc *rcc = STM32F4_RCC;
rcc_set(index, set, &rcc->ahbrstr [0]);
}
void stm32f4_rcc_set_clock(stm32f4_rcc_index index, bool set)
{
volatile stm32f4_rcc *rcc = STM32F4_RCC;
rcc_set(index, set, &rcc->ahbenr [0]);
}
void stm32f4_rcc_set_gpio_clock(int pin, bool set)
{
int port = STM32F4_GPIO_PORT_OF_PIN(pin);
stm32f4_rcc_index index = STM32F4_RCC_GPIOA + port;
stm32f4_rcc_set_clock(index, set);
}
void stm32f4_rcc_set_low_power_clock(stm32f4_rcc_index index, bool set)
{
volatile stm32f4_rcc *rcc = STM32F4_RCC;
rcc_set(index, set, &rcc->ahblpenr [0]);
}
|