I'd like to transfer an array of bytes across two tiles. I know that data has to be passed by value because of separated RAM on tiles. I wanted to utilize transactions, so i wrote down a simple programm containing two task. First one was sending char array of size 100 over channel and the second recived this data in select statement. First task was also measuring the time taken on the transaction, and it was working fine.
I did also second test. The idea of second test was pretty much the same like in previous example, but insted of transfering byte array I sent a structure. This structure had only one field which was a char array of size 100.
Both of those tests are working correctly but the time taken on sending structure was almost 10 times smaller. Transfering byte array in first test took abaout 0.0095 ms, in comparison time taken on sending structure containing a byte array of the same size took about 0.00090ms.
In my application I have to use variable length array so I cannot sent it as a structure. Why is there so big difference between those two cases. Is there any more efficient way of sending array across the tiles than using transactions?
below is source code of example with the structure
Code: Select all
#include <platform.h>
#include <print.h>
#include <stdint.h>
#include <stdio.h>
#define T_1ms 100000 //<- 1 milisecond
#define PARAM_NB 100 //<- byte array size
typedef struct data_structure
{
char bytes[PARAM_NB];
}data_structure;
// Transactions are used for byte array transfer over channel
// sending transaction
transaction send(chanend c, data_structure &data)
{
c <: data;
}
// data are recived in select statement
transaction event(chanend c, data_structure &data)
{
c :> data;
}
void sender_task(chanend c )
{
/** timers measures time taken on transaction **/
timer stopwach;
uint32_t start, stop;
data_structure structure;
/* initialize byte array to send **/
for(int i =0; i < PARAM_NB; i++) structure.bytes[i] = i;
// Send data over channel and measure the time
stopwach :> start;
master send(c, structure);
stopwach :> stop;
// Print measured time in miliseconds
printstr("Time taken on transaction: ");
printf("%.5f ms \n", ((float)(stop - start))/((float)(T_1ms)));
while(1);
}
void reciver_task(chanend c)
{
/* create byte array the data will be stored to**/
data_structure structure;
while(1)
{
select
{
case slave {event(c, structure);}:
break;
}
}
}
int main(void)
{
chan c;
par{
reciver_task( c );
sender_task( c );
}
return 0;
}
... and the source code of example with the byte array
Code: Select all
#include <platform.h>
#include <print.h>
#include <stdint.h>
#include <stdio.h>
#define T_1ms 100000 //<- 1 milisecond
#define PARAM_NB 100 //<- byte array size
// Transactions are used for byte array transfer over channel
// sending transaction
transaction send(chanend c, char *bytes)
{
for(int i=0;i < PARAM_NB; i++)
c <: bytes[i];
}
// data are recived in select statement
transaction event(chanend c, char *bytes)
{
for(int i=0; i<PARAM_NB; i++)
c :> bytes[i];
}
void sender_task(chanend c )
{
/** timers measures time taken on transaction **/
timer stopwach;
uint32_t start, stop;
/* initialize byte array to send **/
char bytes[PARAM_NB];
for(int i =0; i < PARAM_NB; i++) bytes[i] = i;
// Send data over channel and measure the time
stopwach :> start;
master send(c, bytes);
stopwach :> stop;
// Print measured time in miliseconds
printstr("Time taken on transaction: ");
printf("%.5f ms \n", ((float)(stop - start))/((float)(T_1ms)));
while(1);
}
void reciver_task(chanend c)
{
/* create byte array the data will be stored to**/
char bytes[PARAM_NB];
while(1)
{
select
{
case slave {event(c, bytes);}:
break;
}
}
}
void main(void)
{
chan c;
par{
reciver_task( c );
sender_task( c );
}
}
both of those examples was tested on startKIT device.
Thank you in advance for help, and I am sorry for my bad english
Regards,
Automatyk