diff --git a/mkrtos_knl/inc/knl/irq.h b/mkrtos_knl/inc/knl/irq.h index 6c5f15123..9bf1b8684 100755 --- a/mkrtos_knl/inc/knl/irq.h +++ b/mkrtos_knl/inc/knl/irq.h @@ -8,6 +8,7 @@ #define USER_ISR_START_NO 16 bool_t irq_check_usability(int inx); -void irq_alloc(int inx, irq_sender_t *irq, void (*irq_tigger_func)(irq_entry_t *irq)); +bool_t irq_alloc(int inx, irq_sender_t *irq, + void (*irq_tigger_func)(irq_entry_t *irq)); void irq_free(int inx); irq_entry_t *irq_get(int inx); diff --git a/mkrtos_knl/inc/knl/mm.h b/mkrtos_knl/inc/knl/mm.h index ff7b67692..79b6071a9 100755 --- a/mkrtos_knl/inc/knl/mm.h +++ b/mkrtos_knl/inc/knl/mm.h @@ -14,7 +14,6 @@ typedef struct mem_heap union { char name[MEM_HEAP_NAME]; - // pid_t pid; }; struct mem_heap *next; struct mem_heap *prev; @@ -29,7 +28,6 @@ typedef struct mem struct mem_heap *heap_start; //!< 开始位置 struct mem_heap *heap_end; //!< 结束位置 struct mem_heap *l_heap; //!< 空闲位置 - // uint16_t blong_user; //!< 属于用户 spinlock_t lock; } mem_t; diff --git a/mkrtos_knl/knl/app.c b/mkrtos_knl/knl/app.c index d6b6b0abf..7278b7861 100644 --- a/mkrtos_knl/knl/app.c +++ b/mkrtos_knl/knl/app.c @@ -1,3 +1,13 @@ +/** + * @file app.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" #include "app.h" diff --git a/mkrtos_knl/knl/cpulock.c b/mkrtos_knl/knl/cpulock.c index 61e043f57..a7c80f393 100755 --- a/mkrtos_knl/knl/cpulock.c +++ b/mkrtos_knl/knl/cpulock.c @@ -1,3 +1,13 @@ +/** + * @file cpulock.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" #include "arch.h" diff --git a/mkrtos_knl/knl/factory.c b/mkrtos_knl/knl/factory.c index 3930351d1..cb6bd73ae 100755 --- a/mkrtos_knl/knl/factory.c +++ b/mkrtos_knl/knl/factory.c @@ -1,3 +1,13 @@ +/** + * @file factory.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "factory.h" #include "kobject.h" #include "prot.h" diff --git a/mkrtos_knl/knl/globals.c b/mkrtos_knl/knl/globals.c index fb1826e55..47d067cf5 100755 --- a/mkrtos_knl/knl/globals.c +++ b/mkrtos_knl/knl/globals.c @@ -1,9 +1,12 @@ -/* - * @Author: zhangzheng - * @Date: 2023-08-14 09:47:54 - * @LastEditors: zhangzheng 1358745329@qq.com - * @FilePath: /mkrtos-real/mkrtos_knl/inc/knl/globals.h - * @Description: +/** + * @file globals.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * */ #include "globals.h" #include "types.h" diff --git a/mkrtos_knl/knl/init.c b/mkrtos_knl/knl/init.c index cba8b0698..1b0600ea3 100755 --- a/mkrtos_knl/knl/init.c +++ b/mkrtos_knl/knl/init.c @@ -1,3 +1,13 @@ +/** + * @file init.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" #include "init.h" diff --git a/mkrtos_knl/knl/ipc.c b/mkrtos_knl/knl/ipc.c index 1679fb0a9..68e0e5cce 100755 --- a/mkrtos_knl/knl/ipc.c +++ b/mkrtos_knl/knl/ipc.c @@ -1,3 +1,13 @@ +/** + * @file ipc.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "ipc.h" #include "types.h" #include "init.h" @@ -30,7 +40,7 @@ typedef struct ipc kobject_t kobj; //!< 内核对象 spinlock_t lock; //!< 操作的锁 TODO: 使用内核对象锁 slist_head_t wait_send; //!< 发送等待队列 - slist_head_t recv_send; //!< 发送等待队列 + slist_head_t recv_send; //!< 接收等待队列 slist_head_t node; //!< 超时检查链表 thread_t *svr_th; //!< 服务端 TODO:增加引用计数 thread_t *last_cli_th; //!< 上一次发送数据的客户端TODO:增加引用计数 @@ -49,39 +59,82 @@ enum ipc_op static void wake_up_th(ipc_t *ipc); static slist_head_t wait_list; +/** + * @brief 初始化一个超时等待队列 + * + */ void timeout_wait_list_init(void) { slist_init(&wait_list); } INIT_KOBJ(timeout_wait_list_init); + +/** + * @brief 检查超时队列 + * + */ void timeout_times_tick(void) { ipc_t *ipc; - slist_foreach(ipc, &wait_list, node) + slist_foreach(ipc, &wait_list, node) //!< 第一次循环等待的ipc { umword_t status = spinlock_lock(&ipc->lock); ipc_wait_item_t *item; - slist_foreach(item, &ipc->wait_send, node) + slist_foreach(item, &ipc->wait_send, node) //!< 第二次循环等待irq里面的等待者 { if (item->sleep_times != 0 && (--item->sleep_times) == 0) { - // slist_del(&item->node); + //!< 超时时间满后直接唤醒等待者 thread_ready(item->th, TRUE); } } spinlock_set(&ipc->lock, status); } } +/** + * @brief 唤醒某个ipc的所有等待者 + * + * @param ipc + */ +static void timeout_times_wake_ipc(ipc_t *ipc) +{ + assert(ipc); + ipc_wait_item_t *item; + slist_foreach(item, &ipc->wait_send, node) //!< 第二次循环等待irq里面的等待者 + { + //!< 超时时间满后直接唤醒等待者 + thread_ready(item->th, TRUE); + } + thread_sched(); +} +/** + * @brief ipc_wait_item_t结构体初始化 + * + * @param item + * @param ipc + * @param th + * @param times + */ static void ipc_wait_item_init(ipc_wait_item_t *item, ipc_t *ipc, thread_t *th, umword_t times) { slist_init(&item->node); item->th = th; item->sleep_times = times; } - +/** + * @brief 添加到一个等待队列,并进行解锁 + * + * @param ipc + * @param head + * @param th + * @param times 超时时间,为0代表一直超时 + * @param lock + * @param status + * @return int + */ static int add_wait_unlock(ipc_t *ipc, slist_head_t *head, thread_t *th, umword_t times, spinlock_t *lock, int status) { ipc_wait_item_t item; @@ -111,6 +164,11 @@ static int add_wait_unlock(ipc_t *ipc, slist_head_t *head, thread_t *th, umword_ } return 0; } +/** + * @brief 拿出等待队列中的第一个并唤醒 + * + * @param ipc + */ static void wake_up_th(ipc_t *ipc) { slist_head_t *mslist = slist_first(&ipc->wait_send); @@ -118,7 +176,14 @@ static void wake_up_th(ipc_t *ipc) thread_ready(item->th, TRUE); } - +/** + * @brief ipc传输时的数据拷贝 + * + * @param dst_th + * @param src_th + * @param tag + * @return int + */ static int ipc_data_copy(thread_t *dst_th, thread_t *src_th, msg_tag_t tag) { void *src = src_th->msg.msg; @@ -177,7 +242,8 @@ __check: status = spinlock_lock(&ipc->lock); if (ipc->svr_th->status != THREAD_SUSPEND) { - if (add_wait_unlock(ipc, &ipc->wait_send, th, timeout.send_timeout, &ipc->lock, status) < 0) + if (add_wait_unlock(ipc, &ipc->wait_send, th, + timeout.send_timeout, &ipc->lock, status) < 0) { return msg_tag_init4(MSG_TAG_KNL_ERR, 0, 0, -EWTIMEDOUT); } @@ -193,15 +259,14 @@ __check: } ipc->svr_th->msg.tag = tag; thread_ready(ipc->svr_th, TRUE); //!< 直接唤醒接受者 - // thread_suspend(th); //!< 发送后客户端直接进入等待状态 - ipc->last_cli_th = th; //!< 设置上一次发送的客户端 + ipc->last_cli_th = th; //!< 设置上一次发送的客户端 if (add_wait_unlock(ipc, &ipc->recv_send, th, timeout.recv_timeout, &ipc->lock, status) < 0) { ipc->last_cli_th = NULL; + ref_counter_dec_and_release(&ipc->last_cli_th->ref, &ipc->last_cli_th->kobj); return msg_tag_init4(MSG_TAG_KNL_ERR, 0, 0, -ERTIMEDOUT); } - spinlock_set(&ipc->lock, status); - + // spinlock_set(&ipc->lock, status); tmp_tag = th->msg.tag; ipc->last_cli_th = NULL; return tmp_tag; @@ -226,8 +291,9 @@ static int ipc_reply(ipc_t *ipc, thread_t *th, entry_frame_t *f, msg_tag_t tag) //!< 发送数据给svr_th int ret = ipc_data_copy(ipc->last_cli_th, th, tag); //!< 拷贝数据 - if (ret < 0) { - spinlock_set(&ipc->lock, status);; + if (ret < 0) + { + spinlock_set(&ipc->lock, status); return ret; } ipc->last_cli_th->msg.tag = tag; @@ -289,7 +355,9 @@ static void ipc_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, } else { - tag = ipc_call(ipc, th, f, in_tag, ipc_timeout_create(f->r[1])); + ref_counter_inc(&th->ref); //!< 引用计数+1 + tag = ipc_call(ipc, th, f, in_tag, ipc_timeout_create(f->r[1])); //!< ipc call + ref_counter_dec_and_release(&th->ref, &th->kobj); //!< 引用计数-1 } } break; @@ -301,7 +369,9 @@ static void ipc_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, } else { - tag = ipc_wait(ipc, th, f, in_tag); + ref_counter_inc(&th->ref); //!< 引用计数+1 + tag = ipc_wait(ipc, th, f, in_tag); //!< 进入等待 + ref_counter_dec_and_release(&th->ref, &th->kobj); //!< 引用计数-1 f->r[1] = ipc->user_id; } } @@ -314,7 +384,9 @@ static void ipc_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, } else { + ref_counter_inc(&th->ref); //!< 引用计数+1 int ret = ipc_reply(ipc, th, f, in_tag); + ref_counter_dec_and_release(&th->ref, &th->kobj); //!< 引用计数-1 tag = msg_tag_init4(0, 0, 0, ret); } } @@ -330,7 +402,10 @@ static void ipc_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, tag = msg_tag_init4(0, 0, 0, -ENOENT); break; } - ipc->svr_th = container_of(source_kobj, thread_t, kobj); + thread_t *srv_th = container_of(source_kobj, thread_t, kobj); + + ref_counter_inc(&srv_th->ref); + ipc->svr_th = srv_th; ipc->user_id = f->r[2]; tag = msg_tag_init4(0, 0, 0, 0); } @@ -361,16 +436,19 @@ static void ipc_release_stage1(kobject_t *kobj) ipc_t *ipc = container_of(kobj, ipc_t, kobj); kobject_invalidate(kobj); + timeout_times_wake_ipc(ipc); if (ipc->svr_th) { ref_counter_dec_and_release(&ipc->svr_th->ref, &ipc->svr_th->kobj); } + } static void ipc_release_stage2(kobject_t *kobj) { ipc_t *ipc = container_of(kobj, ipc_t, kobj); mm_limit_free(ipc->lim, kobj); + printk("ipc 0x%x\n", kobj); } static void ipc_init(ipc_t *ipc, ram_limit_t *lim) { diff --git a/mkrtos_knl/knl/irq.c b/mkrtos_knl/knl/irq.c index 7102ec239..158a707e5 100755 --- a/mkrtos_knl/knl/irq.c +++ b/mkrtos_knl/knl/irq.c @@ -1,4 +1,13 @@ - +/** + * @file irq.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include #include #include @@ -13,6 +22,12 @@ static irq_entry_t irqs[IRQ_REG_TAB_SIZE] = {0}; static void irq_tigger(irq_entry_t *irq); +/** + * @brief 检查指定的irq号是否可用 + * + * @param inx + * @return bool_t + */ bool_t irq_check_usability(int inx) { if (inx >= IRQ_REG_TAB_SIZE) @@ -21,17 +36,40 @@ bool_t irq_check_usability(int inx) } return irqs[inx].irq_tigger_func == NULL; } -void irq_alloc(int inx, irq_sender_t *irq, void (*irq_tigger_func)(irq_entry_t *irq)) +/** + * @brief 分配一个可用的irq + * + * @param inx + * @param irq + * @param irq_tigger_func + * @return bool_t + */ +bool_t irq_alloc(int inx, irq_sender_t *irq, void (*irq_tigger_func)(irq_entry_t *irq)) { - assert(irqs[inx].irq_tigger_func == NULL); + if (irqs[inx].irq_tigger_func != NULL) + { + return FALSE; + } irqs[inx].irq = irq; irqs[inx].irq_tigger_func = irq_tigger_func; + return TRUE; } +/** + * @brief 释放一个irq + * + * @param inx + */ void irq_free(int inx) { assert(inx < IRQ_REG_TAB_SIZE); irqs[inx].irq_tigger_func = NULL; } +/** + * @brief 获取一个irq + * + * @param inx + * @return irq_entry_t* + */ irq_entry_t *irq_get(int inx) { assert(inx < IRQ_REG_TAB_SIZE); @@ -45,7 +83,7 @@ void entry_handler(void) { umword_t isr_no = arch_get_isr_no(); - isr_no -= USER_ISR_START_NO; + isr_no -= USER_ISR_START_NO; //!< 系统用的irq偏移 // printk("%d.\n", isr_no); if (!irq_check_usability(isr_no)) diff --git a/mkrtos_knl/knl/irq_sender.c b/mkrtos_knl/knl/irq_sender.c index 9ec0561c6..347e3e46c 100644 --- a/mkrtos_knl/knl/irq_sender.c +++ b/mkrtos_knl/knl/irq_sender.c @@ -1,4 +1,13 @@ - +/** + * @file irq_sender.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include #include #include @@ -8,7 +17,11 @@ #include #include #include - +#include +/** + * @brief irq sender的操作号 + * + */ enum irq_sender_op { BIND_IRQ, //!< 绑定一个中断号 @@ -23,19 +36,26 @@ enum irq_sender_op */ static void irq_tigger(irq_entry_t *irq) { - arch_disable_irq(irq->irq->irq_id); - if (irq->irq->wait_thread && thread_get_status(irq->irq->wait_thread) == THREAD_SUSPEND) + arch_disable_irq(irq->irq->irq_id); //!< 触发中断时关闭中断 + if (irq->irq->wait_thread && + thread_get_status(irq->irq->wait_thread) == THREAD_SUSPEND) //!< 线程在休眠时才能唤醒 { thread_ready(irq->irq->wait_thread, TRUE); } else { - irq->irq->irq_cn++; + irq->irq->irq_cn++; //!< 否则中断计数+1 } } +/** + * @brief 等待一个中断的来临 + * + * @param irq + * @param th + * @return int + */ int irq_sender_wait(irq_sender_t *irq, thread_t *th) { - // TODO:临界保护 umword_t status = cpulock_lock(); if (!irq->wait_thread) @@ -48,10 +68,8 @@ int irq_sender_wait(irq_sender_t *irq, thread_t *th) } else { - ref_counter_inc(&irq->wait_thread->ref); //! 线程引用计数+1 thread_suspend(irq->wait_thread); cpulock_set(status); - ref_counter_dec(&irq->wait_thread->ref); //! 线程引用计数+1 irq->wait_thread = NULL; } irq->irq_cn = 0; @@ -64,6 +82,21 @@ int irq_sender_wait(irq_sender_t *irq, thread_t *th) return -EACCES; } } +static bool_t irq_sender_unbind(irq_sender_t *irq, int irq_no) +{ + assert(irq); + if (!irq_check_usability(irq_no) && + irq_get(irq_no)->irq == irq) //!< 是否能够解绑检查 + { + irq_free(irq_no); + ref_counter_dec(&irq->ref); + return TRUE; + } + else + { + return FALSE; + } +} void irq_sender_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, entry_frame_t *f) { assert(kobj); @@ -77,65 +110,95 @@ void irq_sender_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, f->r[0] = msg_tag_init4(0, 0, 0, -EPROTO).raw; return; } + ref_counter_inc(&irq->wait_thread->ref); //! 引用计数+1 switch (sys_p.op) { case BIND_IRQ: { umword_t irq_no = f->r[1]; - if (irq_check_usability(irq_no)) + + if (irq_alloc(irq_no, irq, irq_tigger) == FALSE) { - irq->irq_id = irq_no; - irq_alloc(irq_no, irq, irq_tigger); - ref_counter_inc(&irq->ref); - arch_set_enable_irq_prio(irq_no, f->r[2] & 0xffff, f->r[2] >> 16); - tag = msg_tag_init4(0, 0, 0, 0); - } - else - { - tag = msg_tag_init4(0, 0, 0, -EACCES); + //!< 分配失败则返回错误 + tag = msg_tag_init4(0, 0, 0, -ENOENT); + break; } + irq->irq_id = irq_no; //!< 设置绑定后的irq号 + ref_counter_inc(&irq->ref); //!< 绑定后引用计数+1 + arch_set_enable_irq_prio(irq_no, f->r[2] & 0xffff, f->r[2] >> 16); //!< 绑定时设置优先级 + tag = msg_tag_init4(0, 0, 0, 0); } break; case UNBIND_IRQ: { umword_t irq_no = f->r[1]; - if (!irq_check_usability(irq_no) && irq_get(irq_no)->irq == irq) - { - irq_free(irq_no); - ref_counter_dec(&irq->ref); - tag = msg_tag_init4(0, 0, 0, 0); - } - else - { - tag = msg_tag_init4(0, 0, 0, -EACCES); - } + bool_t suc = irq_sender_unbind(irq, irq_no); + + tag = msg_tag_init4(0, 0, 0, suc ? 0 : -EACCES); } break; case WAIT_IRQ: { int ret = irq_sender_wait(irq, th); - msg_tag_init4(0, 0, 0, ret); + tag = msg_tag_init4(0, 0, 0, ret); } break; case ACK_IRQ: { arch_enable_irq(irq->irq_id); + tag = msg_tag_init4(0, 0, 0, 0); } break; default: break; } + ref_counter_dec_and_release(&irq->wait_thread->ref, &irq->kobj); //! 引用计数+1 + f->r[0] = tag.raw; } +static bool_t irq_sender_put(kobject_t *kobj) +{ + irq_sender_t *irq = container_of(kobj, irq_sender_t, kobj); + + return ref_counter_dec(&irq->ref) == 1; +} +static void irq_sender_stage1(kobject_t *kobj) +{ + irq_sender_t *irq = container_of(kobj, irq_sender_t, kobj); + kobject_invalidate(kobj); //!< 设置kobj为无效 + irq_sender_unbind(irq, irq->irq_id); //!< 解除绑定 +} +static void irq_sender_stage2(kobject_t *kobj) +{ + irq_sender_t *th = container_of(kobj, irq_sender_t, kobj); + task_t *cur_task = thread_get_current_task(); + + mm_limit_free(cur_task->lim, th); + printk("irq_sender 0x%x\n", kobj); +} +/** + * @brief 初始化 + * + * @param irq + */ void irq_sender_init(irq_sender_t *irq) { kobject_init(&irq->kobj); ref_counter_init(&irq->ref); ref_counter_inc(&irq->ref); irq->kobj.invoke_func = irq_sender_syscall; + irq->kobj.stage_1_func = irq_sender_stage1; + irq->kobj.stage_2_func = irq_sender_stage2; + irq->kobj.put_func = irq_sender_put; irq->irq_id = IRQ_INVALID_NO; irq->irq_cn = 0; } +/** + * @brief 创建一个irq_sender_t + * + * @param lim + * @return irq_sender_t* + */ static irq_sender_t *irq_create(ram_limit_t *lim) { irq_sender_t *irq = mm_limit_alloc(lim, sizeof(irq_sender_t)); @@ -147,6 +210,16 @@ static irq_sender_t *irq_create(ram_limit_t *lim) irq_sender_init(irq); return irq; } +/** + * @brief 创建函数 + * + * @param lim + * @param arg0 + * @param arg1 + * @param arg2 + * @param arg3 + * @return kobject_t* + */ static kobject_t *irq_create_func(ram_limit_t *lim, umword_t arg0, umword_t arg1, umword_t arg2, umword_t arg3) { diff --git a/mkrtos_knl/knl/log.c b/mkrtos_knl/knl/log.c index e60d0ce04..899d7c3ae 100755 --- a/mkrtos_knl/knl/log.c +++ b/mkrtos_knl/knl/log.c @@ -43,6 +43,9 @@ static void log_reg(void) // kobject_init(&log.kobj); irq_sender_init(&log.kobj); log.kobj.kobj.invoke_func = log_syscall; + log.kobj.kobj.stage_1_func = kobject_release_stage1; + log.kobj.kobj.stage_2_func = kobject_release_stage2; + log.kobj.kobj.put_func = kobject_put; global_reg_kobj(&log.kobj.kobj, LOG_PROT); irq_alloc(37 /*USART1_IRQn*/, &log.kobj, log_trigger); } diff --git a/mkrtos_knl/knl/map.c b/mkrtos_knl/knl/map.c index 52e523906..695a9205a 100755 --- a/mkrtos_knl/knl/map.c +++ b/mkrtos_knl/knl/map.c @@ -1,3 +1,13 @@ +/** + * @file map.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "map.h" #include "types.h" #include "obj_space.h" diff --git a/mkrtos_knl/knl/misc.c b/mkrtos_knl/knl/misc.c index 700c61efb..30805e9fc 100644 --- a/mkrtos_knl/knl/misc.c +++ b/mkrtos_knl/knl/misc.c @@ -1,4 +1,13 @@ - +/** + * @file misc.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" #include "mm_wrap.h" #include "mm.h" diff --git a/mkrtos_knl/knl/mm.c b/mkrtos_knl/knl/mm.c index 6f1d39f75..11bcf9c13 100755 --- a/mkrtos_knl/knl/mm.c +++ b/mkrtos_knl/knl/mm.c @@ -1,3 +1,13 @@ +/** + * @file mm.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "mm.h" void mem_init(mem_t *_this) diff --git a/mkrtos_knl/knl/mm_man.c b/mkrtos_knl/knl/mm_man.c index a97397d46..9b7ec7fe3 100644 --- a/mkrtos_knl/knl/mm_man.c +++ b/mkrtos_knl/knl/mm_man.c @@ -1,3 +1,13 @@ +/** + * @file mm_man.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" #include "kobject.h" #include "init.h" diff --git a/mkrtos_knl/knl/mm_page.c b/mkrtos_knl/knl/mm_page.c index b7e418589..1b4d4bef1 100644 --- a/mkrtos_knl/knl/mm_page.c +++ b/mkrtos_knl/knl/mm_page.c @@ -1,3 +1,13 @@ +/** + * @file mm_page.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" #include "mm_space.h" #include "mm_wrap.h" diff --git a/mkrtos_knl/knl/mm_space.c b/mkrtos_knl/knl/mm_space.c index 9b33ac34f..5f9c38a1c 100644 --- a/mkrtos_knl/knl/mm_space.c +++ b/mkrtos_knl/knl/mm_space.c @@ -1,4 +1,13 @@ - +/** + * @file mm_space.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" #include "util.h" #include "mm_space.h" diff --git a/mkrtos_knl/knl/mm_wrap.c b/mkrtos_knl/knl/mm_wrap.c index 89804b4e0..c920f392c 100755 --- a/mkrtos_knl/knl/mm_wrap.c +++ b/mkrtos_knl/knl/mm_wrap.c @@ -1,3 +1,13 @@ +/** + * @file mm_wrap.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "mm_wrap.h" #include "types.h" #include "mm.h" diff --git a/mkrtos_knl/knl/obj_space.c b/mkrtos_knl/knl/obj_space.c index f1c599bb7..4bea9e169 100755 --- a/mkrtos_knl/knl/obj_space.c +++ b/mkrtos_knl/knl/obj_space.c @@ -1,4 +1,13 @@ - +/** + * @file obj_space.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "obj_space.h" #include "types.h" diff --git a/mkrtos_knl/knl/printk.c b/mkrtos_knl/knl/printk.c index 0329dca25..ac43baae2 100755 --- a/mkrtos_knl/knl/printk.c +++ b/mkrtos_knl/knl/printk.c @@ -1,12 +1,12 @@ /** * @file printk.c * @author zhangzheng (1358745329@qq.com) - * @brief + * @brief * @version 0.1 * @date 2023-09-14 - * + * * @copyright Copyright (c) 2023 - * + * */ #include "printk.h" #include "stdarg.h" @@ -53,7 +53,7 @@ void printk(const char *fmt, ...) va_list args; umword_t state = 0; - spinlock_lock(&lock); + state = spinlock_lock(&lock); va_start(args, fmt); xvsprintf(print_cache, fmt, args); va_end(args); diff --git a/mkrtos_knl/knl/ram_limit.c b/mkrtos_knl/knl/ram_limit.c index 6af6bec72..bd397b63e 100755 --- a/mkrtos_knl/knl/ram_limit.c +++ b/mkrtos_knl/knl/ram_limit.c @@ -1,3 +1,13 @@ +/** + * @file ram_limit.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "ram_limit.h" #include "types.h" void ram_limit_init(ram_limit_t *limit, size_t max) diff --git a/mkrtos_knl/knl/ref.c b/mkrtos_knl/knl/ref.c index 0c2dab87a..02e1452c1 100644 --- a/mkrtos_knl/knl/ref.c +++ b/mkrtos_knl/knl/ref.c @@ -1,3 +1,13 @@ +/** + * @file ref.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "ref.h" #include int ref_counter_dec_and_release(ref_counter_t *ref, kobject_t *kobj) diff --git a/mkrtos_knl/knl/scheduler.c b/mkrtos_knl/knl/scheduler.c index cdde54287..9c4f3c8c3 100755 --- a/mkrtos_knl/knl/scheduler.c +++ b/mkrtos_knl/knl/scheduler.c @@ -1,10 +1,12 @@ -/* - * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git - * @Date: 2023-08-14 09:47:54 - * @LastEditors: zhangzheng 1358745329@qq.com - * @LastEditTime: 2023-08-18 15:50:09 - * @FilePath: /mkrtos-real/mkrtos_knl/knl/scheduler.c - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE +/** + * @file scheduler.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * */ #include "scheduler.h" #include "util.h" diff --git a/mkrtos_knl/knl/spinlock.c b/mkrtos_knl/knl/spinlock.c index 029a7fa13..e3de9f929 100755 --- a/mkrtos_knl/knl/spinlock.c +++ b/mkrtos_knl/knl/spinlock.c @@ -1,3 +1,13 @@ +/** + * @file spinlock.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" #include "cpulock.h" #include "spinlock.h" @@ -9,7 +19,7 @@ void spinlock_invalidate(spinlock_t *lock) { // TODO:原子操作 umword_t status = 0; - cpulock_lock(); + status = cpulock_lock(); lock->val |= 1UL; cpulock_set(status); } diff --git a/mkrtos_knl/knl/sys.c b/mkrtos_knl/knl/sys.c index db1d6520d..9ff1087f4 100755 --- a/mkrtos_knl/knl/sys.c +++ b/mkrtos_knl/knl/sys.c @@ -23,7 +23,7 @@ typedef struct sys kobject_t kobj; } sys_t; -static sys_t sys_boj; +static sys_t sys_obj; enum sys_op { @@ -34,9 +34,9 @@ static void sys_syscall(kobject_t *kobj, syscall_prot_t sys_p, msg_tag_t in_tag, static void sys_reg(void) { - kobject_init(&sys_boj.kobj); - sys_boj.kobj.invoke_func = sys_syscall; - global_reg_kobj(&sys_boj.kobj, SYS_PROT); + kobject_init(&sys_obj.kobj); + sys_obj.kobj.invoke_func = sys_syscall; + global_reg_kobj(&sys_obj.kobj, SYS_PROT); } INIT_KOBJ(sys_reg); diff --git a/mkrtos_knl/knl/task.c b/mkrtos_knl/knl/task.c index 48208c26d..15ea803c6 100755 --- a/mkrtos_knl/knl/task.c +++ b/mkrtos_knl/knl/task.c @@ -1,3 +1,14 @@ +/** + * @file task.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ + #include "task.h" #include "kobject.h" #include "factory.h" diff --git a/mkrtos_knl/knl/thread.c b/mkrtos_knl/knl/thread.c index 800e08e49..676a6ee29 100755 --- a/mkrtos_knl/knl/thread.c +++ b/mkrtos_knl/knl/thread.c @@ -1,10 +1,12 @@ -/* - * @Author: zhangzheng 1358745329@qq.com - * @Date: 2023-08-14 09:47:54 - * @LastEditors: zhangzheng 1358745329@qq.com - * @LastEditTime: 2023-08-18 16:21:20 - * @FilePath: /mkrtos-real/mkrtos_knl/knl/thread.c - * @Description: 线程管理相关 +/** + * @file thread.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * */ #include "types.h" @@ -54,17 +56,18 @@ static void thread_release_stage1(kobject_t *kobj) { thread_t *th = container_of(kobj, thread_t, kobj); kobject_invalidate(kobj); + thread_unbind(th); if (th->status == THREAD_READY) { thread_suspend(th); } - thread_unbind(th); } static void thread_release_stage2(kobject_t *kobj) { thread_t *th = container_of(kobj, thread_t, kobj); thread_t *cur_th = thread_get_current(); + printk("thread 0x%x\n", kobj); mm_limit_free_align(th->lim, kobj, THREAD_BLOCK_SIZE); if (cur_th == th) diff --git a/mkrtos_knl/knl/thread_armv7m.c b/mkrtos_knl/knl/thread_armv7m.c index 6110c72d5..60d56231e 100644 --- a/mkrtos_knl/knl/thread_armv7m.c +++ b/mkrtos_knl/knl/thread_armv7m.c @@ -1,10 +1,12 @@ -/* - * @Author: zhangzheng 1358745329@qq.com - * @Date: 2023-08-18 15:03:16 - * @LastEditors: zhangzheng 1358745329@qq.com - * @LastEditTime: 2023-08-18 16:22:11 - * @FilePath: /mkrtos-real/mkrtos_knl/knl/thread_armv7m.c - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE +/** + * @file thread_armv7m.c + * @author zhangzheng (135874329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * */ #include "types.h" diff --git a/mkrtos_knl/knl/thread_knl.c b/mkrtos_knl/knl/thread_knl.c index 887a091a9..80ccc8bf2 100755 --- a/mkrtos_knl/knl/thread_knl.c +++ b/mkrtos_knl/knl/thread_knl.c @@ -1,10 +1,12 @@ -/* - * @Author: zhangzheng 1358745329@qq.com - * @Date: 2023-08-14 09:47:54 - * @LastEditors: zhangzheng 1358745329@qq.com - * @LastEditTime: 2023-08-18 16:21:58 - * @FilePath: /mkrtos-real/mkrtos_knl/knl/thread_knl.c - * @Description: 内核线程初始化 +/** + * @file thread_knl.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * */ #include "types.h" diff --git a/mkrtos_knl/knl/util.c b/mkrtos_knl/knl/util.c index 1ccbf57dc..e2169c579 100644 --- a/mkrtos_knl/knl/util.c +++ b/mkrtos_knl/knl/util.c @@ -1,3 +1,13 @@ +/** + * @file util.c + * @author zhangzheng (1358745329@qq.com) + * @brief + * @version 0.1 + * @date 2023-09-29 + * + * @copyright Copyright (c) 2023 + * + */ #include "types.h" int ffs(int x) diff --git a/mkrtos_user/lib/sys_svr/src/ns_cli.c b/mkrtos_user/lib/sys_svr/src/ns_cli.c index f313a98cf..9f6246eed 100644 --- a/mkrtos_user/lib/sys_svr/src/ns_cli.c +++ b/mkrtos_user/lib/sys_svr/src/ns_cli.c @@ -59,119 +59,10 @@ RPC_GENERATION_CALL2(ns_t, NS_REGISTER_OP, register, rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path, rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_IN, RPC_TYPE_BUF, svr_hd) -// RPC_GENERATION_CALL2(ns_t, NS_QUERY_OP, query, -// rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path, -// rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_INOUT, RPC_TYPE_BUF, cli_hd) -msg_tag_t ns_t_query_call(obj_handler_t hd, rpc_ref_array_uint32_t_uint8_t_32_t *var0, rpc_obj_handler_t_t *var1) -{ - void *buf; - ipc_msg_t *msg_ipc; - thread_msg_buf_get(2, (umword_t *)(&buf), ((void *)0)); - msg_ipc = (ipc_msg_t *)buf; - int off = 0; - int off_buf = 0; - int ret = -1; - size_t op_val = ((uint16_t)1); - rpc_memcpy(msg_ipc->msg_buf, &op_val, sizeof(op_val)); - off += rpc_align(sizeof(op_val), __alignof(((uint16_t)1))); - do - { - if (1 == 1) - { - if (1 == 1 || 1 == 4) - { - int ret = rpc_cli_msg_to_buf_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off); - if (ret < 0) - { - return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)}); - } - off = ret; - } - } - } while (0); - do - { - if (1 == 2) - { - if (1 == 1 || 1 == 4) - { - int ret = rpc_cli_msg_to_buf_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf); - if (ret < 0) - { - return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)}); - } - off_buf = ret; - } - } - } while (0); - do - { - if (2 == 1) - { - if (4 == 1 || 4 == 4) - { - int ret = rpc_cli_msg_to_buf_rpc_obj_handler_t_t(var1, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off); - if (ret < 0) - { - return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)}); - } - off = ret; - } - } - } while (0); - do - { - if (2 == 2) - { - if (4 == 1 || 4 == 4) - { - int ret = rpc_cli_msg_to_buf_rpc_obj_handler_t_t(var1, (uint8_t *)((uint8_t *)msg_ipc->map_buf), off_buf); - if (ret < 0) - { - return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)}); - } - off_buf = ret; - } - } - } while (0); - msg_tag_t tag = ipc_call(hd, ((msg_tag_t){.flags = (0), .msg_buf_len = ((((off) / ((sizeof(void *)))) + (((off) % ((sizeof(void *)))) ? 1 : 0))), .map_buf_len = (0), .prot = (0)}), ipc_timeout_create2(0, 0)); - if (((int16_t)((tag).prot)) < 0) - { - return tag; - } - off = 0; - do - { - if (1 == 1) - { - if (1 == 2 || 1 == 4) - { - int ret = rpc_cli_buf_to_msg_rpc_ref_array_uint32_t_uint8_t_32_t(var0, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *))); - if (ret < 0) - { - return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)}); - } - off = ret; - } - } - } while (0); - do - { - if (2 == 1) - { - if (4 == 2 || 4 == 4) - { - int ret = rpc_cli_buf_to_msg_rpc_obj_handler_t_t(var1, (uint8_t *)((uint8_t *)msg_ipc->msg_buf), off, tag.msg_buf_len * (sizeof(void *))); - if (ret < 0) - { - return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)}); - } - off = ret; - } - } - } while (0); - return tag; -} +RPC_GENERATION_CALL2(ns_t, NS_QUERY_OP, query, + rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path, + rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_INOUT, RPC_TYPE_BUF, cli_hd) + int ns_register(const char *path, obj_handler_t svr_hd) { assert(path); diff --git a/mkrtos_user/lib/sys_svr/src/ns_svr.c b/mkrtos_user/lib/sys_svr/src/ns_svr.c index 192ff04f4..8863ce602 100644 --- a/mkrtos_user/lib/sys_svr/src/ns_svr.c +++ b/mkrtos_user/lib/sys_svr/src/ns_svr.c @@ -15,11 +15,11 @@ RPC_GENERATION_OP2(ns_t, NS_REGISTER_OP, register, int ret = namespace_register((char *)(path->data), obj->hd); if (ret >= 0) { - printf("注册服务[%s]成功.\n", (char *)(path->data)); + printf("register [%s] success.\n", (char *)(path->data)); } else { - printf("注册服务[%s]失败.\n", (char *)(path->data)); + printf("register [%s] fail.\n", (char *)(path->data)); } return ret; } diff --git a/mkrtos_user/server/init/src/main.c b/mkrtos_user/server/init/src/main.c index 90838c0b0..ec18e26d0 100644 --- a/mkrtos_user/server/init/src/main.c +++ b/mkrtos_user/server/init/src/main.c @@ -29,12 +29,12 @@ int main(int argc, char *args[]) printf_test(); thread_test(); thread_exit_test(); - ipc_test(); map_test(); ipc_timeout_test(); mm_test(); app_test(); #endif + ipc_test(); uenv_t env = *u_get_global_env(); obj_handler_t ipc_hd; int ret = rpc_creaite_bind_ipc(THREAD_MAIN, NULL, &ipc_hd); @@ -47,14 +47,14 @@ int main(int argc, char *args[]) // printf("app load fail, 0x%x\n", ret); // } - ret = app_load("app", &env); - if (ret < 0) - { - printf("app load fail, 0x%x\n", ret); - } - namespace_init(ipc_hd); + // ret = app_load("app", &env); + // if (ret < 0) + // { + // printf("app load fail, 0x%x\n", ret); + // } + // namespace_init(ipc_hd); - namespace_loop(); + // namespace_loop(); task_unmap(TASK_THIS, vpage_create_raw3(KOBJ_DELETE_RIGHT, 0, TASK_THIS)); // 删除当前task,以及申请得所有对象 printf("exit init.\n"); return 0;