driver update

This commit is contained in:
Blaise Tine
2020-03-16 18:13:58 -04:00
parent 55e2cb4a76
commit f034b4c63a
6 changed files with 103 additions and 95 deletions

View File

@@ -1,4 +1,5 @@
#include <iostream>
#include <fstream>
#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;
}
}
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;
}