typedef struct
{
//char name[ 16 ]; // Name of the CAN controller hardware
//uint32_t ref_clk; // CAN system clock frequency in Hz
//uint32_t sjw_max; // Synchronisation jump width
uint32_t brp_min; // Bit-rate prescaler
uint32_t brp_max;
uint32_t brp_inc;
uint32_t tseg1_min; // Time segement 1 = prop_seg + phase_seg1
uint32_t tseg1_max;
uint32_t tseg2_min; // Time segement 2 = phase_seg2
uint32_t tseg2_max;
} CAN_BitTimingConst_TypeDef; typedef struct
{
uint32_t ref_clk; // CAN system clock frequency in Hz
uint32_t bitrate; // Bit-rate in bits/second
uint32_t sample_point; // Sample point in one-tenth of a percent
uint32_t brp; // Bit-rate prescaler
uint32_t tq; // Time quanta ( TQ ) in nanoseconds
uint32_t tseg1; // Time segement 1 = prop_seg + phase_seg1
uint32_t tseg2; // Time segement 2 = phase_seg2
uint32_t sjw; // Synchronisation jump width in TQs
//uint32_t prop_seg; // Propagation segment in TQs
//uint32_t phase_seg1; // Phase buffer segment 1 in TQs
//uint32_t phase_seg2; // Phase buffer segment 2 in TQs
} CAN_BitTiming_TypeDef; int32_t CAN_CalcBitTiming( CAN_BitTimingConst_TypeDef *btc,
CAN_BitTiming_TypeDef *bt );
#define CAN_CALC_MAX_ERROR 50   // in one-tenth of a percent

int32_t CAN_UpdateSamplePoint( CAN_BitTimingConst_TypeDef *btc,
int32_t sampl_pt, int32_t tseg, int32_t *tseg1, int32_t *tseg2 )
{
*tseg2 = tseg + - ( sampl_pt * ( tseg + ) ) / ; if ( *tseg2 < btc->tseg2_min )
*tseg2 = btc->tseg2_min; if ( *tseg2 > btc->tseg2_max )
*tseg2 = btc->tseg2_max; *tseg1 = tseg - *tseg2; if ( *tseg1 > btc->tseg1_max )
{
*tseg1 = btc->tseg1_max;
*tseg2 = tseg - *tseg1;
} return * ( tseg + - *tseg2 ) / ( tseg + );
} // CIA Sample Point : 75.0% : Speed > 800000
// CIA Sample Point : 80.0% : Speed > 500000
// CIA Sample Point : 87.5% : Speed <= 500000
uint32_t CAN_CIA_SamplePoint( uint32_t bitrate )
{
uint32_t sampl_pt; if ( bitrate > )
sampl_pt = ;
else if ( bitrate > )
sampl_pt = ;
else
sampl_pt = ; return sampl_pt;
} int32_t CAN_CalcBitTiming( CAN_BitTimingConst_TypeDef *btc,
CAN_BitTiming_TypeDef *bt )
{
uint64_t v64;
int32_t rate = ;
int32_t best_error = , error = ;
int32_t best_tseg = , best_brp = , brp = ;
int32_t tsegall, tseg = , tseg1 = , tseg2 = ;
int32_t spt_error = , spt = , sampl_pt; // Use gived sample points
if ( bt->sample_point )
sampl_pt = bt->sample_point;
else
// Use CIA recommended sample points
sampl_pt = CAN_CIA_SamplePoint( bt->bitrate ); // tseg even = round down, odd = round up
for ( tseg = ( btc->tseg1_max + btc->tseg2_max ) * + ;
tseg >= ( btc->tseg1_min + btc->tseg2_min ) * ; tseg-- )
{
tsegall = + tseg / ; // Compute all possible tseg choices (tseg=tseg1+tseg2)
brp = bt->ref_clk / ( tsegall * bt->bitrate ) + tseg % ; // chose brp step which is possible in system
brp = ( brp / btc->brp_inc ) * btc->brp_inc;
if ( ( brp < btc->brp_min ) || ( brp > btc->brp_max ) )
continue; rate = bt->ref_clk / ( brp * tsegall );
error = bt->bitrate - rate; // tseg brp biterror
if ( error < )
error = -error; if ( error > best_error )
continue; best_error = error;
if ( error == )
{
spt = CAN_UpdateSamplePoint( btc, sampl_pt, tseg / , &tseg1, &tseg2 );
error = sampl_pt - spt;
if ( error < )
error = -error;
if ( error > spt_error )
continue; spt_error = error;
} best_tseg = tseg / ;
best_brp = brp;
if ( error == )
break;
} if ( best_error )
{
/* Error in one-tenth of a percent */
error = ( best_error * ) / bt->bitrate;
if ( error > CAN_CALC_MAX_ERROR )
{
// error ( "bitrate error %ld.%ld%% too high\n", error / 10, error % 10 );
return DRIVER_ERROR_PARAMETER;
}
else
{
// warn( "bitrate error %ld.%ld%%\n", error / 10, error % 10 );
}
} v64 = ( (uint64_t) best_brp * 1000000000UL ) / bt->ref_clk; bt->tq = (uint32_t) v64;
bt->brp = best_brp;
bt->tseg2 = tseg2;
bt->tseg1 = tseg1;
bt->sjw = ;
// bt->prop_seg = tseg1 / 2;
// bt->phase_seg1 = tseg1 - bt->prop_seg;
// bt->phase_seg2 = tseg2; // real bit-rate
bt->bitrate = bt->ref_clk / ( bt->brp * ( tseg1 + tseg2 + ) );
// real sample point bt->sample_point = CAN_UpdateSamplePoint( btc, sampl_pt, best_tseg, &tseg1,
&tseg2 ); return DRIVER_OK;
}

CAN Timing Sample Point的更多相关文章

  1. Sample rate 理解

    在Gnuradio中,我们可以看到很多模块中都有Sample rate 这个概念 然后看到一个说明 Any processing block's 'Sample Rate' parameter is ...

  2. JTAG – A technical overview and Timing

    This document provides you with interesting background information about the technology that underpi ...

  3. Calculate CAN bit timing parameters -- STM32

    Calculate CAN bit timing parameters Calculate CAN bit timing parameters typedef struct { //char name ...

  4. Calculate CAN bit timing parameters

    Calculate CAN bit timing parameters TSYNC_SEG === 1 TSEG1 = Prop_Seg + Phase_Seg1 TSEG2 = Phase_Seg2 ...

  5. systemverilog 之interface/timing region/program

    1.connecting the testbench and the design 2.verilog connection review 3.systemverilog interfaces 4.s ...

  6. Linux下UPnP sample分析

        一.UPnP简介   UPnP(Universal Plug and Play)技术是一种屏蔽各种数字设备的硬件和操作系统的通信协议.它是一种数字网络中间件技术,建立在TCP/IP.HTTP协 ...

  7. ABP源码分析十一:Timing

    Timing这个简单实用的功能主要用于以统一的方式表示时间.因为ABP中有大量的module,还支持自定义module,所以将时间统一表示为local时间(默认)或utc时间是必要的. IClockP ...

  8. cocos2d-x for android配置 & 运行 Sample on Linux OS

    1.从http://www.cocos2d-x.org/download下载稳定版 比如cocos2d-x-2.2 2.解压cocos2d-x-2.2.zip,比如本文将其解压到 /opt 目录下 3 ...

  9. android studio2.2 的Find Sample Code点击没有反应

    1 . 出现的问题描述:           右键点击Find Sample Code后半天没有反应,然后提示 Samples are currently unavailable for :{**** ...

随机推荐

  1. 加密算法—MD5、RSA、DES

    最近因为要做一个加密的功能,简单了解了一下加密算法,现在比较常用的有三个加密算法MD5加密算法.RSA加密算法.DES加密算法.       MD5加密算法     定义:MD5算法是将任意长度的“字 ...

  2. M1事后分析汇报总结

    学霸网站项目Postmortem结果 设想和目标 1.       我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 学霸网站为计算机学习提供了一个网上基地,在这里你 ...

  3. 应该了解的Python模块

    Python很优雅.使用以下模块有助于保持你的代码整洁.易于维护.欢迎补充. Docopt.忘了optparse和argparse吧,使用docstring来构建优雅的.高可读性.复杂(如果你有这个需 ...

  4. oracle删除数据恢复

    分为两种方法:scn和时间戳两种方法恢复. 一.通过scn恢复删除且已提交的数据 1.获得当前数据库的scn号 select current_scn from v$database; (切换到sys用 ...

  5. java面试

    1. 问一下服务器管理 2. 问一下流操作 3. 问一下多线程.struts是不是多线程的.或者说servlet的机制. 4. MySQL存储引擎 MyISAM 和 InnoDB 5 跨域问题. 6 ...

  6. IOS AFNetworking配置进IOS

    Prefix Header 中填入绝对路径 //PCH 里面加入这个写代码 #ifndef TARGET_OS_IOS #pragma mark ---------- for AFNetwork st ...

  7. servers无法输入server name

    Here is the workaround that worked for me: Close Eclipse In {workspace-directory}/.metadata/.plugins ...

  8. win8 下 IIS APPPOOL\DefaultAppPool 登录失败的解决方法

    来源:网络 添加ASP.NET网站时,选择添加"添加应用程序"连接sql server 2005(2008)可能会报始下的错误:(说明:2005必报错,2008选报错)" ...

  9. POJ1222_EXTENDED LIGHTS OUT

    给出5*6的位置,每个位置有一个灯,一开始每个灯有各自的状态,你可以选定一些位置使得所有与这个位置相邻以及位置本身的灯都取反. 输出合法方案. 本来是找高斯消元找到这个题目的,可是....我发现可以直 ...

  10. iOS9的一些问题

    1.App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. ...