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

Implement LCD demo #110

Open
wants to merge 8 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
2 changes: 1 addition & 1 deletion rtl/system/ibex_demo_system.sv
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module ibex_demo_system #(
input logic td_i, // JTAG test data input pad
output logic td_o // JTAG test data output pad
);
localparam logic [31:0] MEM_SIZE = 64 * 1024; // 64 KiB
localparam logic [31:0] MEM_SIZE = 128 * 1024; // 128 KiB
localparam logic [31:0] MEM_START = 32'h00100000;
localparam logic [31:0] MEM_MASK = ~(MEM_SIZE-1);

Expand Down
4 changes: 3 additions & 1 deletion sw/c/common/demo_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

#define NUM_PWM_MODULES 12

#define DEFAULT_SPI SPI_FROM_BASE_ADDR(SPI0_BASE)
#define LCD_SPI SPI_FROM_BASE_ADDR(SPI0_BASE)

#define SYSCLK_FREQ 50000000

/**
* Writes character to default UART. Signature matches c stdlib function
Expand Down
11 changes: 11 additions & 0 deletions sw/c/common/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ void spi_send_byte_blocking(spi_t *spi, char c) {
}

spi_status_t spi_get_status(spi_t *spi) { return (spi_status_t)DEV_READ(spi->reg + SPI_STATUS_REG); }

void spi_wait_idle(spi_t *spi) {
while ((spi_get_status(spi) & spi_status_fifo_empty) != spi_status_fifo_empty);
}

void spi_tx(spi_t *spi, const uint8_t *data, uint32_t len) {
spi_wait_idle(spi);
while (len--) {
spi_send_byte_blocking(spi, *data++);
}
}
3 changes: 3 additions & 0 deletions sw/c/common/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ void spi_init(spi_t *spi, spi_reg_t reg, uint32_t speed);
void spi_send_byte_blocking(spi_t *spi, char c);
spi_status_t spi_get_status(spi_t *spi);

void spi_wait_idle(spi_t *spi);
void spi_tx(spi_t *spi, const uint8_t *data, uint32_t len);

#endif // SPI_H__
31 changes: 29 additions & 2 deletions sw/c/demo/lcd_st7735/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
# This is the same sets of compilation flags used in ibex CoreMark core_portme.mak.
set(CMAKE_C_FLAGS "-mtune=sifive-3-series -O3 -falign-functions=16 -funroll-all-loops -finline-functions -falign-jumps=4 -mstrict-align")

add_library(lcd_st7735_lib
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/display_drivers/core/lcd_base.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/display_drivers/core/lucida_console_10pt.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/display_drivers/core/lucida_console_12pt.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/display_drivers/core/m3x6_16pt.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/display_drivers/st7735/lcd_st7735.c
)

add_library(coremark
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/vendor/eembc_coremark/core_list_join.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/vendor/eembc_coremark/core_main.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/vendor/eembc_coremark/core_matrix.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/vendor/eembc_coremark/core_state.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/vendor/eembc_coremark/core_util.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/vendor/eembc_coremark/barebones/cvt.c
coremark/core_portme.c
coremark/ee_printf.c
)

# core_main defines a `main` function, rename it to `coremark_main` instead.
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/vendor/eembc_coremark/core_main.c
PROPERTIES COMPILE_FLAGS -Dmain=coremark_main
)

target_include_directories(coremark PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/vendor/eembc_coremark
${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/lowrisc_ibex/examples/sw/benchmarks/coremark/ibex
)

target_link_libraries(coremark common)

# add_executable(lcd_st7735 main.c)
add_executable(lcd_st7735 main.c lcd.c fractal_fixed.c fractal_float.c fractal_palette.c)
add_executable(lcd_st7735 main.c lcd.c fractal_fixed.c fractal_float.c fractal_palette.c fbcon.c)

# pull in core dependencies and additional i2c hardware support
target_link_libraries(lcd_st7735 common lcd_st7735_lib)
target_link_libraries(lcd_st7735 common lcd_st7735_lib coremark)

target_include_directories(lcd_st7735 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../vendor/display_drivers)
66 changes: 66 additions & 0 deletions sw/c/demo/lcd_st7735/coremark/core_portme.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "core_portme.h"
#include "coremark.h"

#include "demo_system.h"
#include "timer.h"

#define ITERATIONS 100

#if VALIDATION_RUN
volatile ee_s32 seed1_volatile = 0x3415;
volatile ee_s32 seed2_volatile = 0x3415;
volatile ee_s32 seed3_volatile = 0x66;
#endif
#if PERFORMANCE_RUN
volatile ee_s32 seed1_volatile = 0x0;
volatile ee_s32 seed2_volatile = 0x0;
volatile ee_s32 seed3_volatile = 0x66;
#endif
#if PROFILE_RUN
volatile ee_s32 seed1_volatile = 0x8;
volatile ee_s32 seed2_volatile = 0x8;
volatile ee_s32 seed3_volatile = 0x8;
#endif
volatile ee_s32 seed4_volatile = ITERATIONS;
volatile ee_s32 seed5_volatile = 0;

static uint64_t start_time_val, stop_time_val;

void start_time(void) {
start_time_val = timer_read();
}

void stop_time(void) {
stop_time_val = timer_read();
}

CORE_TICKS get_time(void) {
return (CORE_TICKS)(stop_time_val - start_time_val);
}

secs_ret time_in_secs(CORE_TICKS ticks) {
secs_ret retval = ((secs_ret)ticks) / (secs_ret)SYSCLK_FREQ;
return retval;
}

ee_u32 default_num_contexts = 1;

void portable_init(core_portable *p, int *argc, char *argv[]) {
p->portable_id = 1;
}

void portable_fini(core_portable *p) {
CORE_TICKS elapsed = get_time();
float coremark_mhz;

coremark_mhz = (1000000.0f * (float)ITERATIONS) / elapsed;

ee_printf("CoreMark / MHz: %f", coremark_mhz);

p->portable_id = 0;
}
Loading
Loading