Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
completion完成量
2.1.0版本UART发送完成,和dma用到的queue和rt_completion_init问题
发布于 2017-08-11 15:49:03 浏览:3308
订阅该版
在用rt-thread2.1.0的串口的时候,之前只是看看没有深入研究,最近打算仔细研究下,特别是DMA那块。 发现serial.c中的会用到 ```c void rt_completion_init(struct rt_completion *completion), rt_err_t rt_completion_wait(struct rt_completion *completion, rt_int32_t timeout), void rt_completion_done(struct rt_completion *completion) ``` 这三个函数,一般都用在串口的发送中,字面可以理解是发送、等待、和发送完成。 但看了源码除了里面有定时器,以及suspend的链表,其他的有些不懂到底是个什么机制呢? (网上百度了好多,貌似没有人问这个问题)。 还有就是dataqueue.c这个好像主要用在dma发送,先push,dma发送在pop,但是看源码有点云里雾里了,有没有代码的注释呢? 希望大神能给些指点,多谢了
查看更多
8
个回答
默认排序
按发布时间排序
bernard
2017-08-11
这家伙很懒,什么也没写!
rt_completion_wait --> 等待一个工作结束; rt_completion_done --> 通知这个工作已经完成了;
qq_哎
2017-08-11
这家伙很懒,什么也没写!
>rt_completion_wait --> 等待一个工作结束; rt_completion_done --> 通知这个工作已经完成了; ```c rt_err_t rt_completion_wait(struct rt_completion *completion, rt_int32_t timeout) { rt_err_t result; rt_base_t level; rt_thread_t thread; RT_ASSERT(completion != RT_NULL); result = RT_EOK; thread = rt_thread_self(); level = rt_hw_interrupt_disable(); if (completion->flag != RT_COMPLETED) { /* only one thread can suspend on complete */ RT_ASSERT(rt_list_isempty(&(completion->suspended_list))); if (timeout == 0) { result = -RT_ETIMEOUT; goto __exit; } else { /* reset thread error number */ thread->error = RT_EOK; /* suspend thread */ rt_thread_suspend(thread); /* add to suspended list */ rt_list_insert_before(&(completion->suspended_list), &(thread->tlist)); /* current context checking */ RT_DEBUG_NOT_IN_INTERRUPT; /* start timer */ if (timeout > 0) { /* reset the timeout of thread timer and start it */ rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout); rt_timer_start(&(thread->thread_timer)); } /* enable interrupt */ rt_hw_interrupt_enable(level); /* do schedule */ rt_schedule(); /* thread is waked up */ result = thread->error; level = rt_hw_interrupt_disable(); } } /* clean completed flag */ completion->flag = RT_UNCOMPLETED; __exit: rt_hw_interrupt_enable(level); return result; }。 ``` 看了下函数源码,挂起当前线程,然后放入到挂起链表中,然后开起定时器,再调度。。 还是不太明白这样的话是在等待什么完成呢?还有完成的时候是从挂起链表中取出,然后恢复线程。这个到底是怎么通知? 我觉得这种等待完成,可以是用一个事件来做,超时了返回错误,没超时就正确。
bernard
2017-08-11
这家伙很懒,什么也没写!
论坛贴代码,不加格式。。。算了,还是不看了
qq_哎
2017-08-11
这家伙很懒,什么也没写!
```c rt_err_t rt_completion_wait(struct rt_completion *completion, rt_int32_t timeout) { rt_err_t result; rt_base_t level; rt_thread_t thread; RT_ASSERT(completion != RT_NULL); result = RT_EOK; thread = rt_thread_self(); level = rt_hw_interrupt_disable(); if (completion->flag != RT_COMPLETED) { /* only one thread can suspend on complete */ RT_ASSERT(rt_list_isempty(&(completion->suspended_list))); if (timeout == 0) { result = -RT_ETIMEOUT; goto __exit; } else { /* reset thread error number */ thread->error = RT_EOK; /* suspend thread */ rt_thread_suspend(thread); /* add to suspended list */ rt_list_insert_before(&(completion->suspended_list), &(thread->tlist)); /* current context checking */ RT_DEBUG_NOT_IN_INTERRUPT; /* start timer */ if (timeout > 0) { /* reset the timeout of thread timer and start it */ rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout); rt_timer_start(&(thread->thread_timer)); } /* enable interrupt */ rt_hw_interrupt_enable(level); /* do schedule */ rt_schedule(); /* thread is waked up */ result = thread->error; level = rt_hw_interrupt_disable(); } } /* clean completed flag */ completion->flag = RT_UNCOMPLETED; __exit: rt_hw_interrupt_enable(level); return result; }。 ``` 呃,才学会加格式,,,,
qq_哎
2017-08-11
这家伙很懒,什么也没写!
仔细看了下这两个函数的调用, rt_completion_wait是在串口发送数据之后的时候调用(将当前线程放入到rt_completion 变量的挂起链表中 ), rt_completion_done是在中断里调用(从rt_completion 变量的挂起链表中将线程取出,并恢复resume)。 但是这个机制好像还是不太明白整个的过程是什么作用
aozima
2017-08-11
调网络不抓包,调I2C等时序不上逻辑分析仪,就像电工不用万用表!多用整理的好的文字,比截图更省流量,还能在整理过程中思考。
就当成只有一个人使用的event或是sem就可以了。 比event和sem轻量
qq_哎
2017-08-11
这家伙很懒,什么也没写!
>就当成只有一个人使用的event或是sem就可以了。 >比event和sem轻量 --- 哦哦,多谢,那我在多看看event和sem的源码,再理解一下,谢了~
撰写答案
登录
注册新账号
关注者
0
被浏览
3.3k
关于作者
qq_哎
这家伙很懒,什么也没写!
提问
6
回答
26
被采纳
0
关注TA
发私信
相关问题
1
scons编译提示没找到adc.h文件
2
rt_completion_wait 使用
3
rtthread中的completion.c是用来干什么的?
4
Can 发送卡在rt_completion_wait函数
5
rt_completion_wait不能用在ISR里
6
completion使用问题
7
completion,dataqueue,waitqueue等文件的使用说明在哪?
8
完成量的使用,rt_completion_done()函数可以在中断里调用吗?
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
国产MCU移植系列教程汇总,欢迎查看!
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【RA8D1-Vision Board】基于RT-Thread的UART实践
2
【RA8D1-Vision Board】基于RT-Thread的usb设备msc驱动测试
3
【RA8D1-Vision Board】基于RT-Thread的usb设备cdc驱动测试
4
NXP MCXN947测评:ETH设备(二)提交了关于ETH设备的PR
5
【RA8D1-Vision Board】 RA8D1 Vision Board上的USB实践
热门标签
RT-Thread Studio
串口
LWIP
Env
SPI
Bootloader
AT
ART-Pi
Hardfault
CAN总线
FinSH
USB
文件系统
DMA
RT-Thread
SCons
线程
RT-Thread Nano
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
ota在线升级
WIZnet_W5500
I2C_IIC
UART
flash
cubemx
packages_软件包
freemodbus
潘多拉开发板_Pandora
PWM
定时器
ADC
BSP
中断
编译报错
socket
keil_MDK
GD32
MicroPython
msh
Debug
ulog
SFUD
flashDB
SDIO总线
rt_mq_消息队列_msg_queue
本月问答贡献
用户名由3_15位
23
个答案
3
次被采纳
踩姑娘的小蘑菇
16
个答案
3
次被采纳
xiaorui
7
个答案
3
次被采纳
sakumisu
5
个答案
3
次被采纳
三世执戟
32
个答案
1
次被采纳
本月文章贡献
比特饼干
4
篇文章
13
次点赞
ZVML_9668
3
篇文章
2
次点赞
Z_Y
2
篇文章
5
次点赞
xusiwei1236
2
篇文章
3
次点赞
yinxiangxv
2
篇文章
3
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部