Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chips/earlgrey: Use the peripheral clock frequency #2133

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions chips/earlgrey/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use crate::usbdev;

PMPConfigMacro!(4);

pub const CHIP_FREQ: u32 = CONFIG.chip_freq;

pub struct EarlGrey<A: 'static + Alarm<'static>> {
userspace_kernel_boundary: SysCall,
pmp: PMP,
Expand Down
12 changes: 8 additions & 4 deletions chips/earlgrey/src/chip_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ pub struct Config<'a> {
/// Identifier for the platform. This is useful for debugging to confirm the
/// correct configuration of the chip is being used.
pub name: &'a str,
/// The clock speed of the core in Hz.
pub chip_freq: u32,
/// The clock speed of the CPU in Hz.
pub cpu_freq: u32,
/// The clock speed of the peripherals in Hz.
pub peripheral_freq: u32,
/// The baud rate for UART. This allows for a version of the chip that can
/// support a faster baud rate to use it to help with debugging.
pub uart_baudrate: u32,
Expand All @@ -29,14 +31,16 @@ pub struct Config<'a> {
))]
pub const CONFIG: Config = Config {
name: "fpga_nexysvideo",
chip_freq: 50_000_000,
cpu_freq: 50_000_000,
peripheral_freq: 12_500_000,
uart_baudrate: 230400,
};

/// Config for running EarlGrey in a verilog simulator.
#[cfg(feature = "config_sim_verilator")]
pub const CONFIG: Config = Config {
name: "sim_verilator",
chip_freq: 500_000,
cpu_freq: 500_000,
peripheral_freq: 125_000,
uart_baudrate: 9600,
};
4 changes: 2 additions & 2 deletions chips/earlgrey/src/i2c.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::chip;
use crate::chip_config::CONFIG;
use kernel::common::StaticRef;
use lowrisc::i2c::{I2c, I2cRegisters};

pub static mut I2C: I2c = I2c::new(I2C_BASE, (1 / chip::CHIP_FREQ) * 1000 * 1000);
pub static mut I2C: I2c = I2c::new(I2C_BASE, (1 / CONFIG.cpu_freq) * 1000 * 1000);

// This is a placeholder address as the I2C MMIO interface isn't avaliable yet
const I2C_BASE: StaticRef<I2cRegisters> =
Expand Down
5 changes: 2 additions & 3 deletions chips/earlgrey/src/timer.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//! Timer driver.

use crate::chip_config::CONFIG;
use kernel::common::cells::OptionalCell;
use kernel::common::registers::{register_bitfields, register_structs, ReadWrite, WriteOnly};
use kernel::common::StaticRef;
use kernel::hil::time;
use kernel::hil::time::{Ticks, Ticks64, Time};
use kernel::ReturnCode;

use crate::chip::CHIP_FREQ;

const PRESCALE: u16 = ((CHIP_FREQ / 10_000) - 1) as u16; // 10Khz
const PRESCALE: u16 = ((CONFIG.cpu_freq / 10_000) - 1) as u16; // 10Khz

/// 10KHz `Frequency`
#[derive(Debug)]
Expand Down
6 changes: 2 additions & 4 deletions chips/earlgrey/src/uart.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::chip_config::CONFIG;
use kernel::common::StaticRef;
use lowrisc::uart::{Uart, UartRegisters};

use crate::chip;
use crate::chip_config::CONFIG;

pub const UART0_BAUDRATE: u32 = CONFIG.uart_baudrate;

pub static mut UART0: Uart = Uart::new(UART0_BASE, chip::CHIP_FREQ);
pub static mut UART0: Uart = Uart::new(UART0_BASE, CONFIG.peripheral_freq);

const UART0_BASE: StaticRef<UartRegisters> =
unsafe { StaticRef::new(0x4000_0000 as *const UartRegisters) };