2016-09-28 03:01:54 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Piotr Mienkowski
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
* @brief Atmel SAM MCU family Power Management Controller (PMC) module
|
|
|
|
* HAL driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <soc.h>
|
|
|
|
#include <misc/__assert.h>
|
|
|
|
#include <misc/util.h>
|
|
|
|
|
|
|
|
#if ID_PERIPH_COUNT > 64
|
|
|
|
#error "Unsupported SoC, update soc_pmc.c functions"
|
|
|
|
#endif
|
|
|
|
|
2017-04-21 02:30:33 +08:00
|
|
|
void soc_pmc_peripheral_enable(u32_t id)
|
2016-09-28 03:01:54 +08:00
|
|
|
{
|
|
|
|
__ASSERT(id < ID_PERIPH_COUNT, "Invalid peripheral id");
|
|
|
|
|
|
|
|
if (id < 32) {
|
|
|
|
PMC->PMC_PCER0 = BIT(id);
|
|
|
|
#if ID_PERIPH_COUNT > 32
|
|
|
|
} else {
|
|
|
|
PMC->PMC_PCER1 = BIT(id & 0x1F);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 02:30:33 +08:00
|
|
|
void soc_pmc_peripheral_disable(u32_t id)
|
2016-09-28 03:01:54 +08:00
|
|
|
{
|
|
|
|
__ASSERT(id < ID_PERIPH_COUNT, "Invalid peripheral id");
|
|
|
|
|
|
|
|
if (id < 32) {
|
|
|
|
PMC->PMC_PCDR0 = BIT(id);
|
|
|
|
#if ID_PERIPH_COUNT > 32
|
|
|
|
} else {
|
|
|
|
PMC->PMC_PCDR1 = BIT(id & 0x1F);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 02:30:33 +08:00
|
|
|
u32_t soc_pmc_peripheral_is_enabled(u32_t id)
|
2016-09-28 03:01:54 +08:00
|
|
|
{
|
|
|
|
__ASSERT(id < ID_PERIPH_COUNT, "Invalid peripheral id");
|
|
|
|
|
|
|
|
if (id < 32) {
|
|
|
|
return (PMC->PMC_PCSR0 & BIT(id)) != 0;
|
|
|
|
#if ID_PERIPH_COUNT > 32
|
|
|
|
} else {
|
|
|
|
return (PMC->PMC_PCSR1 & BIT(id & 0x1F)) != 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|