specifying stdcore breaks program

Technical questions regarding the XTC tools and programming with XMOS.
kasbah
Member++
Posts: 17
Joined: Thu Oct 14, 2010 12:07 am

specifying stdcore breaks program

Post by kasbah »

I have been going through the "Development Card Tutorial" for the XC-1 board and was playing around with some of the code. The following is a program that rotates a flashing LED, plays different tones when buttons are pressed as well as changing the LED color when the buttons are pressed (through channel c).

Code: Select all

#include <platform.h>
#define BIT_RATE 115200
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE

#define TDELAY 1000000
#define TLENGTH 50

#define FLASH_PERIOD   1000000
#define CYCLE_PERIOD   6000000

in port buttons  = PORT_BUTTON;
out port speaker = PORT_SPEAKER;

out port cled0 = PORT_CLOCKLED_0;
out port cled1 = PORT_CLOCKLED_1;
out port cled2 = PORT_CLOCKLED_2;
out port cledG = PORT_CLOCKLED_SELG;
out port cledR = PORT_CLOCKLED_SELR;

void buttonListener(in port b, out port speaker, chanend c);
void speakerListener(chanend c,out port speaker);
int cycleLED(out port cled0, out port cled1,out port cled2,
             out port cledG,out port cledR, chanend c);

int main(void) {
    chan c;
    par {
        cycleLED(cled0, cled1, cled2, cledG, cledR, c);
        buttonListener(buttons, speaker, c);
    }
    return 0;
}

void buttonListener(in port b, out port spkr, chanend c) {
    timer tmr;
    int  t, isOn = 1;
    int buttonNumber;
    while (1) {

        b when pinsneq(0xf) :> buttonNumber;
        c <: 0;
        switch(buttonNumber){
        case 0x7 :
            tmr :> t;
            for (int i=0; i<TLENGTH; i++) {
                isOn = !isOn;
                t += TDELAY;
                tmr when timerafter(t) :> void;
                spkr <: isOn;
            }
            break;
        case 0xb :
            tmr :> t;
            for (int i=0; i<(TLENGTH*2); i++) {
                isOn = !isOn;
                t += TDELAY/2;
                tmr when timerafter(t) :> void;
                spkr <: isOn;
            }
            break;
        case 0xd :
            tmr :> t;
            for (int i=0; i<(TLENGTH*3); i++) {
                isOn = !isOn;
                t += TDELAY/3;
                tmr when timerafter(t) :> void;
                spkr <: isOn;
            }
            break;
        case 0xe :
            tmr :> t;
            for (int i=0; i<(TLENGTH*4); i++) {
                isOn = !isOn;
                t += TDELAY/4;
                tmr when timerafter(t) :> void;
                spkr <: isOn;
            }
            break;
        }

    }
}

int cycleLED(out port cled0, out port cled1,out port cled2,
             out port cledG,out port cledR, chanend c) {
    unsigned ledOn = 1;
    unsigned ledVal = 1;
    unsigned isGreen = 1;
    timer tmrF, tmrC;
    unsigned timeF, timeC;
    tmrF :> timeF;
    tmrC :> timeC;
    while (1) {
        select {
        case tmrF when timerafter(timeF) :> void :
            ledOn = !ledOn;
            cledR <: ledOn && !isGreen;
            cledG <: ledOn && isGreen;
            timeF += FLASH_PERIOD;
            break;
        case tmrC when timerafter(timeC) :> void :
            cled0 <: ledVal;
            cled1 <: (ledVal >> 4);
            cled2 <: (ledVal >> 8);
            ledVal <<= 1;
            if (ledVal == 0x1000)
                ledVal = 1;
            timeC += CYCLE_PERIOD;
            break;
        case c :> int :
            isGreen = !isGreen;
            break;
        }
    }
    return 0;
}
This works fine. But when I try to specify the core as per patch below:

Code: Select all

--- main_nocore.xc	2010-10-16 23:46:34.000000000 +0100
+++ main_core.xc	2010-10-16 23:40:12.000000000 +0100
@@ -8,14 +8,14 @@
 #define FLASH_PERIOD   1000000
 #define CYCLE_PERIOD   6000000
 
-in port buttons  = PORT_BUTTON;
-out port speaker = PORT_SPEAKER;
+on stdcore[0] : in port buttons  = PORT_BUTTON;
+on stdcore[0] : out port speaker = PORT_SPEAKER;
 
-out port cled0 = PORT_CLOCKLED_0;
-out port cled1 = PORT_CLOCKLED_1;
-out port cled2 = PORT_CLOCKLED_2;
-out port cledG = PORT_CLOCKLED_SELG;
-out port cledR = PORT_CLOCKLED_SELR;
+on stdcore[0] : out port cled0 = PORT_CLOCKLED_0;
+on stdcore[0] : out port cled1 = PORT_CLOCKLED_1;
+on stdcore[0] : out port cled2 = PORT_CLOCKLED_2;
+on stdcore[0] : out port cledG = PORT_CLOCKLED_SELG;
+on stdcore[0] : out port cledR = PORT_CLOCKLED_SELR;
 
 void buttonListener(in port b, out port speaker, chanend c);
 void speakerListener(chanend c,out port speaker);
@@ -25,8 +25,8 @@
 int main(void) {
     chan c;
     par {
-        cycleLED(cled0, cled1, cled2, cledG, cledR, c);
-        buttonListener(buttons, speaker, c);
+        on stdcore[0] : cycleLED(cled0, cled1, cled2, cledG, cledR, c);
+        on stdcore[0] : buttonListener(buttons, speaker, c);
     }
     return 0;
 }
This compiles but does not seem to run. What am I missing? Might it have something to do with my old XC-1 as opposed to XC-1A?


User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

runs fine here, compiled on Windows XP, Desktop tools 10.4 with

xcc -target=XC-1 test.xc

and tested on a XC-1 i see rotating LEDs.

i include the .xe file for the version with stdcore underneath my message.

Edit: redid testing with 10.4.2 with the same results
You do not have the required permissions to view the files attached to this post.
kasbah
Member++
Posts: 17
Joined: Thu Oct 14, 2010 12:07 am

Post by kasbah »

Your compiled program behaves the same as mine:

- LED17 on the back lights up red
- Button LED A lights up green
- LED I lights up green

So something is wrong with my board?
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

Have you put your XC-1 in program mode before loading the program? (see XC-1 Quick Start Guide)
kasbah
Member++
Posts: 17
Joined: Thu Oct 14, 2010 12:07 am

Post by kasbah »

richard wrote:Have you put your XC-1 in program mode before loading the program? (see XC-1 Quick Start Guide)
Ha! Missed that bit. Thanks for the responses and sorry about my stupidity. Is there a way to mark a thread solved?

So how come it kinda half works when it is not in programming mode?
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

kasbah wrote:So how come it kinda half works when it is not in programming mode?
When not in programming mode the demo runs and allocates resources (in particular chanends). When you load code onto the device the demo is interrupted and those resources will still be allocated. If your program tries to use those resources it may hang / trap, but otherwise you can get away with not being in program mode.

The code generated for a program with "on stdcore:" does a bit more channel initialisation than one without which is why it fails in one case and runs in the other.