79 lines
2.7 KiB
C
79 lines
2.7 KiB
C
/**
|
|
******************************************************************************
|
|
* @file malloc.h
|
|
* @author AMG Energy Solution Team
|
|
* @version V1.0.0
|
|
* @date 07-Feb-2022
|
|
* @brief This file provides code for the configuration of
|
|
* the memory heap instances.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
|
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
|
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
|
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
|
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
|
*
|
|
* <h2><center>© COPYRIGHT 2022 AMG</center></h2>
|
|
******************************************************************************
|
|
*/
|
|
|
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
#ifndef __malloc_H
|
|
#define __malloc_H
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "hc32_ddl.h"
|
|
|
|
#ifndef NULL
|
|
#define NULL 0
|
|
#endif
|
|
|
|
// Define three memory pools
|
|
#define MEM_BLOCK_SIZE 32 // Block size is 32 bytes
|
|
#define MEM_MAX_SIZE (20 * 1024) // Maximum memory management 20k
|
|
#define MEM_ALLOC_TABLE_SIZE (MEM_MAX_SIZE / MEM_BLOCK_SIZE) // Memory table size
|
|
|
|
//Memory management controller
|
|
struct _m_mallco_dev
|
|
{
|
|
void (*init)(void); // Initialize
|
|
uint8_t (*perused)(void); // Memory usage
|
|
uint8_t *membase; // Memory pool management SRAMBANK a region of memory
|
|
uint16_t *memmap; // Memory status table
|
|
uint8_t memrdy; // Memory management is ready to
|
|
};
|
|
extern struct _m_mallco_dev mallco_dev; //Defined in malloc.c
|
|
|
|
void mymemset(void *s,uint8_t c,uint32_t count); // Setting memory
|
|
void mymemcpy(void *des,void *src,uint32_t n); // Copy memory
|
|
void mymem_init(void); // Memory initialization function (external/internal calls)
|
|
uint8_t mem_perused(void); // For memory usage (external/internal calls)
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
//Users call a function
|
|
void myfree(void *ptr); // Memory release (external call)
|
|
void *mymalloc(uint32_t size); // Memory allocation (external call)
|
|
void *myrealloc(void *ptr, uint32_t size); // Reallocating memory (external call)
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif /*__ brtc_H */
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/*******************(C)COPYRIGHT 2022 AMG ********************END OF FILE******/
|
|
|
|
|