fix(entry,hook,atomic): Optimize warnings under different compilers.

1.Optimize keil entry points.
2.Modify the detection mode of atomic operations.
3.Optimize type conversion warnings.
This commit is contained in:
MacRsh
2025-04-10 00:33:43 +08:00
parent 707f7c58b7
commit 20a1e71d04
16 changed files with 85 additions and 119 deletions

View File

@@ -32,8 +32,8 @@ typedef struct mr_initcall {
/**
* @brief This macro function defines an initcall.
*
* @param _entry The function of the initcall.
* @param _level The level of the initcall.
* @param _entry The initcall function.
* @param _level The initcall level.
*/
#define MR_INIT_EXPORT(_entry, _level) \
MR_USED const mr_initcall_t __mr_initcall_##_entry MR_SECTION( \

View File

@@ -32,7 +32,7 @@ typedef struct mr_khook {
* @brief This macro function initializes a hook.
*
* @param _entry The hook entry.
* @param _size The size of the entry pointers.
* @param _size The entry size.
*/
#define MR_KHOOK_INIT(_entry, _size) \
{.entry = (_entry), .size = (_size), .next = 0}
@@ -42,9 +42,9 @@ typedef struct mr_khook {
*
* @param khook The khook.
* @param entry The entry pointers.
* @param size The size of the entry pointers.
* @param size The entry size.
*
* @note The size is the number of the entry pointers.
* @note The size is the entry number.
*/
void mr_khook_init(mr_khook_t *khook, mr_ptr_t *entry, mr_size_t size);
@@ -62,11 +62,12 @@ mr_err_t mr_khook_add(mr_khook_t *khook, mr_ptr_t entry);
*
* @param _i The index.
* @param _entry The entry.
* @param _hook The hook.
* @param _type The entry type.
* @param _hook The entry hook.
*/
#define MR_KHOOK_EACH(_i, _entry, _hook) \
for ((_i) = 0, (_entry) = (_hook)->entry[(_i)]; (_i) < (_hook)->next; \
(_i)++, (_entry) = (_hook)->entry[(_i)])
#define MR_KHOOK_EACH(_i, _entry, _type, _hook) \
for ((_i) = 0, (_entry) = (_type)(_hook)->entry[(_i)]; \
(_i) < (_hook)->next; (_i)++, (_entry) = (_type)(_hook)->entry[(_i)])
/** @} */

View File

@@ -144,10 +144,10 @@ MR_INLINE mr_bool_t mr_klist_is_empty(mr_klist_t *head) {
/**
* @brief This macro function gets the container of an element.
*
* @param _ptr The pointer to the element.
* @param _type The type of the element.
* @param _member The member of the element.
* @return The container of the element.
* @param _ptr The element pointer.
* @param _type The element type.
* @param _member The element member.
* @return The element container.
*/
#define MR_KLIST_ENTRY(_ptr, _type, _member) \
MR_CONTAINER_OF(_ptr, _type, _member)

View File

@@ -197,13 +197,12 @@ void mr_kobject_put(mr_kobject_t *kobj);
* @brief This function gets the value of an attribute.
*
* @param kobj The kobject.
* @param name The name of the attribute.
* @param buf The buffer to store the value.
* @param size The size of the buffer.
* @return The length of the value on success, a negative error code on
* failure.
* @param name The attribute name.
* @param buf The output buffer.
* @param size The buffer size.
* @return The value length on success, a negative error code on failure.
*
* @note Set buf to MR_NULL to get the length of the value.
* @note Set buf to MR_NULL to get the value length.
*/
mr_ssize_t mr_kobject_attr_show(mr_kobject_t *kobj, const char *name, char *buf,
mr_size_t size);
@@ -212,13 +211,12 @@ mr_ssize_t mr_kobject_attr_show(mr_kobject_t *kobj, const char *name, char *buf,
* @brief This function sets the value of an attribute.
*
* @param kobj The kobject.
* @param name The name of the attribute.
* @param buf The buffer to store the value.
* @param size The size of the buffer.
* @return The length of the value on success, a negative error code on
* failure.
* @param name The attribute name.
* @param buf The input buffer.
* @param size The buffer size.
* @return The value length on success, a negative error code on failure.
*
* @note Set buf to MR_NULL to get the length of the value.
* @note Set buf to MR_NULL to get the value length.
*/
mr_ssize_t mr_kobject_attr_store(mr_kobject_t *kobj, const char *name,
const char *buf, mr_size_t size);
@@ -227,7 +225,7 @@ mr_ssize_t mr_kobject_attr_store(mr_kobject_t *kobj, const char *name,
* @brief This macro function gets the name of a kobject.
*
* @param _kobj The kobject.
* @return The name of the kobject.
* @return The kobject name on success, MR_NULL on failure.
*/
#define MR_KOBJECT_NAME(_kobj) (((mr_kobject_t *)(_kobj))->name.str)
@@ -235,7 +233,7 @@ mr_ssize_t mr_kobject_attr_store(mr_kobject_t *kobj, const char *name,
* @brief This macro function gets the length of a kobject name.
*
* @param _kobj The kobject.
* @return The length of the kobject name.
* @return The name length on success, 0 on failure.
*
* @note The name length includes the null terminator('\0').
*/

View File

@@ -21,10 +21,10 @@ extern "C" {
/**
* @brief This macro function gets the container of a member.
*
* @param _ptr The pointer to the member.
* @param _type The type of the container.
* @param _member The member of the container.
* @return The container of the member.
* @param _ptr The member pointer.
* @param _type The container type.
* @param _member The member.
* @return The member container.
*/
#define MR_CONTAINER_OF(_ptr, _type, _member) \
((void *)((char *)(_ptr) - (char *)((void *)&(((_type *)0)->_member))))
@@ -33,58 +33,15 @@ extern "C" {
* @brief This macro function gets the size of an array.
*
* @param _array The array.
* @return The size of the array.
* @return The array size.
*/
#define MR_ARRAY_SIZE(_array) (sizeof(_array) / sizeof((_array)[0]))
/**
* @brief This macro function aligns a value upward.
*
* @param _val The value.
* @param _ali The alignment.
* @return The aligned value.
*/
#define MR_ALIGN_UP(_val, _ali) (((_val) + (_ali) - 1) & ~((_ali) - 1))
/**
* @brief This macro function aligns a value downward.
*
* @param _val The value.
* @param _ali The alignment.
* @return The aligned value.
*/
#define MR_ALIGN_DOWN(_val, _ali) ((_val) & ~((_ali) - 1))
/**
* @brief This macro function checks if a bit is set.
*
* @param _val The value.
* @param _mask The mask.
* @return MR_TRUE if the bit is set, MR_FALSE otherwise.
*/
#define MR_BIT_IS_SET(_val, _mask) (((_val) & (_mask)) == (_mask))
/**
* @brief This macro function sets a bit.
*
* @param _val The value.
* @param _mask The mask.
*/
#define MR_BIT_SET(_val, _mask) ((_val) |= (_mask))
/**
* @brief This macro function clear a bit.
*
* @param _val The value.
* @param _mask The mask.
*/
#define MR_BIT_CLR(_val, _mask) ((_val) &= ~(_mask))
/**
* @brief This macro function makes a local variable.
*
* @param _type The type of the local variable.
* @param ... The arguments of the local variable.
* @param _type The local variable type.
* @param ... The local variable value.
*/
#define MR_MAKE_LOCAL(_type, ...) (&((_type){__VA_ARGS__}))

View File

@@ -113,7 +113,7 @@ mr_err_t mr_ktimer_tick_set(mr_ktimer_t *ktimer, mr_tick_t tick);
* @brief This macro function gets the tick of a ktimer.
*
* @param ktimer The ktimer.
* @return The tick of the ktimer.
* @return The ktimer tick.
*/
#define MR_KTIMER_TICK(_ktimer) (((mr_ktimer_t *)(_ktimer))->init_tick)

View File

@@ -15,9 +15,9 @@
#else
#include <libc/mr_compiler.h>
#include <libc/mr_types.h>
#if !defined(__GNUC__) && !defined(__clang__)
#if !defined(__ATOMIC_SEQ_CST)
#include <port/mr_port_irq.h>
#endif /* !defined(__GNUC__) && !defined(__clang__) */
#endif /* !defined(__ATOMIC_SEQ_CST) */
#endif /* defined(MR_USE_3PARTY_ATOMIC) */
#ifdef __cplusplus
@@ -39,7 +39,7 @@ typedef int mr_atomic_t;
/**
* @brief This macro function initializes an atomic.
*
* @param _val The initial value of the atomic.
* @param _val The atomic initial value.
*/
#define MR_ATOMIC_INIT(_val) (_val)
@@ -63,14 +63,14 @@ MR_INLINE mr_atomic_t mr_atomic_load(volatile mr_atomic_t *atomic) {
mr_atomic_t tmp;
int mask;
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ATOMIC_SEQ_CST)
MR_UNUSED(mask);
tmp = __atomic_load_n(atomic, __ATOMIC_SEQ_CST);
#else
mask = mr_port_irq_save();
tmp = *atomic;
mr_port_irq_restore(mask);
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(__ATOMIC_SEQ_CST) */
return tmp;
}
@@ -83,14 +83,14 @@ MR_INLINE mr_atomic_t mr_atomic_load(volatile mr_atomic_t *atomic) {
MR_INLINE void mr_atomic_store(volatile mr_atomic_t *atomic, mr_atomic_t val) {
int mask;
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ATOMIC_SEQ_CST)
MR_UNUSED(mask);
__atomic_store_n(atomic, val, __ATOMIC_SEQ_CST);
#else
mask = mr_port_irq_save();
*atomic = val;
mr_port_irq_restore(mask);
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(__ATOMIC_SEQ_CST) */
}
/**
@@ -105,7 +105,7 @@ MR_INLINE mr_atomic_t mr_atomic_exchange(volatile mr_atomic_t *atomic,
mr_atomic_t tmp;
int mask;
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ATOMIC_SEQ_CST)
MR_UNUSED(mask);
tmp = __atomic_exchange_n(atomic, val, __ATOMIC_SEQ_CST);
#else
@@ -113,7 +113,7 @@ MR_INLINE mr_atomic_t mr_atomic_exchange(volatile mr_atomic_t *atomic,
tmp = *atomic;
*atomic = val;
mr_port_irq_restore(mask);
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(__ATOMIC_SEQ_CST) */
return tmp;
}
@@ -130,7 +130,7 @@ MR_INLINE mr_bool_t mr_atomic_compare_exchange(volatile mr_atomic_t *atomic,
mr_atomic_t new_val) {
int mask;
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ATOMIC_SEQ_CST)
MR_UNUSED(mask);
return __atomic_compare_exchange_n(atomic, old_val, new_val, MR_FALSE,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
@@ -143,7 +143,7 @@ MR_INLINE mr_bool_t mr_atomic_compare_exchange(volatile mr_atomic_t *atomic,
*atomic = new_val;
mr_port_irq_restore(mask);
return MR_TRUE;
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(__ATOMIC_SEQ_CST) */
}
/**
@@ -158,7 +158,7 @@ MR_INLINE mr_atomic_t mr_atomic_fetch_add(volatile mr_atomic_t *atomic,
mr_atomic_t tmp;
int mask;
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ATOMIC_SEQ_CST)
MR_UNUSED(mask);
tmp = __atomic_fetch_add(atomic, val, __ATOMIC_SEQ_CST);
#else
@@ -166,7 +166,7 @@ MR_INLINE mr_atomic_t mr_atomic_fetch_add(volatile mr_atomic_t *atomic,
tmp = *atomic;
*atomic += val;
mr_port_irq_restore(mask);
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(__ATOMIC_SEQ_CST) */
return tmp;
}
@@ -182,7 +182,7 @@ MR_INLINE mr_atomic_t mr_atomic_fetch_sub(volatile mr_atomic_t *atomic,
mr_atomic_t tmp;
int mask;
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ATOMIC_SEQ_CST)
MR_UNUSED(mask);
tmp = __atomic_fetch_sub(atomic, val, __ATOMIC_SEQ_CST);
#else
@@ -190,7 +190,7 @@ MR_INLINE mr_atomic_t mr_atomic_fetch_sub(volatile mr_atomic_t *atomic,
tmp = *atomic;
*atomic -= val;
mr_port_irq_restore(mask);
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(__ATOMIC_SEQ_CST) */
return tmp;
}
@@ -206,7 +206,7 @@ MR_INLINE mr_atomic_t mr_atomic_fetch_and(volatile mr_atomic_t *atomic,
mr_atomic_t tmp;
int mask;
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ATOMIC_SEQ_CST)
MR_UNUSED(mask);
tmp = __atomic_fetch_and(atomic, val, __ATOMIC_SEQ_CST);
#else
@@ -214,7 +214,7 @@ MR_INLINE mr_atomic_t mr_atomic_fetch_and(volatile mr_atomic_t *atomic,
tmp = *atomic;
*atomic &= val;
mr_port_irq_restore(mask);
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(__ATOMIC_SEQ_CST) */
return tmp;
}
@@ -230,7 +230,7 @@ MR_INLINE mr_atomic_t mr_atomic_fetch_or(volatile mr_atomic_t *atomic,
mr_atomic_t tmp;
int mask;
#if defined(__GNUC__) || defined(__clang__)
#if defined(__ATOMIC_SEQ_CST)
MR_UNUSED(mask);
tmp = __atomic_fetch_or(atomic, val, __ATOMIC_SEQ_CST);
#else
@@ -238,7 +238,7 @@ MR_INLINE mr_atomic_t mr_atomic_fetch_or(volatile mr_atomic_t *atomic,
tmp = *atomic;
*atomic |= val;
mr_port_irq_restore(mask);
#endif /* defined(__GNUC__) || defined(__clang__) */
#endif /* defined(__ATOMIC_SEQ_CST) */
return tmp;
}
#endif /* defined(MR_USE_3PARTY_ATOMIC) */

View File

@@ -5,6 +5,15 @@
extern "C" {
#endif /* __cplusplus */
#define MR_USE_KTIMER_ATTR
#define MR_USE_KTIMER
#define MR_USE_KWORKQUEUE
#define MR_USE_KWORKQUEUE_HOOK
#define MR_USE_ENTRY
#define MR_USE_KPRINTF
#define MR_USE_KPRINTF_SAFE
#define MR_USE_LIBC_SCANF
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@@ -54,7 +54,6 @@
#include <port/mr_port_assert.h>
#include <port/mr_port_irq.h>
#include <port/mr_port_output.h>
#include <port/mr_port_thread.h>
/** @} */

View File

@@ -11,26 +11,30 @@
#include <kernel/mr_initcall.h>
MR_INLINE void entry(void) {
extern int main(void);
/* Kernel init */
mr_kernel_init();
/* Run main */
main();
}
/* MR-X entry point */
#if defined(__GNUC__) || defined(__clang__)
int mr_entry(void) {
entry();
return 0;
}
#elif defined(__CC_ARM)
#if defined(__ARMCC_VERSION)
extern int $Super$$main(void);
int $Sub$$main(void) {
/* mr-X entry */
entry();
/* Real entry */
$Super$$main();
return 0;
}
#endif /* defined(__GNUC__) || defined(__clang__) */
#else
extern int main(void);
int mr_entry(void) {
/* mr-X entry */
entry();
/* Real entry */
main();
return 0;
}
#endif /* defined(__ARMCC_VERSION) */
#endif /* defined(MR_USE_ENTRY) */

View File

@@ -41,11 +41,6 @@ void mr_kernel_init(void) {
extern void mr_kworkqueue_kernel_init(void);
mr_kworkqueue_kernel_init();
#endif /* defined(MR_USE_KWORKQUEUE) */
#if defined(MR_USE_IRQ)
/* Init irq */
extern void mr_irq_kernel_init(void);
mr_irq_kernel_init();
#endif /* defined(MR_USE_IRQ) */
}
void mr_user_init(void) {

View File

@@ -28,7 +28,7 @@ MR_INLINE void kclock_hook(void) {
mr_size_t i;
/* Each hooks */
MR_KHOOK_EACH(i, entry, &khook) {
MR_KHOOK_EACH(i, entry, mr_kclock_hook_t *, &khook) {
if (!entry) {
continue;
}

View File

@@ -228,6 +228,7 @@ MR_INLINE mr_err_t kobject_name_alloc(mr_kobject_t *kobj, const char *name) {
}
MR_INLINE void path_free(const char *path, char *ipath) {
/* Check inline path */
if (path == ipath) {
/* Inline path not need to free */
return;

View File

@@ -263,7 +263,7 @@ MR_INLINE void ktimer_timeout_check(void) {
mr_klist_move(&ktimer->list, &list);
/* Save ktimer entry and args */
entry = ktimer->entry;
entry = (mr_ktimer_entry *)ktimer->entry;
args = ktimer->args;
/* Unlock */

View File

@@ -52,6 +52,7 @@ MR_INLINE void kqueue_timer_entry(mr_ktimer_t *ktimer, void *args) {
kqueue = mr_kworkqueue_get(MR_CONTAINER_OF(ktimer, mr_kworkqueue_t, timer));
if (!kqueue) {
/* Kworkqueue is not exist */
mr_ktimer_del(ktimer);
return;
}
@@ -166,8 +167,9 @@ MR_INLINE mr_err_t kqueue_init_add(mr_kworkqueue_t *kqueue, mr_ktype_t *ktype,
ret = mr_kobject_add((mr_kobject_t *)kqueue, (mr_kobject_t *)&kroot, name);
if (ret != 0) {
kqueue_del(kqueue);
return ret;
}
return ret;
return 0;
}
mr_err_t mr_kworkqueue_init(mr_kworkqueue_t *kqueue, const char *name) {

View File

@@ -279,7 +279,7 @@ int mr_vsnprintf(char *buf, mr_size_t size, const char *fmt, mr_va_list args) {
}
/* Get effector */
effector = -1;
effector = '\0';
if ((*fmt == 'l') || (*fmt == 'L') || (*fmt == 'z') || (*fmt == 'h')) {
effector = *(fmt++);
if ((*fmt == 'l') && (effector == 'l')) {