defining interfaces outside of main.xc

If you have a simple question and just want an answer.
Post Reply
jsaksris
Member++
Posts: 29
Joined: Wed Jul 04, 2018 4:06 pm

defining interfaces outside of main.xc

Post by jsaksris »

hello all,

for the reason of code organisation, I would like to define my interfaces and function outside of main.xc

can I get help with the syntax?
I have written the interface in Tasks.xc
and have Tasks.h file so that other files would be able to access the interface and value.

but there is a syntax error for client, server, and interface
Attachments
Capture.PNG
Capture.PNG (13.26 KiB) Viewed 35228 times
Capture.PNG
Capture.PNG (13.26 KiB) Viewed 35228 times


Gothmag
XCore Addict
Posts: 129
Joined: Wed May 11, 2016 3:50 pm

Post by Gothmag »

One server and multiple clients requires an array of them. One per client. Also your interface can't be of type interface, needs to be led_if or some other type. Use a

Code: Select all

typedef struct name {} name;
syntax for it. Then you declare it as name myled_if[3]. myled_if goes to server, individuals go to clients as server/client interface name.
User avatar
Yanava
Member
Posts: 8
Joined: Mon Sep 10, 2018 4:23 pm

Post by Yanava »

You have a couple improvements you can make:

1) As mentioned, you can typedef interface LEDs_interface into LEDs_interface, then use:

void LEDControl(server LEDs_interface);

2) If you are going to handle your interface to multiple clients, you have to allow your server to handle multiple instances. Check the lib_i2c implementation which shows how to do this, you will have to include a counting mechanism on each interface event that will handle events coming from all instances. Also, if you anticipate that there might be racing conditions, like all of the instances will be handling pins, consider including a locking mechanism, so each access can only be performed when the last one was finished. Again, lib_i2c's implementation provides good pointers for that.
Post Reply