This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
bl_mcu_sdk/common/misc/misc.h

211 lines
6.2 KiB
C
Raw Normal View History

2021-04-13 19:23:11 +08:00
/**
* @file misc.h
2021-06-20 12:25:46 +08:00
* @brief
*
2021-04-13 19:23:11 +08:00
* Copyright (c) 2021 Bouffalolab team
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
* 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
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
* http://www.apache.org/licenses/LICENSE-2.0
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
* 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.
2021-06-20 12:25:46 +08:00
*
2021-04-13 19:23:11 +08:00
*/
#ifndef _MISC_H
#define _MISC_H
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
2021-04-13 19:23:11 +08:00
#include "gcc.h"
#include "cmsis_compatible_gcc.h"
2021-04-13 19:23:11 +08:00
/*@} end of group COMMON_Public_Types */
/** @defgroup COMMON_Public_Constants
* @{
*/
/**
* @brief Memory access macro
*/
2021-06-20 12:25:46 +08:00
#define BL_RD_WORD(addr) (*((volatile uint32_t *)(uintptr_t)(addr)))
#define BL_WR_WORD(addr, val) ((*(volatile uint32_t *)(uintptr_t)(addr)) = (val))
#define BL_RD_SHORT(addr) (*((volatile uint16_t *)(uintptr_t)(addr)))
#define BL_WR_SHORT(addr, val) ((*(volatile uint16_t *)(uintptr_t)(addr)) = (val))
#define BL_RD_BYTE(addr) (*((volatile uint8_t *)(uintptr_t)(addr)))
#define BL_WR_BYTE(addr, val) ((*(volatile uint8_t *)(uintptr_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; \
}
2021-04-13 19:23:11 +08:00
/**
* @brief Register access macro
*/
2021-06-20 12:25:46 +08:00
#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_CLR_REG_BIT(val, bitname) ((val)&bitname##_UMSK)
#define BL_GET_REG_BITS_VAL(val, bitname) (((val)&bitname##_MSK) >> bitname##_POS)
#define BL_SET_REG_BITS_VAL(val, bitname, bitval) (((val)&bitname##_UMSK) | ((uint32_t)(bitval) << bitname##_POS))
#define BL_IS_REG_BIT_SET(val, bitname) (((val) & (1U << (bitname##_POS))) != 0)
#define BL_DRV_DUMMY \
{ \
__NOP(); \
__NOP(); \
__NOP(); \
__NOP(); \
}
2021-04-13 19:23:11 +08:00
/* Std driver attribute macro*/
#define ATTR_CLOCK_SECTION __attribute__((section(".sclock_rlt_code")))
#define ATTR_CLOCK_CONST_SECTION __attribute__((section(".sclock_rlt_const")))
#define ATTR_TCM_SECTION __attribute__((section(".tcm_code")))
#define ATTR_TCM_CONST_SECTION __attribute__((section(".tcm_const")))
#define ATTR_DTCM_SECTION __attribute__((section(".tcm_data")))
#define ATTR_HSRAM_SECTION __attribute__((section(".hsram_code")))
#define ATTR_DMA_RAM_SECTION __attribute__((section(".system_ram")))
#define ATTR_HBN_RAM_SECTION __attribute__((section(".hbn_ram_code")))
#define ATTR_HBN_RAM_CONST_SECTION __attribute__((section(".hbn_ram_data")))
#define ATTR_EALIGN(x) __attribute((aligned(x)))
#define ATTR_FALLTHROUGH() __attribute__((fallthrough))
#define ATTR_USED __attribute__((__used__))
2021-06-20 12:25:46 +08:00
#ifdef BIT
#undef BIT
#define BIT(n) (1UL << (n))
#else
#define BIT(n) (1UL << (n))
#endif
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
/**
* @brief Error type definition
*/
2021-06-20 12:25:46 +08:00
typedef enum {
SUCCESS = 0,
ERROR = 1,
TIMEOUT = 2,
INVALID = 3, /* invalid arguments */
NORESC = 4 /* no resource or resource temperary unavailable */
} BL_Err_Type;
2021-04-13 19:23:11 +08:00
/**
* @brief Functional type definition
*/
2021-06-20 12:25:46 +08:00
typedef enum {
DISABLE = 0,
ENABLE = 1,
} BL_Fun_Type;
2021-04-13 19:23:11 +08:00
/**
* @brief Status type definition
*/
2021-06-20 12:25:46 +08:00
typedef enum {
RESET = 0,
SET = 1,
} BL_Sts_Type;
2021-04-13 19:23:11 +08:00
/**
* @brief Mask type definition
*/
2021-06-20 12:25:46 +08:00
typedef enum {
UNMASK = 0,
MASK = 1
} BL_Mask_Type;
2021-04-13 19:23:11 +08:00
/**
* @brief Logical status Type definition
*/
2021-06-20 12:25:46 +08:00
typedef enum {
LOGIC_LO = 0,
LOGIC_HI = !LOGIC_LO
} LogicalStatus;
2021-04-13 19:23:11 +08:00
/**
* @brief Active status Type definition
*/
2021-06-20 12:25:46 +08:00
typedef enum {
DEACTIVE = 0,
ACTIVE = !DEACTIVE
} ActiveStatus;
2021-04-13 19:23:11 +08:00
2021-06-20 12:25:46 +08:00
/**
2021-04-13 19:23:11 +08:00
* @brief Interrupt callback function type
*/
2021-06-20 12:25:46 +08:00
typedef void(intCallback_Type)(void);
typedef void (*pFunc)(void);
2021-04-13 19:23:11 +08:00
/**
* @brief Null Type definition
*/
#ifndef NULL
2021-06-20 12:25:46 +08:00
#define NULL 0
2021-04-13 19:23:11 +08:00
#endif
2021-06-20 12:25:46 +08:00
2021-04-13 19:23:11 +08:00
/*@} end of group COMMON_Public_Constants */
/** @defgroup COMMON_Public_Macros
* @{
*/
2021-06-20 12:25:46 +08:00
#define BL602_MemCpy arch_memcpy
#define BL602_MemSet arch_memset
#define BL602_MemCmp arch_memcmp
#define BL602_MemCpy4 arch_memcpy4
#define BL602_MemCpy_Fast arch_memcpy_fast
#define BL602_MemSet4 arch_memset4
2021-04-13 19:23:11 +08:00
2021-06-20 12:25:46 +08:00
#define BL702_MemCpy arch_memcpy
#define BL702_MemSet arch_memset
#define BL702_MemCmp arch_memcmp
#define BL702_MemCpy4 arch_memcpy4
#define BL702_MemCpy_Fast arch_memcpy_fast
#define BL702_MemSet4 arch_memset4
2021-04-13 19:23:11 +08:00
2021-06-20 12:25:46 +08:00
#define ARCH_MemCpy_Fast arch_memcpy_fast
2021-04-13 19:23:11 +08:00
/**
* @brief Null Type definition
*/
#ifndef NULL
2021-06-20 12:25:46 +08:00
#define NULL 0
2021-04-13 19:23:11 +08:00
#endif
/*@} end of group DRIVER_Public_Macro */
/** @defgroup DRIVER_Public_FunctionDeclaration
* @brief DRIVER functions declaration
* @{
*/
void *arch_memcpy(void *dst, const void *src, uint32_t n);
void *arch_memset(void *s, uint8_t c, uint32_t n);
int arch_memcmp(const void *s1, const void *s2, uint32_t n);
uint32_t *arch_memcpy4(uint32_t *dst, const uint32_t *src, uint32_t n);
void *arch_memcpy_fast(void *pdst, const void *psrc, uint32_t n);
uint32_t *arch_memset4(uint32_t *dst, const uint32_t val, uint32_t n);
2021-06-20 12:25:46 +08:00
void memcopy_to_fifo(void *fifo_addr, uint8_t *data, uint32_t length);
void fifocopy_to_mem(void *fifo_addr, uint8_t *data, uint32_t length);
2021-04-13 19:23:11 +08:00
/*@} end of group DRIVER_COMMON */
#endif /* __BL602_COMMON_H__ */