2009-07-03 06:48:23 +08:00
|
|
|
/*
|
2024-07-11 09:28:41 +08:00
|
|
|
* Copyright (c) 2006-2024 RT-Thread Development Team
|
2013-06-24 17:06:09 +08:00
|
|
|
*
|
2018-09-14 22:37:43 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2006-03-18 Bernard the first version
|
|
|
|
* 2006-04-26 Bernard add semaphore APIs
|
|
|
|
* 2006-08-10 Bernard add version information
|
|
|
|
* 2007-01-28 Bernard rename RT_OBJECT_Class_Static to RT_Object_Class_Static
|
|
|
|
* 2007-03-03 Bernard clean up the definitions to rtdef.h
|
2011-09-23 13:57:31 +08:00
|
|
|
* 2010-04-11 yi.qiu add module feature
|
2013-06-24 00:08:10 +08:00
|
|
|
* 2013-06-24 Bernard add rt_kprintf re-define when not use RT_USING_CONSOLE.
|
2016-08-09 11:29:11 +08:00
|
|
|
* 2016-08-09 ArdaFu add new thread and interrupt hook.
|
2018-11-22 14:40:43 +08:00
|
|
|
* 2018-11-22 Jesven add all cpu's lock and ipi handler
|
2021-03-01 23:58:04 +08:00
|
|
|
* 2021-02-28 Meco Man add RT_KSERVICE_USING_STDLIB
|
2021-11-15 02:04:03 +08:00
|
|
|
* 2021-11-14 Meco Man add rtlegacy.h for compatibility
|
2022-06-05 09:52:21 +08:00
|
|
|
* 2022-06-04 Meco Man remove strnlen
|
2023-05-20 23:41:29 +08:00
|
|
|
* 2023-05-20 Bernard add rtatomic.h header file to included files.
|
2023-07-22 10:36:42 +08:00
|
|
|
* 2023-06-30 ChuShicheng move debug check from the rtdebug.h
|
2023-10-21 20:14:45 +08:00
|
|
|
* 2023-10-16 Shell Support a new backtrace framework
|
2023-12-22 11:15:18 +08:00
|
|
|
* 2023-12-10 xqyjlj fix spinlock in up
|
2024-02-23 17:49:15 +08:00
|
|
|
* 2024-01-25 Shell Add rt_susp_list for IPC primitives
|
2024-03-11 01:39:20 +08:00
|
|
|
* 2024-03-10 Meco Man move std libc related functions to rtklibc
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __RT_THREAD_H__
|
|
|
|
#define __RT_THREAD_H__
|
2013-06-30 20:17:41 +08:00
|
|
|
|
2014-01-11 16:37:13 +08:00
|
|
|
#include <rtconfig.h>
|
|
|
|
#include <rtdef.h>
|
2012-03-22 14:11:44 +08:00
|
|
|
#include <rtservice.h>
|
2012-10-05 16:44:10 +08:00
|
|
|
#include <rtm.h>
|
2023-05-20 23:41:29 +08:00
|
|
|
#include <rtatomic.h>
|
2024-03-11 01:39:20 +08:00
|
|
|
#include <rtklibc.h>
|
2021-11-15 02:04:03 +08:00
|
|
|
#ifdef RT_USING_LEGACY
|
|
|
|
#include <rtlegacy.h>
|
|
|
|
#endif
|
2023-07-23 06:19:34 +08:00
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
#include <finsh.h>
|
|
|
|
#endif /* RT_USING_FINSH */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2024-02-21 11:45:04 +08:00
|
|
|
#ifdef __GNUC__
|
2024-02-23 17:49:15 +08:00
|
|
|
int entry(void);
|
2024-02-21 11:45:04 +08:00
|
|
|
#endif
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup KernelObject
|
2023-02-03 10:00:58 +08:00
|
|
|
* @{
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* kernel object interface
|
|
|
|
*/
|
2012-09-05 13:36:08 +08:00
|
|
|
struct rt_object_information *
|
|
|
|
rt_object_get_information(enum rt_object_class_type type);
|
2020-04-10 00:01:58 +08:00
|
|
|
int rt_object_get_length(enum rt_object_class_type type);
|
|
|
|
int rt_object_get_pointers(enum rt_object_class_type type, rt_object_t *pointers, int maxlen);
|
|
|
|
|
2012-09-07 14:48:02 +08:00
|
|
|
void rt_object_init(struct rt_object *object,
|
|
|
|
enum rt_object_class_type type,
|
|
|
|
const char *name);
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_object_detach(rt_object_t object);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2023-07-23 06:19:34 +08:00
|
|
|
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name);
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_object_delete(rt_object_t object);
|
2023-07-23 06:19:34 +08:00
|
|
|
/* custom object */
|
|
|
|
rt_object_t rt_custom_object_create(const char *name, void *data, rt_err_t (*data_destroy)(void *));
|
|
|
|
rt_err_t rt_custom_object_destroy(rt_object_t obj);
|
|
|
|
#endif /* RT_USING_HEAP */
|
2012-06-02 17:20:19 +08:00
|
|
|
rt_bool_t rt_object_is_systemobject(rt_object_t object);
|
2018-07-11 11:45:37 +08:00
|
|
|
rt_uint8_t rt_object_get_type(rt_object_t object);
|
2024-05-17 13:19:00 +08:00
|
|
|
rt_err_t rt_object_for_each(rt_uint8_t type, rt_object_iter_t iter, void *data);
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_object_t rt_object_find(const char *name, rt_uint8_t type);
|
2023-05-17 17:40:18 +08:00
|
|
|
rt_err_t rt_object_get_name(rt_object_t object, char *name, rt_uint8_t name_size);
|
2009-11-06 15:45:37 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_HOOK
|
2011-09-23 13:57:31 +08:00
|
|
|
void rt_object_attach_sethook(void (*hook)(struct rt_object *object));
|
|
|
|
void rt_object_detach_sethook(void (*hook)(struct rt_object *object));
|
|
|
|
void rt_object_trytake_sethook(void (*hook)(struct rt_object *object));
|
|
|
|
void rt_object_take_sethook(void (*hook)(struct rt_object *object));
|
|
|
|
void rt_object_put_sethook(void (*hook)(struct rt_object *object));
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HOOK */
|
2009-11-06 15:45:37 +08:00
|
|
|
|
2016-08-19 09:56:03 +08:00
|
|
|
/**@}*/
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup Clock
|
2023-02-03 10:00:58 +08:00
|
|
|
* @{
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* clock & timer interface
|
|
|
|
*/
|
|
|
|
rt_tick_t rt_tick_get(void);
|
2011-06-29 22:45:35 +08:00
|
|
|
void rt_tick_set(rt_tick_t tick);
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_tick_increase(void);
|
2024-07-11 09:28:41 +08:00
|
|
|
void rt_tick_increase_tick(rt_tick_t tick);
|
2019-03-20 14:55:59 +08:00
|
|
|
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms);
|
2020-12-30 16:32:20 +08:00
|
|
|
rt_tick_t rt_tick_get_millisecond(void);
|
2022-02-13 14:50:51 +08:00
|
|
|
#ifdef RT_USING_HOOK
|
|
|
|
void rt_tick_sethook(void (*hook)(void));
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HOOK */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
void rt_system_timer_init(void);
|
2009-12-23 21:52:42 +08:00
|
|
|
void rt_system_timer_thread_init(void);
|
|
|
|
|
2012-09-05 13:36:08 +08:00
|
|
|
void rt_timer_init(rt_timer_t timer,
|
|
|
|
const char *name,
|
|
|
|
void (*timeout)(void *parameter),
|
|
|
|
void *parameter,
|
|
|
|
rt_tick_t time,
|
|
|
|
rt_uint8_t flag);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_timer_detach(rt_timer_t timer);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_timer_t rt_timer_create(const char *name,
|
2012-09-05 13:36:08 +08:00
|
|
|
void (*timeout)(void *parameter),
|
|
|
|
void *parameter,
|
|
|
|
rt_tick_t time,
|
|
|
|
rt_uint8_t flag);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_timer_delete(rt_timer_t timer);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_timer_start(rt_timer_t timer);
|
|
|
|
rt_err_t rt_timer_stop(rt_timer_t timer);
|
2017-10-15 22:30:05 +08:00
|
|
|
rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg);
|
2012-06-12 07:38:28 +08:00
|
|
|
rt_tick_t rt_timer_next_timeout_tick(void);
|
|
|
|
void rt_timer_check(void);
|
2009-11-06 15:45:37 +08:00
|
|
|
#ifdef RT_USING_HOOK
|
2018-11-13 11:32:01 +08:00
|
|
|
void rt_timer_enter_sethook(void (*hook)(struct rt_timer *timer));
|
|
|
|
void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer));
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HOOK */
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2016-08-19 09:56:03 +08:00
|
|
|
/**@}*/
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup Thread
|
2023-02-03 10:00:58 +08:00
|
|
|
* @{
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* thread interface
|
|
|
|
*/
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_err_t rt_thread_init(struct rt_thread *thread,
|
2012-09-05 13:36:08 +08:00
|
|
|
const char *name,
|
|
|
|
void (*entry)(void *parameter),
|
|
|
|
void *parameter,
|
|
|
|
void *stack_start,
|
|
|
|
rt_uint32_t stack_size,
|
|
|
|
rt_uint8_t priority,
|
|
|
|
rt_uint32_t tick);
|
2010-04-20 09:09:07 +08:00
|
|
|
rt_err_t rt_thread_detach(rt_thread_t thread);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2012-09-07 14:48:02 +08:00
|
|
|
rt_thread_t rt_thread_create(const char *name,
|
2012-09-05 13:36:08 +08:00
|
|
|
void (*entry)(void *parameter),
|
2012-09-07 14:48:02 +08:00
|
|
|
void *parameter,
|
|
|
|
rt_uint32_t stack_size,
|
|
|
|
rt_uint8_t priority,
|
|
|
|
rt_uint32_t tick);
|
2021-05-28 22:46:49 +08:00
|
|
|
rt_err_t rt_thread_delete(rt_thread_t thread);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2024-05-11 23:51:51 +08:00
|
|
|
rt_err_t rt_thread_close(rt_thread_t thread);
|
2010-04-20 09:09:07 +08:00
|
|
|
rt_thread_t rt_thread_self(void);
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_thread_t rt_thread_find(char *name);
|
2010-04-20 09:09:07 +08:00
|
|
|
rt_err_t rt_thread_startup(rt_thread_t thread);
|
|
|
|
rt_err_t rt_thread_yield(void);
|
|
|
|
rt_err_t rt_thread_delay(rt_tick_t tick);
|
2019-12-19 09:45:58 +08:00
|
|
|
rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick);
|
2018-05-12 12:08:47 +08:00
|
|
|
rt_err_t rt_thread_mdelay(rt_int32_t ms);
|
2017-10-15 22:30:05 +08:00
|
|
|
rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg);
|
2010-04-20 09:09:07 +08:00
|
|
|
rt_err_t rt_thread_suspend(rt_thread_t thread);
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_thread_suspend_with_flag(rt_thread_t thread, int suspend_flag);
|
2010-04-20 09:09:07 +08:00
|
|
|
rt_err_t rt_thread_resume(rt_thread_t thread);
|
2022-12-16 18:38:28 +08:00
|
|
|
#ifdef RT_USING_SMART
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_thread_wakeup(rt_thread_t thread);
|
|
|
|
void rt_thread_wakeup_set(struct rt_thread *thread, rt_wakeup_func_t func, void* user_data);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_SMART */
|
2023-05-17 17:40:18 +08:00
|
|
|
rt_err_t rt_thread_get_name(rt_thread_t thread, char *name, rt_uint8_t name_size);
|
2017-10-15 22:30:05 +08:00
|
|
|
#ifdef RT_USING_SIGNALS
|
|
|
|
void rt_thread_alloc_sig(rt_thread_t tid);
|
|
|
|
void rt_thread_free_sig(rt_thread_t tid);
|
|
|
|
int rt_thread_kill(rt_thread_t tid, int sig);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_SIGNALS */
|
2016-08-09 11:29:11 +08:00
|
|
|
#ifdef RT_USING_HOOK
|
|
|
|
void rt_thread_suspend_sethook(void (*hook)(rt_thread_t thread));
|
2017-04-09 19:12:53 +08:00
|
|
|
void rt_thread_resume_sethook (void (*hook)(rt_thread_t thread));
|
2023-12-23 17:59:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets a hook function when a thread is initialized.
|
|
|
|
*
|
|
|
|
* @param thread is the target thread that initializing
|
|
|
|
*/
|
|
|
|
typedef void (*rt_thread_inited_hookproto_t)(rt_thread_t thread);
|
|
|
|
RT_OBJECT_HOOKLIST_DECLARE(rt_thread_inited_hookproto_t, rt_thread_inited);
|
|
|
|
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HOOK */
|
2016-08-09 11:29:11 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* idle thread interface
|
|
|
|
*/
|
|
|
|
void rt_thread_idle_init(void);
|
2017-05-23 00:01:05 +08:00
|
|
|
#if defined(RT_USING_HOOK) || defined(RT_USING_IDLE_HOOK)
|
2018-07-12 18:37:51 +08:00
|
|
|
rt_err_t rt_thread_idle_sethook(void (*hook)(void));
|
|
|
|
rt_err_t rt_thread_idle_delhook(void (*hook)(void));
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* defined(RT_USING_HOOK) || defined(RT_USING_IDLE_HOOK) */
|
2016-08-09 11:29:11 +08:00
|
|
|
rt_thread_t rt_thread_idle_gethandler(void);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* schedule service
|
|
|
|
*/
|
|
|
|
void rt_system_scheduler_init(void);
|
|
|
|
void rt_system_scheduler_start(void);
|
|
|
|
|
|
|
|
void rt_schedule(void);
|
2024-02-21 11:45:04 +08:00
|
|
|
void rt_scheduler_do_irq_switch(void *context);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2024-03-21 10:26:41 +08:00
|
|
|
#ifdef RT_USING_OVERFLOW_CHECK
|
|
|
|
void rt_scheduler_stack_check(struct rt_thread *thread);
|
|
|
|
|
|
|
|
#define RT_SCHEDULER_STACK_CHECK(thr) rt_scheduler_stack_check(thr)
|
|
|
|
|
|
|
|
#else /* !RT_USING_OVERFLOW_CHECK */
|
|
|
|
|
|
|
|
#define RT_SCHEDULER_STACK_CHECK(thr)
|
|
|
|
|
|
|
|
#endif /* RT_USING_OVERFLOW_CHECK */
|
|
|
|
|
2024-02-23 17:49:15 +08:00
|
|
|
rt_base_t rt_enter_critical(void);
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_exit_critical(void);
|
2024-02-23 17:49:15 +08:00
|
|
|
void rt_exit_critical_safe(rt_base_t critical_level);
|
2013-12-21 11:24:37 +08:00
|
|
|
rt_uint16_t rt_critical_level(void);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_HOOK
|
2009-12-04 17:37:14 +08:00
|
|
|
void rt_scheduler_sethook(void (*hook)(rt_thread_t from, rt_thread_t to));
|
2021-07-05 18:33:22 +08:00
|
|
|
void rt_scheduler_switch_sethook(void (*hook)(struct rt_thread *tid));
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HOOK */
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2018-11-22 14:40:43 +08:00
|
|
|
#ifdef RT_USING_SMP
|
2022-12-03 12:07:44 +08:00
|
|
|
void rt_secondary_cpu_entry(void);
|
2018-11-22 14:40:43 +08:00
|
|
|
void rt_scheduler_ipi_handler(int vector, void *param);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_SMP */
|
2018-11-22 14:40:43 +08:00
|
|
|
|
2016-08-19 09:56:03 +08:00
|
|
|
/**@}*/
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2017-10-15 22:30:05 +08:00
|
|
|
/**
|
2024-06-26 13:40:31 +08:00
|
|
|
* @addtogroup Signal
|
2017-10-15 22:30:05 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#ifdef RT_USING_SIGNALS
|
|
|
|
void rt_signal_mask(int signo);
|
|
|
|
void rt_signal_unmask(int signo);
|
|
|
|
rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler);
|
2018-03-01 13:36:22 +08:00
|
|
|
int rt_signal_wait(const rt_sigset_t *set, rt_siginfo_t *si, rt_int32_t timeout);
|
2017-10-15 22:30:05 +08:00
|
|
|
int rt_system_signal_init(void);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_SIGNALS */
|
2023-02-03 10:00:58 +08:00
|
|
|
/**@}*/
|
2017-10-15 22:30:05 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup MM
|
2023-02-03 10:00:58 +08:00
|
|
|
* @{
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* memory management interface
|
|
|
|
*/
|
|
|
|
#ifdef RT_USING_MEMPOOL
|
|
|
|
/*
|
|
|
|
* memory pool interface
|
|
|
|
*/
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_err_t rt_mp_init(struct rt_mempool *mp,
|
|
|
|
const char *name,
|
|
|
|
void *start,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_size_t block_size);
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_err_t rt_mp_detach(struct rt_mempool *mp);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_mp_t rt_mp_create(const char *name,
|
|
|
|
rt_size_t block_count,
|
|
|
|
rt_size_t block_size);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_mp_delete(rt_mp_t mp);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2011-09-23 13:57:31 +08:00
|
|
|
void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time);
|
|
|
|
void rt_mp_free(void *block);
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef RT_USING_HOOK
|
2011-09-23 13:57:31 +08:00
|
|
|
void rt_mp_alloc_sethook(void (*hook)(struct rt_mempool *mp, void *block));
|
|
|
|
void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block));
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HOOK */
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_MEMPOOL */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_HEAP
|
|
|
|
/*
|
|
|
|
* heap memory interface
|
|
|
|
*/
|
2011-09-23 13:57:31 +08:00
|
|
|
void rt_system_heap_init(void *begin_addr, void *end_addr);
|
2024-06-13 08:55:53 +08:00
|
|
|
void rt_system_heap_init_generic(void *begin_addr, void *end_addr);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2023-05-01 07:35:03 +08:00
|
|
|
void *rt_malloc(rt_size_t size);
|
2011-09-23 13:57:31 +08:00
|
|
|
void rt_free(void *ptr);
|
2023-05-01 07:35:03 +08:00
|
|
|
void *rt_realloc(void *ptr, rt_size_t newsize);
|
2009-10-11 13:43:15 +08:00
|
|
|
void *rt_calloc(rt_size_t count, rt_size_t size);
|
2012-03-17 14:43:49 +08:00
|
|
|
void *rt_malloc_align(rt_size_t size, rt_size_t align);
|
|
|
|
void rt_free_align(void *ptr);
|
2009-12-23 21:52:42 +08:00
|
|
|
|
2022-01-01 19:13:13 +08:00
|
|
|
void rt_memory_info(rt_size_t *total,
|
|
|
|
rt_size_t *used,
|
|
|
|
rt_size_t *max_used);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-12-16 16:23:58 +08:00
|
|
|
#if defined(RT_USING_SLAB) && defined(RT_USING_SLAB_AS_HEAP)
|
2011-08-15 22:05:41 +08:00
|
|
|
void *rt_page_alloc(rt_size_t npages);
|
|
|
|
void rt_page_free(void *addr, rt_size_t npages);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* defined(RT_USING_SLAB) && defined(RT_USING_SLAB_AS_HEAP) */
|
2011-08-15 22:05:41 +08:00
|
|
|
|
2024-06-27 21:37:57 +08:00
|
|
|
/**
|
|
|
|
* @ingroup Hook
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef RT_USING_HOOK
|
2023-12-22 15:44:45 +08:00
|
|
|
void rt_malloc_sethook(void (*hook)(void **ptr, rt_size_t size));
|
|
|
|
void rt_realloc_set_entry_hook(void (*hook)(void **ptr, rt_size_t size));
|
|
|
|
void rt_realloc_set_exit_hook(void (*hook)(void **ptr, rt_size_t size));
|
|
|
|
void rt_free_sethook(void (*hook)(void **ptr));
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HOOK */
|
2024-06-27 21:37:57 +08:00
|
|
|
/**@}*/
|
2010-10-28 09:21:47 +08:00
|
|
|
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2021-12-16 16:23:58 +08:00
|
|
|
#ifdef RT_USING_SMALL_MEM
|
|
|
|
/**
|
|
|
|
* small memory object interface
|
|
|
|
*/
|
|
|
|
rt_smem_t rt_smem_init(const char *name,
|
|
|
|
void *begin_addr,
|
|
|
|
rt_size_t size);
|
|
|
|
rt_err_t rt_smem_detach(rt_smem_t m);
|
|
|
|
void *rt_smem_alloc(rt_smem_t m, rt_size_t size);
|
|
|
|
void *rt_smem_realloc(rt_smem_t m, void *rmem, rt_size_t newsize);
|
|
|
|
void rt_smem_free(void *rmem);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_SMALL_MEM */
|
2021-12-16 16:23:58 +08:00
|
|
|
|
2012-04-14 11:52:56 +08:00
|
|
|
#ifdef RT_USING_MEMHEAP
|
|
|
|
/**
|
|
|
|
* memory heap object interface
|
|
|
|
*/
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_err_t rt_memheap_init(struct rt_memheap *memheap,
|
|
|
|
const char *name,
|
|
|
|
void *start_addr,
|
2018-10-26 06:35:42 +08:00
|
|
|
rt_size_t size);
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_err_t rt_memheap_detach(struct rt_memheap *heap);
|
2018-10-26 06:35:42 +08:00
|
|
|
void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size);
|
2017-09-15 11:02:24 +08:00
|
|
|
void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize);
|
2012-09-05 13:36:08 +08:00
|
|
|
void rt_memheap_free(void *ptr);
|
2021-12-16 16:23:58 +08:00
|
|
|
void rt_memheap_info(struct rt_memheap *heap,
|
2022-01-01 19:13:13 +08:00
|
|
|
rt_size_t *total,
|
|
|
|
rt_size_t *used,
|
|
|
|
rt_size_t *max_used);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_MEMHEAP */
|
2021-12-16 16:23:58 +08:00
|
|
|
|
2024-02-21 11:45:04 +08:00
|
|
|
#ifdef RT_USING_MEMHEAP_AS_HEAP
|
|
|
|
/**
|
|
|
|
* memory heap as heap
|
|
|
|
*/
|
|
|
|
void *_memheap_alloc(struct rt_memheap *heap, rt_size_t size);
|
|
|
|
void _memheap_free(void *rmem);
|
|
|
|
void *_memheap_realloc(struct rt_memheap *heap, void *rmem, rt_size_t newsize);
|
|
|
|
#endif
|
|
|
|
|
2021-12-16 16:23:58 +08:00
|
|
|
#ifdef RT_USING_SLAB
|
|
|
|
/**
|
|
|
|
* slab object interface
|
|
|
|
*/
|
|
|
|
rt_slab_t rt_slab_init(const char *name, void *begin_addr, rt_size_t size);
|
|
|
|
rt_err_t rt_slab_detach(rt_slab_t m);
|
|
|
|
void *rt_slab_page_alloc(rt_slab_t m, rt_size_t npages);
|
|
|
|
void rt_slab_page_free(rt_slab_t m, void *addr, rt_size_t npages);
|
|
|
|
void *rt_slab_alloc(rt_slab_t m, rt_size_t size);
|
|
|
|
void *rt_slab_realloc(rt_slab_t m, void *ptr, rt_size_t size);
|
|
|
|
void rt_slab_free(rt_slab_t m, void *ptr);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_SLAB */
|
2012-04-14 11:52:56 +08:00
|
|
|
|
2016-08-19 09:56:03 +08:00
|
|
|
/**@}*/
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup IPC
|
2023-02-03 10:00:58 +08:00
|
|
|
* @{
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2024-02-23 17:49:15 +08:00
|
|
|
/**
|
|
|
|
* Suspend list - A basic building block for IPC primitives which interacts with
|
|
|
|
* scheduler directly. Its API is similar to a FIFO list.
|
|
|
|
*
|
|
|
|
* Note: don't use in application codes directly
|
|
|
|
*/
|
|
|
|
void rt_susp_list_print(rt_list_t *list);
|
|
|
|
/* reserve thread error while resuming it */
|
|
|
|
#define RT_THREAD_RESUME_RES_THR_ERR (-1)
|
|
|
|
struct rt_thread *rt_susp_list_dequeue(rt_list_t *susp_list, rt_err_t thread_error);
|
|
|
|
rt_err_t rt_susp_list_resume_all(rt_list_t *susp_list, rt_err_t thread_error);
|
|
|
|
rt_err_t rt_susp_list_resume_all_irq(rt_list_t *susp_list,
|
|
|
|
rt_err_t thread_error,
|
|
|
|
struct rt_spinlock *lock);
|
|
|
|
|
|
|
|
/* suspend and enqueue */
|
|
|
|
rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int ipc_flags, int suspend_flag);
|
|
|
|
/* only for a suspended thread, and caller must hold the scheduler lock */
|
|
|
|
rt_err_t rt_susp_list_enqueue(rt_list_t *susp_list, rt_thread_t thread, int ipc_flags);
|
|
|
|
|
2024-06-26 13:40:31 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup semaphore
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef RT_USING_SEMAPHORE
|
|
|
|
/*
|
|
|
|
* semaphore interface
|
|
|
|
*/
|
2012-09-07 14:48:02 +08:00
|
|
|
rt_err_t rt_sem_init(rt_sem_t sem,
|
|
|
|
const char *name,
|
|
|
|
rt_uint32_t value,
|
|
|
|
rt_uint8_t flag);
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_err_t rt_sem_detach(rt_sem_t sem);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag);
|
|
|
|
rt_err_t rt_sem_delete(rt_sem_t sem);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2022-04-15 17:08:44 +08:00
|
|
|
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t timeout);
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_sem_take_interruptible(rt_sem_t sem, rt_int32_t timeout);
|
|
|
|
rt_err_t rt_sem_take_killable(rt_sem_t sem, rt_int32_t timeout);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_sem_trytake(rt_sem_t sem);
|
|
|
|
rt_err_t rt_sem_release(rt_sem_t sem);
|
2017-10-15 22:30:05 +08:00
|
|
|
rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_SEMAPHORE */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2024-06-26 13:40:31 +08:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup mutex
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef RT_USING_MUTEX
|
|
|
|
/*
|
|
|
|
* mutex interface
|
|
|
|
*/
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag);
|
|
|
|
rt_err_t rt_mutex_detach(rt_mutex_t mutex);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag);
|
|
|
|
rt_err_t rt_mutex_delete(rt_mutex_t mutex);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2022-10-15 16:19:13 +08:00
|
|
|
void rt_mutex_drop_thread(rt_mutex_t mutex, rt_thread_t thread);
|
2022-10-16 17:58:51 +08:00
|
|
|
rt_uint8_t rt_mutex_setprioceiling(rt_mutex_t mutex, rt_uint8_t priority);
|
|
|
|
rt_uint8_t rt_mutex_getprioceiling(rt_mutex_t mutex);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2022-04-15 17:08:44 +08:00
|
|
|
rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t timeout);
|
2021-05-30 11:43:44 +08:00
|
|
|
rt_err_t rt_mutex_trytake(rt_mutex_t mutex);
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_mutex_take_interruptible(rt_mutex_t mutex, rt_int32_t time);
|
|
|
|
rt_err_t rt_mutex_take_killable(rt_mutex_t mutex, rt_int32_t time);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_mutex_release(rt_mutex_t mutex);
|
2017-10-15 22:30:05 +08:00
|
|
|
rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg);
|
2023-10-14 13:07:45 +08:00
|
|
|
|
|
|
|
rt_inline rt_thread_t rt_mutex_get_owner(rt_mutex_t mutex)
|
|
|
|
{
|
|
|
|
return mutex->owner;
|
|
|
|
}
|
|
|
|
rt_inline rt_ubase_t rt_mutex_get_hold(rt_mutex_t mutex)
|
|
|
|
{
|
|
|
|
return mutex->hold;
|
|
|
|
}
|
|
|
|
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_MUTEX */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2024-06-26 13:40:31 +08:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup event
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef RT_USING_EVENT
|
|
|
|
/*
|
|
|
|
* event interface
|
|
|
|
*/
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_event_detach(rt_event_t event);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_event_t rt_event_create(const char *name, rt_uint8_t flag);
|
|
|
|
rt_err_t rt_event_delete(rt_event_t event);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set);
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_err_t rt_event_recv(rt_event_t event,
|
|
|
|
rt_uint32_t set,
|
|
|
|
rt_uint8_t opt,
|
|
|
|
rt_int32_t timeout,
|
|
|
|
rt_uint32_t *recved);
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_event_recv_interruptible(rt_event_t event,
|
|
|
|
rt_uint32_t set,
|
|
|
|
rt_uint8_t opt,
|
|
|
|
rt_int32_t timeout,
|
|
|
|
rt_uint32_t *recved);
|
|
|
|
rt_err_t rt_event_recv_killable(rt_event_t event,
|
|
|
|
rt_uint32_t set,
|
|
|
|
rt_uint8_t opt,
|
|
|
|
rt_int32_t timeout,
|
|
|
|
rt_uint32_t *recved);
|
2017-10-15 22:30:05 +08:00
|
|
|
rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_EVENT */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2024-06-26 13:40:31 +08:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup mailbox
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef RT_USING_MAILBOX
|
|
|
|
/*
|
|
|
|
* mailbox interface
|
|
|
|
*/
|
2012-09-07 14:48:02 +08:00
|
|
|
rt_err_t rt_mb_init(rt_mailbox_t mb,
|
|
|
|
const char *name,
|
|
|
|
void *msgpool,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_uint8_t flag);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_mb_detach(rt_mailbox_t mb);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag);
|
|
|
|
rt_err_t rt_mb_delete(rt_mailbox_t mb);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2018-10-26 06:35:42 +08:00
|
|
|
rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value);
|
2024-02-19 14:35:50 +08:00
|
|
|
rt_err_t rt_mb_send_interruptible(rt_mailbox_t mb, rt_ubase_t value);
|
|
|
|
rt_err_t rt_mb_send_killable(rt_mailbox_t mb, rt_ubase_t value);
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
|
2018-10-26 06:35:42 +08:00
|
|
|
rt_ubase_t value,
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_int32_t timeout);
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_mb_send_wait_interruptible(rt_mailbox_t mb,
|
|
|
|
rt_ubase_t value,
|
|
|
|
rt_int32_t timeout);
|
|
|
|
rt_err_t rt_mb_send_wait_killable(rt_mailbox_t mb,
|
|
|
|
rt_ubase_t value,
|
|
|
|
rt_int32_t timeout);
|
2022-01-03 22:30:45 +08:00
|
|
|
rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value);
|
2018-10-26 06:35:42 +08:00
|
|
|
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout);
|
2023-09-17 21:09:05 +08:00
|
|
|
rt_err_t rt_mb_recv_interruptible(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout);
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_mb_recv_killable(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout);
|
2017-10-15 22:30:05 +08:00
|
|
|
rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_MAILBOX */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2024-06-26 13:40:31 +08:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup messagequeue
|
|
|
|
* @{
|
|
|
|
*/
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef RT_USING_MESSAGEQUEUE
|
2023-06-21 18:22:42 +08:00
|
|
|
|
|
|
|
struct rt_mq_message
|
|
|
|
{
|
|
|
|
struct rt_mq_message *next;
|
|
|
|
rt_ssize_t length;
|
2023-06-26 12:06:06 +08:00
|
|
|
#ifdef RT_USING_MESSAGEQUEUE_PRIORITY
|
|
|
|
rt_int32_t prio;
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_MESSAGEQUEUE_PRIORITY */
|
2023-06-21 18:22:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define RT_MQ_BUF_SIZE(msg_size, max_msgs) \
|
|
|
|
((RT_ALIGN((msg_size), RT_ALIGN_SIZE) + sizeof(struct rt_mq_message)) * (max_msgs))
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* message queue interface
|
|
|
|
*/
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_err_t rt_mq_init(rt_mq_t mq,
|
|
|
|
const char *name,
|
|
|
|
void *msgpool,
|
|
|
|
rt_size_t msg_size,
|
|
|
|
rt_size_t pool_size,
|
|
|
|
rt_uint8_t flag);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_mq_detach(rt_mq_t mq);
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_mq_t rt_mq_create(const char *name,
|
|
|
|
rt_size_t msg_size,
|
|
|
|
rt_size_t max_msgs,
|
|
|
|
rt_uint8_t flag);
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_err_t rt_mq_delete(rt_mq_t mq);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2019-07-09 21:34:56 +08:00
|
|
|
rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size);
|
2023-09-17 21:09:05 +08:00
|
|
|
rt_err_t rt_mq_send_interruptible(rt_mq_t mq, const void *buffer, rt_size_t size);
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_mq_send_killable(rt_mq_t mq, const void *buffer, rt_size_t size);
|
2019-09-16 15:12:42 +08:00
|
|
|
rt_err_t rt_mq_send_wait(rt_mq_t mq,
|
|
|
|
const void *buffer,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_int32_t timeout);
|
2022-12-03 12:07:44 +08:00
|
|
|
rt_err_t rt_mq_send_wait_interruptible(rt_mq_t mq,
|
|
|
|
const void *buffer,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_int32_t timeout);
|
|
|
|
rt_err_t rt_mq_send_wait_killable(rt_mq_t mq,
|
|
|
|
const void *buffer,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_int32_t timeout);
|
2019-07-09 21:34:56 +08:00
|
|
|
rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size);
|
2023-06-21 18:22:42 +08:00
|
|
|
rt_ssize_t rt_mq_recv(rt_mq_t mq,
|
2012-09-07 14:48:02 +08:00
|
|
|
void *buffer,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_int32_t timeout);
|
2023-06-21 18:22:42 +08:00
|
|
|
rt_ssize_t rt_mq_recv_interruptible(rt_mq_t mq,
|
2022-12-03 12:07:44 +08:00
|
|
|
void *buffer,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_int32_t timeout);
|
2023-06-21 18:22:42 +08:00
|
|
|
rt_ssize_t rt_mq_recv_killable(rt_mq_t mq,
|
2022-12-03 12:07:44 +08:00
|
|
|
void *buffer,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_int32_t timeout);
|
2017-10-15 22:30:05 +08:00
|
|
|
rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg);
|
2023-06-26 12:06:06 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_MESSAGEQUEUE_PRIORITY
|
|
|
|
rt_err_t rt_mq_send_wait_prio(rt_mq_t mq,
|
|
|
|
const void *buffer,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_int32_t prio,
|
|
|
|
rt_int32_t timeout,
|
|
|
|
int suspend_flag);
|
2023-09-08 18:15:03 +08:00
|
|
|
rt_ssize_t rt_mq_recv_prio(rt_mq_t mq,
|
|
|
|
void *buffer,
|
|
|
|
rt_size_t size,
|
|
|
|
rt_int32_t *prio,
|
|
|
|
rt_int32_t timeout,
|
|
|
|
int suspend_flag);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_MESSAGEQUEUE_PRIORITY */
|
|
|
|
#endif /* RT_USING_MESSAGEQUEUE */
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2024-06-26 13:40:31 +08:00
|
|
|
/**@}*/
|
|
|
|
|
2021-07-03 17:54:58 +08:00
|
|
|
/* defunct */
|
2024-08-30 11:03:55 +08:00
|
|
|
void rt_thread_defunct_init(void);
|
2021-07-03 17:54:58 +08:00
|
|
|
void rt_thread_defunct_enqueue(rt_thread_t thread);
|
|
|
|
rt_thread_t rt_thread_defunct_dequeue(void);
|
2024-08-30 16:30:55 +08:00
|
|
|
void rt_defunct_execute(void);
|
2021-07-03 17:54:58 +08:00
|
|
|
|
2019-09-28 11:56:03 +08:00
|
|
|
/*
|
|
|
|
* spinlock
|
|
|
|
*/
|
|
|
|
struct rt_spinlock;
|
|
|
|
|
|
|
|
void rt_spin_lock_init(struct rt_spinlock *lock);
|
|
|
|
void rt_spin_lock(struct rt_spinlock *lock);
|
|
|
|
void rt_spin_unlock(struct rt_spinlock *lock);
|
|
|
|
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock);
|
|
|
|
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level);
|
|
|
|
|
2016-08-19 09:56:03 +08:00
|
|
|
/**@}*/
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_DEVICE
|
|
|
|
/**
|
|
|
|
* @addtogroup Device
|
2023-02-03 10:00:58 +08:00
|
|
|
* @{
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* device (I/O) system interface
|
|
|
|
*/
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_device_t rt_device_find(const char *name);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2012-09-07 14:48:02 +08:00
|
|
|
rt_err_t rt_device_register(rt_device_t dev,
|
|
|
|
const char *name,
|
|
|
|
rt_uint16_t flags);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_device_unregister(rt_device_t dev);
|
2017-12-24 00:00:18 +08:00
|
|
|
|
2021-05-28 22:46:49 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2017-12-24 00:00:18 +08:00
|
|
|
rt_device_t rt_device_create(int type, int attach_size);
|
|
|
|
void rt_device_destroy(rt_device_t device);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|
2017-12-24 00:00:18 +08:00
|
|
|
|
2012-09-05 13:36:08 +08:00
|
|
|
rt_err_t
|
|
|
|
rt_device_set_rx_indicate(rt_device_t dev,
|
|
|
|
rt_err_t (*rx_ind)(rt_device_t dev, rt_size_t size));
|
|
|
|
rt_err_t
|
|
|
|
rt_device_set_tx_complete(rt_device_t dev,
|
|
|
|
rt_err_t (*tx_done)(rt_device_t dev, void *buffer));
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-05-04 07:17:25 +08:00
|
|
|
rt_err_t rt_device_init (rt_device_t dev);
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_err_t rt_device_open (rt_device_t dev, rt_uint16_t oflag);
|
|
|
|
rt_err_t rt_device_close(rt_device_t dev);
|
2023-02-06 07:35:33 +08:00
|
|
|
rt_ssize_t rt_device_read(rt_device_t dev,
|
2012-09-07 14:48:02 +08:00
|
|
|
rt_off_t pos,
|
|
|
|
void *buffer,
|
|
|
|
rt_size_t size);
|
2023-02-06 07:35:33 +08:00
|
|
|
rt_ssize_t rt_device_write(rt_device_t dev,
|
2012-09-07 14:48:02 +08:00
|
|
|
rt_off_t pos,
|
|
|
|
const void *buffer,
|
|
|
|
rt_size_t size);
|
2017-10-15 22:30:05 +08:00
|
|
|
rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg);
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2016-08-19 09:56:03 +08:00
|
|
|
/**@}*/
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_DEVICE */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* interrupt service
|
|
|
|
*/
|
2013-03-18 16:42:29 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* rt_interrupt_enter and rt_interrupt_leave only can be called by BSP
|
|
|
|
*/
|
|
|
|
void rt_interrupt_enter(void);
|
|
|
|
void rt_interrupt_leave(void);
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2024-05-28 14:27:55 +08:00
|
|
|
/**
|
|
|
|
* CPU object
|
|
|
|
*/
|
|
|
|
struct rt_cpu *rt_cpu_self(void);
|
|
|
|
struct rt_cpu *rt_cpu_index(int index);
|
|
|
|
|
2018-11-22 14:40:43 +08:00
|
|
|
#ifdef RT_USING_SMP
|
|
|
|
|
|
|
|
/*
|
|
|
|
* smp cpus lock service
|
|
|
|
*/
|
|
|
|
|
|
|
|
rt_base_t rt_cpus_lock(void);
|
|
|
|
void rt_cpus_unlock(rt_base_t level);
|
2024-05-08 09:22:09 +08:00
|
|
|
void rt_cpus_lock_status_restore(struct rt_thread *thread);
|
2018-11-22 14:40:43 +08:00
|
|
|
|
2024-05-08 09:22:09 +08:00
|
|
|
#ifdef RT_USING_DEBUG
|
|
|
|
rt_base_t rt_cpu_get_id(void);
|
|
|
|
#else /* !RT_USING_DEBUG */
|
|
|
|
#define rt_cpu_get_id rt_hw_cpu_id
|
|
|
|
#endif /* RT_USING_DEBUG */
|
|
|
|
|
|
|
|
#else /* !RT_USING_SMP */
|
|
|
|
#define rt_cpu_get_id() (0)
|
2024-02-21 11:45:04 +08:00
|
|
|
|
2023-10-20 13:25:47 +08:00
|
|
|
#endif /* RT_USING_SMP */
|
|
|
|
|
2011-06-15 07:59:42 +08:00
|
|
|
/*
|
|
|
|
* the number of nested interrupts.
|
|
|
|
*/
|
|
|
|
rt_uint8_t rt_interrupt_get_nest(void);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2016-08-09 11:29:11 +08:00
|
|
|
#ifdef RT_USING_HOOK
|
|
|
|
void rt_interrupt_enter_sethook(void (*hook)(void));
|
|
|
|
void rt_interrupt_leave_sethook(void (*hook)(void));
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_HOOK */
|
2016-08-09 11:29:11 +08:00
|
|
|
|
2015-03-22 09:06:48 +08:00
|
|
|
#ifdef RT_USING_COMPONENTS_INIT
|
|
|
|
void rt_components_init(void);
|
|
|
|
void rt_components_board_init(void);
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* RT_USING_COMPONENTS_INIT */
|
2012-05-30 14:50:06 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup KernelService
|
2023-02-03 10:00:58 +08:00
|
|
|
* @{
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
/*
|
|
|
|
* general kernel service
|
|
|
|
*/
|
2013-06-24 00:08:10 +08:00
|
|
|
#ifndef RT_USING_CONSOLE
|
|
|
|
#define rt_kprintf(...)
|
2017-01-31 13:18:20 +08:00
|
|
|
#define rt_kputs(str)
|
2013-06-24 00:08:10 +08:00
|
|
|
#else
|
2021-11-16 16:41:26 +08:00
|
|
|
int rt_kprintf(const char *fmt, ...);
|
2017-01-31 13:18:20 +08:00
|
|
|
void rt_kputs(const char *str);
|
2023-11-21 22:39:42 +08:00
|
|
|
#endif /* RT_USING_CONSOLE */
|
2023-10-21 20:14:45 +08:00
|
|
|
|
|
|
|
rt_err_t rt_backtrace(void);
|
|
|
|
rt_err_t rt_backtrace_thread(rt_thread_t thread);
|
2024-06-13 08:55:53 +08:00
|
|
|
rt_err_t rt_backtrace_frame(rt_thread_t thread, struct rt_hw_backtrace_frame *frame);
|
|
|
|
rt_err_t rt_backtrace_formatted_print(rt_ubase_t *buffer, long buflen);
|
|
|
|
rt_err_t rt_backtrace_to_buffer(rt_thread_t thread, struct rt_hw_backtrace_frame *frame,
|
|
|
|
long skip, rt_ubase_t *buffer, long buflen);
|
2023-10-21 20:14:45 +08:00
|
|
|
|
2012-11-28 22:25:06 +08:00
|
|
|
#if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE)
|
2011-09-23 13:57:31 +08:00
|
|
|
rt_device_t rt_console_set_device(const char *name);
|
2012-11-28 22:25:06 +08:00
|
|
|
rt_device_t rt_console_get_device(void);
|
2024-02-23 17:49:15 +08:00
|
|
|
#ifdef RT_USING_THREADSAFE_PRINTF
|
2024-01-09 20:37:47 +08:00
|
|
|
rt_thread_t rt_console_current_user(void);
|
|
|
|
#else
|
|
|
|
rt_inline void *rt_console_current_user(void) { return RT_NULL; }
|
2024-02-23 17:49:15 +08:00
|
|
|
#endif /* RT_USING_THREADSAFE_PRINTF */
|
2023-07-23 06:19:34 +08:00
|
|
|
#endif /* defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE) */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2017-10-15 22:30:05 +08:00
|
|
|
int __rt_ffs(int value);
|
2024-05-30 17:30:03 +08:00
|
|
|
unsigned long __rt_ffsl(unsigned long value);
|
2017-10-15 22:30:05 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_show_version(void);
|
|
|
|
|
2024-05-07 08:40:30 +08:00
|
|
|
#ifdef RT_DEBUGING_ASSERT
|
2017-09-15 11:02:24 +08:00
|
|
|
extern void (*rt_assert_hook)(const char *ex, const char *func, rt_size_t line);
|
|
|
|
void rt_assert_set_hook(void (*hook)(const char *ex, const char *func, rt_size_t line));
|
|
|
|
void rt_assert_handler(const char *ex, const char *func, rt_size_t line);
|
2023-07-01 20:41:02 +08:00
|
|
|
|
|
|
|
#define RT_ASSERT(EX) \
|
|
|
|
if (!(EX)) \
|
|
|
|
{ \
|
|
|
|
rt_assert_handler(#EX, __FUNCTION__, __LINE__); \
|
|
|
|
}
|
2023-07-27 10:53:51 +08:00
|
|
|
#else
|
|
|
|
#define RT_ASSERT(EX)
|
2024-05-07 08:40:30 +08:00
|
|
|
#endif /* RT_DEBUGING_ASSERT */
|
2023-07-01 20:41:02 +08:00
|
|
|
|
2023-07-22 10:36:42 +08:00
|
|
|
#ifdef RT_DEBUGING_CONTEXT
|
2023-07-01 20:41:02 +08:00
|
|
|
/* Macro to check current context */
|
|
|
|
#define RT_DEBUG_NOT_IN_INTERRUPT \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (rt_interrupt_get_nest() != 0) \
|
|
|
|
{ \
|
|
|
|
rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__); \
|
|
|
|
RT_ASSERT(0) \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
/* "In thread context" means:
|
|
|
|
* 1) the scheduler has been started
|
|
|
|
* 2) not in interrupt context.
|
|
|
|
*/
|
|
|
|
#define RT_DEBUG_IN_THREAD_CONTEXT \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (rt_thread_self() == RT_NULL) \
|
|
|
|
{ \
|
|
|
|
rt_kprintf("Function[%s] shall not be used before scheduler start\n", \
|
|
|
|
__FUNCTION__); \
|
|
|
|
RT_ASSERT(0) \
|
|
|
|
} \
|
|
|
|
RT_DEBUG_NOT_IN_INTERRUPT; \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
/* "scheduler available" means:
|
|
|
|
* 1) the scheduler has been started.
|
|
|
|
* 2) not in interrupt context.
|
|
|
|
* 3) scheduler is not locked.
|
|
|
|
*/
|
|
|
|
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (need_check) \
|
|
|
|
{ \
|
|
|
|
if (rt_critical_level() != 0) \
|
|
|
|
{ \
|
|
|
|
rt_kprintf("Function[%s]: scheduler is not available\n", \
|
|
|
|
__FUNCTION__); \
|
|
|
|
RT_ASSERT(0) \
|
|
|
|
} \
|
|
|
|
RT_DEBUG_IN_THREAD_CONTEXT; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
#else
|
|
|
|
#define RT_DEBUG_NOT_IN_INTERRUPT
|
|
|
|
#define RT_DEBUG_IN_THREAD_CONTEXT
|
|
|
|
#define RT_DEBUG_SCHEDULER_AVAILABLE(need_check)
|
2023-07-22 10:36:42 +08:00
|
|
|
#endif /* RT_DEBUGING_CONTEXT */
|
2015-06-11 10:59:25 +08:00
|
|
|
|
2024-01-09 23:09:49 +08:00
|
|
|
rt_inline rt_bool_t rt_in_thread_context(void)
|
|
|
|
{
|
|
|
|
return rt_thread_self() != RT_NULL && rt_interrupt_get_nest() == 0;
|
|
|
|
}
|
|
|
|
|
2024-05-08 09:22:09 +08:00
|
|
|
/* is scheduler available */
|
2024-01-09 23:09:49 +08:00
|
|
|
rt_inline rt_bool_t rt_scheduler_is_available(void)
|
|
|
|
{
|
2024-05-08 09:22:09 +08:00
|
|
|
return rt_critical_level() == 0 && rt_in_thread_context();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RT_USING_SMP
|
|
|
|
/* is thread bond on core */
|
|
|
|
rt_inline rt_bool_t rt_sched_thread_is_binding(rt_thread_t thread)
|
|
|
|
{
|
|
|
|
if (thread == RT_NULL)
|
|
|
|
{
|
|
|
|
thread = rt_thread_self();
|
|
|
|
}
|
|
|
|
return !thread || RT_SCHED_CTX(thread).bind_cpu != RT_CPUS_NR;
|
2024-01-09 23:09:49 +08:00
|
|
|
}
|
|
|
|
|
2024-05-08 09:22:09 +08:00
|
|
|
#else
|
|
|
|
#define rt_sched_thread_is_binding(thread) (RT_TRUE)
|
|
|
|
#endif
|
|
|
|
|
2016-08-19 09:56:03 +08:00
|
|
|
/**@}*/
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-17 14:43:49 +08:00
|
|
|
|
2023-07-22 10:36:42 +08:00
|
|
|
#endif /* __RT_THREAD_H__ */
|