/***************************************************************************
 * 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 Copilot (Sonnet 4.6).
 * 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 <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "mmio_mock.h"
#define PULP_SOC_PERIPHERALS_ADDR 0U
#define PULP_FC_TIMER_OFFSET      0U

#include "bits.h"
#include "timer.h"
#include "timer_irq.h"
#include "../../bsp/timer_irq.c"

static void test_timer_irq_init(void)
{
    uint32_t cfg;
    int ret;

    memset(mock_mmio, 0, sizeof(mock_mmio));
    ret = timer_irq_init(327U);
    assert(ret == 0);
    assert(mock_mmio[TIMER_CMP_LO_OFFSET / 4U] == 327U);

    cfg = mock_mmio[TIMER_CFG_LO_OFFSET / 4U];
    assert((cfg & TIMER_CFG_LO_ENABLE_MASK) != 0U);
    assert((cfg & TIMER_CFG_LO_IRQEN_MASK) != 0U);
    assert((cfg & TIMER_CFG_LO_CCFG_MASK) != 0U);
    assert((cfg & TIMER_CFG_LO_MODE_MASK) != 0U);
    printf("test_timer_irq_init: PASS\n");
}

int main(void)
{
    test_timer_irq_init();
    printf("All timer tests passed.\n");
    return 0;
}
