Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
信号量_semaphore
信号量初始化失败,但返回的是RT_EOK
发布于 2021-10-19 10:20:06 浏览:1584
订阅该版
  使用NANO版本,硬件是STM32G030,信号量怎么也初始化不了,返回的也是RT_EOK
查看更多
Papalymo
2021-10-19
请勿打扰
init 是初始化信号量。 换成create: ```c key_it_sem = rt_sem_create("ksem", 100, RT_IPC_FLAG_PRIO); ``` 或者修改信号量类型为: ```c struct rt_semaphore key_it_sem; ``` 信号量参考例程:https://github.com/RT-Thread/rt-thread/blob/master/examples/utest/testcases/kernel/semaphore_tc.c 信号量文档:https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/ipc1/ipc1?id=%e4%bf%a1%e5%8f%b7%e9%87%8f
2
个回答
默认排序
按发布时间排序
李肯陪你玩赚嵌入式
认证专家
2021-10-19
2022年度和2023年度RT-Thread社区优秀开源布道师,COC深圳城市开发者社区主理人,专注于嵌入式物联网的架构设计
或许你可以了解下rt_sem_init()和rt_sem_create()的区别。 ```c /**@{*/ /** * @brief This function will initialize a static semaphore object. * * @note For the static semaphore object, its memory space is allocated by the compiler during compiling, * and shall placed on the read-write data segment or on the uninitialized data segment. * By contrast, the rt_sem_create() function will allocate memory space automatically and initialize * the semaphore. * * @see rt_sem_create() * * @param sem is a pointer to the semaphore to initialize. It is assumed that storage for the semaphore will be * allocated in your application. * * @param name is a pointer to the name you would like to give the semaphore. * * @param value is the initial value for the semaphore. * If used to share resources, you should initialize the value as the number of available resources. * If used to signal the occurrence of an event, you should initialize the value as 0. * * @param flag is the semaphore flag, which determines the queuing way of how multiple threads wait * when the semaphore is not available. * The semaphore flag can be ONE of the following values: * * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. * * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method * (also known as first-come-first-served (FCFS) scheduling strategy). * * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about * the first-in-first-out principle, and you clearly understand that all threads involved in * this semaphore will become non-real-time threads. * * @return Return the operation status. When the return value is RT_EOK, the initialization is successful. * If the return value is any other values, it represents the initialization failed. * * @warning This function can ONLY be called from threads. */ rt_err_t rt_sem_init(rt_sem_t sem, const char *name, rt_uint32_t value, rt_uint8_t flag) ``` ```c /** * @brief Creating a semaphore object. * * @note For the semaphore object, its memory space is allocated automatically. * By contrast, the rt_sem_init() function will initialize a static semaphore object. * * @see rt_sem_init() * * @param name is a pointer to the name you would like to give the semaphore. * * @param value is the initial value for the semaphore. * If used to share resources, you should initialize the value as the number of available resources. * If used to signal the occurrence of an event, you should initialize the value as 0. * * @param flag is the semaphore flag, which determines the queuing way of how multiple threads wait * when the semaphore is not available. * The semaphore flag can be ONE of the following values: * * RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. * * RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method * (also known as first-come-first-served (FCFS) scheduling strategy). * * NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to * use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about * the first-in-first-out principle, and you clearly understand that all threads involved in * this semaphore will become non-real-time threads. * * @return Return a pointer to the semaphore object. When the return value is RT_NULL, it means the creation failed. * * @warning This function can NOT be called in interrupt context. You can use macor RT_DEBUG_NOT_IN_INTERRUPT to check it. */ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag) ```
撰写答案
登录
注册新账号
关注者
0
被浏览
1.6k
关于作者
BruceLhr
这家伙很懒,什么也没写!
提问
1
回答
0
被采纳
0
关注TA
发私信
相关问题
1
怎样可以将信号量复位为初始值
2
rt_sem_take 引起段错误
3
生产者消费者中是否可以使用一个事件集来代替多个二值信号量?
4
看RTT文档,不太懂有关信号量的死锁问题
5
这样使用UART接收一帧数据的方法是否可行
6
一对多线程间通信的问题
7
动态内存堆 保护全局变量lfree,为什么用信号量而不是互斥信号量
8
二值信号量的使用问题
9
USART1_IRQHandler串口中断接收问题
10
开发文档semaphore_sample.c有问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
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
ART-Pi2快速上手--点灯
2
ART-Pi2移植CMSIS-DAP(基于CherryUSB协议栈)
3
RT-thred的stm32h723对应bsp包CubeMX添加其他外设报错
4
RT-Thread中的time溢出问题,时间戳溢出,解决方法
5
ART-PI使用env驱动ETH网卡,pc和板子可以ping通
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
UART
ESP8266
cubemx
WIZnet_W5500
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
keil_MDK
ulog
SFUD
msh
C++_cpp
MicroPython
本月问答贡献
RTT_逍遥
10
个答案
3
次被采纳
xiaorui
3
个答案
2
次被采纳
winfeng
2
个答案
2
次被采纳
三世执戟
8
个答案
1
次被采纳
KunYi
8
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
lizimu
2
篇文章
8
次点赞
swet123
1
篇文章
4
次点赞
Days
1
篇文章
4
次点赞
YZRD
1
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部