Skip to content

Commit

Permalink
examples: linux: Remove uses of global variables
Browse files Browse the repository at this point in the history
Usually considered bad practice and the code is more readable without.

Signed-off-by: Andrew Davis <afd@ti.com>
  • Loading branch information
glneo authored and arnopo committed Jul 21, 2023
1 parent 3b2a0eb commit 7615f43
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
5 changes: 2 additions & 3 deletions examples/linux/rpmsg-echo-test/echo_test.c
Expand Up @@ -30,9 +30,6 @@ struct _payload {
char data[];
};

struct _payload *i_payload;
struct _payload *r_payload;

#define RPMSG_GET_KFIFO_SIZE 1
#define RPMSG_GET_AVAIL_DATA_SIZE 2
#define RPMSG_GET_FREE_SPACE 3
Expand Down Expand Up @@ -91,6 +88,8 @@ int main(int argc, char *argv[])
};
char ept_dev_name[16];
char ept_dev_path[32];
struct _payload *i_payload;
struct _payload *r_payload;

printf("\r\n Echo test start \r\n");
lookup_channel(rpmsg_dev, &eptinfo);
Expand Down
50 changes: 24 additions & 26 deletions examples/linux/rpmsg-mat-mul/mat_mul_demo.c
Expand Up @@ -73,31 +73,25 @@ static void generate_matrices(int num_matrices,

}

static int charfd = -1, fd;
static struct _matrix i_matrix[2];
static struct _matrix r_matrix;

void matrix_mult(int ntimes)
void matrix_mult(int fd)
{
int i;

for (i=0; i < ntimes; i++){
/* Generate two random matrices */
generate_matrices(2, MATRIX_SIZE, i_matrix);

printf("%d: write rpmsg: %lu bytes\n", i, sizeof(i_matrix));
ssize_t rc = write(fd, i_matrix, sizeof(i_matrix));
if (rc < 0)
fprintf(stderr, "write,errno = %ld, %d\n", rc, errno);

puts("read results");
do {
rc = read(fd, &r_matrix, sizeof(r_matrix));
} while (rc < (int)sizeof(r_matrix));
printf(" \r\n Host : Linux : Printing results \r\n");
matrix_print(&r_matrix);
printf("End of Matrix multiplication demo Round %d\n", i);
}
struct _matrix i_matrix[2];
struct _matrix r_matrix;

/* Generate two random matrices */
generate_matrices(2, MATRIX_SIZE, i_matrix);

printf("write rpmsg: %lu bytes\n", sizeof(i_matrix));
ssize_t rc = write(fd, i_matrix, sizeof(i_matrix));
if (rc < 0)
fprintf(stderr, "write,errno = %ld, %d\n", rc, errno);

puts("read results");
do {
rc = read(fd, &r_matrix, sizeof(r_matrix));
} while (rc < (int)sizeof(r_matrix));
printf(" \r\n Host : Linux : Printing results \r\n");
matrix_print(&r_matrix);
}

/*
Expand All @@ -106,6 +100,7 @@ void matrix_mult(int ntimes)
*/
void send_shutdown(int fd)
{
struct _matrix i_matrix[2];
memset(i_matrix, SHUTDOWN_MSG, sizeof(struct _matrix));
if (write(fd, i_matrix, sizeof(i_matrix)) < 0)
perror("write SHUTDOWN_MSG\n");
Expand All @@ -125,7 +120,7 @@ void print_help(void)
int main(int argc, char *argv[])
{
int ntimes = 1;
int opt, ret;
int opt, ret, fd, charfd = -1;
char rpmsg_dev[NAME_MAX] = "virtio0.rpmsg-openamp-demo-channel.-1.0";
char rpmsg_ctrl_dev_name[NAME_MAX] = "virtio0.rpmsg_ctrl.0.0";
char rpmsg_char_name[16];
Expand Down Expand Up @@ -199,7 +194,10 @@ int main(int argc, char *argv[])
}

PR_DBG("matrix_mult(%d)\n", ntimes);
matrix_mult(ntimes);
for (int i = 0; i < ntimes; i++) {
matrix_mult(fd);
printf("End of Matrix multiplication demo Round %d\n", i);
}

send_shutdown(fd);
close(fd);
Expand Down
2 changes: 0 additions & 2 deletions examples/linux/rpmsg-proxy-app/proxy_app.c
Expand Up @@ -29,8 +29,6 @@ struct _proxy_data {
};

static struct _proxy_data *proxy;
char fw_dst_path[] = "/lib/firmware/image_rpc_demo";
char sbuf[512];

int handle_open(struct _sys_rpc *rpc)
{
Expand Down

0 comments on commit 7615f43

Please sign in to comment.