1 /* 2 * Copyright (c) 2016 Piotr Mienkowski 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 /** @file 7 * @brief Atmel SAM MCU family Power Management Controller (PMC) module 8 * HAL driver. 9 */ 10 11 #include <soc.h> 12 #include <zephyr/sys/__assert.h> 13 #include <zephyr/sys/util.h> 14 15 #if ID_PERIPH_COUNT > 74 16 #error "Unsupported SoC, update soc_pmc.c functions" 17 #endif 18 soc_pmc_peripheral_enable(uint32_t id)19void soc_pmc_peripheral_enable(uint32_t id) 20 { 21 __ASSERT(id < ID_PERIPH_COUNT, "Invalid peripheral id"); 22 23 if (id < 32) { 24 PMC->PMC_PCER0 = BIT(id); 25 #if ID_PERIPH_COUNT > 32 26 } else if (id < 64) { 27 PMC->PMC_PCER1 = BIT(id & 0x1F); 28 #endif 29 #if ID_PERIPH_COUNT > 64 30 } else { 31 /* Nothing to do, thes peripherals can't be enabled */ 32 #endif 33 } 34 } 35 soc_pmc_peripheral_disable(uint32_t id)36void soc_pmc_peripheral_disable(uint32_t id) 37 { 38 __ASSERT(id < ID_PERIPH_COUNT, "Invalid peripheral id"); 39 40 if (id < 32) { 41 PMC->PMC_PCDR0 = BIT(id); 42 #if ID_PERIPH_COUNT > 32 43 } else if (id < 64) { 44 PMC->PMC_PCDR1 = BIT(id & 0x1F); 45 #endif 46 #if ID_PERIPH_COUNT > 64 47 } else { 48 /* Nothing to do, these peripherals can't be disabled */ 49 #endif 50 } 51 } 52 soc_pmc_peripheral_is_enabled(uint32_t id)53uint32_t soc_pmc_peripheral_is_enabled(uint32_t id) 54 { 55 __ASSERT(id < ID_PERIPH_COUNT, "Invalid peripheral id"); 56 57 if (id < 32) { 58 return (PMC->PMC_PCSR0 & BIT(id)) != 0; 59 #if ID_PERIPH_COUNT > 32 60 } else if (id < 64) { 61 return (PMC->PMC_PCSR1 & BIT(id & 0x1F)) != 0; 62 #endif 63 #if ID_PERIPH_COUNT > 64 64 } else { 65 /* These peripherals are always enabled */ 66 return 1; 67 #endif 68 } 69 return 0; 70 } 71