forked from RT-Thread/rt-thread
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05e974c
commit 483ead5
Showing
23 changed files
with
2,217 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
mainmenu "RT-Thread Project Configuration" | ||
|
||
config BSP_DIR | ||
string | ||
option env="BSP_ROOT" | ||
default "." | ||
|
||
config RTT_DIR | ||
string | ||
option env="RTT_ROOT" | ||
default "../../" | ||
|
||
config PKGS_DIR | ||
string | ||
option env="PKGS_ROOT" | ||
default "packages" | ||
|
||
source "$RTT_DIR/Kconfig" | ||
source "$PKGS_DIR/Kconfig" | ||
|
||
config SOC_LA132 | ||
bool | ||
select ARCH_LOONGARCH32 | ||
select RT_USING_COMPONENTS_INIT | ||
select RT_USING_USER_MAIN | ||
default y | ||
|
||
source "$BSP_DIR/drivers/Kconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# QEMU/LoongArch32 VIRT64 BSP Introduction | ||
|
||
## 1. Introduction | ||
|
||
This project ported RT-Thread on QEMU LoongArch32 VIRT64 machine. | ||
|
||
## 2. Compiling | ||
|
||
Download the `loongarch32-newlib-elf-xxx` of x86_64 hosted platform,set the `RTT_EXEC_PATH` is system environment after decompress the binary. | ||
|
||
```bash | ||
cd rt-thread/bsp/qemu-virt64-loongarch32 | ||
scons | ||
``` | ||
|
||
## 3. Execution | ||
|
||
The project execution tool is `qemu-system-loongarch64`. | ||
|
||
```bash | ||
cd rt-thread/bsp/qemu-virt64-loongarch32 | ||
./qemu.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# for module compiling | ||
import os | ||
from building import * | ||
|
||
cwd = GetCurrentDir() | ||
objs = [] | ||
list = os.listdir(cwd) | ||
|
||
for d in list: | ||
path = os.path.join(cwd, d) | ||
if os.path.isfile(os.path.join(path, 'SConscript')): | ||
objs = objs + SConscript(os.path.join(d, 'SConscript')) | ||
|
||
Return('objs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import sys | ||
import rtconfig | ||
|
||
from rtconfig import RTT_ROOT | ||
|
||
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] | ||
from building import * | ||
|
||
TARGET = 'rtthread.' + rtconfig.TARGET_EXT | ||
|
||
DefaultEnvironment(tools=[]) | ||
env = Environment(tools = ['mingw'], | ||
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, | ||
CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS, | ||
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS, | ||
AR = rtconfig.AR, ARFLAGS = '-rc', | ||
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) | ||
env.PrependENVPath('PATH', rtconfig.EXEC_PATH) | ||
env['ASCOM'] = env['ASPPCOM'] | ||
|
||
Export('RTT_ROOT') | ||
Export('rtconfig') | ||
|
||
# prepare building environment | ||
objs = PrepareBuilding(env, RTT_ROOT) | ||
|
||
# make a building | ||
DoBuilding(TARGET, objs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from building import * | ||
|
||
cwd = GetCurrentDir() | ||
src = Glob('*.c') + Glob('*.cpp') + Glob('*_gcc.S') | ||
CPPPATH = [cwd] | ||
|
||
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) | ||
|
||
Return('group') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2024, RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024-06-13 Feiyang Chen the first version | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
int main(void) | ||
{ | ||
printf("Welcome to RT-Thread/LoongArch32!\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
menu "Hardware Drivers Config" | ||
|
||
menuconfig BSP_USING_UART | ||
bool "Using UART" | ||
select RT_USING_SERIAL | ||
default y | ||
|
||
if BSP_USING_UART | ||
config BSP_USING_UART0 | ||
bool "Using UART0" | ||
default y | ||
|
||
config BSP_USING_UART1 | ||
bool "Using UART1" | ||
default n | ||
endif | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from building import * | ||
|
||
cwd = GetCurrentDir() | ||
src = Glob('*.c') + Glob('*.cpp') + Glob('*_gcc.S') | ||
CPPPATH = [cwd] | ||
|
||
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) | ||
|
||
Return('group') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2024, RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024-06-13 Feiyang Chen the first version | ||
*/ | ||
|
||
#include <rtthread.h> | ||
#include <rthw.h> | ||
|
||
#include "board.h" | ||
#include "interrupt.h" | ||
|
||
void rt_hw_board_init(void) | ||
{ | ||
rt_hw_interrupt_init(); | ||
|
||
#ifdef RT_USING_COMPONENTS_INIT | ||
rt_components_board_init(); | ||
#endif | ||
|
||
#ifdef RT_USING_CONSOLE | ||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME); | ||
#endif | ||
|
||
#ifdef RT_USING_HEAP | ||
rt_system_heap_init((void *)RT_HW_HEAP_BEGIN, (void *)RT_HW_HEAP_END); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2024, RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024-06-13 Feiyang Chen the first version | ||
*/ | ||
|
||
#ifndef BOARD_H__ | ||
#define BOARD_H__ | ||
|
||
#include "addr.h" | ||
|
||
#if defined(SOC_LA464) | ||
#define RT_HW_HEAP_SIZE (64 * 1024 * 1024) | ||
#elif defined(SOC_LA132) | ||
#define RT_HW_HEAP_SIZE (4 * 1024 * 1024) | ||
#else | ||
#error "Unsupported SOC series" | ||
#endif | ||
|
||
extern unsigned char __bss_end; | ||
|
||
#define RT_HW_HEAP_BEGIN (&__bss_end) | ||
#define RT_HW_HEAP_END (&__bss_end + RT_HW_HEAP_SIZE) | ||
|
||
void rt_hw_board_init(void); | ||
|
||
#endif /* BOARD_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2024, RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024-06-13 Feiyang Chen the first version | ||
*/ | ||
|
||
#include <rthw.h> | ||
#include <rtthread.h> | ||
|
||
#include "board.h" | ||
#include "drv_timer.h" | ||
#include "interrupt.h" | ||
#include "loongarch.h" | ||
|
||
static void rt_hw_timer_handler(int vector, void *param) | ||
{ | ||
rt_interrupt_enter(); | ||
|
||
/* clear interrupt */ | ||
__csrwr_w(CSR_TINTCLR_TI, LOONGARCH_CSR_TINTCLR); | ||
|
||
/* increase a OS tick */ | ||
rt_tick_increase(); | ||
|
||
rt_interrupt_leave(); | ||
} | ||
|
||
static unsigned int get_cpu_freq(void) | ||
{ | ||
unsigned int res; | ||
unsigned int base_freq; | ||
unsigned int cfm, cfd; | ||
|
||
base_freq = __cpucfg(LOONGARCH_CPUCFG4); | ||
res = __cpucfg(LOONGARCH_CPUCFG5); | ||
cfm = res & 0xffff; | ||
cfd = (res >> 16) & 0xffff; | ||
|
||
if (!base_freq || !cfm || !cfd) | ||
return 100000000; /* default CPU frequency */ | ||
|
||
return (base_freq * cfm / cfd); | ||
} | ||
|
||
int rt_hw_timer_init(void) | ||
{ | ||
rt_ubase_t period; | ||
rt_ubase_t timer_config; | ||
|
||
period = get_cpu_freq() / RT_TICK_PER_SECOND; | ||
timer_config = period & CSR_TCFG_VAL; | ||
timer_config |= (CSR_TCFG_PERIOD | CSR_TCFG_EN); | ||
__csrwr_w(timer_config, LOONGARCH_CSR_TCFG); | ||
|
||
rt_hw_interrupt_install(IRQ_TO_VECTOR(ESTAT_IS_TIMER_SHIFT), rt_hw_timer_handler, RT_NULL, "tick"); | ||
rt_hw_interrupt_umask(ESTAT_IS_TIMER_SHIFT); | ||
|
||
return 0; | ||
} | ||
INIT_BOARD_EXPORT(rt_hw_timer_init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2024, RT-Thread Development Team | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Change Logs: | ||
* Date Author Notes | ||
* 2024-06-13 Feiyang Chen the first version | ||
*/ | ||
|
||
#ifndef DRV_TIMER_H__ | ||
#define DRV_TIMER_H__ | ||
|
||
int rt_hw_timer_init(void); | ||
|
||
#endif /* DRV_TIMER_H__ */ |
Oops, something went wrong.