driver update
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
CXXFLAGS += -O0 -g -Wall -Wextra -pedantic -Wfatal-errors
|
CXXFLAGS += -O3 -Wall -Wextra -pedantic -Wfatal-errors
|
||||||
|
|
||||||
CXXFLAGS += -I../sw
|
CXXFLAGS += -I../sw
|
||||||
|
|
||||||
LDFLAGS += -L./obj_dir
|
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
|
DRV_CFLAGS += -I../../sw
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public:
|
|||||||
|
|
||||||
~vx_device() {
|
~vx_device() {
|
||||||
mutex_.lock();
|
mutex_.lock();
|
||||||
is_done_ = false;
|
is_done_ = true;
|
||||||
mutex_.unlock();
|
mutex_.unlock();
|
||||||
|
|
||||||
thread_.join();
|
thread_.join();
|
||||||
@@ -171,6 +171,8 @@ private:
|
|||||||
std::cout << "Device ready..." << std::endl;
|
std::cout << "Device ready..." << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "Device shutdown..." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __thread_proc__(vx_device* device) {
|
static void __thread_proc__(vx_device* device) {
|
||||||
|
|||||||
@@ -48,11 +48,11 @@ $(PROJECT): vx_driver.o
|
|||||||
$(PROJECT_ASE): vx_driver.o
|
$(PROJECT_ASE): vx_driver.o
|
||||||
$(CC) $(DRV_CFLAGS) -DUSE_ASE $^ $(DRV_LDFLAGS) $(ASE_LIBS) -o $@
|
$(CC) $(DRV_CFLAGS) -DUSE_ASE $^ $(DRV_LDFLAGS) $(ASE_LIBS) -o $@
|
||||||
|
|
||||||
test: test.o $(PROJECT)
|
test: test.o utils.o $(PROJECT)
|
||||||
$(CXX) $(CXXFLAGS) test.o $(LDFLAGS) -lvxdrv -o $@
|
$(CXX) $(CXXFLAGS) test.o utils.o $(LDFLAGS) -lvxdrv -o $@
|
||||||
|
|
||||||
test_ase: test.o $(PROJECT_ASE)
|
test_ase: test.o utils.o $(PROJECT_ASE)
|
||||||
$(CXX) $(CXXFLAGS) -DUSE_ASE test.o $(LDFLAGS) -lvxdrv_ase -o $@
|
$(CXX) $(CXXFLAGS) -DUSE_ASE test.o utils.o $(LDFLAGS) -lvxdrv_ase -o $@
|
||||||
|
|
||||||
vx_driver.o: vx_driver.c
|
vx_driver.o: vx_driver.c
|
||||||
$(CC) $(DRV_CFLAGS) -c $^ -o $@
|
$(CC) $(DRV_CFLAGS) -c $^ -o $@
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include <vx_driver.h>
|
#include <vx_driver.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
// parse command arguments
|
// parse command arguments
|
||||||
parse_args(argc, argv);
|
parse_args(argc, argv);
|
||||||
@@ -146,7 +61,7 @@ int main(int argc, char *argv[]) {
|
|||||||
vx_dev_close(device);
|
vx_dev_close(device);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// close device
|
// close device
|
||||||
vx_dev_close(device);
|
vx_dev_close(device);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
static uint32_t hti_old(char c) {
|
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;
|
out->is_eof = is_eof;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vx_driver.h>
|
||||||
|
|
||||||
struct ihex_t {
|
struct ihex_t {
|
||||||
static constexpr int MAX_LINE_SIZE = 524;
|
static constexpr int MAX_LINE_SIZE = 524;
|
||||||
static constexpr int MAX_DATA_SIZE = 255;
|
static constexpr int MAX_DATA_SIZE = 255;
|
||||||
@@ -12,4 +14,6 @@ struct ihex_t {
|
|||||||
bool is_eof;
|
bool is_eof;
|
||||||
};
|
};
|
||||||
|
|
||||||
int parse_ihex_line(char* line, ihex_t* out);
|
int parse_ihex_line(char* line, ihex_t* out);
|
||||||
|
|
||||||
|
int upload_program(vx_device_h device, const char* filename);
|
||||||
Reference in New Issue
Block a user