From 0928046a748bb57736e445a6cf03a100932f3247 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Fri, 1 Jul 2022 08:28:54 +0100 Subject: [PATCH 1/6] Increase delay in xscope_fread() from 0.1 ms to 0.5 ms --- CHANGELOG.rst | 5 +++++ xscope_fileio/module_build_info | 2 +- xscope_fileio/src/xscope_io_device.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 322eb12..160e3c7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ xscope fileio change log ======================== +1.1.1 +----- + + * CHANGED: increase xscope_fread() delay for Windows work-around to 0.5 ms + 1.1.0 ----- diff --git a/xscope_fileio/module_build_info b/xscope_fileio/module_build_info index 7b658d6..e6ada03 100644 --- a/xscope_fileio/module_build_info +++ b/xscope_fileio/module_build_info @@ -1,4 +1,4 @@ -VERSION = 1.1.0 +VERSION = 1.1.1 MODULE_XCC_FLAGS = $(XCC_FLAGS) diff --git a/xscope_fileio/src/xscope_io_device.c b/xscope_fileio/src/xscope_io_device.c index 691ff68..22355d6 100644 --- a/xscope_fileio/src/xscope_io_device.c +++ b/xscope_fileio/src/xscope_io_device.c @@ -95,7 +95,7 @@ size_t xscope_fread(xscope_file_t *xscope_file, uint8_t *buffer, size_t n_bytes_ // Add a delay to avoid a race condition seen only on Windows // See issue 30 - #define XSCOPE_FREAD_RACE_CONDITION_DELAY ( XS1_TIMER_MHZ * 100 ) + #define XSCOPE_FREAD_RACE_CONDITION_DELAY ( XS1_TIMER_MHZ * 500 ) // Define the timeafter macro until it becomes available in C source files via xs1.h #define timeafter(A, B) ((int)((B) - (A)) < 0) From 0220e49e367f2f605a6b666d1f70570ebe0006c5 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Tue, 19 Jul 2022 15:35:54 -0400 Subject: [PATCH 2/6] Add check for init being called and complete --- xscope_fileio/api/xscope_io_device.h | 33 ++++++++++++++++++---------- xscope_fileio/src/xscope_io_device.c | 6 +++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/xscope_fileio/api/xscope_io_device.h b/xscope_fileio/api/xscope_io_device.h index c871868..67a2e51 100644 --- a/xscope_fileio/api/xscope_io_device.h +++ b/xscope_fileio/api/xscope_io_device.h @@ -31,10 +31,19 @@ extern "C"{ * * @param xscope_end is the app side channel end connected xscope_host_data() * task in the top level application. - * @return void + * @return void ******************************************************************************/ void xscope_io_init(chanend_t xscope_end); +/****************************************************************************** + * xscope_fileio_is_initialized + * + * This returns the status of the host xscope fileio connection + * + * @return 1 if initialized, else 0 + ******************************************************************************/ +unsigned xscope_fileio_is_initialized(void); + /****************************************************************************** * xscope_open_files * @@ -44,7 +53,7 @@ void xscope_io_init(chanend_t xscope_end); * * @param read_file_name to open on host * @param write_file_name to open on host - * @return an initialised xscope_file_handle + * @return an initialised xscope_file_handle ******************************************************************************/ xscope_file_t xscope_open_file(const char* filename, char* attributes); @@ -56,9 +65,9 @@ xscope_file_t xscope_open_file(const char* filename, char* attributes); * 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 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. + * @return number of bytes actually read. Will be zero if EOF already hit. ******************************************************************************/ size_t xscope_fread(xscope_file_t *xscope_io_handle, uint8_t *buffer, size_t n_bytes_to_read); @@ -68,9 +77,9 @@ size_t xscope_fread(xscope_file_t *xscope_io_handle, uint8_t *buffer, size_t n_b * 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 buffer that will be read and sent to be written on the host * @param n_bytes_to_write - * @return void + * @return void ******************************************************************************/ void xscope_fwrite(xscope_file_t *xscope_io_handle, uint8_t *buffer, size_t n_bytes_to_write); @@ -80,9 +89,9 @@ void xscope_fwrite(xscope_file_t *xscope_io_handle, uint8_t *buffer, size_t n_by * Sets the file position of the stream to the given offset * * @param handle of file to operate on - * @param offset in bytes + * @param offset in bytes * @param whence - SEEK_SET, SEEK_CUR or SEEK_END - * @return void + * @return void ******************************************************************************/ void xscope_fseek(xscope_file_t *xscope_io_handle, int offset, int whence); @@ -92,9 +101,9 @@ void xscope_fseek(xscope_file_t *xscope_io_handle, int offset, int whence); * Obtain the file position of the stream * * @param handle of file to operate on - * @return void + * @return void ******************************************************************************/ -int xscope_ftell(xscope_file_t *xscope_file); +int xscope_ftell(xscope_file_t *xscope_file); /****************************************************************************** @@ -104,7 +113,7 @@ int xscope_ftell(xscope_file_t *xscope_file); * This must be called at the end of device application as it also signals * terminate to the host app. * - * @return void + * @return void ******************************************************************************/ void xscope_close_all_files(void); @@ -112,4 +121,4 @@ void xscope_close_all_files(void); } #endif -#endif \ No newline at end of file +#endif diff --git a/xscope_fileio/src/xscope_io_device.c b/xscope_fileio/src/xscope_io_device.c index 010cbe9..1bc560f 100644 --- a/xscope_fileio/src/xscope_io_device.c +++ b/xscope_fileio/src/xscope_io_device.c @@ -16,6 +16,7 @@ chanend_t c_xscope = 0; unsigned file_idx = 0; lock_t file_access_lock; +volatile unsigned xscope_io_init_flag = 0; __attribute__((weak)) void xscope_fileio_lock_alloc(void) { @@ -33,11 +34,16 @@ void xscope_fileio_lock_release(void) { lock_release(file_access_lock); } +unsigned xscope_fileio_is_initialized(void) { + return xscope_io_init_flag; +} + void xscope_io_init(chanend_t xscope_end){ xscope_fileio_lock_alloc(); xscope_mode_lossless(); c_xscope = xscope_end; xscope_connect_data_from_host(c_xscope); + xscope_io_init_flag = 1; } xscope_file_t xscope_open_file(const char* filename, char* attributes){ From ddfcab4d69757ffa0155a0484c10d824f629c5be Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Wed, 20 Jul 2022 08:39:51 -0400 Subject: [PATCH 3/6] Rework bugfix so it should be backwards compat Makes the xscope_open_file() explicitly wait until xscope_io_init() has completed. Still retains the helper function to allow the app to check if xscope_fileio is initialized to prevent busy waiting on first xscope_open_file() call in the rtos use cases. --- xscope_fileio/src/xscope_io_device.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xscope_fileio/src/xscope_io_device.c b/xscope_fileio/src/xscope_io_device.c index 1bc560f..a4567b4 100644 --- a/xscope_fileio/src/xscope_io_device.c +++ b/xscope_fileio/src/xscope_io_device.c @@ -47,6 +47,10 @@ void xscope_io_init(chanend_t xscope_end){ } xscope_file_t xscope_open_file(const char* filename, char* attributes){ + /* Wait until xscope_fileio is initialized */ + while(xscope_fileio_is_initialized() == 0) { + delay_ticks(1); + } xscope_fileio_lock_acquire(); xscope_file_t xscope_file; strcpy(xscope_file.filename, filename); From 3f30734b6ca26d905182502e786538c2c9e12bc6 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Wed, 20 Jul 2022 08:45:50 -0400 Subject: [PATCH 4/6] Remove explicit delay --- CHANGELOG.rst | 9 ++++++++- xscope_fileio/src/xscope_io_device.c | 10 ---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 160e3c7..55fbcc4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ xscope fileio change log ======================== +1.1.2 +----- + + * REMOVED: xscope_fread() delay for Windows work-around to 0.5 ms + * ADDED: checks that xscope_io_init() has completed before allowing a file to be opened + + 1.1.1 ----- @@ -18,7 +25,7 @@ xscope fileio change log * ADDED: support for building and running the host endpoint on Windows * ADDED: XMOS public V1 license * ADDED: support for run_on_target() to optionally redirect stdout to file - * REMOVED:run_on_target() method returns stdout/err as list of lines + * REMOVED:run_on_target() method returns stdout/err as list of lines * REMOVED: optional verbose kwarg in run_on_target()to reduce verbosity 0.4.0 diff --git a/xscope_fileio/src/xscope_io_device.c b/xscope_fileio/src/xscope_io_device.c index 1143a06..616bfa5 100644 --- a/xscope_fileio/src/xscope_io_device.c +++ b/xscope_fileio/src/xscope_io_device.c @@ -103,16 +103,6 @@ size_t xscope_fread(xscope_file_t *xscope_file, uint8_t *buffer, size_t n_bytes_ xscope_bytes(XSCOPE_ID_READ_BYTES, sizeof(packet), packet); - // Add a delay to avoid a race condition seen only on Windows - // See issue 30 - #define XSCOPE_FREAD_RACE_CONDITION_DELAY ( XS1_TIMER_MHZ * 500 ) - - // Define the timeafter macro until it becomes available in C source files via xs1.h - #define timeafter(A, B) ((int)((B) - (A)) < 0) - - uint32_t time_delay = get_reference_time() + XSCOPE_FREAD_RACE_CONDITION_DELAY; - while(timeafter(time_delay, get_reference_time())); - do { int bytes_read = 0; From 30bfba3e21fdd5e1cdfcd5c548582a678c5fc757 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Wed, 20 Jul 2022 11:20:41 -0400 Subject: [PATCH 5/6] Adds to readme and changelog --- CHANGELOG.rst | 2 +- README.rst | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 55fbcc4..8b9a42b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,7 +6,7 @@ xscope fileio change log * REMOVED: xscope_fread() delay for Windows work-around to 0.5 ms * ADDED: checks that xscope_io_init() has completed before allowing a file to be opened - + * ADDED: adds helper function, xscope_fileio_is_initialized(), to allow application to check if the host connection has been established 1.1.1 ----- diff --git a/README.rst b/README.rst index 4b678c7..32f9a74 100644 --- a/README.rst +++ b/README.rst @@ -59,6 +59,8 @@ Source and header files for device code are found in ``src_xcore`` void xscope_io_init(chanend_t xscope_end); + unsigned xscope_fileio_is_initialized(void); + xscope_file_t xscope_open_file(char* filename, char* attributes); //NOTE MAXIMUM n_bytes_to_read of 64kB on Linux http://bugzilla/show_bug.cgi?id=18528 @@ -68,7 +70,7 @@ Source and header files for device code are found in ``src_xcore`` void xscope_fseek(xscope_file_t *xscope_io_handle, int offset, int whence); - int xscope_ftell(xscope_file_t *xscope_file); + int xscope_ftell(xscope_file_t *xscope_file); void xscope_close_all_files(void); @@ -76,7 +78,7 @@ The device side application requires a multi-tile main since it uses the xscope_ 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 +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: @@ -90,7 +92,7 @@ System Architecture ------------------- The ``run_on_target`` function calls ``xrun --xscope-port`` with the binary and specified target adapter, -and simultaneously launches a host application to communicate xscope data to/from +and simultaneously launches a host application to communicate xscope data to/from the xrun process via sockets. The host application responds to ``xscope_fileio`` API calls in the firmware code, reading/writing to the host file system. From 5c9f621512cba4e5ac9bfacf0dd2cd2c5514b310 Mon Sep 17 00:00:00 2001 From: Michael Banther Date: Thu, 21 Jul 2022 12:11:55 +0100 Subject: [PATCH 6/6] Corrected change log --- CHANGELOG.rst | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8b9a42b..4590f5d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,18 +1,13 @@ xscope fileio change log ======================== -1.1.2 +1.1.1 ----- - * REMOVED: xscope_fread() delay for Windows work-around to 0.5 ms + * REMOVED: xscope_fread() delay for Windows race condition * ADDED: checks that xscope_io_init() has completed before allowing a file to be opened * ADDED: adds helper function, xscope_fileio_is_initialized(), to allow application to check if the host connection has been established -1.1.1 ------ - - * CHANGED: increase xscope_fread() delay for Windows work-around to 0.5 ms - 1.1.0 -----