blob: 53552b8519043024d8d3df14a5db2352e7acbf1c [file] [log] [blame]
/*
* Copyright 2023 Google LLC
* Copyright lowRISC contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This test checks that when ml_clk is disabled, the corresponding output
// signal from clkmgr will be constant 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,
kTopMatchaGateableClocksMlPeri);
return true;
}