Skip to content

Commit

Permalink
Merge pull request #25 from xmos/feature/examples
Browse files Browse the repository at this point in the history
Feature/examples
  • Loading branch information
keithm-xmos committed Sep 22, 2020
2 parents 8abe6bf + 4c617f6 commit f8bc01c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
69 changes: 64 additions & 5 deletions tensorflow/lite/micro/kernels/xcore/xcore_device_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@
#include <string.h>

#ifdef XCORE

#include <xcore/port.h>
#include <xcore/swmem_fill.h>
#include <xmos_flash.h>

#ifdef USE_SWMEM
#ifdef USE_QSPI_SWMEM_DEV
#include "soc.h"
#include "qspi_flash_dev.h"

static chanend_t swmem_c;

#define WORDS_TO_BYTES(w) ((w) * sizeof(uint32_t))
#define BYTES_TO_WORDS(b) (((b) + sizeof(uint32_t) - 1) / sizeof(uint32_t))

#define WORD_TO_BYTE_ADDRESS(w) WORDS_TO_BYTES(w)
#define BYTE_TO_WORD_ADDRESS(b) ((b) / sizeof(uint32_t))
#else
flash_ports_t flash_ports_0 = {PORT_SQI_CS, PORT_SQI_SCLK, PORT_SQI_SIO,
XS1_CLKBLK_5};

Expand All @@ -21,28 +33,57 @@ flash_qe_config_t flash_qe_config_0 = {flash_qe_location_status_reg_0,
flash_qe_bit_6};

flash_handle_t flash_handle;
#endif /* USE_QSPI_SWMEM_DEV */

swmem_fill_t swmem_fill_handle;

void swmem_fill(fill_slot_t address) {
swmem_fill_buffer_t buf;
unsigned int *buf_ptr = (unsigned int *)buf;

swmem_fill_buffer_t buf;
unsigned int *buf_ptr = (unsigned int *)buf;

#ifdef USE_QSPI_SWMEM_DEV
qspi_flash_dev_cmd_t local_cmd;
local_cmd.operation = qspi_flash_dev_op_read;
local_cmd.byte_address = WORD_TO_BYTE_ADDRESS((address - (void *)XS1_SWMEM_BASE) >> 2);
local_cmd.byte_count = WORDS_TO_BYTES(SWMEM_FILL_SIZE_WORDS);

soc_peripheral_function_code_tx(swmem_c, QSPI_DEV_SWMEM_REQ);
soc_peripheral_varlist_tx(swmem_c, 1,
sizeof(qspi_flash_dev_cmd_t), &local_cmd);
soc_peripheral_varlist_rx(swmem_c, 1,
local_cmd.byte_count, buf_ptr);
swmem_fill_populate_from_buffer(swmem_fill_handle, address, buf);
#else
flash_read_quad(&flash_handle, (address - (void *)XS1_SWMEM_BASE) >> 2,
buf_ptr, SWMEM_FILL_SIZE_WORDS);

uint32_t adr = (address - (void *)XS1_SWMEM_BASE) >> 2;

swmem_fill_populate_from_buffer(swmem_fill_handle, address, buf);
#endif /* USE_QSPI_SWMEM_DEV */
}

#ifdef USE_QSPI_SWMEM_DEV
void swmem_setup(chanend_t ctrl_swmem_c) {
swmem_c = ctrl_swmem_c;

swmem_fill_handle = swmem_fill_get();
}
#else
void swmem_setup() {
flash_connect(&flash_handle, &flash_ports_0, flash_clock_config,
flash_qe_config_0);

swmem_fill_handle = swmem_fill_get();
}
#endif /* USE_QSPI_SWMEM_DEV */

void swmem_teardown() {
swmem_fill_free(swmem_fill_handle);
#ifdef USE_QSPI_SWMEM_DEV
#else
flash_disconnect(&flash_handle);
#endif /* USE_QSPI_SWMEM_DEV */
}

void swmem_handler(void *ignored) {
Expand All @@ -52,12 +93,30 @@ void swmem_handler(void *ignored) {
swmem_fill(address);
}
}
#endif /* USE_SWMEM */

void memload(void **dest, void *src, size_t size) {
#ifdef USE_SWMEM
if (IS_SWMEM(src)) {
#ifdef USE_QSPI_SWMEM_DEV
qspi_flash_dev_cmd_t local_cmd;
local_cmd.operation = qspi_flash_dev_op_read;
local_cmd.byte_address = WORD_TO_BYTE_ADDRESS(((uintptr_t)src - XS1_SWMEM_BASE) >> 2);
local_cmd.byte_count = WORDS_TO_BYTES(size);

assert(local_cmd.byte_count <= QSPI_FLASH_DEV_WRITE_BUFSIZE);
soc_peripheral_function_code_tx(swmem_c, QSPI_DEV_SWMEM_REQ);
soc_peripheral_varlist_tx(swmem_c, 1,
sizeof(qspi_flash_dev_cmd_t), &local_cmd);
soc_peripheral_varlist_rx(swmem_c, 1,
size * sizeof(uint32_t*), (unsigned int *)*dest);
#else
flash_read_quad(&flash_handle, ((uintptr_t)src - XS1_SWMEM_BASE) >> 2,
(unsigned int *)*dest, size);
} else if (IS_EXTMEM(src)) {
#endif /* USE_QSPI_SWMEM_DEV */
} else
#endif /* USE_SWMEM */
if (IS_EXTMEM(src)) {
memcpy(*dest, src, size);
}
}
Expand Down
10 changes: 9 additions & 1 deletion tensorflow/lite/micro/kernels/xcore/xcore_device_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ extern "C" {
#define IS_SWMEM(a) \
(((uintptr_t)a >= 0x40000000) && (((uintptr_t)a <= 0x80000000)))

#ifdef USE_SWMEM
#ifndef USE_QSPI_SWMEM_DEV
void swmem_setup();
#else
#include <xcore/chanend.h>
void swmem_setup(chanend_t ctrl_swmem_c);
#endif // USE_QSPI_SWMEM_DEV
#endif // USE_SWMEM

void swmem_handler(void *ignored);
void swmem_teardown();

Expand All @@ -51,4 +59,4 @@ void memload(void **dest, void *src, size_t size);
}
#endif

#endif // XCORE_DEVICE_MEMORY_H_
#endif // XCORE_DEVICE_MEMORY_H_
3 changes: 1 addition & 2 deletions tensorflow/lite/micro/tools/make/targets/xcore_makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
# $ make -f tensorflow/lite/micro/tools/make/Makefile TARGET="xcore" test

ifeq ($(TARGET), xcore)
XTIME_URL := "https://www.xmos.com/download/Tools-15---Linux-64%2815.0.0_rc1%29.tgz?key=132D-9DC9-E913-0229-ECE6-D5AB-F511-2B19"
XTIME_MD5 := "8f6543c8ac4af7583edf75e62df322a2"
$(eval $(call add_third_party_download,$(XTIME_URL),$(XTIME_MD5),xtimecomposer))
# TODO download lib_mic_array, lib_xassert, lib_dsp (for microspeech)
PLATFORM_FLAGS = -target=XU316-1024-FB265-C32 -mcmodel=large -Os -DXCORE -Wno-xcore-fptrgroup -report
CXX_TOOL := xcc
CC_TOOL := xcc
Expand Down
3 changes: 3 additions & 0 deletions tensorflow/lite/micro/tools/make/third_party_downloads.inc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ ZEPHYR_MD5 := "755622eb4812fde918a6382b65d50c3b"
XTENSA_HIFI4_URL :="http://mirror.tensorflow.org/github.com/foss-xtensa/nnlib-hifi4/raw/master/archive/xa_nnlib_06_27.zip"
XTENSA_HIFI4_MD5 :="45fdc1209a8da62ab568aa6040f7eabf"
XTIME_URL := "https://www.xmos.com/download/Tools-15---Linux-64%2815.0.0_rc1%29.tgz?key=132D-9DC9-E913-0229-ECE6-D5AB-F511-2B19"
XTIME_MD5 := "8f6543c8ac4af7583edf75e62df322a2"
ETHOSU_URL := "https://git.mlplatform.org/ml/ethos-u/ethos-u-core-driver.git/snapshot/ethos-u-core-driver-2b201c340788ac582cec160b7217c2b5405b04f9.tar.gz"
ETHOSU_MD5 := "0c148b90a1ee01de398892eb3a63e717"
Expand Down
5 changes: 5 additions & 0 deletions tensorflow/lite/micro/xcore/debug_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ limitations under the License.

#include "tensorflow/lite/micro/debug_log.h"

#if (HAS_LIB_RTOS_SUPPORT == 1)
#include "rtos_printf.h"
extern "C" void DebugLog(const char* s) { rtos_printf("%s", s); }
#else
#include <cstdio>
extern "C" void DebugLog(const char* s) { printf("%s", s); }
#endif

0 comments on commit f8bc01c

Please sign in to comment.