Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _targets/Makefile.riscv64-gr765
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Copyright 2025 Phoenix Systems
#

DEFAULT_COMPONENTS := grlib-uart
DEFAULT_COMPONENTS := grlib-uart grlib-can-core grlib-can-driver can-sender-stress can-receiver-stress can-test-app
43 changes: 43 additions & 0 deletions can/grlib-can/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Makefile for Phoenix-RTOS grlib-can
#
# Copyright 2023 Phoenix Systems
#
# %LICENSE%
#
NAME := grlib-can-core
LOCAL_SRCS := grlib-can-core.c
LOCAL_HEADERS := grlib-can-core.h grlib-can-shared.h

include $(static-lib.mk)


NAME := grlib-can-driver
LOCAL_SRCS := grlib-can-driver.c
DEP_LIBS := grlib-can-core

include $(binary.mk)

NAME := grlib-can-if
LOCAL_SRCS := grlib-can-if.c
LOCAL_HEADERS := grlib-can-if.h

include $(static-lib.mk)

NAME := can-test-app
LOCAL_SRCS := can-test-app.c
DEP_LIBS := grlib-can-if

include $(binary.mk)

NAME := can-sender-stress
LOCAL_SRCS := grlib-can-sender-stress-test.c
DEP_LIBS := grlib-can-core

include $(binary.mk)

NAME := can-receiver-stress
LOCAL_SRCS := grlib-can-receiver-stress-test.c
DEP_LIBS := grlib-can-core

include $(binary.mk)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new line at the end of the file

102 changes: 102 additions & 0 deletions can/grlib-can/can-test-app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include <errno.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing file header

#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/debug.h>
#include <sys/file.h>
#include <sys/msg.h>
#include <sys/interrupt.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/threads.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <posix/utils.h>

#include "grlib-can-if.h"

int main(int argc, char **argv)
{
char *canDevice = "/dev/can0";
oid_t canDev;

if (lookup(canDevice, NULL, &canDev) < 0) {
printf("Device does not exist\n");
return EXIT_FAILURE;
}

printf("Successfully checked CAN device oid\n");

printf("Can device open: %d\n", grlibCan_open(canDev));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The return value of grlibCan_open() is printed but not checked for errors. If the device fails to open, the program continues, and subsequent calls will likely fail. It's important to add error handling here.


uint32_t status;
grlibCan_getStatus(canDev, &status);
printf("Can device status: %x\n", status);

grlibCan_config_t config;

grlibCan_getConfig(canDev, &config);
printf("Can device baud rate - nom: %d, data: %d\n", config.nomBdRate, config.dataBdRate);

grlibCan_msg_t frames[10];

frames->frame.head = (1 << 18);
frames->frame.stat = 0x10u << 24;
frames->frame.payload[0] = 0x0F;

for (int i = 1; i < 10; i++) {
memcpy((void *)&frames[i], (void *)frames, sizeof(grlibCan_msg_t));
frames[i].frame.payload[0] = 0x0F + i;
}

int ret = grlibCan_Send(canDev, frames, 10, true);
printf("Can device managed to send %d frames : block\n", ret);

grlibCan_msg_t buf[10];

ret = grlibCan_Recv(canDev, buf, 10, true);
printf("Can device managed to receive %d frames : block\n", ret);

ret = grlibCan_Send(canDev, frames, 10, false);
printf("Can device managed to send %d frames : non-block\n", ret);

ret = grlibCan_Recv(canDev, buf, 10, false);
printf("Can device managed to receive %d frames : non-block\n", ret);

printf("Sending frame of extended length\n");
frames->frame.stat = 0xF0 << 24 | (1 << 2);
ret = grlibCan_Send(canDev, (void *)frames, 5, true);
printf("Ret: %d\n", ret);

printf("Trying to read in SYNC mode to buffer which is to small\n");
ret = grlibCan_Recv(canDev, buf, 1, true);
printf("Ret: %d\n", ret);

printf("Trying to read in SYNC mode to buffer of appropriate size\n");
ret = grlibCan_Recv(canDev, buf, 5, true);
printf("Ret: %d\n", ret);

printf("Sending frame of extended length\n");
frames->frame.stat = 0xF0 << 24 | (1 << 2);
ret = grlibCan_Send(canDev, (void *)frames, 5, true);
printf("Ret: %d\n", ret);

printf("Trying to read in ASYNC mode to buffer which is to small\n");
ret = grlibCan_Recv(canDev, buf, 1, false);
printf("Ret: %d\n", ret);

printf("Trying to read in ASYNC mode to buffer of appropriate size\n");
ret = grlibCan_Recv(canDev, buf, 5, false);
printf("Ret: %d\n", ret);

printf("Closing device\n");
grlibCan_close(canDev);

ret = grlibCan_Send(canDev, frames, 10, true);
printf("Trying to send with device closed: %d\n", ret);

return EXIT_SUCCESS;
}
Loading
Loading