libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
signal.cpp
1#include "signal.hpp"
2
3#include "libxr_def.hpp"
4#include "timebase.hpp"
5#include "timer.hpp"
6
7using namespace LibXR;
8
9static uint32_t sig;
10
11ErrorCode Signal::Action(Thread &thread, int signal) {
12 UNUSED(thread);
13 ASSERT(signal > 0 && signal < 32);
14
15 sig |= 1 << signal;
16 return ErrorCode::OK;
17}
18
20 UNUSED(in_isr);
21 return Action(thread, signal);
22}
23
24ErrorCode Signal::Wait(int signal, uint32_t timeout) {
25 ASSERT(signal > 0 && signal < 32);
26 uint32_t flag = (1 << signal);
27
28 if ((sig | flag) == flag) {
29 sig &= ~flag;
30 return ErrorCode::OK;
31 } else if (timeout == 0) {
32 return ErrorCode::TIMEOUT;
33 }
34
36
37 while (Timebase::GetMilliseconds() - now < timeout) {
38 if ((sig | flag) == flag) {
39 sig &= ~flag;
40 return ErrorCode::OK;
41 }
42
44 }
45 return ErrorCode::TIMEOUT;
46}
static ErrorCode Action(Thread &thread, int signal)
触发目标线程的信号处理操作。 Triggers a signal action on the target thread.
Definition signal.cpp:7
static ErrorCode Wait(int signal, uint32_t timeout=UINT32_MAX)
等待指定信号的到来。 Waits for the specified signal.
Definition signal.cpp:35
static ErrorCode ActionFromCallback(Thread &thread, int signal, bool in_isr)
在回调环境中触发目标线程的信号处理操作。 Triggers a signal action on the target thread from a callback environment.
Definition signal.cpp:16
线程管理类,封装 FreeRTOS 任务创建和调度 Thread management class encapsulating FreeRTOS task creation and scheduling
Definition thread.hpp:15
static TimestampMS GetMilliseconds()
获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
Definition timebase.hpp:63
static void RefreshTimerInIdle()
在空闲时刷新定时器 Refreshes the timer during idle time
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值