blob: 0635003d74b067c1fe12373bc847ec3222326413 [file] [log] [blame]
// Copyright 2023 Google LLC.
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#include "hw/top_matcha/sw/autogen/top_matcha.h"
#include "sw/device/lib/base/abs_mmio.h"
#include "sw/device/lib/base/memory.h"
#include "sw/device/lib/dif/dif_aon_timer.h"
#include "sw/device/lib/dif/dif_base.h"
#include "sw/device/lib/dif/dif_clkmgr.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/aon_timer_testutils.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
OTTF_DEFINE_TEST_CONFIG();
static dif_aon_timer_t aon_timer;
/**
* Turn off the clock for 400us, then turn on
* Check the result in chip_sw_clkmgr_off_peri_vseq
*/
static void test_gateable_clocks_off_without_reset(
const dif_clkmgr_t *clkmgr, dif_clkmgr_gateable_clock_t clock) {
// Make sure the clock for the unit is on.
CHECK_DIF_OK(
dif_clkmgr_gateable_clock_set_enabled(clkmgr, clock, kDifToggleEnabled));
LOG_INFO("Testing gateable clock ...");
// Disable the peripheral's clock.
CHECK_DIF_OK(
dif_clkmgr_gateable_clock_set_enabled(clkmgr, clock, kDifToggleDisabled));
// Wait for the clock to really turn off.
busy_spin_micros(400);
// Enalbe the clock
CHECK_DIF_OK(
dif_clkmgr_gateable_clock_set_enabled(clkmgr, clock, kDifToggleEnabled));
}
bool test_main(void) {
dif_clkmgr_t clkmgr;
CHECK_DIF_OK(dif_clkmgr_init(
mmio_region_from_addr(TOP_MATCHA_CLKMGR_AON_BASE_ADDR), &clkmgr));
// Initialize aon timer.
CHECK_DIF_OK(dif_aon_timer_init(
mmio_region_from_addr(TOP_MATCHA_AON_TIMER_AON_BASE_ADDR), &aon_timer));
test_gateable_clocks_off_without_reset(&clkmgr,
kTopMatchaGateableClocksSmcPeri);
return true;
}