drivers: clock_control: Add clock_fixed_rate driver
Add fixed-clock clock control driver. This is a first step towards making fixed-clocks a first-class citizen in the clock control framework. Since the change is hidden behind a Kconfig enable this is opt-in for now. Signed-off-by: Moritz Fischer <moritzf@google.com>
This commit is contained in:
parent
4828c89fa2
commit
28ed7f057d
9 changed files with 179 additions and 0 deletions
9
tests/drivers/clock_control/fixed_clock/CMakeLists.txt
Normal file
9
tests/drivers/clock_control/fixed_clock/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(fixed_clock)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
17
tests/drivers/clock_control/fixed_clock/app.overlay
Normal file
17
tests/drivers/clock_control/fixed_clock/app.overlay
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Google, LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
*/
|
||||
|
||||
/ {
|
||||
test {
|
||||
test_fixed_rate_clk0: clk {
|
||||
compatible = "fixed-clock";
|
||||
clock-frequency = <100>;
|
||||
#clock-cells = <0>;
|
||||
};
|
||||
|
||||
};
|
||||
};
|
4
tests/drivers/clock_control/fixed_clock/prj.conf
Normal file
4
tests/drivers/clock_control/fixed_clock/prj.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_NEW_API=y
|
||||
CONFIG_CLOCK_CONTROL=y
|
||||
CONFIG_CLOCK_CONTROL_FIXED_RATE_CLOCK=y
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Google, LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/drivers/clock_control.h>
|
||||
|
||||
#define TEST_FIXED_RATE_CLK0 DT_NODELABEL(test_fixed_rate_clk0)
|
||||
#define TEST_FIXED_RATE_CLK0_RATE DT_PROP(TEST_FIXED_RATE_CLK0, clock_frequency)
|
||||
|
||||
/*
|
||||
* Basic test for checking correctness of clock_api implementation
|
||||
*/
|
||||
ZTEST(fixed_clk, test_fixed_rate_clk_on_off_status_rate)
|
||||
{
|
||||
const struct device *dev = DEVICE_DT_GET(TEST_FIXED_RATE_CLK0);
|
||||
enum clock_control_status status;
|
||||
uint32_t rate;
|
||||
int err;
|
||||
|
||||
zassert_equal(device_is_ready(dev), true, "%s: Device wasn't ready",
|
||||
dev->name);
|
||||
|
||||
status = clock_control_get_status(dev, 0);
|
||||
zassert_equal(status, CLOCK_CONTROL_STATUS_ON,
|
||||
"%s: Unexpected status (%d)", dev->name, status);
|
||||
|
||||
err = clock_control_on(dev, 0);
|
||||
zassert_equal(0, err, "%s: Unexpected err (%d)", dev->name, err);
|
||||
|
||||
status = clock_control_get_status(dev, 0);
|
||||
zassert_equal(status, CLOCK_CONTROL_STATUS_ON,
|
||||
"%s: Unexpected status (%d)", dev->name, status);
|
||||
|
||||
err = clock_control_off(dev, 0);
|
||||
zassert_equal(0, err, "%s: Expected 0, got (%d)",
|
||||
dev->name, err);
|
||||
|
||||
status = clock_control_get_status(dev, 0);
|
||||
zassert_equal(status, CLOCK_CONTROL_STATUS_ON,
|
||||
"%s: Unexpected status (%d)", dev->name, status);
|
||||
|
||||
err = clock_control_get_rate(dev, 0, &rate);
|
||||
zassert_equal(0, err, "%s: Unexpected err (%d)", dev->name, err);
|
||||
zassert_equal(TEST_FIXED_RATE_CLK0_RATE, rate,
|
||||
"%s: Got wrong rate, expected %u, got %u\n",
|
||||
dev->name, TEST_FIXED_RATE_CLK0_RATE, rate);
|
||||
}
|
||||
|
||||
ZTEST_SUITE(fixed_clk, NULL, NULL, NULL, NULL, NULL);
|
7
tests/drivers/clock_control/fixed_clock/testcase.yaml
Normal file
7
tests/drivers/clock_control/fixed_clock/testcase.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
tests:
|
||||
drivers.clock.clock_control_fixed_clock:
|
||||
tags:
|
||||
- drivers
|
||||
- clock
|
||||
platform_allow:
|
||||
- native_posix_64
|
Loading…
Add table
Add a link
Reference in a new issue