Skip to content

Commit 372dd8d

Browse files
committed
[config] Add config setting, RT-Thread class code and metadata files
- Modify code to adapt Arduino build process (e.g. `#include` directive) - Modify interrupt related functions - For SAM architecture, rename `PendSV_Handler()` to `pendSVHook()` - Add example "Blink"
1 parent dc8afde commit 372dd8d

38 files changed

+498
-92
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Arduino RT-Thread Library #
2+
3+
This is a fork of [RT-Thread](https://github.com/RT-Thread/rt-thread) project and modified for Arduino.
4+
5+
Currently only the kernel APIs are avaiable and most of the optional components are removed for the sake of simplicity. Some of the optional components may be added back later.
6+
7+
8+
## Supported Architectures ##
9+
* SAM (ARM Cortex-M3, Tested with Arduino Due)
10+
* SAMD (ARM Cortex-M0+, Tested with Arduino MKRZero)
11+
12+
13+
## Known Issues ##
14+
* Native USB port is not working currently.
15+
So for Arduino Due, please connect to host with the "Programming Port"; and for "Arduino MKRZero", please avoid using "Serial" and "rt_kprintf" (by insert `#define CONFIG_NO_CONSOLE` before `#include <rtt.h>`).

examples/Blink/Blink.ino

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <rtt.h>
2+
3+
struct rt_thread blink_thread;
4+
byte blink_thread_stack[1024];
5+
bool led_state = false;
6+
7+
// user thread entry function
8+
void blink_thread_entry(void* parameter) {
9+
rt_kprintf("Start blink_thread\n");
10+
11+
// the loop is here
12+
while (true) {
13+
led_state = !led_state;
14+
digitalWrite(LED_BUILTIN, led_state ? HIGH : LOW);
15+
rt_kprintf("Sleep for 1 second\n");
16+
rt_thread_sleep(RT_TICK_PER_SECOND);
17+
}
18+
}
19+
20+
// RT-Thread function called by "RT_T.begin()"
21+
void rt_application_init(void) {
22+
rt_kprintf("Call rt_application_init");
23+
24+
// statically initialize user thread
25+
if (RT_EOK != rt_thread_init(
26+
&blink_thread, // [in/out] thread descriptor
27+
"blink", // [in] thread name
28+
blink_thread_entry, // [in] thread entry function
29+
RT_NULL, // [in] thread parameter (for entry function)
30+
blink_thread_stack, // [in] thread stack
31+
sizeof(blink_thread_stack), // [in] thread stack size
32+
10, // [in] thread priority
33+
20)) { // [in] thread ticks
34+
rt_kprintf("Failed to initialize user thread!\n");
35+
} else {
36+
// start user thread
37+
rt_thread_startup(&blink_thread);
38+
}
39+
}
40+
41+
void setup() {
42+
pinMode(LED_BUILTIN, OUTPUT);
43+
Serial.begin(9600);
44+
while (!Serial);
45+
Serial.println("Start RT-Thread");
46+
RT_T.begin();
47+
}
48+
49+
// this function is not called
50+
void loop() {
51+
// no code should be here
52+
}

keywords.txt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#######################################
2+
# Syntax Coloring Map For RT-Thread
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
rt_int8_t KEYWORD1
9+
rt_int16_t KEYWORD1
10+
rt_int32_t KEYWORD1
11+
rt_uint8_t KEYWORD1
12+
rt_uint16_t KEYWORD1
13+
rt_uint32_t KEYWORD1
14+
rt_bool_t KEYWORD1
15+
rt_base_t KEYWORD1
16+
rt_ubase_t KEYWORD1
17+
rt_err_t KEYWORD1
18+
rt_time_t KEYWORD1
19+
rt_tick_t KEYWORD1
20+
rt_flag_t KEYWORD1
21+
rt_size_t KEYWORD1
22+
rt_dev_t KEYWORD1
23+
rt_off_t KEYWORD1
24+
rt_thread KEYWORD1
25+
26+
#######################################
27+
# Methods and Functions (KEYWORD2)
28+
#######################################
29+
rt_hw_board_init KEYWORD2
30+
rt_application_init KEYWORD2
31+
32+
#######################################
33+
# Kernel Service
34+
#######################################
35+
rt_kprintf KEYWORD2
36+
rt_show_version KEYWORD2
37+
38+
#######################################
39+
# Interrupt
40+
#######################################
41+
rt_hw_interrupt_disable KEYWORD2
42+
rt_hw_interrupt_enable KEYWORD2
43+
44+
#######################################
45+
# Thread
46+
#######################################
47+
rt_thread_init KEYWORD2
48+
rt_thread_detach KEYWORD2
49+
rt_thread_create KEYWORD2
50+
rt_thread_self KEYWORD2
51+
rt_thread_find KEYWORD2
52+
rt_thread_startup KEYWORD2
53+
rt_thread_delete KEYWORD2
54+
rt_thread_yield KEYWORD2
55+
rt_thread_mdelay KEYWORD2
56+
rt_thread_control KEYWORD2
57+
rt_thread_suspend KEYWORD2
58+
rt_thread_resume KEYWORD2
59+
rt_thread_timeout KEYWORD2
60+
rt_thread_sleep KEYWORD2
61+
62+
#######################################
63+
# Instances (KEYWORD2)
64+
#######################################
65+
RT_T KEYWORD2
66+
67+
#######################################
68+
# Constants (LITERAL1)
69+
#######################################
70+
CONFIG_HEAP_SIZE LITERAL1
71+
CONFIG_PRIORITY_MAX LITERAL1
72+
CONFIG_KERNEL_PRIORITY LITERAL1
73+
CONFIG_NO_CONSOLE LITERAL1
74+
RT_EOK LITERAL1
75+
RT_ERROR LITERAL1
76+
RT_ETIMEOUT LITERAL1
77+
RT_EFULL LITERAL1
78+
RT_EEMPTY LITERAL1
79+
RT_ENOMEM LITERAL1
80+
RT_ENOSYS LITERAL1
81+
RT_EBUSY LITERAL1
82+
RT_EIO LITERAL1
83+
RT_EINTR LITERAL1
84+
RT_EINVAL LITERAL1

libcpu/arm/cortex-m0/context_gcc.S

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,6 @@
2525
.equ NVIC_PENDSV_PRI, 0x00FF0000 /* PendSV priority value (lowest) */
2626
.equ NVIC_PENDSVSET, 0x10000000 /* value to trigger PendSV exception */
2727

28-
/*
29-
* rt_base_t rt_hw_interrupt_disable();
30-
*/
31-
.global rt_hw_interrupt_disable
32-
.type rt_hw_interrupt_disable, %function
33-
rt_hw_interrupt_disable:
34-
MRS R0, PRIMASK
35-
CPSID I
36-
BX LR
37-
38-
/*
39-
* void rt_hw_interrupt_enable(rt_base_t level);
40-
*/
41-
.global rt_hw_interrupt_enable
42-
.type rt_hw_interrupt_enable, %function
43-
rt_hw_interrupt_enable:
44-
MSR PRIMASK, R0
45-
BX LR
46-
4728
/*
4829
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
4930
* R0 --> from

libcpu/arm/cortex-m0/cpuport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* 2012-12-23 aozima stack addr align to 8byte.
1212
*/
1313

14-
#include <rtthread.h>
14+
#include "include/rtthread.h"
1515

1616
struct exception_stack_frame
1717
{

libcpu/arm/cortex-m3/context_gcc.S

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* 2013-06-18 aozima add restore MSP feature.
1313
* 2013-07-09 aozima enhancement hard fault exception handler.
1414
*/
15-
15+
1616
.cpu cortex-m3
1717
.fpu softvfp
1818
.syntax unified
@@ -26,25 +26,6 @@
2626
.equ SHPR3, 0xE000ED20 /* system priority register (3) */
2727
.equ PENDSV_PRI_LOWEST, 0x00FF0000 /* PendSV priority value (lowest) */
2828

29-
/*
30-
* rt_base_t rt_hw_interrupt_disable();
31-
*/
32-
.global rt_hw_interrupt_disable
33-
.type rt_hw_interrupt_disable, %function
34-
rt_hw_interrupt_disable:
35-
MRS R0, PRIMASK
36-
CPSID I
37-
BX LR
38-
39-
/*
40-
* void rt_hw_interrupt_enable(rt_base_t level);
41-
*/
42-
.global rt_hw_interrupt_enable
43-
.type rt_hw_interrupt_enable, %function
44-
rt_hw_interrupt_enable:
45-
MSR PRIMASK, R0
46-
BX LR
47-
4829
/*
4930
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
5031
* R0 --> from
@@ -80,9 +61,9 @@ _reswitch:
8061
* R1 --> switch to thread stack
8162
* psr, pc, LR, R12, R3, R2, R1, R0 are pushed into [from] stack
8263
*/
83-
.global PendSV_Handler
84-
.type PendSV_Handler, %function
85-
PendSV_Handler:
64+
.global pendSVHook
65+
.type pendSVHook, %function
66+
pendSVHook:
8667
/* disable interrupt to protect context switch */
8768
MRS R2, PRIMASK
8869
CPSID I

libcpu/arm/cortex-m3/cpuport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* 2013-07-09 aozima enhancement hard fault exception handler.
1414
*/
1515

16-
#include <rtthread.h>
16+
#include "include/rtthread.h"
1717

1818
struct exception_stack_frame
1919
{

library.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name=RT-Thread
2+
version=0.1.0
3+
author=Bernard Xiong <[email protected]>
4+
maintainer=onelife <[email protected]>
5+
sentence=Real Time Operating System porting for Arduino SAM and SAMD boards
6+
paragraph=RT-Thread is an open source IoT operating system from China, which has strong scalability: from a tiny kernel running on a tiny core, for example ARM Cortex-M0, or Cortex-M3/4/7, to a rich feature system running on MIPS32, ARM Cortex-A8, ARM Cortex-A9 DualCore etc.
7+
category=Timing
8+
url=https://github.com/onelife/Arduino_RT-Thread_Library
9+
architectures=sam,samd
10+
licence=Apache License 2.0
11+
includes=rtt.h

src/include/libc/libc_stat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
4343

44+
#elif defined(CONFIG_ARDUINO)
45+
4446
#else
4547
#define S_IFMT 00170000
4648
#define S_IFSOCK 0140000

src/include/rtdef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ typedef int (*init_fn_t)(void);
197197
};
198198
#define INIT_EXPORT(fn, level) \
199199
const char __rti_##fn##_name[] = #fn; \
200-
RT_USED const struct rt_init_desc __rt_init_desc_##fn SECTION(".rti_fn."level) = \
200+
RT_USED const struct rt_init_desc __rt_init_desc_##fn = \
201201
{ __rti_##fn##_name, fn};
202202
#else
203203
#define INIT_EXPORT(fn, level) \
204-
RT_USED const init_fn_t __rt_init_##fn SECTION(".rti_fn."level) = fn
204+
RT_USED const init_fn_t __rt_init_##fn = fn
205205
#endif
206206
#endif
207207
#else

0 commit comments

Comments
 (0)