/** * @file misc.h * @brief * * Copyright (c) 2021 Bouffalolab team * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The * ASF licenses this file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * */ #ifndef _MISC_H #define _MISC_H #include "stdio.h" #include "stdint.h" #include "string.h" #include "stdarg.h" #include "stdbool.h" #include "gcc.h" /*@} end of group COMMON_Public_Types */ /** @defgroup COMMON_Public_Constants * @{ */ /** * @brief Memory access macro */ #define BL_RD_WORD(addr) (*((volatile uint32_t*)(addr))) #define BL_WR_WORD(addr,val) ((*(volatile uint32_t*)(addr))=(val)) #define BL_RD_SHORT(addr) (*((volatile uint16_t*)(addr))) #define BL_WR_SHORT(addr,val) ((*(volatile uint16_t*)(addr))=(val)) #define BL_RD_BYTE(addr) (*((volatile uint8_t*)(addr))) #define BL_WR_BYTE(addr,val) ((*(volatile uint8_t*)(addr))=(val)) #define BL_RDWD_FRM_BYTEP(p) ((p[3]<<24)|(p[2]<<16)|(p[1]<<8)|(p[0])) #define BL_WRWD_TO_BYTEP(p,val) {p[0]=val&0xff;p[1]=(val>>8)&0xff;p[2]=(val>>16)&0xff;p[3]=(val>>24)&0xff;} /** * @brief Register access macro */ #define BL_RD_REG16(addr,regname) BL_RD_SHORT(addr+regname##_OFFSET) #define BL_WR_REG16(addr,regname,val) BL_WR_SHORT(addr+regname##_OFFSET,val) #define BL_RD_REG(addr,regname) BL_RD_WORD(addr+regname##_OFFSET) #define BL_WR_REG(addr,regname,val) BL_WR_WORD(addr+regname##_OFFSET,val) #define BL_SET_REG_BIT(val,bitname) ( (val) |(1U<> bitname##_POS ) #define BL_SET_REG_BITS_VAL(val,bitname,bitval) ( ((val)&bitname##_UMSK) | ((uint32_t)(bitval)<