forked from lowRISC/opentitan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Douglas Reis <[email protected]>
- Loading branch information
Showing
3 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <stdint.h> | ||
|
||
#include "sw/device/lib/base/mmio.h" | ||
#include "sw/device/lib/dif/dif_pinmux.h" | ||
#include "sw/device/lib/dif/dif_pwm.h" | ||
#include "sw/device/lib/runtime/hart.h" | ||
#include "sw/device/lib/runtime/log.h" | ||
#include "sw/device/lib/testing/test_framework/check.h" | ||
#include "sw/device/lib/testing/test_framework/ottf_main.h" | ||
|
||
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" | ||
|
||
OTTF_DEFINE_TEST_CONFIG(); | ||
|
||
static status_t pwm_pinmux(void) { | ||
|
||
dif_pinmux_t pinmux; | ||
mmio_region_t base_addr = | ||
mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR); | ||
CHECK_DIF_OK(dif_pinmux_init(base_addr, &pinmux)); | ||
|
||
TRY(dif_pinmux_output_select(&pinmux, kTopEarlgreyPinmuxMioOutIoa8, | ||
kTopEarlgreyPinmuxOutselPwmAonPwm0)); | ||
|
||
return OK_STATUS(); | ||
} | ||
|
||
bool test_main(void) { | ||
dif_pwm_t pwm; | ||
mmio_region_t base_addr = mmio_region_from_addr(TOP_EARLGREY_PWM_AON_BASE_ADDR); | ||
CHECK_DIF_OK(dif_pwm_init(base_addr, &pwm)); | ||
CHECK_STATUS_OK(pwm_pinmux()); | ||
|
||
const dif_pwm_config_t kPwmConfig = { | ||
.clock_divisor = 0x08000, | ||
.beats_per_pulse_cycle = 2, | ||
}; | ||
CHECK_DIF_OK(dif_pwm_configure(&pwm, kPwmConfig)); | ||
|
||
dif_pwm_channel_config_t channel_config = { | ||
.duty_cycle_a = kPwmConfig.beats_per_pulse_cycle / 2, | ||
.duty_cycle_b = 0, | ||
.phase_delay = 0, | ||
.mode = kDifPwmModeFirmware, | ||
.polarity = kDifPwmPolarityActiveHigh, | ||
.blink_parameter_x = 0, | ||
.blink_parameter_y = 0, | ||
}; | ||
CHECK_DIF_OK(dif_pwm_configure_channel(&pwm, kDifPwmChannel0, channel_config)); | ||
CHECK_DIF_OK(dif_pwm_phase_cntr_set_enabled(&pwm, kDifToggleEnabled)); | ||
CHECK_DIF_OK(dif_pwm_channel_set_enabled(&pwm, kDifPwmChannel0, kDifToggleEnabled)); | ||
|
||
busy_spin_micros(500 * 1000); | ||
return true; | ||
} |