Skip to content

Commit

Permalink
Add boilerplate for sifive,trace 'uart' driver
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
  • Loading branch information
nategraff-sifive committed Aug 19, 2019
1 parent 2444567 commit 2df07a2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ nobase_include_HEADERS = \
metal/drivers/sifive_rtc0.h \
metal/drivers/sifive_spi0.h \
metal/drivers/sifive_test0.h \
metal/drivers/sifive_trace.h \
metal/drivers/sifive_uart0.h \
metal/drivers/sifive_wdog0.h \
metal/machine/inline.h \
Expand Down Expand Up @@ -178,6 +179,7 @@ libriscv__mmachine__@MACHINE_NAME@_a_SOURCES = \
src/drivers/sifive_rtc0.c \
src/drivers/sifive_spi0.c \
src/drivers/sifive_test0.c \
src/drivers/sifive_trace.c \
src/drivers/sifive_uart0.c \
src/drivers/sifive_wdog0.c \
src/button.c \
Expand Down
21 changes: 21 additions & 0 deletions Makefile.in

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions metal/drivers/sifive_trace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright 2019 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#ifndef METAL__DRIVERS__SIFIVE_TRACE_H
#define METAL__DRIVERS__SIFIVE_TRACE_H

#include <metal/io.h>
#include <metal/uart.h>
#include <metal/compiler.h>

struct __metal_driver_vtable_sifive_trace {
const struct metal_uart_vtable uart;
};

struct __metal_driver_sifive_trace;

__METAL_DECLARE_VTABLE(__metal_driver_vtable_sifive_trace)

struct __metal_driver_sifive_trace {
struct metal_uart uart;
};

#endif /* METAL__DRIVERS__SIFIVE_TRACE_H */
44 changes: 44 additions & 0 deletions src/drivers/sifive_trace.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright 2019 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#include <metal/machine/platform.h>

#ifdef METAL_SIFIVE_TRACE

#include <metal/drivers/sifive_trace.h>
#include <metal/machine.h>

#define TRACE_REG(base, offset) (((unsigned long)base + offset))
#define TRACE_REGB(base, offset) (__METAL_ACCESS_ONCE((__metal_io_u8 *)TRACE_REG(base, offset)))
#define TRACE_REGW(base, offset) (__METAL_ACCESS_ONCE((__metal_io_u32 *)TRACE_REG(base, offset)))

int __metal_driver_sifive_trace_putc(struct metal_uart *trace, unsigned char c)
{
long base = __metal_driver_sifive_trace_base(trace);
return 0;
}

int __metal_driver_sifive_trace_getc(struct metal_uart *trace, unsigned char *c)
{
long base = __metal_driver_sifive_trace_base(trace);
return 0;
}

void __metal_driver_sifive_trace_init(struct metal_uart *trace, int baud_rate)
{
long base = __metal_driver_sifive_trace_base(trace);
}

__METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_trace) = {
.uart.init = __metal_driver_sifive_trace_init,
.uart.putc = __metal_driver_sifive_trace_putc,
.uart.getc = __metal_driver_sifive_trace_getc,

.uart.get_baud_rate = NULL,
.uart.set_baud_rate = NULL,

.uart.controller_interrupt = NULL,
.uart.get_interrupt_id = NULL,
};

#endif /* METAL_SIFIVE_TRACE */

0 comments on commit 2df07a2

Please sign in to comment.