1 /** 2 * 3 * Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries. 4 * 5 * \asf_license_start 6 * 7 * \page License 8 * 9 * SPDX-License-Identifier: Apache-2.0 10 * 11 * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 * not use this file except in compliance with the License. 13 * You may obtain a copy of the Licence at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, software 18 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 * See the License for the specific language governing permissions and 21 * limitations under the License. 22 * 23 * \asf_license_stop 24 * 25 */ 26 27 #ifndef _REGACCESS_H 28 #define _REGACCESS_H 29 30 #include <stdint.h> 31 32 #define MMCR32(a) *((volatile uint32_t *)(uintptr_t)(a)) 33 #define MMCR16(a) *((volatile uint16_t *)(uintptr_t)(a)) 34 #define MMCR8(a) *((volatile uint8_t *)(uintptr_t)(a)) 35 36 #define MMCR_RD32(a, v) v = *((volatile uint32_t *)(uintptr_t)(a)) 37 #define MMCR_RD16(a, v) v = *((volatile uint16_t *)(uintptr_t)(a)) 38 #define MMCR_RD8(a, v) v = *((volatile uint8_t *)(uintptr_t)(a)) 39 40 #define MMCR_WR32(a, d) *((volatile uint32_t *)(uintptr_t)(a)) = (uint32_t)(d) 41 #define MMCR_WR16(a, h) *((volatile uint16_t *)(uintptr_t)(a)) = (uint16_t)(h) 42 #define MMCR_WR8(a, b) *((volatile uint8_t *)(uintptr_t)(a)) = (uint8_t)(b) 43 44 #define REG32(a) *((volatile uint32_t *)(uintptr_t)(a)) 45 #define REG16(a) *((volatile uint16_t *)(uintptr_t)(a)) 46 #define REG8(a) *((volatile uint8_t *)(uintptr_t)(a)) 47 48 #define REG32W(a, d) *((volatile uint32_t *)(uintptr_t)(a)) = (uint32_t)(d) 49 #define REG16W(a, h) *((volatile uint16_t *)(uintptr_t)(a)) = (uint16_t)(h) 50 #define REG8W(a, b) *((volatile uint8_t *)(uintptr_t)(a)) = (uint8_t)(b) 51 52 #define REG32R(a, d) (d) = *(volatile uint32_t *)(uintptr_t)(a) 53 #define REG16R(a, h) (h) = *(volatile uint16_t *)(uintptr_t)(a) 54 #define REG8R(a, b) (b) = *(volatile uint8_t *)(uintptr_t)(a) 55 56 #define REG32_OFS(a, ofs) *(volatile uint32_t *)((uintptr_t)(a) + (uintptr_t)(ofs)) 57 #define REG16_OFS(a, ofs) *(volatile uint16_t *)((uintptr_t)(a) + (uintptr_t)(ofs)) 58 #define REG8_OFS(a, ofs) *(volatile uint8_t *)((uintptr_t)(a) + (uintptr_t)(ofs)) 59 60 #define REG32_BIT_SET(a, b) *(volatile uint32_t *)(a) |= (1ul << (b)) 61 #define REG32_BIT_CLR(a, b) *(volatile uint32_t *)(a) &= ~(1ul << (b)) 62 63 #define REG16_BIT_SET(a, b) *(volatile uint16_t *)(a) |= (1ul << (b)) 64 #define REG16_BIT_CLR(a, b) *(volatile uint16_t *)(a) &= ~(1ul << (b)) 65 66 #define REG8_BIT_SET(a, b) *(volatile uint8_t *)(a) |= (1ul << (b)) 67 #define REG8_BIT_CLR(a, b) *(volatile uint8_t *)(a) &= ~(1ul << (b)) 68 69 #endif // #ifndef _REGACCESS_H 70