Skip to content

Commit 8d34371

Browse files
committed
Moved atsam4s power to atsamxx
1 parent d923083 commit 8d34371

4 files changed

Lines changed: 95 additions & 4 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef KLIB_ATSAM3X8E_POWER_HPP
2+
#define KLIB_ATSAM3X8E_POWER_HPP
3+
4+
#include <targets/core/atmel/atsamxx/power.hpp>
5+
6+
namespace klib::atsam3x8e::io {
7+
using power_control = klib::core::atsamxx::io::power_control;
8+
}
9+
10+
#endif

targets/chip/atsam3x8e/io/watchdog.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#include <cstdint>
55

6-
#include <atsam3x8e.hpp>
7-
86
#include <targets/core/atmel/atsamxx/watchdog.hpp>
97

108
namespace klib::atsam3x8e::io::periph {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef KLIB_ATSAM4S2B_POWER_HPP
22
#define KLIB_ATSAM4S2B_POWER_HPP
33

4-
#include <targets/core/atmel/atsam4s/power.hpp>
4+
#include <targets/core/atmel/atsamxx/power.hpp>
55

66
namespace klib::atsam4s2b::io {
7-
using power_control = klib::core::atsam4s::io::power_control;
7+
using power_control = klib::core::atsamxx::io::power_control;
88
}
99

1010
#endif
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#ifndef KLIB_ATMEL_ATSAMXX_POWER_CONTROL_HPP
2+
#define KLIB_ATMEL_ATSAMXX_POWER_CONTROL_HPP
3+
4+
#include <klib/klib.hpp>
5+
6+
namespace klib::core::atsamxx::io {
7+
class power_control {
8+
public:
9+
/**
10+
* @brief Enable the clock on the peripheral
11+
*
12+
* @tparam P
13+
*/
14+
template <typename P>
15+
static void enable() {
16+
// disable the write protect
17+
write_protect<false>();
18+
19+
// set the bit to enable the clock on the peripheral
20+
if constexpr (P::clock_id < 32) {
21+
PMC->PMC_PCER0 = (0x1 << P::clock_id);
22+
}
23+
else {
24+
PMC->PMC_PCER1 = (0x1 << (P::clock_id - 32));
25+
}
26+
27+
// enable the write protect again
28+
write_protect<true>();
29+
}
30+
31+
/**
32+
* @brief Disable the clock on the peripheral
33+
*
34+
* @tparam P
35+
*/
36+
template <typename P>
37+
static void disable() {
38+
// disable the write protect
39+
write_protect<false>();
40+
41+
// set the bit to enable the clock on the peripheral
42+
if constexpr (P::clock_id < 32) {
43+
PMC->PMC_PCDR0 = (0x1 << P::clock_id);
44+
}
45+
else {
46+
PMC->PMC_PCDR1 = (0x1 << (P::clock_id - 32));
47+
}
48+
49+
// enable the write protect again
50+
write_protect<true>();
51+
}
52+
53+
/**
54+
* @brief Get the clock status of a peripheral
55+
*
56+
* @tparam P
57+
* @return true
58+
* @return false
59+
*/
60+
template <typename P>
61+
static bool status() {
62+
// return the value of the clock id in the register (1 = enabled, 0 = disabled)
63+
if constexpr ((P::clock_id * 2) < 32) {
64+
return PMC->PMC_PCSR0 & (0x1 << P::clock_id);
65+
}
66+
else {
67+
return PMC->PMC_PCSR1 & (0x1 << (P::clock_id - 32));
68+
}
69+
}
70+
71+
/**
72+
* @brief Disables/enables the write protect on the PMC
73+
*
74+
*/
75+
template <bool Enable>
76+
static void write_protect() {
77+
// disable the PMC write protection
78+
PMC->PMC_WPMR = (0x504D43 << 8) | Enable;
79+
}
80+
};
81+
}
82+
83+
#endif

0 commit comments

Comments
 (0)