summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHubretXie <[email protected]>2019-05-16 10:22:41 +0800
committerGitHub <[email protected]>2019-05-16 10:22:41 +0800
commit9de2942b159b7d08bc79aa370008bc42eeafc1e0 (patch)
treec6ed31f70123415e96da63973a8184e96eaad824 /examples
parentfd05ad76d69e02ee2c36e8eb73781a5654073be4 (diff)
parent4539172f5c97306a322ac1768c5c8eb4f878ea3c (diff)
Merge pull request #4 from RT-Thread/master
sync
Diffstat (limited to 'examples')
-rw-r--r--examples/nanopb/SConscript13
-rw-r--r--examples/nanopb/simple.c73
-rw-r--r--examples/nanopb/simple.options1
-rw-r--r--examples/nanopb/simple.pb.c18
-rw-r--r--examples/nanopb/simple.pb.h45
-rw-r--r--examples/nanopb/simple.proto10
-rw-r--r--examples/pm/timer_app.c3
-rw-r--r--examples/pm/wakeup_app.c77
8 files changed, 79 insertions, 161 deletions
diff --git a/examples/nanopb/SConscript b/examples/nanopb/SConscript
deleted file mode 100644
index 7c8bce9f26..0000000000
--- a/examples/nanopb/SConscript
+++ /dev/null
@@ -1,13 +0,0 @@
-Import('RTT_ROOT')
-Import('rtconfig')
-from building import *
-
-src = Split('''
-simple.c
-simple.pb.c
-''')
-CPPPATH = [RTT_ROOT + '/examples/nanopb']
-
-group = DefineGroup('Nanopb_test', src, depend = ['RT_USING_NANOPB'], CPPPATH = CPPPATH)
-
-Return('group') \ No newline at end of file
diff --git a/examples/nanopb/simple.c b/examples/nanopb/simple.c
deleted file mode 100644
index 2b793c014f..0000000000
--- a/examples/nanopb/simple.c
+++ /dev/null
@@ -1,73 +0,0 @@
-#include <rthw.h>
-#include <stm32f10x.h>
-#include <pb_encode.h>
-#include <pb_decode.h>
-#include "simple.pb.h"
-
-int nanopb_test()
-{
- /* This is the buffer where we will store our message. */
- uint8_t buffer[128];
- size_t message_length;
- bool status;
-
- /* Encode our message */
- {
- /* Allocate space on the stack to store the message data.
- *
- * Nanopb generates simple struct definitions for all the messages.
- * - check out the contents of simple.pb.h! */
- SimpleMessage message = SimpleMessage_init_zero;
-
- /* Create a stream that will write to our buffer. */
- pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
-
- /* Fill in the lucky number */
- message.lucky_number = 13;
-
- /* Now we are ready to encode the message! */
- status = pb_encode(&stream, SimpleMessage_fields, &message);
- message_length = stream.bytes_written;
-
- /* Then just check for any errors.. */
- if (!status)
- {
- rt_kprintf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
- return 1;
- }
- }
-
- /* Now we could transmit the message over network, store it in a file or
- * wrap it to a pigeon's leg.
- */
-
- /* But because we are lazy, we will just decode it immediately. */
-
- {
- /* Allocate space for the decoded message. */
- SimpleMessage message;
-
- /* Create a stream that reads from the buffer. */
- pb_istream_t stream = pb_istream_from_buffer(buffer, message_length);
-
- /* Now we are ready to decode the message. */
- status = pb_decode(&stream, SimpleMessage_fields, &message);
-
- /* Check for errors... */
- if (!status)
- {
- rt_kprintf("Decoding failed: %s\n", PB_GET_ERROR(&stream));
- return 1;
- }
-
- /* Print the data contained in the message. */
- rt_kprintf("Your lucky number was %d!\n", message.lucky_number);
- }
-
- return 0;
-}
-
-#ifdef RT_USING_FINSH
-#include <finsh.h>
-FINSH_FUNCTION_EXPORT(nanopb_test, nanopb encode/decode test.)
-#endif
diff --git a/examples/nanopb/simple.options b/examples/nanopb/simple.options
deleted file mode 100644
index 90960d0d34..0000000000
--- a/examples/nanopb/simple.options
+++ /dev/null
@@ -1 +0,0 @@
-SimpleMessage.name max_size:16 \ No newline at end of file
diff --git a/examples/nanopb/simple.pb.c b/examples/nanopb/simple.pb.c
deleted file mode 100644
index eaf09e58da..0000000000
--- a/examples/nanopb/simple.pb.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Automatically generated nanopb constant definitions */
-/* Generated by nanopb-0.3.1 at Tue Mar 10 01:16:15 2015. */
-
-#include "simple.pb.h"
-
-#if PB_PROTO_HEADER_VERSION != 30
-#error Regenerate this file with the current version of nanopb generator.
-#endif
-
-
-
-const pb_field_t SimpleMessage_fields[3] = {
- PB_FIELD( 1, INT32 , REQUIRED, STATIC , FIRST, SimpleMessage, lucky_number, lucky_number, 0),
- PB_FIELD( 2, BYTES , REQUIRED, STATIC , OTHER, SimpleMessage, name, lucky_number, 0),
- PB_LAST_FIELD
-};
-
-
diff --git a/examples/nanopb/simple.pb.h b/examples/nanopb/simple.pb.h
deleted file mode 100644
index 47521dee69..0000000000
--- a/examples/nanopb/simple.pb.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* Automatically generated nanopb header */
-/* Generated by nanopb-0.3.1 at Tue Mar 10 01:16:15 2015. */
-
-#ifndef PB_SIMPLE_PB_H_INCLUDED
-#define PB_SIMPLE_PB_H_INCLUDED
-#include <pb.h>
-
-#if PB_PROTO_HEADER_VERSION != 30
-#error Regenerate this file with the current version of nanopb generator.
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Enum definitions */
-/* Struct definitions */
-typedef PB_BYTES_ARRAY_T(16) SimpleMessage_name_t;
-
-typedef struct _SimpleMessage {
- int32_t lucky_number;
- SimpleMessage_name_t name;
-} SimpleMessage;
-
-/* Default values for struct fields */
-
-/* Initializer values for message structs */
-#define SimpleMessage_init_default {0, {0, {0}}}
-#define SimpleMessage_init_zero {0, {0, {0}}}
-
-/* Field tags (for use in manual encoding/decoding) */
-#define SimpleMessage_lucky_number_tag 1
-#define SimpleMessage_name_tag 2
-
-/* Struct field encoding specification for nanopb */
-extern const pb_field_t SimpleMessage_fields[3];
-
-/* Maximum encoded size of messages (where known) */
-#define SimpleMessage_size 29
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif
diff --git a/examples/nanopb/simple.proto b/examples/nanopb/simple.proto
deleted file mode 100644
index 1905d0e50b..0000000000
--- a/examples/nanopb/simple.proto
+++ /dev/null
@@ -1,10 +0,0 @@
-// A very simple protocol definition, consisting of only
-// one message.
-
-message SimpleMessage {
- required int32 lucky_number = 1;
- required bytes name = 2;
-}
-
-
-
diff --git a/examples/pm/timer_app.c b/examples/pm/timer_app.c
index 5c20d0f690..b7ff675b39 100644
--- a/examples/pm/timer_app.c
+++ b/examples/pm/timer_app.c
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2018-08-07 Tanek first implementation
+ * 2019-05-06 Zero-Free adapt to the new power management interface
*/
#include <board.h>
@@ -39,7 +40,7 @@ static int timer_app_init(void)
rt_timer_start(timer1);
/* keep in timer mode */
- rt_pm_request(PM_SLEEP_MODE_TIMER);
+ rt_pm_request(PM_SLEEP_MODE_DEEP);
return 0;
}
diff --git a/examples/pm/wakeup_app.c b/examples/pm/wakeup_app.c
new file mode 100644
index 0000000000..0d4c42a997
--- /dev/null
+++ b/examples/pm/wakeup_app.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2019-05-09 Zero-Free first implementation
+ */
+
+#include <board.h>
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#ifdef RT_USING_PM
+
+#define WAKEUP_EVENT_BUTTON (1 << 0)
+#define PIN_LED_R GET_PIN(E, 7)
+#define WAKEUP_PIN GET_PIN(C, 13)
+#define WAKEUP_APP_THREAD_STACK_SIZE 1024
+
+static rt_event_t wakeup_event;
+
+static void wakeup_callback(void *args)
+{
+ rt_event_send(wakeup_event, WAKEUP_EVENT_BUTTON);
+}
+
+static void wakeup_init(void)
+{
+ rt_pin_mode(WAKEUP_PIN, PIN_MODE_INPUT_PULLUP);
+ rt_pin_attach_irq(WAKEUP_PIN, PIN_IRQ_MODE_FALLING, wakeup_callback, RT_NULL);
+ rt_pin_irq_enable(WAKEUP_PIN, 1);
+}
+
+static void wakeup_app_entry(void *parameter)
+{
+ wakeup_init();
+ rt_pm_request(PM_SLEEP_MODE_DEEP);
+
+ while (1)
+ {
+ if (rt_event_recv(wakeup_event,
+ WAKEUP_EVENT_BUTTON,
+ RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR,
+ RT_WAITING_FOREVER, RT_NULL) == RT_EOK)
+ {
+ rt_pm_request(PM_SLEEP_MODE_NONE);
+
+ rt_pin_mode(PIN_LED_R, PIN_MODE_OUTPUT);
+ rt_pin_write(PIN_LED_R, 0);
+ rt_thread_delay(rt_tick_from_millisecond(500));
+ rt_pin_write(PIN_LED_R, 1);
+
+ rt_pm_release(PM_SLEEP_MODE_NONE);
+ }
+ }
+}
+
+static int wakeup_app(void)
+{
+ rt_thread_t tid;
+
+ wakeup_event = rt_event_create("wakup", RT_IPC_FLAG_FIFO);
+ RT_ASSERT(wakeup_event != RT_NULL);
+
+ tid = rt_thread_create("wakeup_app", wakeup_app_entry, RT_NULL,
+ WAKEUP_APP_THREAD_STACK_SIZE, RT_MAIN_THREAD_PRIORITY, 20);
+ RT_ASSERT(tid != RT_NULL);
+
+ rt_thread_startup(tid);
+
+ return 0;
+}
+INIT_APP_EXPORT(wakeup_app);
+
+#endif