From a5c2b3900f1455418ea4f7d846bfc3a357c098d8 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 10:49:26 +0000 Subject: [PATCH 01/18] Support for fseek --- src_xcore/config.xscope | 1 + src_xcore/xscope_io_common.h | 3 ++- src_xcore/xscope_io_device.c | 13 +++++++++++++ src_xcore/xscope_io_device.h | 16 ++++++++++++++-- xscope_fileio/host/xscope_io_host.c | 23 ++++++++++++++++++++++- 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src_xcore/config.xscope b/src_xcore/config.xscope index 34987bf..e24fd79 100644 --- a/src_xcore/config.xscope +++ b/src_xcore/config.xscope @@ -3,6 +3,7 @@ + diff --git a/src_xcore/xscope_io_common.h b/src_xcore/xscope_io_common.h index 2976b8c..546b0a6 100644 --- a/src_xcore/xscope_io_common.h +++ b/src_xcore/xscope_io_common.h @@ -20,7 +20,8 @@ enum{ XSCOPE_ID_READ_BYTES = 1, XSCOPE_ID_WRITE_SETUP = 2, XSCOPE_ID_WRITE_BYTES = 3, - XSCOPE_ID_HOST_QUIT = 4, + XSCOPE_ID_SEEK = 4, + XSCOPE_ID_HOST_QUIT = 5, }; #endif \ No newline at end of file diff --git a/src_xcore/xscope_io_device.c b/src_xcore/xscope_io_device.c index b723687..57a8764 100644 --- a/src_xcore/xscope_io_device.c +++ b/src_xcore/xscope_io_device.c @@ -138,6 +138,19 @@ void xscope_fwrite(uint8_t *buffer, size_t n_bytes_to_write, xscope_file_t *xsco lock_release(file_access_lock); } +void xscope_fseek(int offset, int whence, xscope_file_t *xscope_file){ + lock_acquire(file_access_lock); + xassert(whence == SEEK_SET || whence == SEEK_CUR || whence == SEEK_END); + unsigned char packet[1 + 1 + sizeof(offset)]; + packet[0] = xscope_file->index + '0'; + packet[1] = whence + '0'; + memcpy(&packet[2], &offset, sizeof(offset)); + xscope_bytes(XSCOPE_ID_SEEK, sizeof(packet), packet); + if(VERBOSE) printf("Seeking file id: %u whence %d offset %d\n", xscope_file->index, whence, offset); + lock_release(file_access_lock); +} + + void xscope_close_files(void){ xscope_bytes(XSCOPE_ID_HOST_QUIT, 1, (unsigned char*)"!"); if(VERBOSE) printf("Sent close files\n"); diff --git a/src_xcore/xscope_io_device.h b/src_xcore/xscope_io_device.h index 92930f3..6ed2b32 100644 --- a/src_xcore/xscope_io_device.h +++ b/src_xcore/xscope_io_device.h @@ -58,16 +58,28 @@ size_t xscope_fread(uint8_t *buffer, size_t n_bytes_to_read, xscope_file_t *xsco * Writes a number of bytes from the buffer provided by the application. * * @param buffer that will be read and sent to be written on the host - * @param n_bytes_to_read + * @param n_bytes_to_write * @return void ******************************************************************************/ void xscope_fwrite(uint8_t *buffer, size_t n_bytes_to_write, xscope_file_t *xscope_io_handle); +/****************************************************************************** + * xscope_seek SEEK_SET, SEEK_CUR or SEEK_END. Note no error checking yet!! + * + * Sets the file position of the stream to the given offset + * + * @param offset in bytes + * @param whence - SEEK_SET, SEEK_CUR or SEEK_END + * @return void + ******************************************************************************/ +void xscope_fseek(int offset, int whence, xscope_file_t *xscope_io_handle); + /****************************************************************************** * xscope_close_files * * Closes both the read and write file on the host. - * This must be called at the end of device application. + * This must be called at the end of device application as it also signals + * terminate to the host app. * * @return void ******************************************************************************/ diff --git a/xscope_fileio/host/xscope_io_host.c b/xscope_fileio/host/xscope_io_host.c index eb5a0e0..a075f58 100644 --- a/xscope_fileio/host/xscope_io_host.c +++ b/xscope_fileio/host/xscope_io_host.c @@ -173,9 +173,30 @@ void xscope_record( } break; + case XSCOPE_ID_SEEK: + { + assert(length == 6); + unsigned file_idx = databytes[0] - '0'; + int whence = databytes[1] - '0'; + int offset; + memcpy(&offset, &databytes[2], sizeof(offset)); + + if(VERBOSE) printf("[HOST] seek file idx: %u whence: %d offset: %d\n", file_idx, whence, offset); + + int ret = fseek(host_files[file_idx].fp, offset, whence); + if(ret == 0){ + if(VERBOSE) printf("[HOST] Normal seek. New position: %ld\n", ftell(host_files[file_idx].fp)); + } + else { + printf("[HOST] Error - fseek on file %s returned: %d\n", host_files[file_idx].file_name, ret); + assert(0); + } + } + break; + case XSCOPE_ID_HOST_QUIT: { - if(VERBOSE) printf("Host: quit received\n"); + if(VERBOSE) printf("[HOST] quit received\n"); running = 0; return; } From 96f1f82a0bd8475166817ede036d14973d30a542 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 10:49:51 +0000 Subject: [PATCH 02/18] Support for C & XC --- src_xcore/xscope_io_device.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src_xcore/xscope_io_device.h b/src_xcore/xscope_io_device.h index 6ed2b32..7542ee5 100644 --- a/src_xcore/xscope_io_device.h +++ b/src_xcore/xscope_io_device.h @@ -2,8 +2,14 @@ #ifndef XSCOPE_IO_DEVICE_H_ #define XSCOPE_IO_DEVICE_H_ +#ifdef __XC__ +#define chanend_t chanend +#else #include +#endif + #include +#include #include "xscope_io_common.h" typedef struct{ From 21b3d0ddcdc050478e32021cb832a4e369185d88 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 10:50:45 +0000 Subject: [PATCH 03/18] Improve clarity of printing from host app --- xscope_fileio/host/xscope_io_host.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/xscope_fileio/host/xscope_io_host.c b/xscope_fileio/host/xscope_io_host.c index a075f58..484cef8 100644 --- a/xscope_fileio/host/xscope_io_host.c +++ b/xscope_fileio/host/xscope_io_host.c @@ -28,7 +28,7 @@ void xscope_print( unsigned char *data) { if (length) { - printf("Device: "); + printf("[DEVICE] "); for (int i = 0; i < length; i++) printf("%c", *(&data[i])); } @@ -47,7 +47,7 @@ void xscope_register( unsigned int data_type, unsigned char *data_name) { - if(VERBOSE) printf("Host: xSCOPE register event (id [%d] name [%s])\n", id, name); + if(VERBOSE) printf("[HOST] xSCOPE register event (id [%d] name [%s])\n", id, name); } int send_file_chunk(unsigned file_idx, unsigned req_size) @@ -58,7 +58,7 @@ int send_file_chunk(unsigned file_idx, unsigned req_size) n_bytes_read = fread(buf, 1, req_size, host_files[file_idx].fp); if(n_bytes_read < req_size){ - if(VERBOSE) printf("Host: Unexpected end of file, device requested: %u available: %u sent: 0\n", req_size, n_bytes_read); + if(VERBOSE) printf("[HOST] Unexpected end of file, device requested: %u available: %u sent: 0\n", req_size, n_bytes_read); xscope_ep_request_upload(END_MARKER_LEN, (const unsigned char *)end_sting); //End free(buf); return(-1); @@ -72,10 +72,10 @@ int send_file_chunk(unsigned file_idx, unsigned req_size) xscope_ep_request_upload(left_over, &buf[(n_bytes_read / MAX_XSCOPE_SIZE_BYTES) * MAX_XSCOPE_SIZE_BYTES]); } - if(VERBOSE) printf("Host: sent block %u\n", n_bytes_read); + if(VERBOSE) printf("[HOST] sent block %u\n", n_bytes_read); if(feof(host_files[file_idx].fp)){ - if(VERBOSE) printf("Host: End of file\n"); + if(VERBOSE) printf("[HOST] End of file\n"); xscope_ep_request_upload(END_MARKER_LEN, (const unsigned char *)end_sting); //End } @@ -100,7 +100,7 @@ void xscope_record( assert(file_idx < MAX_FILES_OPEN); strcpy(host_files[file_idx].file_name, (const char *)&databytes[2]); host_files[file_idx].mode = databytes[1] - '0'; - if(VERBOSE) printf("Host: Open file: %d, %lu, %s, idx: %u mode: %u\n", length, strlen((char*)databytes), + if(VERBOSE) printf("[HOST] Open file: %d, %lu, %s, idx: %u mode: %u\n", length, strlen((char*)databytes), host_files[file_idx].file_name, file_idx, host_files[file_idx].mode); switch(host_files[file_idx].mode){ case XSCOPE_IO_READ_BINARY: @@ -137,7 +137,7 @@ void xscope_record( unsigned file_idx = databytes[0] - '0'; unsigned transfer_size; memcpy(&transfer_size, &databytes[1], sizeof(transfer_size)); - if(VERBOSE) printf("Host: read bytes idx: %u transfer length: %u\n", file_idx, transfer_size); + if(VERBOSE) printf("[HOST] read bytes idx: %u transfer length: %u\n", file_idx, transfer_size); send_file_chunk(file_idx, transfer_size); } break; @@ -146,25 +146,25 @@ void xscope_record( { unsigned file_idx = databytes[0] - '0'; if(write_size != 0){ - printf("Host: Error - write_size not initialised to 0. Last write incomplete?\n"); + printf("[HOST] Error - write_size not initialised to 0. Last write incomplete?\n"); assert(0); } write_file_idx = file_idx; memcpy(&write_size, &databytes[1], sizeof(write_size)); - if(VERBOSE) printf("Host: write transfer setup idx: %u, bytes: %u\n", file_idx, write_size); + if(VERBOSE) printf("[HOST] write transfer setup idx: %u, bytes: %u\n", file_idx, write_size); } break; case XSCOPE_ID_WRITE_BYTES: { - if(VERBOSE) printf("Host: write idx: %u bytes transfer length: %u\n",write_file_idx, length); + if(VERBOSE) printf("[HOST] write idx: %u bytes transfer length: %u\n", write_file_idx, length); fwrite(databytes, 1, length, host_files[write_file_idx].fp); write_size -= length; if(write_size == 0){ - if(VERBOSE) printf("Host: Normal end of write transfer\n"); + if(VERBOSE) printf("[HOST] Normal end of write transfer\n"); } else if(write_size < 0){ - printf("Host: Error - write overran by %d bytes.", -write_size); + printf("[HOST] Error - write overran by %d bytes.", -write_size); assert(0); } else{ @@ -204,7 +204,7 @@ void xscope_record( default: { - printf("Host: unexpected xSCOPE record event (id [%u] length [%u]\n", id, length); + printf("[HOST] unexpected xSCOPE record event (id [%u] length [%u]\n", id, length); } break; } @@ -230,7 +230,7 @@ int main(int argc, char *argv[]) usleep(10000); //Back off for 10ms to reduce processor usage during poll } - if(VERBOSE) printf("Host: Exit received\n"); + if(VERBOSE) printf("[HOST] Exit received\n"); //Wait another 100ms to allow any remaining outs from the device to arrive before we terminate usleep(100000); for(unsigned idx = 0; idx < MAX_FILES_OPEN; idx++){ From b7b846bbd8ec46d9f20f6667fced3185fd522d6d Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 10:54:28 +0000 Subject: [PATCH 04/18] Add example app showing python and XC usage --- .gitignore | 2 ++ example/Makefile | 49 ++++++++++++++++++++++++++++++ example/run_example.py | 25 +++++++++++++++ example/test.xc | 69 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 example/Makefile create mode 100644 example/run_example.py create mode 100644 example/test.xc diff --git a/.gitignore b/.gitignore index 6f4fc22..3cc5a0d 100644 --- a/.gitignore +++ b/.gitignore @@ -150,3 +150,5 @@ _deps # Host binary xscope_fileio/host/xscope_host_endpoint +*.bin +*.o diff --git a/example/Makefile b/example/Makefile new file mode 100644 index 0000000..a50e1e3 --- /dev/null +++ b/example/Makefile @@ -0,0 +1,49 @@ +TARGET_FLAG ?= -target=XCORE-AI-EXPLORER +TARGET_EXEC ?= fileio_test.xe + +XCC ?= xcc + +SRCS := test.xc ../src_xcore/xscope_io_device.c +INC_DIRS += $(dir $(SRCS)) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) + +BUILD_DIR := build +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) +DEPS := $(OBJS:.o=.d) + +CFLAGS := -c $(INC_FLAGS) $(TARGET_FLAG) -Os -g +XCFLAGS := $(CFLAGS) + +$(TARGET_EXEC): $(OBJS) ../src_xcore/config.xscope +# @echo $^ +# @echo $(SRCS) + @echo "**HELLO LINKER**" + $(XCC) $(TARGET_FLAG) -o $@ $^ -report + +# c source +$(BUILD_DIR)/%.c.o: %.c + $(MKDIR_P) $(dir $@) + @echo "**HELLO C**" + $(XCC) $(CFLAGS) -c $< -o $@ + +# xc source +$(BUILD_DIR)/%.xc.o: %.xc + $(MKDIR_P) $(dir $@) + @echo "**HELLO XC**" + $(XCC) $(XCFLAGS) -c $< -o $@ + +# asm source +$(BUILD_DIR)/%.S.o: %.S + $(MKDIR_P) $(dir $@) + @echo "**HELLO ASM**" + $(XCC) $(ASMFLAGS) -c $< -o $@ + +.PHONY: clean + +clean: + $(RM) -r build + $(RM) $(TARGET_EXEC) + +-include $(DEPS) + +MKDIR_P ?= mkdir -p diff --git a/example/run_example.py b/example/run_example.py new file mode 100644 index 0000000..fd2effb --- /dev/null +++ b/example/run_example.py @@ -0,0 +1,25 @@ +#We assume that the Xscope FileIO Python library has been installed via pip beforehand and is available to import. Please see readme for instuctions. + +import xscope_fileio + +firmware_xe = "fileio_test.xe" +adapter_id = "L4Ss6YfM" +ref_text = b"Evolution is change in the heritable characteristics of biological populations over successive generations." + b"\x00"; +with open("ref.bin", "wb") as ref_file: + ref_file.write(ref_text) + +xscope_fileio.run_on_target(adapter_id, firmware_xe, use_xsim=False) + +with open("dut.bin", "rb") as dut_file: + dut_text = dut_file.read() + +with open("dut_mod.bin", "rb") as dut_mod_file: + dut_mod_text = dut_mod_file.read() + +ref_mod_text = ref_text[0:10] + b"IS" + ref_text[12:-1] + +assert dut_text == ref_text +print(dut_mod_text, ref_mod_text) +assert dut_mod_text == ref_mod_text + +print("PASS") \ No newline at end of file diff --git a/example/test.xc b/example/test.xc new file mode 100644 index 0000000..fb09765 --- /dev/null +++ b/example/test.xc @@ -0,0 +1,69 @@ +#include +#include +#include +#include +extern "C"{ +#include "xscope_io_device.h" +} +#include + +void test(void){ + const char ref_file_name[] = "ref.bin"; + const char ref_array[] = "Evolution is change in the heritable characteristics of biological populations over successive generations."; + + xscope_file_t read_xscope_file = xscope_open_file(ref_file_name, "rb"); + char buffer[256] = {0}; + + //Load in full ref array from disk + size_t num_bytes = xscope_fread(buffer, sizeof(ref_array), &read_xscope_file); + printf("Full sentence (%u): %s\n", num_bytes, buffer); + + //Seek relative to start for read + xscope_fseek(10, SEEK_SET, &read_xscope_file); + memset(buffer, 0, sizeof(buffer)); + xscope_fread(buffer, 2, &read_xscope_file); + printf("Should say 'is': %s\n", buffer); + + //Seek relative to end for read + xscope_fseek(-29, SEEK_END, &read_xscope_file); + memset(buffer, 0, sizeof(buffer)); + xscope_fread(buffer, 4, &read_xscope_file); + printf("Should say 'over': %s\n", buffer); + + //Seek relative to current for read + xscope_fseek(1, SEEK_CUR, &read_xscope_file); + memset(buffer, 0, sizeof(buffer)); + xscope_fread(buffer, 10, &read_xscope_file); + printf("Should say 'successive': %s\n", buffer); + + //Load in full ref again + xscope_fseek(0, SEEK_SET, &read_xscope_file); + num_bytes = xscope_fread(buffer, sizeof(ref_array), &read_xscope_file); + printf("Full sentence (%u): %s\n", num_bytes, buffer); + + //Copy it out to dut for comparing + const char dut_file_name[] = "dut.bin"; + xscope_file_t write_xscope_file = xscope_open_file(dut_file_name, "wb"); + xscope_fwrite(buffer, sizeof(ref_array), &write_xscope_file); + + //Test fseek on write file + const char dut_mod_file_name[] = "dut_mod.bin"; + xscope_file_t write_xscope_fil_mod = xscope_open_file(dut_mod_file_name, "wb"); + xscope_fwrite(buffer, sizeof(ref_array), &write_xscope_fil_mod); + xscope_fseek(10, SEEK_SET, &write_xscope_fil_mod); + xscope_fwrite("IS ", 3, &write_xscope_fil_mod); + + xscope_close_files(); +} + +int main(void){ + chan xscope_chan; + par{ + xscope_host_data(xscope_chan); + on tile[0]:{ + xscope_io_init(xscope_chan); + test(); + } + } + return 0; +} \ No newline at end of file From c702c19a604ed9c399d4ef5032d7a3a0f7349882 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 15:02:39 +0000 Subject: [PATCH 05/18] fseek support --- example/run_example.py | 2 +- example/test.xc | 11 +++++++++-- src_xcore/config.xscope | 1 + src_xcore/xscope_io_common.h | 3 ++- src_xcore/xscope_io_device.c | 11 +++++++++++ src_xcore/xscope_io_device.h | 10 ++++++++++ xscope_fileio/host/xscope_io_host.c | 12 ++++++++++++ 7 files changed, 46 insertions(+), 4 deletions(-) diff --git a/example/run_example.py b/example/run_example.py index fd2effb..fcc95d1 100644 --- a/example/run_example.py +++ b/example/run_example.py @@ -16,7 +16,7 @@ with open("dut_mod.bin", "rb") as dut_mod_file: dut_mod_text = dut_mod_file.read() -ref_mod_text = ref_text[0:10] + b"IS" + ref_text[12:-1] +ref_mod_text = ref_text[0:10] + b"IS" + ref_text[12:] assert dut_text == ref_text print(dut_mod_text, ref_mod_text) diff --git a/example/test.xc b/example/test.xc index fb09765..932b9ad 100644 --- a/example/test.xc +++ b/example/test.xc @@ -20,24 +20,29 @@ void test(void){ //Seek relative to start for read xscope_fseek(10, SEEK_SET, &read_xscope_file); + printf("Should say 10: %d\n", xscope_ftell(&read_xscope_file)); + memset(buffer, 0, sizeof(buffer)); xscope_fread(buffer, 2, &read_xscope_file); printf("Should say 'is': %s\n", buffer); //Seek relative to end for read xscope_fseek(-29, SEEK_END, &read_xscope_file); + printf("Should say 79: %d\n", xscope_ftell(&read_xscope_file)); memset(buffer, 0, sizeof(buffer)); xscope_fread(buffer, 4, &read_xscope_file); printf("Should say 'over': %s\n", buffer); //Seek relative to current for read xscope_fseek(1, SEEK_CUR, &read_xscope_file); + printf("Should say 84: %d\n", xscope_ftell(&read_xscope_file)); memset(buffer, 0, sizeof(buffer)); xscope_fread(buffer, 10, &read_xscope_file); printf("Should say 'successive': %s\n", buffer); //Load in full ref again xscope_fseek(0, SEEK_SET, &read_xscope_file); + printf("Should say 0: %d\n", xscope_ftell(&read_xscope_file)); num_bytes = xscope_fread(buffer, sizeof(ref_array), &read_xscope_file); printf("Full sentence (%u): %s\n", num_bytes, buffer); @@ -50,8 +55,10 @@ void test(void){ const char dut_mod_file_name[] = "dut_mod.bin"; xscope_file_t write_xscope_fil_mod = xscope_open_file(dut_mod_file_name, "wb"); xscope_fwrite(buffer, sizeof(ref_array), &write_xscope_fil_mod); - xscope_fseek(10, SEEK_SET, &write_xscope_fil_mod); - xscope_fwrite("IS ", 3, &write_xscope_fil_mod); + xscope_fseek(10, SEEK_SET, &write_xscope_fil_mod); + printf("Should say 10: %d\n", xscope_ftell(&write_xscope_fil_mod)); + xscope_fwrite("IS", 2, &write_xscope_fil_mod); + printf("Should say 12: %d\n", xscope_ftell(&write_xscope_fil_mod)); xscope_close_files(); } diff --git a/src_xcore/config.xscope b/src_xcore/config.xscope index e24fd79..0d3b65e 100644 --- a/src_xcore/config.xscope +++ b/src_xcore/config.xscope @@ -4,6 +4,7 @@ + diff --git a/src_xcore/xscope_io_common.h b/src_xcore/xscope_io_common.h index 546b0a6..b6181e2 100644 --- a/src_xcore/xscope_io_common.h +++ b/src_xcore/xscope_io_common.h @@ -21,7 +21,8 @@ enum{ XSCOPE_ID_WRITE_SETUP = 2, XSCOPE_ID_WRITE_BYTES = 3, XSCOPE_ID_SEEK = 4, - XSCOPE_ID_HOST_QUIT = 5, + XSCOPE_ID_TELL = 5, + XSCOPE_ID_HOST_QUIT = 6, }; #endif \ No newline at end of file diff --git a/src_xcore/xscope_io_device.c b/src_xcore/xscope_io_device.c index 57a8764..6ba6a2d 100644 --- a/src_xcore/xscope_io_device.c +++ b/src_xcore/xscope_io_device.c @@ -150,6 +150,17 @@ void xscope_fseek(int offset, int whence, xscope_file_t *xscope_file){ lock_release(file_access_lock); } +int xscope_ftell( xscope_file_t *xscope_file){ + lock_acquire(file_access_lock); + const unsigned char idx = xscope_file->index + '0'; + xscope_bytes(XSCOPE_ID_TELL, 1, &idx); + int offset, bytes_read = 0; + xscope_data_from_host(c_xscope, (char *)&offset, &bytes_read); + xassert(bytes_read = sizeof(offset)); + if(VERBOSE) printf("Tell file id: %u offset %d\n", xscope_file->index, offset); + lock_release(file_access_lock); + return offset; +} void xscope_close_files(void){ xscope_bytes(XSCOPE_ID_HOST_QUIT, 1, (unsigned char*)"!"); diff --git a/src_xcore/xscope_io_device.h b/src_xcore/xscope_io_device.h index 7542ee5..46ea46c 100644 --- a/src_xcore/xscope_io_device.h +++ b/src_xcore/xscope_io_device.h @@ -80,6 +80,16 @@ void xscope_fwrite(uint8_t *buffer, size_t n_bytes_to_write, xscope_file_t *xsco ******************************************************************************/ void xscope_fseek(int offset, int whence, xscope_file_t *xscope_io_handle); +/****************************************************************************** + * xscope_ftell + * + * Obtain the file position of the stream + * + * @return void + ******************************************************************************/ +int xscope_ftell( xscope_file_t *xscope_file); + + /****************************************************************************** * xscope_close_files * diff --git a/xscope_fileio/host/xscope_io_host.c b/xscope_fileio/host/xscope_io_host.c index 484cef8..0f8a8d8 100644 --- a/xscope_fileio/host/xscope_io_host.c +++ b/xscope_fileio/host/xscope_io_host.c @@ -194,6 +194,18 @@ void xscope_record( } break; + case XSCOPE_ID_TELL: + { + assert(length == 1); + unsigned file_idx = databytes[0] - '0'; + printf("%d\n", file_idx); + int offset = ftell(host_files[file_idx].fp); + printf("%d\n", 3); + if(VERBOSE) printf("[HOST] tell file idx: %d offset: %d\n", file_idx, offset); + xscope_ep_request_upload(sizeof(offset), (const unsigned char *)&offset); + } + break; + case XSCOPE_ID_HOST_QUIT: { if(VERBOSE) printf("[HOST] quit received\n"); From bbe62791232c3ede01e2d363b502d46769f00eb6 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 15:14:15 +0000 Subject: [PATCH 06/18] Remove debug print from ftell implementation --- xscope_fileio/host/xscope_io_host.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/xscope_fileio/host/xscope_io_host.c b/xscope_fileio/host/xscope_io_host.c index 0f8a8d8..98a7027 100644 --- a/xscope_fileio/host/xscope_io_host.c +++ b/xscope_fileio/host/xscope_io_host.c @@ -198,9 +198,7 @@ void xscope_record( { assert(length == 1); unsigned file_idx = databytes[0] - '0'; - printf("%d\n", file_idx); int offset = ftell(host_files[file_idx].fp); - printf("%d\n", 3); if(VERBOSE) printf("[HOST] tell file idx: %d offset: %d\n", file_idx, offset); xscope_ep_request_upload(sizeof(offset), (const unsigned char *)&offset); } From 04040d57f093e08fead8d038279c335c301134d2 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 15:28:37 +0000 Subject: [PATCH 07/18] Fix compiler issue calling from XC --- src_xcore/xscope_io_device.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src_xcore/xscope_io_device.h b/src_xcore/xscope_io_device.h index 46ea46c..39066b9 100644 --- a/src_xcore/xscope_io_device.h +++ b/src_xcore/xscope_io_device.h @@ -18,6 +18,9 @@ typedef struct{ unsigned index; } xscope_file_t; +#ifdef __XC__ +extern "C"{ +#endif /****************************************************************************** * xscope_io_init @@ -101,5 +104,8 @@ int xscope_ftell( xscope_file_t *xscope_file); ******************************************************************************/ void xscope_close_files(void); +#ifdef __XC__ +} +#endif #endif \ No newline at end of file From 30109f602e288046fbcd5718165fc23324385917 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 17:17:38 +0000 Subject: [PATCH 08/18] Reorganise examples dir --- {example => examples/fileio_features_xc}/Makefile | 4 ++-- {example => examples/fileio_features_xc}/run_example.py | 0 {example => examples/fileio_features_xc}/test.xc | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {example => examples/fileio_features_xc}/Makefile (88%) rename {example => examples/fileio_features_xc}/run_example.py (100%) rename {example => examples/fileio_features_xc}/test.xc (100%) diff --git a/example/Makefile b/examples/fileio_features_xc/Makefile similarity index 88% rename from example/Makefile rename to examples/fileio_features_xc/Makefile index a50e1e3..bc7dfb1 100644 --- a/example/Makefile +++ b/examples/fileio_features_xc/Makefile @@ -3,7 +3,7 @@ TARGET_EXEC ?= fileio_test.xe XCC ?= xcc -SRCS := test.xc ../src_xcore/xscope_io_device.c +SRCS := test.xc ../../src_xcore/xscope_io_device.c INC_DIRS += $(dir $(SRCS)) INC_FLAGS := $(addprefix -I,$(INC_DIRS)) @@ -14,7 +14,7 @@ DEPS := $(OBJS:.o=.d) CFLAGS := -c $(INC_FLAGS) $(TARGET_FLAG) -Os -g XCFLAGS := $(CFLAGS) -$(TARGET_EXEC): $(OBJS) ../src_xcore/config.xscope +$(TARGET_EXEC): $(OBJS) ../../src_xcore/config.xscope # @echo $^ # @echo $(SRCS) @echo "**HELLO LINKER**" diff --git a/example/run_example.py b/examples/fileio_features_xc/run_example.py similarity index 100% rename from example/run_example.py rename to examples/fileio_features_xc/run_example.py diff --git a/example/test.xc b/examples/fileio_features_xc/test.xc similarity index 100% rename from example/test.xc rename to examples/fileio_features_xc/test.xc From 516b628f0a8bc3cd15978784e450e0604361d13d Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 17:17:53 +0000 Subject: [PATCH 09/18] comment only --- src_xcore/xscope_io_device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_xcore/xscope_io_device.h b/src_xcore/xscope_io_device.h index 39066b9..3890d94 100644 --- a/src_xcore/xscope_io_device.h +++ b/src_xcore/xscope_io_device.h @@ -96,7 +96,7 @@ int xscope_ftell( xscope_file_t *xscope_file); /****************************************************************************** * xscope_close_files * - * Closes both the read and write file on the host. + * Closes all files on the host. * This must be called at the end of device application as it also signals * terminate to the host app. * From d07b34861e168ee457b52140c32f842d15bb7159 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 12 Mar 2021 17:18:26 +0000 Subject: [PATCH 10/18] Add C based throughput example (30MB) --- examples/throughput_c/Makefile | 49 ++++++++++++++++++++++ examples/throughput_c/main.xc | 19 +++++++++ examples/throughput_c/run_example.py | 17 ++++++++ examples/throughput_c/test.c | 63 ++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 examples/throughput_c/Makefile create mode 100644 examples/throughput_c/main.xc create mode 100644 examples/throughput_c/run_example.py create mode 100644 examples/throughput_c/test.c diff --git a/examples/throughput_c/Makefile b/examples/throughput_c/Makefile new file mode 100644 index 0000000..4a28fdc --- /dev/null +++ b/examples/throughput_c/Makefile @@ -0,0 +1,49 @@ +TARGET_FLAG ?= -target=XCORE-AI-EXPLORER +TARGET_EXEC ?= fileio_test.xe + +XCC ?= xcc + +SRCS := main.xc test.c ../../src_xcore/xscope_io_device.c +INC_DIRS += $(dir $(SRCS)) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) + +BUILD_DIR := build +OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) +DEPS := $(OBJS:.o=.d) + +CFLAGS := -c $(INC_FLAGS) $(TARGET_FLAG) -Os -g +XCFLAGS := $(CFLAGS) + +$(TARGET_EXEC): $(OBJS) ../../src_xcore/config.xscope +# @echo $^ +# @echo $(SRCS) + @echo "**HELLO LINKER**" + $(XCC) $(TARGET_FLAG) -o $@ $^ -report + +# c source +$(BUILD_DIR)/%.c.o: %.c + $(MKDIR_P) $(dir $@) + @echo "**HELLO C**" + $(XCC) $(CFLAGS) -c $< -o $@ + +# xc source +$(BUILD_DIR)/%.xc.o: %.xc + $(MKDIR_P) $(dir $@) + @echo "**HELLO XC**" + $(XCC) $(XCFLAGS) -c $< -o $@ + +# asm source +$(BUILD_DIR)/%.S.o: %.S + $(MKDIR_P) $(dir $@) + @echo "**HELLO ASM**" + $(XCC) $(ASMFLAGS) -c $< -o $@ + +.PHONY: clean + +clean: + $(RM) -r build + $(RM) $(TARGET_EXEC) + +-include $(DEPS) + +MKDIR_P ?= mkdir -p diff --git a/examples/throughput_c/main.xc b/examples/throughput_c/main.xc new file mode 100644 index 0000000..09e72f5 --- /dev/null +++ b/examples/throughput_c/main.xc @@ -0,0 +1,19 @@ +#include +#include +#include + +extern "C" { +void main_tile0(chanend); +} + +int main (void) +{ + chan xscope_chan; + par + { + xscope_host_data(xscope_chan); + on tile[0]: main_tile0(xscope_chan); + } + return 0; +} + diff --git a/examples/throughput_c/run_example.py b/examples/throughput_c/run_example.py new file mode 100644 index 0000000..72c151f --- /dev/null +++ b/examples/throughput_c/run_example.py @@ -0,0 +1,17 @@ +#We assume that the Xscope FileIO Python library has been installed via pip beforehand and is available to import. Please see readme for instuctions. +import numpy as np +import xscope_fileio + +firmware_xe = "fileio_test.xe" +adapter_id = "L4Ss6YfM" + +ref = np.random.randint(256, size=(30 * 1024 * 1024)).astype(np.uint8) +ref.tofile("ref.bin") + +xscope_fileio.run_on_target(adapter_id, firmware_xe, use_xsim=False) + +dut = np.fromfile("dut.bin", dtype=np.uint8) + +assert np.array_equal(ref, dut) + +print("PASS") \ No newline at end of file diff --git a/examples/throughput_c/test.c b/examples/throughput_c/test.c new file mode 100644 index 0000000..d4edd72 --- /dev/null +++ b/examples/throughput_c/test.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include "xscope_io_device.h" + +#include + +#define IN_FILE_NAME "ref.bin" +#define OUT_FILE_NAME "dut.bin" + +float ticks_to_KBPS(unsigned ticks, unsigned num_bytes){ + const float ticks_per_second = 100000000; + float kb = (float)num_bytes / 1000; + float time_s = (float) ticks / ticks_per_second; + + return kb/time_s; +} + +void do_test(void){ + xscope_file_t read_xscope_file = xscope_open_file(IN_FILE_NAME, "rb"); + xscope_file_t write_xscope_file = xscope_open_file(OUT_FILE_NAME, "wb"); + + uint8_t buffer[256*1024] = {0}; + + xscope_fseek(0, SEEK_END, &read_xscope_file); + unsigned fsize = xscope_ftell(&read_xscope_file); + xscope_fseek(0, SEEK_SET, &read_xscope_file); + printf("Input file size kB: %d\n", fsize / 1000); + + unsigned read_total_time = 0; + unsigned write_total_time = 0; + + + //Load in full ref array from disk + size_t num_bytes = 0; + do{ + unsigned t0 = get_reference_time(); + num_bytes = xscope_fread(buffer, sizeof(buffer), &read_xscope_file); + unsigned t1 = get_reference_time(); + read_total_time += t1 - t0; + + unsigned t2 = get_reference_time(); + xscope_fwrite(buffer, num_bytes, &write_xscope_file); + unsigned t3 = get_reference_time(); + write_total_time += t3 - t2; + } while(num_bytes > 0); + + + + + + printf("Throughput KBPS Read: %f, Write: %f\n", ticks_to_KBPS(read_total_time, fsize), ticks_to_KBPS(write_total_time, fsize)); +} + +void main_tile0(chanend_t xscope_chan) +{ + xscope_io_init(xscope_chan); + do_test(); + xscope_close_files(); +} From 2285daa9075ea2e20fabc1f328e45269f42e5151 Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 15 Mar 2021 11:55:13 +0000 Subject: [PATCH 11/18] Updated API and file layout to support module_build_info --- .gitignore | 1 + examples/fileio_features_xc/Makefile | 78 +++++++------------ examples/fileio_features_xc/run_example.py | 7 +- examples/fileio_features_xc/test.xc | 28 +++---- examples/throughput_c/Makefile | 16 ++-- examples/throughput_c/test.c | 10 +-- {xscope_fileio/host => host}/Makefile | 2 +- {xscope_fileio/host => host}/xscope_io_host.c | 0 xscope_fileio/__init__.py | 2 +- .../api}/xscope_io_device.h | 16 ++-- {src_xcore => xscope_fileio}/config.xscope | 0 xscope_fileio/module_build_info | 0 .../src}/xscope_io_device.c | 8 +- .../xscope_io_common.h | 0 14 files changed, 76 insertions(+), 92 deletions(-) rename {xscope_fileio/host => host}/Makefile (60%) rename {xscope_fileio/host => host}/xscope_io_host.c (100%) rename {src_xcore => xscope_fileio/api}/xscope_io_device.h (86%) rename {src_xcore => xscope_fileio}/config.xscope (100%) create mode 100644 xscope_fileio/module_build_info rename {src_xcore => xscope_fileio/src}/xscope_io_device.c (95%) rename {src_xcore => xscope_fileio}/xscope_io_common.h (100%) diff --git a/.gitignore b/.gitignore index 3cc5a0d..3d222a0 100644 --- a/.gitignore +++ b/.gitignore @@ -152,3 +152,4 @@ _deps xscope_fileio/host/xscope_host_endpoint *.bin *.o +examples/fileio_features_xc/.build diff --git a/examples/fileio_features_xc/Makefile b/examples/fileio_features_xc/Makefile index bc7dfb1..ffc077f 100644 --- a/examples/fileio_features_xc/Makefile +++ b/examples/fileio_features_xc/Makefile @@ -1,49 +1,29 @@ -TARGET_FLAG ?= -target=XCORE-AI-EXPLORER -TARGET_EXEC ?= fileio_test.xe - -XCC ?= xcc - -SRCS := test.xc ../../src_xcore/xscope_io_device.c -INC_DIRS += $(dir $(SRCS)) -INC_FLAGS := $(addprefix -I,$(INC_DIRS)) - -BUILD_DIR := build -OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) -DEPS := $(OBJS:.o=.d) - -CFLAGS := -c $(INC_FLAGS) $(TARGET_FLAG) -Os -g -XCFLAGS := $(CFLAGS) - -$(TARGET_EXEC): $(OBJS) ../../src_xcore/config.xscope -# @echo $^ -# @echo $(SRCS) - @echo "**HELLO LINKER**" - $(XCC) $(TARGET_FLAG) -o $@ $^ -report - -# c source -$(BUILD_DIR)/%.c.o: %.c - $(MKDIR_P) $(dir $@) - @echo "**HELLO C**" - $(XCC) $(CFLAGS) -c $< -o $@ - -# xc source -$(BUILD_DIR)/%.xc.o: %.xc - $(MKDIR_P) $(dir $@) - @echo "**HELLO XC**" - $(XCC) $(XCFLAGS) -c $< -o $@ - -# asm source -$(BUILD_DIR)/%.S.o: %.S - $(MKDIR_P) $(dir $@) - @echo "**HELLO ASM**" - $(XCC) $(ASMFLAGS) -c $< -o $@ - -.PHONY: clean - -clean: - $(RM) -r build - $(RM) $(TARGET_EXEC) - --include $(DEPS) - -MKDIR_P ?= mkdir -p +# The TARGET variable determines what target system the application is +# compiled for. It either refers to an XN file in the source directories +# or a valid argument for the --target option when compiling +TARGET = XCORE-AI-EXPLORER + +# The APP_NAME variable determines the name of the final .xe file. It should +# not include the .xe postfix. If left blank the name will default to +# the project name +APP_NAME = + +# The USED_MODULES variable lists other modules used by the application. +USED_MODULES = xscope_fileio(>=0.1.0) + +# The flags passed to xcc when building the application +# You can also set the following to override flags for a particular language: +# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS +# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to +# xcc for the final link (mapping) stage. +XCC_FLAGS = -Os -g -report -DTEST_WAV_XSCOPE=1 + +# The XCORE_ARM_PROJECT variable, if set to 1, configures this +# project to create both xCORE and ARM binaries. +XCORE_ARM_PROJECT = 0 + +# The VERBOSE variable, if set to 1, enables verbose output from the make system. +VERBOSE = 0 + +XMOS_MAKE_PATH ?= ../.. +-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common \ No newline at end of file diff --git a/examples/fileio_features_xc/run_example.py b/examples/fileio_features_xc/run_example.py index fcc95d1..045e76d 100644 --- a/examples/fileio_features_xc/run_example.py +++ b/examples/fileio_features_xc/run_example.py @@ -1,14 +1,15 @@ #We assume that the Xscope FileIO Python library has been installed via pip beforehand and is available to import. Please see readme for instuctions. - +import subprocess import xscope_fileio -firmware_xe = "fileio_test.xe" + +firmware_xe = "bin/fileio_features_xc.xe" adapter_id = "L4Ss6YfM" ref_text = b"Evolution is change in the heritable characteristics of biological populations over successive generations." + b"\x00"; with open("ref.bin", "wb") as ref_file: ref_file.write(ref_text) -xscope_fileio.run_on_target(adapter_id, firmware_xe, use_xsim=False) +xscope_fileio.run_on_target(adapter_id, firmware_xe, use_xsim=True) with open("dut.bin", "rb") as dut_file: dut_text = dut_file.read() diff --git a/examples/fileio_features_xc/test.xc b/examples/fileio_features_xc/test.xc index 932b9ad..4d0360a 100644 --- a/examples/fileio_features_xc/test.xc +++ b/examples/fileio_features_xc/test.xc @@ -15,52 +15,52 @@ void test(void){ char buffer[256] = {0}; //Load in full ref array from disk - size_t num_bytes = xscope_fread(buffer, sizeof(ref_array), &read_xscope_file); + size_t num_bytes = xscope_fread(&read_xscope_file, buffer, sizeof(ref_array)); printf("Full sentence (%u): %s\n", num_bytes, buffer); //Seek relative to start for read - xscope_fseek(10, SEEK_SET, &read_xscope_file); + xscope_fseek(&read_xscope_file, 10, SEEK_SET); printf("Should say 10: %d\n", xscope_ftell(&read_xscope_file)); memset(buffer, 0, sizeof(buffer)); - xscope_fread(buffer, 2, &read_xscope_file); + xscope_fread(&read_xscope_file, buffer, 2); printf("Should say 'is': %s\n", buffer); //Seek relative to end for read - xscope_fseek(-29, SEEK_END, &read_xscope_file); + xscope_fseek(&read_xscope_file, -29, SEEK_END); printf("Should say 79: %d\n", xscope_ftell(&read_xscope_file)); memset(buffer, 0, sizeof(buffer)); - xscope_fread(buffer, 4, &read_xscope_file); + xscope_fread(&read_xscope_file, buffer, 4); printf("Should say 'over': %s\n", buffer); //Seek relative to current for read - xscope_fseek(1, SEEK_CUR, &read_xscope_file); + xscope_fseek(&read_xscope_file, 1, SEEK_CUR); printf("Should say 84: %d\n", xscope_ftell(&read_xscope_file)); memset(buffer, 0, sizeof(buffer)); - xscope_fread(buffer, 10, &read_xscope_file); + xscope_fread(&read_xscope_file, buffer, 10); printf("Should say 'successive': %s\n", buffer); //Load in full ref again - xscope_fseek(0, SEEK_SET, &read_xscope_file); + xscope_fseek(&read_xscope_file, 0, SEEK_SET); printf("Should say 0: %d\n", xscope_ftell(&read_xscope_file)); - num_bytes = xscope_fread(buffer, sizeof(ref_array), &read_xscope_file); + num_bytes = xscope_fread(&read_xscope_file, buffer, sizeof(ref_array)); printf("Full sentence (%u): %s\n", num_bytes, buffer); //Copy it out to dut for comparing const char dut_file_name[] = "dut.bin"; xscope_file_t write_xscope_file = xscope_open_file(dut_file_name, "wb"); - xscope_fwrite(buffer, sizeof(ref_array), &write_xscope_file); + xscope_fwrite(&write_xscope_file, buffer, sizeof(ref_array)); //Test fseek on write file const char dut_mod_file_name[] = "dut_mod.bin"; xscope_file_t write_xscope_fil_mod = xscope_open_file(dut_mod_file_name, "wb"); - xscope_fwrite(buffer, sizeof(ref_array), &write_xscope_fil_mod); - xscope_fseek(10, SEEK_SET, &write_xscope_fil_mod); + xscope_fwrite(&write_xscope_fil_mod, buffer, sizeof(ref_array)); + xscope_fseek(&write_xscope_fil_mod, 10, SEEK_SET); printf("Should say 10: %d\n", xscope_ftell(&write_xscope_fil_mod)); - xscope_fwrite("IS", 2, &write_xscope_fil_mod); + xscope_fwrite(&write_xscope_fil_mod, "IS", 2); printf("Should say 12: %d\n", xscope_ftell(&write_xscope_fil_mod)); - xscope_close_files(); + xscope_close_all_files(); } int main(void){ diff --git a/examples/throughput_c/Makefile b/examples/throughput_c/Makefile index 4a28fdc..f8db440 100644 --- a/examples/throughput_c/Makefile +++ b/examples/throughput_c/Makefile @@ -3,9 +3,9 @@ TARGET_EXEC ?= fileio_test.xe XCC ?= xcc -SRCS := main.xc test.c ../../src_xcore/xscope_io_device.c +SRCS := main.xc test.c ../../xscope_fileio/src/xscope_io_device.c INC_DIRS += $(dir $(SRCS)) -INC_FLAGS := $(addprefix -I,$(INC_DIRS)) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) -I../../xscope_fileio/api -I../../xscope_fileio BUILD_DIR := build OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) @@ -14,28 +14,26 @@ DEPS := $(OBJS:.o=.d) CFLAGS := -c $(INC_FLAGS) $(TARGET_FLAG) -Os -g XCFLAGS := $(CFLAGS) -$(TARGET_EXEC): $(OBJS) ../../src_xcore/config.xscope -# @echo $^ -# @echo $(SRCS) - @echo "**HELLO LINKER**" +$(TARGET_EXEC): $(OBJS) ../../xscope_fileio/config.xscope +# @echo "**HELLO LINKER**" $(XCC) $(TARGET_FLAG) -o $@ $^ -report # c source $(BUILD_DIR)/%.c.o: %.c $(MKDIR_P) $(dir $@) - @echo "**HELLO C**" +# @echo "**HELLO C**" $(XCC) $(CFLAGS) -c $< -o $@ # xc source $(BUILD_DIR)/%.xc.o: %.xc $(MKDIR_P) $(dir $@) - @echo "**HELLO XC**" +# @echo "**HELLO XC**" $(XCC) $(XCFLAGS) -c $< -o $@ # asm source $(BUILD_DIR)/%.S.o: %.S $(MKDIR_P) $(dir $@) - @echo "**HELLO ASM**" +# @echo "**HELLO ASM**" $(XCC) $(ASMFLAGS) -c $< -o $@ .PHONY: clean diff --git a/examples/throughput_c/test.c b/examples/throughput_c/test.c index d4edd72..65e08bd 100644 --- a/examples/throughput_c/test.c +++ b/examples/throughput_c/test.c @@ -25,9 +25,9 @@ void do_test(void){ uint8_t buffer[256*1024] = {0}; - xscope_fseek(0, SEEK_END, &read_xscope_file); + xscope_fseek(&read_xscope_file, 0, SEEK_END); unsigned fsize = xscope_ftell(&read_xscope_file); - xscope_fseek(0, SEEK_SET, &read_xscope_file); + xscope_fseek(&read_xscope_file, 0, SEEK_SET); printf("Input file size kB: %d\n", fsize / 1000); unsigned read_total_time = 0; @@ -38,12 +38,12 @@ void do_test(void){ size_t num_bytes = 0; do{ unsigned t0 = get_reference_time(); - num_bytes = xscope_fread(buffer, sizeof(buffer), &read_xscope_file); + num_bytes = xscope_fread(&read_xscope_file, buffer, sizeof(buffer)); unsigned t1 = get_reference_time(); read_total_time += t1 - t0; unsigned t2 = get_reference_time(); - xscope_fwrite(buffer, num_bytes, &write_xscope_file); + xscope_fwrite(&write_xscope_file, buffer, num_bytes); unsigned t3 = get_reference_time(); write_total_time += t3 - t2; } while(num_bytes > 0); @@ -59,5 +59,5 @@ void main_tile0(chanend_t xscope_chan) { xscope_io_init(xscope_chan); do_test(); - xscope_close_files(); + xscope_close_all_files(); } diff --git a/xscope_fileio/host/Makefile b/host/Makefile similarity index 60% rename from xscope_fileio/host/Makefile rename to host/Makefile index d6c7558..398275f 100644 --- a/xscope_fileio/host/Makefile +++ b/host/Makefile @@ -4,7 +4,7 @@ default_: all GCC ?= gcc xscope_host_endpoint : xscope_io_host.c - $(GCC) -o $@ $< -I ../../src_xcore -I ${XMOS_TOOL_PATH}/include ${XMOS_TOOL_PATH}/lib/xscope_endpoint.so -std=c99 + $(GCC) -o $@ $< -I ../xscope_fileio -I ${XMOS_TOOL_PATH}/include ${XMOS_TOOL_PATH}/lib/xscope_endpoint.so -std=c99 .PHONY: all all: xscope_host_endpoint diff --git a/xscope_fileio/host/xscope_io_host.c b/host/xscope_io_host.c similarity index 100% rename from xscope_fileio/host/xscope_io_host.c rename to host/xscope_io_host.c diff --git a/xscope_fileio/__init__.py b/xscope_fileio/__init__.py index be9d1c5..06d22f1 100644 --- a/xscope_fileio/__init__.py +++ b/xscope_fileio/__init__.py @@ -14,7 +14,7 @@ # for a busy CPU XRUN_TIMEOUT = 20 -HOST_PATH = (Path(__file__).parent / "host") +HOST_PATH = (Path(__file__).parent / "../host") def _get_host_exe(): diff --git a/src_xcore/xscope_io_device.h b/xscope_fileio/api/xscope_io_device.h similarity index 86% rename from src_xcore/xscope_io_device.h rename to xscope_fileio/api/xscope_io_device.h index 3890d94..ef56d36 100644 --- a/src_xcore/xscope_io_device.h +++ b/xscope_fileio/api/xscope_io_device.h @@ -55,46 +55,50 @@ xscope_file_t xscope_open_file(const char* filename, char* attributes); * It sends a command to the host app which responds with an upload of the * requested data from the file. Each read is contiguous from the previous read * + * @param handle of file to operate on * @param buffer that will be written the file read * @param n_bytes_to_read * @return number of bytes actually read. Will be zero if EOF already hit. ******************************************************************************/ -size_t xscope_fread(uint8_t *buffer, size_t n_bytes_to_read, xscope_file_t *xscope_io_handle); +size_t xscope_fread(xscope_file_t *xscope_io_handle, uint8_t *buffer, size_t n_bytes_to_read); /****************************************************************************** * xscope_fwrite * * Writes a number of bytes from the buffer provided by the application. * + * @param handle of file to operate on * @param buffer that will be read and sent to be written on the host * @param n_bytes_to_write * @return void ******************************************************************************/ -void xscope_fwrite(uint8_t *buffer, size_t n_bytes_to_write, xscope_file_t *xscope_io_handle); +void xscope_fwrite(xscope_file_t *xscope_io_handle, uint8_t *buffer, size_t n_bytes_to_write); /****************************************************************************** * xscope_seek SEEK_SET, SEEK_CUR or SEEK_END. Note no error checking yet!! * * Sets the file position of the stream to the given offset * + * @param handle of file to operate on * @param offset in bytes * @param whence - SEEK_SET, SEEK_CUR or SEEK_END * @return void ******************************************************************************/ -void xscope_fseek(int offset, int whence, xscope_file_t *xscope_io_handle); +void xscope_fseek(xscope_file_t *xscope_io_handle, int offset, int whence); /****************************************************************************** * xscope_ftell * * Obtain the file position of the stream * + * @param handle of file to operate on * @return void ******************************************************************************/ -int xscope_ftell( xscope_file_t *xscope_file); +int xscope_ftell(xscope_file_t *xscope_file); /****************************************************************************** - * xscope_close_files + * xscope_close_all_files * * Closes all files on the host. * This must be called at the end of device application as it also signals @@ -102,7 +106,7 @@ int xscope_ftell( xscope_file_t *xscope_file); * * @return void ******************************************************************************/ -void xscope_close_files(void); +void xscope_close_all_files(void); #ifdef __XC__ } diff --git a/src_xcore/config.xscope b/xscope_fileio/config.xscope similarity index 100% rename from src_xcore/config.xscope rename to xscope_fileio/config.xscope diff --git a/xscope_fileio/module_build_info b/xscope_fileio/module_build_info new file mode 100644 index 0000000..e69de29 diff --git a/src_xcore/xscope_io_device.c b/xscope_fileio/src/xscope_io_device.c similarity index 95% rename from src_xcore/xscope_io_device.c rename to xscope_fileio/src/xscope_io_device.c index 6ba6a2d..0af74b7 100644 --- a/src_xcore/xscope_io_device.c +++ b/xscope_fileio/src/xscope_io_device.c @@ -62,7 +62,7 @@ xscope_file_t xscope_open_file(const char* filename, char* attributes){ return xscope_file; } -size_t xscope_fread(uint8_t *buffer, size_t n_bytes_to_read, xscope_file_t *xscope_file){ +size_t xscope_fread(xscope_file_t *xscope_file, uint8_t *buffer, size_t n_bytes_to_read){ lock_acquire(file_access_lock); xassert(xscope_file->mode == XSCOPE_IO_READ_BINARY || xscope_file->mode == XSCOPE_IO_READ_TEXT); @@ -107,7 +107,7 @@ size_t xscope_fread(uint8_t *buffer, size_t n_bytes_to_read, xscope_file_t *xsco return n_bytes_read; } -void xscope_fwrite(uint8_t *buffer, size_t n_bytes_to_write, xscope_file_t *xscope_file){ +void xscope_fwrite(xscope_file_t *xscope_file, uint8_t *buffer, size_t n_bytes_to_write){ lock_acquire(file_access_lock); xassert(xscope_file->mode == XSCOPE_IO_WRITE_BINARY || xscope_file->mode == XSCOPE_IO_WRITE_TEXT); @@ -138,7 +138,7 @@ void xscope_fwrite(uint8_t *buffer, size_t n_bytes_to_write, xscope_file_t *xsco lock_release(file_access_lock); } -void xscope_fseek(int offset, int whence, xscope_file_t *xscope_file){ +void xscope_fseek(xscope_file_t *xscope_file, int offset, int whence){ lock_acquire(file_access_lock); xassert(whence == SEEK_SET || whence == SEEK_CUR || whence == SEEK_END); unsigned char packet[1 + 1 + sizeof(offset)]; @@ -150,7 +150,7 @@ void xscope_fseek(int offset, int whence, xscope_file_t *xscope_file){ lock_release(file_access_lock); } -int xscope_ftell( xscope_file_t *xscope_file){ +int xscope_ftell(xscope_file_t *xscope_file){ lock_acquire(file_access_lock); const unsigned char idx = xscope_file->index + '0'; xscope_bytes(XSCOPE_ID_TELL, 1, &idx); diff --git a/src_xcore/xscope_io_common.h b/xscope_fileio/xscope_io_common.h similarity index 100% rename from src_xcore/xscope_io_common.h rename to xscope_fileio/xscope_io_common.h From 0dde568fec95cb1312780794f15d378b4e89e2f3 Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 15 Mar 2021 11:55:50 +0000 Subject: [PATCH 12/18] Add changelog and update readme --- CHANGELOG.rst | 14 ++++++++++++++ README.md | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 CHANGELOG.rst diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..e564bdb --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,14 @@ +xscope_fileo +============ + +0.1.0 +----- + + * ADDED: ftell and fseek + * ADDED: XC and C based examples + * CHANGED: module_build_info friendly layout of embedded source + * CHANGED: API argument ordering so file handle comes last as per stdio + +0.0.1 +----- + * ADDED: Initial version with support for fread & frwite + python helper diff --git a/README.md b/README.md index 643fb9e..c537c17 100644 --- a/README.md +++ b/README.md @@ -51,17 +51,25 @@ void xscope_io_init(chanend_t xscope_end); xscope_file_t xscope_open_file(char* filename, char* attributes); -size_t xscope_fread(uint8_t *buffer, size_t n_bytes_to_read, xscope_file_t *xscope_io_handle); +size_t xscope_fread(xscope_file_t *xscope_io_handle, uint8_t *buffer, size_t n_bytes_to_read); -void xscope_fwrite(uint8_t *buffer, size_t n_bytes_to_write, xscope_file_t *xscope_io_handle); +void xscope_fwrite(xscope_file_t *xscope_io_handle, uint8_t *buffer, size_t n_bytes_to_write); -void xscope_close_files(void); +void xscope_fseek(xscope_file_t *xscope_io_handle, int offset, int whence); + +int xscope_ftell(xscope_file_t *xscope_file); + +void xscope_close_all_files(void); ``` +The device side application requires a multi-tile main since it uses the xscope_host_data(xscope_chan); service +to communicate with the host, which requires this. See examples for XC and C applications for how to do this. + + Note currently missing from fileio api: ``` -fseek, ftell, fprintf, fscanf +fprintf, fscanf ``` ## System Architecture From a2dc53599d1dfeedc98bddf49bce2f59df6d43cc Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 15 Mar 2021 15:41:07 +0000 Subject: [PATCH 13/18] fix missing change of api in c --- xscope_fileio/src/xscope_io_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xscope_fileio/src/xscope_io_device.c b/xscope_fileio/src/xscope_io_device.c index 0af74b7..5aa5342 100644 --- a/xscope_fileio/src/xscope_io_device.c +++ b/xscope_fileio/src/xscope_io_device.c @@ -162,7 +162,7 @@ int xscope_ftell(xscope_file_t *xscope_file){ return offset; } -void xscope_close_files(void){ +void xscope_close_all_files(void){ xscope_bytes(XSCOPE_ID_HOST_QUIT, 1, (unsigned char*)"!"); if(VERBOSE) printf("Sent close files\n"); hwtimer_t t = hwtimer_alloc(); hwtimer_delay(t, 5000000); //50ms to allow messages to make it before xgdb quit From be5e9d5d1086a393f8890ec30bde4e80711c9ec1 Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 15 Mar 2021 15:41:25 +0000 Subject: [PATCH 14/18] Add version info to module build info --- xscope_fileio/module_build_info | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xscope_fileio/module_build_info b/xscope_fileio/module_build_info index e69de29..291780f 100644 --- a/xscope_fileio/module_build_info +++ b/xscope_fileio/module_build_info @@ -0,0 +1,6 @@ +VERSION = 0.1.0 + +MODULE_XCC_FLAGS = $(XCC_FLAGS) + +DEPENDENT_MODULES = + From da1fca04ee9831e7106a347b73caa71d8011be92 Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 15 Mar 2021 16:29:41 +0000 Subject: [PATCH 15/18] Correct readme --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c537c17..9a205a6 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,11 @@ Currently it supports: * Arbitrary number (32 currently) of **read or write** files (not read/write) - * **Sequential** (not random) access only - - * “wb” and “rb” file access mode only + * “wb” or “rb” file access mode only * 6-8MBytes/s Device to Host speed - * 150-850kBytes/s Host to Device speed (Linux < 200kB, Mac > 800kB) + * Up to 1MBytes/s Host to Device speed (on tools 15.0.4) This compares to around 2kBytes/s for fileio over JTAG supported using `xrun --io`. From fa13f054a0932f52844f21101222e9ca492aae1c Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 16 Mar 2021 09:38:40 +0000 Subject: [PATCH 16/18] FIx host setup path --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 3febe1c..a23919a 100644 --- a/setup.py +++ b/setup.py @@ -45,9 +45,9 @@ def run(self): # So it's "xscope_fileio" not "xscope_fileio/" package_data={ "xscope_fileio": [ - "host/Makefile", - "host/xscope_io_host.c", - "host/xscope_host_endpoint", + "../host/Makefile", + "../host/xscope_io_host.c", + "../host/xscope_host_endpoint", ] }, packages=setuptools.find_packages(), From 2e2244bab8c089de12d43bd474174c5ef7dcdab9 Mon Sep 17 00:00:00 2001 From: shuchitak Date: Tue, 16 Mar 2021 09:42:45 +0000 Subject: [PATCH 17/18] fix host path --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a23919a..b345b8e 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ class CustomBuildCommand(build): def run(self): # Make the host binary - with pushd("xscope_fileio/host/"): + with pushd("host/"): subprocess.check_output("make") build.run(self) @@ -31,7 +31,7 @@ class CustomDevelopCommand(develop): def run(self): # Make the host binary - with pushd("xscope_fileio/host/"): + with pushd("host/"): subprocess.check_output("make") develop.run(self) From 10654676f0d1d436444aafea3f578bf8e7994a37 Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 16 Mar 2021 12:16:02 +0000 Subject: [PATCH 18/18] config.xscope goes in local app to avoid waf issues --- CHANGELOG.rst | 6 ++++++ README.md | 3 +++ .../fileio_features_xc}/config.xscope | 0 examples/throughput_c/Makefile | 2 +- examples/throughput_c/config.xscope | 10 ++++++++++ xscope_fileio/config.xscope.txt | 10 ++++++++++ 6 files changed, 30 insertions(+), 1 deletion(-) rename {xscope_fileio => examples/fileio_features_xc}/config.xscope (100%) create mode 100644 examples/throughput_c/config.xscope create mode 100644 xscope_fileio/config.xscope.txt diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e564bdb..8f7f914 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ xscope_fileo ============ +0.2.0 +----- + + * FIXED: setup.py now properly builds host app + * CHANGED: config.xscope now needs to be copied to local firmware app + 0.1.0 ----- diff --git a/README.md b/README.md index 9a205a6..97ba39b 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ void xscope_close_all_files(void); The device side application requires a multi-tile main since it uses the xscope_host_data(xscope_chan); service to communicate with the host, which requires this. See examples for XC and C applications for how to do this. +You will also need a copy of `config.xscope` in your firmware directory. This +enables xscope in the tools and sets up the xscope probes used by fileio for communicating with the host app. You +can find a copy in `xscope_fileio/config.xscope xscope_fileio/config.xscope.txt` which you should rename to `config.xscope`. Note currently missing from fileio api: diff --git a/xscope_fileio/config.xscope b/examples/fileio_features_xc/config.xscope similarity index 100% rename from xscope_fileio/config.xscope rename to examples/fileio_features_xc/config.xscope diff --git a/examples/throughput_c/Makefile b/examples/throughput_c/Makefile index f8db440..1460f6d 100644 --- a/examples/throughput_c/Makefile +++ b/examples/throughput_c/Makefile @@ -14,7 +14,7 @@ DEPS := $(OBJS:.o=.d) CFLAGS := -c $(INC_FLAGS) $(TARGET_FLAG) -Os -g XCFLAGS := $(CFLAGS) -$(TARGET_EXEC): $(OBJS) ../../xscope_fileio/config.xscope +$(TARGET_EXEC): $(OBJS) config.xscope # @echo "**HELLO LINKER**" $(XCC) $(TARGET_FLAG) -o $@ $^ -report diff --git a/examples/throughput_c/config.xscope b/examples/throughput_c/config.xscope new file mode 100644 index 0000000..0d3b65e --- /dev/null +++ b/examples/throughput_c/config.xscope @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/xscope_fileio/config.xscope.txt b/xscope_fileio/config.xscope.txt new file mode 100644 index 0000000..0d3b65e --- /dev/null +++ b/xscope_fileio/config.xscope.txt @@ -0,0 +1,10 @@ + + + + + + + + + +