How to find declaration of a service function from interface Topic is solved

If you have a simple question and just want an answer.
User avatar
breakersun
Junior Member
Posts: 6
Joined: Thu Mar 27, 2014 2:53 pm

How to find declaration of a service function from interface

Post by breakersun »

Dear Fellows,

I am a beginner of XMOS multicore from ST/Microchip MCU application.

Here I get a startkit and try to figure out how to make program on XMOS multicore.Seems I have some problem to find out how the button/led/touch slider works, cause I can't find out how is an interface function working, such as below one:

typedef interface startkit_button_if {
   [[notification]] slave void changed(); // Can't find the declaration, how it works?
   [[clears_notification]] button_val_t get_value(); // Can't find the declaration, how it works?
 } startkit_button_if;
 
I think I could use some help from community here. 
Would anybody help me to get over with it? I will be appreciate for that.
 
Thanks!
B.R.
Leo Sun


View Solution
vinith
Junior Member
Posts: 5
Joined: Wed Jul 31, 2013 6:44 am

Post by vinith »

Hello Leo Sun,

A function marked as [[notification]] will (well!) notify to the client program that something has occurred. It is a notification event. Function marked as [[clears_notification]] will clear the notification issued by calling them.

In your specific example here, you may write an app using the interface as:

void app(client interface startkit_button_if i_skbutton) {
  while(1) {
    select {
      case i_skbutton.changed(): { // something changed in the startkit button interface
        button_val_t btn_val;
        /*
            Get the button value using button interface. This will also clear the notification.
            If something else changes in the button interface then the 'changed()' event will be triggerred again and you will enter this case.
        */
        btn_val = i_skbutton.get_value(); // 
      }
    }
  }
}
 
If you need more information on using interfaces; please open the xTIMEcomposer Studio. Open the 'HowTo' window by: Window -> Show View -> HowTo. This will open the HowTo browser in the bottom left of xTIMEcomposer Studio. Search for 'interface' in this HowTo browser and look at various examples that will be listed as the result of this search.
 
I hope this helps.
Regards,
Vinith
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

An interface describes how two tasks communicate. To use an interface you must start two tasks running in parallel. One task (the client end) will make requests over the interface. The other task (the server end) will respond to requests from the client. To find the code that runs when you perform a method call on an interface you need to look at the implementation of the function that takes the server side of the interface as an argument.

In the case of the startKIT GPIO driver the relevent code is in startkit_gpio.xc :

https://github.com/xcore/sw_startkit_ex ... it_gpio.xc

The startkit_gpio_driver() function takes the server side of the interface as an argument and passes it to the startkit_gpio_driver_aux() function. Inside this function it has the following case:

    // Case handling a request for the button value
    case !isnull(i_button) => i_button.get_value() -> button_val_t res:
      res = button_val;
      break;

It is this code that handles the get_value() method. In this case the code is very simple - it just returns the value last read from the button (button_val). The button_val variable is updated in another case of the select which periodically samples the value on a port.