Hello
I want to send a pointer(who points to an array) over an interface so i can use this array later in the programm.
I managed to create the interface and to send the pointer over the interface. The problem is that at the server interface ( where i receive the pointer ), i don't manage to use the pointer outside the server interface function. After using "select" and "case", i can receive the pointer, (movable) then using " return move(pointer)",the function should return the pointer.
But when i call the function so i can access the pointer to copy the array from the client interface, i have a " conflicting types" error. Note that the pointer points to a double array.
Does someone know what the problem might be ? I just want to access the pointer that has been sent . I already read the Xmos Programming Guide but in the examples, they only use the the pointer within the function.
Thank you
Best regards
Tom
use of a pointer at the server interface
-
- Member
- Posts: 14
- Joined: Mon Jun 19, 2023 9:32 pm
-
- Experienced Member
- Posts: 120
- Joined: Mon Apr 16, 2018 9:14 am
This works for me:
Where temp is an array to transfer.
Code: Select all
case i[int j].set_array(char a[]):
memcpy(a, temp, sizeof(temp));
break;
-
- Member
- Posts: 14
- Joined: Mon Jun 19, 2023 9:32 pm
Thank you for your quick answer
Since temp is the array to transfer in your case, shouldn't it be: case i[int j].set_array(char temp[]), and then temp will be copied in a ?
Since temp is the array to transfer in your case, shouldn't it be: case i[int j].set_array(char temp[]), and then temp will be copied in a ?
-
- Experienced Member
- Posts: 120
- Joined: Mon Apr 16, 2018 9:14 am
It just works for me. In client I use char buffer[]; interface_name.set_array(buffer);
Real code is a bit more complicated, I just shared an idea with you.
I am not sure if pointer is a good idea at all because, for example, there is no shared memory between tiles. Every tile has its own dedicated memory, on physical level.
Real code is a bit more complicated, I just shared an idea with you.
I am not sure if pointer is a good idea at all because, for example, there is no shared memory between tiles. Every tile has its own dedicated memory, on physical level.
-
- Member
- Posts: 14
- Joined: Mon Jun 19, 2023 9:32 pm
I tried to do as you said and this is my code so far ( an example)
with the "task3" function i, receive the array from the interface and copy it in a new array. The interface "cdc_data" can be only be used in a function ( or so they said), also i created a function "receive" that intitalizes cdc_data and then call the function task3. With the function"convert_int32" i do some other conversion, but this isn't the main problem.
The error says " conflicting types" by calling the receive function. Do you know what the issue is and how i can fix that ? As i said , once i receive the array, i just want to copy it or directly uses it outside the function.
Regards
Code: Select all
void task3(server interface my_interface cdc, double data[100])
{
//double data[100];
select{
case cdc.fill_buffer( double a[n], unsigned n):
memcpy(data,a, n*sizeof(double));
break;
case cdc.available_bytes() -> int vjgigi: // case needed
break ;
case cdc.flush_buffer():
break;
}
}
void receive(double data[100]){
interface my_interface cdc_data;
task3(cdc_data,data);
}
void convert_int32( double data[100],int32_t datas[100]){
for (int i =0; i<100; i++){
datas[i]=(int32_t)(Q15(data[i])); // explicit cast
}
}
double data[100]; // array which receive the data sent over interface
int32_t numbers[100];
receive(data);
convert_int32_t(data,numbers);
with the "task3" function i, receive the array from the interface and copy it in a new array. The interface "cdc_data" can be only be used in a function ( or so they said), also i created a function "receive" that intitalizes cdc_data and then call the function task3. With the function"convert_int32" i do some other conversion, but this isn't the main problem.
The error says " conflicting types" by calling the receive function. Do you know what the issue is and how i can fix that ? As i said , once i receive the array, i just want to copy it or directly uses it outside the function.
Regards
-
- Experienced Member
- Posts: 120
- Joined: Mon Apr 16, 2018 9:14 am
As far as I know, this part of the code is wrong:
You need to move your server to main.xc/main() into par section.
I also do not see while(1) before select. It doesn't work that way.
Just look at any simple client-server example. First make it work without array.
Code: Select all
void receive(double data[100]){
interface my_interface cdc_data;
task3(cdc_data,data);
}
I also do not see while(1) before select. It doesn't work that way.
Just look at any simple client-server example. First make it work without array.
-
- Member
- Posts: 14
- Joined: Mon Jun 19, 2023 9:32 pm
I just wanted to send the array from one file (from main.xc) to another file(xc file) so i can use it directly
I thought an interface was the best way to do it. Is there any other way to do it ?
I thought an interface was the best way to do it. Is there any other way to do it ?
-
- Experienced Member
- Posts: 120
- Joined: Mon Apr 16, 2018 9:14 am
XMOS is not like other architectures. Look at examples, believe me, it is made not by idiots. It's very helpful. If you add while(1) to your server task, you can use one core for multiple tasks no problem. Client-server is a powerful tool. It incapsulated inter-core/inter-tile data transfer in a very comfortable way.
So if you need to use a standard way of programming and don't care much about real-time data streaming and processing at hundred MHz, it's better to use ARM processor and a standard ANSI C style. IMHO.
So if you need to use a standard way of programming and don't care much about real-time data streaming and processing at hundred MHz, it's better to use ARM processor and a standard ANSI C style. IMHO.
-
- Experienced Member
- Posts: 120
- Joined: Mon Apr 16, 2018 9:14 am
I think your current code problem has nothing to do with array. You made a server, but I see no client.
-
- Member
- Posts: 14
- Joined: Mon Jun 19, 2023 9:32 pm
Yes the client is in main.xc file . I thought i just needed to add the client where i want to receive the data