feat: publish FreeRTOS C FC06 card

This commit is contained in:
2026-07-19 16:36:03 +02:00
commit 0fc6158501
195 changed files with 60591 additions and 0 deletions
+23
View File
@@ -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
+18
View File
@@ -0,0 +1,18 @@
.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
+48
View File
@@ -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 );
}
+16
View File
@@ -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
+30
View File
@@ -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" );
}
}
+10
View File
@@ -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
+34
View File
@@ -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;
}
+274
View File
@@ -0,0 +1,274 @@
#include <stddef.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "lab_freertos.h"
#include "lab_io.h"
#include "task01_software_timers.h"
#define FC06_ACTOR_MAIN 1U
#define FC06_ACTOR_CONTROLLER 2U
#define FC06_ACTOR_DAEMON 3U
#define FC06_ACTOR_VERIFIER 4U
TimerExperiment g_fc06;
TimerEvidence g_fc06_events[ FC06_EVENT_CAPACITY ];
volatile uint32_t g_fc06_event_count;
volatile uint32_t g_fc06_last_checkpoint;
volatile uint32_t g_fc06_pass;
static uintptr_t read_sp( void )
{
uintptr_t value;
__asm__ volatile( "mv %0, sp" : "=r"( value ) );
return value;
}
__attribute__( ( noinline, used ) )
void fc06_checkpoint_committed( uint32_t point, const void * subject )
{
( void ) point;
( void ) subject;
__asm__ volatile( "" ::: "memory" );
}
static void fc06_publish( uint32_t point,
uint32_t actor,
uint32_t value,
const void * subject )
{
UBaseType_t state;
uint32_t index;
TimerEvidence * event;
state = taskENTER_CRITICAL_FROM_ISR();
index = g_fc06_event_count;
if( index >= FC06_EVENT_CAPACITY )
{
taskEXIT_CRITICAL_FROM_ISR( state );
lab_fail( 0xFC060001U );
}
event = &g_fc06_events[ index ];
event->sequence = index + 1U;
event->event = point;
event->tick = ( uint32_t ) xTaskGetTickCount();
event->actor = actor;
event->value = value;
__asm__ volatile( "" ::: "memory" );
event->committed = 0xFC060000U | ( index + 1U );
g_fc06_event_count = index + 1U;
g_fc06_last_checkpoint = point;
taskEXIT_CRITICAL_FROM_ISR( state );
fc06_checkpoint_committed( point, subject );
}
__attribute__( ( noinline, used ) )
void fc06_timer_callback( TimerHandle_t timer )
{
TimerTag * tag = ( TimerTag * ) pvTimerGetTimerID( timer );
TickType_t tick = xTaskGetTickCount();
if( tag == NULL || tag->marker != 0xFC0600A5U )
{
lab_fail( 0xFC060101U );
}
g_fc06.daemon_seen = xTimerGetTimerDaemonTaskHandle();
g_fc06.callback_sp = read_sp();
if( tag->kind == FC06_TIMER_AUTO )
{
uint32_t index = g_fc06.auto_count;
if( index >= 3U )
{
lab_fail( 0xFC060102U );
}
g_fc06.auto_tick[ index ] = ( uint32_t ) tick;
g_fc06.auto_count = index + 1U;
fc06_publish( index == 0U ? 4U : ( index == 1U ? 5U : 8U ),
FC06_ACTOR_DAEMON,
( uint32_t ) tick,
timer );
}
else if( tag->kind == FC06_TIMER_ONE_SHOT )
{
++g_fc06.one_shot_count;
g_fc06.one_shot_tick = ( uint32_t ) tick;
fc06_publish( 7U,
FC06_ACTOR_DAEMON,
( uint32_t ) tick,
timer );
}
else
{
lab_fail( 0xFC060103U );
}
}
__attribute__( ( noinline, used ) )
void fc06_controller_entry( void * context )
{
TimerExperiment * experiment = ( TimerExperiment * ) context;
TickType_t started;
if( experiment == NULL )
{
lab_fail( 0xFC060201U );
}
experiment->controller_sp = read_sp();
started = xTaskGetTickCount();
experiment->start_accepted =
( xTimerStart( experiment->one_shot, 0U ) == pdPASS ) &&
( xTimerStart( experiment->automatic, 0U ) == pdPASS );
fc06_publish( 2U,
FC06_ACTOR_CONTROLLER,
experiment->start_accepted,
experiment );
vTaskDelay( 1U );
experiment->reset_accepted =
xTimerReset( experiment->one_shot, 0U ) == pdPASS;
fc06_publish( 3U,
FC06_ACTOR_CONTROLLER,
experiment->reset_accepted,
experiment->one_shot );
while( experiment->auto_count < 2U )
{
if( ( xTaskGetTickCount() - started ) > FC06_TIMEOUT_TICKS )
{
lab_fail( 0xFC060202U );
}
vTaskDelay( 1U );
}
experiment->change_accepted =
xTimerChangePeriod( experiment->automatic, 3U, 0U ) == pdPASS;
fc06_publish( 6U,
FC06_ACTOR_CONTROLLER,
experiment->change_accepted,
experiment->automatic );
while( experiment->one_shot_count < 1U || experiment->auto_count < 3U )
{
if( ( xTaskGetTickCount() - started ) > FC06_TIMEOUT_TICKS )
{
lab_fail( 0xFC060203U );
}
vTaskDelay( 1U );
}
experiment->stop_accepted =
xTimerStop( experiment->automatic, 0U ) == pdPASS;
experiment->controller_done = 1U;
fc06_publish( 9U,
FC06_ACTOR_CONTROLLER,
experiment->stop_accepted,
experiment->automatic );
vTaskDelete( NULL );
lab_fail( 0xFC060204U );
}
__attribute__( ( noinline, used ) )
void fc06_verifier_entry( void * context )
{
TimerExperiment * experiment = ( TimerExperiment * ) context;
TickType_t started;
if( experiment == NULL )
{
lab_fail( 0xFC060301U );
}
started = xTaskGetTickCount();
while( experiment->controller_done == 0U )
{
if( ( xTaskGetTickCount() - started ) > FC06_TIMEOUT_TICKS )
{
lab_fail( 0xFC060302U );
}
vTaskDelay( 1U );
}
experiment->pass =
experiment->start_accepted != 0U &&
experiment->reset_accepted != 0U &&
experiment->change_accepted != 0U &&
experiment->stop_accepted != 0U &&
experiment->one_shot_count == 1U &&
experiment->auto_count == 3U &&
fc06_timeline_is_exact( experiment->auto_tick,
experiment->one_shot_tick ) != 0 &&
experiment->daemon_seen == xTimerGetTimerDaemonTaskHandle() &&
experiment->daemon_seen != experiment->controller &&
experiment->callback_sp != experiment->controller_sp &&
g_fc06_event_count == 9U;
g_fc06_pass = experiment->pass;
fc06_publish( 10U,
FC06_ACTOR_VERIFIER,
experiment->pass,
experiment );
experiment->digest = fc06_digest( g_fc06_events, g_fc06_event_count );
if( experiment->pass == 0U )
{
lab_fail( 0xFC060303U );
}
lab_puts( "PASS FC06: one-shot reset, auto-reload period change, daemon\n" );
lab_put_u32( experiment->digest );
lab_exit( 0U );
}
static TaskHandle_t fc06_create_task( TaskFunction_t entry,
const char * name,
UBaseType_t priority )
{
TaskHandle_t handle = NULL;
if( xTaskCreate( entry,
name,
FC06_TASK_STACK_WORDS,
&g_fc06,
priority,
&handle ) != pdPASS )
{
lab_fail( 0xFC060401U + priority );
}
return handle;
}
int main( void )
{
lab_heap_initialize();
g_fc06.one_shot_tag.kind = FC06_TIMER_ONE_SHOT;
g_fc06.one_shot_tag.marker = 0xFC0600A5U;
g_fc06.automatic_tag.kind = FC06_TIMER_AUTO;
g_fc06.automatic_tag.marker = 0xFC0600A5U;
fc06_publish( 1U, FC06_ACTOR_MAIN, configTIMER_QUEUE_LENGTH, &g_fc06 );
g_fc06.one_shot = xTimerCreate( "one-shot",
5U,
pdFALSE,
&g_fc06.one_shot_tag,
fc06_timer_callback );
g_fc06.automatic = xTimerCreate( "auto",
2U,
pdTRUE,
&g_fc06.automatic_tag,
fc06_timer_callback );
if( g_fc06.one_shot == NULL || g_fc06.automatic == NULL )
{
lab_fail( 0xFC060405U );
}
g_fc06.controller =
fc06_create_task( fc06_controller_entry,
"controller",
FC06_CONTROLLER_PRIORITY );
g_fc06.verifier =
fc06_create_task( fc06_verifier_entry,
"verifier",
FC06_VERIFIER_PRIORITY );
vTaskStartScheduler();
lab_fail( 0xFC060406U );
}