Skip to content

Commit

Permalink
correct feature/mode flags, fix dlc=8 bug in dlc2len
Browse files Browse the repository at this point in the history
  • Loading branch information
ericevenchick committed Sep 9, 2020
1 parent f3708c7 commit 66122d7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
6 changes: 3 additions & 3 deletions sources/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int can_len2dlc(uint8_t len) {
return 0;
}
int can_dlc2len(uint8_t dlc) {
if (dlc < 8) {
if (dlc <= 8) {
return dlc;
} else if (dlc == 9) {
return 12;
Expand Down Expand Up @@ -182,11 +182,11 @@ int can_start(uint8_t channel, uint32_t flags) {

MCAN_GetDefaultConfig(&config);
monitor_mode[channel] = 0;
if (flags & GS_CAN_FEATURE_LISTEN_ONLY) {
if (flags & GS_CAN_MODE_LISTEN_ONLY) {
config.enableBusMon = true;
monitor_mode[channel] = 1;
}
if (flags & GS_CAN_FEATURE_LOOP_BACK) {
if (flags & GS_CAN_MODE_LOOP_BACK) {
config.enableLoopBackExt = true;
}
if (flags & GS_CAN_MODE_FD) {
Expand Down
10 changes: 8 additions & 2 deletions sources/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,14 @@ void APPTask(void) {
while (rx_frames_index > 0) {
primask = DisableGlobalIRQ();
rx_frames_index--;
usb_send((uint8_t*) &rx_frames[rx_frames_index],
sizeof(struct gs_host_frame));
if (rx_frames[rx_frames_index].flags & GS_CAN_FLAG_FD) {
usb_send((uint8_t*) &rx_frames[rx_frames_index],
sizeof(struct gs_host_frame));
} else {
// send correct size for non-FD frame
usb_send((uint8_t*) &rx_frames[rx_frames_index],
sizeof(struct gs_host_frame_non_fd));
}
EnableGlobalIRQ(primask);
}
}
Expand Down
42 changes: 29 additions & 13 deletions usb/device/class/gs_usb/gs_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ struct gs_device_config {
uint32_t hw_version;
};

#define GS_CAN_MODE_NORMAL 0
#define GS_CAN_MODE_LISTEN_ONLY BIT(0)
#define GS_CAN_MODE_LOOP_BACK BIT(1)
#define GS_CAN_MODE_TRIPLE_SAMPLE BIT(2)
#define GS_CAN_MODE_ONE_SHOT BIT(3)
#define GS_CAN_MODE_FD BIT(4)
#define GS_CAN_MODE_NORMAL 0
#define GS_CAN_MODE_LISTEN_ONLY BIT(0)
#define GS_CAN_MODE_LOOP_BACK BIT(1)
#define GS_CAN_MODE_TRIPLE_SAMPLE BIT(2)
#define GS_CAN_MODE_ONE_SHOT BIT(3)
#define GS_CAN_MODE_HW_TIMESTAMP BIT(4)
#define GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE BIT(7)
#define GS_CAN_MODE_FD BIT(8)

struct gs_device_mode {
uint32_t mode;
Expand All @@ -89,13 +91,15 @@ struct gs_identify_mode {
};

#define BIT(X) (1<<X)
#define GS_CAN_FEATURE_LISTEN_ONLY BIT(0)
#define GS_CAN_FEATURE_LOOP_BACK BIT(1)
#define GS_CAN_FEATURE_TRIPLE_SAMPLE BIT(2)
#define GS_CAN_FEATURE_ONE_SHOT BIT(3)
#define GS_CAN_FEATURE_HW_TIMESTAMP BIT(4)
#define GS_CAN_FEATURE_IDENTIFY BIT(5)
#define GS_CAN_FEATURE_FD BIT(6)
#define GS_CAN_FEATURE_LISTEN_ONLY BIT(0)
#define GS_CAN_FEATURE_LOOP_BACK BIT(1)
#define GS_CAN_FEATURE_TRIPLE_SAMPLE BIT(2)
#define GS_CAN_FEATURE_ONE_SHOT BIT(3)
#define GS_CAN_FEATURE_HW_TIMESTAMP BIT(4)
#define GS_CAN_FEATURE_IDENTIFY BIT(5)
#define GS_CAN_FEATURE_USER_ID BIT(6)
#define GS_CAN_FEATURE_PAD_PKTS_TO_MAX_PKT_SIZE BIT(7)
#define GS_CAN_FEATURE_FD BIT(8)

struct gs_device_bt_const {
uint32_t feature;
Expand Down Expand Up @@ -127,6 +131,18 @@ struct gs_host_frame {
uint8_t data[64];
};

struct gs_host_frame_non_fd {
uint32_t echo_id;
uint32_t can_id;

uint8_t can_dlc;
uint8_t channel;
uint8_t flags;
uint8_t reserved;

uint8_t data[8];
};

struct gs_usb_dev {
struct gs_host_config host_config;
uint32_t sof_timestamp_us;
Expand Down
8 changes: 5 additions & 3 deletions usb/device/class/gs_usb/gs_usb_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ static const struct gs_device_config device_config = { 0, // reserved 1

// bit timing constraints
static const struct gs_device_bt_const can_dev_bt_const = {
GS_CAN_FEATURE_LISTEN_ONLY // supported features
| GS_CAN_FEATURE_LOOP_BACK | GS_CAN_FEATURE_HW_TIMESTAMP
| GS_CAN_FEATURE_IDENTIFY | GS_CAN_FEATURE_FD,
// supported features
GS_CAN_FEATURE_LISTEN_ONLY |
GS_CAN_FEATURE_LOOP_BACK |
GS_CAN_FEATURE_IDENTIFY |
GS_CAN_FEATURE_FD,
24000000, // can timing base clock
1, // tseg1 min
16, // tseg1 max
Expand Down

1 comment on commit 66122d7

@fxj000
Copy link

@fxj000 fxj000 commented on 66122d7 Oct 18, 2020

Choose a reason for hiding this comment

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

Hello, ericevenchick & linklayer,
is there a Windows driver for CANtact pro? I want to test it on my demo board LPC54616, but no driver to support it.
If you have the windows driver, could you please send it to me, thank you. my email: [email protected]

Please sign in to comment.