diff --git a/driver/sim/Makefile b/driver/sim/Makefile index 1f5c05be..4259dd8b 100644 --- a/driver/sim/Makefile +++ b/driver/sim/Makefile @@ -1,11 +1,11 @@ -CXXFLAGS += -O0 -g -Wall -Wextra -pedantic -Wfatal-errors +CXXFLAGS += -O3 -Wall -Wextra -pedantic -Wfatal-errors CXXFLAGS += -I../sw LDFLAGS += -L./obj_dir -DRV_CFLAGS += -O0 -g -Wall -Wextra -pedantic -Wfatal-errors +DRV_CFLAGS += -O3 -Wall -Wextra -pedantic -Wfatal-errors DRV_CFLAGS += -I../../sw diff --git a/driver/sim/vx_driver.cpp b/driver/sim/vx_driver.cpp index 7e1606ea..f18ffcee 100644 --- a/driver/sim/vx_driver.cpp +++ b/driver/sim/vx_driver.cpp @@ -87,7 +87,7 @@ public: ~vx_device() { mutex_.lock(); - is_done_ = false; + is_done_ = true; mutex_.unlock(); thread_.join(); @@ -171,6 +171,8 @@ private: std::cout << "Device ready..." << std::endl; } } + + std::cout << "Device shutdown..." << std::endl; } static void __thread_proc__(vx_device* device) { diff --git a/driver/sw/Makefile b/driver/sw/Makefile index 1355750a..cbbd3c1f 100644 --- a/driver/sw/Makefile +++ b/driver/sw/Makefile @@ -48,11 +48,11 @@ $(PROJECT): vx_driver.o $(PROJECT_ASE): vx_driver.o $(CC) $(DRV_CFLAGS) -DUSE_ASE $^ $(DRV_LDFLAGS) $(ASE_LIBS) -o $@ -test: test.o $(PROJECT) - $(CXX) $(CXXFLAGS) test.o $(LDFLAGS) -lvxdrv -o $@ +test: test.o utils.o $(PROJECT) + $(CXX) $(CXXFLAGS) test.o utils.o $(LDFLAGS) -lvxdrv -o $@ -test_ase: test.o $(PROJECT_ASE) - $(CXX) $(CXXFLAGS) -DUSE_ASE test.o $(LDFLAGS) -lvxdrv_ase -o $@ +test_ase: test.o utils.o $(PROJECT_ASE) + $(CXX) $(CXXFLAGS) -DUSE_ASE test.o utils.o $(LDFLAGS) -lvxdrv_ase -o $@ vx_driver.o: vx_driver.c $(CC) $(DRV_CFLAGS) -c $^ -o $@ diff --git a/driver/sw/test.cpp b/driver/sw/test.cpp index 42df93f2..eaba4bb3 100644 --- a/driver/sw/test.cpp +++ b/driver/sw/test.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include "utils.h" @@ -38,90 +37,6 @@ static void parse_args(int argc, char **argv) { } } -static int upload_program(vx_device_h device, const char* filename, uint32_t transfer_size = 16 * VX_CACHE_LINESIZE) { - std::ifstream ifs(filename); - if (!ifs) { - std::cout << "error: " << filename << " not found" << std::endl; - return -1; - } - - // allocate device buffer - auto buffer = vx_buf_alloc(device, transfer_size); - if (nullptr == buffer) - return -1; - - // get buffer address - auto buf_ptr = (uint8_t*)vs_buf_ptr(buffer); - - // - // copy initialization routine - // - - ((uint32_t*)buf_ptr)[0] = 0xf1401073; - ((uint32_t*)buf_ptr)[1] = 0xf1401073; - ((uint32_t*)buf_ptr)[2] = 0x30101073; - ((uint32_t*)buf_ptr)[3] = 0x800000b7; - ((uint32_t*)buf_ptr)[4] = 0x000080e7; - - vx_copy_to_fpga(buffer, 0, 5 * 4, 0); - - // - // copy hex program - // - - char line[ihex_t::MAX_LINE_SIZE]; - uint32_t hex_offset = 0; - uint32_t prev_hex_address = 0; - uint32_t dest_address = -1; - uint32_t src_offset = 0; - - while (true) { - ifs.getline(line, ihex_t::MAX_LINE_SIZE); - if (!ifs) - break; - - ihex_t ihex; - parse_ihex_line(line, &ihex); - if (ihex.is_eof) - break; - - if (ihex.has_offset) { - hex_offset = ihex.offset; - } - - if (ihex.data_size != 0) { - auto hex_address = ihex.address + hex_offset; - if (dest_address == (uint32_t)-1) { - dest_address = (hex_address / VX_CACHE_LINESIZE) * VX_CACHE_LINESIZE; - src_offset = hex_address - dest_address; - } else { - auto delta = hex_address - prev_hex_address; - src_offset += delta; - } - for (uint32_t i = 0; i < ihex.data_size; ++i) { - if (src_offset >= transfer_size) { - // flush current batch to FPGA - vx_copy_to_fpga(buffer, dest_address, transfer_size, 0); - dest_address = (hex_address/ VX_CACHE_LINESIZE) * VX_CACHE_LINESIZE; - src_offset = hex_address - dest_address; - } - buf_ptr[src_offset++] = ihex.data[i]; - ++hex_address; - } - prev_hex_address = hex_address; - } - } - - // flush last batch to FPGA - if (src_offset) { - vx_copy_to_fpga(buffer, dest_address, src_offset, 0); - } - - vx_buf_release(buffer); - - return 0; -} - int main(int argc, char *argv[]) { // parse command arguments parse_args(argc, argv); @@ -146,7 +61,7 @@ int main(int argc, char *argv[]) { vx_dev_close(device); return -1; } - + // close device vx_dev_close(device); diff --git a/driver/sw/utils.cpp b/driver/sw/utils.cpp index 5f73eefd..f0752630 100644 --- a/driver/sw/utils.cpp +++ b/driver/sw/utils.cpp @@ -1,4 +1,5 @@ #include +#include #include "utils.h" static uint32_t hti_old(char c) { @@ -66,4 +67,90 @@ int parse_ihex_line(char* line, ihex_t* out) { out->is_eof = is_eof; return 0; - } \ No newline at end of file + } + + int upload_program(vx_device_h device, const char* filename) { + std::ifstream ifs(filename); + if (!ifs) { + std::cout << "error: " << filename << " not found" << std::endl; + return -1; + } + + uint32_t transfer_size = 16 * VX_CACHE_LINESIZE; + + // allocate device buffer + auto buffer = vx_buf_alloc(device, transfer_size); + if (nullptr == buffer) + return -1; + + // get buffer address + auto buf_ptr = (uint8_t*)vs_buf_ptr(buffer); + + // + // copy initialization routine + // + + ((uint32_t*)buf_ptr)[0] = 0xf1401073; + ((uint32_t*)buf_ptr)[1] = 0xf1401073; + ((uint32_t*)buf_ptr)[2] = 0x30101073; + ((uint32_t*)buf_ptr)[3] = 0x800000b7; + ((uint32_t*)buf_ptr)[4] = 0x000080e7; + + vx_copy_to_fpga(buffer, 0, 5 * 4, 0); + + // + // copy hex program + // + + char line[ihex_t::MAX_LINE_SIZE]; + uint32_t hex_offset = 0; + uint32_t prev_hex_address = 0; + uint32_t dest_address = -1; + uint32_t src_offset = 0; + + while (true) { + ifs.getline(line, ihex_t::MAX_LINE_SIZE); + if (!ifs) + break; + + ihex_t ihex; + parse_ihex_line(line, &ihex); + if (ihex.is_eof) + break; + + if (ihex.has_offset) { + hex_offset = ihex.offset; + } + + if (ihex.data_size != 0) { + auto hex_address = ihex.address + hex_offset; + if (dest_address == (uint32_t)-1) { + dest_address = (hex_address / VX_CACHE_LINESIZE) * VX_CACHE_LINESIZE; + src_offset = hex_address - dest_address; + } else { + auto delta = hex_address - prev_hex_address; + src_offset += delta; + } + for (uint32_t i = 0; i < ihex.data_size; ++i) { + if (src_offset >= transfer_size) { + // flush current batch to FPGA + vx_copy_to_fpga(buffer, dest_address, transfer_size, 0); + dest_address = (hex_address/ VX_CACHE_LINESIZE) * VX_CACHE_LINESIZE; + src_offset = hex_address - dest_address; + } + buf_ptr[src_offset++] = ihex.data[i]; + ++hex_address; + } + prev_hex_address = hex_address; + } + } + + // flush last batch to FPGA + if (src_offset) { + vx_copy_to_fpga(buffer, dest_address, src_offset, 0); + } + + vx_buf_release(buffer); + + return 0; +} \ No newline at end of file diff --git a/driver/sw/utils.h b/driver/sw/utils.h index cc82ea63..78427ef2 100644 --- a/driver/sw/utils.h +++ b/driver/sw/utils.h @@ -1,6 +1,8 @@ #pragma once +#include + struct ihex_t { static constexpr int MAX_LINE_SIZE = 524; static constexpr int MAX_DATA_SIZE = 255; @@ -12,4 +14,6 @@ struct ihex_t { bool is_eof; }; -int parse_ihex_line(char* line, ihex_t* out); \ No newline at end of file +int parse_ihex_line(char* line, ihex_t* out); + +int upload_program(vx_device_h device, const char* filename); \ No newline at end of file