Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e672334

Browse files
committed
[elf] Add "HelloMo" example
1 parent f129b50 commit e672334

File tree

9 files changed

+243
-39
lines changed

9 files changed

+243
-39
lines changed

‎examples/Blink/Blink.ino‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
/***************************************************************************//**
2+
* @file Blink.ino
3+
* @brief Arduino RT-Thread library "Blink" example
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
16
#include <rtt.h>
27

3-
// NOTES: "CONFIG_USING_FINSH" and "CONFIG_USING_SPISD" in "rtconfig.h" may be turned off to save memory
8+
/* NOTES
9+
The following flags in "rtconfig.h" may be turned off to save memory:
10+
- CONFIG_USING_FINSH
11+
- CONFIG_USING_SPISD
12+
*/
413

514
struct rt_thread blink_thread;
615
byte blink_thread_stack[1024];

‎examples/DataLogger/DataLogger.ino‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
/***************************************************************************//**
2+
* @file DataLogger.ino
3+
* @brief Arduino RT-Thread library "DataLogger" example
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
16
#include <rtt.h>
27

8+
39
// RT-Thread function called by "RT_T.begin()"
410
void rt_setup(void) {
511
}

‎examples/FinSH/FinSH.ino‎

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
1+
/***************************************************************************//**
2+
* @file FinSH.ino
3+
* @brief Arduino RT-Thread library "FinSH" example
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
16
#include <rtt.h>
27

3-
// ATTENTION: Please append the new shell command and variable to "shell_cmd.h" and "shell_var.h"
4-
5-
// NOTES: When using FinSH without MSH (CONFIG_USING_MSH == 0)
6-
// - please append the following line to "shell_cmd.h" (without //)
7-
// ADD_FINSH_CMD(led, Turn on/off builtin LED, led, rt_uint32_t, rt_uint32_t id, rt_uint8_t state)
8-
//
9-
// - and append the following 2 lines to "shell_var.h" (without //)
10-
// ADD_SHELL_VAR(id, LED ID, led_id, finsh_type_uint)
11-
// ADD_SHELL_VAR(state, LED state, led_state, finsh_type_uchar)
12-
//
13-
// After upload, send the following command through "Serial Monitor" and check the result.
14-
// led(0, 1)
15-
// led(0, 0)
16-
// led(id, state)
17-
// state
18-
// state=0
19-
// led(id, state)
20-
21-
// NOTES: When using FinSH with MSH (CONFIG_USING_MSH == 1, the default config)
22-
// - please append the following line to "shell_cmd.h" (without //)
23-
// ADD_MSH_CMD(led, Turn on/off builtin LED, led, rt_uint32_t, rt_uint32_t id, rt_uint8_t state)
24-
// Due to MSH doesn't support shell variables, "ADD_SHELL_VAR" has no effect
25-
//
26-
// After upload, send the following command through "Serial Monitor" and check the result.
27-
// led 0, 1, 2
28-
// led 1, 1
29-
// led 0, 1
8+
/* ATTENTION
9+
Please append your new shell commands and variables to "shell_cmd.h" and
10+
"shell_var.h".
11+
*/
12+
13+
/* NOTES
14+
When using FinSH without MSH (CONFIG_USING_FINSH == 1 &&
15+
CONFIG_USING_MSH == 0):
16+
- please append the following line to "shell_cmd.h":
17+
ADD_FINSH_CMD(led, Turn on/off builtin LED, led, rt_uint32_t, rt_uint32_t id, rt_uint8_t state)
18+
- and append the following 2 lines to "shell_var.h"
19+
ADD_SHELL_VAR(id, LED ID, led_id, finsh_type_uint)
20+
ADD_SHELL_VAR(state, LED state, led_state, finsh_type_uchar)
21+
22+
After uploaded, please send the following command through "Serial Monitor"
23+
and observe the output:
24+
led(0, 1)
25+
led(0, 0)
26+
led(id, state)
27+
state
28+
state=0
29+
led(id, state)
30+
*/
31+
32+
/* NOTES
33+
When using FinSH with MSH (default, CONFIG_USING_FINSH == 1 &&
34+
CONFIG_USING_MSH == 1):
35+
- please append the following line to "shell_cmd.h":
36+
ADD_MSH_CMD(led, Turn on/off builtin LED, led, rt_uint32_t, rt_uint32_t id, rt_uint8_t state)
37+
- due to MSH doesn't support shell variables, "ADD_SHELL_VAR" has no effect
38+
39+
After uploaded, please send the following command through "Serial Monitor"
40+
and observe the output:
41+
led 0, 1, 2
42+
led 1, 1
43+
led 0, 1
44+
*/
3045

3146
extern "C" {
3247

‎examples/HelloMo/HelloMo.ino‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/***************************************************************************//**
2+
* @file HelloMo.ino
3+
* @brief Arduino RT-Thread library "HelloMo" example
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
6+
#include <rtt.h>
7+
8+
/* ATTENTION
9+
The following flags in "rtconfig.h" must be turned on:
10+
- CONFIG_USING_MODULE
11+
*/
12+
13+
/* NOTES
14+
To build code as "MO" file:
15+
1. Compile
16+
- you may copy the compiling command from Arduino's output window (select
17+
[File-> Preferences-> Show verbose output during: compilation] if you
18+
can't see the command)
19+
- add options "-mlong-calls -fPIC"
20+
21+
2. Link
22+
- you may copy the compiling command from Arduino's output window
23+
- keep only "hello_mo.c.o"
24+
- remove option "-Wl,--unresolved-symbols=report-all"
25+
- remove option "-LC:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_362673"
26+
- remove option "-TC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\variants\\mkrzero/linker_scripts/gcc/flash_with_bootloader.ld"
27+
- remove option: "-Wl,--start-group ... -Wl,--end-group"
28+
- add options "-shared -fPIC -nostdlib -Wl,-marmelf -Wl,-z,max-page-size=0x4"
29+
- add option to set entry point (e.g. "-Wl,-esay_hello")
30+
31+
3. Strip
32+
- use "arm-none-eabi-strip"
33+
34+
To build code as "SO" file:
35+
1. Compile
36+
- same as above
37+
38+
2. Link
39+
- same as above, but
40+
- add option to set entry point to NULL (e.g. "-Wl,-e0")
41+
42+
3. Strip
43+
- use "arm-none-eabi-strip"
44+
*/
45+
46+
void setup() {
47+
RT_T.begin();
48+
// no code here as RT_T.begin() never return
49+
}
50+
51+
// this function will be called by "Arduino" thread
52+
void loop() {
53+
// may put some code here that will be run repeatedly
54+
}
55+
56+
/* EXAMPLE
57+
58+
To build "hello_mo.c" as "SO" file:
59+
60+
"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-gcc" -mcpu=cortex-m0plus -mthumb -c -g -Os -mlong-calls -fPIC -Wall -Wextra -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_MKRZERO -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804f -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino MKRZero\"" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS\4円.5.0/CMSIS/Include/" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS-Atmel\1円.1.0/CMSIS/Device/ATMEL/" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\cores\\arduino" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\variants\\mkrzero" "-IC:\\Users\\onelife\\Documents\\Arduino\\libraries\\RT-Thread\\src" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\libraries\\SPI" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\hello_mo.c" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\hello_mo.c.o"
61+
62+
"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-g++" -Os -shared -fPIC -nostdlib -Wl,-e0 -Wl,-marmelf -Wl,-z,max-page-size=0x4 -Wl,--gc-sections -save-temps "-Wl,-Map,C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--warn-common -Wl,--warn-section-align -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.elf" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\hello_mo.c.o"
63+
64+
"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-strip" -R .hash -R .comment -R .ARM.attributes "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.elf" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello.so"
65+
66+
67+
To build "load_mo.c" as "MO" file:
68+
69+
"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-gcc" -mcpu=cortex-m0plus -mthumb -c -g -Os -mlong-calls -fPIC -Wall -Wextra -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_SAMD_MKRZERO -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x804f -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino MKRZero\"" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS\4円.5.0/CMSIS/Include/" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\CMSIS-Atmel\1円.1.0/CMSIS/Device/ATMEL/" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\cores\\arduino" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\variants\\mkrzero" "-IC:\\Users\\onelife\\Documents\\Arduino\\libraries\\RT-Thread\\src" "-IC:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\samd\1円.6.21\\libraries\\SPI" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\load_mo.c" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\load_mo.c.o"
70+
71+
"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-g++" -Os -shared -fPIC -nostdlib -Wl,-eload_hello -Wl,-marmelf -Wl,-z,max-page-size=0x4 -Wl,--gc-sections -save-temps "-Wl,-Map,C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/load_mo.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--warn-common -Wl,--warn-section-align -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/load_mo.elf" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\load_mo.c.o"
72+
73+
"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-strip" -R .hash -R .comment -R .ARM.attributes "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/load_mo.elf" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/load.mo"
74+
75+
76+
To build "hello_mo.c" as "MO" file (change a link option and output name):
77+
78+
"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-g++" -Os -shared -fPIC -nostdlib -Wl,-esay_hello -Wl,-marmelf -Wl,-z,max-page-size=0x4 -Wl,--gc-sections -save-temps "-Wl,-Map,C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--warn-common -Wl,--warn-section-align -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.elf" "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658\\sketch\\hello_mo.c.o"
79+
80+
"C:\\Users\\onelife\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\4円.8.3-2014q1/bin/arm-none-eabi-strip" -R .hash -R .comment -R .ARM.attributes "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello_mo.elf" -o "C:\\Users\\onelife\\AppData\\Local\\Temp\\arduino_build_66658/hello.mo"
81+
82+
*/

‎examples/HelloMo/hello_mo.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/***************************************************************************//**
2+
* @file hello_mo.c
3+
* @brief Arduino RT-Thread library "HelloMo" example
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
6+
#include "mo.h"
7+
8+
int say_hello(unsigned char argc, char **argv) {
9+
char *input;
10+
11+
if (argc < 2) {
12+
input = "there";
13+
} else {
14+
input = argv[1];
15+
}
16+
rt_kprintf("Hello %s!\n\t--- From %s\n", input, argv[0]);
17+
18+
return 0;
19+
}
20+
21+
void module_init(void *param) {
22+
rt_dlmodule_t *self = (rt_dlmodule_t *)param;
23+
24+
rt_kprintf("%s init\n", self->parent.name);
25+
}
26+
27+
void module_cleanup(void *param) {
28+
rt_dlmodule_t *self = (rt_dlmodule_t *)param;
29+
30+
rt_kprintf("%s cleanup\n", self->parent.name);
31+
}

‎examples/HelloMo/load_mo.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/***************************************************************************//**
2+
* @file load_mo.c
3+
* @brief Arduino RT-Thread library "HelloMo" example
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
6+
#include "mo.h"
7+
8+
int load_hello(unsigned char argc, char **argv) {
9+
rt_dlmodule_t *hello;
10+
int (*say_hello)(unsigned char argc, char **argv);
11+
char *param[2];
12+
(void)argc;
13+
(void)argv;
14+
15+
param[0] = "loader";
16+
param[1] = "there";
17+
18+
hello = dlopen("hello.so", 0);
19+
if (!hello) {
20+
rt_kprintf("Load \"hello.so\" failed\n");
21+
return -1;
22+
}
23+
rt_kprintf("Load \"%s\" ok\n", hello->parent.name);
24+
25+
say_hello = dlsym(hello, "say_hello");
26+
if (!say_hello) {
27+
rt_kprintf("Get symbal \"say_hello\" failed\n");
28+
return -1;
29+
}
30+
rt_kprintf("Symbal \"say_hello\" => %p\n", say_hello);
31+
32+
say_hello(2, param);
33+
34+
// while (1) {
35+
// rt_thread_sleep(1000);
36+
// }
37+
38+
dlclose(hello);
39+
40+
return 0;
41+
}

‎examples/RttMutex/RttMutex.ino‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
/***************************************************************************//**
2+
* @file RttMutex.ino
3+
* @brief Arduino RT-Thread library "RttMutex" example
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
16
#include <rtt.h>
27

3-
// NOTES: "CONFIG_USING_SPISD" in "rtconfig.h" may be turned off to save memory
8+
/* NOTES
9+
The following flags in "rtconfig.h" may be turned off to save memory:
10+
- CONFIG_USING_SPISD
11+
*/
412

513
#define THREAD_NUM 3
614
#define STACK_SIZE 256

‎examples/SysLog/SysLog.ino‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1+
/***************************************************************************//**
2+
* @file SysLog.ino
3+
* @brief Arduino RT-Thread library "SysLog" example
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
16
#include <rtt.h>
7+
8+
/* NOTES
9+
The following flags in "rtconfig.h" may be turned off to save memory:
10+
- CONFIG_USING_FINSH
11+
- CONFIG_USING_SPISD
12+
*/
13+
214
#define LOG_LVL LOG_LVL_DBG
315
#define LOG_TAG "EXAMPLE"
416
#include <log.h>
517

6-
// NOTES: "LOG_LVL" and "LOG_TAG" must be defined before "#include <log.h>"
7-
// Available LOG_LVL:
8-
// - LOG_LVL_ASSERT
9-
// - LOG_LVL_ERROR
10-
// - LOG_LVL_WARNING
11-
// - LOG_LVL_INFO
12-
// - LOG_LVL_DBG
13-
14-
// NOTES: "CONFIG_USING_FINSH" and "CONFIG_USING_SPISD" in "rtconfig.h" may be turned off to save memory
15-
18+
/* NOTES
19+
"LOG_LVL" and "LOG_TAG" must be defined before "#include <log.h>".
20+
Available LOG_LVL:
21+
- LOG_LVL_ASSERT
22+
- LOG_LVL_ERROR
23+
- LOG_LVL_WARNING
24+
- LOG_LVL_INFO
25+
- LOG_LVL_DBG
26+
*/
1627

1728
// RT-Thread function called by "RT_T.begin()"
1829
void rt_setup(void) {

‎src/components/libc/libdl/dlmodule.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ rt_dlmodule_t *dlmodule_create(void) {
221221
void dlmodule_destroy_subthread(rt_dlmodule_t *module,
222222
rt_thread_t thread) {
223223
RT_ASSERT(thread->module_id == module);
224+
(void)module;
224225

225226
/* lock scheduler to prevent scheduling in cleanup function. */
226227
rt_enter_critical();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /