1.内存管理适配更多标准API。
This commit is contained in:
@@ -16,15 +16,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup Memory.
|
||||
* @{
|
||||
*/
|
||||
int mr_heap_init(void);
|
||||
void *mr_malloc(size_t size);
|
||||
void mr_free(void *memory);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @addtogroup Interrupt.
|
||||
*/
|
||||
@@ -40,43 +31,29 @@ void mr_delay_ms(uint32_t ms);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @addtogroup Initialization.
|
||||
* @addtogroup Memory.
|
||||
* @{
|
||||
*/
|
||||
void mr_auto_init(void);
|
||||
int mr_heap_init(void);
|
||||
void *mr_malloc(size_t size);
|
||||
void mr_free(void *memory);
|
||||
size_t mr_malloc_usable_size(void *memory);
|
||||
void *mr_calloc(size_t num, size_t size);
|
||||
void *mr_realloc(void *memory, size_t size);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @addtogroup Printf.
|
||||
* @{
|
||||
*/
|
||||
int mr_printf_output(const char *buf, size_t size);
|
||||
int mr_printf(const char *fmt, ...);
|
||||
const char *mr_strerror(int err);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @addtogroup Device.
|
||||
* @{
|
||||
*/
|
||||
int mr_dev_register(struct mr_dev *dev,
|
||||
const char *name,
|
||||
int type,
|
||||
int sflags,
|
||||
struct mr_dev_ops *ops,
|
||||
struct mr_drv *drv);
|
||||
int mr_dev_isr(struct mr_dev *dev, int event, void *args);
|
||||
int mr_dev_get_full_name(struct mr_dev *dev, char *buf, size_t bufsz);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @addtogroup Device description.
|
||||
* @{
|
||||
* @addtogroup Initialization.
|
||||
*/
|
||||
int mr_dev_open(const char *name, int oflags);
|
||||
int mr_dev_close(int desc);
|
||||
ssize_t mr_dev_read(int desc, void *buf, size_t size);
|
||||
ssize_t mr_dev_write(int desc, const void *buf, size_t size);
|
||||
int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
void mr_auto_init(void);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
@@ -109,6 +86,31 @@ struct mr_avl *mr_avl_find(struct mr_avl *tree, uint32_t value);
|
||||
size_t mr_avl_get_length(struct mr_avl *tree);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @addtogroup Device.
|
||||
* @{
|
||||
*/
|
||||
int mr_dev_register(struct mr_dev *dev,
|
||||
const char *name,
|
||||
int type,
|
||||
int sflags,
|
||||
struct mr_dev_ops *ops,
|
||||
struct mr_drv *drv);
|
||||
int mr_dev_isr(struct mr_dev *dev, int event, void *args);
|
||||
int mr_dev_get_full_name(struct mr_dev *dev, char *buf, size_t bufsz);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @addtogroup Device description.
|
||||
* @{
|
||||
*/
|
||||
int mr_dev_open(const char *name, int oflags);
|
||||
int mr_dev_close(int desc);
|
||||
ssize_t mr_dev_read(int desc, void *buf, size_t size);
|
||||
ssize_t mr_dev_write(int desc, const void *buf, size_t size);
|
||||
int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -115,7 +115,7 @@ extern "C" {
|
||||
*
|
||||
* @return The maximum of the two values.
|
||||
*/
|
||||
#define mr_max(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
|
||||
#define mr_max(a, b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
|
||||
|
||||
/**
|
||||
* @brief This macro function gets the minimum of two values.
|
||||
@@ -125,7 +125,31 @@ extern "C" {
|
||||
*
|
||||
* @return The minimum of the two values.
|
||||
*/
|
||||
#define mr_min(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
|
||||
#define mr_min(a, b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
|
||||
|
||||
/**
|
||||
* @brief This macro function ensures that a value is within a specified range.
|
||||
*
|
||||
* @param value The value.
|
||||
* @param min The minimum value.
|
||||
* @param max The maximum value.
|
||||
*
|
||||
* @return The value within the specified range.
|
||||
*/
|
||||
#define mr_bound(value, min, max) \
|
||||
({__typeof__(value) _value = (value); __typeof__(min) _min = (min); __typeof__(max) _max = (max); \
|
||||
(_value) < (_min) ? (_min) : ((_value) > (_max) ? (_max) : (_value));})
|
||||
|
||||
/**
|
||||
* @brief This macro function ensures that a value is within a specified range.
|
||||
*
|
||||
* @param value The value.
|
||||
* @param min The minimum value.
|
||||
* @param max The maximum value.
|
||||
*
|
||||
* @return The value within the specified range.
|
||||
*/
|
||||
#define mr_limit(value, min, max) mr_bound(value, min, max)
|
||||
|
||||
/**
|
||||
* @brief This macro function swaps two values.
|
||||
@@ -133,7 +157,7 @@ extern "C" {
|
||||
* @param a The first value.
|
||||
* @param b The second value.
|
||||
*/
|
||||
#define mr_swap(a, b) do { typeof(a) temp = a; a = b; b = temp; } while (0)
|
||||
#define mr_swap(a, b) do { typeof (a) temp = a; a = b; b = temp; } while (0)
|
||||
|
||||
/**
|
||||
* @brief This macro function aligns the size up to a multiple of 4.
|
||||
@@ -149,6 +173,25 @@ extern "C" {
|
||||
*/
|
||||
#define mr_align4_down(size) ((size) & (~3))
|
||||
|
||||
/**
|
||||
* @brief This macro function concatenates two strings.
|
||||
*
|
||||
* @param a The first string.
|
||||
* @param b The second string.
|
||||
*
|
||||
* @return The concatenated string.
|
||||
*/
|
||||
#define MR_CONCAT(a, b) a##b
|
||||
|
||||
/**
|
||||
* @brief This macro function converts an integer to a string.
|
||||
*
|
||||
* @param a The integer to convert.
|
||||
*
|
||||
* @return The string representation of the integer.
|
||||
*/
|
||||
#define MR_STR(a) #a
|
||||
|
||||
/**
|
||||
* @brief This macro function checks if a list is empty.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user