Led and button - cores interconnection doubt

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
dahoma
Member++
Posts: 16
Joined: Thu Jan 03, 2019 2:19 pm

Led and button - cores interconnection doubt

Post by dahoma »

Hello guys.

I have just started with easy programming codes to understand the xmos architecture. In particular, I am working with xcore 200 multichannel-audio platform

Well, the case is simple, I wanna flash a LED when I push one of the general purpose buttons. How I set out this is, programming a specific task for flash the matrix led and another specific task for the buttons.
I know that there are easier ways to perform this but I wanna make in this way because I want to know how a task in one core can communicate with another task in a different core. I believe that the solutions come from streaming data over channels

The code is this:

Code: Select all

/*
 * ledbuton.xc
 *
 *  Created on: 30/01/2019
 *      Author: Sergio
 */


#include <platform.h>
#include <print.h>
#include <stdio.h>
#include <xs1.h>

/* Buttons/switch port */
in port p_sw = on tile[1] : XS1_PORT_4B;

/* LED grid port */
out port p_leds_row = on tile[1] : XS1_PORT_4C;
out port p_leds_col = on tile[1] : XS1_PORT_4D;

void my_led_matrix(streaming chanend c) {


    int i;
    c :> i;

    //if (i == 1){

    //    if (Pxx == 0x1){
    //        p_leds_row <: 0x0;
    //        delay_milliseconds(500);
    //    }
    //}

    if (i == 1){
        p_leds_row <: 0x0;
        delay_milliseconds(500);

    }
}

void my_button(streaming chanend c){
    int current_val = 0;
    int is_stable = 1;
    timer tmr ;
    const unsigned debounce_delay_ms = 50;
    unsigned debounce_timeout ;
    while (1) {

        select {
        // If the button is " stable ", react when the I/O pin changes value
        case is_stable => p_sw when pinsneq ( current_val ) :> current_val :
            if ( current_val == 0x1) {

                    c <: 1;

                printf(" Button up\n");
            } else {


                printf (" Button down \n");
            }

            is_stable = 0;
            int current_time ;
            tmr :> current_time ;
            // Calculate time to event after debounce period
            // note that XS1_TIMER_HZ is defined in timer .h
            debounce_timeout = current_time + ( debounce_delay_ms * XS1_TIMER_HZ );
            break ;

            // If the button is not stable (i.e. bouncing around ) then select
            // when we the timer reaches the timeout to renter a stable period
        case ! is_stable => tmr when timerafter ( debounce_timeout ) :> void :
                is_stable = 1;
                break ;
        }
    }
}


int main(){

    streaming chan c;

    par{
       on tile[1]: my_button(c);
       on tile[1]: my_led_matrix(c);
   }

   return 0;
}
It compiles but the leds does not flash when I push the button.

Another thing that I believe that I am allowed to do is this:

Code: Select all

    par{
       on tile[1].core[0]: my_button(c);
       on tile[1].core[1]: my_led_matrix(c);
   }

Someone can please help me


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am

Post by mon2 »

Hi. Start with forcing the LEDs to be on but review this thread before proceeding:

https://www.xcore.com/viewtopic.php?f=3 ... e50#p31562

Please post your results.
User avatar
dahoma
Member++
Posts: 16
Joined: Thu Jan 03, 2019 2:19 pm

Post by dahoma »

mon2 wrote:Hi. Start with forcing the LEDs to be on but review this thread before proceeding:

https://www.xcore.com/viewtopic.php?f=3 ... e50#p31562

Please post your results.
Yes, I started with this case and it works fine.