00_rtthread_kernel_object

RT-Thread是一个实时操作系统,其内核包括线程、信号量、互斥量等对象。对象容器通过链表管理这些内核对象。文章详细介绍了RT-Thread的线程、定时器等结构体以及进程间通信的各种结构,强调了设备结构体的继承关系和启动流程。

1.基本介绍

参考官方文档地址:RT-Thread 文档中心

RT-Thread的内核架构图如下:

RT-Thread内核对象包括线程、信号量、互斥量、事件、邮箱、消息队列和定时器、内存池、设备驱动等。对象容器中包含每类内核对象的信息,包括对象类型、大小等。

对象容器给每类内核对象分配了一个链表,所有的内核对象都被链接到该链表上,RT-Thread的内核对象容器链表如下图所示:

内核对象的结构体如下:

 定时器的结构类型如下:

线程的结构类型如下:

/**
 * Thread structure
 */
struct rt_thread
{
    /* rt object */
    char        name[RT_NAME_MAX];                      /**< the name of thread */
    rt_uint8_t  type;                                   /**< type of object */
    rt_uint8_t  flags;                                  /**< thread's flags */

    rt_list_t   list;                                   /**< the object list */
    rt_list_t   tlist;                                  /**< the thread list */

    /* stack point and entry */
    void       *sp;                                     /**< stack point */
    void       *entry;                                  /**< entry */
    void       *parameter;                              /**< parameter */
    void       *stack_addr;                             /**< stack address */
    rt_uint32_t stack_size;                             /**< stack size */

    /* error code */
    rt_err_t    error;                                  /**< error code */

    rt_uint8_t  stat;                                   /**< thread status */

    /* priority */
    rt_uint8_t  current_priority;                       /**< current priority */
    rt_uint8_t  init_priority;                          /**< initialized priority */
#if RT_THREAD_PRIORITY_MAX > 32
    rt_uint8_t  number;
    rt_uint8_t  high_mask;
#endif
    rt_uint32_t number_mask;

#if defined(RT_USING_EVENT)
    /* thread event */
    rt_uint32_t event_set;
    rt_uint8_t  event_info;
#endif

    rt_ubase_t  init_tick;                              /**< thread's initialized tick */
    rt_ubase_t  remaining_tick;                         /**< remaining tick */

    struct rt_timer thread_timer;                       /**< built-in thread timer */

    void (*cleanup)(struct rt_thread *tid);             /**< cleanup function when thread exit */

    rt_uint32_t user_data;                              /**< private user data beyond this thread */
};
typedef struct rt_thread *rt_thread_t;

 进程间通信的基本结构体如下:

 进程间通信之信号量的结构体如下:

 进程间通信之互斥体的结构体如下:

 进程间通信之事件的结构体如下:

 进程间通信之邮箱的结构体如下:

 进程间通信之消息队列的结构体如下:

 进程间的通信的每一种类型都包含了进程间通信的结构体,这就是面向对象中的父类。

RT-Thread中的设备结构体继承内核对象,结构体如下:

RT-Thread的启动流程如下图所示:

2.补充一下基本的数据结构类型和常用的宏定义

* 与数据对齐相关的

* 软件版本相关的

从中可以看出我使用的软件版本号;

* 链表相关的数据结构定义

 

 双连链表和单链表的定义;

* 定时器的结构体定义

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值