Skip to content

Commit b242b1e

Browse files
committed
[examples][pm]add wakeup application for pm.
1 parent 42a32fd commit b242b1e

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

examples/pm/wakeup_app.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2006-2018, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2019-05-09 Zero-Free first implementation
9+
*/
10+
11+
#include <board.h>
12+
#include <rtthread.h>
13+
#include <rtdevice.h>
14+
15+
#ifdef RT_USING_PM
16+
17+
#define WAKEUP_EVENT_BUTTON (1 << 0)
18+
#define PIN_LED_R GET_PIN(E, 7)
19+
#define WAKEUP_PIN GET_PIN(C, 13)
20+
#define WAKEUP_APP_THREAD_STACK_SIZE 1024
21+
22+
static rt_event_t wakeup_event;
23+
24+
static void wakeup_callback(void *args)
25+
{
26+
rt_event_send(wakeup_event, WAKEUP_EVENT_BUTTON);
27+
}
28+
29+
static void wakeup_init(void)
30+
{
31+
rt_pin_mode(WAKEUP_PIN, PIN_MODE_INPUT_PULLUP);
32+
rt_pin_attach_irq(WAKEUP_PIN, PIN_IRQ_MODE_FALLING, wakeup_callback, RT_NULL);
33+
rt_pin_irq_enable(WAKEUP_PIN, 1);
34+
}
35+
36+
static void wakeup_app_entry(void *parameter)
37+
{
38+
wakeup_init();
39+
rt_pm_request(PM_SLEEP_MODE_DEEP);
40+
41+
while (1)
42+
{
43+
if (rt_event_recv(wakeup_event,
44+
WAKEUP_EVENT_BUTTON,
45+
RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,
46+
RT_WAITING_FOREVER, RT_NULL) == RT_EOK)
47+
{
48+
rt_pm_request(PM_SLEEP_MODE_NONE);
49+
50+
rt_pin_mode(PIN_LED_R, PIN_MODE_OUTPUT);
51+
rt_pin_write(PIN_LED_R, 0);
52+
rt_thread_delay(rt_tick_from_millisecond(500));
53+
rt_pin_write(PIN_LED_R, 1);
54+
55+
rt_pm_release(PM_SLEEP_MODE_NONE);
56+
}
57+
}
58+
}
59+
60+
static int wakeup_app(void)
61+
{
62+
rt_thread_t tid;
63+
64+
wakeup_event = rt_event_create("wakup", RT_IPC_FLAG_FIFO);
65+
RT_ASSERT(wakeup_event != RT_NULL);
66+
67+
tid = rt_thread_create("wakeup_app", wakeup_app_entry, RT_NULL,
68+
WAKEUP_APP_THREAD_STACK_SIZE, RT_MAIN_THREAD_PRIORITY, 20);
69+
RT_ASSERT(tid != RT_NULL);
70+
71+
rt_thread_startup(tid);
72+
73+
return 0;
74+
}
75+
INIT_APP_EXPORT(wakeup_app);
76+
77+
#endif

0 commit comments

Comments
 (0)