Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

// 添加 软核 picorv32 支持 #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions rt-thread/bsp/picorv32_blink/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2020-2020, YuZhaorong
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-06-09 YuZhaorong the first version
*/

#include <stdint.h>
#include <rthw.h>
#include <rtthread.h>

#define TIMER_IRQ_VECTOR 0
#define ECALL_IRQ_VECTOR 1
#define SYSTEM_BUS_VECTOR 2
#define SYSTEM_CORE_CLOCK 10000000l // 10 MHZ
// Holds the system core clock, which is the system clock
// frequency supplied to the SysTick timer and the processor
// core clock.
extern uint32_t riscv_timer(uint32_t time);
static uint32_t sys_timer_ticks = 0 ;
static uint32_t _riscv_time_config(rt_uint32_t ticks)
{
sys_timer_ticks = ticks;
return riscv_timer(ticks);
}

#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
#define RT_HEAP_SIZE 1024
static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 4K(1024 * 4)
RT_WEAK void *rt_heap_begin_get(void)
{
return rt_heap;
}

RT_WEAK void *rt_heap_end_get(void)
{
return rt_heap + RT_HEAP_SIZE;
}
#endif

void riscv_timer_handler(int vector, void *param)
{
riscv_timer(sys_timer_ticks);
rt_tick_increase();

}
void riscv_ecall_handler(int vector, void *param)
{

}
/**
* This function will initial your board.
*/
void rt_hw_board_init()
{



/* Call components board initial (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif

#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
#endif


/* System time Configuration */
_riscv_time_config(SYSTEM_CORE_CLOCK / RT_TICK_PER_SECOND);
/*Register System timer interrupt function*/
rt_hw_interrupt_init();
rt_hw_interrupt_install(TIMER_IRQ_VECTOR,riscv_timer_handler,RT_NULL,"riscv_timer");
rt_hw_interrupt_install(ECALL_IRQ_VECTOR,riscv_ecall_handler,RT_NULL,"riscv_ecall");
rt_hw_interrupt_umask(ECALL_IRQ_VECTOR);
}


101 changes: 101 additions & 0 deletions rt-thread/bsp/picorv32_blink/buill/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# CMake 最低版本号要求

cmake_minimum_required (VERSION 3.1)



ENABLE_LANGUAGE(ASM)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR risc_v)


set(tools /opt/riscv32i)
set(LINKR_FILE ../src/sections.ld)
set(CMAKE_ASM_COMPILER ${tools}/bin/riscv32-unknown-elf-gcc)
set(CMAKE_C_COMPILER ${tools}/bin/riscv32-unknown-elf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/riscv32-unknown-elf-g++)
set(CMAKE_OBJCOPY ${tools}/bin/riscv32-unknown-elf-objcopy)
set(CMAKE_OBJDUMP ${tools}/bin/riscv32-unknown-elf-objdump)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

#CXXFLAGS = -MD -Os -Wall -std=c++11
#CCFLAGS = -MD -Os -Wall
#LDFLAGS = -Wl,--gc-sections,--no-relax
#LDFLAGS = -ffunction-sections -Wl,--gc-sections
#LDLIBS = -ffunction-sections -fdata-sections






set(CMAKE_C_FLAGS "-MD -Os -Wall" )


set(CMAKE_ASM_FLAGS "-nostdlib" )
set(LD_FLAGS "-ffunction-sections -nostartfiles -Wl,--gc-sections")

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(ENABLE_EXPORTS True)
# 项目信息

set(PROJECT_NAME RISC_V)

set(BIN_TARGET ${PROJECT_NAME}.bin)
set(HEX_TARGET ${PROJECT_NAME}.hex)
set(MAP_TARGET ${PROJECT_NAME}.map)
set(LSS_TARGET ${PROJECT_NAME}.asm)
set(TMP_TARGET ${PROJECT_NAME}.tmp)

set(RISCV_SRC
../src/start.S
../board.c
../src/main.c
../../../libcpu/risc-v/picorv32/interrupt_gcc.S
../../../libcpu/risc-v/picorv32/interrupt.c
../../../libcpu/risc-v/picorv32/context_gcc.S
../../../libcpu/risc-v/picorv32/cpuport.c
../../../src/clock.c
../../../src/components.c
../../../src/cpu.c
../../../src/idle.c
../../../src/ipc.c
../../../src/irq.c
../../../src/kservice.c
../../../src/mem.c
../../../src/memheap.c
../../../src/mempool.c
../../../src/object.c
../../../src/scheduler.c
../../../src/slab.c
../../../src/thread.c
../../../src/timer.c
)
# create binary & hex files and show size of resulting firmware image

project (${PROJECT_NAME} )

include_directories(../../../libcpu/risc-v/picorv32
../
../../../include/
../../../include/libc/
./)

# 指定生成目标
add_executable(${PROJECT_NAME}.elf ${RISCV_SRC})

target_link_libraries(${PROJECT_NAME}.elf PRIVATE -T${LINKR_FILE} ${LD_FLAGS},-Map=${MAP_TARGET})

add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND echo "${PROJECT_NAME}.elf"
COMMAND ${CMAKE_OBJCOPY} -Obinary ${PROJECT_NAME}.elf ${BIN_TARGET}
COMMAND ${CMAKE_OBJCOPY} -O verilog ${PROJECT_NAME}.elf ${TMP_TARGET}
COMMAND ${CMAKE_OBJDUMP} -S ${PROJECT_NAME}.elf > ${LSS_TARGET}
COMMAND echo "${PROJECT_NAME}.elf"
COMMENT "Generating ${HEX_TARGET}, ${BIN_TARGET}")


156 changes: 156 additions & 0 deletions rt-thread/bsp/picorv32_blink/rtconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/* RT-Thread config file */

#ifndef __RTTHREAD_CFG_H__
#define __RTTHREAD_CFG_H__

#include <rtthread.h>

#if defined(__CC_ARM) || defined(__CLANG_ARM)
#include "RTE_Components.h"

#if defined(RTE_USING_FINSH)
#define RT_USING_FINSH
#endif //RTE_USING_FINSH

#endif //(__CC_ARM) || (__CLANG_ARM)

// <<< Use Configuration Wizard in Context Menu >>>
// <h>Basic Configuration
// <o>Maximal level of thread priority <8-256>
// <i>Default: 32
#define RT_THREAD_PRIORITY_MAX 8
// <o>OS tick per second
// <i>Default: 1000 (1ms)
#define RT_TICK_PER_SECOND 100
// <o>Alignment size for CPU architecture data access
// <i>Default: 4
#define RT_ALIGN_SIZE 4
// <o>the max length of object name<2-16>
// <i>Default: 8
#define RT_NAME_MAX 8
// <c1>Using RT-Thread components initialization
// <i>Using RT-Thread components initialization
#define RT_USING_COMPONENTS_INIT
// </c>

#define RT_USING_USER_MAIN

// <o>the stack size of main thread<1-4086>
// <i>Default: 512
#define RT_MAIN_THREAD_STACK_SIZE 256

// </h>

// <h>Debug Configuration
// <c1>enable kernel debug configuration
// <i>Default: enable kernel debug configuration
//#define RT_DEBUG
// </c>
// <o>enable components initialization debug configuration<0-1>
// <i>Default: 0
#define RT_DEBUG_INIT 0
// <c1>thread stack over flow detect
// <i> Diable Thread stack over flow detect
//#define RT_USING_OVERFLOW_CHECK
// </c>
// </h>

// <h>Hook Configuration
// <c1>using hook
// <i>using hook
//#define RT_USING_HOOK
// </c>
// <c1>using idle hook
// <i>using idle hook
//#define RT_USING_IDLE_HOOK
// </c>
// </h>
#define IDLE_THREAD_STACK_SIZE 128*4
// <e>Software timers Configuration
// <i> Enables user timers
#define RT_USING_TIMER_SOFT 0
#if RT_USING_TIMER_SOFT == 0
#undef RT_USING_TIMER_SOFT
#endif
// <o>The priority level of timer thread <0-31>
// <i>Default: 4
#define RT_TIMER_THREAD_PRIO 4
// <o>The stack size of timer thread <0-8192>
// <i>Default: 512
#define RT_TIMER_THREAD_STACK_SIZE 512
// </e>

// <h>IPC(Inter-process communication) Configuration
// <c1>Using Semaphore
// <i>Using Semaphore
#define RT_USING_SEMAPHORE
// </c>
// <c1>Using Mutex
// <i>Using Mutex
//#define RT_USING_MUTEX
// </c>
// <c1>Using Event
// <i>Using Event
//#define RT_USING_EVENT
// </c>
// <c1>Using MailBox
// <i>Using MailBox
#define RT_USING_MAILBOX
// </c>
// <c1>Using Message Queue
// <i>Using Message Queue
//#define RT_USING_MESSAGEQUEUE
// </c>
// </h>

// <h>Memory Management Configuration
// <c1>Dynamic Heap Management
// <i>Dynamic Heap Management
//#define RT_USING_HEAP
// </c>
// <c1>using small memory
// <i>using small memory
#define RT_USING_SMALL_MEM
// </c>
// <c1>using tiny size of memory
// <i>using tiny size of memory
//#define RT_USING_TINY_SIZE
// </c>
// </h>

// <h>Console Configuration
// <c1>Using console
// <i>Using console
#define RT_USING_CONSOLE
// </c>
// <o>the buffer size of console <1-1024>
// <i>the buffer size of console
// <i>Default: 128 (128Byte)
#define RT_CONSOLEBUF_SIZE 128
// </h>

#if defined(RT_USING_FINSH)
#define FINSH_USING_MSH
#define FINSH_USING_MSH_ONLY
// <h>Finsh Configuration
// <o>the priority of finsh thread <1-7>
// <i>the priority of finsh thread
// <i>Default: 6
#define __FINSH_THREAD_PRIORITY 5
#define FINSH_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 8 * __FINSH_THREAD_PRIORITY + 1)
// <o>the stack of finsh thread <1-4096>
// <i>the stack of finsh thread
// <i>Default: 4096 (4096Byte)
#define FINSH_THREAD_STACK_SIZE 512
// <o>the history lines of finsh thread <1-32>
// <i>the history lines of finsh thread
// <i>Default: 5
#define FINSH_HISTORY_LINES 1

#define FINSH_USING_SYMTAB
// </h>
#endif

// <<< end of configuration section >>>

#endif
Loading