need help to get xscope working

Technical questions regarding the XTC tools and programming with XMOS.
ycui7
Member
Posts: 9
Joined: Wed Sep 25, 2024 5:46 am

need help to get xscope working

Post by ycui7 »

I am new to XMOS ecosystem. The question might be too simple.

I am following the documentation from XMOS to enable xscope debugging so I can figure out why my custom board not working. So far, it seems most documetations are out of date and written for obsolete xtimecomposer. When I try to copy the code from out-of-date documentation I got the following error.

In file included from C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/_support/xcore_chanend_impl.h:9:
C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/_support/xcore_resource_impl.h:22:14: error: cannot declare pointer to function
typedef void(*__xcore_interrupt_callback_t)(void);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/_support/xcore_resource_impl.h:23:14: error: cannot declare pointer to function
typedef void(*__xcore_select_callback_t)(void);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/_support/xcore_resource_impl.h:27:68: error: void * pointer must be declared as unsafe
_XCORE_INLINE void __xcore_resource_setup_callback(resource_t __r, void *__data, void(*__func)(void), uint32_t __type) _XCORE_NOTHROW
^~~~~~~~~~~~
C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/_support/xcore_resource_impl.h:27:82: error: cannot declare pointer to function
_XCORE_INLINE void __xcore_resource_setup_callback(resource_t __r, void *__data, void(*__func)(void), uint32_t __type) _XCORE_NOTHROW
^~~~~~~~~~~~~~~~~~~
C:\Program Files\XMOS\XTC\15.3.0\target/include\xcore/_support/xcore_resource_impl.h:33:19: error: cannot declare pointer to function
register void(* const __func_reg)(void) asm("r11") = __func;
^~~~~~~~~~~~~~~~~~~~~~~~~


C:\Program Files\XMOS\XTC\15.3.0\target/include\xscope.h:363:6: error: cannot declare a function in local scope.
void xscope_mode_lossless();
^~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\XMOS\XTC\15.3.0\target/include\xscope.h:372:6: error: cannot declare a function in local scope.
void xscope_mode_lossy();
^~~~~~~~~~~~~~~~~~~
C:\Program Files\XMOS\XTC\15.3.0\target/include\xscope.h:385:6: error: cannot declare a function in local scope.
void xscope_data_from_host(chanend c, char buf[256], int &n);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\XMOS\XTC\15.3.0\target/include\xscope.h:399:6: error: cannot declare a function in local scope.
void xscope_connect_data_from_host(chanend from_host);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


And the source that I changed is below. this is the evaluation board example code in audiohw.xc

#include <xs1.h>
#include <platform.h>
#include "xassert.h"
#include "xua.h"
#include "i2c.h"
#include "es9219q.h"

#include <stdio.h>
#include <xcore/channel.h>
#include <xscope.h>



extern "C" {
#include "sw_pll.h"
}

// CODEC I2C lines
on tile[0]: port p_i2c_scl = XS1_PORT_1O;
on tile[0]: port p_i2c_sda = XS1_PORT_1P;

// CODEC reset line
on tile[0]: out port p_codec_reset = PORT_BUTTONS;

// CODEC Reset
#define CODEC_RELEASE_RESET (0x30) // Release codec from D4, D5

typedef enum
{
AUDIOHW_CMD_REGWR,
AUDIOHW_CMD_REGRD
} audioHwCmd_t;

static inline void ES9219Q_REGREAD(unsigned reg, unsigned &val, client interface i2c_master_if i2c)
{
i2c_regop_res_t result;
val = i2c.read_reg(ES9219Q_I2C_DEVICE_ADDR, reg, result);
}

static inline void ES9219Q_REGWRITE(unsigned reg, unsigned val, client interface i2c_master_if i2c)
{
i2c.write_reg(ES9219Q_I2C_DEVICE_ADDR, reg, val);
}

void AudioHwRemote2(chanend c, client interface i2c_master_if i2c)
{
while(1)
{
unsigned cmd;
c :> cmd;

if(cmd == AUDIOHW_CMD_REGRD)
{
unsigned regAddr, regVal;
c :> regAddr;
ES9219Q_REGREAD(regAddr, regVal, i2c);
c <: regVal;
}
else
{
unsigned regAddr, regValue;
c :> regAddr;
c :> regValue;
ES9219Q_REGWRITE(regAddr, regValue, i2c);
}
}
}

void AudioHwRemote(chanend c)
{
i2c_master_if i2c[1];
par
{
i2c_master(i2c, 1, p_i2c_scl, p_i2c_sda, 10);
AudioHwRemote2(c, i2c[0]);
}
}

unsafe chanend uc_audiohw;

static inline void CODEC_REGWRITE(unsigned reg, unsigned val)
{
unsafe
{
uc_audiohw <: (unsigned) AUDIOHW_CMD_REGWR;
uc_audiohw <: reg;
uc_audiohw <: val;
}
}

static inline void CODEC_REGREAD(unsigned reg, unsigned &val)
{
unsafe
{
uc_audiohw <: (unsigned) AUDIOHW_CMD_REGRD;
uc_audiohw <: reg;
uc_audiohw :> val;
}
}

/* Note this is called from tile[1] but the I2C lines to the CODEC are on tile[0]
* use a channel to communicate CODEC reg read/writes to a remote core */
void AudioHwInit()
{
unsigned regVal = 0;
xscope_int(TILE0_RESULT, 1);

/* Take CODEC out of reset */
p_codec_reset <: CODEC_RELEASE_RESET;
xscope_int(TILE0_RESULT, 2);

delay_milliseconds(100);
xscope_int(TILE0_RESULT, 3);

delay_milliseconds(1);

assert(DEFAULT_FREQ >= 22050);
xscope_int(TILE0_RESULT, 4);

// Set the fractional divider if used
if(DEFAULT_FREQ % 22050 == 0)
{
sw_pll_fixed_clock(MCLK_441);
}
else
{
sw_pll_fixed_clock(MCLK_48);
}
xscope_int(TILE0_RESULT, 5);

delay_milliseconds(1);
}

/* Configures the external audio hardware for the required sample frequency.
* See gpio.h for I2C helper functions and gpio access
*/
void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode,
unsigned sampRes_DAC, unsigned sampRes_ADC)
{
assert(samFreq >= 22050);

// Set the AppPLL up to output MCLK.
if ((samFreq % 22050) == 0)
{
sw_pll_fixed_clock(MCLK_441);
}
else if ((samFreq % 24000) == 0)
{
sw_pll_fixed_clock(MCLK_48);
}

}
markp
Verified
Member++
Posts: 19
Joined: Thu Jan 10, 2019 6:07 pm

Post by markp »

You only need to add the include directive:

#include <xscope.h>

Do *NOT* add

#include <xcore/channel.h>

This is not compatible with .xc source which is what you have here.

Also, there is no need to add:
#include <stdio.h>

although this should not cause the issue you are seeing.
ycui7
Member
Posts: 9
Joined: Wed Sep 25, 2024 5:46 am

Post by ycui7 »

the final verdict is that the xscope did not work because the custom adapter had two bad solder joints on the xlink pins. everything works now.