feat: add lab-rv32i-freertos-isr-drivers card
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "FreeRTOS.h"
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
volatile size_t g_cpp_allocation_count;
|
||||
volatile size_t g_cpp_deallocation_count;
|
||||
volatile size_t g_cpp_live_allocations;
|
||||
volatile uintptr_t g_cpp_allocation_addresses[ 4 ];
|
||||
volatile uintptr_t g_cpp_deallocation_addresses[ 4 ];
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void * allocate_or_fail( size_t bytes )
|
||||
{
|
||||
void * const memory = pvPortMalloc( bytes == 0U ? 1U : bytes );
|
||||
configASSERT( memory != nullptr );
|
||||
|
||||
if( g_cpp_allocation_count < 4U )
|
||||
{
|
||||
g_cpp_allocation_addresses[ g_cpp_allocation_count ] =
|
||||
reinterpret_cast< uintptr_t >( memory );
|
||||
}
|
||||
++g_cpp_allocation_count;
|
||||
++g_cpp_live_allocations;
|
||||
return memory;
|
||||
}
|
||||
|
||||
void release( void * memory ) noexcept
|
||||
{
|
||||
if( memory == nullptr )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( g_cpp_deallocation_count < 4U )
|
||||
{
|
||||
g_cpp_deallocation_addresses[ g_cpp_deallocation_count ] =
|
||||
reinterpret_cast< uintptr_t >( memory );
|
||||
}
|
||||
++g_cpp_deallocation_count;
|
||||
--g_cpp_live_allocations;
|
||||
vPortFree( memory );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void * operator new( size_t bytes )
|
||||
{
|
||||
return allocate_or_fail( bytes );
|
||||
}
|
||||
|
||||
void * operator new[]( size_t bytes )
|
||||
{
|
||||
return allocate_or_fail( bytes );
|
||||
}
|
||||
|
||||
void operator delete( void * memory ) noexcept
|
||||
{
|
||||
release( memory );
|
||||
}
|
||||
|
||||
void operator delete[]( void * memory ) noexcept
|
||||
{
|
||||
release( memory );
|
||||
}
|
||||
|
||||
void operator delete( void * memory, size_t ) noexcept
|
||||
{
|
||||
release( memory );
|
||||
}
|
||||
|
||||
void operator delete[]( void * memory, size_t ) noexcept
|
||||
{
|
||||
release( memory );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
.section .text
|
||||
.global _start
|
||||
.type _start, @function
|
||||
|
||||
_start:
|
||||
.option push
|
||||
.option norelax
|
||||
la gp, __global_pointer$
|
||||
.option pop
|
||||
|
||||
/* Hazard3 init.S has already installed the bootstrap stack. */
|
||||
la a0, __bss_start
|
||||
la a1, __bss_end
|
||||
1:
|
||||
bgeu a0, a1, 2f
|
||||
sb zero, 0(a0)
|
||||
addi a0, a0, 1
|
||||
j 1b
|
||||
2:
|
||||
call main
|
||||
tail _exit
|
||||
|
||||
.size _start, .-_start
|
||||
@@ -0,0 +1,27 @@
|
||||
.section .text.hazard3_freertos_traps, "ax", @progbits
|
||||
|
||||
/*
|
||||
* Hazard3 init.S owns mtvec and exposes weak vector targets. Strong symbols
|
||||
* below route exceptions (including ecall/yield) and the machine timer IRQ to
|
||||
* the official FreeRTOS RISC-V trap handler.
|
||||
*/
|
||||
.global handle_exception
|
||||
.type handle_exception, @function
|
||||
handle_exception:
|
||||
j freertos_risc_v_trap_handler
|
||||
.size handle_exception, .-handle_exception
|
||||
|
||||
.global isr_machine_timer
|
||||
.type isr_machine_timer, @function
|
||||
isr_machine_timer:
|
||||
j freertos_risc_v_trap_handler
|
||||
.size isr_machine_timer, .-isr_machine_timer
|
||||
|
||||
/* Route a real machine-external interrupt through the FreeRTOS full-context
|
||||
* trap path. The application handler runs on xISRStack and may request a
|
||||
* context switch before portcontextRESTORE_CONTEXT selects the next task. */
|
||||
.global isr_external_irq
|
||||
.type isr_external_irq, @function
|
||||
isr_external_irq:
|
||||
j freertos_risc_v_trap_handler
|
||||
.size isr_external_irq, .-isr_external_irq
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "lab_freertos.h"
|
||||
#include "lab_io.h"
|
||||
|
||||
/* Official heap_4.c uses this application-owned arena. */
|
||||
__attribute__( ( aligned( 16 ) ) ) uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
|
||||
volatile uint32_t g_failure_code;
|
||||
|
||||
int lab_address_in_heap( const volatile void * address )
|
||||
{
|
||||
const uintptr_t value = ( uintptr_t ) address;
|
||||
const uintptr_t first = ( uintptr_t ) &ucHeap[ 0 ];
|
||||
const uintptr_t past_last = ( uintptr_t ) &ucHeap[ configTOTAL_HEAP_SIZE ];
|
||||
|
||||
return ( value >= first ) && ( value < past_last );
|
||||
}
|
||||
|
||||
void lab_heap_initialize( void )
|
||||
{
|
||||
void * probe = pvPortMalloc( 1U );
|
||||
|
||||
if( probe == NULL )
|
||||
{
|
||||
lab_fail( 0xA6000002UL );
|
||||
}
|
||||
vPortFree( probe );
|
||||
}
|
||||
|
||||
void lab_fail( uint32_t code )
|
||||
{
|
||||
g_failure_code = code;
|
||||
lab_puts( "FAIL\n" );
|
||||
lab_put_u32( code );
|
||||
lab_exit( code );
|
||||
}
|
||||
|
||||
void lab_assert_fail( const char * file, int line )
|
||||
{
|
||||
( void ) file;
|
||||
lab_fail( 0xA5000000UL | ( ( uint32_t ) line & 0xFFFFUL ) );
|
||||
}
|
||||
|
||||
void vApplicationMallocFailedHook( void )
|
||||
{
|
||||
lab_fail( 0xA6000001UL );
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef LAB_FREERTOS_H
|
||||
#define LAB_FREERTOS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
|
||||
extern volatile uint32_t g_failure_code;
|
||||
|
||||
int lab_address_in_heap( const volatile void * address );
|
||||
void lab_heap_initialize( void );
|
||||
void lab_fail( uint32_t code ) __attribute__( ( noreturn ) );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lab_io.h"
|
||||
|
||||
#define H3_IO_BASE ( 0xC0000000UL )
|
||||
#define H3_IO_PRINT_CHAR ( *( ( volatile uint32_t * ) ( H3_IO_BASE + 0x0UL ) ) )
|
||||
#define H3_IO_PRINT_U32 ( *( ( volatile uint32_t * ) ( H3_IO_BASE + 0x4UL ) ) )
|
||||
#define H3_IO_EXIT ( *( ( volatile uint32_t * ) ( H3_IO_BASE + 0x8UL ) ) )
|
||||
|
||||
void lab_puts( const char * text )
|
||||
{
|
||||
while( *text != '\0' )
|
||||
{
|
||||
H3_IO_PRINT_CHAR = ( uint32_t ) ( unsigned char ) *text;
|
||||
++text;
|
||||
}
|
||||
}
|
||||
void lab_put_u32( uint32_t value )
|
||||
{
|
||||
H3_IO_PRINT_U32 = value;
|
||||
}
|
||||
|
||||
void lab_exit( uint32_t code )
|
||||
{
|
||||
H3_IO_EXIT = code;
|
||||
for( ; ; )
|
||||
{
|
||||
__asm volatile ( "wfi" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef LAB_IO_H
|
||||
#define LAB_IO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void lab_puts( const char * text );
|
||||
void lab_put_u32( uint32_t value );
|
||||
void lab_exit( uint32_t code ) __attribute__( ( noreturn ) );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <stddef.h>
|
||||
|
||||
void * memcpy( void * destination, const void * source, size_t count )
|
||||
{
|
||||
unsigned char * out = ( unsigned char * ) destination;
|
||||
const unsigned char * in = ( const unsigned char * ) source;
|
||||
|
||||
for( size_t index = 0; index < count; ++index )
|
||||
{
|
||||
out[ index ] = in[ index ];
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
void * memset( void * destination, int value, size_t count )
|
||||
{
|
||||
unsigned char * out = ( unsigned char * ) destination;
|
||||
|
||||
for( size_t index = 0; index < count; ++index )
|
||||
{
|
||||
out[ index ] = ( unsigned char ) value;
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
size_t strlen( const char * text )
|
||||
{
|
||||
size_t length = 0;
|
||||
|
||||
while( text[ length ] != '\0' )
|
||||
{
|
||||
++length;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
Reference in New Issue
Block a user