Skip to content

Commit b4cfb41

Browse files
committed
[bsp] Add LonganNano board support
- Get drivers from upstream - Fix no context switching after interrupt issue [libcpu] Get RISC-V support from upstream [drv] Add device IPC and common serial device driver from upstream
1 parent 282ab4e commit b4cfb41

35 files changed

+5574
-50
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ I hope this project will release the power of multitasking on Arduino platform.
6262
| --- | --- | --- |
6363
| SAM | ARM Cortex-M3 | Tested with Arduino Due |
6464
| SAMD | ARM Cortex-M0+ | Tested with Arduino MKRZero |
65+
| GD32V | Bumblebee (RV32IMAC) | Tested with Longan Nano |
6566

6667

6768
## License ##

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name=RT-Thread
2-
version=0.7.8
2+
version=0.8.0
33
author=onelife <[email protected]>, Bernard Xiong <[email protected]>
44
maintainer=onelife <[email protected]>
55
sentence=Real Time Operating System porting for Arduino SAM and SAMD boards
66
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.
77
category=Timing
88
url=https://github.com/onelife/Arduino_RT-Thread_Library
9-
architectures=sam,samd
9+
architectures=sam,samd,gd32v
1010
licence=Apache License 2.0
1111
includes=rtt.h

src/bsp/LonganNano/drv_tick.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/***************************************************************************//**
2+
* @file drv_tick.cpp
3+
* @brief Arduino RT-Thread library RISC-V tick driver
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
6+
/* Includes ------------------------------------------------------------------*/
7+
#include "include/rtthread.h"
8+
9+
#if defined(BOARD_SIPEED_LONGAN_NANO)
10+
11+
#include "bsp/bsp.h"
12+
13+
/***************************************************************************//**
14+
* @addtogroup LonganNano
15+
* @{
16+
******************************************************************************/
17+
18+
/* Private typedef -----------------------------------------------------------*/
19+
/* Private define ------------------------------------------------------------*/
20+
/* Private function prototypes -----------------------------------------------*/
21+
/* Private constants ---------------------------------------------------------*/
22+
/* Private variables ---------------------------------------------------------*/
23+
static rt_uint64_t overflow = 0;
24+
25+
/* Private functions ---------------------------------------------------------*/
26+
27+
/* Public functions ----------------------------------------------------------*/
28+
rt_err_t bsp_hw_tick_init(void) {
29+
rt_uint64_t ticks;
30+
31+
/* get counter value */
32+
ticks = *(rt_uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIME);
33+
/* set compare value */
34+
if ((ticks + (TIMER_FREQ / RT_TICK_PER_SECOND)) < ticks) {
35+
/* overflow */
36+
overflow = ticks + (TIMER_FREQ / RT_TICK_PER_SECOND);
37+
*(rt_uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIMECMP) = (rt_uint64_t)(-1);
38+
} else {
39+
overflow = 0;
40+
*(rt_uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIMECMP) = \
41+
ticks + (TIMER_FREQ / RT_TICK_PER_SECOND);
42+
43+
}
44+
*(rt_uint32_t *)(TIMER_CTRL_ADDR + TIMER_MSIP) = 1;
45+
eclic_irq_enable(CLIC_INT_TMR, 0, 0);
46+
47+
return RT_EOK;
48+
}
49+
50+
/* system timer ISR */
51+
void eclic_mtip_handler(void) {
52+
rt_uint64_t ticks;
53+
54+
/* update compare value */
55+
if (overflow > 0) {
56+
/* overflow 2nd half */
57+
*(rt_uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIME) = 0;
58+
*(rt_uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIMECMP) = overflow;
59+
overflow = 0;
60+
return;
61+
}
62+
63+
ticks = *(rt_uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIME);
64+
if ((ticks + (TIMER_FREQ / RT_TICK_PER_SECOND)) < ticks) {
65+
/* overflow */
66+
overflow = ticks + (TIMER_FREQ / RT_TICK_PER_SECOND);
67+
*(rt_uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIMECMP) = \
68+
(rt_uint64_t)(-1);
69+
} else {
70+
overflow = 0;
71+
*(rt_uint64_t *)(TIMER_CTRL_ADDR + TIMER_MTIMECMP) = \
72+
ticks + (TIMER_FREQ / RT_TICK_PER_SECOND);
73+
}
74+
rt_interrupt_enter();
75+
rt_tick_increase();
76+
rt_interrupt_leave();
77+
}
78+
79+
/***************************************************************************//**
80+
* @}
81+
******************************************************************************/
82+
83+
#endif /* defined(BOARD_SIPEED_LONGAN_NANO) */

src/bsp/LonganNano/drv_tick.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/***************************************************************************//**
2+
* @file drv_tick.h
3+
* @brief Arduino RT-Thread library RISC-V tick driver header
4+
* @author onelife <onelife.real[at]gmail.com>
5+
******************************************************************************/
6+
#ifndef __LONGAN_NANO_DRV_TICK_H__
7+
#define __LONGAN_NANO_DRV_TICK_H__
8+
9+
/* Includes ------------------------------------------------------------------*/
10+
/* Exported defines ----------------------------------------------------------*/
11+
/* Exported types ------------------------------------------------------------*/
12+
/* Exported constants --------------------------------------------------------*/
13+
14+
/* Exported functions ------------------------------------------------------- */
15+
rt_err_t bsp_hw_tick_init(void);
16+
17+
#endif /* __LONGAN_NANO_DRV_TICK_H__ */

0 commit comments

Comments
 (0)