8000 I2C protocol refactor, Meson driver rewrite, added libi2c by omeh-a · Pull Request #434 · au-ts/sddf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

I2C protocol refactor, Meson driver rewrite, added libi2c #434

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 53 additions & 22 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ const DriverClass = struct {
virtio,
};

const Timer = enum {
arm,
meson,
imx,
jh7110,
goldfish
};
const Timer = enum { arm, meson, imx, jh7110, goldfish };

const Network = enum {
imx,
Expand Down Expand Up @@ -71,6 +65,9 @@ const util_putchar_serial_src = [_][]const u8{
"util/putchar_serial.c",
};

const libi2c_src = [_][]const u8{"i2c/libi2c.c"};
const libi2c_raw_src = [_][]const u8{"i2c/libi2c_raw.c"};

var libmicrokit: std.Build.LazyPath = undefined;
var libmicrokit_linker_script: std.Build.LazyPath = undefined;
var libmicrokit_include: std.Build.LazyPath = undefined;
Expand All @@ -93,7 +90,7 @@ fn addSerialDriver(
.virtio => "console.c",
else => "uart.c",
};
const source = b.fmt("drivers/serial/{s}/{s}", .{@tagName(class), source_name});
const source = b.fmt("drivers/serial/{s}/{s}", .{ @tagName(class), source_name });
const driver_include = b.fmt("drivers/serial/{s}/include", .{@tagName(class)});
driver.addCSourceFile(.{
.file = b.path(source),
Expand All @@ -119,7 +116,7 @@ fn addTimerDriver(
.optimize = optimize,
.strip = false,
});
const source = b.fmt("drivers/timer/{s}/timer.c", .{ @tagName(class) });
const source = b.fmt("drivers/timer/{s}/timer.c", .{@tagName(class)});
driver.addCSourceFile(.{
.file = b.path(source),
});
Expand Down Expand Up @@ -192,16 +189,16 @@ fn addBlockDriver(
optimize: std.builtin.OptimizeMode,
) *std.Bu 10000 ild.Step.Compile {
const driver = addPd(b, .{
.name = b.fmt("driver_blk_{s}.elf", .{ @tagName(class) }),
.name = b.fmt("driver_blk_{s}.elf", .{@tagName(class)}),
.target = target,
.optimize = optimize,
.strip = false,
});
const source = b.fmt("drivers/blk/{s}/block.c", .{ @tagName(class) });
const source = b.fmt("drivers/blk/{s}/block.c", .{@tagName(class)});
driver.addCSourceFile(.{
.file = b.path(source),
});
driver.addIncludePath(b.path(b.fmt("drivers/blk/{s}/", .{ @tagName(class) })));
driver.addIncludePath(b.path(b.fmt("drivers/blk/{s}/", .{@tagName(class)})));
driver.addIncludePath(b.path("include"));
driver.addIncludePath(b.path("include/microkit"));
driver.linkLibrary(util);
Expand All @@ -217,16 +214,16 @@ fn addMmcDriver(
optimize: std.builtin.OptimizeMode,
) *std.Build.Step.Compile {
const driver = addPd(b, .{
.name = b.fmt("driver_blk_mmc_{s}.elf", .{ @tagName(class) }),
.name = b.fmt("driver_blk_mmc_{s}.elf", .{@tagName(class)}),
.target = target,
.optimize = optimize,
.strip = false,
});
const source = b.fmt("drivers/blk/mmc/{s}/usdhc.c", .{ @tagName(class) });
const source = b.fmt("drivers/blk/mmc/{s}/usdhc.c", .{@tagName(class)});
driver.addCSourceFile(.{
.file = b.path(source),
});
driver.addIncludePath(b.path(b.fmt("drivers/blk/mmc/{s}/", .{ @tagName(class) })));
driver.addIncludePath(b.path(b.fmt("drivers/blk/mmc/{s}/", .{@tagName(class)})));
driver.addIncludePath(b.path("include"));
driver.addIncludePath(b.path("include/microkit"));
driver.linkLibrary(util);
Expand All @@ -242,16 +239,16 @@ fn addNetworkDriver(
optimize: std.builtin.OptimizeMode,
) *std.Build.Step.Compile {
const driver = addPd(b, .{
.name = b.fmt("driver_net_{s}.elf", .{ @tagName(class) }),
.name = b.fmt("driver_net_{s}.elf", .{@tagName(class)}),
.target = target,
.optimize = optimize,
.strip = false,
});
const source = b.fmt("drivers/network/{s}/ethernet.c", .{ @tagName(class) });
const source = b.fmt("drivers/network/{s}/ethernet.c", .{@tagName(class)});
driver.addCSourceFile(.{
.file = b.path(source),
});
driver.addIncludePath(b.path(b.fmt("drivers/network/{s}/", .{ @tagName(class) })));
driver.addIncludePath(b.path(b.fmt("drivers/network/{s}/", .{@tagName(class)})));
driver.addIncludePath(b.path("include"));
driver.addIncludePath(b.path("include/microkit"));
driver.linkLibrary(util);
Expand All @@ -268,17 +265,17 @@ fn addGpuDriver(
optimize: std.builtin.OptimizeMode,
) *std.Build.Step.Compile {
const driver = addPd(b, .{
.name = b.fmt("driver_gpu_{s}.elf", .{ @tagName(class) }),
.name = b.fmt("driver_gpu_{s}.elf", .{@tagName(class)}),
.target = target,
.optimize = optimize,
.strip = false,
});
const source = b.fmt("drivers/gpu/{s}/gpu.c", .{ @tagName(class) });
const source = b.fmt("drivers/gpu/{s}/gpu.c", .{@tagName(class)});
driver.addCSourceFile(.{
.file = b.path(source),
});
driver.addIncludePath(gpu_config_include);
driver.addIncludePath(b.path(b.fmt("drivers/gpu/{s}/", .{ @tagName(class) })));
driver.addIncludePath(b.path(b.fmt("drivers/gpu/{s}/", .{@tagName(class)})));
driver.addIncludePath(b.path("include"));
driver.addIncludePath(b.path("include/microkit"));
driver.linkLibrary(util);
Expand Down Expand Up @@ -365,7 +362,7 @@ pub fn build(b: *std.Build) !void {
.strip = false,
});
blk_virt.addCSourceFiles(.{
.files = &. { "blk/components/virt.c", "blk/components/partitioning.c" },
.files = &.{ "blk/components/virt.c", "blk/components/partitioning.c" },
});
blk_virt.addIncludePath(b.path("include"));
blk_virt.addIncludePath(b.path("include/microkit"));
Expand Down Expand Up @@ -470,6 +467,40 @@ pub fn build(b: *std.Build) !void {
i2c_virt.linkLibrary(util_putchar_debug);
b.installArtifact(i2c_virt);

const libi2c = b.addStaticLibrary(.{
.name = "libi2c",
.target = target,
.optimize = optimize,
});
libi2c.addCSourceFiles(.{
.files = &libi2c_src,
});
libi2c.addIncludePath(b.path("include/sddf/i2c"));
libi2c.addIncludePath(b.path("include/sddf"));
libi2c.addIncludePath(b.path("include/microkit"));
libi2c.addIncludePath(b.path("include/"));
libi2c.addIncludePath(b.path("libco/"));
libi2c.addIncludePath(libmicrokit_include);
libi2c.installHeadersDirectory(b.path("include"), "", .{});
b.installArtifact(libi2c);

const libi2c_raw = b.addStaticLibrary(.{
.name = "libi2c_raw",
.target = target,
.optimize = optimize,
});
libi2c_raw.addCSourceFiles(.{
.files = &libi2c_raw_src,
});
libi2c_raw.addIncludePath(b.path("include/sddf/i2c"));
libi2c_raw.addIncludePath(b.path("include/sddf"));
libi2c_raw.addIncludePath(b.path("include/microkit"));
libi2c_raw.addIncludePath(b.path("include/"));
libi2c_raw.addIncludePath(b.path("libco/"));
libi2c_raw.addIncludePath(libmicrokit_include);
libi2c_raw.installHeadersDirectory(b.path("include"), "", .{});
b.installArtifact(libi2c_raw);

// I2C drivers
inline for (std.meta.fields(DriverClass.I2cHost)) |class| {
const driver = addI2cDriverHost(b, util, @enumFromInt(class.value), target, optimize);
Expan 9E81 d Down
43 changes: 1 addition & 42 deletions drivers/i2c/meson/driver.h
Original file line number Diff line number Diff line change
@@ -1,52 +1,11 @@
/*
* Copyright 2023, UNSW
* Copyright 2025, UNSW
*
* SPDX-License-Identifier: BSD-2-Clause
*/

// i2c-driver.h
// Header containing all generic features for I2C drivers targeting the
// sDDF and seL4 core platform.
// Matt Rossouw (matthew.rossouw@unsw.edu.au)
// 08/2023

#pragma once

#include <stdint.h>
#include <sddf/util/printf.h>
#include "gpio.h"
#include "clk.h"

enum data_direction {
DATA_DIRECTION_WRITE = 0x0,
DATA_DIRECTION_READ = 0x1
};

// Driver state
typedef struct _i2c_ifState {
/* Pointer to current request/response being handled */
uint8_t *curr_data;
/* Number of bytes in current request (number of tokens) */
int curr_request_len;
/* Number of bytes in current response (only the data) and not the error tokens at the start */
int curr_response_len;
/* Number of bytes remaining to dispatch in the current request.*/
size_t remaining;
/* Flag indicating that there is more independent requests waiting on the queue_handle.request. */
bool notified;

/* Number of bytes to read/write if request data offset is in the midst of a buffer. If this is
zero, no read/write is in progress and we can interpret the current byte as a token.*/
uint8_t rw_remaining;

enum data_direction data_direction;
/* I2C bus address of the current request being handled */
size_t addr;
} i2c_ifState_t;

#define DATA_DIRECTION_WRITE (0x0)
#define DATA_DIRECTION_READ (0x1)

// Ctl register fields
#define REG_CTRL_START (BIT(0))
#define REG_CTRL_ACK_IGNORE (BIT(1))
Expand Down
Loading
Loading
0