Task Priority Using Priority Modes Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
shaw
Experienced Member
Posts: 71
Joined: Fri Mar 25, 2011 12:36 am

Task Priority Using Priority Modes

Post by shaw »

We are working on a new project on XU316-1024-FB265-C32, based on Xmos USB Audio 2 development software kit. Using Xmos Tools 15.2.1. We would like to prioritize 1 or 2 of the tasks. I tried using approach described in AN02030, but ran into a build problem with including xcore/thread.h, problem with the Assembly code in header files(s). I tried defining functions myself, it built ok, but has a runtime problem. Still not right. Any tips on setting a thread to high priority mode. (here is what I"ve tried)

#define THREAD_MODE_HIGH_PRIORITY 0x1
static inline void local_thread_mode_set_bits(unsigned bits)
{
__asm__ volatile("setpt res[%0], %1" :: "r"(0xF), "r"(bits));
}

// call from within top of thread,
local_thread_mode_set_bits(THREAD_MODE_HIGH_PRIORITY);
View Solution
User avatar
fabriceo
Respected Member
Posts: 265
Joined: Mon Jan 08, 2018 4:14 pm

Post by fabriceo »

well, setting a core as high priority is done with setsr 0x400, and low priority with clrsr 0x400, not setpt
shaw
Experienced Member
Posts: 71
Joined: Fri Mar 25, 2011 12:36 am

Post by shaw »

Is this what you mean?
__asm__ volatile("setsr 0x400");

Does this enable user level interrupts OR does it actually set the priority. Isn't the Processor Status register used to set high priority mode? Maybe I'm missing something.
User avatar
fabriceo
Respected Member
Posts: 265
Joined: Mon Jan 08, 2018 4:14 pm

Post by fabriceo »

I had recently to do a priority switch in assembly and then I found this in disassembling a program containing set_core_high_priority_on()/off
and it works.

the ISA says:

Code: Select all

The ability of a
thread to accept events or interrupts is controlled by information held in the thread status
register (sr), and may be explicitly controlled using SETSR and CLRSR instructions with
appropriate operands.
SETSR sr ←sr ∨u16 set thread state
CLRSR sr ←sr ∧¬u16 clear thread state
GETSR r11 ←sr ∧u16 get thread state
The operand of these instructions should be one (or more) of
EEBLE enable events
IEBLE enable interrupts
INENB determine if thread is enabling events
ININT determine if thread is in interrupt mode
HIPRI set thread to high priority mode
FAST set thread to fast mode
KEDI set thread to switch to dual issue on kernel entry
the HIPRI mask is 0x400

also you can find it in the xcore_thread_impl.h

yes this register is also used for the interrupt flag
User avatar
Ross
Verified
XCore Legend
Posts: 1223
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

What was the original build problem you had please? There's example code provided along side the app note that builds and runs?

(what isn't documented is that you can also use void set_core_high_priority_on(void); from xs1.h)
Technical Director @ XMOS. Opinions expressed are my own
shaw
Experienced Member
Posts: 71
Joined: Fri Mar 25, 2011 12:36 am

Post by shaw »

here is the debug output when including file: xcore/thread.h

Analyzing xua_audiohub.xc
In file included from .../wkspace/lib_xua/lib_xua/src/core/audiohub/xua_audiohub.xc:36:
In file included from C:\Program Files (x86)\XMOS\XTC\15.2.1\target/include\xcore/thread.h:10:
In file included from C:\Program Files (x86)\XMOS\XTC\15.2.1\target/include\xcore/_support/xcore_thread_impl.h:6:
C:\Program Files (x86)\XMOS\XTC\15.2.1\target/include\xcore/_support/xcore_common.h:28:1: error: parse error before "asm"
asm (".globalresource 0x0,\"lib_xcore\",\"global\"");
^
In file included from .../wkspace/lib_xua/lib_xua/src/core/audiohub/xua_audiohub.xc:36:
In file included from C:\Program Files (x86)\XMOS\XTC\15.2.1\target/include\xcore/thread.h:10:
In file included from C:\Program Files (x86)\XMOS\XTC\15.2.1\target/include\xcore/_support/xcore_thread_impl.h:8:
C:\Program Files (x86)\XMOS\XTC\15.2.1\target/include\xcore/_support/xcore_resource_impl.h:22:14: error: cannot declare pointer to function
typedef void(*__xcore_interrupt_callback_t)(void);
....
User avatar
Ross
Verified
XCore Legend
Posts: 1223
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Lib_xcore provides a lot of the basic features of XC for C - ports, channels, timers, threads etc. The example in AN02030 is pure C, for XC use the functions in xc1.h

I'll raise an issue to make this clear in the note.
Technical Director @ XMOS. Opinions expressed are my own
shaw
Experienced Member
Posts: 71
Joined: Fri Mar 25, 2011 12:36 am

Post by shaw »

set_core_high_priority_on() is working as intended. Thank-you