mcu_hi3321_watch/middleware/utils/update/common/upg_alloc.c
2025-05-26 20:15:20 +08:00

42 lines
998 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) @CompanyNameMagicTag 2021-2021. All rights reserved.
* Description: UPG alloc memory functions source file
*/
#include <stddef.h>
#include <stdint.h>
#include "common_def.h"
#include "upg_common.h"
#include "upg_porting.h"
#include "upg_alloc.h"
STATIC bool upg_is_flash_addr(const void *addr)
{
uintptr_t start_addr = upg_get_flash_base_addr();
uintptr_t end_addr = start_addr + upg_get_flash_size();
if (start_addr <= (uintptr_t)(addr) && (uintptr_t)(addr) < end_addr) {
return true;
}
return false;
}
void *upg_malloc(uint32_t size)
{
if (upg_get_func_list()->malloc != NULL) {
return upg_get_func_list()->malloc(size);
}
return NULL;
}
void upg_free(void *addr)
{
if (addr == NULL || upg_is_flash_addr(addr)) { /* 使用总线方式直接读取时flash地址不需要释放 */
return;
}
if (upg_get_func_list()->free != NULL) {
return upg_get_func_list()->free(addr);
}
return;
}