Hardware Configuration
硬件配置中包含CAN或者CANFD的参数配置,其中包含波特率、时间片1、时间片2、时间量子中的同步跳跃宽度、采样点数等信息;随着研发系统中各类型的平台化,测试想要跟上研发的进度,也必须进行平台化,那么为了适配一个公司中多样的产品类型,我们就需要适配不同产品的CAN&CANFD信息配置,这里我们就能通过该函数进行修改和控制,下面我们介绍下配置的参数函数。
canGetConfiguration & canSetConfiguration
功能 :读取/设置CANFD控制器的参数
Channel:CANoe配置的CANFD通道
canSetting:
float baudrate:CAN通道波特率
unsigned char tseg1, tseg2:时间片中时间段1和2的长度
unsigned char sjw:同步时间片中的跳跃宽度
unsigned char sam:采样点数 (1 or 3)
unsigned int flags
canGetConfiguration:
bit 0、bit 1:0,未知传输模式;1,低速;2:单线;3,高速
bit 8:0x100,该通道被配置为高速CAN
All other:保留值
canSetConfiguration:
bit 0:0,正常模式;1,静默模式(确认未创建)
All Other:保留值全部设置为0
返回值:
1:成功获取CAN通道配置
0:获取CAN通道配置失败
代码示例
void CANFD_Channel_Setting()
{
int ret;
int channel = 1;
CANsettings abrSettings;
CANsettings dbrSettings;
abrSettings.baudrate = 1000000;
abrSettings.tseg1=5;
abrSettings.tseg2=2;
abrSettings.sjw=2;
abrSettings.sam=1;
abrSettings.flags = 0;
dbrSettings.baudrate = 4000000;
dbrSettings.tseg1=6;
dbrSettings.tseg2=3;
dbrSettings.sjw=2;
dbrSettings.sam=1;
dbrSettings.flags = 0;
write("设置CANFD波特率为4M");
ret = canFdSetConfiguration(channel, abrSettings, dbrSettings);
ret = canFdGetConfiguration(channel, abrSettings, dbrSettings);
if (ret)
{
write("Arbitration settings: baud= %f, tseg1 = %d, tseg2= %d, sjw = %d, sam = %d, flags = 0x%x",abrSettings.baudrate, abrSettings.tseg1, abrSettings.tseg2, abrSettings.sjw, abrSettings.sam, abrSettings.flags);
write("Data settings: baud= %f, tseg1 = %d, tseg2= %d, sjw = %d, sam = %d, flags = 0x%x",dbrSettings.baudrate, dbrSettings.tseg1, dbrSettings.tseg2, dbrSettings.sjw, dbrSettings.sam, dbrSettings.flags);
}
}
canFdGetConfiguration & canFdSetConfiguration
功能 :读取CAN控制器的参数
Channel:CANoe配置的CAN通道
canSetting:
float baudrate:CAN通道波特率
unsigned char tseg1, tseg2:时间片中时间段1和2的长度
unsigned char sjw:同步时间片中的跳跃宽度
unsigned char sam:采样点数 (1 or 3)
unsigned int flags
canGetConfiguration:
bit 0、bit 1:0,未知传输模式;1,低速;2:单线;3,高速
bit 8:0x100,该通道被配置为高速CAN
All other:保留值
canSetConfiguration:
bit 0:0,正常模式;1,静默模式(确认未创建)
All Other:保留值全部设置为0
返回值:
1:成功获取CAN通道配置
0:获取CAN通道配置失败
代码示例
void CAN_Channel_Setting()
{
int ret;
int channel = 1; //CAN1通道
canSettings settings;
settings.baudrate = 1000000;//波特率为1M
settings.tseg1=5;
settings.tseg2=2;
settings.sjw=2;
settings.sam=1;
settings.flags = 0;
write("设置CAN1通道波特率为1M");
ret = canSetConfiguration(channel, settings);
//读取CAN1通道的配置信息
ret = canGetConfiguration(channel, settings);
if (ret)
{
write("Settings: baud= %f, tseg1 = %d, tseg2= %d, sjw = %d, sam = %d, flags = 0x%x",
settings.baudrate, settings.tseg1, settings.tseg2, settings.sjw, settings.sam, settings.flags);
}
}