"interface" in headers vs. task body
-
- XCore Expert
- Posts: 512
- Joined: Wed Apr 25, 2012 8:52 pm
"interface" in headers vs. task body
This thread is a branch from "Error: Storage size of 'my-interface' isn't known" at https://www.xcore.com/forum/viewtopic.php?f=47&t=4437, since the original theme of that thread was solved.
Last edited by aclassifier on Mon Mar 28, 2016 8:04 am, edited 4 times in total.
-
- XCore Expert
- Posts: 512
- Joined: Wed Apr 25, 2012 8:52 pm
More precisely this thread starts at https://www.xcore.com/forum/viewtopic.p ... 857#p22857
There seems to be some problem with how the compiler expects the header when it's alone in a header file and when it's at the top of the source in the xc file. I will come back with more.
There seems to be some problem with how the compiler expects the header when it's alone in a header file and when it's at the top of the source in the xc file. I will come back with more.
-
- XCore Expert
- Posts: 512
- Joined: Wed Apr 25, 2012 8:52 pm
Problem description (code examples and attachments). The header of the code seems according to how it should be, but I am not able to find a version of the header file head that's also being accepted. Part of this is repetition of the previous thread.
DEFINITIONS:
One header file:
Another header file:
It displays ? here for syntax error, gone if I remove the set return from read:
USAGE
Header file:
ERROR MESSAGE 2
Description Resource Path Location Type
interface declared inside parameter list examples_adafruit_ssd1306_128x32_i2c.h /Aquarium/src line 50 C/C++ Problem
Source file:
Main file:
ERROR MESSAGE 1
Description Resource Path Location Type
incompatible type for argument 2 of `test_display' Aquarium.xc /Aquarium/src line 49 C/C++ Problem
DEFINITIONS:
One header file:
Code: Select all
#define NUM_STARTKIT_ADC_INPUTS 4
#define ADC_PERIOD_TIME_USE 1000
#define NUM_STARTKIT_ADC_NEEDED_DATA_SETS 1000
typedef struct tag_startkit_adc_vals {
unsigned short x[NUM_STARTKIT_ADC_INPUTS];
} t_startkit_adc_vals;
It displays ? here for syntax error, gone if I remove the set return from read:
Code: Select all
typedef interface startkit_adc_user_handle { //startkit_adc_user_handle {
[[guarded]] void trigger (void);
[[guarded]][[clears_notification]] {unsigned int, unsigned int} read (t_startkit_adc_vals return_adc_vals); // adc_cnt, no_adc_cnt
[[notification]] slave void complete (void);
} startkit_adc_user_handle_if;
[[combinable]]
void startKIT_adc_user_handle (
const unsigned int Num_of_data_sets,
client startkit_adc_acquire_if i_startkit_adc_acquire,
server startkit_adc_user_handle_if i_startkit_adc_user_handle);
Header file:
ERROR MESSAGE 2
Description Resource Path Location Type
interface declared inside parameter list examples_adafruit_ssd1306_128x32_i2c.h /Aquarium/src line 50 C/C++ Problem
Code: Select all
[[combinable]]
extern void test_display (
client interface delay_if i_delay, // If not "interface" here then "parse error before "i_delay""
50 client interface startkit_adc_user_handle_if i_startkit_adc_user_handle,
chanend c_button_left,
chanend c_button_center,
chanend c_button_right);
Code: Select all
[[combinable]]
void test_display (
client delay_if i_delay, // "interface" here seems to make no difference
client startkit_adc_user_handle_if i_startkit_adc_user_handle, // "interface" here seems to make no difference
chanend c_button_left,
chanend c_button_center,
chanend c_button_right)
//client interface startkit_adc_acquire_if i_startkit_adc_acquire)
{
// code
}
ERROR MESSAGE 1
Description Resource Path Location Type
incompatible type for argument 2 of `test_display' Aquarium.xc /Aquarium/src line 49 C/C++ Problem
Code: Select all
int main () {
chan c_button_left;
chan c_button_center;
chan c_button_right;
interface delay_if i_delay;
//
chan c_analogue;
startkit_adc_acquire_if i_startkit_adc_acquire;
startkit_adc_user_handle_if i_startkit_adc_user_handle;
par {
49 on tile[0].core[0]: test_display (i_delay, i_startkit_adc_user_handle, c_button_left, c_button_center, c_button_right);
on tile[0].core[1]: inP_Button_Task (BUTTON_LEFT, inP_button_left, c_button_left);
on tile[0].core[1]: inP_Button_Task (BUTTON_CENTER, inP_button_center, c_button_center);
on tile[0].core[1]: inP_Button_Task (BUTTON_RIGHT, inP_button_right, c_button_right);
on tile[0].core[2]: startKIT_adc_user_handle (NUM_STARTKIT_ADC_NEEDED_DATA_SETS, i_startkit_adc_acquire, i_startkit_adc_user_handle);
on tile[0].core[3]: server_delay_iff(i_delay);
on tile[0].core[4]: adc_task (i_startkit_adc_acquire, c_analogue, ADC_PERIOD_TIME_USEC);
startkit_adc (c_analogue); // Declare the ADC service (this is the ADC hardware, not a task)
}
You do not have the required permissions to view the files attached to this post.
-
- XCore Expert
- Posts: 512
- Joined: Wed Apr 25, 2012 8:52 pm
No solution yet.
I tried to make the adc client a library module instead of just a file in my project, in the hope that the compiler saw that use pattern as different. No change.
Along the way I made the interface 100% equal to the startKIT adc interface, so that I could plug and unplug my in-between client by just a few commenting in and out. It's easy to switch between the error and the ok.
To me this is now starting to look like a tool problem.
I tried to make the adc client a library module instead of just a file in my project, in the hope that the compiler saw that use pattern as different. No change.
Along the way I made the interface 100% equal to the startKIT adc interface, so that I could plug and unplug my in-between client by just a few commenting in and out. It's easy to switch between the error and the ok.
To me this is now starting to look like a tool problem.
-
- Experienced Member
- Posts: 104
- Joined: Fri Dec 11, 2009 8:29 pm
I think this is still the same issue as in the other thread. You have an interface named startkit_adc_user_handle and a typedef named startkit_adc_user_handle_if.
The header is wrong it should be:
or
These two are equivalent according to the typedef.
Alternatively, you can rename your interface and typedef to have the same name in which case either putting the interface keyword before the name or not will work.
The header is wrong it should be:
Code: Select all
[[combinable]]
extern void test_display (
client interface delay_if i_delay,
client startkit_adc_user_handle_if i_startkit_adc_user_handle,
chanend c_button_left,
chanend c_button_center,
chanend c_button_right);
Code: Select all
[[combinable]]
extern void test_display (
client interface delay_if i_delay,
client interface startkit_adc_user_handle i_startkit_adc_user_handle,
chanend c_button_left,
chanend c_button_center,
chanend c_button_right);
Alternatively, you can rename your interface and typedef to have the same name in which case either putting the interface keyword before the name or not will work.
-
- XCore Expert
- Posts: 512
- Joined: Wed Apr 25, 2012 8:52 pm
If I instead move a dummy structure of the code into the main file, it compiles fine.
I find it rather strange that in test_dummy "interface" is needed for the first interface and not allowed for the second!
Here's the code:
I find it rather strange that in test_dummy "interface" is needed for the first interface and not allowed for the second!
Here's the code:
Code: Select all
/*
#include <platform.h>
#include <xs1.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#//include <iso646.h>
#include <xccompat.h> // REFERENCE_PARAMs
#include "i2c.h"
#include "startkit_adc.h"
#include "random.h" // xmos. ALso uses "random_conf.h"
//
#include "defines_adafruit.h"
#include "module_adafruit_SSD1306.h"
#include "button_press.h"
#include "module_cancelable_delay.h"
#include "param.h"
//
#include "examples_adafruit_ssd1306_128x32_i2c.h"
#include "lib_startkit_adc_client.h"
port inP_button_left = on tile[0]:XS1_PORT_1N; // P1N0, X0D37 B_Left
port inP_button_center = on tile[0]:XS1_PORT_1O; // P1O0, X0D38 B_Center
port inP_button_right = on tile[0]:XS1_PORT_1P; // P11P, X0D39 B_Right
[[combinable]]
void test_dummy (
client interface delay_if i_delay,
client lib_startkit_adc_client_if i_lib_startkit_adc_client,
chanend c_button_left,
chanend c_button_center,
chanend c_button_right)
{
while(1) {
select
{
case i_lib_startkit_adc_client.complete():
{
break;
}
}
}
}
int main () {
chan c_button_left;
chan c_button_center;
chan c_button_right;
interface delay_if i_delay;
//
chan c_analogue;
startkit_adc_acquire_if i_startkit_adc_acquire;
lib_startkit_adc_client_if i_lib_startkit_adc_client;
par {
on tile[0].core[0]: test_dummy (i_delay, i_lib_startkit_adc_client, c_button_left, c_button_center, c_button_right);
on tile[0].core[1]: inP_Button_Task (BUTTON_LEFT, inP_button_left, c_button_left);
on tile[0].core[1]: inP_Button_Task (BUTTON_CENTER, inP_button_center, c_button_center);
on tile[0].core[1]: inP_Button_Task (BUTTON_RIGHT, inP_button_right, c_button_right);
on tile[0].core[2]: lib_startKIT_adc_client (NUM_STARTKIT_ADC_NEEDED_DATA_SETS, i_startkit_adc_acquire, i_lib_startkit_adc_client);
on tile[0].core[3]: server_delay_iff(i_delay);
on tile[0].core[4]: adc_task (i_startkit_adc_acquire, c_analogue, ADC_PERIOD_TIME_USEC);
startkit_adc (c_analogue); // Declare the ADC service (this is the ADC hardware, not a task)
}
return 0;
}
-
- XCore Expert
- Posts: 512
- Joined: Wed Apr 25, 2012 8:52 pm
davelacey, thanks for your response above my previous post. I didn't see it or it hadn't bee updated.
I have tried what you said and I am afraid it doesn't help. But when I move the whole thing into the main file it works. I regard this as a tool problem, and am in the process of filing it now.
With your first example I get
- parse error before "i_startkit_adc_user_handle"
- too many arguments to function `test_display'
With your second example I get
- "interface declared inside parameter list"
If I then remove interface I get the same two errors as above
A local full body code like this works, you are right that here any will do. I have new names now since I made a separate library instead (but this did not hide the error):
Another thing:
defines one typedef and one interface? Is that how I should read it? I have watched these tags (the first) for 15 years and never really used then for anything. I assume the usage you describe would be the reasonable way to use these. But what's the purpose?
I have tried what you said and I am afraid it doesn't help. But when I move the whole thing into the main file it works. I regard this as a tool problem, and am in the process of filing it now.
With your first example I get
- parse error before "i_startkit_adc_user_handle"
- too many arguments to function `test_display'
With your second example I get
- "interface declared inside parameter list"
If I then remove interface I get the same two errors as above
A local full body code like this works, you are right that here any will do. I have new names now since I made a separate library instead (but this did not hide the error):
Code: Select all
[[combinable]]
void test_display2 (
client interface delay_if i_delay,
client lib_startkit_adc_client_if i_lib_startkit_adc_client, // Any..
//client interface lib_startkit_adc_client i_lib_startkit_adc_client, // ..will do
chanend c_button_left,
chanend c_button_center,
chanend c_button_right)
{
Code: Select all
typedef interface startkit_adc_user_handle {
// ..
} startkit_adc_user_handle_if;
-
- Experienced Member
- Posts: 104
- Joined: Fri Dec 11, 2009 8:29 pm
Those errors suggest that compiler hasn't seen the interface/typedef declaration at all before the function definition. This, coupled with the your other experiment suggests a header include problem. A couple of things to check (sorry if they seem a bit obvious):aclassifier wrote:davelacey, thanks for your response above my previous post. I didn't see it or it hadn't bee updated.
I have tried what you said and I am afraid it doesn't help. But when I move the whole thing into the main file it works. I regard this as a tool problem, and am in the process of filing it now.
With your first example I get
- parse error before "i_startkit_adc_user_handle"
- too many arguments to function `test_display'
With your second example I get
- "interface declared inside parameter list"
If I then remove interface I get the same two errors as above
1) Are you idempotent defines (i.e. the #ifndef _my_header_h_ ... bits at the start and end) in the headers all unique?
2) Do you accidentally have a mutally recursive header inclusions? (check the source location trace in the error message)
You can add the -save-temps flag to the XCC_FLAGS variable in the Makefile and it will put the preprocessed source files (.xi files) in the .build folder of the project so you can have a look at what the compiler is seeing after all the include files have been included.
-
- XCore Expert
- Posts: 512
- Joined: Wed Apr 25, 2012 8:52 pm
Again, only saw it now. I don't think any of that goes. But I will investigate further. Will be back. Thanks!davelacey wrote:Those errors suggest that compiler hasn't seen the interface/typedef declaration at all before the function definition. This, coupled with the your other experiment suggests a header include problem. A couple of things to check (sorry if they seem a bit obvious):aclassifier wrote:davelacey, thanks for your response above my previous post. I didn't see it or it hadn't bee updated.
I have tried what you said and I am afraid it doesn't help. But when I move the whole thing into the main file it works. I regard this as a tool problem, and am in the process of filing it now.
With your first example I get
- parse error before "i_startkit_adc_user_handle"
- too many arguments to function `test_display'
With your second example I get
- "interface declared inside parameter list"
If I then remove interface I get the same two errors as above
1) Are you idempotent defines (i.e. the #ifndef _my_header_h_ ... bits at the start and end) in the headers all unique?
2) Do you accidentally have a mutally recursive header inclusions? (check the source location trace in the error message)
You can add the -save-temps flag to the XCC_FLAGS variable in the Makefile and it will put the preprocessed source files (.xi files) in the .build folder of the project so you can have a look at what the compiler is seeing after all the include files have been included.
Last edited by aclassifier on Mon Mar 28, 2016 3:14 pm, edited 1 time in total.
-
- XCore Expert
- Posts: 512
- Joined: Wed Apr 25, 2012 8:52 pm
After having added -save-temps and run "defaults write com.apple.finder AppleShowAllFiles YES" in OS X Terminal and restarted Finder I found the .build directory and the Aquarium.xi. I can see there that as I change in the source of the include file the Aquarium.xi follows the source.aclassifier wrote:Again, only saw it now. I don't think any of that goes. But I will investigate further. Will be back. Thanks!davelacey wrote:Those errors suggest that compiler hasn't seen the interface/typedef declaration at all before the function definition. This, coupled with the your other experiment suggests a header include problem. A couple of things to check (sorry if they seem a bit obvious):aclassifier wrote:davelacey, thanks for your response above my previous post. I didn't see it or it hadn't bee updated.
I have tried what you said and I am afraid it doesn't help. But when I move the whole thing into the main file it works. I regard this as a tool problem, and am in the process of filing it now.
With your first example I get
- parse error before "i_startkit_adc_user_handle"
- too many arguments to function `test_display'
With your second example I get
- "interface declared inside parameter list"
If I then remove interface I get the same two errors as above
1) Are you idempotent defines (i.e. the #ifndef _my_header_h_ ... bits at the start and end) in the headers all unique?
2) Do you accidentally have a mutally recursive header inclusions? (check the source location trace in the error message)
You can add the -save-temps flag to the XCC_FLAGS variable in the Makefile and it will put the preprocessed source files (.xi files) in the .build folder of the project so you can have a look at what the compiler is seeing after all the include files have been included.