[feat][common] update mmheap driver which costs less ram,update gcc section

This commit is contained in:
jzlv 2021-09-26 12:52:14 +08:00
parent 53aa115201
commit 05c6122569
10 changed files with 734 additions and 1161 deletions

View File

@ -24,7 +24,7 @@
#ifndef __MY_MATH_F_H__
#define __MY_MATH_F_H__
#include "bflb_platform.h"
#include "misc.h"
#include "math.h"
typedef float float32_t;

View File

@ -20,7 +20,6 @@
*
*/
#include "drv_device.h"
#include "string.h"
#define dev_open (dev->open)
#define dev_close (dev->close)

View File

@ -24,7 +24,7 @@
#define __DRV_DEVICE_H__
#include "drv_list.h"
#include "bflb_platform.h"
#include "stdio.h"
#define DEVICE_NAME_MAX 20 /* max device name*/
@ -63,7 +63,7 @@
#define DEVICE_EINVAL 22 /* Invalid argument */
#define DEVICE_ENOSPACE 23 /* No more Device for Allocate */
#define __ASSERT_PRINT(fmt, ...) bflb_platform_printf(fmt, ##__VA_ARGS__)
#define __ASSERT_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define __ASSERT_LOC(test) \
__ASSERT_PRINT("ASSERTION FAIL [%s] @ %s:%d\n", \

File diff suppressed because it is too large Load Diff

View File

@ -1,194 +1,143 @@
/**
* @file drv_mmheap.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 _DRV_MMHEAP_H_
#define _DRV_MMHEAP_H_
#include "stdint.h"
#include "string.h"
#define MEMHEAP_STATUS_OK 0
#define MEMHEAP_STATUS_INVALID_ADDR -1
#define MEMHEAP_STATUS_INVALID_SIZE -2
#define MEMHEAP_STATUS_OVERFLOW -3
#define MEMHEAP_STATUS_ALREADY_NOT_EXIST -4
#define MEMHEAP_STATUS_ALREADY_EXIST -5
/**
* log2 of number of linear subdivisions of block sizes. Larger
* values require more memory in the control structure. Values of
* 4 or 5 are typical.
*/
#define MMHEAP_SL_INDEX_COUNT_LOG2 5
/* All allocation sizes and addresses are aligned to 4 bytes. */
#define MMHEAP_ALIGN_SIZE_LOG2 2
#define MMHEAP_ALIGN_SIZE (1 << MMHEAP_ALIGN_SIZE_LOG2)
/*
* We support allocations of sizes up to (1 << MMHEAP_FL_INDEX_MAX) bits.
* However, because we linearly subdivide the second-level lists, and
* our minimum size granularity is 4 bytes, it doesn't make sense to
* create first-level lists for sizes smaller than MMHEAP_SL_INDEX_COUNT * 4,
* or (1 << (K_MMHEAP_SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be
* trying to split size ranges into more slots than we have available.
* Instead, we calculate the minimum threshold size, and place all
* blocks below that size into the 0th first-level list.
*/
#define MMHEAP_FL_INDEX_MAX 30
#define MMHEAP_SL_INDEX_COUNT (1 << MMHEAP_SL_INDEX_COUNT_LOG2)
#define MMHEAP_FL_INDEX_SHIFT (MMHEAP_SL_INDEX_COUNT_LOG2 + MMHEAP_ALIGN_SIZE_LOG2)
#define MMHEAP_FL_INDEX_COUNT (MMHEAP_FL_INDEX_MAX - MMHEAP_FL_INDEX_SHIFT + 1)
#define MMHEAP_SMALL_BLOCK_SIZE (1 << MMHEAP_FL_INDEX_SHIFT)
#define MMHEAP_BLOCK_CURR_FREE (1 << 0)
#define MMHEAP_BLOCK_PREV_FREE (1 << 1)
#define MMHEAP_BLOCK_SIZE_MASK ~(MMHEAP_BLOCK_CURR_FREE | MMHEAP_BLOCK_PREV_FREE)
#define MMHEAP_BLOCK_STATE_MASK (MMHEAP_BLOCK_CURR_FREE | MMHEAP_BLOCK_PREV_FREE)
typedef struct
{
uint32_t used; /* space is used */
uint32_t free; /* space is free */
} mmheap_info_t;
/**
* Block structure.
*
* There are several implementation subtleties involved:
* - The prev_phys_block field is only valid if the previous block is free.
* - The prev_phys_block field is actually stored at the end of the
* previous block. It appears at the beginning of this structure only to
* simplify the implementation.
* - The next_free / prev_free fields are only valid if the block is free.
*/
typedef struct mmheap_blk_st {
struct mmheap_blk_st *prev_phys_blk;
size_t size;
struct mmheap_blk_st *next_free;
struct mmheap_blk_st *prev_free;
} mmheap_blk_t;
/**
* A free block must be large enough to store its header minus the size of
* the prev_phys_block field, and no larger than the number of addressable
* bits for FL_INDEX.
*/
#define MMHEAP_BLK_SIZE_MIN (sizeof(mmheap_blk_t) - sizeof(mmheap_blk_t *))
#define MMHEAP_BLK_SIZE_MAX (1 << MMHEAP_FL_INDEX_MAX)
#define MMHEAP_BLK_HEADER_OVERHEAD (sizeof(size_t))
#define MMHEAP_BLK_START_OFFSET (((uint32_t)(uintptr_t) & (((mmheap_blk_t *)0)->size)) + sizeof(size_t))
#define MMHEAP_POOL_MAX 3
/**
* memory heap control
*/
typedef struct
{
int pool_cnt;
void *pool_start[MMHEAP_POOL_MAX];
mmheap_blk_t block_null; /**< Empty lists point at this block to indicate they are free. */
uint32_t fl_bitmap; /**< Bitmaps for free lists. */
uint32_t sl_bitmap[MMHEAP_FL_INDEX_COUNT];
mmheap_blk_t *blocks[MMHEAP_FL_INDEX_COUNT][MMHEAP_SL_INDEX_COUNT]; /**< Head of free lists. */
} mmheap_ctl_t;
/**
* @brief Add a pool.
* Add addtional pool to the heap.
*
* @attention None
*
* @param[in] pool_start start address of the pool.
* @param[in] pool_size size of the pool.
*
* @return errcode
*/
int mmheap_pool_add(void *pool_start, size_t pool_size);
/**
* @brief Alloc memory.
* Allocate size bytes and returns a pointer to the allocated memory.
*
* @attention size should no bigger than MMHEAP_BLK_SIZE_MAX.
*
* @param[in] size size of the memory.
*
* @return the pointer to the allocated memory.
*/
void *mmheap_alloc(size_t size);
void *mmheap_calloc(size_t num, size_t size);
/**
* @brief Alloc start address aligned memory from the heap.
* Alloc aligned address and specified size memory from the heap.
*
* @attention
*
* @param[in] size size of the memory.
* @param[in] align address align mask of the memory.
*
* @return the pointer to the allocated memory.
*/
void *mmheap_aligned_alloc(size_t size, size_t align);
/**
* @brief Realloc memory from the heap.
* Change the size of the memory block pointed to by ptr to size bytes.
*
* @attention
* <ul>
* <li> if ptr is NULL, then the call is equivalent to mmheap_alloc(size), for all values of size.
* <li> if ptr is if size is equal to zero, and ptr is not K_NULL, then the call is equivalent to mmheap_free(ptr).
* </ul>
*
* @param[in] ptr old pointer to the memory space.
* @param[in] size new size of the memory space.
*
* @return the new pointer to the allocated memory.
*/
void *mmheap_realloc(void *ptr, size_t size);
/**
* @brief Free the memory.
* Free the memory space pointed to by ptr, which must have been returned by a previous call to mmheap_alloc(), mmheap_aligned_alloc(), or mmheap_realloc().
*
* @attention
*
* @param[in] ptr pointer to the memory.
*
* @return None.
*/
void mmheap_free(void *ptr);
int mmheap_init_with_pool(void *pool_start, size_t pool_size);
#endif /* _DRV_MMHEAP_H_ */
/**
* @file drv_mmheap.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 __DRV_MMHEAP_H
#define __DRV_MMHEAP_H
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "bflb_platform.h"
#ifndef MMHEAP_LOCK
#define MMHEAP_LOCK()
#endif
#ifndef MMHEAP_UNLOCK
#define MMHEAP_UNLOCK()
#endif
#ifndef MMHEAP_ASSERT
#define MMHEAP_ASSERT(A) \
if (!(A)) \
bflb_platform_printf("mmheap malloc error:drv_mmheap,%d\r\n", __LINE__)
#endif
#ifndef MMHEAP_MALLOC_FAIL
#define MMHEAP_MALLOC_FAIL() bflb_platform_printf("mmheap malloc fail:drv_mmheap,%d\r\n", __LINE__)
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct heap_region {
void *addr;
size_t mem_size;
};
struct heap_node {
struct heap_node *next_node;
size_t mem_size;
};
struct heap_info {
struct heap_node *pStart;
struct heap_node *pEnd;
size_t total_size;
};
struct heap_state {
size_t remain_size;
size_t free_node_num;
size_t max_node_size;
size_t min_node_size;
};
void mmheap_init(struct heap_info *pRoot, const struct heap_region *pRigon);
/**
* @brief Alloc start address aligned memory from the heap.
* Alloc aligned address and specified size memory from the heap.
*
* @attention
*
* @param[in] pRoot heap info.
* @param[in] align_size address align mask of the memory.
* @param[in] want_size size of the memory.
*
* @return the pointer to the allocated memory.
*/
void *mmheap_align_alloc(struct heap_info *pRoot, size_t align_size, size_t want_size);
/**
* @brief Alloc memory.
* Allocate size bytes and returns a pointer to the allocated memory.
*
* @attention size should no bigger than MMHEAP_BLK_SIZE_MAX.
*
* @param[in] pRoot heap info.
* @param[in] want_size size of the memory.
*
* @return the pointer to the allocated memory.
*/
void *mmheap_alloc(struct heap_info *pRoot, size_t want_size);
/**
* @brief Realloc memory from the heap.
* Change the size of the memory block pointed to by ptr to size bytes.
*
* @attention
* <ul>
* <li> if ptr is NULL, then the call is equivalent to mmheap_alloc(size), for all values of size.
* <li> if ptr is if size is equal to zero, and ptr is not NULL, then the call is equivalent to mmheap_free(ptr).
* </ul>
*
* @param[in] pRoot heap info.
* @param[in] src_addr old pointer to the memory space.
* @param[in] want_size new size of the memory space.
*
* @return the new pointer to the allocated memory.
*/
void *mmheap_realloc(struct heap_info *pRoot, void *src_addr, size_t want_size);
/**
* @brief Free the memory.
* Free the memory space pointed to by ptr, which must have been returned by a previous call to mmheap_alloc(), mmheap_aligned_alloc(), or mmheap_realloc().
*
* @attention
*
* @param[in] pRoot heap info.
* @param[in] addr pointer to the memory.
*
* @return None.
*/
void mmheap_free(struct heap_info *pRoot, void *addr);
/**
* @brief get mmheap state
*
* @param pRoot heap info.
* @param pState heap state
*/
void mmheap_get_state(struct heap_info *pRoot, struct heap_state *pState);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,60 @@
#ifndef __COMMON_H
#define __COMMON_H
/**
* @brief Memory access macro
*/
#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; \
}
/**
* @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_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 \
{ \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
__ASM volatile("nop"); \
}
/* Std driver attribute macro*/
//#define ATTR_UNI_SYMBOL
#define ATTR_STRINGIFY(x) #x
#define ATTR_TOSTRING(x) ATTR_STRINGIFY(x)
#define ATTR_UNI_SYMBOL __FILE__ ATTR_TOSTRING(__LINE__)
#define ATTR_CLOCK_SECTION __attribute__((section(".sclock_rlt_code." ATTR_UNI_SYMBOL)))
#define ATTR_CLOCK_CONST_SECTION __attribute__((section(".sclock_rlt_const." ATTR_UNI_SYMBOL)))
#define ATTR_TCM_SECTION __attribute__((section(".tcm_code." ATTR_UNI_SYMBOL)))
#define ATTR_TCM_CONST_SECTION __attribute__((section(".tcm_const." ATTR_UNI_SYMBOL)))
#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__))
#endif

112
common/misc/compiler/gcc.h Normal file
View File

@ -0,0 +1,112 @@
#ifndef __GCC_H
#define __GCC_H
#ifndef __ORDER_BIG_ENDIAN__
#define __ORDER_BIG_ENDIAN__ (1)
#endif
#ifndef __ORDER_LITTLE_ENDIAN__
#define __ORDER_LITTLE_ENDIAN__ (2)
#endif
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
/* CPP header guards */
#ifdef __cplusplus
#define EXTERN_C_BEGIN extern "C" {
#define EXTERN_C_END }
#else
#define EXTERN_C_BEGIN
#define EXTERN_C_END
#endif
#define __MACRO_BEGIN do {
#define __MACRO_END \
} \
while (0)
#if defined(__GNUC__)
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __INLINE__
#define __INLINE__ inline
#endif
#ifndef __ALWAYS_INLINE
#define __ALWAYS_INLINE inline __attribute__((always_inline))
#endif
#ifndef __ALWAYS_STATIC_INLINE
#define __ALWAYS_STATIC_INLINE __attribute__((always_inline)) static inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __UNUSED__
#define __UNUSED__ __attribute__((__unused__))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __WEAK__
#define __WEAK__ __attribute__((weak))
#endif
#ifndef __PACKED
#define __PACKED __attribute__((packed, aligned(1)))
#endif
#ifndef __PACKED__
#define __PACKED__ __attribute__((packed))
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION union __attribute__((packed, aligned(1)))
#endif
#ifndef __IRQ
#define __IRQ __attribute__((interrupt))
#endif
#ifndef __IRQ_ALIGN64
#define __IRQ_ALIGN64 __attribute__((interrupt, aligned(64)))
#endif
#ifndef ALIGN4
#define ALIGN4 __attribute((aligned(4)))
#endif
#ifndef PACK_START
#define PACK_START
#endif
#ifndef PACK_END
#define PACK_END __attribute__((packed))
#endif
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
#ifndef __ALIGNED__
#define __ALIGNED__(x) __attribute__((aligned(x)))
#endif
#ifndef SECTION
#define SECTION(x) __attribute__((section(x)))
#endif
#ifndef __CONST__
#define __CONST__ __attribute__((__const__))
#endif
#ifndef __NAKED__
#define __NAKED__ __attribute__((naked))
#endif
#ifndef __deprecated
#define __deprecated __attribute__((deprecated))
#endif
#endif
#endif

View File

@ -1,80 +0,0 @@
/**
* @file gcc.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 _GCC_H
#define _GCC_H
/*------------------ RealView Compiler -----------------*/
#if defined(__GNUC__)
#define __ASM__ __asm
#define __VOLATILE__ volatile
#define __INLINE__ inline
#define __STATIC__ static
#define __STATIC_INLINE__ static inline
#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef likely
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
#define __UNUSED__ __attribute__((__unused__))
#define __USED__ __attribute__((__used__))
#define __PACKED__ __attribute__((packed))
#define __ALIGNED__(x) __attribute__((aligned(x)))
#define __PURE__ __attribute__((__pure__))
#define __CONST__ __attribute__((__const__))
#define __NO_RETURN__ __attribute__((__noreturn__))
#define __NAKED__ __attribute__((naked))
#define __WEAK__ __attribute__((weak))
#define SECTION(x) __attribute__((section(x)))
#define __API__ __declspec(dllexport)
#endif
#ifdef __GNUC__
#define WARN_UNUSED_RET __attribute__((warn_unused_result))
#define WEAK __attribute__((weak))
#ifndef PACK_START
#define PACK_START
#endif
#ifndef PACK_END
#define PACK_END __attribute__((packed))
#endif
#define NORETURN __attribute__((noreturn))
#else /* __GNUC__ */
#define WARN_UNUSED_RET
#define WEAK __weak
#define PACK_START __packed
#define PACK_END
#define NORETURN
#endif /* __GNUC__ */
#endif

View File

@ -33,8 +33,7 @@
* @return Destination pointer
*
*******************************************************************************/
__WEAK__
void *ATTR_TCM_SECTION arch_memcpy(void *dst, const void *src, uint32_t n)
__WEAK__ void *ATTR_TCM_SECTION arch_memcpy(void *dst, const void *src, uint32_t n)
{
const uint8_t *p = src;
uint8_t *q = dst;
@ -56,8 +55,7 @@ void *ATTR_TCM_SECTION arch_memcpy(void *dst, const void *src, uint32_t n)
* @return Destination pointer
*
*******************************************************************************/
__WEAK__
uint32_t *ATTR_TCM_SECTION arch_memcpy4(uint32_t *dst, const uint32_t *src, uint32_t n)
__WEAK__ uint32_t *ATTR_TCM_SECTION arch_memcpy4(uint32_t *dst, const uint32_t *src, uint32_t n)
{
const uint32_t *p = src;
uint32_t *q = dst;
@ -79,8 +77,7 @@ uint32_t *ATTR_TCM_SECTION arch_memcpy4(uint32_t *dst, const uint32_t *src, uint
* @return Destination pointer
*
*******************************************************************************/
__WEAK__
void *ATTR_TCM_SECTION arch_memcpy_fast(void *pdst, const void *psrc, uint32_t n)
__WEAK__ void *ATTR_TCM_SECTION arch_memcpy_fast(void *pdst, const void *psrc, uint32_t n)
{
uint32_t left, done, i = 0;
uint8_t *dst = (uint8_t *)pdst;
@ -112,8 +109,7 @@ void *ATTR_TCM_SECTION arch_memcpy_fast(void *pdst, const void *psrc, uint32_t n
* @return Destination pointer
*
*******************************************************************************/
__WEAK__
void *ATTR_TCM_SECTION arch_memset(void *s, uint8_t c, uint32_t n)
__WEAK__ void *ATTR_TCM_SECTION arch_memset(void *s, uint8_t c, uint32_t n)
{
uint8_t *p = (uint8_t *)s;
@ -134,8 +130,7 @@ void *ATTR_TCM_SECTION arch_memset(void *s, uint8_t c, uint32_t n)
* @return Destination pointer
*
*******************************************************************************/
__WEAK__
uint32_t *ATTR_TCM_SECTION arch_memset4(uint32_t *dst, const uint32_t val, uint32_t n)
__WEAK__ uint32_t *ATTR_TCM_SECTION arch_memset4(uint32_t *dst, const uint32_t val, uint32_t n)
{
uint32_t *q = dst;
@ -156,8 +151,7 @@ uint32_t *ATTR_TCM_SECTION arch_memset4(uint32_t *dst, const uint32_t val, uint3
* @return compare result
*
*******************************************************************************/
__WEAK__
int ATTR_TCM_SECTION arch_memcmp(const void *s1, const void *s2, uint32_t n)
__WEAK__ int ATTR_TCM_SECTION arch_memcmp(const void *s1, const void *s2, uint32_t n)
{
const unsigned char *c1 = s1, *c2 = s2;
int d = 0;

View File

@ -29,66 +29,8 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include "gcc.h"
#include "cmsis_compatible_gcc.h"
/*@} end of group COMMON_Public_Types */
/** @defgroup COMMON_Public_Constants
* @{
*/
/**
* @brief Memory access macro
*/
#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; \
}
/**
* @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_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(); \
}
/* 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__))
#include "compiler/gcc.h"
#include "compiler/common.h"
#ifdef BIT
#undef BIT
@ -161,12 +103,6 @@ typedef void (*pFunc)(void);
#define NULL 0
#endif
/*@} end of group COMMON_Public_Constants */
/** @defgroup COMMON_Public_Macros
* @{
*/
#define BL602_MemCpy arch_memcpy
#define BL602_MemSet arch_memset
#define BL602_MemCmp arch_memcmp
@ -181,8 +117,12 @@ typedef void (*pFunc)(void);
#define BL702_MemCpy_Fast arch_memcpy_fast
#define BL702_MemSet4 arch_memset4
#define ARCH_MemCpy arch_memcpy
#define ARCH_MemSet arch_memset
#define ARCH_MemCmp arch_memcmp
#define ARCH_MemCpy4 arch_memcpy4
#define ARCH_MemCpy_Fast arch_memcpy_fast
#define ARCH_MemSet4 arch_memset4
/**
* @brief Null Type definition
*/
@ -190,12 +130,6 @@ typedef void (*pFunc)(void);
#define NULL 0
#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);
@ -204,7 +138,4 @@ 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);
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);
/*@} end of group DRIVER_COMMON */
#endif /* __BL602_COMMON_H__ */
#endif