Skip to content

Commit

Permalink
Merge pull request #18 from uv-software/development
Browse files Browse the repository at this point in the history
Release candidate 2 for version 0.3.1
  • Loading branch information
uv-software authored Jun 9, 2024
2 parents d6893a6 + a2f1331 commit 7922988
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 65 deletions.
4 changes: 2 additions & 2 deletions Deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ _All rights reserved._
- Change-log: list all major changes, e.g. from commit comments
- Assets: drag and drop the artifacts archive (see above)
3. Click on `Publish release`.
4. That's all folks!
4. That´s all folks!

### Announcement
## Announce the new Release

1. Create a new post with the change-log in the `mac-can.github.io` repo.
2. Update the KvaserCAN-Wrapper page in the `mac-can.github.io` repo.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### CAN API V3 Wrapper Library for Kvaser CAN Interfaces (Windows®)

_Copyright © 2017-2024 Uwe Vogt, UV Software, Berlin ([email protected])_
_Copyright © 2017-2024 Uwe Vogt, UV Software, Berlin ([email protected])_

![MSBuild](https://github.com/uv-software/KvaserCAN-Wrapper/actions/workflows/msbuild.yml/badge.svg)

Expand Down
2 changes: 1 addition & 1 deletion Sources/KvaserCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CANCPP CKvaserCAN : public CCanApi {
// CKvaserCAN-specific error codes (CAN API V3 extension)
enum EErrorCodes {
// note: range 0...-99 is reserved by CAN API V3
GeneralError = VendorSpecific, ///< mapped Kvaser CANlib error codes
GeneralError = VendorSpecific
};
// CCanApi overrides
static bool GetFirstChannel(SChannelInfo &info, void *param = NULL);
Expand Down
44 changes: 12 additions & 32 deletions Sources/KvaserCAN_Defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,6 @@ extern "C" {
/* ----------- options ------------------------------------------------
*/

/** @name Compiler Switches
* @brief Options for conditional compilation.
* @{ */
/** @note Set define OPTION_KVASER_BIT_TIMING to a non-zero value to compile
* with non CiA bit-timing (e.g. in the build environment).
*/
#ifndef OPTION_DISABLED
#define OPTION_DISABLED 0 /**< if a define is not defined, it is automatically set to 0 */
#endif
#ifndef OPTION_KVASER_BIT_TIMING
#define OPTION_KVASER_BIT_TIMING OPTION_DISABLED
#endif
#if (OPTION_KVASER_BIT_TIMING != OPTION_DISABLED)
#ifdef _MSC_VER
#pragma message ( "Compilation with non CiA bit-timming!" )
#else
#warning Compilation with non CiA bit-timming!
#endif
#endif
/** @} */

/* ----------- defines ------------------------------------------------
*/
Expand All @@ -100,23 +80,23 @@ extern "C" {
/** @name Kvaser CAN 2.0 Bit-rate Settings
* @brief Default values (not compatible to CiA CANopen DS-301 spec.).
* @{ */
#define KVASER_CAN_BR_1M(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp= 1;x.btr.nominal.tseg1= 5;x.btr.nominal.tseg2= 2;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_800K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp= 1;x.btr.nominal.tseg1= 7;x.btr.nominal.tseg2= 2;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_500K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp= 2;x.btr.nominal.tseg1= 5;x.btr.nominal.tseg2= 2;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_250K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp= 4;x.btr.nominal.tseg1= 5;x.btr.nominal.tseg2= 2;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_125K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp= 4;x.btr.nominal.tseg1=11;x.btr.nominal.tseg2= 4;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_100K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp= 5;x.btr.nominal.tseg1=11;x.btr.nominal.tseg2= 4;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_50K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=10;x.btr.nominal.tseg1=11;x.btr.nominal.tseg2= 4;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_20K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=25;x.btr.nominal.tseg1=11;x.btr.nominal.tseg2= 4;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_10K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=50;x.btr.nominal.tseg1=11;x.btr.nominal.tseg2= 4;x.btr.nominal.sjw= 1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_1M(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=1; x.btr.nominal.tseg1=5; x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_800K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=1; x.btr.nominal.tseg1=7; x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_500K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=2; x.btr.nominal.tseg1=5; x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_250K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=4; x.btr.nominal.tseg1=5; x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_125K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=4; x.btr.nominal.tseg1=11;x.btr.nominal.tseg2=4;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_100K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=5; x.btr.nominal.tseg1=11;x.btr.nominal.tseg2=4;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_50K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=10; x.btr.nominal.tseg1=11;x.btr.nominal.tseg2=4;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_20K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=25; x.btr.nominal.tseg1=11;x.btr.nominal.tseg2=4;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_10K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=50; x.btr.nominal.tseg1=11;x.btr.nominal.tseg2=4;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
#define KVASER_CAN_BR_5K(x) do{x.btr.frequency=KVASER_CAN_CLOCK;x.btr.nominal.brp=100;x.btr.nominal.tseg1=11;x.btr.nominal.tseg2=4;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0)
/** @} */

#if (OPTION_CAN_2_0_ONLY == 0)
/** @name Kvaser CAN FD Bit-rate Settings w/o Bit-rate Switching
* @brief Default values for long frames only (0 to 64 bytes).
* @{ */
#define KVASER_CAN_FD_BR_1M(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=31;x.btr.nominal.tseg2= 8;x.btr.nominal.sjw= 8;} while(0)
#define KVASER_CAN_FD_BR_1M(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=31;x.btr.nominal.tseg2=8; x.btr.nominal.sjw=8; } while(0)
#define KVASER_CAN_FD_BR_500K(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=63;x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;} while(0)
#define KVASER_CAN_FD_BR_250K(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=4;x.btr.nominal.tseg1=63;x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;} while(0)
#define KVASER_CAN_FD_BR_125K(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=8;x.btr.nominal.tseg1=63;x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;} while(0)
Expand All @@ -125,8 +105,8 @@ extern "C" {
/** @name Kvaser CAN FD Bit-rate Settings with Bit-rate Switching
* @brief Default values for long and fast frames only (up to 8 Mbps).
* @{ */
#define KVASER_CAN_FD_BR_1M8M(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=31;x.btr.nominal.tseg2= 8;x.btr.nominal.sjw= 8;x.btr.data.brp=1;x.btr.data.tseg1= 7;x.btr.data.tseg2=2;x.btr.data.sjw=1;} while(0)
#define KVASER_CAN_FD_BR_500K4M(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=63;x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;x.btr.data.brp=2;x.btr.data.tseg1= 7;x.btr.data.tseg2=2;x.btr.data.sjw=2;} while(0)
#define KVASER_CAN_FD_BR_1M8M(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=31;x.btr.nominal.tseg2=8; x.btr.nominal.sjw=8; x.btr.data.brp=1;x.btr.data.tseg1=7; x.btr.data.tseg2=2;x.btr.data.sjw=1;} while(0)
#define KVASER_CAN_FD_BR_500K4M(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=63;x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;x.btr.data.brp=2;x.btr.data.tseg1=7; x.btr.data.tseg2=2;x.btr.data.sjw=2;} while(0)
#define KVASER_CAN_FD_BR_250K2M(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=4;x.btr.nominal.tseg1=63;x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;x.btr.data.brp=2;x.btr.data.tseg1=15;x.btr.data.tseg2=4;x.btr.data.sjw=4;} while(0)
#define KVASER_CAN_FD_BR_125K1M(x) do {x.btr.frequency=KVASER_CAN_FD_CLOCK;x.btr.nominal.brp=8;x.btr.nominal.tseg1=63;x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;x.btr.data.brp=2;x.btr.data.tseg1=31;x.btr.data.tseg2=8;x.btr.data.sjw=8;} while(0)
/** @} */
Expand Down
4 changes: 2 additions & 2 deletions Sources/KvaserCAN_Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ extern "C" {
* @{ */
#define KVASER_LIB_ID 600 /**< library ID (CAN/COP API V1 compatible) */
#if defined(_WIN32) || defined (_WIN64)
#define KVASER_LIB_CANLIB "canLib32.dll"
#define KVASER_LIB_CANLIB "canlib32.dll"
#define KVASER_LIB_WRAPPER "u3cankvl.dll"
#elif defined(__APPLE__)
#define KVASER_LIB_CANLIB "(n/a)"
#define KVASER_LIB_CANLIB "(driverless)"
#define KVASER_LIB_WRAPPER "libUVCANKVL.dylib"
#else
#error Platform not supported
Expand Down
54 changes: 27 additions & 27 deletions Sources/Wrapper/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ static canStatus kvaser_get_filter(int handle, uint64_t *filter, int xtd);
static canStatus kvaser_set_filter(int handle, uint64_t filter, int xtd);
static canStatus kvaser_reset_filter(int handle);

static int map_index2params(int index, btr_nominal_t *busParams);
static int map_bitrate2params(const can_bitrate_t *bitrate, btr_nominal_t *busParams);
static int map_params2bitrate(const btr_nominal_t *busParams, long canClock, can_bitrate_t *bitrate);
static int map_bitrate2paramsFd(const can_bitrate_t *bitrate, btr_data_t *busParams);
static int map_paramsFd2bitrate(const btr_data_t *busParams, long canClock, can_bitrate_t *bitrate);
static int map_index2busparams(int index, btr_nominal_t *busParams);
static int map_bitrate2busparams(const can_bitrate_t *bitrate, btr_nominal_t *busParams);
static int map_busparams2bitrate(const btr_nominal_t *busParams, long canClock, can_bitrate_t *bitrate);
static int map_bitrate2busparams_fd(const can_bitrate_t *bitrate, btr_data_t *busParams);
static int map_busparams2bitrate_fd(const btr_data_t *busParams, long canClock, can_bitrate_t *bitrate);

static int lib_parameter(uint16_t param, void *value, size_t nbyte);
static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte);
Expand All @@ -224,14 +224,14 @@ static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte);
static const char version[] = "CAN API V3 for Kvaser CAN Interfaces, Version " VERSION_STRING;

can_board_t can_boards[NUM_CHANNELS+1] = { // list of supported CAN channels
{KVASER_CAN_CHANNEL0, "Kvaser CAN Channel 0"},
{KVASER_CAN_CHANNEL1, "Kvaser CAN Channel 1"},
{KVASER_CAN_CHANNEL2, "Kvaser CAN Channel 2"},
{KVASER_CAN_CHANNEL3, "Kvaser CAN Channel 3"},
{KVASER_CAN_CHANNEL4, "Kvaser CAN Channel 4"},
{KVASER_CAN_CHANNEL5, "Kvaser CAN Channel 5"},
{KVASER_CAN_CHANNEL6, "Kvaser CAN Channel 6"},
{KVASER_CAN_CHANNEL7, "Kvaser CAN Channel 7"},
{KVASER_CAN_CHANNEL0, (char *)"Kvaser CAN Channel 0"},
{KVASER_CAN_CHANNEL1, (char *)"Kvaser CAN Channel 1"},
{KVASER_CAN_CHANNEL2, (char *)"Kvaser CAN Channel 2"},
{KVASER_CAN_CHANNEL3, (char *)"Kvaser CAN Channel 3"},
{KVASER_CAN_CHANNEL4, (char *)"Kvaser CAN Channel 4"},
{KVASER_CAN_CHANNEL5, (char *)"Kvaser CAN Channel 5"},
{KVASER_CAN_CHANNEL6, (char *)"Kvaser CAN Channel 6"},
{KVASER_CAN_CHANNEL7, (char *)"Kvaser CAN Channel 7"},
{EOF, NULL}
};
static const uint8_t dlc_table[16] = { // DLC to length
Expand Down Expand Up @@ -484,7 +484,7 @@ int can_start(int handle, const can_bitrate_t *bitrate)
if (bitrate->index <= 0) { // bit-rate from index
if (can[handle].mode.fdoe)
return CANERR_BAUDRATE; // CAN 2.0 only
if ((rc = map_index2params(bitrate->index, &nominal)) != CANERR_NOERROR)
if ((rc = map_index2busparams(bitrate->index, &nominal)) != CANERR_NOERROR)
return rc;
if ((sts = canSetBusParams(can[handle].handle, nominal.bitRate, nominal.tseg1, nominal.tseg2,
nominal.sjw, nominal.noSamp, nominal.syncmode)) != canOK)
Expand All @@ -496,14 +496,14 @@ int can_start(int handle, const can_bitrate_t *bitrate)
#endif
}
else { // bit-rate from parameter
if ((rc = map_bitrate2params(bitrate, &nominal)) != CANERR_NOERROR)
if ((rc = map_bitrate2busparams(bitrate, &nominal)) != CANERR_NOERROR)
return rc;
if ((sts = canSetBusParams(can[handle].handle, nominal.bitRate, nominal.tseg1, nominal.tseg2,
nominal.sjw, nominal.noSamp, nominal.syncmode)) != canOK)
return (sts != canERR_PARAM) ? kvaser_error(sts) : CANERR_BAUDRATE;
/* bit-rate for CAN FD data (BRSE) */
if (can[handle].mode.fdoe && can[handle].mode.brse) {
if ((rc = map_bitrate2paramsFd(bitrate, &data)) != CANERR_NOERROR)
if ((rc = map_bitrate2busparams_fd(bitrate, &data)) != CANERR_NOERROR)
return rc;
if ((sts = canSetBusParamsFd(can[handle].handle, data.bitRate, data.tseg1, data.tseg2, data.sjw)) != canOK)
return (sts != canERR_PARAM) ? kvaser_error(sts) : CANERR_BAUDRATE;
Expand Down Expand Up @@ -535,7 +535,7 @@ int can_start(int handle, const can_bitrate_t *bitrate)

int can_reset(int handle)
{
int rc = CANERR_FATAL; // return code
canStatus sts; // return value

if (!init) // must be initialized
return CANERR_NOTINIT;
Expand All @@ -552,9 +552,9 @@ int can_reset(int handle)
return CANERR_NOERROR;
#endif
// stop the CAN controller (bus off)
rc = canBusOff(can[handle].handle);
can[handle].status.can_stopped = (rc == CANERR_NOERROR) ? 1 : 0;
return rc;
sts = canBusOff(can[handle].handle);
can[handle].status.can_stopped = (sts == canOK) ? 1 : 0;
return (sts == canOK) ? CANERR_NOERROR : kvaser_error(sts);
}

int can_write(int handle, const can_message_t *msg, uint16_t timeout)
Expand Down Expand Up @@ -809,13 +809,13 @@ int can_bitrate(int handle, can_bitrate_t *bitrate, can_speed_t *speed)
/* bit-rate for CAN 2.0 & CAN FD */
if ((sts = canGetBusParams(can[handle].handle, &nominal.bitRate, &nominal.tseg1, &nominal.tseg2,
&nominal.sjw, &nominal.noSamp, &nominal.syncmode)) == canOK)
(void)map_params2bitrate(&nominal, can[handle].frequency, &tmpBitrate);
(void)map_busparams2bitrate(&nominal, can[handle].frequency, &tmpBitrate);
else
return kvaser_error(sts);
/* bit-rate for CAN FD data (BRSE) */
if (can[handle].mode.fdoe && can[handle].mode.brse) {
if ((sts = canGetBusParamsFd(can[handle].handle, &data.bitRate, &data.tseg1, &data.tseg2, &data.sjw)) == canOK)
(void)map_paramsFd2bitrate(&data, can[handle].frequency, &tmpBitrate);
(void)map_busparams2bitrate_fd(&data, can[handle].frequency, &tmpBitrate);
else
return kvaser_error(sts);
}
Expand Down Expand Up @@ -1063,7 +1063,7 @@ static canStatus kvaser_reset_filter(int handle)
return canOK;
}

static int map_index2params(int index, btr_nominal_t *busParams)
static int map_index2busparams(int index, btr_nominal_t *busParams)
{
switch (index) {
case CANBTR_INDEX_1M: KVASER_BDR_1000((*busParams)); break;
Expand All @@ -1084,7 +1084,7 @@ static int map_index2params(int index, btr_nominal_t *busParams)
return CANERR_NOERROR;
}

static int map_bitrate2params(const can_bitrate_t *bitrate, btr_nominal_t *busParams)
static int map_bitrate2busparams(const can_bitrate_t *bitrate, btr_nominal_t *busParams)
{
// sanity check
if (!bitrate || !busParams)
Expand Down Expand Up @@ -1114,7 +1114,7 @@ static int map_bitrate2params(const can_bitrate_t *bitrate, btr_nominal_t *busPa
return CANERR_NOERROR;
}

static int map_params2bitrate(const btr_nominal_t *busParams, long canClock, can_bitrate_t *bitrate)
static int map_busparams2bitrate(const btr_nominal_t *busParams, long canClock, can_bitrate_t *bitrate)
{
// sanity check
if (!busParams || !bitrate)
Expand All @@ -1138,7 +1138,7 @@ static int map_params2bitrate(const btr_nominal_t *busParams, long canClock, can
return CANERR_NOERROR;
}

static int map_bitrate2paramsFd(const can_bitrate_t *bitrate, btr_data_t *busParams)
static int map_bitrate2busparams_fd(const can_bitrate_t *bitrate, btr_data_t *busParams)
{
// sanity check
if (!bitrate || !busParams)
Expand All @@ -1164,7 +1164,7 @@ static int map_bitrate2paramsFd(const can_bitrate_t *bitrate, btr_data_t *busPar
return CANERR_NOERROR;
}

static int map_paramsFd2bitrate(const btr_data_t *busParams, long canClock, can_bitrate_t *bitrate)
static int map_busparams2bitrate_fd(const btr_data_t *busParams, long canClock, can_bitrate_t *bitrate)
{
// sanity check
if (!busParams || !bitrate)
Expand Down

0 comments on commit 7922988

Please sign in to comment.