/*************************************************************************** * Copyright (c) 2026 Eclipse ThreadX contributors * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. * * AI Disclosure: This file was largely AI-generated by Codex (GPT-6-Sol). * The AI-generated portions may be considered public domain (CC0-1.0) * and not subject to the project's licence. The human contributor has * reviewed and verified that the code is correct. * * SPDX-License-Identifier: MIT and CC0-1.0 ***************************************************************************/ #include "tx_api.h" #include "hwtimer.h" #include "plic.h" #include "uart.h" #include #define TEST_TIMER_INTERVAL 8u #define TEST_MCAUSE_TIMER (((uintptr_t)1u << 63) | 7u) extern volatile unsigned int test_irq_count; extern volatile unsigned int test_expected_bit; /* Toggle source 2 in timer context to preempt source 1 updates. */ void trap_handler(uintptr_t mcause, uintptr_t mepc, uintptr_t mtval) { (void)mepc; (void)mtval; if (mcause != TEST_MCAUSE_TIMER) { uart_puts("TEST_PLIC_UNEXPECTED_TRAP"); for (;;) { } } /* MISRA C:2012 Rule 11.4 deviation: the timer has a fixed MMIO address. */ *(volatile uint64_t *)ERBIUM_MTIMECMP = *(volatile uint64_t *)ERBIUM_MTIME + TEST_TIMER_INTERVAL; if (test_expected_bit == 0u) { plic_irq_enable(2); test_expected_bit = 1u; } else { plic_irq_disable(2); test_expected_bit = 0u; } test_irq_count++; }