From 0120a4acb664d860c43abbb741108de3c36def75 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Tue, 6 Sep 2022 09:30:37 -0400 Subject: [PATCH 1/8] Add nonfunctional xlink example --- examples/examples.cmake | 3 +- examples/freertos/xlink/README.rst | 90 +++ examples/freertos/xlink/XCORE-AI-EXPLORER.xn | 108 ++++ examples/freertos/xlink/src/FreeRTOSConfig.h | 118 ++++ examples/freertos/xlink/src/app_conf.h | 56 ++ examples/freertos/xlink/src/config.xscope | 24 + examples/freertos/xlink/src/main.c | 591 +++++++++++++++++++ examples/freertos/xlink/xlink.cmake | 108 ++++ 8 files changed, 1097 insertions(+), 1 deletion(-) create mode 100644 examples/freertos/xlink/README.rst create mode 100644 examples/freertos/xlink/XCORE-AI-EXPLORER.xn create mode 100644 examples/freertos/xlink/src/FreeRTOSConfig.h create mode 100644 examples/freertos/xlink/src/app_conf.h create mode 100644 examples/freertos/xlink/src/config.xscope create mode 100644 examples/freertos/xlink/src/main.c create mode 100644 examples/freertos/xlink/xlink.cmake diff --git a/examples/examples.cmake b/examples/examples.cmake index a7155e7fc..24fff2048 100644 --- a/examples/examples.cmake +++ b/examples/examples.cmake @@ -2,7 +2,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL XCORE_XS3A) ## Bare metal examples include(${CMAKE_CURRENT_LIST_DIR}/bare-metal/explorer_board/explorer_board.cmake) - # + ## FreeRTOS examples include(${CMAKE_CURRENT_LIST_DIR}/freertos/device_control/device_control.cmake) include(${CMAKE_CURRENT_LIST_DIR}/freertos/dispatcher/dispatcher.cmake) @@ -11,6 +11,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL XCORE_XS3A) include(${CMAKE_CURRENT_LIST_DIR}/freertos/iot/iot.cmake) include(${CMAKE_CURRENT_LIST_DIR}/freertos/l2_cache/l2_cache.cmake) include(${CMAKE_CURRENT_LIST_DIR}/freertos/usb/usb.cmake) + include(${CMAKE_CURRENT_LIST_DIR}/freertos/xlink/xlink.cmake) else() add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/freertos/device_control/host) endif() diff --git a/examples/freertos/xlink/README.rst b/examples/freertos/xlink/README.rst new file mode 100644 index 000000000..f4bff31ed --- /dev/null +++ b/examples/freertos/xlink/README.rst @@ -0,0 +1,90 @@ +############## +XLINK +############## + +This example application demonstrates various capabilities of the Explorer board using FreeRTOS. The application uses I2C, I2S, SPI, UART, flash, mic array, and GPIO devices. + +The FreeRTOS application creates a single stage audio pipeline which applies a variable gain. The output audio is sent to the DAC and can be listened to via the 3.5mm audio jack. The audio gain can be adjusted via GPIO, where button A is volume up and button B is volume down. + +********************** +Preparing the hardware +********************** + +The UART loopback section of the demo requires that a jumper cable be connected +between X1D36 and X1D39. This connects the Tx pin to the Rx pin. + +********************* +Building the firmware +********************* + +Run the following commands in the xcore_sdk root folder to build the firmware: + +.. tab:: Linux and Mac + + .. code-block:: console + + cmake -B build -DCMAKE_TOOLCHAIN_FILE=xmos_cmake_toolchain/xs3a.cmake + cd build + make example_freertos_xlink + +.. tab:: Windows + + .. code-block:: console + + cmake -G "NMake Makefiles" -B build -DCMAKE_TOOLCHAIN_FILE=xmos_cmake_toolchain/xs3a.cmake + cd build + nmake example_freertos_xlink + +.. note:: + The host applications are required to create the filesystem. See the SDK Installation instructions for more information. + +From the xcore_sdk build folder, create the filesystem and flash the device with the following command: + +.. tab:: Linux and Mac + + .. code-block:: console + + make flash_fs_example_freertos_xlink + +.. tab:: Windows + + .. code-block:: console + + nmake flash_fs_example_freertos_xlink + +******************** +Running the firmware +******************** + +From the xcore_sdk build folder run: + +.. tab:: Linux and Mac + + .. code-block:: console + + make run_example_freertos_xlink + +.. tab:: Windows + + .. code-block:: console + + nmake run_example_freertos_xlink + + +******************************** +Debugging the firmware with xgdb +******************************** + +From the xcore_sdk build folder run: + +.. tab:: Linux and Mac + + .. code-block:: console + + make debug_example_freertos_xlink + +.. tab:: Windows + + .. code-block:: console + + nmake debug_example_freertos_xlink diff --git a/examples/freertos/xlink/XCORE-AI-EXPLORER.xn b/examples/freertos/xlink/XCORE-AI-EXPLORER.xn new file mode 100644 index 000000000..a9ab7384b --- /dev/null +++ b/examples/freertos/xlink/XCORE-AI-EXPLORER.xn @@ -0,0 +1,108 @@ + + + Board + xcore.ai Explorer Kit + + + tileref tile[2] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/freertos/xlink/src/FreeRTOSConfig.h b/examples/freertos/xlink/src/FreeRTOSConfig.h new file mode 100644 index 000000000..931308e9a --- /dev/null +++ b/examples/freertos/xlink/src/FreeRTOSConfig.h @@ -0,0 +1,118 @@ +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/* Here is a good place to include header files that are required across +your application. */ +#include "platform.h" + +/* + * TODO remove this. Just a hack to prevent the i2s task from calling vTaskSuspendAll(). Not a good solution. + * the i2s task should probably not be using a FreeRTOS stream buffer. + */ +#define sbRECEIVE_COMPLETED( pxStreamBuffer ) + +#define configUSE_PREEMPTION 1 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#define configUSE_TICKLESS_IDLE 0 +#define configCPU_CLOCK_HZ 100000000 +#define configNUM_CORES 5 +#define configTICK_RATE_HZ 1000 +#define configMAX_PRIORITIES 32 +#define configRUN_MULTIPLE_PRIORITIES 1 +#define configUSE_TASK_PREEMPTION_DISABLE 1 +#define configUSE_CORE_AFFINITY 1 +#define configMINIMAL_STACK_SIZE ( configSTACK_DEPTH_TYPE ) 256 +#define configMAX_TASK_NAME_LEN 16 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_TASK_NOTIFICATIONS 1 +#define configTASK_NOTIFICATION_ARRAY_ENTRIES 2 +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */ +#define configQUEUE_REGISTRY_SIZE 10 +#define configUSE_QUEUE_SETS 1 +#define configUSE_TIME_SLICING 1 +#define configUSE_NEWLIB_REENTRANT 0 +#define configENABLE_BACKWARD_COMPATIBILITY 1 /* Required for FreeRTOS_TCP_WIN.c TODO: active closed bug, may have been fixed upstream */ +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5 +#define configSTACK_DEPTH_TYPE uint32_t +#define configMESSAGE_BUFFER_LENGTH_TYPE size_t + + +/* Memory allocation related definitions. */ +#define configSUPPORT_STATIC_ALLOCATION 0 +#define configSUPPORT_DYNAMIC_ALLOCATION 1 +#define configTOTAL_HEAP_SIZE 256*1024 +#define configAPPLICATION_ALLOCATED_HEAP 0 + +/* Hook function related definitions. */ +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCHECK_FOR_STACK_OVERFLOW 1 +#define configUSE_MALLOC_FAILED_HOOK 1 +#define configUSE_DAEMON_TASK_STARTUP_HOOK 0 +#define configUSE_CORE_INIT_HOOK 0 + +/* Run time and task stats gathering related definitions. */ +#define configGENERATE_RUN_TIME_STATS 1 +#define configUSE_TRACE_FACILITY 1 +#define configUSE_STATS_FORMATTING_FUNCTIONS 2 /* Setting to 2 does not include in tasks.c */ + +/* Co-routine related definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES 1 + +/* Software timer related definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define configTIMER_QUEUE_LENGTH 10 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE << 2 ) + +/* Define to trap errors during development. */ +#define configASSERT(x) xassert(x) + +/* Define to enable debug_printf() */ +#define configENABLE_DEBUG_PRINTF 1 + +/* Define to map sprintf and snprintf to the + * lite versions in lib_rtos_support */ + #include +#define configUSE_DEBUG_SPRINTF 1 + +/* Define to enable debug prints from tasks.c */ +#if ON_TILE(0) +#define configTASKS_DEBUG 0 +#endif +#if ON_TILE(1) +#define configTASKS_DEBUG 0 +#endif + +/* FreeRTOS MPU specific definitions. */ +#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0 + +/* Optional functions - most linkers will remove unused functions anyway. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_xResumeFromISR 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xEventGroupSetBitFromISR 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_xTaskAbortDelay 1 +#define INCLUDE_xTaskGetHandle 1 +#define INCLUDE_xTaskResumeFromISR 1 +#define INCLUDE_xQueueGetMutexHolder 1 + +/* A header file that defines trace macro can be included here. */ +// #include "xcore_trace.h" + +#endif /* FREERTOS_CONFIG_H */ diff --git a/examples/freertos/xlink/src/app_conf.h b/examples/freertos/xlink/src/app_conf.h new file mode 100644 index 000000000..3fa2b64e4 --- /dev/null +++ b/examples/freertos/xlink/src/app_conf.h @@ -0,0 +1,56 @@ +// Copyright 2021-2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef APP_CONF_H_ +#define APP_CONF_H_ + +/* Intertile Communication Configuration */ +#define appconfI2C_MASTER_RPC_PORT 10 +#define appconfI2C_MASTER_RPC_PRIORITY (configMAX_PRIORITIES/2) + +#define appconfGPIO_T0_RPC_PORT 11 +#define appconfGPIO_T1_RPC_PORT 12 +#define appconfGPIO_RPC_PRIORITY (configMAX_PRIORITIES/2) + +/* I/O and interrupt cores for Tile 0 */ +#define appconfI2C_IO_CORE 3 /* Must be kept off core 0 with the RTOS tick ISR */ +#define appconfI2C_INTERRUPT_CORE 0 /* Must be kept off I/O cores. */ + +/* I/O and interrupt cores for Tile 1 */ +#define appconfPDM_MIC_IO_CORE 1 /* Must be kept off I/O cores. Must be kept off core 0 with the RTOS tick ISR */ +#define appconfI2S_IO_CORE 2 /* Must be kept off core 0 with the RTOS tick ISR */ +#define appconfPDM_MIC_INTERRUPT_CORE 3 /* Must be kept off I/O cores. Best kept off core 0 with the tick ISR. */ +#define appconfI2S_INTERRUPT_CORE 4 /* Must be kept off I/O cores. Best kept off core 0 with the tick ISR. */ + +/* Audio Pipeline Configuration */ +#define appconfAUDIO_CLOCK_FREQUENCY MIC_ARRAY_CONFIG_MCLK_FREQ +#define appconfPDM_CLOCK_FREQUENCY MIC_ARRAY_CONFIG_PDM_FREQ +#define appconfPIPELINE_AUDIO_SAMPLE_RATE 16000 +#define appconfAUDIO_PIPELINE_STAGE_ZERO_GAIN 20 +#define appconfAUDIO_PIPELINE_MAX_GAIN 60 +#define appconfAUDIO_PIPELINE_MIN_GAIN 0 +#define appconfAUDIO_PIPELINE_GAIN_STEP 4 +#define appconfAUDIO_FRAME_LENGTH MIC_ARRAY_CONFIG_SAMPLES_PER_FRAME +#define appconfMIC_COUNT MIC_ARRAY_CONFIG_MIC_COUNT +#define appconfPRINT_AUDIO_FRAME_POWER 0 +#define appconfFRAMES_IN_ALL_CHANS (appconfAUDIO_FRAME_LENGTH * appconfMIC_COUNT) +#define appconfPOWER_THRESHOLD (float)0.00001 +#define appconfEXP -31 + +/* UART Configuration */ +#define appconfUART_BAUD_RATE 806400 + +/* GPIO Configuration */ +#define appconfGPIO_VOLUME_RAPID_FIRE_MS 100 + +/* Task Priorities */ +#define appconfSTARTUP_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define appconfAUDIO_PIPELINE_TASK_PRIORITY ( configMAX_PRIORITIES - 4 ) +#define appconfGPIO_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) +#define appconfFILESYSTEM_DEMO_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) +#define appconfMEM_ANALYSIS_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define appconfSPI_MASTER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define appconfQSPI_FLASH_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define appconfUART_RX_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) + +#endif /* APP_CONF_H_ */ diff --git a/examples/freertos/xlink/src/config.xscope b/examples/freertos/xlink/src/config.xscope new file mode 100644 index 000000000..bb71bfe23 --- /dev/null +++ b/examples/freertos/xlink/src/config.xscope @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/freertos/xlink/src/main.c b/examples/freertos/xlink/src/main.c new file mode 100644 index 000000000..cb2dd7c14 --- /dev/null +++ b/examples/freertos/xlink/src/main.c @@ -0,0 +1,591 @@ +// Copyright 2019-2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +/* System headers */ +#include +#include + +#include +#include +#include +#include + +#include + +/* FreeRTOS headers */ +#include "FreeRTOS.h" +#include "queue.h" + +/* Library headers */ + +/* App headers */ +#include "app_conf.h" +#include "platform/platform_init.h" +#include "platform/driver_instances.h" + +#ifndef LIBXCORE_HWTIMER_HAS_REFERENCE_TIME +#error This library requires reference time +#endif + +// todo verify 1 == 5wire +#define W 0 + +#define RX_TIME_OUT_TICKS 500000000 + +// tx +#define RE_ENABLE_TX_PERIOD 6 +#define SEND_CTRL_TOKEN 2500000 + +unsigned g_comm_state = 0; +/* + +tile 1 +xlink2_rx4 IOR X1D61 +xlink2_rx3 IOR X1D62 +xlink2_rx2 IOR X1D63 + +xlink2_rx1 IOR X1D64 +xlink2_rx0 IOR X1D65 +xlink2_tx0 IOR X1D66 +xlink2_tx1 IOR X1D67 + +xlink2_tx2 IOR X1D68 +xlink2_tx3 IOR X1D69 +xlink2_tx4 IOR X1D70 + +*/ + + +/* node is sswitch */ +/* tile config is pswitch??? possibly */ + +static const char plink_type_str[4][16] = { + "channel end", "error", "psctl", "idle" +}; + +static const char slink_type_str[3][16] = { + "plink", "external link", "control link" +}; + +void print_chanend_status(unsigned t, int chan_num) +{ + // unsigned x; + // int l = XS1_PSWITCH_LLINK_0_NUM + chan_num; + // (void) read_pswitch_reg(t, l, &x); + // rtos_printf("chanend %d: 0x%X\n", chan_num, x); + // rtos_printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); + // rtos_printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); + // rtos_printf("junk %d\n", XS1_LINK_JUNK(x)); + // rtos_printf("network %d\n", XS1_LINK_NETWORK(x)); + // rtos_printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); + // rtos_printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), plink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); +} + +void print_plink_pswitch_status(unsigned t, int plink_num) +{ + // unsigned x; + // int l = XS1_SSWITCH_PLINK_0_NUM + plink_num; + // (void) read_pswitch_reg(t, l, &x); + // rtos_printf("plink %d (pswitch): 0x%X\n", plink_num, x); + // rtos_printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); + // rtos_printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); + // rtos_printf("junk %d\n", XS1_LINK_JUNK(x)); + // rtos_printf("network %d\n", XS1_LINK_NETWORK(x)); + // rtos_printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); + // rtos_printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), plink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); +} + +void print_plink_sswitch_status(unsigned t, int plink_num) +{ + // unsigned x; + // int l = XS1_SSWITCH_PLINK_0_NUM + plink_num; + // (void) read_sswitch_reg(t, l, &x); + // rtos_printf("plink %d (sswitch): 0x%X\n", plink_num, x); + // rtos_printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); + // rtos_printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); + // rtos_printf("junk %d\n", XS1_LINK_JUNK(x)); + // rtos_printf("network %d\n", XS1_LINK_NETWORK(x)); + // rtos_printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); + // rtos_printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), slink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); +} + +void print_slink_status(unsigned t, int link_num) +{ + // unsigned x; + // int l = XS1_NUM_SSWITCH_SLINK + link_num; + // (void) read_sswitch_reg(t, l, &x); + // rtos_printf("slink %d: 0x%X\n", link_num, x); + // rtos_printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); + // rtos_printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); + // rtos_printf("junk %d\n", XS1_LINK_JUNK(x)); + // rtos_printf("network %d\n", XS1_LINK_NETWORK(x)); + // rtos_printf("direction %d\n", XS1_LINK_DIRECTION(x)); + // rtos_printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); + // rtos_printf("src_target_type %d\n", XS1_LINK_SRC_TARGET_TYPE(x), slink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); +} + + +#define INTER_DELAY 2 +#define INTRA_DELAY 3 + +void link_disable(unsigned link_num); +void link_enable(unsigned link_num); +void link_reset(unsigned link_num); +void link_hello(unsigned link_num); +unsigned link_got_credit(unsigned link_num); + +/* Disable link by resetting ENABLE bit in link's control register */ +void link_disable(unsigned link_num) { + unsigned x = 0; + (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, &x); + x &= ~XS1_XLINK_ENABLE_MASK; + (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, x); +} + +/* Configure link by performing the following in the link's control register + * - Set intertoken and intratoken delays + * - Set ENABLE bit + * - Set WIDE bit if 5-bit link required + */ +void link_enable(unsigned link_num) { + unsigned x = 0; + (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, &x); + x |= XS1_XLINK_INTRA_TOKEN_DELAY_SET(x, INTER_DELAY); + x |= XS1_XLINK_INTRA_TOKEN_DELAY_SET(x, INTRA_DELAY); + x |= XS1_XLINK_ENABLE_MASK; + x |= W * XS1_XLINK_WIDE_MASK; + (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, x); +} + +/* Reset link by setting RESET bit in link's control register */ +void link_reset(unsigned link_num) { + unsigned x = 0; + unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; + (void) read_sswitch_reg(get_local_tile_id(), l, &x); + x |= XS1_XLINK_RX_RESET_MASK; + (void) write_sswitch_reg(get_local_tile_id(), l, x); +} + +/* Send a HELLO by setting HELLO bit in link's control register */ +void link_hello(unsigned link_num) { + unsigned x = 0; + unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; + (void) read_sswitch_reg(get_local_tile_id(), l, &x); + x |= XS1_XLINK_HELLO_MASK; + (void) write_sswitch_reg(get_local_tile_id(), l, x); +} + +unsigned link_got_credit(unsigned link_num) { + unsigned x = 0; + unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; + (void) read_sswitch_reg(get_local_tile_id(), l, &x); + return XS1_TX_CREDIT(x); +} + + + +#define LINK_NUM 2 + +#if (DEMO_TILE == 0) +#define CHANEND_TILE_ID 0x80010002 +#else +#define CHANEND_TILE_ID 0x80030002 +#endif + +static int g_data_tokens = 0; +static int g_ctrl_tokens = 0; +static int g_timeout_cnts = 0; + + +void xlink_report_task(void) { + int full_rep_cnt = 0; + + while(1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + rtos_printf("Communication rate: %d bytes per sec \t\t\t ==>\t %d Mbit/sec\n", g_data_tokens, ((g_data_tokens*8)/1000000)); + if (!(full_rep_cnt++ % 10)) { + rtos_printf("\nApplication control token count: \t\t%d \n", g_ctrl_tokens); + rtos_printf("Receive timeouts: \t\t\t\t%d \n\n", g_timeout_cnts); + } + g_data_tokens = 0; + } +} + +void xlink_rx(void) { + unsigned comm_state = 0; + chanend_t c_tileid = 0; + unsigned tm_out_ctr = 0; + unsigned rx_loop = 0; + + uint32_t last_time = 0; + hwtimer_t tmr_rx = hwtimer_alloc(); + char rx = 'z'; + uint32_t id = 0; + int reg_val = 0; + int direction = 0x0; + + unsigned x = 0; + + rtos_printf("RX started...tile id: %x\n", get_local_tile_id()); + rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); + rtos_osal_thread_preemption_disable(NULL); + while(1) { + rtos_printf("rx state: %d\n", comm_state); + switch (comm_state) { + default: + break; + case 0: /* Setup link direction */ + reg_val = 0; + direction = 0x0; + reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); + (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); + comm_state = 1; + break; + case 1: /* Channel alloc */ + c_tileid = chanend_alloc(); + rtos_printf("Allocated chanend 0x%x\n", c_tileid); + // configASSERT(c_tileid == CHANEND_TILE_ID); + comm_state = 2; + break; + case 2: /* Reconfigure links, setting up a single static link */ + // for (int i=1; i<8; i++) { + // rtos_printf("%d\n", i); + // link_disable(i); + // } + rtos_printf("a\n"); + link_disable(LINK_NUM); + rtos_printf("b\n"); + link_enable(LINK_NUM); + rtos_printf("c\n"); + rtos_printf("c\n"); + id = 0x80030000; + + // x |= XS1_XSTATIC_ENABLE_SET(x, 1); + // x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, c_tileid); + + (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); + delay_milliseconds(150); + rtos_printf("d\n"); + comm_state = 3; + break; + case 3: /* Wait for transmit credits */ + do { + link_reset(LINK_NUM); + link_hello(LINK_NUM); + delay_milliseconds(100); + } while (!link_got_credit(LINK_NUM)); + rtos_printf("RX Got Credit\n"); + + /* Setup local control vars */ + rx_loop = 1; + tm_out_ctr++; + last_time = get_reference_time(); + comm_state = 4; + break; + case 4: /* Receive data loop */ + rx = 'z'; + + TRIGGERABLE_SETUP_EVENT_VECTOR(tmr_rx, timeout); + TRIGGERABLE_SETUP_EVENT_VECTOR(c_tileid, transaction); + + triggerable_disable_all(); + + uint32_t trigger_time = hwtimer_get_time(tmr_rx) + RX_TIME_OUT_TICKS; + hwtimer_set_trigger_time(tmr_rx, trigger_time); + triggerable_enable_trigger(tmr_rx); + triggerable_enable_trigger(c_tileid); + + while(rx_loop) { + TRIGGERABLE_WAIT_EVENT(timeout, transaction); + { + transaction: + { + if (chanend_test_control_token_next_byte(c_tileid)) { + rx = chanend_in_control_token(c_tileid); + g_ctrl_tokens++; + } else { + rx = chanend_in_byte(c_tileid); + g_data_tokens++; + } + triggerable_disable_trigger(tmr_rx); + hwtimer_clear_trigger_time(tmr_rx); + trigger_time = hwtimer_get_time(tmr_rx) + RX_TIME_OUT_TICKS; + hwtimer_set_trigger_time(tmr_rx, trigger_time); + triggerable_enable_trigger(tmr_rx); + continue; + } + timeout: + { + triggerable_disable_trigger(c_tileid); + triggerable_disable_trigger(tmr_rx); + rtos_printf("Timed out\n"); + rx_loop = 0; + comm_state = 3; + continue; + } + } + } + break; + case 6: /* End of Communication */ + chanend_free(c_tileid); + link_disable(LINK_NUM); + comm_state = 1; + break; + } + } +} + +void xlink_tx_reenable(void) { + while(1) { + vTaskDelay(pdMS_TO_TICKS(RE_ENABLE_TX_PERIOD * 1000)); + + print_slink_status(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + LINK_NUM); + print_slink_status(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + LINK_NUM); + g_comm_state = 1; + rtos_printf("Reenable tx link\n"); + link_disable(LINK_NUM); + link_enable(LINK_NUM); + } +} + +void transmit_handler(unsigned comm_state) { + chanend_t c_other_tile = 0; + unsigned err_ctr = 0; + int reg_val = 0; + int direction = 0x0; + int ret = 0; + uint32_t id = 0; + unsigned x = 0; + + rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); + rtos_osal_thread_preemption_disable(NULL); + while(1) { + rtos_printf("tx state: %d\n", comm_state); + if (g_comm_state) { + g_comm_state = 0; + comm_state = 4; + } + switch (comm_state) { + default: + comm_state = 4; + break; + case 0: /* Setup Link Direction */ + reg_val = 0; + direction = 0x1; // tx + reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); + (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); + comm_state = 1; + break; + case 1: /* Channel setup */ + c_other_tile = chanend_alloc(); + chanend_set_dest(c_other_tile, 0x80030002); // hardcode to expected rx + + // chanend_set_dest(c_other_tile, 0x80030702); // hardcode to expected rx + comm_state = 2; + break; + case 2: /* reconfigure links, leaving only one open */ + for (int i=1; i<8; i++) { + rtos_printf("%d\n", i); + link_disable(i); + } + rtos_printf("a\n"); + link_enable(LINK_NUM); + rtos_printf("b\n"); + comm_state = 3; + break; + case 3: /* Setup a static routing configuration */ + id = 0x80010000; + + (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, id); + delay_milliseconds(150); + comm_state = 4; + break; + case 4: /* Wait for transmit credits */ + rtos_printf("TX try to get Credit\n"); + do { + link_reset(LINK_NUM); + link_hello(LINK_NUM); + delay_milliseconds(100); + } while (!link_got_credit(LINK_NUM)); + rtos_printf("TX Got Credit\n"); + + /* Setup local control vars */ + err_ctr = 0; + comm_state = 5; + break; + case 5: /* Send data tokens */ + chanend_out_byte(c_other_tile, 'a'); + if (err_ctr++ == SEND_CTRL_TOKEN) { + err_ctr = 0; + chanend_out_control_token(c_other_tile, XS1_CT_ACK); + } + break; + case 6: + chanend_free(c_other_tile); + link_disable(LINK_NUM); + comm_state = 2; + break; + } + } +} + +#include "trycatch.h" + +void xlink_tx(void) { + exception_t exception; + + rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); + rtos_osal_thread_preemption_disable(NULL); + rtos_printf("TX started...tile id: %x\n", get_local_tile_id()); + while(1) { + TRY { + transmit_handler(0); + } CATCH (exception) { + rtos_printf("Got exception.\n"); + transmit_handler(4); + } + } +} + +void vApplicationMallocFailedHook( void ) +{ + rtos_printf("Malloc Failed on tile %d!\n", THIS_XCORE_TILE); + for(;;); +} + +void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) { + rtos_printf("\nStack Overflow!!! %d %s!\n", THIS_XCORE_TILE, pcTaskName); + configASSERT(0); +} + +#define debug_print_sswitch_reg(name) { \ + unsigned testval = 0; \ + (void) read_sswitch_reg(get_local_tile_id(), name, &testval); \ + rtos_printf("sswitch "#name": 0x%x\n", testval); \ +} + +#define debug_print_pswitch_reg(name) { \ + unsigned testval = 0; \ + (void) read_pswitch_reg(get_local_tile_id(), name, &testval); \ + rtos_printf("pswitch "#name": 0x%x\n", testval); \ +} + +#include + +void startup_task(void *arg) +{ + rtos_printf("Startup task running from tile %d on core %d\n", THIS_XCORE_TILE, portGET_CORE_ID()); + + // platform_start(); + +#if ON_TILE(0) + rtos_printf("\n\nDebug info:\n"); + rtos_printf("tile id: %x\n", get_local_tile_id()); + + debug_print_sswitch_reg(XS1_SSWITCH_NODE_ID_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_NODE_CONFIG_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID1_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID2_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID3_NUM); + + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_0_NUM); + + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_0_NUM); + + rtos_printf("\n"); + + debug_print_pswitch_reg(XS1_SSWITCH_NODE_ID_NUM); + debug_print_pswitch_reg(XS1_SSWITCH_NODE_CONFIG_NUM); + debug_print_pswitch_reg(XS1_SSWITCH_DEVICE_ID0_NUM); + debug_print_pswitch_reg(XS1_SSWITCH_DEVICE_ID1_NUM); + debug_print_pswitch_reg(XS1_SSWITCH_DEVICE_ID2_NUM); + debug_print_pswitch_reg(XS1_SSWITCH_DEVICE_ID3_NUM); + + debug_print_pswitch_reg(XS1_SSWITCH_SLINK_0_NUM); + debug_print_pswitch_reg(XS1_SSWITCH_PLINK_0_NUM); + debug_print_pswitch_reg(XS1_SSWITCH_XLINK_0_NUM); + debug_print_pswitch_reg(XS1_SSWITCH_XSTATIC_0_NUM); + + rtos_printf("\n\n"); + _Exit(0); +#endif + + +#if ON_TILE(1) +#if DEMO_TILE == 0 + xTaskCreate((TaskFunction_t) xlink_report_task, + "xlink_report_task", + RTOS_THREAD_STACK_SIZE(xlink_report_task), + NULL, + appconfSTARTUP_TASK_PRIORITY, + NULL); + + xTaskCreate((TaskFunction_t) xlink_rx, + "xlink_rx", + RTOS_THREAD_STACK_SIZE(xlink_rx), + NULL, + appconfSTARTUP_TASK_PRIORITY, + NULL); +#else + xTaskCreate((TaskFunction_t) xlink_tx_reenable, + "xlink_tx_reenable", + RTOS_THREAD_STACK_SIZE(xlink_tx_reenable), + NULL, + appconfSTARTUP_TASK_PRIORITY, + NULL); + + xTaskCreate((TaskFunction_t) xlink_tx, + "xlink_tx", + RTOS_THREAD_STACK_SIZE(xlink_tx), + NULL, + appconfSTARTUP_TASK_PRIORITY, + NULL); +#endif +#endif + + for (;;) { + // rtos_printf("Tile[%d]:\n\tMinimum heap free: %d\n\tCurrent heap free: %d\n", THIS_XCORE_TILE, xPortGetMinimumEverFreeHeapSize(), xPortGetFreeHeapSize()); + vTaskDelay(pdMS_TO_TICKS(5000)); + } +} + +static void tile_common_init(chanend_t c) +{ + // platform_init(c); + // chanend_free(c); + + xTaskCreate((TaskFunction_t) startup_task, + "startup_task", + RTOS_THREAD_STACK_SIZE(startup_task), + NULL, + appconfSTARTUP_TASK_PRIORITY, + NULL); + + rtos_printf("start scheduler on tile %d\n", THIS_XCORE_TILE); + vTaskStartScheduler(); +} + +#if ON_TILE(0) +void main_tile0(chanend_t c0, chanend_t c1, chanend_t c2, chanend_t c3) { + (void)c0; + (void)c2; + (void)c3; + + tile_common_init(c1); +} +#endif + +#if ON_TILE(1) +void main_tile1(chanend_t c0, chanend_t c1, chanend_t c2, chanend_t c3) { + (void)c1; + (void)c2; + (void)c3; + + tile_common_init(c0); +} +#endif diff --git a/examples/freertos/xlink/xlink.cmake b/examples/freertos/xlink/xlink.cmake new file mode 100644 index 000000000..fd3db4519 --- /dev/null +++ b/examples/freertos/xlink/xlink.cmake @@ -0,0 +1,108 @@ +#********************** +# Gather Sources +#********************** +file(GLOB_RECURSE APP_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.c) +set(APP_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/src) + +#********************** +# Flags +#********************** +set(APP_COMPILER_FLAGS + -Os + -g + -report + -fxscope + -lquadspi + -mcmodel=large + -Wno-xcore-fptrgroup + ${CMAKE_CURRENT_LIST_DIR}/src/config.xscope + ${CMAKE_CURRENT_LIST_DIR}/XCORE-AI-EXPLORER.xn +) +set(APP_COMPILE_DEFINITIONS + DEBUG_PRINT_ENABLE=1 + PLATFORM_USES_TILE_0=1 + PLATFORM_USES_TILE_1=1 + XE_BASE_TILE=0 + + XUD_CORE_CLOCK=600 +) + +set(APP_LINK_OPTIONS + -lquadspi + -report + ${CMAKE_CURRENT_LIST_DIR}/XCORE-AI-EXPLORER.xn + ${CMAKE_CURRENT_LIST_DIR}/src/config.xscope +) + +set(APP_LINK_LIBRARIES + rtos::bsp_config::xcore_ai_explorer +) + +#********************** +# Tile Targets +#********************** +set(TARGET_NAME tile0_example_freertos_xlink_0) +add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL) +target_sources(${TARGET_NAME} PUBLIC ${APP_SOURCES}) +target_include_directories(${TARGET_NAME} PUBLIC ${APP_INCLUDES}) +target_compile_definitions(${TARGET_NAME} PUBLIC ${APP_COMPILE_DEFINITIONS} DEMO_TILE=0 THIS_XCORE_TILE=0) +target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS}) +target_link_libraries(${TARGET_NAME} PUBLIC ${APP_LINK_LIBRARIES}) +target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS}) +unset(TARGET_NAME) + +set(TARGET_NAME tile1_example_freertos_xlink_0) +add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL) +target_sources(${TARGET_NAME} PUBLIC ${APP_SOURCES}) +target_include_directories(${TARGET_NAME} PUBLIC ${APP_INCLUDES}) +target_compile_definitions(${TARGET_NAME} PUBLIC ${APP_COMPILE_DEFINITIONS} DEMO_TILE=0 THIS_XCORE_TILE=1) +target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS}) +target_link_libraries(${TARGET_NAME} PUBLIC ${APP_LINK_LIBRARIES}) +target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS}) +unset(TARGET_NAME) + +#********************** +# Merge binaries +#********************** +merge_binaries(example_freertos_xlink_0 tile0_example_freertos_xlink_0 tile1_example_freertos_xlink_0 1) + +#********************** +# Create run and debug targets +#********************** +create_run_target(example_freertos_xlink_0) +create_debug_target(example_freertos_xlink_0) + + +#********************** +# Tile Targets +#********************** +set(TARGET_NAME tile0_example_freertos_xlink_1) +add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL) +target_sources(${TARGET_NAME} PUBLIC ${APP_SOURCES}) +target_include_directories(${TARGET_NAME} PUBLIC ${APP_INCLUDES}) +target_compile_definitions(${TARGET_NAME} PUBLIC ${APP_COMPILE_DEFINITIONS} DEMO_TILE=1 THIS_XCORE_TILE=0) +target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS}) +target_link_libraries(${TARGET_NAME} PUBLIC ${APP_LINK_LIBRARIES}) +target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS}) +unset(TARGET_NAME) + +set(TARGET_NAME tile1_example_freertos_xlink_1) +add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL) +target_sources(${TARGET_NAME} PUBLIC ${APP_SOURCES}) +target_include_directories(${TARGET_NAME} PUBLIC ${APP_INCLUDES}) +target_compile_definitions(${TARGET_NAME} PUBLIC ${APP_COMPILE_DEFINITIONS} DEMO_TILE=1 THIS_XCORE_TILE=1) +target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS}) +target_link_libraries(${TARGET_NAME} PUBLIC ${APP_LINK_LIBRARIES}) +target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS}) +unset(TARGET_NAME) + +#********************** +# Merge binaries +#********************** +merge_binaries(example_freertos_xlink_1 tile0_example_freertos_xlink_1 tile1_example_freertos_xlink_1 1) + +#********************** +# Create run and debug targets +#********************** +create_run_target(example_freertos_xlink_1) +create_debug_target(example_freertos_xlink_1) From f5565783de813ac7545d6f9849c2a61a778a5ba6 Mon Sep 17 00:00:00 2001 From: xmos-jmccarthy Date: Tue, 6 Sep 2022 15:15:28 -0400 Subject: [PATCH 2/8] Update submodule for lib_trycatch --- modules/core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core b/modules/core index ca3119103..8f6f9192a 160000 --- a/modules/core +++ b/modules/core @@ -1 +1 @@ -Subproject commit ca3119103bbbaacc6178b8a6c3ff30d3217928ca +Subproject commit 8f6f9192a15af3d5d63ceff0355145a01fc35d4a From fa56c03097e8e991b20dbe06868ffacef6fef5ae Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Fri, 9 Sep 2022 11:59:59 -0400 Subject: [PATCH 3/8] Add some debug --- examples/freertos/xlink/src/main.c | 337 ++++++++++++++++++---------- examples/freertos/xlink/xlink.cmake | 13 ++ 2 files changed, 234 insertions(+), 116 deletions(-) diff --git a/examples/freertos/xlink/src/main.c b/examples/freertos/xlink/src/main.c index cb2dd7c14..4fa2f6aed 100644 --- a/examples/freertos/xlink/src/main.c +++ b/examples/freertos/xlink/src/main.c @@ -37,6 +37,47 @@ #define SEND_CTRL_TOKEN 2500000 unsigned g_comm_state = 0; + +#define RX_DIRECTION 2 +#define TX_DIRECTION 5 + + +#define debug_print_sswitch_reg(name) { \ + unsigned testval = 0; \ + (void) read_sswitch_reg(get_local_tile_id(), name, &testval); \ + printf("tile 0x%x:sswitch 0x%x "#name": 0x%x\n", get_local_tile_id(), name, testval); \ +} + +#define debug_print_pswitch_reg(name) { \ + unsigned testval = 0; \ + (void) read_pswitch_reg(get_local_tile_id(), name, &testval); \ + printf("pswitch "#name": 0x%x\n", testval); \ +} + +#include + +#define debug_xlinks() { \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_0_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_1_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_2_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_3_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_4_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_5_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_6_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_7_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_8_NUM); \ + \ + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_0_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_1_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_2_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_3_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_4_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_5_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_6_NUM); \ + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_7_NUM); \ +} +// XS1_RES_TYPE_CHANEND + /* tile 1 @@ -56,9 +97,6 @@ xlink2_tx4 IOR X1D70 */ -/* node is sswitch */ -/* tile config is pswitch??? possibly */ - static const char plink_type_str[4][16] = { "channel end", "error", "psctl", "idle" }; @@ -72,13 +110,13 @@ void print_chanend_status(unsigned t, int chan_num) // unsigned x; // int l = XS1_PSWITCH_LLINK_0_NUM + chan_num; // (void) read_pswitch_reg(t, l, &x); - // rtos_printf("chanend %d: 0x%X\n", chan_num, x); - // rtos_printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); - // rtos_printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); - // rtos_printf("junk %d\n", XS1_LINK_JUNK(x)); - // rtos_printf("network %d\n", XS1_LINK_NETWORK(x)); - // rtos_printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); - // rtos_printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), plink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); + // printf("chanend %d: 0x%X\n", chan_num, x); + // printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); + // printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); + // printf("junk %d\n", XS1_LINK_JUNK(x)); + // printf("network %d\n", XS1_LINK_NETWORK(x)); + // printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); + // printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), plink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); } void print_plink_pswitch_status(unsigned t, int plink_num) @@ -86,13 +124,13 @@ void print_plink_pswitch_status(unsigned t, int plink_num) // unsigned x; // int l = XS1_SSWITCH_PLINK_0_NUM + plink_num; // (void) read_pswitch_reg(t, l, &x); - // rtos_printf("plink %d (pswitch): 0x%X\n", plink_num, x); - // rtos_printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); - // rtos_printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); - // rtos_printf("junk %d\n", XS1_LINK_JUNK(x)); - // rtos_printf("network %d\n", XS1_LINK_NETWORK(x)); - // rtos_printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); - // rtos_printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), plink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); + // printf("plink %d (pswitch): 0x%X\n", plink_num, x); + // printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); + // printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); + // printf("junk %d\n", XS1_LINK_JUNK(x)); + // printf("network %d\n", XS1_LINK_NETWORK(x)); + // printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); + // printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), plink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); } void print_plink_sswitch_status(unsigned t, int plink_num) @@ -100,13 +138,13 @@ void print_plink_sswitch_status(unsigned t, int plink_num) // unsigned x; // int l = XS1_SSWITCH_PLINK_0_NUM + plink_num; // (void) read_sswitch_reg(t, l, &x); - // rtos_printf("plink %d (sswitch): 0x%X\n", plink_num, x); - // rtos_printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); - // rtos_printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); - // rtos_printf("junk %d\n", XS1_LINK_JUNK(x)); - // rtos_printf("network %d\n", XS1_LINK_NETWORK(x)); - // rtos_printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); - // rtos_printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), slink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); + // printf("plink %d (sswitch): 0x%X\n", plink_num, x); + // printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); + // printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); + // printf("junk %d\n", XS1_LINK_JUNK(x)); + // printf("network %d\n", XS1_LINK_NETWORK(x)); + // printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); + // printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), slink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); } void print_slink_status(unsigned t, int link_num) @@ -114,14 +152,14 @@ void print_slink_status(unsigned t, int link_num) // unsigned x; // int l = XS1_NUM_SSWITCH_SLINK + link_num; // (void) read_sswitch_reg(t, l, &x); - // rtos_printf("slink %d: 0x%X\n", link_num, x); - // rtos_printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); - // rtos_printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); - // rtos_printf("junk %d\n", XS1_LINK_JUNK(x)); - // rtos_printf("network %d\n", XS1_LINK_NETWORK(x)); - // rtos_printf("direction %d\n", XS1_LINK_DIRECTION(x)); - // rtos_printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); - // rtos_printf("src_target_type %d\n", XS1_LINK_SRC_TARGET_TYPE(x), slink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); + // printf("slink %d: 0x%X\n", link_num, x); + // printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); + // printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); + // printf("junk %d\n", XS1_LINK_JUNK(x)); + // printf("network %d\n", XS1_LINK_NETWORK(x)); + // printf("direction %d\n", XS1_LINK_DIRECTION(x)); + // printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); + // printf("src_target_type %d\n", XS1_LINK_SRC_TARGET_TYPE(x), slink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); } @@ -150,7 +188,7 @@ void link_disable(unsigned link_num) { void link_enable(unsigned link_num) { unsigned x = 0; (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, &x); - x |= XS1_XLINK_INTRA_TOKEN_DELAY_SET(x, INTER_DELAY); + x |= XS1_XLINK_INTER_TOKEN_DELAY_SET(x, INTER_DELAY); x |= XS1_XLINK_INTRA_TOKEN_DELAY_SET(x, INTRA_DELAY); x |= XS1_XLINK_ENABLE_MASK; x |= W * XS1_XLINK_WIDE_MASK; @@ -202,10 +240,10 @@ void xlink_report_task(void) { while(1) { vTaskDelay(pdMS_TO_TICKS(1000)); - rtos_printf("Communication rate: %d bytes per sec \t\t\t ==>\t %d Mbit/sec\n", g_data_tokens, ((g_data_tokens*8)/1000000)); + printf("Communication rate: %d bytes per sec \t\t\t ==>\t %d Mbit/sec\n", g_data_tokens, ((g_data_tokens*8)/1000000)); if (!(full_rep_cnt++ % 10)) { - rtos_printf("\nApplication control token count: \t\t%d \n", g_ctrl_tokens); - rtos_printf("Receive timeouts: \t\t\t\t%d \n\n", g_timeout_cnts); + printf("\nApplication control token count: \t\t%d \n", g_ctrl_tokens); + printf("Receive timeouts: \t\t\t\t%d \n\n", g_timeout_cnts); } g_data_tokens = 0; } @@ -226,55 +264,77 @@ void xlink_rx(void) { unsigned x = 0; - rtos_printf("RX started...tile id: %x\n", get_local_tile_id()); + printf("RX started...tile id: %x\n", get_local_tile_id()); rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); rtos_osal_thread_preemption_disable(NULL); + + read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, &x); + printf("node is 0x%x\n", x); + // x = XS1_SS_NODE_ID_ID_SET(x, 0x20); + // printf("set node to 0x%x\n", x); + // write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, x); + + debug_print_sswitch_reg(XS1_SSWITCH_NODE_ID_NUM); + while(1) { - rtos_printf("rx state: %d\n", comm_state); + // printf("rx state: %d\n", comm_state); switch (comm_state) { default: break; case 0: /* Setup link direction */ reg_val = 0; - direction = 0x0; + direction = RX_DIRECTION; reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); comm_state = 1; break; case 1: /* Channel alloc */ c_tileid = chanend_alloc(); - rtos_printf("Allocated chanend 0x%x\n", c_tileid); + printf("Allocated chanend 0x%x\n", c_tileid); + // configASSERT(c_tileid == CHANEND_TILE_ID); comm_state = 2; break; case 2: /* Reconfigure links, setting up a single static link */ // for (int i=1; i<8; i++) { - // rtos_printf("%d\n", i); + // printf("%d\n", i); // link_disable(i); // } - rtos_printf("a\n"); + // printf("a\n"); link_disable(LINK_NUM); - rtos_printf("b\n"); + // printf("b\n"); link_enable(LINK_NUM); - rtos_printf("c\n"); - rtos_printf("c\n"); - id = 0x80030000; + delay_milliseconds(100); + // printf("c\n"); + // printf("c\n"); + // id = 0x80030000; - // x |= XS1_XSTATIC_ENABLE_SET(x, 1); - // x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, c_tileid); + x = 0; + x |= XS1_XSTATIC_ENABLE_SET(x, 1); + x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, (c_tileid >> 8) & 0x0000001F); + x |= XS1_XSTATIC_DEST_PROC_SET(x, 1); (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); - delay_milliseconds(150); - rtos_printf("d\n"); + // delay_milliseconds(150); + // printf("d\n"); + + + debug_xlinks(); + + // (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, &x); + + // printf("d\n"); + // printf("static link reg is 0x%x\n", x); comm_state = 3; break; case 3: /* Wait for transmit credits */ + // printf("RX try to get Credit\n"); do { link_reset(LINK_NUM); link_hello(LINK_NUM); delay_milliseconds(100); } while (!link_got_credit(LINK_NUM)); - rtos_printf("RX Got Credit\n"); + printf("RX Got Credit\n"); /* Setup local control vars */ rx_loop = 1; @@ -318,7 +378,7 @@ void xlink_rx(void) { { triggerable_disable_trigger(c_tileid); triggerable_disable_trigger(tmr_rx); - rtos_printf("Timed out\n"); + printf("Timed out\n"); rx_loop = 0; comm_state = 3; continue; @@ -338,11 +398,8 @@ void xlink_rx(void) { void xlink_tx_reenable(void) { while(1) { vTaskDelay(pdMS_TO_TICKS(RE_ENABLE_TX_PERIOD * 1000)); - - print_slink_status(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + LINK_NUM); - print_slink_status(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + LINK_NUM); g_comm_state = 1; - rtos_printf("Reenable tx link\n"); + printf("Reenable tx link\n"); link_disable(LINK_NUM); link_enable(LINK_NUM); } @@ -359,8 +416,15 @@ void transmit_handler(unsigned comm_state) { rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); rtos_osal_thread_preemption_disable(NULL); + + read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, &x); + printf("node is 0x%x\n", x); + x = XS1_SS_NODE_ID_ID_SET(x, 0x4002); + printf("set node to 0x%x\n", x); + write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, x); + while(1) { - rtos_printf("tx state: %d\n", comm_state); + // printf("tx state: %d\n", comm_state); if (g_comm_state) { g_comm_state = 0; comm_state = 4; @@ -371,43 +435,63 @@ void transmit_handler(unsigned comm_state) { break; case 0: /* Setup Link Direction */ reg_val = 0; - direction = 0x1; // tx + direction = TX_DIRECTION; reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); comm_state = 1; break; case 1: /* Channel setup */ c_other_tile = chanend_alloc(); - chanend_set_dest(c_other_tile, 0x80030002); // hardcode to expected rx + chanend_set_dest(c_other_tile, 0x80020702); // hardcode to expected rx - // chanend_set_dest(c_other_tile, 0x80030702); // hardcode to expected rx + (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, &x); + x = XS1_DIME_DIR_SET(x, TX_DIRECTION); + (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, x); + + // chanend_set_dest(c_other_tile, 0x80050702); // hardcode to expected rx comm_state = 2; break; case 2: /* reconfigure links, leaving only one open */ - for (int i=1; i<8; i++) { - rtos_printf("%d\n", i); + for (int i=0; i<8; i++) { + // printf("%d\n", i); link_disable(i); } - rtos_printf("a\n"); + // printf("a\n"); link_enable(LINK_NUM); - rtos_printf("b\n"); + // printf("b\n"); comm_state = 3; break; case 3: /* Setup a static routing configuration */ - id = 0x80010000; - - (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, id); + x = 0x80000000; + + // x = 0; + x |= XS1_XSTATIC_ENABLE_SET(x, 1); + // x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, 0); + x |= XS1_XSTATIC_DEST_PROC_SET(x, 1); + // printf("chanid is 0x%x\n", (c_other_tile >> 8) & 0x0000001F); + x = write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); + // printf("ret was 0x%x\n", x); delay_milliseconds(150); + + // printf("read ret was 0x%x\n", read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, &x)); + + // printf("d\n"); + // printf("static link reg is 0x%x\n", x); + + debug_xlinks(); + debug_print_sswitch_reg(XS1_SSWITCH_DIMENSION_DIRECTION0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_DIMENSION_DIRECTION1_NUM); + comm_state = 4; break; case 4: /* Wait for transmit credits */ - rtos_printf("TX try to get Credit\n"); + // printf("TX try to get Credit\n"); do { link_reset(LINK_NUM); link_hello(LINK_NUM); delay_milliseconds(100); } while (!link_got_credit(LINK_NUM)); - rtos_printf("TX Got Credit\n"); + printf("TX Got Credit\n"); /* Setup local control vars */ err_ctr = 0; @@ -415,6 +499,7 @@ void transmit_handler(unsigned comm_state) { break; case 5: /* Send data tokens */ chanend_out_byte(c_other_tile, 'a'); + printf("sent\n"); if (err_ctr++ == SEND_CTRL_TOKEN) { err_ctr = 0; chanend_out_control_token(c_other_tile, XS1_CT_ACK); @@ -436,12 +521,12 @@ void xlink_tx(void) { rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); rtos_osal_thread_preemption_disable(NULL); - rtos_printf("TX started...tile id: %x\n", get_local_tile_id()); + printf("TX started...tile id: %x\n", get_local_tile_id()); while(1) { TRY { transmit_handler(0); } CATCH (exception) { - rtos_printf("Got exception.\n"); + printf("Got exception.\n"); transmit_handler(4); } } @@ -449,72 +534,82 @@ void xlink_tx(void) { void vApplicationMallocFailedHook( void ) { - rtos_printf("Malloc Failed on tile %d!\n", THIS_XCORE_TILE); + printf("Malloc Failed on tile %d!\n", THIS_XCORE_TILE); for(;;); } void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) { - rtos_printf("\nStack Overflow!!! %d %s!\n", THIS_XCORE_TILE, pcTaskName); + printf("\nStack Overflow!!! %d %s!\n", THIS_XCORE_TILE, pcTaskName); configASSERT(0); } -#define debug_print_sswitch_reg(name) { \ - unsigned testval = 0; \ - (void) read_sswitch_reg(get_local_tile_id(), name, &testval); \ - rtos_printf("sswitch "#name": 0x%x\n", testval); \ -} - -#define debug_print_pswitch_reg(name) { \ - unsigned testval = 0; \ - (void) read_pswitch_reg(get_local_tile_id(), name, &testval); \ - rtos_printf("pswitch "#name": 0x%x\n", testval); \ -} - -#include - void startup_task(void *arg) { - rtos_printf("Startup task running from tile %d on core %d\n", THIS_XCORE_TILE, portGET_CORE_ID()); + printf("Startup task running from tile %d on core %d\n", THIS_XCORE_TILE, portGET_CORE_ID()); // platform_start(); -#if ON_TILE(0) - rtos_printf("\n\nDebug info:\n"); - rtos_printf("tile id: %x\n", get_local_tile_id()); +#if 1 +#if ON_TILE(1) + vTaskDelay(pdMS_TO_TICKS(500)); +#endif + printf("\n\nDebug info:\n"); + printf("tile id: %x\n", get_local_tile_id()); debug_print_sswitch_reg(XS1_SSWITCH_NODE_ID_NUM); debug_print_sswitch_reg(XS1_SSWITCH_NODE_CONFIG_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID1_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID2_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID3_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_DIMENSION_DIRECTION0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_DIMENSION_DIRECTION1_NUM); + // debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID0_NUM); + // debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID1_NUM); + // debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID2_NUM); + // debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID3_NUM); debug_print_sswitch_reg(XS1_SSWITCH_SLINK_0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_1_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_2_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_3_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_4_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_5_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_6_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_7_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_SLINK_8_NUM); debug_print_sswitch_reg(XS1_SSWITCH_PLINK_0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_1_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_2_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_3_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_4_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_5_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_6_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_PLINK_7_NUM); - rtos_printf("\n"); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_1_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_2_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_3_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_4_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_5_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_6_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_7_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XLINK_8_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_NODE_ID_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_NODE_CONFIG_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_DEVICE_ID0_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_DEVICE_ID1_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_DEVICE_ID2_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_DEVICE_ID3_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_0_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_1_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_2_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_3_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_4_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_5_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_6_NUM); + debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_7_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_SLINK_0_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_PLINK_0_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_XLINK_0_NUM); - debug_print_pswitch_reg(XS1_SSWITCH_XSTATIC_0_NUM); + printf("\n"); - rtos_printf("\n\n"); - _Exit(0); +#if ON_TILE(1) + // _Exit(0); +#endif + vTaskDelay(pdMS_TO_TICKS(500)); #endif - #if ON_TILE(1) #if DEMO_TILE == 0 @@ -548,9 +643,19 @@ void startup_task(void *arg) #endif #endif + +#if ON_TILE(0) +port_t leds = XS1_PORT_4C; +int led_status=0; +port_enable(leds); +#endif for (;;) { - // rtos_printf("Tile[%d]:\n\tMinimum heap free: %d\n\tCurrent heap free: %d\n", THIS_XCORE_TILE, xPortGetMinimumEverFreeHeapSize(), xPortGetFreeHeapSize()); - vTaskDelay(pdMS_TO_TICKS(5000)); +#if ON_TILE(0) + port_out(leds, led_status); + led_status ^= 1; +#endif + // printf("Tile[%d]:\n\tMinimum heap free: %d\n\tCurrent heap free: %d\n", THIS_XCORE_TILE, xPortGetMinimumEverFreeHeapSize(), xPortGetFreeHeapSize()); + vTaskDelay(pdMS_TO_TICKS(1000)); } } @@ -566,7 +671,7 @@ static void tile_common_init(chanend_t c) appconfSTARTUP_TASK_PRIORITY, NULL); - rtos_printf("start scheduler on tile %d\n", THIS_XCORE_TILE); + printf("start scheduler on tile %d\n", THIS_XCORE_TILE); vTaskStartScheduler(); } diff --git a/examples/freertos/xlink/xlink.cmake b/examples/freertos/xlink/xlink.cmake index fd3db4519..658a8cee6 100644 --- a/examples/freertos/xlink/xlink.cmake +++ b/examples/freertos/xlink/xlink.cmake @@ -106,3 +106,16 @@ merge_binaries(example_freertos_xlink_1 tile0_example_freertos_xlink_1 tile1_exa #********************** create_run_target(example_freertos_xlink_1) create_debug_target(example_freertos_xlink_1) + +#********************** +# Create custom target to build both example applications +#********************** +add_custom_target(example_freertos_xlink_both + COMMAND + DEPENDS + example_freertos_xlink_0 + example_freertos_xlink_1 + COMMENT + "Create both xlink example applications" + VERBATIM +) \ No newline at end of file From b90afe73bcb7ac67eba73dbbcab6ce2c4bc4f3c7 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Mon, 12 Sep 2022 15:46:37 -0400 Subject: [PATCH 4/8] Functional xlink example --- examples/freertos/xlink/src/main.c | 336 +++++++++-------------------- 1 file changed, 106 insertions(+), 230 deletions(-) diff --git a/examples/freertos/xlink/src/main.c b/examples/freertos/xlink/src/main.c index 4fa2f6aed..79591fdc4 100644 --- a/examples/freertos/xlink/src/main.c +++ b/examples/freertos/xlink/src/main.c @@ -23,9 +23,6 @@ #include "platform/platform_init.h" #include "platform/driver_instances.h" -#ifndef LIBXCORE_HWTIMER_HAS_REFERENCE_TIME -#error This library requires reference time -#endif // todo verify 1 == 5wire #define W 0 @@ -38,45 +35,13 @@ unsigned g_comm_state = 0; -#define RX_DIRECTION 2 +#define RX_DIRECTION 0 #define TX_DIRECTION 5 -#define debug_print_sswitch_reg(name) { \ - unsigned testval = 0; \ - (void) read_sswitch_reg(get_local_tile_id(), name, &testval); \ - printf("tile 0x%x:sswitch 0x%x "#name": 0x%x\n", get_local_tile_id(), name, testval); \ -} - -#define debug_print_pswitch_reg(name) { \ - unsigned testval = 0; \ - (void) read_pswitch_reg(get_local_tile_id(), name, &testval); \ - printf("pswitch "#name": 0x%x\n", testval); \ -} #include -#define debug_xlinks() { \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_0_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_1_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_2_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_3_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_4_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_5_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_6_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_7_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_8_NUM); \ - \ - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_0_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_1_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_2_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_3_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_4_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_5_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_6_NUM); \ - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_7_NUM); \ -} -// XS1_RES_TYPE_CHANEND /* @@ -97,87 +62,21 @@ xlink2_tx4 IOR X1D70 */ -static const char plink_type_str[4][16] = { - "channel end", "error", "psctl", "idle" -}; - -static const char slink_type_str[3][16] = { - "plink", "external link", "control link" -}; - -void print_chanend_status(unsigned t, int chan_num) -{ - // unsigned x; - // int l = XS1_PSWITCH_LLINK_0_NUM + chan_num; - // (void) read_pswitch_reg(t, l, &x); - // printf("chanend %d: 0x%X\n", chan_num, x); - // printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); - // printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); - // printf("junk %d\n", XS1_LINK_JUNK(x)); - // printf("network %d\n", XS1_LINK_NETWORK(x)); - // printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); - // printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), plink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); -} - -void print_plink_pswitch_status(unsigned t, int plink_num) -{ - // unsigned x; - // int l = XS1_SSWITCH_PLINK_0_NUM + plink_num; - // (void) read_pswitch_reg(t, l, &x); - // printf("plink %d (pswitch): 0x%X\n", plink_num, x); - // printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); - // printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); - // printf("junk %d\n", XS1_LINK_JUNK(x)); - // printf("network %d\n", XS1_LINK_NETWORK(x)); - // printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); - // printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), plink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); -} - -void print_plink_sswitch_status(unsigned t, int plink_num) -{ - // unsigned x; - // int l = XS1_SSWITCH_PLINK_0_NUM + plink_num; - // (void) read_sswitch_reg(t, l, &x); - // printf("plink %d (sswitch): 0x%X\n", plink_num, x); - // printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); - // printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); - // printf("junk %d\n", XS1_LINK_JUNK(x)); - // printf("network %d\n", XS1_LINK_NETWORK(x)); - // printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); - // printf("src_target_type %d (%s)\n", XS1_LINK_SRC_TARGET_TYPE(x), slink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); -} - -void print_slink_status(unsigned t, int link_num) -{ - // unsigned x; - // int l = XS1_NUM_SSWITCH_SLINK + link_num; - // (void) read_sswitch_reg(t, l, &x); - // printf("slink %d: 0x%X\n", link_num, x); - // printf("src_inuse %d\n", XS1_LINK_SRC_INUSE(x)); - // printf("dst_inuse %d\n", XS1_LINK_DST_INUSE(x)); - // printf("junk %d\n", XS1_LINK_JUNK(x)); - // printf("network %d\n", XS1_LINK_NETWORK(x)); - // printf("direction %d\n", XS1_LINK_DIRECTION(x)); - // printf("src_target_id %d\n", XS1_LINK_SRC_TARGET_ID(x)); - // printf("src_target_type %d\n", XS1_LINK_SRC_TARGET_TYPE(x), slink_type_str[XS1_LINK_SRC_TARGET_TYPE(x)]); -} - - #define INTER_DELAY 2 #define INTRA_DELAY 3 -void link_disable(unsigned link_num); -void link_enable(unsigned link_num); -void link_reset(unsigned link_num); -void link_hello(unsigned link_num); -unsigned link_got_credit(unsigned link_num); +void link_disable(unsigned tileid, unsigned link_num); +void link_enable(unsigned tileid, unsigned link_num); +void link_reset(unsigned tileid, unsigned link_num); +void link_hello(unsigned tileid, unsigned link_num); +unsigned link_got_credit(unsigned tileid, unsigned link_num); /* Disable link by resetting ENABLE bit in link's control register */ -void link_disable(unsigned link_num) { +void link_disable(unsigned tileid, unsigned link_num) { unsigned x = 0; - (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, &x); + (void) read_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, &x); x &= ~XS1_XLINK_ENABLE_MASK; - (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, x); + (void) write_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, x); } /* Configure link by performing the following in the link's control register @@ -185,38 +84,38 @@ void link_disable(unsigned link_num) { * - Set ENABLE bit * - Set WIDE bit if 5-bit link required */ -void link_enable(unsigned link_num) { +void link_enable(unsigned tileid, unsigned link_num) { unsigned x = 0; - (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, &x); + (void) read_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, &x); x |= XS1_XLINK_INTER_TOKEN_DELAY_SET(x, INTER_DELAY); x |= XS1_XLINK_INTRA_TOKEN_DELAY_SET(x, INTRA_DELAY); x |= XS1_XLINK_ENABLE_MASK; x |= W * XS1_XLINK_WIDE_MASK; - (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XLINK_0_NUM + link_num, x); + (void) write_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, x); } /* Reset link by setting RESET bit in link's control register */ -void link_reset(unsigned link_num) { +void link_reset(unsigned tileid, unsigned link_num) { unsigned x = 0; unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; - (void) read_sswitch_reg(get_local_tile_id(), l, &x); + (void) read_sswitch_reg(tileid, l, &x); x |= XS1_XLINK_RX_RESET_MASK; - (void) write_sswitch_reg(get_local_tile_id(), l, x); + (void) write_sswitch_reg(tileid, l, x); } /* Send a HELLO by setting HELLO bit in link's control register */ -void link_hello(unsigned link_num) { +void link_hello(unsigned tileid, unsigned link_num) { unsigned x = 0; unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; - (void) read_sswitch_reg(get_local_tile_id(), l, &x); + (void) read_sswitch_reg(tileid, l, &x); x |= XS1_XLINK_HELLO_MASK; - (void) write_sswitch_reg(get_local_tile_id(), l, x); + (void) write_sswitch_reg(tileid, l, x); } -unsigned link_got_credit(unsigned link_num) { +unsigned link_got_credit(unsigned tileid, unsigned link_num) { unsigned x = 0; unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; - (void) read_sswitch_reg(get_local_tile_id(), l, &x); + (void) read_sswitch_reg(tileid, l, &x); return XS1_TX_CREDIT(x); } @@ -224,26 +123,26 @@ unsigned link_got_credit(unsigned link_num) { #define LINK_NUM 2 -#if (DEMO_TILE == 0) -#define CHANEND_TILE_ID 0x80010002 -#else -#define CHANEND_TILE_ID 0x80030002 -#endif static int g_data_tokens = 0; static int g_ctrl_tokens = 0; static int g_timeout_cnts = 0; +#define RX_NODE_ID 0x20 void xlink_report_task(void) { int full_rep_cnt = 0; + size_t n = 0; while(1) { vTaskDelay(pdMS_TO_TICKS(1000)); - printf("Communication rate: %d bytes per sec \t\t\t ==>\t %d Mbit/sec\n", g_data_tokens, ((g_data_tokens*8)/1000000)); + + rtos_i2c_master_write(i2c_master_ctx, 0xc, &g_data_tokens, sizeof(g_data_tokens), &n, 1); + + rtos_printf("Communication rate: %d bytes per sec \t\t\t ==>\t %d Mbit/sec\n", g_data_tokens, ((g_data_tokens*8)/1000000)); if (!(full_rep_cnt++ % 10)) { - printf("\nApplication control token count: \t\t%d \n", g_ctrl_tokens); - printf("Receive timeouts: \t\t\t\t%d \n\n", g_timeout_cnts); + rtos_printf("\nApplication control token count: \t\t%d \n", g_ctrl_tokens); + rtos_printf("Receive timeouts: \t\t\t\t%d \n\n", g_timeout_cnts); } g_data_tokens = 0; } @@ -264,20 +163,15 @@ void xlink_rx(void) { unsigned x = 0; - printf("RX started...tile id: %x\n", get_local_tile_id()); - rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); - rtos_osal_thread_preemption_disable(NULL); + size_t n = 0; - read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, &x); - printf("node is 0x%x\n", x); - // x = XS1_SS_NODE_ID_ID_SET(x, 0x20); - // printf("set node to 0x%x\n", x); - // write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, x); + rtos_printf("RX started...tile id: %x\n", get_local_tile_id()); + rtos_osal_thread_core_exclusion_set(NULL, ~(1 << 1)); + rtos_osal_thread_preemption_disable(NULL); - debug_print_sswitch_reg(XS1_SSWITCH_NODE_ID_NUM); - while(1) { - // printf("rx state: %d\n", comm_state); + // rtos_printf("rx state: %d\n", comm_state); + rtos_i2c_master_write(i2c_master_ctx, 0xa, &comm_state, sizeof(comm_state), &n, 1); switch (comm_state) { default: break; @@ -285,56 +179,36 @@ void xlink_rx(void) { reg_val = 0; direction = RX_DIRECTION; reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); - (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); + (void) write_sswitch_reg(RX_NODE_ID, XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); comm_state = 1; break; case 1: /* Channel alloc */ c_tileid = chanend_alloc(); - printf("Allocated chanend 0x%x\n", c_tileid); - - // configASSERT(c_tileid == CHANEND_TILE_ID); + rtos_i2c_master_write(i2c_master_ctx, 0xf, &c_tileid, sizeof(c_tileid), &n, 1); comm_state = 2; break; case 2: /* Reconfigure links, setting up a single static link */ - // for (int i=1; i<8; i++) { - // printf("%d\n", i); - // link_disable(i); - // } - // printf("a\n"); - link_disable(LINK_NUM); - // printf("b\n"); - link_enable(LINK_NUM); + for (int i=0; i<8; i++) { + link_disable(RX_NODE_ID, i); + } + link_enable(RX_NODE_ID, LINK_NUM); delay_milliseconds(100); - // printf("c\n"); - // printf("c\n"); - // id = 0x80030000; - x = 0; x |= XS1_XSTATIC_ENABLE_SET(x, 1); - x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, (c_tileid >> 8) & 0x0000001F); + x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, ((c_tileid >> 8) & 0x0000001F)); x |= XS1_XSTATIC_DEST_PROC_SET(x, 1); - (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); - // delay_milliseconds(150); - // printf("d\n"); - - - debug_xlinks(); + (void) write_sswitch_reg(RX_NODE_ID, XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); - // (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, &x); - - // printf("d\n"); - // printf("static link reg is 0x%x\n", x); comm_state = 3; break; case 3: /* Wait for transmit credits */ - // printf("RX try to get Credit\n"); do { - link_reset(LINK_NUM); - link_hello(LINK_NUM); + link_reset(RX_NODE_ID, LINK_NUM); + link_hello(RX_NODE_ID, LINK_NUM); delay_milliseconds(100); - } while (!link_got_credit(LINK_NUM)); - printf("RX Got Credit\n"); + + } while (!link_got_credit(RX_NODE_ID, LINK_NUM)); /* Setup local control vars */ rx_loop = 1; @@ -378,7 +252,7 @@ void xlink_rx(void) { { triggerable_disable_trigger(c_tileid); triggerable_disable_trigger(tmr_rx); - printf("Timed out\n"); + rtos_printf("Timed out\n"); rx_loop = 0; comm_state = 3; continue; @@ -388,7 +262,7 @@ void xlink_rx(void) { break; case 6: /* End of Communication */ chanend_free(c_tileid); - link_disable(LINK_NUM); + link_disable(RX_NODE_ID, LINK_NUM); comm_state = 1; break; } @@ -399,9 +273,9 @@ void xlink_tx_reenable(void) { while(1) { vTaskDelay(pdMS_TO_TICKS(RE_ENABLE_TX_PERIOD * 1000)); g_comm_state = 1; - printf("Reenable tx link\n"); - link_disable(LINK_NUM); - link_enable(LINK_NUM); + rtos_printf("Reenable tx link\n"); + link_disable(get_local_tile_id(), LINK_NUM); + link_enable(get_local_tile_id(), LINK_NUM); } } @@ -414,17 +288,13 @@ void transmit_handler(unsigned comm_state) { uint32_t id = 0; unsigned x = 0; - rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); - rtos_osal_thread_preemption_disable(NULL); + unsigned tileid = get_local_tile_id(); read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, &x); - printf("node is 0x%x\n", x); - x = XS1_SS_NODE_ID_ID_SET(x, 0x4002); - printf("set node to 0x%x\n", x); - write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, x); + rtos_printf("node is 0x%x\n", x); while(1) { - // printf("tx state: %d\n", comm_state); + // rtos_printf("tx state: %d\n", comm_state); if (g_comm_state) { g_comm_state = 0; comm_state = 4; @@ -442,56 +312,37 @@ void transmit_handler(unsigned comm_state) { break; case 1: /* Channel setup */ c_other_tile = chanend_alloc(); - chanend_set_dest(c_other_tile, 0x80020702); // hardcode to expected rx + chanend_set_dest(c_other_tile, 0x00210902); // hardcode to expected rx (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, &x); - x = XS1_DIME_DIR_SET(x, TX_DIRECTION); + x = XS1_DIMF_DIR_SET(x, TX_DIRECTION); (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, x); - // chanend_set_dest(c_other_tile, 0x80050702); // hardcode to expected rx comm_state = 2; break; case 2: /* reconfigure links, leaving only one open */ for (int i=0; i<8; i++) { - // printf("%d\n", i); - link_disable(i); + link_disable(tileid, i); } - // printf("a\n"); - link_enable(LINK_NUM); - // printf("b\n"); + link_enable(tileid, LINK_NUM); comm_state = 3; break; case 3: /* Setup a static routing configuration */ - x = 0x80000000; - - // x = 0; + x = 0; x |= XS1_XSTATIC_ENABLE_SET(x, 1); - // x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, 0); - x |= XS1_XSTATIC_DEST_PROC_SET(x, 1); - // printf("chanid is 0x%x\n", (c_other_tile >> 8) & 0x0000001F); x = write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); - // printf("ret was 0x%x\n", x); - delay_milliseconds(150); - // printf("read ret was 0x%x\n", read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, &x)); - - // printf("d\n"); - // printf("static link reg is 0x%x\n", x); - - debug_xlinks(); - debug_print_sswitch_reg(XS1_SSWITCH_DIMENSION_DIRECTION0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_DIMENSION_DIRECTION1_NUM); + delay_milliseconds(150); comm_state = 4; break; case 4: /* Wait for transmit credits */ - // printf("TX try to get Credit\n"); do { - link_reset(LINK_NUM); - link_hello(LINK_NUM); + link_reset(tileid, LINK_NUM); + link_hello(tileid, LINK_NUM); delay_milliseconds(100); - } while (!link_got_credit(LINK_NUM)); - printf("TX Got Credit\n"); + } while (!link_got_credit(tileid, LINK_NUM)); + // rtos_printf("TX Got Credit\n"); /* Setup local control vars */ err_ctr = 0; @@ -499,7 +350,7 @@ void transmit_handler(unsigned comm_state) { break; case 5: /* Send data tokens */ chanend_out_byte(c_other_tile, 'a'); - printf("sent\n"); + if (err_ctr++ == SEND_CTRL_TOKEN) { err_ctr = 0; chanend_out_control_token(c_other_tile, XS1_CT_ACK); @@ -507,7 +358,7 @@ void transmit_handler(unsigned comm_state) { break; case 6: chanend_free(c_other_tile); - link_disable(LINK_NUM); + link_disable(tileid, LINK_NUM); comm_state = 2; break; } @@ -519,14 +370,15 @@ void transmit_handler(unsigned comm_state) { void xlink_tx(void) { exception_t exception; - rtos_osal_thread_core_exclusion_set(NULL, (1 << 0)); + rtos_osal_thread_core_exclusion_set(NULL, ~(1 << 1)); rtos_osal_thread_preemption_disable(NULL); - printf("TX started...tile id: %x\n", get_local_tile_id()); + + rtos_printf("TX started...tile id: %x\n", get_local_tile_id()); while(1) { TRY { transmit_handler(0); } CATCH (exception) { - printf("Got exception.\n"); + rtos_printf("Got exception.\n"); transmit_handler(4); } } @@ -534,27 +386,27 @@ void xlink_tx(void) { void vApplicationMallocFailedHook( void ) { - printf("Malloc Failed on tile %d!\n", THIS_XCORE_TILE); + rtos_printf("Malloc Failed on tile %d!\n", THIS_XCORE_TILE); for(;;); } void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName) { - printf("\nStack Overflow!!! %d %s!\n", THIS_XCORE_TILE, pcTaskName); + rtos_printf("\nStack Overflow!!! %d %s!\n", THIS_XCORE_TILE, pcTaskName); configASSERT(0); } void startup_task(void *arg) { - printf("Startup task running from tile %d on core %d\n", THIS_XCORE_TILE, portGET_CORE_ID()); + rtos_printf("Startup task running from tile %d on core %d\n", THIS_XCORE_TILE, portGET_CORE_ID()); - // platform_start(); + platform_start(); -#if 1 +#if 0 #if ON_TILE(1) vTaskDelay(pdMS_TO_TICKS(500)); #endif - printf("\n\nDebug info:\n"); - printf("tile id: %x\n", get_local_tile_id()); + rtos_printf("\n\nDebug info:\n"); + rtos_printf("tile id: %x\n", get_local_tile_id()); debug_print_sswitch_reg(XS1_SSWITCH_NODE_ID_NUM); debug_print_sswitch_reg(XS1_SSWITCH_NODE_CONFIG_NUM); @@ -603,13 +455,14 @@ void startup_task(void *arg) debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_6_NUM); debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_7_NUM); - printf("\n"); + rtos_printf("\nDebug end\n\n"); #if ON_TILE(1) // _Exit(0); #endif vTaskDelay(pdMS_TO_TICKS(500)); #endif + rtos_printf("Create tasks\n"); #if ON_TILE(1) #if DEMO_TILE == 0 @@ -654,15 +507,15 @@ port_enable(leds); port_out(leds, led_status); led_status ^= 1; #endif - // printf("Tile[%d]:\n\tMinimum heap free: %d\n\tCurrent heap free: %d\n", THIS_XCORE_TILE, xPortGetMinimumEverFreeHeapSize(), xPortGetFreeHeapSize()); + // rtos_printf("Tile[%d]:\n\tMinimum heap free: %d\n\tCurrent heap free: %d\n", THIS_XCORE_TILE, xPortGetMinimumEverFreeHeapSize(), xPortGetFreeHeapSize()); vTaskDelay(pdMS_TO_TICKS(1000)); } } static void tile_common_init(chanend_t c) { - // platform_init(c); - // chanend_free(c); + platform_init(c); + chanend_free(c); xTaskCreate((TaskFunction_t) startup_task, "startup_task", @@ -671,7 +524,7 @@ static void tile_common_init(chanend_t c) appconfSTARTUP_TASK_PRIORITY, NULL); - printf("start scheduler on tile %d\n", THIS_XCORE_TILE); + rtos_printf("start scheduler on tile %d\n", THIS_XCORE_TILE); vTaskStartScheduler(); } @@ -681,6 +534,21 @@ void main_tile0(chanend_t c0, chanend_t c1, chanend_t c2, chanend_t c3) { (void)c2; (void)c3; +unsigned x = 0; + read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, &x); + rtos_printf("node is 0x%x\n", x); +#if DEMO_TILE == 0 + x = XS1_SS_NODE_ID_ID_SET(x, RX_NODE_ID); + rtos_printf("set node to 0x%x\n", x); + write_sswitch_reg_no_ack(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, x); + delay_milliseconds(100); + + chanend_t c_other = chanend_get_dest(c1); + c_other &= 0x0000FFFF; + c_other |= 0x00210000; + chanend_set_dest(c1, c_other); +#endif + tile_common_init(c1); } #endif @@ -691,6 +559,14 @@ void main_tile1(chanend_t c0, chanend_t c1, chanend_t c2, chanend_t c3) { (void)c2; (void)c3; +#if DEMO_TILE == 0 + delay_milliseconds(110); + chanend_t c_other = chanend_get_dest(c0); + c_other &= 0x0000FFFF; + c_other |= 0x00200000; + chanend_set_dest(c0, c_other); +#endif + tile_common_init(c0); } #endif From 87b1be2118cb60e1267896a7d1bfc6247f37eeb5 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Mon, 12 Sep 2022 15:49:02 -0400 Subject: [PATCH 5/8] Minor cleanup --- examples/freertos/xlink/src/main.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/freertos/xlink/src/main.c b/examples/freertos/xlink/src/main.c index 79591fdc4..e0e721478 100644 --- a/examples/freertos/xlink/src/main.c +++ b/examples/freertos/xlink/src/main.c @@ -40,8 +40,9 @@ unsigned g_comm_state = 0; -#include - +#define INTER_DELAY 2 +#define INTRA_DELAY 3 +#define LINK_NUM 2 /* @@ -62,9 +63,6 @@ xlink2_tx4 IOR X1D70 */ -#define INTER_DELAY 2 -#define INTRA_DELAY 3 - void link_disable(unsigned tileid, unsigned link_num); void link_enable(unsigned tileid, unsigned link_num); void link_reset(unsigned tileid, unsigned link_num); @@ -121,7 +119,6 @@ unsigned link_got_credit(unsigned tileid, unsigned link_num) { -#define LINK_NUM 2 static int g_data_tokens = 0; From 440898b647b7f4e44ecdb801c0db40a0246da1b2 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Wed, 14 Sep 2022 10:52:09 -0400 Subject: [PATCH 6/8] Remove xscope. Cleanup initialization Moves node setup to xn file to avoid gross manual changing of existing chanend destination in cmain functions. Removes xscope. Adds additional i2c debug. --- examples/freertos/xlink/XCORE-AI-EXPLORER.xn | 25 ++- .../freertos/xlink/XCORE-AI-EXPLORER_tx.xn | 109 ++++++++++++ .../freertos/xlink/bsp_config/CMakeLists.txt | 31 ++++ .../platform/driver_instances.c | 16 ++ .../platform/driver_instances.h | 32 ++++ .../platform/platform_conf.h | 62 +++++++ .../platform/platform_init.c | 78 +++++++++ .../platform/platform_init.h | 12 ++ .../platform/platform_start.c | 36 ++++ examples/freertos/xlink/src/FreeRTOSConfig.h | 6 +- examples/freertos/xlink/src/config.xscope | 24 --- examples/freertos/xlink/src/main.c | 161 +++++------------- examples/freertos/xlink/xlink.cmake | 37 ++-- 13 files changed, 467 insertions(+), 162 deletions(-) create mode 100644 examples/freertos/xlink/XCORE-AI-EXPLORER_tx.xn create mode 100644 examples/freertos/xlink/bsp_config/CMakeLists.txt create mode 100644 examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/driver_instances.c create mode 100644 examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/driver_instances.h create mode 100644 examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_conf.h create mode 100644 examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_init.c create mode 100644 examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_init.h create mode 100644 examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_start.c delete mode 100644 examples/freertos/xlink/src/config.xscope diff --git a/examples/freertos/xlink/XCORE-AI-EXPLORER.xn b/examples/freertos/xlink/XCORE-AI-EXPLORER.xn index a9ab7384b..ac4754ef0 100644 --- a/examples/freertos/xlink/XCORE-AI-EXPLORER.xn +++ b/examples/freertos/xlink/XCORE-AI-EXPLORER.xn @@ -12,7 +12,7 @@ - + @@ -75,6 +75,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/freertos/xlink/XCORE-AI-EXPLORER_tx.xn b/examples/freertos/xlink/XCORE-AI-EXPLORER_tx.xn new file mode 100644 index 000000000..4dde19f84 --- /dev/null +++ b/examples/freertos/xlink/XCORE-AI-EXPLORER_tx.xn @@ -0,0 +1,109 @@ + + + Board + xcore.ai Explorer Kit + + + tileref tile[2] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/freertos/xlink/bsp_config/CMakeLists.txt b/examples/freertos/xlink/bsp_config/CMakeLists.txt new file mode 100644 index 000000000..5d4d1417e --- /dev/null +++ b/examples/freertos/xlink/bsp_config/CMakeLists.txt @@ -0,0 +1,31 @@ +if(${CMAKE_SYSTEM_NAME} STREQUAL XCORE_XS3A) + ## Create Explorer Board 2V0 target + add_library(example_freertos_xlink_board_support_config_xcore_ai_explorer_2V0 INTERFACE) + target_sources(example_freertos_xlink_board_support_config_xcore_ai_explorer_2V0 + INTERFACE + XCORE-AI-EXPLORER_2V0/platform/driver_instances.c + XCORE-AI-EXPLORER_2V0/platform/platform_init.c + XCORE-AI-EXPLORER_2V0/platform/platform_start.c + ) + target_include_directories(example_freertos_xlink_board_support_config_xcore_ai_explorer_2V0 + INTERFACE + XCORE-AI-EXPLORER_2V0 + ) + target_link_libraries(example_freertos_xlink_board_support_config_xcore_ai_explorer_2V0 + INTERFACE + core::general + rtos::freertos + rtos::drivers::general + ) + target_compile_definitions(example_freertos_xlink_board_support_config_xcore_ai_explorer_2V0 + INTERFACE + XCOREAI_EXPLORER=1 + PLATFORM_SUPPORTS_TILE_0=1 + PLATFORM_SUPPORTS_TILE_1=1 + PLATFORM_SUPPORTS_TILE_2=0 + PLATFORM_SUPPORTS_TILE_3=0 + ) + + ## Create an alias + add_library(example::freertos::xlink::bsp_config::xcore_ai_explorer_2V0 ALIAS example_freertos_xlink_board_support_config_xcore_ai_explorer_2V0) +endif() diff --git a/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/driver_instances.c b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/driver_instances.c new file mode 100644 index 000000000..3518a2abc --- /dev/null +++ b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/driver_instances.c @@ -0,0 +1,16 @@ +// Copyright (c) 2021-2022 XMOS LIMITED. This Software is subject to the terms of the +// XMOS Public License: Version 1 + +#include "platform/driver_instances.h" + +static rtos_intertile_t intertile_ctx_s; +rtos_intertile_t *intertile_ctx = &intertile_ctx_s; + +static rtos_gpio_t gpio_ctx_t0_s; +rtos_gpio_t *gpio_ctx_t0 = &gpio_ctx_t0_s; + +static rtos_gpio_t gpio_ctx_t1_s; +rtos_gpio_t *gpio_ctx_t1 = &gpio_ctx_t1_s; + +static rtos_i2c_master_t i2c_master_ctx_s; +rtos_i2c_master_t *i2c_master_ctx = &i2c_master_ctx_s; diff --git a/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/driver_instances.h b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/driver_instances.h new file mode 100644 index 000000000..a31ca9e3e --- /dev/null +++ b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/driver_instances.h @@ -0,0 +1,32 @@ +// Copyright (c) 2021-2022 XMOS LIMITED. This Software is subject to the terms of the +// XMOS Public License: Version 1 + +#ifndef DRIVER_INSTANCES_H_ +#define DRIVER_INSTANCES_H_ + +#include "rtos_intertile.h" +#include "rtos_i2c_master.h" +#include "rtos_gpio.h" + +#define I2C_TILE_NO 0 + +/** TILE 0 Clock Blocks */ +// #define UNUSED_CLKBLK XS1_CLKBLK_1 +// #define UNUSED_CLKBLK XS1_CLKBLK_2 +// #define UNUSED_CLKBLK XS1_CLKBLK_3 +// #define UNUSED_CLKBLK XS1_CLKBLK_4 /* Reserved for lib_xud */ +// #define UNUSED_CLKBLK XS1_CLKBLK_5 /* Reserved for lib_xud */ + +/** TILE 1 Clock Blocks */ +// #define UNUSED_CLKBLK XS1_CLKBLK_1 +// #define UNUSED_CLKBLK XS1_CLKBLK_2 +// #define UNUSED_CLKBLK XS1_CLKBLK_3 +// #define UNUSED_CLKBLK XS1_CLKBLK_4 +// #define UNUSED_CLKBLK XS1_CLKBLK_5 + +extern rtos_intertile_t *intertile_ctx; +extern rtos_gpio_t *gpio_ctx_t0; +extern rtos_gpio_t *gpio_ctx_t1; +extern rtos_i2c_master_t *i2c_master_ctx; + +#endif /* DRIVER_INSTANCES_H_ */ diff --git a/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_conf.h b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_conf.h new file mode 100644 index 000000000..43e1f0366 --- /dev/null +++ b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_conf.h @@ -0,0 +1,62 @@ +// Copyright (c) 2022 XMOS LIMITED. This Software is subject to the terms of the +// XMOS Public License: Version 1 + +#ifndef PLATFORM_CONF_H_ +#define PLATFORM_CONF_H_ + +/* + * This file contains defaults to build a basic project targetting the + * XCORE-AI-EXPLORER board. Users may create their own app_conf.h to override + * any default settings. + * + * For a different soft tapeout design, it is recommended to create an entirely + * different board support package. + */ + +#if __has_include("app_conf.h") +#include "app_conf.h" +#endif /* __has_include("app_conf.h") */ + +/*****************************************/ +/* Intertile Communication Configuration */ +/*****************************************/ +#ifndef appconfI2C_MASTER_RPC_PORT +#define appconfI2C_MASTER_RPC_PORT 10 +#endif /* appconfI2C_MASTER_RPC_PORT */ + +#ifndef appconfI2C_MASTER_RPC_PRIORITY +#define appconfI2C_MASTER_RPC_PRIORITY (configMAX_PRIORITIES/2) +#endif /* appconfI2C_MASTER_RPC_PRIORITY */ + +#ifndef appconfGPIO_T0_RPC_PORT +#define appconfGPIO_T0_RPC_PORT 11 +#endif /* appconfGPIO_T0_RPC_PORT */ + +#ifndef appconfGPIO_T1_RPC_PORT +#define appconfGPIO_T1_RPC_PORT 12 +#endif /* appconfGPIO_T1_RPC_PORT */ + +#ifndef appconfGPIO_RPC_PRIORITY +#define appconfGPIO_RPC_PRIORITY (configMAX_PRIORITIES/2) +#endif /* appconfGPIO_RPC_PRIORITY */ + +/*****************************************/ +/* I/O and interrupt cores for Tile 0 */ +/*****************************************/ +#ifndef appconfI2C_IO_CORE +#define appconfI2C_IO_CORE 3 /* Must be kept off core 0 with the RTOS tick ISR */ +#endif /* appconfI2C_IO_CORE */ + +#ifndef appconfI2C_INTERRUPT_CORE +#define appconfI2C_INTERRUPT_CORE 0 /* Must be kept off I/O cores. */ +#endif /* appconfI2C_INTERRUPT_CORE */ + +/*****************************************/ +/* I/O and interrupt cores for Tile 1 */ +/*****************************************/ + +/*****************************************/ +/* I/O Task Priorities */ +/*****************************************/ + +#endif /* PLATFORM_CONF_H_ */ diff --git a/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_init.c b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_init.c new file mode 100644 index 000000000..49cb2c250 --- /dev/null +++ b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_init.c @@ -0,0 +1,78 @@ +// Copyright (c) 2021-2022 XMOS LIMITED. This Software is subject to the terms of the +// XMOS Public License: Version 1 + +#include + +#include "platform_conf.h" +#include "platform/driver_instances.h" + +static void gpio_init(void) +{ + static rtos_driver_rpc_t gpio_rpc_config_t0; + static rtos_driver_rpc_t gpio_rpc_config_t1; + rtos_intertile_t *client_intertile_ctx[1] = {intertile_ctx}; + +#if ON_TILE(0) + rtos_gpio_init(gpio_ctx_t0); + + rtos_gpio_rpc_host_init( + gpio_ctx_t0, + &gpio_rpc_config_t0, + client_intertile_ctx, + 1); + + rtos_gpio_rpc_client_init( + gpio_ctx_t1, + &gpio_rpc_config_t1, + intertile_ctx); +#endif + +#if ON_TILE(1) + rtos_gpio_init(gpio_ctx_t1); + + rtos_gpio_rpc_client_init( + gpio_ctx_t0, + &gpio_rpc_config_t0, + intertile_ctx); + + rtos_gpio_rpc_host_init( + gpio_ctx_t1, + &gpio_rpc_config_t1, + client_intertile_ctx, + 1); +#endif +} + +static void i2c_init(void) +{ + static rtos_driver_rpc_t i2c_rpc_config; + +#if ON_TILE(I2C_TILE_NO) + rtos_intertile_t *client_intertile_ctx[1] = {intertile_ctx}; + rtos_i2c_master_init( + i2c_master_ctx, + PORT_I2C_SCL, 0, 0, + PORT_I2C_SDA, 0, 0, + 0, + 100); + + rtos_i2c_master_rpc_host_init( + i2c_master_ctx, + &i2c_rpc_config, + client_intertile_ctx, + 1); +#else + rtos_i2c_master_rpc_client_init( + i2c_master_ctx, + &i2c_rpc_config, + intertile_ctx); +#endif +} + +void platform_init(chanend_t other_tile_c) +{ + rtos_intertile_init(intertile_ctx, other_tile_c); + + gpio_init(); + i2c_init(); +} diff --git a/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_init.h b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_init.h new file mode 100644 index 000000000..98725556d --- /dev/null +++ b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_init.h @@ -0,0 +1,12 @@ +// Copyright (c) 2021 XMOS LIMITED. This Software is subject to the terms of the +// XMOS Public License: Version 1 + +#ifndef PLATFORM_INIT_H_ +#define PLATFORM_INIT_H_ + +#include + +void platform_init(chanend_t other_tile_c); +void platform_start(void); + +#endif /* PLATFORM_INIT_H_ */ diff --git a/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_start.c b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_start.c new file mode 100644 index 000000000..7403ce776 --- /dev/null +++ b/examples/freertos/xlink/bsp_config/XCORE-AI-EXPLORER_2V0/platform/platform_start.c @@ -0,0 +1,36 @@ +// Copyright (c) 2021-2022 XMOS LIMITED. This Software is subject to the terms of the +// XMOS Public License: Version 1 + +#include + +#include "platform_conf.h" +#include "platform/driver_instances.h" + +static void gpio_start(void) +{ + rtos_gpio_rpc_config(gpio_ctx_t0, appconfGPIO_T0_RPC_PORT, appconfGPIO_RPC_PRIORITY); + rtos_gpio_rpc_config(gpio_ctx_t1, appconfGPIO_T1_RPC_PORT, appconfGPIO_RPC_PRIORITY); + +#if ON_TILE(0) + rtos_gpio_start(gpio_ctx_t0); +#endif +#if ON_TILE(1) + rtos_gpio_start(gpio_ctx_t1); +#endif +} + +static void i2c_start(void) +{ + rtos_i2c_master_rpc_config(i2c_master_ctx, appconfI2C_MASTER_RPC_PORT, appconfI2C_MASTER_RPC_PRIORITY); +#if ON_TILE(I2C_TILE_NO) + rtos_i2c_master_start(i2c_master_ctx); +#endif +} + +void platform_start(void) +{ + rtos_intertile_start(intertile_ctx); + + gpio_start(); + i2c_start(); +} diff --git a/examples/freertos/xlink/src/FreeRTOSConfig.h b/examples/freertos/xlink/src/FreeRTOSConfig.h index 931308e9a..b954bd30e 100644 --- a/examples/freertos/xlink/src/FreeRTOSConfig.h +++ b/examples/freertos/xlink/src/FreeRTOSConfig.h @@ -56,8 +56,8 @@ your application. */ #define configUSE_CORE_INIT_HOOK 0 /* Run time and task stats gathering related definitions. */ -#define configGENERATE_RUN_TIME_STATS 1 -#define configUSE_TRACE_FACILITY 1 +#define configGENERATE_RUN_TIME_STATS 0 +#define configUSE_TRACE_FACILITY 0 #define configUSE_STATS_FORMATTING_FUNCTIONS 2 /* Setting to 2 does not include in tasks.c */ /* Co-routine related definitions. */ @@ -74,7 +74,7 @@ your application. */ #define configASSERT(x) xassert(x) /* Define to enable debug_printf() */ -#define configENABLE_DEBUG_PRINTF 1 +#define configENABLE_DEBUG_PRINTF 0 /* Define to map sprintf and snprintf to the * lite versions in lib_rtos_support */ diff --git a/examples/freertos/xlink/src/config.xscope b/examples/freertos/xlink/src/config.xscope deleted file mode 100644 index bb71bfe23..000000000 --- a/examples/freertos/xlink/src/config.xscope +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/freertos/xlink/src/main.c b/examples/freertos/xlink/src/main.c index e0e721478..3a60c78be 100644 --- a/examples/freertos/xlink/src/main.c +++ b/examples/freertos/xlink/src/main.c @@ -127,19 +127,32 @@ static int g_timeout_cnts = 0; #define RX_NODE_ID 0x20 +#define RX_STATE_ID 0x01 +#define RX_REPORT_BYTES_PER_SEC_ID 0x82 +#define RX_REPORT_CTRL_TOKENS_PER_SEC_ID 0x83 +#define RX_REPORT_TIMEOUTS_PER_SEC_ID 0x84 +#define I2C_SLAVE_ADDR 0xc + +static void i2c_send_word(uint8_t id, uint32_t word) { + uint8_t debug_buf[5] = {0}; + size_t n = 0; + + debug_buf[0] = id; + memcpy(&debug_buf[1], &word, sizeof(uint32_t)); + rtos_i2c_master_write(i2c_master_ctx, I2C_SLAVE_ADDR, debug_buf, sizeof(debug_buf), &n, 1); +} + void xlink_report_task(void) { int full_rep_cnt = 0; + uint8_t debug_buf[5] = {0}; size_t n = 0; while(1) { vTaskDelay(pdMS_TO_TICKS(1000)); - - rtos_i2c_master_write(i2c_master_ctx, 0xc, &g_data_tokens, sizeof(g_data_tokens), &n, 1); - - rtos_printf("Communication rate: %d bytes per sec \t\t\t ==>\t %d Mbit/sec\n", g_data_tokens, ((g_data_tokens*8)/1000000)); + i2c_send_word(RX_REPORT_BYTES_PER_SEC_ID, g_data_tokens); if (!(full_rep_cnt++ % 10)) { - rtos_printf("\nApplication control token count: \t\t%d \n", g_ctrl_tokens); - rtos_printf("Receive timeouts: \t\t\t\t%d \n\n", g_timeout_cnts); + i2c_send_word(RX_REPORT_CTRL_TOKENS_PER_SEC_ID, g_ctrl_tokens); + i2c_send_word(RX_REPORT_TIMEOUTS_PER_SEC_ID, g_timeout_cnts); } g_data_tokens = 0; } @@ -160,15 +173,12 @@ void xlink_rx(void) { unsigned x = 0; - size_t n = 0; - - rtos_printf("RX started...tile id: %x\n", get_local_tile_id()); rtos_osal_thread_core_exclusion_set(NULL, ~(1 << 1)); rtos_osal_thread_preemption_disable(NULL); while(1) { - // rtos_printf("rx state: %d\n", comm_state); - rtos_i2c_master_write(i2c_master_ctx, 0xa, &comm_state, sizeof(comm_state), &n, 1); + i2c_send_word(RX_STATE_ID, comm_state); + switch (comm_state) { default: break; @@ -181,7 +191,6 @@ void xlink_rx(void) { break; case 1: /* Channel alloc */ c_tileid = chanend_alloc(); - rtos_i2c_master_write(i2c_master_ctx, 0xf, &c_tileid, sizeof(c_tileid), &n, 1); comm_state = 2; break; case 2: /* Reconfigure links, setting up a single static link */ @@ -190,6 +199,7 @@ void xlink_rx(void) { } link_enable(RX_NODE_ID, LINK_NUM); delay_milliseconds(100); + x = 0; x |= XS1_XSTATIC_ENABLE_SET(x, 1); x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, ((c_tileid >> 8) & 0x0000001F)); @@ -197,6 +207,8 @@ void xlink_rx(void) { (void) write_sswitch_reg(RX_NODE_ID, XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); + delay_milliseconds(100); + comm_state = 3; break; case 3: /* Wait for transmit credits */ @@ -249,7 +261,6 @@ void xlink_rx(void) { { triggerable_disable_trigger(c_tileid); triggerable_disable_trigger(tmr_rx); - rtos_printf("Timed out\n"); rx_loop = 0; comm_state = 3; continue; @@ -270,7 +281,7 @@ void xlink_tx_reenable(void) { while(1) { vTaskDelay(pdMS_TO_TICKS(RE_ENABLE_TX_PERIOD * 1000)); g_comm_state = 1; - rtos_printf("Reenable tx link\n"); + /* Reenable tx link */ link_disable(get_local_tile_id(), LINK_NUM); link_enable(get_local_tile_id(), LINK_NUM); } @@ -285,13 +296,9 @@ void transmit_handler(unsigned comm_state) { uint32_t id = 0; unsigned x = 0; - unsigned tileid = get_local_tile_id(); - - read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, &x); - rtos_printf("node is 0x%x\n", x); + unsigned switch_id = get_local_tile_id(); while(1) { - // rtos_printf("tx state: %d\n", comm_state); if (g_comm_state) { g_comm_state = 0; comm_state = 4; @@ -304,30 +311,30 @@ void transmit_handler(unsigned comm_state) { reg_val = 0; direction = TX_DIRECTION; reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); - (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); + (void) write_sswitch_reg(switch_id, XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); comm_state = 1; break; case 1: /* Channel setup */ c_other_tile = chanend_alloc(); chanend_set_dest(c_other_tile, 0x00210902); // hardcode to expected rx - (void) read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, &x); + (void) read_sswitch_reg(switch_id, XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, &x); x = XS1_DIMF_DIR_SET(x, TX_DIRECTION); - (void) write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, x); + (void) write_sswitch_reg(switch_id, XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, x); comm_state = 2; break; case 2: /* reconfigure links, leaving only one open */ for (int i=0; i<8; i++) { - link_disable(tileid, i); + link_disable(switch_id, i); } - link_enable(tileid, LINK_NUM); + link_enable(switch_id, LINK_NUM); comm_state = 3; break; case 3: /* Setup a static routing configuration */ x = 0; x |= XS1_XSTATIC_ENABLE_SET(x, 1); - x = write_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); + x = write_sswitch_reg(switch_id, XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); delay_milliseconds(150); @@ -335,11 +342,10 @@ void transmit_handler(unsigned comm_state) { break; case 4: /* Wait for transmit credits */ do { - link_reset(tileid, LINK_NUM); - link_hello(tileid, LINK_NUM); + link_reset(switch_id, LINK_NUM); + link_hello(switch_id, LINK_NUM); delay_milliseconds(100); - } while (!link_got_credit(tileid, LINK_NUM)); - // rtos_printf("TX Got Credit\n"); + } while (!link_got_credit(switch_id, LINK_NUM)); /* Setup local control vars */ err_ctr = 0; @@ -355,7 +361,7 @@ void transmit_handler(unsigned comm_state) { break; case 6: chanend_free(c_other_tile); - link_disable(tileid, LINK_NUM); + link_disable(switch_id, LINK_NUM); comm_state = 2; break; } @@ -369,13 +375,10 @@ void xlink_tx(void) { rtos_osal_thread_core_exclusion_set(NULL, ~(1 << 1)); rtos_osal_thread_preemption_disable(NULL); - - rtos_printf("TX started...tile id: %x\n", get_local_tile_id()); while(1) { TRY { transmit_handler(0); } CATCH (exception) { - rtos_printf("Got exception.\n"); transmit_handler(4); } } @@ -398,69 +401,6 @@ void startup_task(void *arg) platform_start(); -#if 0 -#if ON_TILE(1) - vTaskDelay(pdMS_TO_TICKS(500)); -#endif - rtos_printf("\n\nDebug info:\n"); - rtos_printf("tile id: %x\n", get_local_tile_id()); - - debug_print_sswitch_reg(XS1_SSWITCH_NODE_ID_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_NODE_CONFIG_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_DIMENSION_DIRECTION0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_DIMENSION_DIRECTION1_NUM); - // debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID0_NUM); - // debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID1_NUM); - // debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID2_NUM); - // debug_print_sswitch_reg(XS1_SSWITCH_DEVICE_ID3_NUM); - - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_1_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_2_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_3_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_4_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_5_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_6_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_7_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_SLINK_8_NUM); - - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_1_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_2_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_3_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_4_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_5_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_6_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_PLINK_7_NUM); - - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_1_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_2_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_3_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_4_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_5_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_6_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_7_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XLINK_8_NUM); - - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_0_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_1_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_2_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_3_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_4_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_5_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_6_NUM); - debug_print_sswitch_reg(XS1_SSWITCH_XSTATIC_7_NUM); - - rtos_printf("\nDebug end\n\n"); - -#if ON_TILE(1) - // _Exit(0); -#endif - vTaskDelay(pdMS_TO_TICKS(500)); -#endif - rtos_printf("Create tasks\n"); - #if ON_TILE(1) #if DEMO_TILE == 0 xTaskCreate((TaskFunction_t) xlink_report_task, @@ -495,9 +435,9 @@ void startup_task(void *arg) #if ON_TILE(0) -port_t leds = XS1_PORT_4C; -int led_status=0; -port_enable(leds); + port_t leds = XS1_PORT_4C; + int led_status=0; + port_enable(leds); #endif for (;;) { #if ON_TILE(0) @@ -531,21 +471,6 @@ void main_tile0(chanend_t c0, chanend_t c1, chanend_t c2, chanend_t c3) { (void)c2; (void)c3; -unsigned x = 0; - read_sswitch_reg(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, &x); - rtos_printf("node is 0x%x\n", x); -#if DEMO_TILE == 0 - x = XS1_SS_NODE_ID_ID_SET(x, RX_NODE_ID); - rtos_printf("set node to 0x%x\n", x); - write_sswitch_reg_no_ack(get_local_tile_id(), XS1_SSWITCH_NODE_ID_NUM, x); - delay_milliseconds(100); - - chanend_t c_other = chanend_get_dest(c1); - c_other &= 0x0000FFFF; - c_other |= 0x00210000; - chanend_set_dest(c1, c_other); -#endif - tile_common_init(c1); } #endif @@ -556,14 +481,6 @@ void main_tile1(chanend_t c0, chanend_t c1, chanend_t c2, chanend_t c3) { (void)c2; (void)c3; -#if DEMO_TILE == 0 - delay_milliseconds(110); - chanend_t c_other = chanend_get_dest(c0); - c_other &= 0x0000FFFF; - c_other |= 0x00200000; - chanend_set_dest(c0, c_other); -#endif - tile_common_init(c0); } #endif diff --git a/examples/freertos/xlink/xlink.cmake b/examples/freertos/xlink/xlink.cmake index 658a8cee6..27e3ccc2f 100644 --- a/examples/freertos/xlink/xlink.cmake +++ b/examples/freertos/xlink/xlink.cmake @@ -3,6 +3,7 @@ #********************** file(GLOB_RECURSE APP_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.c) set(APP_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/src) +add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/bsp_config) #********************** # Flags @@ -15,8 +16,6 @@ set(APP_COMPILER_FLAGS -lquadspi -mcmodel=large -Wno-xcore-fptrgroup - ${CMAKE_CURRENT_LIST_DIR}/src/config.xscope - ${CMAKE_CURRENT_LIST_DIR}/XCORE-AI-EXPLORER.xn ) set(APP_COMPILE_DEFINITIONS DEBUG_PRINT_ENABLE=1 @@ -27,15 +26,29 @@ set(APP_COMPILE_DEFINITIONS XUD_CORE_CLOCK=600 ) +set(RX_APP_COMPILER_FLAGS + ${CMAKE_CURRENT_LIST_DIR}/XCORE-AI-EXPLORER.xn +) + +set(TX_APP_COMPILER_FLAGS + ${CMAKE_CURRENT_LIST_DIR}/XCORE-AI-EXPLORER_tx.xn +) + set(APP_LINK_OPTIONS -lquadspi -report +) + +set(RX_APP_LINK_OPTIONS ${CMAKE_CURRENT_LIST_DIR}/XCORE-AI-EXPLORER.xn - ${CMAKE_CURRENT_LIST_DIR}/src/config.xscope +) + +set(TX_APP_LINK_OPTIONS + ${CMAKE_CURRENT_LIST_DIR}/XCORE-AI-EXPLORER_tx.xn ) set(APP_LINK_LIBRARIES - rtos::bsp_config::xcore_ai_explorer + example::freertos::xlink::bsp_config::xcore_ai_explorer_2V0 ) #********************** @@ -46,9 +59,9 @@ add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL) target_sources(${TARGET_NAME} PUBLIC ${APP_SOURCES}) target_include_directories(${TARGET_NAME} PUBLIC ${APP_INCLUDES}) target_compile_definitions(${TARGET_NAME} PUBLIC ${APP_COMPILE_DEFINITIONS} DEMO_TILE=0 THIS_XCORE_TILE=0) -target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS}) +target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS} ${RX_APP_COMPILER_FLAGS}) target_link_libraries(${TARGET_NAME} PUBLIC ${APP_LINK_LIBRARIES}) -target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS}) +target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS} ${RX_APP_LINK_OPTIONS}) unset(TARGET_NAME) set(TARGET_NAME tile1_example_freertos_xlink_0) @@ -56,9 +69,9 @@ add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL) target_sources(${TARGET_NAME} PUBLIC ${APP_SOURCES}) target_include_directories(${TARGET_NAME} PUBLIC ${APP_INCLUDES}) target_compile_definitions(${TARGET_NAME} PUBLIC ${APP_COMPILE_DEFINITIONS} DEMO_TILE=0 THIS_XCORE_TILE=1) -target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS}) +target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS} ${RX_APP_COMPILER_FLAGS}) target_link_libraries(${TARGET_NAME} PUBLIC ${APP_LINK_LIBRARIES}) -target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS}) +target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS} ${RX_APP_LINK_OPTIONS}) unset(TARGET_NAME) #********************** @@ -81,9 +94,9 @@ add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL) target_sources(${TARGET_NAME} PUBLIC ${APP_SOURCES}) target_include_directories(${TARGET_NAME} PUBLIC ${APP_INCLUDES}) target_compile_definitions(${TARGET_NAME} PUBLIC ${APP_COMPILE_DEFINITIONS} DEMO_TILE=1 THIS_XCORE_TILE=0) -target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS}) +target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS} ${TX_APP_COMPILER_FLAGS}) target_link_libraries(${TARGET_NAME} PUBLIC ${APP_LINK_LIBRARIES}) -target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS}) +target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS} ${TX_APP_LINK_OPTIONS}) unset(TARGET_NAME) set(TARGET_NAME tile1_example_freertos_xlink_1) @@ -91,9 +104,9 @@ add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL) target_sources(${TARGET_NAME} PUBLIC ${APP_SOURCES}) target_include_directories(${TARGET_NAME} PUBLIC ${APP_INCLUDES}) target_compile_definitions(${TARGET_NAME} PUBLIC ${APP_COMPILE_DEFINITIONS} DEMO_TILE=1 THIS_XCORE_TILE=1) -target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS}) +target_compile_options(${TARGET_NAME} PRIVATE ${APP_COMPILER_FLAGS} ${TX_APP_COMPILER_FLAGS}) target_link_libraries(${TARGET_NAME} PUBLIC ${APP_LINK_LIBRARIES}) -target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS}) +target_link_options(${TARGET_NAME} PRIVATE ${APP_LINK_OPTIONS} ${TX_APP_LINK_OPTIONS}) unset(TARGET_NAME) #********************** From a3324fec2ec0fe10657934456a40379dcf446f70 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Wed, 14 Sep 2022 12:02:01 -0400 Subject: [PATCH 7/8] Add documentation and cleanup example --- examples/freertos/xlink/README.rst | 142 ++++-- examples/freertos/xlink/src/app_conf.h | 51 +-- .../freertos/xlink/src/link/link_helpers.c | 70 +++ .../freertos/xlink/src/link/link_helpers.h | 13 + examples/freertos/xlink/src/main.c | 417 +----------------- .../freertos/xlink/src/xlink_rx/xlink_rx.c | 190 ++++++++ .../freertos/xlink/src/xlink_rx/xlink_rx.h | 9 + .../freertos/xlink/src/xlink_tx/xlink_tx.c | 144 ++++++ .../freertos/xlink/src/xlink_tx/xlink_tx.h | 9 + examples/freertos/xlink/xlink.cmake | 7 +- 10 files changed, 575 insertions(+), 477 deletions(-) create mode 100644 examples/freertos/xlink/src/link/link_helpers.c create mode 100644 examples/freertos/xlink/src/link/link_helpers.h create mode 100644 examples/freertos/xlink/src/xlink_rx/xlink_rx.c create mode 100644 examples/freertos/xlink/src/xlink_rx/xlink_rx.h create mode 100644 examples/freertos/xlink/src/xlink_tx/xlink_tx.c create mode 100644 examples/freertos/xlink/src/xlink_tx/xlink_tx.h diff --git a/examples/freertos/xlink/README.rst b/examples/freertos/xlink/README.rst index f4bff31ed..b7b61df29 100644 --- a/examples/freertos/xlink/README.rst +++ b/examples/freertos/xlink/README.rst @@ -2,16 +2,79 @@ XLINK ############## -This example application demonstrates various capabilities of the Explorer board using FreeRTOS. The application uses I2C, I2S, SPI, UART, flash, mic array, and GPIO devices. - -The FreeRTOS application creates a single stage audio pipeline which applies a variable gain. The output audio is sent to the DAC and can be listened to via the 3.5mm audio jack. The audio gain can be adjusted via GPIO, where button A is volume up and button B is volume down. +This example application demonstrates the `AN01024 `_ application note in FreeRTOS on XCORE AI. ********************** Preparing the hardware ********************** -The UART loopback section of the demo requires that a jumper cable be connected -between X1D36 and X1D39. This connects the Tx pin to the Rx pin. +This example requires 2 XCORE-AI-EXPLORER boards, and a user provided device to act as an I2C slave. + +To setup the board for testing, the following connections must be made: + +.. list-table:: XCORE-AI-EXPLORER to XCORE-AI-EXPLORER Connections 2 Wire + :widths: 50 50 + :header-rows: 1 + :align: left + + * - BOARD 0 + - BOARD 1 + * - GND + - GND + * - X1D65 + - X1D66 + * - X1D66 + - X1D65 + * - X1D64 + - X1D67 + * - X1D67 + - X1D64 + * - X1D63 + - X1D68 + * - X1D68 + - X1D63 + * - X1D62 + - X1D69 + * - X1D69 + - X1D62 + * - X1D61 + - X1D70 + * - X1D70 + - X1D61 + +.. list-table:: XCORE-AI-EXPLORER to XCORE-AI-EXPLORER Connections 5 Wire Additions + :widths: 50 50 + :header-rows: 1 + :align: left + + * - BOARD 0 + - BOARD 1 + * - X1D63 + - X1D68 + * - X1D68 + - X1D63 + * - X1D62 + - X1D69 + * - X1D69 + - X1D62 + * - X1D61 + - X1D70 + * - X1D70 + - X1D61 + +.. list-table:: XCORE-AI-EXPLORER Board 0 to Host Connections + :widths: 50 50 + :header-rows: 1 + :align: left + + * - BOARD 0 + - Host + * - GND + - Host GND + * - SCL + - Host SCL + * - SDA + - Host SDA ********************* Building the firmware @@ -25,7 +88,7 @@ Run the following commands in the xcore_sdk root folder to build the firmware: cmake -B build -DCMAKE_TOOLCHAIN_FILE=xmos_cmake_toolchain/xs3a.cmake cd build - make example_freertos_xlink + make example_freertos_xlink_both .. tab:: Windows @@ -33,58 +96,53 @@ Run the following commands in the xcore_sdk root folder to build the firmware: cmake -G "NMake Makefiles" -B build -DCMAKE_TOOLCHAIN_FILE=xmos_cmake_toolchain/xs3a.cmake cd build - nmake example_freertos_xlink - -.. note:: - The host applications are required to create the filesystem. See the SDK Installation instructions for more information. - -From the xcore_sdk build folder, create the filesystem and flash the device with the following command: - -.. tab:: Linux and Mac - - .. code-block:: console - - make flash_fs_example_freertos_xlink - -.. tab:: Windows - - .. code-block:: console - - nmake flash_fs_example_freertos_xlink + nmake example_freertos_xlink_both ******************** Running the firmware ******************** -From the xcore_sdk build folder run: +This application requires example_freertos_xlink_0.xe to be run on BOARD 0, IE, the board with a host I2C connection. -.. tab:: Linux and Mac +Use the following command to determine available device: - .. code-block:: console +.. code-block:: console - make run_example_freertos_xlink + xrun --list-devices -.. tab:: Windows +From the xcore_sdk build folder run: - .. code-block:: console +.. code-block:: console - nmake run_example_freertos_xlink + xrun --id 0 example_freertos_xlink_0.xe + +In another console, from the xcore_sdk build folder run: +.. code-block:: console -******************************** -Debugging the firmware with xgdb -******************************** + xrun --id 1 example_freertos_xlink_1.xe -From the xcore_sdk build folder run: +BOARD 0 will send out status messages and communication details to slave address 0xC. -.. tab:: Linux and Mac - - .. code-block:: console +The data will contain an ID, followed by a 4 byte payload. The payload is an int32, sent least significant byte first. - make debug_example_freertos_xlink +Payloads match to ID per the table below: -.. tab:: Windows +.. list-table:: XCORE-AI-EXPLORER to XCORE-AI-EXPLORER Connections 2 Wire + :widths: 50 50 + :header-rows: 1 + :align: left - .. code-block:: console + * - ID + - Payload + * - 0x01 + - RX state + * - 0x82 + - received data bytes in the last second + * - 0x83 + - received control tokens in the last second + * - 0x84 + - timeouts in the last second - nmake debug_example_freertos_xlink +.. note:: + Data rates are highly dependant on the electrical characteristics of the physical connection. Refer to `xCONNECT Architecture `_ for more information. \ No newline at end of file diff --git a/examples/freertos/xlink/src/app_conf.h b/examples/freertos/xlink/src/app_conf.h index 3fa2b64e4..3227571d9 100644 --- a/examples/freertos/xlink/src/app_conf.h +++ b/examples/freertos/xlink/src/app_conf.h @@ -4,6 +4,22 @@ #ifndef APP_CONF_H_ #define APP_CONF_H_ +/* XLINK Configuration */ +/* 0 = 2 wire; 1 = 5 wire */ +#define appconfXLINK_WIRE_TYPE 0 +#define appconfLINK_NUM 2 +#define appconfINTER_DELAY 2 +#define appconfINTRA_DELAY 3 + +#define appconfRX_DIRECTION 0 +#define appconfRX_NODE_ID 0x20 +#define appconfRX_DEBUG_I2C_SLAVE_ADDR 0xc +#define appconfRX_TIME_OUT_TICKS 500000000 + +#define appconfTX_DIRECTION 5 +#define appconfRE_ENABLE_TX_PERIOD 6 +#define appconfSEND_CTRL_TOKEN 2500000 + /* Intertile Communication Configuration */ #define appconfI2C_MASTER_RPC_PORT 10 #define appconfI2C_MASTER_RPC_PRIORITY (configMAX_PRIORITIES/2) @@ -17,40 +33,13 @@ #define appconfI2C_INTERRUPT_CORE 0 /* Must be kept off I/O cores. */ /* I/O and interrupt cores for Tile 1 */ -#define appconfPDM_MIC_IO_CORE 1 /* Must be kept off I/O cores. Must be kept off core 0 with the RTOS tick ISR */ -#define appconfI2S_IO_CORE 2 /* Must be kept off core 0 with the RTOS tick ISR */ -#define appconfPDM_MIC_INTERRUPT_CORE 3 /* Must be kept off I/O cores. Best kept off core 0 with the tick ISR. */ -#define appconfI2S_INTERRUPT_CORE 4 /* Must be kept off I/O cores. Best kept off core 0 with the tick ISR. */ - -/* Audio Pipeline Configuration */ -#define appconfAUDIO_CLOCK_FREQUENCY MIC_ARRAY_CONFIG_MCLK_FREQ -#define appconfPDM_CLOCK_FREQUENCY MIC_ARRAY_CONFIG_PDM_FREQ -#define appconfPIPELINE_AUDIO_SAMPLE_RATE 16000 -#define appconfAUDIO_PIPELINE_STAGE_ZERO_GAIN 20 -#define appconfAUDIO_PIPELINE_MAX_GAIN 60 -#define appconfAUDIO_PIPELINE_MIN_GAIN 0 -#define appconfAUDIO_PIPELINE_GAIN_STEP 4 -#define appconfAUDIO_FRAME_LENGTH MIC_ARRAY_CONFIG_SAMPLES_PER_FRAME -#define appconfMIC_COUNT MIC_ARRAY_CONFIG_MIC_COUNT -#define appconfPRINT_AUDIO_FRAME_POWER 0 -#define appconfFRAMES_IN_ALL_CHANS (appconfAUDIO_FRAME_LENGTH * appconfMIC_COUNT) -#define appconfPOWER_THRESHOLD (float)0.00001 -#define appconfEXP -31 - -/* UART Configuration */ -#define appconfUART_BAUD_RATE 806400 - -/* GPIO Configuration */ -#define appconfGPIO_VOLUME_RAPID_FIRE_MS 100 +#ifndef appconfXLINK_RX_IO_CORE 1 /* Must be kept off core 0 with the RTOS tick ISR */ +#ifndef appconfXLINK_TX_IO_CORE 1 /* Must be kept off core 0 with the RTOS tick ISR */ /* Task Priorities */ #define appconfSTARTUP_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) -#define appconfAUDIO_PIPELINE_TASK_PRIORITY ( configMAX_PRIORITIES - 4 ) #define appconfGPIO_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) -#define appconfFILESYSTEM_DEMO_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) -#define appconfMEM_ANALYSIS_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) -#define appconfSPI_MASTER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) -#define appconfQSPI_FLASH_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) -#define appconfUART_RX_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define appconfXLINK_RX_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define appconfXLINK_TX_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) #endif /* APP_CONF_H_ */ diff --git a/examples/freertos/xlink/src/link/link_helpers.c b/examples/freertos/xlink/src/link/link_helpers.c new file mode 100644 index 000000000..e5b5fc119 --- /dev/null +++ b/examples/freertos/xlink/src/link/link_helpers.c @@ -0,0 +1,70 @@ +// Copyright 2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +/* System headers */ +#include +#include +#include + +/* Library headers */ + +/* App headers */ +#include "app_conf.h" +#include "link_helpers.h" +#include "platform/platform_init.h" +#include "platform/driver_instances.h" + +#ifdef appconfXLINK_WIRE_TYPE +#define W appconfXLINK_WIRE_TYPE +#else +/* default to 2 wire */ +#define W 0 +#endif + +/* Disable link by resetting ENABLE bit in link's control register */ +void link_disable(unsigned tileid, unsigned link_num) { + unsigned x = 0; + (void) read_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, &x); + x &= ~XS1_XLINK_ENABLE_MASK; + (void) write_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, x); +} + +/* Configure link by performing the following in the link's control register + * - Set intertoken and intratoken delays + * - Set ENABLE bit + * - Set WIDE bit if 5-bit link required + */ +void link_enable(unsigned tileid, unsigned link_num) { + unsigned x = 0; + (void) read_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, &x); + x |= XS1_XLINK_INTER_TOKEN_DELAY_SET(x, appconfINTER_DELAY); + x |= XS1_XLINK_INTRA_TOKEN_DELAY_SET(x, appconfINTRA_DELAY); + x |= XS1_XLINK_ENABLE_MASK; + x |= W * XS1_XLINK_WIDE_MASK; + (void) write_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, x); +} + +/* Reset link by setting RESET bit in link's control register */ +void link_reset(unsigned tileid, unsigned link_num) { + unsigned x = 0; + unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; + (void) read_sswitch_reg(tileid, l, &x); + x |= XS1_XLINK_RX_RESET_MASK; + (void) write_sswitch_reg(tileid, l, x); +} + +/* Send a HELLO by setting HELLO bit in link's control register */ +void link_hello(unsigned tileid, unsigned link_num) { + unsigned x = 0; + unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; + (void) read_sswitch_reg(tileid, l, &x); + x |= XS1_XLINK_HELLO_MASK; + (void) write_sswitch_reg(tileid, l, x); +} + +unsigned link_got_credit(unsigned tileid, unsigned link_num) { + unsigned x = 0; + unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; + (void) read_sswitch_reg(tileid, l, &x); + return XS1_TX_CREDIT(x); +} \ No newline at end of file diff --git a/examples/freertos/xlink/src/link/link_helpers.h b/examples/freertos/xlink/src/link/link_helpers.h new file mode 100644 index 000000000..25370b44e --- /dev/null +++ b/examples/freertos/xlink/src/link/link_helpers.h @@ -0,0 +1,13 @@ +// Copyright 2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef LINK_HELPERS_H_ +#define LINK_HELPERS_H_ + +void link_disable(unsigned tileid, unsigned link_num); +void link_enable(unsigned tileid, unsigned link_num); +void link_reset(unsigned tileid, unsigned link_num); +void link_hello(unsigned tileid, unsigned link_num); +unsigned link_got_credit(unsigned tileid, unsigned link_num); + +#endif /* LINK_HELPERS_H_ */ \ No newline at end of file diff --git a/examples/freertos/xlink/src/main.c b/examples/freertos/xlink/src/main.c index 3a60c78be..8a17a8d16 100644 --- a/examples/freertos/xlink/src/main.c +++ b/examples/freertos/xlink/src/main.c @@ -5,13 +5,6 @@ #include #include -#include -#include -#include -#include - -#include - /* FreeRTOS headers */ #include "FreeRTOS.h" #include "queue.h" @@ -20,370 +13,12 @@ /* App headers */ #include "app_conf.h" +#include "link_helpers.h" +#include "xlink_rx.h" +#include "xlink_tx.h" #include "platform/platform_init.h" #include "platform/driver_instances.h" - -// todo verify 1 == 5wire -#define W 0 - -#define RX_TIME_OUT_TICKS 500000000 - -// tx -#define RE_ENABLE_TX_PERIOD 6 -#define SEND_CTRL_TOKEN 2500000 - -unsigned g_comm_state = 0; - -#define RX_DIRECTION 0 -#define TX_DIRECTION 5 - - - -#define INTER_DELAY 2 -#define INTRA_DELAY 3 -#define LINK_NUM 2 - -/* - -tile 1 -xlink2_rx4 IOR X1D61 -xlink2_rx3 IOR X1D62 -xlink2_rx2 IOR X1D63 - -xlink2_rx1 IOR X1D64 -xlink2_rx0 IOR X1D65 -xlink2_tx0 IOR X1D66 -xlink2_tx1 IOR X1D67 - -xlink2_tx2 IOR X1D68 -xlink2_tx3 IOR X1D69 -xlink2_tx4 IOR X1D70 - -*/ - - -void link_disable(unsigned tileid, unsigned link_num); -void link_enable(unsigned tileid, unsigned link_num); -void link_reset(unsigned tileid, unsigned link_num); -void link_hello(unsigned tileid, unsigned link_num); -unsigned link_got_credit(unsigned tileid, unsigned link_num); - -/* Disable link by resetting ENABLE bit in link's control register */ -void link_disable(unsigned tileid, unsigned link_num) { - unsigned x = 0; - (void) read_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, &x); - x &= ~XS1_XLINK_ENABLE_MASK; - (void) write_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, x); -} - -/* Configure link by performing the following in the link's control register - * - Set intertoken and intratoken delays - * - Set ENABLE bit - * - Set WIDE bit if 5-bit link required - */ -void link_enable(unsigned tileid, unsigned link_num) { - unsigned x = 0; - (void) read_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, &x); - x |= XS1_XLINK_INTER_TOKEN_DELAY_SET(x, INTER_DELAY); - x |= XS1_XLINK_INTRA_TOKEN_DELAY_SET(x, INTRA_DELAY); - x |= XS1_XLINK_ENABLE_MASK; - x |= W * XS1_XLINK_WIDE_MASK; - (void) write_sswitch_reg(tileid, XS1_SSWITCH_XLINK_0_NUM + link_num, x); -} - -/* Reset link by setting RESET bit in link's control register */ -void link_reset(unsigned tileid, unsigned link_num) { - unsigned x = 0; - unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; - (void) read_sswitch_reg(tileid, l, &x); - x |= XS1_XLINK_RX_RESET_MASK; - (void) write_sswitch_reg(tileid, l, x); -} - -/* Send a HELLO by setting HELLO bit in link's control register */ -void link_hello(unsigned tileid, unsigned link_num) { - unsigned x = 0; - unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; - (void) read_sswitch_reg(tileid, l, &x); - x |= XS1_XLINK_HELLO_MASK; - (void) write_sswitch_reg(tileid, l, x); -} - -unsigned link_got_credit(unsigned tileid, unsigned link_num) { - unsigned x = 0; - unsigned l = XS1_SSWITCH_XLINK_0_NUM + link_num; - (void) read_sswitch_reg(tileid, l, &x); - return XS1_TX_CREDIT(x); -} - - - - - -static int g_data_tokens = 0; -static int g_ctrl_tokens = 0; -static int g_timeout_cnts = 0; - -#define RX_NODE_ID 0x20 - -#define RX_STATE_ID 0x01 -#define RX_REPORT_BYTES_PER_SEC_ID 0x82 -#define RX_REPORT_CTRL_TOKENS_PER_SEC_ID 0x83 -#define RX_REPORT_TIMEOUTS_PER_SEC_ID 0x84 -#define I2C_SLAVE_ADDR 0xc - -static void i2c_send_word(uint8_t id, uint32_t word) { - uint8_t debug_buf[5] = {0}; - size_t n = 0; - - debug_buf[0] = id; - memcpy(&debug_buf[1], &word, sizeof(uint32_t)); - rtos_i2c_master_write(i2c_master_ctx, I2C_SLAVE_ADDR, debug_buf, sizeof(debug_buf), &n, 1); -} - -void xlink_report_task(void) { - int full_rep_cnt = 0; - uint8_t debug_buf[5] = {0}; - size_t n = 0; - - while(1) { - vTaskDelay(pdMS_TO_TICKS(1000)); - i2c_send_word(RX_REPORT_BYTES_PER_SEC_ID, g_data_tokens); - if (!(full_rep_cnt++ % 10)) { - i2c_send_word(RX_REPORT_CTRL_TOKENS_PER_SEC_ID, g_ctrl_tokens); - i2c_send_word(RX_REPORT_TIMEOUTS_PER_SEC_ID, g_timeout_cnts); - } - g_data_tokens = 0; - } -} - -void xlink_rx(void) { - unsigned comm_state = 0; - chanend_t c_tileid = 0; - unsigned tm_out_ctr = 0; - unsigned rx_loop = 0; - - uint32_t last_time = 0; - hwtimer_t tmr_rx = hwtimer_alloc(); - char rx = 'z'; - uint32_t id = 0; - int reg_val = 0; - int direction = 0x0; - - unsigned x = 0; - - rtos_osal_thread_core_exclusion_set(NULL, ~(1 << 1)); - rtos_osal_thread_preemption_disable(NULL); - - while(1) { - i2c_send_word(RX_STATE_ID, comm_state); - - switch (comm_state) { - default: - break; - case 0: /* Setup link direction */ - reg_val = 0; - direction = RX_DIRECTION; - reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); - (void) write_sswitch_reg(RX_NODE_ID, XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); - comm_state = 1; - break; - case 1: /* Channel alloc */ - c_tileid = chanend_alloc(); - comm_state = 2; - break; - case 2: /* Reconfigure links, setting up a single static link */ - for (int i=0; i<8; i++) { - link_disable(RX_NODE_ID, i); - } - link_enable(RX_NODE_ID, LINK_NUM); - delay_milliseconds(100); - - x = 0; - x |= XS1_XSTATIC_ENABLE_SET(x, 1); - x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, ((c_tileid >> 8) & 0x0000001F)); - x |= XS1_XSTATIC_DEST_PROC_SET(x, 1); - - (void) write_sswitch_reg(RX_NODE_ID, XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); - - delay_milliseconds(100); - - comm_state = 3; - break; - case 3: /* Wait for transmit credits */ - do { - link_reset(RX_NODE_ID, LINK_NUM); - link_hello(RX_NODE_ID, LINK_NUM); - delay_milliseconds(100); - - } while (!link_got_credit(RX_NODE_ID, LINK_NUM)); - - /* Setup local control vars */ - rx_loop = 1; - tm_out_ctr++; - last_time = get_reference_time(); - comm_state = 4; - break; - case 4: /* Receive data loop */ - rx = 'z'; - - TRIGGERABLE_SETUP_EVENT_VECTOR(tmr_rx, timeout); - TRIGGERABLE_SETUP_EVENT_VECTOR(c_tileid, transaction); - - triggerable_disable_all(); - - uint32_t trigger_time = hwtimer_get_time(tmr_rx) + RX_TIME_OUT_TICKS; - hwtimer_set_trigger_time(tmr_rx, trigger_time); - triggerable_enable_trigger(tmr_rx); - triggerable_enable_trigger(c_tileid); - - while(rx_loop) { - TRIGGERABLE_WAIT_EVENT(timeout, transaction); - { - transaction: - { - if (chanend_test_control_token_next_byte(c_tileid)) { - rx = chanend_in_control_token(c_tileid); - g_ctrl_tokens++; - } else { - rx = chanend_in_byte(c_tileid); - g_data_tokens++; - } - triggerable_disable_trigger(tmr_rx); - hwtimer_clear_trigger_time(tmr_rx); - trigger_time = hwtimer_get_time(tmr_rx) + RX_TIME_OUT_TICKS; - hwtimer_set_trigger_time(tmr_rx, trigger_time); - triggerable_enable_trigger(tmr_rx); - continue; - } - timeout: - { - triggerable_disable_trigger(c_tileid); - triggerable_disable_trigger(tmr_rx); - rx_loop = 0; - comm_state = 3; - continue; - } - } - } - break; - case 6: /* End of Communication */ - chanend_free(c_tileid); - link_disable(RX_NODE_ID, LINK_NUM); - comm_state = 1; - break; - } - } -} - -void xlink_tx_reenable(void) { - while(1) { - vTaskDelay(pdMS_TO_TICKS(RE_ENABLE_TX_PERIOD * 1000)); - g_comm_state = 1; - /* Reenable tx link */ - link_disable(get_local_tile_id(), LINK_NUM); - link_enable(get_local_tile_id(), LINK_NUM); - } -} - -void transmit_handler(unsigned comm_state) { - chanend_t c_other_tile = 0; - unsigned err_ctr = 0; - int reg_val = 0; - int direction = 0x0; - int ret = 0; - uint32_t id = 0; - unsigned x = 0; - - unsigned switch_id = get_local_tile_id(); - - while(1) { - if (g_comm_state) { - g_comm_state = 0; - comm_state = 4; - } - switch (comm_state) { - default: - comm_state = 4; - break; - case 0: /* Setup Link Direction */ - reg_val = 0; - direction = TX_DIRECTION; - reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); - (void) write_sswitch_reg(switch_id, XS1_SSWITCH_SLINK_0_NUM + LINK_NUM, reg_val); - comm_state = 1; - break; - case 1: /* Channel setup */ - c_other_tile = chanend_alloc(); - chanend_set_dest(c_other_tile, 0x00210902); // hardcode to expected rx - - (void) read_sswitch_reg(switch_id, XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, &x); - x = XS1_DIMF_DIR_SET(x, TX_DIRECTION); - (void) write_sswitch_reg(switch_id, XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, x); - - comm_state = 2; - break; - case 2: /* reconfigure links, leaving only one open */ - for (int i=0; i<8; i++) { - link_disable(switch_id, i); - } - link_enable(switch_id, LINK_NUM); - comm_state = 3; - break; - case 3: /* Setup a static routing configuration */ - x = 0; - x |= XS1_XSTATIC_ENABLE_SET(x, 1); - x = write_sswitch_reg(switch_id, XS1_SSWITCH_XSTATIC_0_NUM + LINK_NUM, x); - - delay_milliseconds(150); - - comm_state = 4; - break; - case 4: /* Wait for transmit credits */ - do { - link_reset(switch_id, LINK_NUM); - link_hello(switch_id, LINK_NUM); - delay_milliseconds(100); - } while (!link_got_credit(switch_id, LINK_NUM)); - - /* Setup local control vars */ - err_ctr = 0; - comm_state = 5; - break; - case 5: /* Send data tokens */ - chanend_out_byte(c_other_tile, 'a'); - - if (err_ctr++ == SEND_CTRL_TOKEN) { - err_ctr = 0; - chanend_out_control_token(c_other_tile, XS1_CT_ACK); - } - break; - case 6: - chanend_free(c_other_tile); - link_disable(switch_id, LINK_NUM); - comm_state = 2; - break; - } - } -} - -#include "trycatch.h" - -void xlink_tx(void) { - exception_t exception; - - rtos_osal_thread_core_exclusion_set(NULL, ~(1 << 1)); - rtos_osal_thread_preemption_disable(NULL); - while(1) { - TRY { - transmit_handler(0); - } CATCH (exception) { - transmit_handler(4); - } - } -} - void vApplicationMallocFailedHook( void ) { rtos_printf("Malloc Failed on tile %d!\n", THIS_XCORE_TILE); @@ -403,50 +38,26 @@ void startup_task(void *arg) #if ON_TILE(1) #if DEMO_TILE == 0 - xTaskCreate((TaskFunction_t) xlink_report_task, - "xlink_report_task", - RTOS_THREAD_STACK_SIZE(xlink_report_task), - NULL, - appconfSTARTUP_TASK_PRIORITY, - NULL); - - xTaskCreate((TaskFunction_t) xlink_rx, - "xlink_rx", - RTOS_THREAD_STACK_SIZE(xlink_rx), - NULL, - appconfSTARTUP_TASK_PRIORITY, - NULL); + create_xlink_rx_tasks(appconfXLINK_RX_TASK_PRIORITY); #else - xTaskCreate((TaskFunction_t) xlink_tx_reenable, - "xlink_tx_reenable", - RTOS_THREAD_STACK_SIZE(xlink_tx_reenable), - NULL, - appconfSTARTUP_TASK_PRIORITY, - NULL); - - xTaskCreate((TaskFunction_t) xlink_tx, - "xlink_tx", - RTOS_THREAD_STACK_SIZE(xlink_tx), - NULL, - appconfSTARTUP_TASK_PRIORITY, - NULL); + create_xlink_tx_tasks(appconfXLINK_TX_TASK_PRIORITY); #endif #endif - #if ON_TILE(0) - port_t leds = XS1_PORT_4C; + /* 1s Heartbeat */ + const rtos_gpio_port_id_t led_port = rtos_gpio_port(PORT_LEDS); + rtos_gpio_port_enable(gpio_ctx_t0, led_port); int led_status=0; - port_enable(leds); -#endif + for (;;) { -#if ON_TILE(0) - port_out(leds, led_status); - led_status ^= 1; -#endif - // rtos_printf("Tile[%d]:\n\tMinimum heap free: %d\n\tCurrent heap free: %d\n", THIS_XCORE_TILE, xPortGetMinimumEverFreeHeapSize(), xPortGetFreeHeapSize()); + rtos_gpio_port_out(gpio_ctx_t0, led_port, led_status); + led_status ^= 1; vTaskDelay(pdMS_TO_TICKS(1000)); } +#else + vTaskSuspend(NULL); +#endif } static void tile_common_init(chanend_t c) diff --git a/examples/freertos/xlink/src/xlink_rx/xlink_rx.c b/examples/freertos/xlink/src/xlink_rx/xlink_rx.c new file mode 100644 index 000000000..777e61630 --- /dev/null +++ b/examples/freertos/xlink/src/xlink_rx/xlink_rx.c @@ -0,0 +1,190 @@ +// Copyright 2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +/* System headers */ +#include +#include +#include +#include +#include +#include +#include + +/* Library headers */ + +/* App headers */ +#include "app_conf.h" +#include "link_helpers.h" +#include "xlink_rx.h" +#include "platform/platform_init.h" +#include "platform/driver_instances.h" + +static int g_data_tokens = 0; +static int g_ctrl_tokens = 0; +static int g_timeout_cnts = 0; + +/* XLINK RX debug info */ +#define RX_STATE_ID 0x01 +#define RX_REPORT_BYTES_PER_SEC_ID 0x82 +#define RX_REPORT_CTRL_TOKENS_PER_SEC_ID 0x83 +#define RX_REPORT_TIMEOUTS_PER_SEC_ID 0x84 + +static void i2c_send_word(uint8_t id, uint32_t word) { + uint8_t debug_buf[5] = {0}; + size_t n = 0; + + debug_buf[0] = id; + memcpy(&debug_buf[1], &word, sizeof(uint32_t)); + rtos_i2c_master_write(i2c_master_ctx, appconfRX_DEBUG_I2C_SLAVE_ADDR, debug_buf, sizeof(debug_buf), &n, 1); +} + +void xlink_report_task(void) { + int full_rep_cnt = 0; + uint8_t debug_buf[5] = {0}; + size_t n = 0; + + while(1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + i2c_send_word(RX_REPORT_BYTES_PER_SEC_ID, g_data_tokens); + if (!(full_rep_cnt++ % 10)) { + i2c_send_word(RX_REPORT_CTRL_TOKENS_PER_SEC_ID, g_ctrl_tokens); + i2c_send_word(RX_REPORT_TIMEOUTS_PER_SEC_ID, g_timeout_cnts); + } + g_data_tokens = 0; + } +} + +void xlink_rx(void) { + unsigned comm_state = 0; + chanend_t c_tileid = 0; + unsigned tm_out_ctr = 0; + unsigned rx_loop = 0; + + uint32_t last_time = 0; + hwtimer_t tmr_rx = hwtimer_alloc(); + char rx = 'z'; + uint32_t id = 0; + int reg_val = 0; + int direction = 0x0; + + unsigned x = 0; + + rtos_osal_thread_core_exclusion_set(NULL, ~(1 << appconfXLINK_RX_IO_CORE)); + rtos_osal_thread_preemption_disable(NULL); + + while(1) { + i2c_send_word(RX_STATE_ID, comm_state); + + switch (comm_state) { + default: + break; + case 0: /* Setup link direction */ + reg_val = 0; + direction = appconfRX_DIRECTION; + reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); + (void) write_sswitch_reg(appconfRX_NODE_ID, XS1_SSWITCH_SLINK_0_NUM + appconfLINK_NUM, reg_val); + comm_state = 1; + break; + case 1: /* Channel alloc */ + c_tileid = chanend_alloc(); + comm_state = 2; + break; + case 2: /* Reconfigure links, setting up a single static link */ + for (int i=0; i<8; i++) { + link_disable(appconfRX_NODE_ID, i); + } + link_enable(appconfRX_NODE_ID, appconfLINK_NUM); + delay_milliseconds(100); + + x = 0; + x |= XS1_XSTATIC_ENABLE_SET(x, 1); + x |= XS1_XSTATIC_DEST_CHAN_END_SET(x, ((c_tileid >> 8) & 0x0000001F)); + x |= XS1_XSTATIC_DEST_PROC_SET(x, 1); + + (void) write_sswitch_reg(appconfRX_NODE_ID, XS1_SSWITCH_XSTATIC_0_NUM + appconfLINK_NUM, x); + + delay_milliseconds(100); + + comm_state = 3; + break; + case 3: /* Wait for transmit credits */ + do { + link_reset(appconfRX_NODE_ID, appconfLINK_NUM); + link_hello(appconfRX_NODE_ID, appconfLINK_NUM); + delay_milliseconds(100); + + } while (!link_got_credit(appconfRX_NODE_ID, appconfLINK_NUM)); + + /* Setup local control vars */ + rx_loop = 1; + tm_out_ctr++; + last_time = get_reference_time(); + comm_state = 4; + break; + case 4: /* Receive data loop */ + rx = 'z'; + + TRIGGERABLE_SETUP_EVENT_VECTOR(tmr_rx, timeout); + TRIGGERABLE_SETUP_EVENT_VECTOR(c_tileid, transaction); + + triggerable_disable_all(); + + uint32_t trigger_time = hwtimer_get_time(tmr_rx) + appconfRX_TIME_OUT_TICKS; + hwtimer_set_trigger_time(tmr_rx, trigger_time); + triggerable_enable_trigger(tmr_rx); + triggerable_enable_trigger(c_tileid); + + while(rx_loop) { + TRIGGERABLE_WAIT_EVENT(timeout, transaction); + { + transaction: + { + if (chanend_test_control_token_next_byte(c_tileid)) { + rx = chanend_in_control_token(c_tileid); + g_ctrl_tokens++; + } else { + rx = chanend_in_byte(c_tileid); + g_data_tokens++; + } + triggerable_disable_trigger(tmr_rx); + hwtimer_clear_trigger_time(tmr_rx); + trigger_time = hwtimer_get_time(tmr_rx) + appconfRX_TIME_OUT_TICKS; + hwtimer_set_trigger_time(tmr_rx, trigger_time); + triggerable_enable_trigger(tmr_rx); + continue; + } + timeout: + { + triggerable_disable_trigger(c_tileid); + triggerable_disable_trigger(tmr_rx); + rx_loop = 0; + comm_state = 3; + continue; + } + } + } + break; + case 6: /* End of Communication */ + chanend_free(c_tileid); + link_disable(appconfRX_NODE_ID, appconfLINK_NUM); + comm_state = 1; + break; + } + } +} + +void create_xlink_rx_tasks(unsigned priority) { + xTaskCreate((TaskFunction_t) xlink_report_task, + "xlink_report_task", + RTOS_THREAD_STACK_SIZE(xlink_report_task), + NULL, + priority, + NULL); + + xTaskCreate((TaskFunction_t) xlink_rx, + "xlink_rx", + RTOS_THREAD_STACK_SIZE(xlink_rx), + NULL, + priority, + NULL); +} \ No newline at end of file diff --git a/examples/freertos/xlink/src/xlink_rx/xlink_rx.h b/examples/freertos/xlink/src/xlink_rx/xlink_rx.h new file mode 100644 index 000000000..a4308d7be --- /dev/null +++ b/examples/freertos/xlink/src/xlink_rx/xlink_rx.h @@ -0,0 +1,9 @@ +// Copyright 2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef XLINK_RX_H_ +#define XLINK_RX_H_ + +void create_xlink_rx_tasks(unsigned priority); + +#endif /* XLINK_RX_H_ */ \ No newline at end of file diff --git a/examples/freertos/xlink/src/xlink_tx/xlink_tx.c b/examples/freertos/xlink/src/xlink_tx/xlink_tx.c new file mode 100644 index 000000000..142eb03cd --- /dev/null +++ b/examples/freertos/xlink/src/xlink_tx/xlink_tx.c @@ -0,0 +1,144 @@ +// Copyright 2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +/* System headers */ +#include +#include +#include +#include +#include +#include +#include + +/* Library headers */ +#include "trycatch.h" + +/* App headers */ +#include "app_conf.h" +#include "link_helpers.h" +#include "xlink_tx.h" +#include "platform/platform_init.h" +#include "platform/driver_instances.h" + +static unsigned g_comm_state = 0; + +void xlink_tx_reenable(void) { + while(1) { + vTaskDelay(pdMS_TO_TICKS(appconfRE_ENABLE_TX_PERIOD * 1000)); + g_comm_state = 1; + /* Reenable tx link */ + link_disable(get_local_tile_id(), appconfLINK_NUM); + link_enable(get_local_tile_id(), appconfLINK_NUM); + } +} + +void transmit_handler(unsigned comm_state) { + chanend_t c_other_tile = 0; + unsigned err_ctr = 0; + int reg_val = 0; + int direction = 0x0; + int ret = 0; + + unsigned x = 0; + + unsigned switch_id = get_local_tile_id(); + + while(1) { + if (g_comm_state) { + g_comm_state = 0; + comm_state = 4; + } + switch (comm_state) { + default: + comm_state = 4; + break; + case 0: /* Setup Link Direction */ + reg_val = 0; + direction = appconfTX_DIRECTION; + reg_val = XS1_LINK_DIRECTION_SET(reg_val, direction); + (void) write_sswitch_reg(switch_id, XS1_SSWITCH_SLINK_0_NUM + appconfLINK_NUM, reg_val); + comm_state = 1; + break; + case 1: /* Channel setup */ + c_other_tile = chanend_alloc(); + chanend_set_dest(c_other_tile, 0x00210902); // hardcode to expected rx + + (void) read_sswitch_reg(switch_id, XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, &x); + x = XS1_DIMF_DIR_SET(x, appconfTX_DIRECTION); + (void) write_sswitch_reg(switch_id, XS1_SSWITCH_DIMENSION_DIRECTION1_NUM, x); + + comm_state = 2; + break; + case 2: /* reconfigure links, leaving only one open */ + for (int i=0; i<8; i++) { + link_disable(switch_id, i); + } + link_enable(switch_id, appconfLINK_NUM); + comm_state = 3; + break; + case 3: /* Setup a static routing configuration */ + x = 0; + x |= XS1_XSTATIC_ENABLE_SET(x, 1); + x = write_sswitch_reg(switch_id, XS1_SSWITCH_XSTATIC_0_NUM + appconfLINK_NUM, x); + + delay_milliseconds(150); + + comm_state = 4; + break; + case 4: /* Wait for transmit credits */ + do { + link_reset(switch_id, appconfLINK_NUM); + link_hello(switch_id, appconfLINK_NUM); + delay_milliseconds(100); + } while (!link_got_credit(switch_id, appconfLINK_NUM)); + + /* Setup local control vars */ + err_ctr = 0; + comm_state = 5; + break; + case 5: /* Send data tokens */ + chanend_out_byte(c_other_tile, 'a'); + + if (err_ctr++ == appconfSEND_CTRL_TOKEN) { + err_ctr = 0; + chanend_out_control_token(c_other_tile, XS1_CT_ACK); + } + break; + case 6: + chanend_free(c_other_tile); + link_disable(switch_id, appconfLINK_NUM); + comm_state = 2; + break; + } + } +} + +void xlink_tx(void) { + exception_t exception; + + rtos_osal_thread_core_exclusion_set(NULL, ~(1 << appconfXLINK_TX_IO_CORE)); + rtos_osal_thread_preemption_disable(NULL); + while(1) { + TRY { + transmit_handler(0); + } CATCH (exception) { + transmit_handler(4); + } + } +} + +void create_xlink_tx_tasks(unsigned priority) { + xTaskCreate((TaskFunction_t) xlink_tx_reenable, + "xlink_tx_reenable", + RTOS_THREAD_STACK_SIZE(xlink_tx_reenable), + NULL, + priority, + NULL); + + xTaskCreate((TaskFunction_t) xlink_tx, + "xlink_tx", + RTOS_THREAD_STACK_SIZE(xlink_tx), + NULL, + priority, + NULL); +} \ No newline at end of file diff --git a/examples/freertos/xlink/src/xlink_tx/xlink_tx.h b/examples/freertos/xlink/src/xlink_tx/xlink_tx.h new file mode 100644 index 000000000..3986a4a3b --- /dev/null +++ b/examples/freertos/xlink/src/xlink_tx/xlink_tx.h @@ -0,0 +1,9 @@ +// Copyright 2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef XLINK_TX_H_ +#define XLINK_TX_H_ + +void create_xlink_tx_tasks(unsigned priority); + +#endif /* XLINK_TX_H_ */ \ No newline at end of file diff --git a/examples/freertos/xlink/xlink.cmake b/examples/freertos/xlink/xlink.cmake index 27e3ccc2f..32a12247b 100644 --- a/examples/freertos/xlink/xlink.cmake +++ b/examples/freertos/xlink/xlink.cmake @@ -2,7 +2,12 @@ # Gather Sources #********************** file(GLOB_RECURSE APP_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.c) -set(APP_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/src) +set(APP_INCLUDES + ${CMAKE_CURRENT_LIST_DIR}/src + ${CMAKE_CURRENT_LIST_DIR}/src/link + ${CMAKE_CURRENT_LIST_DIR}/src/xlink_rx + ${CMAKE_CURRENT_LIST_DIR}/src/xlink_tx +) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/bsp_config) #********************** From 92b68c471ebd713ed33b0a585013e905aa2b2376 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Wed, 14 Sep 2022 12:05:36 -0400 Subject: [PATCH 8/8] Update core submodule --- modules/core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core b/modules/core index 8f6f9192a..81fa485da 160000 --- a/modules/core +++ b/modules/core @@ -1 +1 @@ -Subproject commit 8f6f9192a15af3d5d63ceff0355145a01fc35d4a +Subproject commit 81fa485dac2c2fc27b5f3f915ade780895273c43