驱动支持completion

This commit is contained in:
zhangzheng
2023-11-21 22:18:46 +08:00
parent 13fd264adf
commit 7336f4a480
6 changed files with 31 additions and 33 deletions

View File

@@ -117,11 +117,11 @@ int app_load(const char *name, uenv_t *cur_env)
{
goto end_del_obj;
}
// tag = task_map(hd_task, hd_ipc, hd_ipc, 0);
// if (msg_tag_get_prot(tag) < 0)
// {
// goto end_del_obj;
// }
tag = task_map(hd_task, FUTEX_PROT, FUTEX_PROT, KOBJ_DELETE_RIGHT);
if (msg_tag_get_prot(tag) < 0)
{
goto end_del_obj;
}
tag = task_map(hd_task, hd_thread, THREAD_MAIN, 0);
if (msg_tag_get_prot(tag) < 0)
{

View File

@@ -13,8 +13,7 @@
/* 完成量控制块 */
static struct rt_completion completion;
__attribute__((aligned(RT_ALIGN_SIZE)))
static char thread1_stack[2048];
__attribute__((aligned(RT_ALIGN_SIZE))) static char thread1_stack[2048];
static struct rt_thread thread1;
/* 线程 1 入口函数 */
@@ -27,8 +26,7 @@ static void thread1_completion_wait(void *param)
rt_kprintf("thread1 leave.\n");
}
__attribute__((aligned(RT_ALIGN_SIZE)))
static char thread2_stack[2048];
__attribute__((aligned(RT_ALIGN_SIZE))) static char thread2_stack[2048];
static struct rt_thread thread2;
/* 线程 2 入口 */

View File

@@ -21,9 +21,9 @@ int main(void)
dfs_init();
#if 0
rtthread_drv_test();
#endif
completion_sample();
#endif
rtthread_drv_test();
/* set LED0 pin mode to output */
rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);

View File

@@ -10,7 +10,7 @@
#include <assert.h>
#include <u_thread.h>
#include <u_ipc.h>
#include <atomic.h>
extern unsigned long get_thread_area(void);
rt_weak void *rt_calloc(rt_size_t count, rt_size_t size)
@@ -57,34 +57,31 @@ rt_err_t rt_thread_yield(void)
return 0;
}
static umword_t intr_status = 0;
static bool_t to_suspend;
static bool_t to_run;
static rt_thread_t to_suspend;
static rt_thread_t to_run;
rt_base_t rt_hw_interrupt_disable(void)
{
rt_base_t old = intr_status;
rt_base_t old;
unsigned long area = get_thread_area();
if (intr_status != 0)
if (intr_status == area)
{
while (intr_status != get_thread_area())
;
return intr_status;
}
intr_status = get_thread_area();
while (old = a_cas((volatile int *)(&intr_status), 0, area))
;
return old;
}
void rt_hw_interrupt_enable(rt_base_t level)
{
rt_thread_t thread;
thread = rt_thread_self();
if (level == 0)
{
if (to_run)
{
rt_thread_t tmp = to_run;
to_run = 0;
pthread_mutex_unlock(&thread->suspend_lock);
u_sleep_ms(1);
pthread_mutex_lock(&thread->suspend_lock);
pthread_mutex_unlock(&tmp->suspend_lock);
}
}
intr_status = level;
@@ -93,10 +90,12 @@ void rt_hw_interrupt_enable(rt_base_t level)
if (to_suspend)
{
thread->stat = RT_THREAD_SUSPEND;
rt_thread_t tmp = to_suspend;
tmp->stat = RT_THREAD_SUSPEND;
to_suspend = 0;
pthread_mutex_lock(&thread->suspend_lock);
thread->stat = 0;
pthread_mutex_lock(&tmp->suspend_lock);
tmp->stat = 0;
}
}
}
@@ -182,7 +181,7 @@ rt_err_t rt_thread_suspend_with_flag(rt_thread_t thread, int suspend_flag)
}
else
{
to_suspend = 1;
to_suspend = thread;
}
return 0;
}
@@ -198,7 +197,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
}
else
{
to_suspend = 1;
to_suspend = thread;
}
return 0;
}
@@ -207,12 +206,11 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
if (!rt_hw_interrupt_is_disabled())
{
pthread_mutex_unlock(&thread->suspend_lock);
pthread_mutex_lock(&thread->suspend_lock);
printf("[drv]%s:%d\n", __func__, __LINE__);
}
else
{
to_run = 1;
to_run = thread;
}
return 0;
}

View File

@@ -60,6 +60,8 @@ void rtthread_drv_test(void)
assert(rt_thread_self != 0);
#if 0
rt_thread_resume(rt_thread_self());
rt_thread_suspend(rt_thread_self());

View File

@@ -36,8 +36,8 @@ int main(int argc, char *args[])
thread_press_test();
kobj_create_press_test();
ipc_test();
pthread_lock_test();
pthread_cond_lock_test();
pthread_lock_test();
#endif
uenv_t env = *u_get_global_env();
obj_handler_t ipc_hd;