How to assign CLKBLK to port in ASM?

If you have a simple question and just want an answer.
ffomich
Experienced Member
Posts: 119
Joined: Mon Sep 15, 2014 1:32 pm

How to assign CLKBLK to port in ASM?

Post by ffomich »

Hi,
can anyone help me with assembler?

There is working example from SpdifReceive.S

Code: Select all

void task(in port p, //r0
              clock clk); //r1


    SETCI   r1, 7   // XS1_SETC_RUNR_STOP - stop clock
    SETCLK  r0, r1 - assign clock to port
    SETCI   r1, 15  // XS1_SETC_RUNR_START - start clock
Each CLKBLK has unique code

Code: Select all

#define XS1_CLKBLK_REF 0x6
#define XS1_CLKBLK_1 0x106
#define XS1_CLKBLK_2 0x206
#define XS1_CLKBLK_3 0x306
#define XS1_CLKBLK_4 0x406
#define XS1_CLKBLK_5 0x506
How can I assign port to another CLKBLK inside my task using CLKBLK code?
Something like this:

Code: Select all

void task(in port p, //r0
              clock clk); //r1

    SETCI   r1, 7   // stop clock
    LDC	r4, 0x0106 // load CLKBLK code
    SETCLK  r0, r4 // assign new clock to port
    SETCI   r4, 15 // start clock



User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

I find that often I don't actually need to configure ports and clock blocks in assembly. Doing it is tedious, cumbersome and error prone. Instead I now try to configure my ports and clock blocks in XC outside of my assembly routines.

If you absolutely can't avoid assembly for port/clock block configuration, however, use the SETCLK instruction. Remember to stop the clock block, as you did in your example. Are you having any issues with this code?

It might be useful to write a little test program using the XC configure functions and look in simulator output to see SETCLK/SETC instructions those configure functions compiled into.
ffomich
Experienced Member
Posts: 119
Joined: Mon Sep 15, 2014 1:32 pm

Post by ffomich »

Now it work. I don't know why it didn't work before :)

Code: Select all

r0 - port, r2 - divider, r4 - clock

    LDC   r4, XS1_CLKBLK_1 // load CLKBLK code
    SETCI   r4, 7   // stop clock
    SETD   r4, r2  // set clock divider  
    SETCLK  r0, r4 // assign new clock to port
    SETCI   r4, 15 // start clock
Note:

xCORE-200: The XMOS XS2 Architecture, p.191
Format of SETCLK instruction is:

Code: Select all

SETCLK port, clock
XS1 PORTS: USE AND SPECIFICATION (1.02) 2008/11/25, ch.3.6
All examples have inverse parameters order.