/*
 * QTest testcase for STML4X5_USART
 *
 * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr>
 * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
 */

#include "qemu/osdep.h"
#include "libqtest.h"
#include "hw/misc/stm32l4x5_rcc_internals.h"
#include "hw/registerfields.h"

#define RCC_BASE_ADDR 0x40021000
/* Use USART 1 ADDR, assume the others work the same */
#define USART1_BASE_ADDR 0x40013800

/* See stm32l4x5_usart for definitions */
REG32(CR1, 0x00)
    FIELD(CR1, M1, 28, 1)
    FIELD(CR1, OVER8, 15, 1)
    FIELD(CR1, M0, 12, 1)
    FIELD(CR1, PCE, 10, 1)
    FIELD(CR1, TXEIE, 7, 1)
    FIELD(CR1, RXNEIE, 5, 1)
    FIELD(CR1, TE, 3, 1)
    FIELD(CR1, RE, 2, 1)
    FIELD(CR1, UE, 0, 1)
REG32(CR2, 0x04)
REG32(CR3, 0x08)
    FIELD(CR3, OVRDIS, 12, 1)
REG32(BRR, 0x0C)
REG32(GTPR, 0x10)
REG32(RTOR, 0x14)
REG32(RQR, 0x18)
REG32(ISR, 0x1C)
    FIELD(ISR, TXE, 7, 1)
    FIELD(ISR, RXNE, 5, 1)
    FIELD(ISR, ORE, 3, 1)
REG32(ICR, 0x20)
REG32(RDR, 0x24)
REG32(TDR, 0x28)

#define NVIC_ISPR1 0XE000E204
#define NVIC_ICPR1 0xE000E284
#define USART1_IRQ 37

static bool check_nvic_pending(QTestState *qts, unsigned int n)
{
    /* No USART interrupts are less than 32 */
    assert(n > 32);
    n -= 32;
    return qtest_readl(qts, NVIC_ISPR1) & (1 << n);
}

static bool clear_nvic_pending(QTestState *qts, unsigned int n)
{
    /* No USART interrupts are less than 32 */
    assert(n > 32);
    n -= 32;
    qtest_writel(qts, NVIC_ICPR1, (1 << n));
    return true;
}

/*
 * Wait indefinitely for the flag to be updated.
 * If this is run on a slow CI runner,
 * the meson harness will timeout after 10 minutes for us.
 */
static bool usart_wait_for_flag(QTestState *qts, uint32_t event_addr,
                                uint32_t flag)
{
    while (true) {
        if ((qtest_readl(qts, event_addr) & flag)) {
            return true;
        }
        g_usleep(1000);
    }

    return false;
}

static void usart_receive_string(QTestState *qts, int sock_fd, const char *in,
                                 char *out)
{
    int i, in_len = strlen(in);

    g_assert_true(send(sock_fd, in, in_len, 0) == in_len);
    for (i = 0; i < in_len; i++) {
        g_assert_true(usart_wait_for_flag(qts,
            USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK));
        out[i] = qtest_readl(qts, USART1_BASE_ADDR + A_RDR);
    }
    out[i] = '\0';
}

static void usart_send_string(QTestState *qts, const char *in)
{
    int i, in_len = strlen(in);

    for (i = 0; i < in_len; i++) {
        qtest_writel(qts, USART1_BASE_ADDR + A_TDR, in[i]);
        g_assert_true(usart_wait_for_flag(qts,
            USART1_BASE_ADDR + A_ISR, R_ISR_TXE_MASK));
    }
}

/* Init the RCC clocks to run at 80 MHz */
static void init_clocks(QTestState *qts)
{
    uint32_t value;

    /* MSIRANGE can be set only when MSI is OFF or READY */
    qtest_writel(qts, (RCC_BASE_ADDR + A_CR), R_CR_MSION_MASK);

    /* Clocking from MSI, in case MSI was not the default source */
    qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), 0);

    /*
     * Update PLL and set MSI as the source clock.
     * PLLM = 1 --> 000
     * PLLN = 40 --> 40
     * PPLLR = 2 --> 00
     * PLLDIV = unused, PLLP = unused (SAI3), PLLQ = unused (48M1)
     * SRC = MSI --> 01
     */
    qtest_writel(qts, (RCC_BASE_ADDR + A_PLLCFGR), R_PLLCFGR_PLLREN_MASK |
            (40 << R_PLLCFGR_PLLN_SHIFT) |
            (0b01 << R_PLLCFGR_PLLSRC_SHIFT));

    /* PLL activation */

    value = qtest_readl(qts, (RCC_BASE_ADDR + A_CR));
    qtest_writel(qts, (RCC_BASE_ADDR + A_CR), value | R_CR_PLLON_MASK);

    /* RCC_CFGR is OK by defaut */
    qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), 0);

    /* CCIPR : no periph clock by default */
    qtest_writel(qts, (RCC_BASE_ADDR + A_CCIPR), 0);

    /* Switches on the PLL clock source */
    value = qtest_readl(qts, (RCC_BASE_ADDR + A_CFGR));
    qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), (value & ~R_CFGR_SW_MASK) |
        (0b11 << R_CFGR_SW_SHIFT));

    /* Enable SYSCFG clock enabled */
    qtest_writel(qts, (RCC_BASE_ADDR + A_APB2ENR), R_APB2ENR_SYSCFGEN_MASK);

    /* Enable the IO port B clock (See p.252) */
    qtest_writel(qts, (RCC_BASE_ADDR + A_AHB2ENR), R_AHB2ENR_GPIOBEN_MASK);

    /* Enable the clock for USART1 (cf p.259) */
    /* We rewrite SYSCFGEN to not disable it */
    qtest_writel(qts, (RCC_BASE_ADDR + A_APB2ENR),
                 R_APB2ENR_SYSCFGEN_MASK | R_APB2ENR_USART1EN_MASK);

    /* TODO: Enable usart via gpio */

    /* Set PCLK as the clock for USART1(cf p.272) i.e. reset both bits */
    qtest_writel(qts, (RCC_BASE_ADDR + A_CCIPR), 0);

    /* Reset USART1 (see p.249) */
    qtest_writel(qts, (RCC_BASE_ADDR + A_APB2RSTR), 1 << 14);
    qtest_writel(qts, (RCC_BASE_ADDR + A_APB2RSTR), 0);
}

static void init_uart(QTestState *qts)
{
    uint32_t cr1;

    init_clocks(qts);

    /*
     * For 115200 bauds, see p.1349.
     * The clock has a frequency of 80Mhz,
     * for 115200, we have to put a divider of 695 = 0x2B7.
     */
    qtest_writel(qts, (USART1_BASE_ADDR + A_BRR), 0x2B7);

    /*
     * Set the oversampling by 16,
     * disable the parity control and
     * set the word length to 8. (cf p.1377)
     */
    cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1));
    cr1 &= ~(R_CR1_M1_MASK | R_CR1_M0_MASK | R_CR1_OVER8_MASK | R_CR1_PCE_MASK);
    qtest_writel(qts, (USART1_BASE_ADDR + A_CR1), cr1);

    /* Enable the transmitter, the receiver and the USART. */
    qtest_writel(qts, (USART1_BASE_ADDR + A_CR1),
        R_CR1_UE_MASK | R_CR1_RE_MASK | R_CR1_TE_MASK);
}

static void test_write_read(void)
{
    QTestState *qts = qtest_init("-M b-l475e-iot01a");

    /* Test that we can write and retrieve a value from the device */
    qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 0xFFFFFFFF);
    const uint32_t tdr = qtest_readl(qts, USART1_BASE_ADDR + A_TDR);
    g_assert_cmpuint(tdr, ==, 0x000001FF);

    qtest_quit(qts);
}

static void test_receive_char(void)
{
    int sock_fd;
    uint32_t cr1;
    QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd);

    init_uart(qts);

    /* Try without initializing IRQ */
    g_assert_true(send(sock_fd, "a", 1, 0) == 1);
    usart_wait_for_flag(qts, USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK);
    g_assert_cmphex(qtest_readl(qts, USART1_BASE_ADDR + A_RDR), ==, 'a');
    g_assert_false(check_nvic_pending(qts, USART1_IRQ));

    /* Now with the IRQ */
    cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1));
    cr1 |= R_CR1_RXNEIE_MASK;
    qtest_writel(qts, USART1_BASE_ADDR + A_CR1, cr1);
    g_assert_true(send(sock_fd, "b", 1, 0) == 1);
    usart_wait_for_flag(qts, USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK);
    g_assert_cmphex(qtest_readl(qts, USART1_BASE_ADDR + A_RDR), ==, 'b');
    g_assert_true(check_nvic_pending(qts, USART1_IRQ));
    clear_nvic_pending(qts, USART1_IRQ);

    close(sock_fd);

    qtest_quit(qts);
}

static void test_send_char(void)
{
    int sock_fd;
    char s[1];
    uint32_t cr1;
    QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd);

    init_uart(qts);

    /* Try without initializing IRQ */
    qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 'c');
    g_assert_true(recv(sock_fd, s, 1, 0) == 1);
    g_assert_cmphex(s[0], ==, 'c');
    g_assert_false(check_nvic_pending(qts, USART1_IRQ));

    /* Now with the IRQ */
    cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1));
    cr1 |= R_CR1_TXEIE_MASK;
    qtest_writel(qts, USART1_BASE_ADDR + A_CR1, cr1);
    qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 'd');
    g_assert_true(recv(sock_fd, s, 1, 0) == 1);
    g_assert_cmphex(s[0], ==, 'd');
    g_assert_true(check_nvic_pending(qts, USART1_IRQ));
    clear_nvic_pending(qts, USART1_IRQ);

    close(sock_fd);

    qtest_quit(qts);
}

static void test_receive_str(void)
{
    int sock_fd;
    char s[10];
    QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd);

    init_uart(qts);

    usart_receive_string(qts, sock_fd, "hello", s);
    g_assert_true(memcmp(s, "hello", 5) == 0);

    close(sock_fd);

    qtest_quit(qts);
}

static void test_send_str(void)
{
    int sock_fd;
    char s[10];
    QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd);

    init_uart(qts);

    usart_send_string(qts, "world");
    g_assert_true(recv(sock_fd, s, 10, 0) == 5);
    g_assert_true(memcmp(s, "world", 5) == 0);

    close(sock_fd);

    qtest_quit(qts);
}

int main(int argc, char **argv)
{
    int ret;

    g_test_init(&argc, &argv, NULL);
    g_test_set_nonfatal_assertions();

    qtest_add_func("stm32l4x5/usart/write_read", test_write_read);
    qtest_add_func("stm32l4x5/usart/receive_char", test_receive_char);
    qtest_add_func("stm32l4x5/usart/send_char", test_send_char);
    qtest_add_func("stm32l4x5/usart/receive_str", test_receive_str);
    qtest_add_func("stm32l4x5/usart/send_str", test_send_str);
    ret = g_test_run();

    return ret;
}

