| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2022-2023, The Puppy RTOS Authors | ||
| 3 | * | ||
| 4 | * SPDX-License-Identifier: Apache-2.0 | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <puppy.h> | ||
| 8 | #include <puppy/kobj.h> | ||
| 9 | #include <string.h> | ||
| 10 | |||
| 11 | #define KLOG_TAG "obj" | ||
| 12 | #define KLOG_LVL KLOG_WARNING | ||
| 13 | #include <puppy/klog.h> | ||
| 14 | |||
| 15 | static p_list_t _g_obj_list = P_LIST_STATIC_INIT(&_g_obj_list); | ||
| 16 | |||
| 17 | 55 | void p_obj_init(p_obj_t obj, const char *name, uint8_t type, uint8_t ex_type) | |
| 18 | { | ||
| 19 | 55 | struct p_obj *object = obj; | |
| 20 | p_base_t key; | ||
| 21 | |||
| 22 | KLOG_D("p_obj_init --> [%s]@0x%x, type:%x, ex_type:%x...", name, object, type, ex_type); | ||
| 23 | 55 | object->name = name; | |
| 24 | 55 | type = type & (P_OBJ_TYPE_MASK | P_OBJ_TYPE_STATIC); | |
| 25 | 55 | object->type = (uint16_t)type | ((uint16_t)ex_type << 8); | |
| 26 | 55 | key = arch_irq_lock(); | |
| 27 | 55 | p_list_append(&_g_obj_list, &object->node); | |
| 28 | 55 | arch_irq_unlock(key); | |
| 29 | KLOG_D("done"); | ||
| 30 | 55 | } | |
| 31 | |||
| 32 | ✗ | bool p_obj_is_static(p_obj_t obj) | |
| 33 | { | ||
| 34 | ✗ | struct p_obj *object = obj; | |
| 35 | ✗ | return ((object->type & P_OBJ_TYPE_STATIC) == P_OBJ_TYPE_STATIC); | |
| 36 | } | ||
| 37 | 2373 | uint8_t p_obj_get_type(p_obj_t obj) | |
| 38 | { | ||
| 39 | 2373 | struct p_obj *object = obj; | |
| 40 | |||
| 41 | 2373 | return object->type & P_OBJ_TYPE_MASK; | |
| 42 | } | ||
| 43 | 263 | uint8_t p_obj_get_extype(p_obj_t obj) | |
| 44 | { | ||
| 45 | 263 | struct p_obj *object = obj; | |
| 46 | |||
| 47 | 263 | return object->type >> 8; | |
| 48 | } | ||
| 49 | 46 | void p_obj_deinit(p_obj_t obj) | |
| 50 | { | ||
| 51 | 46 | struct p_obj *object = obj; | |
| 52 | p_base_t key; | ||
| 53 | KLOG_D("p_obj_deinit --> [%s]@0x%x, type:%x...", object->name, object, object->type); | ||
| 54 | 46 | key = arch_irq_lock(); | |
| 55 | 46 | p_list_remove(&object->node); | |
| 56 | 46 | arch_irq_unlock(key); | |
| 57 | KLOG_D("done"); | ||
| 58 | 46 | } | |
| 59 | |||
| 60 | ✗ | p_obj_t p_obj_find(const char *name) | |
| 61 | { | ||
| 62 | p_node_t *node; | ||
| 63 | struct p_obj *object; | ||
| 64 | |||
| 65 | ✗ | p_list_for_each_node(&_g_obj_list, node) | |
| 66 | { | ||
| 67 | ✗ | object = p_list_entry(node, struct p_obj, node); | |
| 68 | ✗ | if (strncmp(object->name, name, INT32_MAX - 1) == 0) | |
| 69 | { | ||
| 70 | ✗ | return object; | |
| 71 | } | ||
| 72 | } | ||
| 73 | ✗ | return NULL; | |
| 74 | } | ||
| 75 | |||
| 76 | ✗ | void list_thread(void) | |
| 77 | { | ||
| 78 | p_node_t *node; | ||
| 79 | struct p_obj *object; | ||
| 80 | int maxlen; | ||
| 81 | |||
| 82 | ✗ | maxlen = 8; | |
| 83 | |||
| 84 | ✗ | printk("thread cpu bind pri state stack size max used left tick error\n"); | |
| 85 | ✗ | printk("------- --- ---- --- ------- ---------- ------ ---------- ------\n"); | |
| 86 | |||
| 87 | ✗ | p_list_for_each_node(&_g_obj_list, node) | |
| 88 | { | ||
| 89 | ✗ | object = p_list_entry(node, struct p_obj, node); | |
| 90 | ✗ | if (p_obj_get_type(object) != P_OBJ_TYPE_THREAD) | |
| 91 | { | ||
| 92 | ✗ | continue; | |
| 93 | } | ||
| 94 | { | ||
| 95 | uint8_t stat; | ||
| 96 | uint8_t *ptr; | ||
| 97 | ✗ | struct _thread_obj *thread = (struct _thread_obj *)object; | |
| 98 | |||
| 99 | ✗ | if (thread->oncpu != CPU_NA) | |
| 100 | { | ||
| 101 | ✗ | printk("%-*.*s %3d %3d %3d ", maxlen, maxlen, thread->kobj.name, thread->oncpu, thread->bindcpu, thread->prio); | |
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | ✗ | printk("%-*.*s %s %3d %3d ", maxlen, maxlen, thread->kobj.name, "N/A", thread->bindcpu, thread->prio); | |
| 106 | } | ||
| 107 | |||
| 108 | ✗ | stat = thread->state; | |
| 109 | ✗ | if (stat == P_THREAD_STATE_READY) printk(" ready "); | |
| 110 | ✗ | else if (stat == P_THREAD_STATE_BLOCK) printk(" blocked"); | |
| 111 | ✗ | else if (stat == P_THREAD_STATE_INIT) printk(" init "); | |
| 112 | ✗ | else if (stat == P_THREAD_STATE_DEAD) printk(" dead "); | |
| 113 | ✗ | else if (stat == P_THREAD_STATE_RUN) printk(" running"); | |
| 114 | ✗ | else if (stat == P_THREAD_STATE_SLEEP) printk(" sleep "); | |
| 115 | |||
| 116 | ✗ | ptr = (uint8_t *)thread->stack_addr; | |
| 117 | ✗ | while (*ptr == '#') ptr ++; | |
| 118 | ✗ | printk(" 0x%08x %02d%% 0x%08x %s\n", | |
| 119 | thread->stack_size, | ||
| 120 | ✗ | (thread->stack_size - ((p_ubase_t) ptr - (p_ubase_t) thread->stack_addr)) * 100 | |
| 121 | ✗ | / thread->stack_size, | |
| 122 | thread->slice_ticks, | ||
| 123 | p_errno_str(thread->errno)); | ||
| 124 | } | ||
| 125 | } | ||
| 126 | ✗ | } | |
| 127 |