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

fix several applications #325

Merged
merged 10 commits into from
Jun 30, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions hw/ip/pdm2pcm/tb/pdm_core_tb.sv
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ module pdm_core_tb;
end

fpcm = $fopen("signals/pcm.txt", "w");
if (fpcm) begin
$display("PCM File opened successfully.");
end else begin
if (!fpcm) begin
$display("Failed to open PCM file.");
$stop();
end

rstn_i = 0;
Expand Down
55 changes: 53 additions & 2 deletions hw/ip/soc_ctrl/rtl/soc_ctrl_reg_top.sv
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module soc_ctrl_reg_top #(
parameter type reg_rsp_t = logic,
parameter int AW = 5
) (
input clk_i,
input rst_ni,
input logic clk_i,
input logic rst_ni,
input reg_req_t reg_req_i,
output reg_rsp_t reg_rsp_o,
// To HW
Expand Down Expand Up @@ -413,3 +413,54 @@ module soc_ctrl_reg_top #(
`ASSERT(en2addrHit, (reg_we || reg_re) |-> $onehot0(addr_hit))

endmodule

module soc_ctrl_reg_top_intf #(
parameter int AW = 5,
localparam int DW = 32
) (
input logic clk_i,
input logic rst_ni,
REG_BUS.in regbus_slave,
// To HW
output soc_ctrl_reg_pkg::soc_ctrl_reg2hw_t reg2hw, // Write
input soc_ctrl_reg_pkg::soc_ctrl_hw2reg_t hw2reg, // Read
// Config
input devmode_i // If 1, explicit error return for unmapped register access
);
localparam int unsigned STRB_WIDTH = DW / 8;

`include "register_interface/typedef.svh"
`include "register_interface/assign.svh"

// Define structs for reg_bus
typedef logic [AW-1:0] addr_t;
typedef logic [DW-1:0] data_t;
typedef logic [STRB_WIDTH-1:0] strb_t;
`REG_BUS_TYPEDEF_ALL(reg_bus, addr_t, data_t, strb_t)

reg_bus_req_t s_reg_req;
reg_bus_rsp_t s_reg_rsp;

// Assign SV interface to structs
`REG_BUS_ASSIGN_TO_REQ(s_reg_req, regbus_slave)
`REG_BUS_ASSIGN_FROM_RSP(regbus_slave, s_reg_rsp)



soc_ctrl_reg_top #(
.reg_req_t(reg_bus_req_t),
.reg_rsp_t(reg_bus_rsp_t),
.AW(AW)
) i_regs (
.clk_i,
.rst_ni,
.reg_req_i(s_reg_req),
.reg_rsp_o(s_reg_rsp),
.reg2hw, // Write
.hw2reg, // Read
.devmode_i
);

endmodule


4 changes: 1 addition & 3 deletions hw/ip_examples/pdm2pcm_dummy/rtl/pdm2pcm_dummy.sv
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ module pdm2pcm_dummy #(
init = 1;
lineidx = 0;
fpdm = $fopen(filepath, "r");
if (fpdm) begin
$display("PDM File opened successfully.");
end else begin
if (!fpdm) begin
$display("Failed to open PDM file.");
$display(" > Please check if this the simulation was launched using");
$display(" `make *-sim` or `make run-pdm2pcm`.");
Expand Down
10 changes: 5 additions & 5 deletions sw/applications/example_dma/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int main(int argc, char *argv[])
PRINTF("DMA single mode success.\n\r");
} else {
PRINTF("DMA single mode failure: %d errors out of %d bytes checked\n\r", errors, trans.size_b );
return -1;
return EXIT_FAILURE;
}

#endif // TEST_SINGULAR_MODE
Expand Down Expand Up @@ -203,7 +203,7 @@ int main(int argc, char *argv[])
PRINTF("DMA address mode success.\n\r");
} else {
PRINTF("DMA address mode failure: %d errors out of %d bytes checked\n\r", errors, trans.size_b );
return -1;
return EXIT_FAILURE;
}

trans.mode = DMA_TRANS_MODE_SINGLE;
Expand Down Expand Up @@ -270,7 +270,7 @@ int main(int argc, char *argv[])
PRINTF("DMA address mode in external memory success.\n\r");
} else {
PRINTF("DMA address mode in external memory failure: %d errors out of %d bytes checked\n\r", errors, trans.size_b );
return -1;
return EXIT_FAILURE;
}

trans.mode = DMA_TRANS_MODE_SINGLE;
Expand Down Expand Up @@ -335,7 +335,7 @@ int main(int argc, char *argv[])
PRINTF("DMA multiple transactions success.\n\r");
} else {
PRINTF("DMA multiple transactions failure: %d errors out of %d words checked\n\r", errors, TEST_DATA_SIZE);
return -1;
return EXIT_FAILURE;
}

#endif // TEST_PENDING_TRANSACTION
Expand Down Expand Up @@ -394,7 +394,7 @@ int main(int argc, char *argv[])
PRINTF("DMA window success\n\r");
} else {
PRINTF("DMA window failure: %d errors out of %d words checked\n\r", errors, TEST_DATA_SIZE);
return -1;
return EXIT_FAILURE;
}

#endif // TEST_WINDOW
Expand Down
91 changes: 91 additions & 0 deletions sw/applications/example_matfadd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdlib.h>
#include "csr.h"
#include "matrixAdd32.h"
#include <math.h>

#define FS_INITIAL 0x01

Expand All @@ -30,6 +31,90 @@ uint32_t check_results(float * C, int N, int M);

float m_c[HEIGHT*WIDTH];

void swap(char *a, char *b)
{
char temp = *a;
*a = *b;
*b = temp;
}

// A function to print a floating point number using putchar
void putfloat(float x, int p)
{
// Check if x is negative
if (x < 0)
{
// Print a minus sign
putchar('-');
// Make x positive
x = -x;
}

// Convert the integer part of x into a string of digits
long i = (long)x; // Get the integer part
char int_str[20]; // An array to store the digits
int len = 0; // The length of the string
do
{
// Get the last digit and store it in the array
int_str[len] = '0' + i % 10;
len++;
// Remove the last digit from i
i /= 10;
} while (i > 0);

// Reverse the string of digits
for (int j = 0; j < len / 2; j++)
{
// Swap the elements at both ends
swap(&int_str[j], &int_str[len - 1 - j]);
}

// Print the string of digits
for (int j = 0; j < len; j++)
{
putchar(int_str[j]);
}

// Print a decimal point
putchar('.');

// Convert the fractional part of x into a string of digits
float f = x - (long)x; // Get the fractional part
char frac_str[20]; // An array to store the digits
len = 0; // The length of the string
while (p--)
{
// Get the first digit after the decimal point and store it in the array
f = (f - (long)f) * 10;
frac_str[len] = '0' + (long)f;
len++;
// Round up if necessary
if (fabs(f - (long)f) >= 0.5f)
{
frac_str[len - 1]++;
}
}

// Print the string of digits
for (int j = 0; j < len; j++)
{
putchar(frac_str[j]);
}
}

void __attribute__ ((noinline)) printMatrix(float * C, int N, int M)
{
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
putfloat(C[i*N+j], 2);
if( j != M -1)
printf(", ");
}
printf("\n");
}
}

int main()
{
int N = WIDTH;
Expand All @@ -52,6 +137,12 @@ int main()
errors = check_results(m_c, N, M);

PRINTF("program finished with %d errors and %d cycles\n\r", errors, cycles);

#ifdef ENABLE_PRINTF
printMatrix(m_c,N,M);
#endif


return errors;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@
#define COPY_DATA_PER_CYCLE COPY_DATA_UNITS
#endif //TEST_CIRCULAR


// Warning in case of targetting simulation
#ifdef TARGET_SIM
#pragma message("This app does not allow Flash write operations in simulation!")
#endif

#define REVERT_24b_ADDR(addr) ((((uint32_t)addr & 0xff0000) >> 16) | ((uint32_t)addr & 0xff00) | (((uint32_t)addr & 0xff) << 16))

#define FLASH_ADDR 0x00008500 // 256B data alignment
Expand Down Expand Up @@ -278,6 +272,22 @@ static inline __attribute__((always_inline)) void spi_wait_4_resp()
int main(int argc, char *argv[])
{

#ifdef TARGET_SIM
#pragma message("This app does not allow Flash write operations in simulation!")
PRINTF("Flash writes are not permitted during Simulation, only on FPGA\n");
return EXIT_SUCCESS;
#endif

soc_ctrl_t soc_ctrl;
soc_ctrl.base_addr = mmio_region_from_addr((uintptr_t)SOC_CTRL_START_ADDRESS);

#ifdef USE_SPI_FLASH
if ( get_spi_flash_mode(&soc_ctrl) == SOC_CTRL_SPI_FLASH_MODE_SPIMEMIO )
{
PRINTF("This application cannot work with the memory mapped SPI FLASH module - do not use the FLASH_EXEC linker script for this application\n");
return EXIT_SUCCESS;
}
#endif
spi_config();
dma_init(NULL);

Expand Down
16 changes: 14 additions & 2 deletions sw/applications/example_spi_host/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ void fic_irq_spi_flash(void)

int main(int argc, char *argv[])
{

soc_ctrl_t soc_ctrl;
soc_ctrl.base_addr = mmio_region_from_addr((uintptr_t)SOC_CTRL_START_ADDRESS);

#ifdef USE_SPI_FLASH
if ( get_spi_flash_mode(&soc_ctrl) == SOC_CTRL_SPI_FLASH_MODE_SPIMEMIO )
{
PRINTF("This application cannot work with the memory mapped SPI FLASH module - do not use the FLASH_EXEC linker script for this application\n");
return EXIT_SUCCESS;
}
#endif
// spi_host_t spi_host;
#ifndef USE_SPI_FLASH
spi_host.base_addr = mmio_region_from_addr((uintptr_t)SPI_HOST_START_ADDRESS);
#else
spi_host.base_addr = mmio_region_from_addr((uintptr_t)SPI_FLASH_START_ADDRESS);
#endif

soc_ctrl_t soc_ctrl;
soc_ctrl.base_addr = mmio_region_from_addr((uintptr_t)SOC_CTRL_START_ADDRESS);
uint32_t core_clk = soc_ctrl_get_frequency(&soc_ctrl);

// Enable interrupt on processor side
Expand Down Expand Up @@ -230,6 +239,9 @@ int main(int argc, char *argv[])
PRINTF("success!\n\r");
} else {
PRINTF("failure, %d errors!\n\r", errors);
return EXIT_FAILURE;
}

return EXIT_SUCCESS;

}
16 changes: 14 additions & 2 deletions sw/applications/example_spi_host_dma/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,25 @@ uint32_t copy_data[COPY_DATA_NUM] __attribute__ ((aligned (4))) = { 0 };

int main(int argc, char *argv[])
{

soc_ctrl_t soc_ctrl;
soc_ctrl.base_addr = mmio_region_from_addr((uintptr_t)SOC_CTRL_START_ADDRESS);

#ifdef USE_SPI_FLASH
if ( get_spi_flash_mode(&soc_ctrl) == SOC_CTRL_SPI_FLASH_MODE_SPIMEMIO )
{
PRINTF("This application cannot work with the memory mapped SPI FLASH module - do not use the FLASH_EXEC linker script for this application\n");
return EXIT_SUCCESS;
}
#endif


#ifndef USE_SPI_FLASH
spi_host.base_addr = mmio_region_from_addr((uintptr_t)SPI_HOST_START_ADDRESS);
#else
spi_host.base_addr = mmio_region_from_addr((uintptr_t)SPI_FLASH_START_ADDRESS);
#endif

soc_ctrl_t soc_ctrl;
soc_ctrl.base_addr = mmio_region_from_addr((uintptr_t)SOC_CTRL_START_ADDRESS);
uint32_t core_clk = soc_ctrl_get_frequency(&soc_ctrl);

// Enable interrupt on processor side
Expand Down Expand Up @@ -273,6 +284,7 @@ int main(int argc, char *argv[])
PRINTF("success! (bytes checked: %d)\n\r", count*sizeof(*copy_data));
} else {
PRINTF("failure, %d errors! (Out of %d)\n\r", errors, count);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Expand Down
Loading