Git Product home page Git Product logo

mac-can / kvasercan-library Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 2.0 7.59 MB

macOS® Driver and SDK for USB CAN Interfaces from Kvaser

Home Page: https://mac-can.github.io/drivers/KvaserCAN/

License: BSD 2-Clause "Simplified" License

Makefile 1.05% C 21.55% C++ 52.80% Shell 0.12% Swift 1.77% Objective-C 0.21% Objective-C++ 22.24% Python 0.26%
can can-bus kvaser kvaser-interface macos usb iousbkit macos-driver can-fd

kvasercan-library's Introduction

Running CAN and CAN FD on Mac is the mission of the MacCAN project. There are many companies offering multifarious CAN hardware and CAN software. Unfortunately, few of them provide a driver for the Mac.

UV Software provides macOS® user-space drivers for USB-to-CAN interfaces from various vendors.

CAN API V3 on macOS® macOS® CAN User-Space Drivers:

See the MacCAN GitHub Pages website to learn more about the entire MacCAN project and its sub-projects.

A generic documentation of the CAN API V3 application programming interface can be found here.

Copyright © 2021-2024 Uwe Vogt, UV Software, Berlin.

kvasercan-library's People

Contributors

mac-can avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kvasercan-library's Issues

Time stamp overflow

Leaf devices

Devices from Leaf device family provide a 48-bit counter running at 48 MHz for hardware time stamps. This counter will overflow after 3:15:28.124 hours.

Mhydra devices

Devices from Mhydra device family provide a 64-bit counter running at 80 MHz which will overflow after 2668 days and 19:11:40.921 hours (approx. 7.3 years).

Test case "Set CAN FD bus params with field `data.tseg2` set to invalid value" failed

Findings:
Function KvaserCAN_SetBusParamsFd accepts invalid value 17 in field data.tseg2 of parameter params (KvaserUSB_BusParamsFd_t).

Remarks:
According to CAN FD specification the valid range for data phase parameter tseg2 shall be 1 to 16.

Affected:

  • Leaf Pro HS v2
  • Hybrid Pro 2x CAN/LIN

Rootcause:
The function itself does not check the range of the data field in the structure KvaserUSB_BusParamsFd_t The affected devices (and only the affected devices) do not response with an error when given an invalid value in field data.tseg2.

Comment:
This behavior on driver level is assessed as a minor issue, because sanity checks for CAN FD bit-rate settings are implemented on user level (CAN API V3).

Testcase:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TC19: Set CAN FD bus params with field 'data.tseg2' set to invalid value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
expected: Not CANUSB_SUCCESS

note: this test requires a CAN FD capable device

pre:
- initialize DUT1 with configured settings

test: loop over selected invalid bus params
- sub(1): 1Mbps : 8Mbps with field 'data.tseg2' set to 255
- sub(2): 500kbps : 4Mbps with field 'data.tseg2' set to 17
- sub(3): 250kbps : 2Mbps with field 'data.tseg2' set to 255
- sub(4): 125kbps : 1Mbps with field 'data.tseg2' set to 17
-- try to set invalid bus params into DUT1
-- if nevertheless successful get bus params from DUT1
-- and compare set and get bus params

post:
- shutdown DUT1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note: Value 255 is recognized as invalid by the affected devices and the corresponding sub-testcase passed.

Wrong calculation of CAN bus parameters for devices with 24MHz CAN clock

Bit-rate settings of CAN API V3 are based on the CAN clock (frequency) and a prescaler besides two time segments to determine the sample point, while Kvaser´s bus parameters are giving directly the bit-rate as well as the two time segments to determine the sample point.

Findings:

  1. If the specified CAN clock (type can_bitrate_t field frequency) does not match the clock of the CAN interface, this could result in a non-intended CAN bit-rate due to the internal conversion to corresponding bus parameters without clock reference.
  2. The conversion of bus parameters (type KvaserUSB_BusParams_t) to CAN API bit-rate settings assumes a fixed CAN clock of 80 MHz for all CAN interfaces. The result shows in this case for CAN interfaces running with 24 MHz (or not running with 80 MHz) a wrong bit-rate.

Additional information:

  • CAN Library: since Version 0.1
  • CAN Hardware: Leaf Light v2

CAN API Bit-rate Settings:

typedef union can_bitrate_t_ {
    int32_t index;                      /**< index to predefined bit-rate (<= 0) */
    struct {                            /*   bit-timing register: */
        int32_t frequency;              /**<   clock domain (frequency in [Hz]) */
        struct {                        /*     nominal bus speed: */
            uint16_t brp;               /**<     bit-rate prescaler */
            uint16_t tseg1;             /**<     TSEG1 segment */
            uint16_t tseg2;             /**<     TSEG2 segment */
            uint16_t sjw;               /**<     synchronization jump width */
            uint8_t  sam;               /**<     number of samples (SJA1000) */
        } nominal;                      /**<   nominal bus speed */
        struct {                        /*     data bus speed: */
            uint16_t brp;               /**<     bit-rate prescaler */
            uint16_t tseg1;             /**<     TSEG1 segment */
            uint16_t tseg2;             /**<     TSEG2 segment */
            uint16_t sjw;               /**<     synchronization jump width */
        } data;                         /**<   data bus speed */
    } btr;                              /**< bit-timing register */
} can_bitrate_t;

Kvaser CAN Bus Parameters:

typedef struct kvaser_bus_params_t_ {   /* bus parameter: */
    uint32_t bitRate;                   /* - bit rate (in [Hz]) */
    uint8_t  tseg1;                     /* - time segment 1 */
    uint8_t  tseg2;                     /* - time segment 2 */
    uint8_t  sjw;                       /* - synchronization jump width */
    uint8_t  noSamp;                    /* - number of sample points */
} KvaserUSB_BusParams_t;

Problem on Mac book pro (M1 Pro chip)

Hello,

I have sent you an email directly and you kindly reply, but because I still have the problem, I found it could be a good idea to fill in an issue ?

I am trying to make my Kvaser Leaf work on my Mac M1 on Ventura, but I get this output

CAN API V3 for Kvaser CAN Interfaces, Version 0.3.1 (0xaaa925f)
myDriver.GetProperty(CANPROP_GET_SPEC): value = 3.0
myDriver.GetProperty(CANPROP_GET_VERSION): value = 0.3
myDriver.GetProperty(CANPROP_GET_PATCH_NO): value = 1
myDriver.GetProperty(CANPROP_GET_BUILD_NO): value = aaa925f
myDriver.GetProperty(CANPROP_GET_LIBRARY_ID): value = 600
myDriver.GetProperty(CANPROP_GET_LIBRARY_DLLNAME): value = 'libUVCANKVL.dylib'
myDriver.GetProperty(CANPROP_GET_LIBRARY_VENDOR): value = 'UV Software, Berlin'
Loading the MacCAN driver...
- Run loop started so notifications will be received
+++ Unable to open device #0 (device not present)
+++ MacCAN-Core: device could not be opened (00)
+++ error: myDriver.InitializeChannel(0) returned -95
Cheers!
Program ended with exit code: 161

I have made tests with :

  • Memorator pro 5 5xHS : EAN 73-30130-00778-9
  • USBcan leaf 4xHS : EAN 73-30130-00831-1
  • USBcan Light 2xHS : EAN 73-30130-00714-7
    And on :
  • MacBook Pro
  • Apple M1 Pro
  • Ventura 13..1

Any idea ?

Thanks for your help and the work done !

Jacques

Flags for transmit messages cannot be set with the Swift wrapper

Stupidly, there is a copy-paste error in the CAN API Swift wrapper that prevents to set message flags other than standard frames for transmit messages.

Wrong:

    public struct Message {
        public struct Flags: OptionSet {
            // message flags as option set
            public static let StandardFrame = Flags([])
            public static let ExtendedFrame = Mode(rawValue: 0x01)
            public static let RemoteFrame = Mode(rawValue: 0x02)
            public static let CanFdLongFrame = Mode(rawValue: 0x04)
            public static let CanFdFastFrame = Mode(rawValue: 0x08)
            // message flags from C interface
            ...

Much better:

    public struct Message {
        public struct Flags: OptionSet {
            // message flags as option set
            public static let StandardFrame = Flags([])
            public static let ExtendedFrame = Flags(rawValue: 0x01)
            public static let RemoteFrame = Flags(rawValue: 0x02)
            public static let CanFdLongFrame = Flags(rawValue: 0x04)
            public static let CanFdFastFrame = Flags(rawValue: 0x08)
            // message flags from C interface
            ...

MAC M1 Pro Kvaser Leaf Light v2 Timeout error.

I downloaded and built v0.3.1 and seem to be stuck with an interface timeout error. I get a similar error with the can_moni and can_test programs. Below is the result of kvl_test TEST INFO which i saw was the most informative from other posts/issues.

Any help appreciated.

dtravis@Dexter-MacBook-Pro KvaserCAN-Library % ./Trial/kvl_test TEST INFO
>>> CAN API V3 for Kvaser CAN Interfaces, Version 0.3.1 (0xaaa925f)
>>> myDriver.GetProperty(CANPROP_GET_SPEC): value = 3.0
>>> myDriver.GetProperty(CANPROP_GET_VERSION): value = 0.3
>>> myDriver.GetProperty(CANPROP_GET_PATCH_NO): value = 1
>>> myDriver.GetProperty(CANPROP_GET_BUILD_NO): value = aaa925f
>>> myDriver.GetProperty(CANPROP_GET_LIBRARY_ID): value = 600
>>> myDriver.GetProperty(CANPROP_GET_LIBRARY_DLLNAME): value = 'libUVCANKVL.dylib'
>>> myDriver.GetProperty(CANPROP_GET_LIBRARY_VENDOR): value = 'UV Software, Berlin'
    Loading the MacCAN driver...
    - One device added at location 02140000
      - Device #0: Kvaser Leaf Light v2
        - Properties: vendor = bfd, product = 120, release = 0001, speed = 2
    - Run loop started so notifications will be received
>>> CCanAPI::ProbeChannel(0): state = available
+++ Sorry, device #1 is not available
>>> CCanAPI::ProbeChannel(1): state = not available
+++ Sorry, device #2 is not available
>>> CCanAPI::ProbeChannel(2): state = not available
+++ Sorry, device #3 is not available
>>> CCanAPI::ProbeChannel(3): state = not available
+++ Sorry, device #4 is not available
>>> CCanAPI::ProbeChannel(4): state = not available
+++ Sorry, device #5 is not available
>>> CCanAPI::ProbeChannel(5): state = not available
+++ Sorry, device #6 is not available
>>> CCanAPI::ProbeChannel(6): state = not available
+++ Sorry, device #7 is not available
>>> CCanAPI::ProbeChannel(7): state = not available
      + Device #0: asynchronous event source added to run loop
        - Message pipe of size 512 bytes
        - Message queue for 65536 elements of size 88 bytes
        - Double buffer each of size 512 bytes for endpoint #1
    Initializing Kvaser Leaf Light v2 driver...
>>> Kvaser Leaf Light v2 (device #0): stop chip (go bus OFF)
>>> Kvaser Leaf Light v2 (device #0): set driver mode NORMAL
>>> Kvaser Leaf Light v2 (device #0): trigger chip state event
+++ Kvaser Leaf Light v2 (device #0): card information could not be read (-50)
+++ Sorry, device #0 is not opened or not available
+++ error: myDriver.InitializeChannel(0) returned -50
Cheers!
dtravis@Dexter-MacBook-Pro KvaserCAN-Library % ./Binaries/can_moni 'Kvaser CAN Channel 0' --baudrate=500 --mode=2.0 -v
CAN Monitor for Kvaser CAN Interfaces, Version 0.3.1 (0xaaa925f)
Copyright (c) 2007,2020-2022 by Uwe Vogt, UV Software, Berlin

This program comes with ABSOLUTELY NO WARRANTY!

This is free software, and you are welcome to redistribute it
under certain conditions; type `--version' for details.

Op.-mode=CAN2.0 (op_mode=00h)
[email protected]% (f_clock=8000000,nom_brp=1,nom_tseg1=13,nom_tseg2=2,nom_sjw=1,nom_sam=0)

Hardware=Kvaser CAN Channel 0...FAILED!
+++ error: CAN Controller could not be initialized (-50)
Copyright (c) 2007,2020-2022 by Uwe Vogt, UV Software, Berlin

Occasionally the device is not recognized immediately after power-on or awake from hibernation

Occasionally the device is not recognized immediately after power-on or awake from hibernation:

+++ Unable to find interfaces on device #0: e00002bc
+++ error: myDriver.InitializeChannel(0) returned -95

It seems that there is no iterator available to create the device interface for the interface (file MacCAN_IOUsbKit.c, line 1698, rev. 1006).

Workaround:

  • Start the application again, and everything works fine.

Action points:

  • Further investigation required.

Additional information:

  • CAN Library: MacCAN-KvaserCAN Version 0.1 (Commit 64e4388 of June 3, 2021)
  • CAN Hardware: Kvaser Leaf Light v2 and Kvaser Leaf Pro HS v2
  • Mac Hardware: MacBook Pro (2019, x86_64 architecture) running macOS 11.4

Test case "Set CAN FD bus params with field `data.tseg1` set to invalid value" failed

Findings:
Function KvaserCAN_SetBusParamsFd accepts invalid value 33 in field data.tseg1 of parameter params (KvaserUSB_BusParamsFd_t).

Remarks:
According to CAN FD specification the valid range for data phase parameter tseg1 shall be 1 to 32.

Affected:

  • Leaf Pro HS v2
  • Hybrid Pro 2x CAN/LIN

Rootcause:
The function itself does not check the range of the data field in the structure KvaserUSB_BusParamsFd_t. The affected devices (and only the affected devices) do not response with an error when given an invalid value in field data.tseg1.

Comment:
This behavior on driver level is assessed as a minor issue, because sanity checks for CAN FD bit-rate settings are implemented on user level (CAN API V3).

Testcase:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TC17: Set CAN FD bus params with field 'data.tseg1' set to invalid value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
expected: Not CANUSB_SUCCESS

note: this test requires a CAN FD capable device

pre:
- initialize DUT1 with configured settings

test: loop over selected invalid bus params
- sub(1): 1Mbps : 8Mbps with field 'data.tseg1' set to 33
- sub(2): 500kbps : 4Mbps with field 'data.tseg1' set to 255
- sub(3): 250kbps : 2Mbps with field 'data.tseg1' set to 255
- sub(4): 125kbps : 1Mbps with field 'data.tseg1' set to 33
-- try to set invalid bus params into DUT1
-- if nevertheless successful get bus params from DUT1
-- and compare set and get bus params

post:
- shutdown DUT1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note: Value 255 is recognized as invalid by the affected devices and the corresponding sub-testcase passed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.