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>
|
2019-06-26 22:33:39 +08:00
|
|
|
#include <sys/__assert.h>
|
2019-06-26 22:33:55 +08:00
|
|
|
#include <sys/util.h>
|
2016-09-28 03:01:54 +08:00
|
|
|
|
2019-02-08 05:58:01 +08:00
|
|
|
#if ID_PERIPH_COUNT > 74
|
2016-09-28 03:01:54 +08:00
|
|
|
#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
|
2019-02-08 05:58:01 +08:00
|
|
|
} else if (id < 64) {
|
2016-09-28 03:01:54 +08:00
|
|
|
PMC->PMC_PCER1 = BIT(id & 0x1F);
|
2019-02-08 05:58:01 +08:00
|
|
|
#endif
|
|
|
|
#if ID_PERIPH_COUNT > 64
|
|
|
|
} else {
|
|
|
|
/* Nothing to do, thes peripherals can't be enabled */
|
2016-09-28 03:01:54 +08:00
|
|
|
#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
|
2019-02-08 05:58:01 +08:00
|
|
|
} else if (id < 64) {
|
2016-09-28 03:01:54 +08:00
|
|
|
PMC->PMC_PCDR1 = BIT(id & 0x1F);
|
2019-02-08 05:58:01 +08:00
|
|
|
#endif
|
|
|
|
#if ID_PERIPH_COUNT > 64
|
|
|
|
} else {
|
|
|
|
/* Nothing to do, these peripherals can't be disabled */
|
2016-09-28 03:01:54 +08:00
|
|
|
#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
|
2019-02-08 05:58:01 +08:00
|
|
|
} else if (id < 64) {
|
2016-09-28 03:01:54 +08:00
|
|
|
return (PMC->PMC_PCSR1 & BIT(id & 0x1F)) != 0;
|
2019-02-08 05:58:01 +08:00
|
|
|
#endif
|
|
|
|
#if ID_PERIPH_COUNT > 64
|
|
|
|
} else {
|
|
|
|
/* These peripherals are always enabled */
|
|
|
|
return 1;
|
2016-09-28 03:01:54 +08:00
|
|
|
#endif
|
|
|
|
}
|
2019-02-08 05:58:01 +08:00
|
|
|
return 0;
|
2016-09-28 03:01:54 +08:00
|
|
|
}
|