initial commit
This commit is contained in:
commit
cff2a21efc
550 files changed
+154887
No files matched your search
@@ -0,0 +1,97 @@
|
||||
#include "../../lv_conf_internal.h"
|
||||
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
||||
|
||||
#ifndef LV_TLSF_H
|
||||
#define LV_TLSF_H
|
||||
|
||||
/*
|
||||
** Two Level Segregated Fit memory allocator, version 3.1.
|
||||
** Written by Matthew Conte
|
||||
** http://tlsf.baisoku.org
|
||||
**
|
||||
** Based on the original documentation by Miguel Masmano:
|
||||
** http://www.gii.upv.es/tlsf/main/docs
|
||||
**
|
||||
** This implementation was written to the specification
|
||||
** of the document, therefore no GPL restrictions apply.
|
||||
**
|
||||
** Copyright (c) 2006-2016, Matthew Conte
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** * Neither the name of the copyright holder nor the
|
||||
** names of its contributors may be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
|
||||
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../../osal/lv_os.h"
|
||||
#include "../../misc/lv_ll.h"
|
||||
#include "../../misc/lv_types.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* lv_tlsf_t: a TLSF structure. Can contain 1 to N pools. */
|
||||
/* lv_pool_t: a block of memory that TLSF can manage. */
|
||||
typedef void * lv_tlsf_t;
|
||||
typedef void * lv_pool_t;
|
||||
|
||||
/* Create/destroy a memory pool. */
|
||||
lv_tlsf_t lv_tlsf_create(void * mem);
|
||||
lv_tlsf_t lv_tlsf_create_with_pool(void * mem, size_t bytes);
|
||||
void lv_tlsf_destroy(lv_tlsf_t tlsf);
|
||||
lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf);
|
||||
|
||||
/* Add/remove memory pools. */
|
||||
lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void * mem, size_t bytes);
|
||||
void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool);
|
||||
|
||||
/* malloc/memalign/realloc/free replacements. */
|
||||
void * lv_tlsf_malloc(lv_tlsf_t tlsf, size_t bytes);
|
||||
void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t bytes);
|
||||
void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size);
|
||||
size_t lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr);
|
||||
|
||||
/* Returns internal block size, not original request size */
|
||||
size_t lv_tlsf_block_size(void * ptr);
|
||||
|
||||
/* Overheads/limits of internal structures. */
|
||||
size_t lv_tlsf_size(void);
|
||||
size_t lv_tlsf_align_size(void);
|
||||
size_t lv_tlsf_block_size_min(void);
|
||||
size_t lv_tlsf_block_size_max(void);
|
||||
size_t lv_tlsf_pool_overhead(void);
|
||||
size_t lv_tlsf_alloc_overhead(void);
|
||||
|
||||
/* Debugging. */
|
||||
typedef void (*lv_tlsf_walker)(void * ptr, size_t size, int used, void * user);
|
||||
void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void * user);
|
||||
/* Returns nonzero if any internal consistency check fails. */
|
||||
int lv_tlsf_check(lv_tlsf_t tlsf);
|
||||
int lv_tlsf_check_pool(lv_pool_t pool);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /*LV_TLSF_H*/
|
||||
|
||||
#endif /*LV_STDLIB_BUILTIN*/
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @file lv_tlsf_private.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_TLSF_PRIVATE_H
|
||||
#define LV_TLSF_PRIVATE_H
|
||||
|
||||
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include "lv_tlsf.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef struct {
|
||||
#if LV_USE_OS
|
||||
lv_mutex_t mutex;
|
||||
#endif
|
||||
lv_tlsf_t tlsf;
|
||||
size_t cur_used;
|
||||
size_t max_used;
|
||||
lv_ll_t pool_ll;
|
||||
} lv_tlsf_state_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN*/
|
||||
|
||||
#endif /*LV_TLSF_PRIVATE_H*/
|
||||
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* @file lv_mem.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_MEM_H
|
||||
#define LV_MEM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../lv_conf_internal.h"
|
||||
|
||||
#include "lv_string.h"
|
||||
|
||||
#include "../misc/lv_types.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef void * lv_mem_pool_t;
|
||||
|
||||
/**
|
||||
* Heap information structure.
|
||||
*/
|
||||
typedef struct {
|
||||
size_t total_size; /**< Total heap size */
|
||||
size_t free_cnt;
|
||||
size_t free_size; /**< Size of available memory */
|
||||
size_t free_biggest_size;
|
||||
size_t used_cnt;
|
||||
size_t max_used; /**< Max size of Heap memory used */
|
||||
uint8_t used_pct; /**< Percentage used */
|
||||
uint8_t frag_pct; /**< Amount of fragmentation */
|
||||
} lv_mem_monitor_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize to use malloc/free/realloc etc
|
||||
*/
|
||||
void lv_mem_init(void);
|
||||
|
||||
/**
|
||||
* Drop all dynamically allocated memory and reset the memory pools' state
|
||||
*/
|
||||
void lv_mem_deinit(void);
|
||||
|
||||
lv_mem_pool_t lv_mem_add_pool(void * mem, size_t bytes);
|
||||
|
||||
void lv_mem_remove_pool(lv_mem_pool_t pool);
|
||||
|
||||
/**
|
||||
* Allocate memory dynamically
|
||||
* @param size requested size in bytes
|
||||
* @return pointer to allocated uninitialized memory, or NULL on failure
|
||||
*/
|
||||
void * lv_malloc(size_t size);
|
||||
|
||||
/**
|
||||
* Allocate a block of zeroed memory dynamically
|
||||
* @param num requested number of element to be allocated.
|
||||
* @param size requested size of each element in bytes.
|
||||
* @return pointer to allocated zeroed memory, or NULL on failure
|
||||
*/
|
||||
void * lv_calloc(size_t num, size_t size);
|
||||
|
||||
/**
|
||||
* Allocate zeroed memory dynamically
|
||||
* @param size requested size in bytes
|
||||
* @return pointer to allocated zeroed memory, or NULL on failure
|
||||
*/
|
||||
void * lv_zalloc(size_t size);
|
||||
|
||||
/**
|
||||
* Allocate zeroed memory dynamically
|
||||
* @param size requested size in bytes
|
||||
* @return pointer to allocated zeroed memory, or NULL on failure
|
||||
*/
|
||||
void * lv_malloc_zeroed(size_t size);
|
||||
|
||||
/**
|
||||
* Free an allocated data
|
||||
* @param data pointer to an allocated memory
|
||||
*/
|
||||
void lv_free(void * data);
|
||||
|
||||
/**
|
||||
* Reallocate a memory with a new size. The old content will be kept.
|
||||
* @param data_p pointer to an allocated memory.
|
||||
* Its content will be copied to the new memory block and freed
|
||||
* @param new_size the desired new size in byte
|
||||
* @return pointer to the new memory, NULL on failure
|
||||
*/
|
||||
void * lv_realloc(void * data_p, size_t new_size);
|
||||
|
||||
/**
|
||||
* Used internally to execute a plain `malloc` operation
|
||||
* @param size size in bytes to `malloc`
|
||||
*/
|
||||
void * lv_malloc_core(size_t size);
|
||||
|
||||
/**
|
||||
* Used internally to execute a plain `free` operation
|
||||
* @param p memory address to free
|
||||
*/
|
||||
void lv_free_core(void * p);
|
||||
|
||||
/**
|
||||
* Used internally to execute a plain realloc operation
|
||||
* @param p memory address to realloc
|
||||
* @param new_size size in bytes to realloc
|
||||
*/
|
||||
void * lv_realloc_core(void * p, size_t new_size);
|
||||
|
||||
/**
|
||||
* Used internally by lv_mem_monitor() to gather LVGL heap state information.
|
||||
* @param mon_p pointer to lv_mem_monitor_t object to be populated.
|
||||
*/
|
||||
void lv_mem_monitor_core(lv_mem_monitor_t * mon_p);
|
||||
|
||||
lv_result_t lv_mem_test_core(void);
|
||||
|
||||
/**
|
||||
* @brief Tests the memory allocation system by allocating and freeing a block of memory.
|
||||
* @return LV_RESULT_OK if the memory allocation system is working properly, or LV_RESULT_INVALID if there is an error.
|
||||
*/
|
||||
lv_result_t lv_mem_test(void);
|
||||
|
||||
/**
|
||||
* Give information about the work memory of dynamic allocation
|
||||
* @param mon_p pointer to a lv_mem_monitor_t variable,
|
||||
* the result of the analysis will be stored here
|
||||
*/
|
||||
void lv_mem_monitor(lv_mem_monitor_t * mon_p);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_MEM_H*/
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @file lv_mem_private.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_MEM_PRIVATE_H
|
||||
#define LV_MEM_PRIVATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include "lv_mem.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_MEM_PRIVATE_H*/
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @file lv_sprintf.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_SPRINTF_H
|
||||
#define LV_SPRINTF_H
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include(LV_INTTYPES_INCLUDE)
|
||||
#include LV_INTTYPES_INCLUDE
|
||||
/* platform-specific printf format for int32_t, usually "d" or "ld" */
|
||||
#define LV_PRId32 PRId32
|
||||
#define LV_PRIu32 PRIu32
|
||||
#define LV_PRIx32 PRIx32
|
||||
#define LV_PRIX32 PRIX32
|
||||
#else
|
||||
#define LV_PRId32 "d"
|
||||
#define LV_PRIu32 "u"
|
||||
#define LV_PRIx32 "x"
|
||||
#define LV_PRIX32 "X"
|
||||
#endif
|
||||
#else
|
||||
/* hope this is correct for ports without __has_include or without inttypes.h */
|
||||
#define LV_PRId32 "d"
|
||||
#define LV_PRIu32 "u"
|
||||
#define LV_PRIx32 "x"
|
||||
#define LV_PRIX32 "X"
|
||||
#endif
|
||||
|
||||
#include "../misc/lv_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int lv_snprintf(char * buffer, size_t count, const char * format, ...);
|
||||
|
||||
int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /* LV_SPRINTF_H */
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* @file lv_string.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_STRING_H
|
||||
#define LV_STRING_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../lv_conf_internal.h"
|
||||
#include "../misc/lv_types.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* @brief Copies a block of memory from a source address to a destination address.
|
||||
* @param dst Pointer to the destination array where the content is to be copied.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @param len Number of bytes to copy.
|
||||
* @return Pointer to the destination array.
|
||||
* @note The function does not check for any overlapping of the source and destination memory blocks.
|
||||
*/
|
||||
void * lv_memcpy(void * dst, const void * src, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Fills a block of memory with a specified value.
|
||||
* @param dst Pointer to the destination array to fill with the specified value.
|
||||
* @param v Value to be set. The value is passed as an int, but the function fills
|
||||
* the block of memory using the unsigned char conversion of this value.
|
||||
* @param len Number of bytes to be set to the value.
|
||||
*/
|
||||
void lv_memset(void * dst, uint8_t v, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Move a block of memory from source to destination
|
||||
* @param dst Pointer to the destination array where the content is to be copied.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @param len Number of bytes to copy
|
||||
* @return Pointer to the destination array.
|
||||
*/
|
||||
void * lv_memmove(void * dst, const void * src, size_t len);
|
||||
|
||||
/**
|
||||
* @brief This function will compare two memory blocks
|
||||
* @param p1 Pointer to the first memory block
|
||||
* @param p2 Pointer to the second memory block
|
||||
* @param len Number of bytes to compare
|
||||
* @return The difference between the value of the first unmatching byte.
|
||||
*/
|
||||
int lv_memcmp(const void * p1, const void * p2, size_t len);
|
||||
|
||||
/**
|
||||
* Same as `memset(dst, 0x00, len)`.
|
||||
* @param dst pointer to the destination buffer
|
||||
* @param len number of byte to set
|
||||
*/
|
||||
static inline void lv_memzero(void * dst, size_t len)
|
||||
{
|
||||
lv_memset(dst, 0x00, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the length of the string str up to, but not including the terminating null character.
|
||||
* @param str Pointer to the null-terminated byte string to be examined.
|
||||
* @return The length of the string in bytes.
|
||||
*/
|
||||
size_t lv_strlen(const char * str);
|
||||
|
||||
/**
|
||||
* @brief Copies up to dst_size-1 (non-null) characters from src to dst. A null terminator is always added.
|
||||
* @param dst Pointer to the destination array where the content is to be copied.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @param dst_size Maximum number of characters to be copied to dst, including the null character.
|
||||
* @return The length of src. The return value is equivalent to the value returned by lv_strlen(src)
|
||||
*/
|
||||
size_t lv_strlcpy(char * dst, const char * src, size_t dst_size);
|
||||
|
||||
/**
|
||||
* @brief Copies up to dest_size characters from the string pointed to by src to the character array pointed to by dst
|
||||
* and fills the remaining length with null bytes.
|
||||
* @param dst Pointer to the destination array where the content is to be copied.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @param dest_size Maximum number of characters to be copied to dst.
|
||||
* @return A pointer to the destination array, which is dst.
|
||||
* @note dst will not be null terminated if dest_size bytes were copied from src before the end of src was reached.
|
||||
*/
|
||||
char * lv_strncpy(char * dst, const char * src, size_t dest_size);
|
||||
|
||||
/**
|
||||
* @brief Copies the string pointed to by src, including the terminating null character,
|
||||
* to the character array pointed to by dst.
|
||||
* @param dst Pointer to the destination array where the content is to be copied.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @return A pointer to the destination array, which is dst.
|
||||
*/
|
||||
char * lv_strcpy(char * dst, const char * src);
|
||||
|
||||
/**
|
||||
* @brief This function will compare two strings without specified length.
|
||||
* @param s1 pointer to the first string
|
||||
* @param s2 pointer to the second string
|
||||
* @return the difference between the value of the first unmatching character.
|
||||
*/
|
||||
int lv_strcmp(const char * s1, const char * s2);
|
||||
|
||||
/**
|
||||
* @brief Duplicate a string by allocating a new one and copying the content.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @return A pointer to the new allocated string. NULL if failed.
|
||||
*/
|
||||
char * lv_strdup(const char * src);
|
||||
|
||||
/**
|
||||
* @brief Copies the string pointed to by src, including the terminating null character,
|
||||
* to the end of the string pointed to by dst.
|
||||
* @param dst Pointer to the destination string where the content is to be appended.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @return A pointer to the destination string, which is dst.
|
||||
*/
|
||||
char * lv_strcat(char * dst, const char * src);
|
||||
|
||||
/**
|
||||
* @brief Copies up to src_len characters from the string pointed to by src
|
||||
* to the end of the string pointed to by dst.
|
||||
* A terminating null character is appended to dst even if no null character
|
||||
* was encountered in src after src_len characters were copied.
|
||||
* @param dst Pointer to the destination string where the content is to be appended.
|
||||
* @param src Pointer to the source of data to be copied.
|
||||
* @param src_len Maximum number of characters from src to be copied to the end of dst.
|
||||
* @return A pointer to the destination string, which is dst.
|
||||
*/
|
||||
char * lv_strncat(char * dst, const char * src, size_t src_len);
|
||||
|
||||
/**
|
||||
* @brief Searches for the first occurrence of character c in the string str.
|
||||
* @param str Pointer to the null-terminated byte string to be searched.
|
||||
* @param c The character to be searched for.
|
||||
* @return A pointer to the first occurrence of character c in the string str, or a null pointer if c is not found.
|
||||
*/
|
||||
char * lv_strchr(const char * str, int c);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_STRING_H*/
|
||||
Reference in new issue
Block a user