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. 手机驱动无法正常安装,出现adb interface失败

    手机一直无法用usb连接上电脑,试了各种方法,总是提示安装驱动失败,或者找不到文件. 在网上找了各种方法,后来结果证明,是我自己手贱了,... 方法: Win7系统用户已经碰到几次在安装adb驱动时提 ...

  2. mysql and 和 or 的 优先级和 查询问题

    1. select * from trade where id=1 and cid=1 or pid=2 ; 2. select * from trade where cid=1 or (pid=2 ...

  3. PHP 判断数组是否为空的5大方法

    1. isset功能:判断变量是否被初始化 说明:它并不会判断变量是否为空,并且可以用来判断数组中元素是否被定义过 注意:当使用isset来判断数组元素是否被初始化过时,它的效率比array_key_ ...

  4. 【转】移动端viewport的使用

    web端网站转移至移动端页面,注意点如下: 1.首先引入viewport调整页面宽度 <meta name="viewport" content="width=de ...

  5. PAM禁止root用户登录,限制普通用户使用su切换到root

    系统环境是CentOS 6.5, 介绍下PAM(Pluggable Authentication Modules)在ssh服务上的简单配置过程. 1.必须先添加普通用户,并属于wheel组:保证有除r ...

  6. autorelease的对象何时被释放

    autorelease的对象何时被释放 参考答案: 如果了解一点点Run Loop的知道,应该了解到:Run Loop在每个事件循环结束后会去自动释放池将所有自动释放对象的引用计数减一,若引用计数变成 ...

  7. php redis 代码实例

    <?phpheader("Content-type:text/html;charset=utf8");$redis = new redis();$redis ->con ...

  8. java编程规范

    一.规范存在的意义 应用编码规范对于软件本身和软件开发人员而言尤为重要,有以下几个原因: 1.好的编码规范可以尽可能的减少一个软件的维护成本 , 并且几乎没有任何一个软件,在其整个生命周期中,均由最初 ...

  9. Kali Linux Web 渗透测试视频教程— 第二课 google hack 实战

    Kali Linux Web 渗透测试— 第二课 代理简介 文/玄魂 课程地址: http://edu.51cto.com/course/course_id-1887.html 目录 shellKal ...

  10. SQL Server 2012 列存储索引分析(翻译)

    一.概述 列存储索引是SQL Server 2012中为提高数据查询的性能而引入的一个新特性,顾名思义,数据以列的方式存储在页中,不同于聚集索引.非聚集索引及堆表等以行为单位的方式存储.因为它并不要求 ...