mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-07 14:47:42 -04:00
Update RISC-V_IGLOO2_Creative_SoftConsole demo to make use of new RISC-V porting layer structure and exercise some external interrupts - all tests currently passing in Renode.
This commit is contained in:
parent
101806906d
commit
8285ca6b5f
9 changed files with 149 additions and 184 deletions
|
@ -1,17 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* (c) Copyright 2016-2018 Microsemi SoC Products Group. All rights reserved.
|
||||
*
|
||||
*
|
||||
* file name : microsemi-riscv-igloo2.ld
|
||||
* Mi-V soft processor linker script for creating a SoftConsole downloadable
|
||||
* image executing in eNVM.
|
||||
*
|
||||
*
|
||||
* This linker script assumes that the eNVM is connected at on the Mi-V soft
|
||||
* processor memory space.
|
||||
* processor memory space.
|
||||
*
|
||||
* SVN $Revision: 9661 $
|
||||
* SVN $Date: 2018-01-15 16:13:33 +0530 (Mon, 15 Jan 2018) $
|
||||
*/
|
||||
|
||||
|
||||
OUTPUT_ARCH( "riscv" )
|
||||
ENTRY(_start)
|
||||
|
||||
|
@ -24,19 +24,19 @@ MEMORY
|
|||
|
||||
RAM_START_ADDRESS = 0x80000000; /* Must be the same value MEMORY region ram ORIGIN above. */
|
||||
RAM_SIZE = 64k; /* Must be the same value MEMORY region ram LENGTH above. */
|
||||
STACK_SIZE = 2k; /* needs to be calculated for your application */
|
||||
STACK_SIZE = 2k; /* needs to be calculated for your application */
|
||||
HEAP_SIZE = 2k; /* needs to be calculated for your application */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : ALIGN(0x10)
|
||||
{
|
||||
KEEP (*(SORT_NONE(.text.entry)))
|
||||
KEEP (*(SORT_NONE(.text.entry)))
|
||||
. = ALIGN(0x10);
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
*(.plt)
|
||||
. = ALIGN(0x10);
|
||||
|
||||
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
|
@ -45,12 +45,12 @@ SECTIONS
|
|||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*crtend.o(.dtors))
|
||||
|
||||
|
||||
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
||||
*(.gcc_except_table)
|
||||
*(.gcc_except_table)
|
||||
*(.eh_frame_hdr)
|
||||
*(.eh_frame)
|
||||
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
|
@ -66,14 +66,14 @@ SECTIONS
|
|||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
. = ALIGN(0x10);
|
||||
|
||||
|
||||
} >envm
|
||||
|
||||
/* short/global data section */
|
||||
.sdata : ALIGN(0x10)
|
||||
{
|
||||
__sdata_load = LOADADDR(.sdata);
|
||||
__sdata_start = .;
|
||||
__sdata_start = .;
|
||||
PROVIDE( __global_pointer$ = . + 0x800);
|
||||
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2)
|
||||
*(.srodata*)
|
||||
|
@ -84,9 +84,9 @@ SECTIONS
|
|||
|
||||
/* data section */
|
||||
.data : ALIGN(0x10)
|
||||
{
|
||||
{
|
||||
__data_load = LOADADDR(.data);
|
||||
__data_start = .;
|
||||
__data_start = .;
|
||||
*(.got.plt) *(.got)
|
||||
*(.shdata)
|
||||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
|
@ -103,10 +103,10 @@ SECTIONS
|
|||
. = ALIGN(0x10);
|
||||
__sbss_end = .;
|
||||
} > ram
|
||||
|
||||
|
||||
/* sbss section */
|
||||
.bss : ALIGN(0x10)
|
||||
{
|
||||
{
|
||||
__bss_start = .;
|
||||
*(.shbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
|
@ -117,7 +117,7 @@ SECTIONS
|
|||
|
||||
/* End of uninitialized data segment */
|
||||
_end = .;
|
||||
|
||||
|
||||
.heap : ALIGN(0x10)
|
||||
{
|
||||
__heap_start = .;
|
||||
|
@ -126,13 +126,14 @@ SECTIONS
|
|||
. = ALIGN(0x10);
|
||||
_heap_end = __heap_end;
|
||||
} > ram
|
||||
|
||||
|
||||
.stack : ALIGN(0x10)
|
||||
{
|
||||
__stack_bottom = .;
|
||||
. += STACK_SIZE;
|
||||
__stack_top = .;
|
||||
_sp = .;
|
||||
__freertos_irq_stack_top = .;
|
||||
} > ram
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*******************************************************************************
|
||||
* (c) Copyright 2016-2018 Microsemi SoC Products Group. All rights reserved.
|
||||
*
|
||||
*
|
||||
* file name : microsemi-riscv-ram.ld
|
||||
* Mi-V soft processor linker script for creating a SoftConsole downloadable
|
||||
* debug image executing in SRAM.
|
||||
*
|
||||
*
|
||||
* This linker script assumes that the SRAM is connected at on the Mi-V soft
|
||||
* processor memory space. The start address and size of the memory space must
|
||||
* be correct as per the Libero design.
|
||||
|
@ -12,7 +12,7 @@
|
|||
* SVN $Revision: 9661 $
|
||||
* SVN $Date: 2018-01-15 16:13:33 +0530 (Mon, 15 Jan 2018) $
|
||||
*/
|
||||
|
||||
|
||||
OUTPUT_ARCH( "riscv" )
|
||||
ENTRY(_start)
|
||||
|
||||
|
@ -24,19 +24,19 @@ MEMORY
|
|||
|
||||
RAM_START_ADDRESS = 0x80000000; /* Must be the same value MEMORY region ram ORIGIN above. */
|
||||
RAM_SIZE = 512k; /* Must be the same value MEMORY region ram LENGTH above. */
|
||||
STACK_SIZE = 64k; /* needs to be calculated for your application */
|
||||
STACK_SIZE = 64k; /* needs to be calculated for your application */
|
||||
HEAP_SIZE = 64k; /* needs to be calculated for your application */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : ALIGN(0x10)
|
||||
{
|
||||
KEEP (*(SORT_NONE(.text.entry)))
|
||||
KEEP (*(SORT_NONE(.text.entry)))
|
||||
. = ALIGN(0x10);
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
*(.plt)
|
||||
. = ALIGN(0x10);
|
||||
|
||||
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
|
@ -45,12 +45,12 @@ SECTIONS
|
|||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*crtend.o(.dtors))
|
||||
|
||||
|
||||
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
||||
*(.gcc_except_table)
|
||||
*(.gcc_except_table)
|
||||
*(.eh_frame_hdr)
|
||||
*(.eh_frame)
|
||||
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
|
@ -66,14 +66,14 @@ SECTIONS
|
|||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
. = ALIGN(0x10);
|
||||
|
||||
|
||||
} > ram
|
||||
|
||||
/* short/global data section */
|
||||
.sdata : ALIGN(0x10)
|
||||
{
|
||||
__sdata_load = LOADADDR(.sdata);
|
||||
__sdata_start = .;
|
||||
__sdata_start = .;
|
||||
PROVIDE( __global_pointer$ = . + 0x800);
|
||||
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2)
|
||||
*(.srodata*)
|
||||
|
@ -84,9 +84,9 @@ SECTIONS
|
|||
|
||||
/* data section */
|
||||
.data : ALIGN(0x10)
|
||||
{
|
||||
{
|
||||
__data_load = LOADADDR(.data);
|
||||
__data_start = .;
|
||||
__data_start = .;
|
||||
*(.got.plt) *(.got)
|
||||
*(.shdata)
|
||||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
|
@ -103,10 +103,10 @@ SECTIONS
|
|||
. = ALIGN(0x10);
|
||||
__sbss_end = .;
|
||||
} > ram
|
||||
|
||||
|
||||
/* sbss section */
|
||||
.bss : ALIGN(0x10)
|
||||
{
|
||||
{
|
||||
__bss_start = .;
|
||||
*(.shbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
|
@ -117,7 +117,7 @@ SECTIONS
|
|||
|
||||
/* End of uninitialized data segment */
|
||||
_end = .;
|
||||
|
||||
|
||||
.heap : ALIGN(0x10)
|
||||
{
|
||||
__heap_start = .;
|
||||
|
@ -126,13 +126,14 @@ SECTIONS
|
|||
. = ALIGN(0x10);
|
||||
_heap_end = __heap_end;
|
||||
} > ram
|
||||
|
||||
|
||||
.stack : ALIGN(0x10)
|
||||
{
|
||||
__stack_bottom = .;
|
||||
. += STACK_SIZE;
|
||||
__stack_top = .;
|
||||
_sp = .;
|
||||
__freertos_irq_stack_top = .;
|
||||
} > ram
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#if 0
|
||||
/*******************************************************************************
|
||||
* (c) Copyright 2016-2018 Microsemi SoC Products Group. All rights reserved.
|
||||
*
|
||||
|
@ -15,6 +14,8 @@
|
|||
|
||||
#include "riscv_hal.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -66,70 +67,6 @@ uint8_t External_31_IRQHandler(void);
|
|||
extern void Software_IRQHandler(void);
|
||||
extern void Timer_IRQHandle( void );
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Increment value for the mtimecmp register in order to achieve a system tick
|
||||
* interrupt as specified through the SysTick_Config() function.
|
||||
*/
|
||||
static uint64_t g_systick_increment = 0U;
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Disable all interrupts.
|
||||
*/
|
||||
void __disable_irq(void)
|
||||
{
|
||||
clear_csr(mstatus, MSTATUS_MPIE);
|
||||
clear_csr(mstatus, MSTATUS_MIE);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Enabler all interrupts.
|
||||
*/
|
||||
void __enable_irq(void)
|
||||
{
|
||||
set_csr(mstatus, MSTATUS_MIE);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Configure the machine timer to generate an interrupt.
|
||||
*/
|
||||
uint32_t SysTick_Config(uint32_t ticks)
|
||||
{
|
||||
uint32_t ret_val = ERROR;
|
||||
|
||||
g_systick_increment = (uint64_t)(ticks) / RTC_PRESCALER;
|
||||
|
||||
if (g_systick_increment > 0U)
|
||||
{
|
||||
uint32_t mhart_id = read_csr(mhartid);
|
||||
|
||||
PRCI->MTIMECMP[mhart_id] = PRCI->MTIME + g_systick_increment;
|
||||
|
||||
set_csr(mie, MIP_MTIP);
|
||||
|
||||
__enable_irq();
|
||||
|
||||
ret_val = SUCCESS;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* RISC-V interrupt handler for machine timer interrupts.
|
||||
*/
|
||||
volatile uint32_t ulTimerInterrupts = 0;
|
||||
extern void Timer_IRQHandler( void );
|
||||
static void handle_m_timer_interrupt(void)
|
||||
{
|
||||
// clear_csr(mie, MIP_MTIP);
|
||||
|
||||
Timer_IRQHandler();
|
||||
|
||||
// PRCI->MTIMECMP[read_csr(mhartid)] = PRCI->MTIME + g_systick_increment;
|
||||
|
||||
// set_csr(mie, MIP_MTIP);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* RISC-V interrupt handler for external interrupts.
|
||||
*/
|
||||
|
@ -172,7 +109,7 @@ uint8_t (*ext_irq_handler_table[32])(void) =
|
|||
/*------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
static void handle_m_ext_interrupt(void)
|
||||
void handle_m_ext_interrupt(void)
|
||||
{
|
||||
uint32_t int_num = PLIC_ClaimIRQ();
|
||||
uint8_t disable = EXT_IRQ_KEEP_ENABLED;
|
||||
|
@ -187,82 +124,7 @@ static void handle_m_ext_interrupt(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void handle_m_soft_interrupt(void)
|
||||
{
|
||||
Software_IRQHandler();
|
||||
|
||||
/*Clear software interrupt*/
|
||||
PRCI->MSIP[0] = 0x00U;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Trap/Interrupt handler
|
||||
*/
|
||||
#define ENV_CALL_FROM_M_MODE 11
|
||||
extern void vTaskSwitchContext( void );
|
||||
|
||||
uintptr_t handle_trap(uintptr_t mcause, uintptr_t mepc)
|
||||
{
|
||||
/*_RB_*/
|
||||
if( mcause == ENV_CALL_FROM_M_MODE )
|
||||
{
|
||||
vTaskSwitchContext();
|
||||
|
||||
/* Ensure not to return to the instruction that generated the exception. */
|
||||
mepc += 4;
|
||||
} else
|
||||
/*end _RB_*/
|
||||
if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_EXT))
|
||||
{
|
||||
handle_m_ext_interrupt();
|
||||
}
|
||||
else if ((mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_TIMER))
|
||||
{
|
||||
handle_m_timer_interrupt();
|
||||
}
|
||||
else if ( (mcause & MCAUSE_INT) && ((mcause & MCAUSE_CAUSE) == IRQ_M_SOFT))
|
||||
{
|
||||
handle_m_soft_interrupt();
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
/*
|
||||
Arguments supplied to this function are mcause, mepc (exception PC) and stack pointer
|
||||
based onprivileged-isa specification
|
||||
mcause values and meanings are:
|
||||
0 Instruction address misaligned (mtval/mbadaddr is the address)
|
||||
1 Instruction access fault (mtval/mbadaddr is the address)
|
||||
2 Illegal instruction (mtval/mbadaddr contains the offending instruction opcode)
|
||||
3 Breakpoint
|
||||
4 Load address misaligned (mtval/mbadaddr is the address)
|
||||
5 Load address fault (mtval/mbadaddr is the address)
|
||||
6 Store/AMO address fault (mtval/mbadaddr is the address)
|
||||
7 Store/AMO access fault (mtval/mbadaddr is the address)
|
||||
8 Environment call from U-mode
|
||||
9 Environment call from S-mode
|
||||
A Environment call from M-mode
|
||||
B Instruction page fault
|
||||
C Load page fault (mtval/mbadaddr is the address)
|
||||
E Store page fault (mtval/mbadaddr is the address)
|
||||
*/
|
||||
|
||||
uintptr_t mip = read_csr(mip); /* interrupt pending */
|
||||
uintptr_t mbadaddr = read_csr(mbadaddr); /* additional info and meaning depends on mcause */
|
||||
uintptr_t mtvec = read_csr(mtvec); /* trap vector */
|
||||
uintptr_t mscratch = read_csr(mscratch); /* temporary, sometimes might hold temporary value of a0 */
|
||||
uintptr_t mstatus = read_csr(mstatus); /* status contains many smaller fields: */
|
||||
|
||||
/* breakpoint*/
|
||||
__asm("ebreak");
|
||||
#else
|
||||
_exit(1 + mcause);
|
||||
#endif
|
||||
}
|
||||
return mepc;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -143,7 +143,7 @@ static inline void PLIC_init(void)
|
|||
PLIC->TARGET[hart_id].PRIORITY_THRESHOLD = 0;
|
||||
|
||||
/* Enable machine external interrupts. */
|
||||
// set_csr(mie, MIP_MEIP);
|
||||
set_csr(mie, MIP_MEIP);
|
||||
}
|
||||
|
||||
/*==============================================================================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue