xref: /openbmc/qemu/tests/qtest/stm32l4x5.h (revision f774a677507966222624a9b2859f06ede7608100)
1*88446cfeSInès Varhol /*
2*88446cfeSInès Varhol  * QTest testcase header for STM32L4X5 :
3*88446cfeSInès Varhol  * used for consolidating common objects in stm32l4x5_*-test.c
4*88446cfeSInès Varhol  *
5*88446cfeSInès Varhol  * Copyright (c) 2024 Arnaud Minier <arnaud.minier@telecom-paris.fr>
6*88446cfeSInès Varhol  * Copyright (c) 2024 Inès Varhol <ines.varhol@telecom-paris.fr>
7*88446cfeSInès Varhol  *
8*88446cfeSInès Varhol  * This work is licensed under the terms of the GNU GPL, version 2 or later.
9*88446cfeSInès Varhol  * See the COPYING file in the top-level directory.
10*88446cfeSInès Varhol  */
11*88446cfeSInès Varhol 
12*88446cfeSInès Varhol #include "libqtest.h"
13*88446cfeSInès Varhol 
14*88446cfeSInès Varhol /* copied from clock.h */
15*88446cfeSInès Varhol #define CLOCK_PERIOD_1SEC (1000000000llu << 32)
16*88446cfeSInès Varhol #define CLOCK_PERIOD_FROM_HZ(hz) (((hz) != 0) ? CLOCK_PERIOD_1SEC / (hz) : 0u)
17*88446cfeSInès Varhol /*
18*88446cfeSInès Varhol  * MSI (4 MHz) is used as system clock source after startup
19*88446cfeSInès Varhol  * from Reset.
20*88446cfeSInès Varhol  * AHB, APB1 and APB2 prescalers are set to 1 at reset.
21*88446cfeSInès Varhol  */
22*88446cfeSInès Varhol #define SYSCLK_PERIOD CLOCK_PERIOD_FROM_HZ(4000000)
23*88446cfeSInès Varhol #define RCC_AHB2ENR 0x4002104C
24*88446cfeSInès Varhol #define RCC_APB1ENR1 0x40021058
25*88446cfeSInès Varhol #define RCC_APB1ENR2 0x4002105C
26*88446cfeSInès Varhol #define RCC_APB2ENR 0x40021060
27*88446cfeSInès Varhol 
28*88446cfeSInès Varhol 
get_clock_period(QTestState * qts,const char * path)29*88446cfeSInès Varhol static inline uint64_t get_clock_period(QTestState *qts, const char *path)
30*88446cfeSInès Varhol {
31*88446cfeSInès Varhol     uint64_t clock_period = 0;
32*88446cfeSInès Varhol     QDict *r;
33*88446cfeSInès Varhol 
34*88446cfeSInès Varhol     r = qtest_qmp(qts, "{ 'execute': 'qom-get', 'arguments':"
35*88446cfeSInès Varhol         " { 'path': %s, 'property': 'qtest-clock-period'} }", path);
36*88446cfeSInès Varhol     g_assert_false(qdict_haskey(r, "error"));
37*88446cfeSInès Varhol     clock_period = qdict_get_int(r, "return");
38*88446cfeSInès Varhol     qobject_unref(r);
39*88446cfeSInès Varhol     return clock_period;
40*88446cfeSInès Varhol }
41*88446cfeSInès Varhol 
42*88446cfeSInès Varhol 
43