1 // Copyright (C) 2022 Beken Corporation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <soc/soc.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /** 24 * RD an 8-bit register from the core 25 * @param _pBase core base address in memory 26 * @param _offset offset into the core's register space 27 * @return 8-bit datum 28 */ 29 #define REG_RD8(_pBase, _offset) *((volatile UINT8 *)(_pBase + _offset)) 30 31 /** 32 * RD a 16-bit register from the core 33 * @param _pBase core base address in memory 34 * @param _offset offset into the core's register space 35 * @return 16-bit datum 36 */ 37 #define REG_RD16(_pBase, _offset) *((volatile UINT16 *)(_pBase + _offset)) 38 39 /** 40 * RD a 32-bit register from the core 41 * @param _pBase core base address in memory 42 * @param _offset offset into the core's register space 43 * @return 32-bit datum 44 */ 45 #define REG_RD32(_pBase, _offset) *((volatile UINT32 *)(_pBase + _offset)) 46 47 /** 48 * WR an 8-bit core register 49 * @param _pBase core base address in memory 50 * @param _offset offset into the core's register space 51 * @param _data 8-bit datum 52 */ 53 #define REG_WR8(_pBase, _offset, _data) \ 54 (*((volatile UINT8 *)(_pBase + _offset)) = _data) 55 56 /** 57 * WR a 16-bit core register 58 * @param _pBase core base address in memory 59 * @param _offset offset into the core's register space 60 * @param _data 16-bit datum 61 */ 62 #define REG_WR16(_pBase, _offset, _data) \ 63 (*((volatile UINT16 *)(_pBase + _offset)) = _data) 64 65 /** 66 * WR a 32-bit core register 67 * @param _pBase core base address in memory 68 * @param _offset offset into the core's register space 69 * @param _data 32-bit datum 70 */ 71 #define REG_WR32(_pBase, _offset, _data) \ 72 (*((volatile UINT32 *)(_pBase + _offset)) = _data) 73 74 #ifdef __cplusplus 75 } 76 #endif 77