精华内容
下载资源
问答
  • TC397MCMCAN实战
    2021-11-06 17:17:30

    一、TC397 CAN简介

        The MCMCAN implements Bosch M_CAN as CAN nodes. The M_CAN performs communication according to ISO 11898-1 and according to ISO 11898-4 (Time-triggered communication on CAN). The M_CAN provides all features of time-triggered communication specified in ISO 11898-4, including event synchronized time-triggered communication, global system time, and clock drift compensation.In addition the M_CAN supports classical CAN
    and CAN FD communication according to ISO 11898-1. The CAN FD option can be used together with eventtriggered and time-triggered CAN communication

    二、Feature List
    The following are the features of the MCMCAN module
    • ISO 11898-1, -4
    • CAN FD with up to 64 data bytes supported
    • TTCAN protocol level 1 and level 2 completely in hardware
    • Event synchronized time-triggered communication supported
    • CAN Error Logging
    • AUTOSAR optimized
    • SAE J1939 optimized
    • Improved acceptance filtering
    • Two configurable Receive FIFOs
    • Separate signalling on reception of High Priority Messages
    • Up to 4 CAN nodes
    • Direct Message RAM access for Host CPU
    • Multiple M_CANs share the same Message RAM
    • Programmable loop-back test mode
    • Maskable module interrupts
    • 8/16/32-bit Generic Slave Interface for connection customer-specific Host CPUs
    Features offered by each M_CAN node:
    • Two configurable Receive FIFOs
    • Separate signaling on reception of High Priority Messages
    • Up to 64 dedicated Receive Buffers
    • Up to 32 dedicated Transmit Buffers
    • Configurable Transmit FIFO
    • Configurable Transmit Queue
    • Configurable Transmit Event FIFO

        TC397 MCMCAN 有3个模块,每个模块有4个节点,所以最多提供12路CAN,CPU可以直接访问CAN消息RAM。

    具体信息可以参考TC3xx User Manual part2 V2.0第40章CAN Interface(MCMCAN,页码1946)

    三、CAN00代码收发

    以官方开发板为硬件平台进行代码的讲解,CAN00的接线图如下

    P20.7, CAN00的RX管脚

    P20.8, CAN00的TX管脚

    即远离开发板上X202丝印的2个管

    实验现象和代码如下:
    CAN00发送ID为 0x5215210, 中断中翻转LED0
    CAN接收 0x5205200 扩展帧, 数据为0x00 11 22 33 44 55 66 77 时, 点亮LED3

    (1) can00头文件

    #include "can00.h"
    #include "led.h"

    Mcmcan00Type g_mcmcan00;

    //CAN pins复用
    IFX_CONST IfxCan_Can_Pins Can00_pins = {
        &IfxCan_TXD00_P20_8_OUT, IfxPort_OutputMode_pushPull, //CAN00_TX
        &IfxCan_RXD00B_P20_7_IN, IfxPort_InputMode_pullUp,    //CAN00_RX
        IfxPort_PadDriver_cmosAutomotiveSpeed4                //管脚翻转速度
    };


    //CAN 发送中断
    IFX_INTERRUPT(canIsrTxHandler, 0, ISR_PRIORITY_CAN_TX);
    void canIsrTxHandler(void)
    {
        //清除CAN发送完成中断
        IfxCan_Node_clearInterruptFlag(g_mcmcan00.can00Node.node, IfxCan_Interrupt_transmissionCompleted);
        IfxPort_togglePin(LED0);
    }

    //CAN接收中断
    IFX_INTERRUPT(canIsrRxHandler, 0, ISR_PRIORITY_CAN_RX);
    void canIsrRxHandler(void)
    {
        //clear the "message stored to Dedicated RX Buffer" interrupt flag
        IfxCan_Node_clearInterruptFlag(g_mcmcan00.can00Node.node, IfxCan_Interrupt_messageStoredToDedicatedRxBuffer);
        /* Clear the "New Data" flag; as long as the "New Data" flag is set, the respective Rx buffer is
         * locked against updates from received matching frames.
         */
        IfxCan_Node_clearRxBufferNewDataFlag(g_mcmcan00.can00Node.node, g_mcmcan00.canFilter.rxBufferOffset);
        /* Read the received CAN message */
        IfxCan_Can_readMessage(&g_mcmcan00.can00Node, &g_mcmcan00.rxMsg, g_mcmcan00.rxData);
        //IfxPort_togglePin(LED2);
        //根据收到的报文,进行不同的处理
        if((g_mcmcan00.rxMsg.messageId == CAN_MESSAGE_RX_ID1) && (g_mcmcan00.rxData[1] == 0x77665544))
        {
            if(g_mcmcan00.rxData[0] == 0x33221100)
            {
                IfxPort_togglePin(LED3);
            }
        }

    }

    //CAN bufoff 中断处理
    IFX_INTERRUPT(canIsrBusOffHandler, 0, ISR_PRIORITY_CAN_BUSOFF);
    void canIsrBusOffHandler(void)
    {
        IfxCan_Node_clearInterruptFlag(g_mcmcan00.can00Node.node, IfxCan_Interrupt_busOffStatus);
        can00Init();
    }

    void can00Init(void)
    {
        //CAN00 module configuration and initialization
        IfxCan_Can_initModuleConfig(&g_mcmcan00.canConfig, &MODULE_CAN0); //CAN模块默认配置
        IfxCan_Can_initModule(&g_mcmcan00.canModule, &g_mcmcan00.canConfig);//CAN模块用户配置

        //CAN 模块节点默认配置
        IfxCan_Can_initNodeConfig(&g_mcmcan00.canNodeConfig, &g_mcmcan00.canModule);

        //CAN 模块节点0用户配置
        g_mcmcan00.canNodeConfig.nodeId = IfxCan_NodeId_0;
        g_mcmcan00.canNodeConfig.clockSource = IfxCan_ClockSource_both; //跟其它的有什么区别?
        g_mcmcan00.canNodeConfig.frame.type = IfxCan_FrameType_transmitAndReceive;
        g_mcmcan00.canNodeConfig.frame.mode = IfxCan_FrameMode_standard; //Classic CAN

        g_mcmcan00.canNodeConfig.txConfig.txMode = IfxCan_TxMode_dedicatedBuffers;
        g_mcmcan00.canNodeConfig.txConfig.dedicatedTxBuffersNumber = 255;
        g_mcmcan00.canNodeConfig.txConfig.txBufferDataFieldSize = IfxCan_DataFieldSize_8;

        g_mcmcan00.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_dedicatedBuffers;
        g_mcmcan00.canNodeConfig.rxConfig.rxBufferDataFieldSize = IfxCan_DataFieldSize_8;

        g_mcmcan00.canNodeConfig.filterConfig.extendedListSize = 255;
        g_mcmcan00.canNodeConfig.filterConfig.messageIdLength = IfxCan_MessageIdLength_extended;

        g_mcmcan00.canNodeConfig.messageRAM.extendedFilterListStartAddress = 0x100; //
        g_mcmcan00.canNodeConfig.messageRAM.rxBuffersStartAddress = 0x200;
        g_mcmcan00.canNodeConfig.messageRAM.txBuffersStartAddress = 0x400;
        g_mcmcan00.canNodeConfig.messageRAM.baseAddress = MODULE_CAN0_RAM+NODE0_RAM_OFFSET;

        g_mcmcan00.canNodeConfig.baudRate.baudrate = 500000; //500KBaud

        //transmit interrutp
        g_mcmcan00.canNodeConfig.interruptConfig.transmissionCompletedEnabled = TRUE;
        g_mcmcan00.canNodeConfig.interruptConfig.traco.priority = ISR_PRIORITY_CAN_TX;
        g_mcmcan00.canNodeConfig.interruptConfig.traco.interruptLine = IfxCan_InterruptLine_0;
        g_mcmcan00.canNodeConfig.interruptConfig.traco.typeOfService = IfxSrc_Tos_cpu0;

        //receive interrupt
        g_mcmcan00.canNodeConfig.interruptConfig.messageStoredToDedicatedRxBufferEnabled = TRUE;
        g_mcmcan00.canNodeConfig.interruptConfig.reint.priority = ISR_PRIORITY_CAN_RX;
        g_mcmcan00.canNodeConfig.interruptConfig.reint.interruptLine = IfxCan_InterruptLine_1;
        g_mcmcan00.canNodeConfig.interruptConfig.reint.typeOfService = IfxSrc_Tos_cpu0;

        //CAN模块0的节点0绑定的pin脚配置
        g_mcmcan00.canNodeConfig.pins = &Can00_pins;

        //调用节点初始化接口,进行CAN0节点0的初始化
        IfxCan_Can_initNode(&g_mcmcan00.can00Node, &g_mcmcan00.canNodeConfig);

        //CAN filter configuration and initialization
        g_mcmcan00.canFilter.number = 0;
        g_mcmcan00.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
        g_mcmcan00.canFilter.id1 = CAN_MESSAGE_RX_ID1;
        g_mcmcan00.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
        IfxCan_Can_setExtendedFilter(&g_mcmcan00.can00Node, &g_mcmcan00.canFilter);

        g_mcmcan00.canFilter.number = 1;
        g_mcmcan00.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
        g_mcmcan00.canFilter.id2 = CAN_MESSAGE_RX_ID2;
        g_mcmcan00.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
        IfxCan_Can_setExtendedFilter(&g_mcmcan00.can00Node, &g_mcmcan00.canFilter);

        g_mcmcan00.canFilter.number = 2;
        g_mcmcan00.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
        g_mcmcan00.canFilter.id1 = CAN_MESSAGE_RX_ID3;
        g_mcmcan00.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
        IfxCan_Can_setExtendedFilter(&g_mcmcan00.can00Node, &g_mcmcan00.canFilter);

    }
     

    (3) Cpu0_Main.c函数

    /**********************************************************************************************************************
     * \file Cpu0_Main.c
     * \copyright Copyright (C) Infineon Technologies AG 2019
     * 
     * Use of this file is subject to the terms of use agreed between (i) you or the company in which ordinary course of 
     * business you are acting and (ii) Infineon Technologies AG or its licensees. If and as long as no such terms of use
     * are agreed, use of this file is subject to following:
     * 
     * Boost Software License - Version 1.0 - August 17th, 2003
     * 
     * Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and 
     * accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute,
     * and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the
     * Software is furnished to do so, all subject to the following:
     * 
     * The copyright notices in the Software and this entire statement, including the above license grant, this restriction
     * and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all 
     * derivative works of the Software, unless such copies or derivative works are solely in the form of 
     * machine-executable object code generated by a source language processor.
     * 
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
     * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 
     * COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN 
     * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
     * IN THE SOFTWARE.
     *********************************************************************************************************************/
     /*\title MCMCAN data transmission
     * \abstract MCMCAN is used to exchange data between two nodes, implemented in the same device using Loop-Back mode.
     * \description A CAN message is sent from CAN node 0 to CAN node 1 using Loop-Back mode. After the CAN message
     *              transmission, an interrupt is generated and an LED is turned on to confirm successful message
     *              transmission. Once the CAN message is successfully received by the CAN node 1, an interrupt is
     *              generated. Inside the interrupt service routine the content of the received CAN message is compared to
     *              the content of the transmitted CAN message. In case of a success, another LED is turned on to confirm
     *              successful message reception.
     *
     * \name MCMCAN_1_KIT_TC397_TFT
     * \version V1.0.2
     * \board APPLICATION KIT TC3X7 V2.0, KIT_A2G_TC397_5V_TFT, TC39xXX_B-Step
     * \keywords CAN, MCMCAN, AURIX, INTERRUPT, LOOP-BACK, MCMCAN_1
     * \documents https://www.infineon.com/aurix-expert-training/Infineon-AURIX_MCMCAN_1_KIT_TC397_TFT-TR-v01_00_02-EN.pdf
     * \documents https://www.infineon.com/aurix-expert-training/TC39B_iLLD_UM_1_0_1_12_1.chm
     * \lastUpdated 2021-03-22
     *********************************************************************************************************************/
    #include "Ifx_Types.h"
    #include "IfxCpu.h"
    #include "IfxScuWdt.h"
    #include "Bsp.h"
    //#include "MCMCAN.h"
    #include "can00.h"
    #include "led.h"

    #include "IfxCan_Can.h"
    #include "IfxCan.h"
    #include "IfxCpu_Irq.h"
    #include "IfxPort.h"


    IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;

    extern Mcmcan00Type g_mcmcan00;

    void core0_main(void)
    {
        IfxCpu_enableInterrupts();
        
        /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
         * Enable the watchdogs and service them periodically if it is required
         */
        IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
        IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
        
        /* Wait for CPU sync event */
        IfxCpu_emitEvent(&g_cpuSyncEvent);
        IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
        
        /* Application code: initialization of MCMCAN module, LEDs and the transmission of the CAN message */
        ledInit();
        initTime();
        can00Init();

        IfxCan_Can_initMessage(&g_mcmcan00.txMsg);
        g_mcmcan00.txMsg.messageId = CAN_MESSAGE_TX_ID0;
        g_mcmcan00.txMsg.bufferNumber = 0;
        g_mcmcan00.txMsg.dataLengthCode = IfxCan_DataLengthCode_8;//8 bytes
        g_mcmcan00.txMsg.frameMode = IfxCan_FrameMode_standard;   //Classic CAN
        g_mcmcan00.txMsg.messageIdLength=IfxCan_MessageIdLength_extended;  //Extended Frame
        g_mcmcan00.txData[0] = 0xAABBCCDD;
        g_mcmcan00.txData[1] = 0x12345678;

        while(1)
        {
            //blinkLED();

            //transmitCanMessage();
            while(IfxCan_Status_notSentBusy ==
                    IfxCan_Can_sendMessage(&g_mcmcan00.can00Node, &g_mcmcan00.txMsg, &g_mcmcan00.txData[0]) );
            waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, WAIT_TIME*4));    /* Wait 2s*/


        }
    }

    /** \brief Initialize the time constants.
     *
     * Initialize the time constants TimeConst_0s, TimeConst_100ns, TimeConst_1us,
     * TimeConst_10us, TimeConst_100us, TimeConst_1ms, TimeConst_10ms, TimeConst_100ms,
     * TimeConst_1s, TimeConst_10s
     * \return None.
     */
    void initTime(void)
    {
        sint32 Fsys = IfxStm_getFrequency(BSP_DEFAULT_TIMER);

        TimeConst[TIMER_INDEX_10NS]  = Fsys / (1000000000 / 10);
        TimeConst[TIMER_INDEX_100NS] = Fsys / (1000000000 / 100);
        TimeConst[TIMER_INDEX_1US]   = Fsys / (1000000 / 1);
        TimeConst[TIMER_INDEX_10US]  = Fsys / (1000000 / 10);
        TimeConst[TIMER_INDEX_100US] = Fsys / (1000000 / 100);
        TimeConst[TIMER_INDEX_1MS]   = Fsys / (1000 / 1);
        TimeConst[TIMER_INDEX_10MS]  = Fsys / (1000 / 10);
        TimeConst[TIMER_INDEX_100MS] = Fsys / (1000 / 100);
        TimeConst[TIMER_INDEX_1S]    = Fsys * (1);
        TimeConst[TIMER_INDEX_10S]   = Fsys * (10);
        TimeConst[TIMER_INDEX_100S]  = Fsys * (100);
    }

    实验效果图


     

    更多相关内容
  • TC397_Blink_LED.zip

    2020-10-27 11:29:14
    TC397_Blink_LED, AURIX Development Studio开发环境, GPIO操作, 适配KIT_A2G_TC397_5V_TFT评估板
  • TC397芯片参考手册和数据手册
  • TC397_UART.zip

    2020-10-27 19:50:32
    AURIX Development Studio开发环境, UART操作, 发送, 中断, printf, 适配KIT_A2G_TC397_5V_TFT评估板
  • TC397 LIN Master 用例

    2021-08-24 22:27:44
    文章目录LIN简介单片机与LINTC397 LINUSB-LIN分析仪TC397 KIT LIN工程示例参考 LIN简介 LIN (Local Interconnect Network), 一种广播串行网络,最多包括 16 个节点(一个主节点,通常最多 15 个从节点)。所有消息都...

    LIN简介

    LIN (Local Interconnect Network), 一种广播串行网络,最多包括 16 个节点(一个主节点,通常最多 15 个从节点)。所有消息都由主站发起,最多有一个从站回复给定的消息标识符。主节点也可以通过回复自己的消息来充当从节点。因为所有的通信都是由主机发起的,所以没有必要进行碰撞检测。

    在这里插入图片描述

    除了供电的两根电源线, LIN传输数据是单线, 主节点内配置 1kΩ电阻端接 12V ,从节点内配置 30kΩ电阻端接 12V 。

    协议的主要特性如下:

    • 单主机,最多 16 个从机(即无总线仲裁)。这是 LIN 联盟为实现确定性时间响应而推荐的值。 从节点位置检测 (SNPD) 允许在上电后分配节点地址
    • 单线通信高达 19.2 kbit/s @ 40 米总线长度。在LIN规范2.2中, 速度高达20 kbit/s。
    • 保证延迟时间。
    • 可变长度的数据帧(2、4 和 8 字节)。
    • 配置灵活性。 带时间同步的多播接收,无需晶体或陶瓷谐振器。
    • 数据校验和错误检测。
    • 检测缺陷节点。
    • 基于标准 UART/SCI 硬件的低成本实现。 分层网络推动者。
    • 工作电压为 12 V
    • 主任务传输由中断信号后跟同步和标识符字段组成的报头。从设备以一个数据帧进行响应,该数据帧由 2、4 和 8 个数据字节加上 3 个控制信息字节组成。

    在这里插入图片描述

    消息(Message)包含以下字段:

    • 同步中断, 13bit
    • 同步字节, 0x55
    • 标识符字节, id, identifier
    • 数据字节, 0~8 Bytes
    • 校验和字节, V1.3(Classic, 标准校验, 仅校验数据字节), V2.0+(Enhanced, 增强校验, id+data)

    六种帧类型(Frame Type):

    • Unconditional frame, 无条件帧(普通帧), 标识符在 0 到 59(0x00 到 0x3b)的范围内. 所有订阅者都应接收该帧并将其提供给应用程序(假设未检测到错误)
    • Event-triggered frame, 事件触发帧, 携带的普通帧的第一个数据字节应等于分配给事件触发帧的受保护标识符, 仅当其数据值发生变化时,从设备以相关联的普通帧进行回复。这样的目的是提高 LIN 集群的响应能力,无需为很少发生事件的多个从节点的轮询分配过多的总线带宽。
    • Sporadic frame, 零星帧, 当主任务知道帧中携带的信号已被更新时,零星帧的头应仅在其相关的帧时隙中发送
    • Diagnostic frame, 诊断帧, 始终包含八个数据字节。标识符是 60 (0x3C),称为主请求帧,或 61(0x3D),称为从响应帧。在生成诊断帧的头之前,主任务询问其诊断模块是否应发送或总线是否应静默。从属任务根据其诊断模块发布和订阅响应。
    • User-defined frame, 用户自定义帧, 可携带任何信息, 标识符是 62 (0x3E)。处理分配给该帧的帧时隙时,始终传输用户定义帧的标头
    • Reserved frame, 保留帧, 标识符63 (0x3F), LIN 2.0不用

    LIN通常用于对车辆性能或安全不关键的子系统中,下面给出了一些示例

    在这里插入图片描述

    通常CAN在DB9中为7H / 2L, LIN在DB9中常见为3GND / 7LIN / 9VBAT(不排除其它接法)

    在这里插入图片描述

    单片机与LIN

    如下:

    TC397 LIN

    参考:

    TC397有12路 ASCLIN (Asynchronous Synchronous Interface), 这是个3合1的模块: ASC(UART), LIN, SPI.

    作为LIN使用时:

    • 支持所有四个基本的LIN事务,包括标题/响应传输和接收,作为主设备或从设备 在这里插入图片描述

    • 支持标准Lin V1.3 / 2.0 / 2.1 / 2.2和碰撞检测的J2602

    • 自动波特率检测, 可选的碰撞检测, 总线空闲检测, wake-up能力, Stuck at zero/one monitoring for safety

    USB-LIN分析仪

    直接某宝随便买了个一百块左右的USB-LIN调试器, 上位机做的很人性化, 除了时间戳可能不是太准, 没太大毛病, 收发自如, 用着较爽

    USB转LIN调试器 LIN总线 转换器 STM32-淘宝网 (taobao.com)

    在这里插入图片描述

    TC397 KIT LIN

    KIT_A2G_TC397_3V3_TFT - Infineon Technologies 如图

    在这里插入图片描述

    原理图上是

    在这里插入图片描述

    TLE7259-3_DS_rev10 (infineon.com) 的框图

    在这里插入图片描述

    BUS引脚外挂了1K上拉电阻, 默认是Lin Master, 不挂的话是Slave.

    板子要供12V电源, 和USB-LIN分析仪的连接仅需LIN, GND两根线

    在这里插入图片描述

    下面的示例也只演示TC397 ASCLIN2作为Master时的情形, USB-LIN分析仪作为Slave.

    工程示例

    对于TC397官方 AURIX™ Expert Training - Infineon Technologies 开放了一个 LIN master communication via ASCLIN module (infineon.com) 的示例工程, 里面用了一个IO加示波器来测的, 并没用上面原理图对应的IO和LIN收发器, 我们稍微改一下, 暂且都放在main.c里面

    #include "Ifx_Types.h"
    #include "IfxCpu.h"
    #include "IfxScuWdt.h"
    
    IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
    
    #include "IfxAsclin.h"
    #include "IfxAsclin_Lin.h"
    
    IfxAsclin_Lin g_lin_master_2;
    
    const IfxAsclin_Lin_Pins asclin2_pins =
    {
        &IfxAsclin2_RXD_P10_6_IN,   IfxPort_InputMode_pullUp,                    /* RX port pin                                      */
        &IfxAsclin2_TX_P10_5_OUT,   IfxPort_OutputMode_pushPull,                 /* TX port pin                                      */
        IfxPort_PadDriver_cmosAutomotiveSpeed4
    };
    
    void asclin_lin_master_init(IfxAsclin_Lin *g_lin, Ifx_ASCLIN *asclin,const IfxAsclin_Lin_Pins *pins, float32 baud)
    {
        /* Initialize one instance of IfxAsclin_Lin_Config with default values */
        IfxAsclin_Lin_Config linMasterConfig;
        IfxAsclin_Lin_initModuleConfig(&linMasterConfig, asclin);
    
        linMasterConfig.linMode = IfxAsclin_LinMode_master;         /* Set the LIN mode of operation                    */
        linMasterConfig.brg.baudrate = baud;                        /* Set the desired baud rate                        */
    
        linMasterConfig.pins = pins;                               /* Port pins configuration                          */
    
        /* Initialize module */
        IfxAsclin_Lin_initModule(g_lin, &linMasterConfig);
    }
    
    void asclin_lin_master_send_message(IfxAsclin_Lin *g_lin, uint8 id, uint8 *data, uint8 len)
    {
        /* After the transmission of the LIN header by the master, the master itself starts the transmission
         * of the message.
         */
        IfxAsclin_Lin_sendHeader(g_lin, &id);                       /* Send LIN header                                  */
    
        if(g_lin->acknowledgmentFlags.txHeaderEnd == 1)             /* If the LIN header has been transmitted           */
        {
            IfxAsclin_Lin_sendResponse(g_lin, data, len);           /* Send message                                     */
        }
    }
    
    void asclin_lin_master_receive_message(IfxAsclin_Lin *g_lin, uint8 id, uint8 *data, uint8 len)
    {
        IfxAsclin_Lin_sendHeader(g_lin, &id);                       /* Send LIN header                                  */
        IfxAsclin_Lin_receiveResponse(g_lin, data, len);            /* wait until receive response end acknowledgemnet or an error is occured*/
    
    //    if(g_lin->acknowledgmentFlags.rxResponseEnd == 1)
    //    {
    //        IfxAsclin_Lin_receiveResponse(g_lin, data, len);
    //    }
    }
    
    void core0_main(void)
    {
        IfxCpu_enableInterrupts();
        
        /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
         * Enable the watchdogs and service them periodically if it is required
         */
        IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
        IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
        
        /* Wait for CPU sync event */
        IfxCpu_emitEvent(&g_cpuSyncEvent);
        IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
        
        asclin_lin_master_init(&g_lin_master_2, &MODULE_ASCLIN2, &asclin2_pins, 19200);
    
        uint8 tx_data[8] = {8,7,6,5,4,3,2,1};
        asclin_lin_master_send_message(&g_lin_master_2, 0x11, tx_data, 8);
    
        uint8 rx_data[8];
        asclin_lin_master_receive_message(&g_lin_master_2, 0x3A, rx_data, 8);
    
        while(1)
        {
        }
    }
    

    其中:

    • P10.6为接收, P10.5为发送, 对应Asclin2, 作为Master
    • 通信速率设置为19200bps
    • IfxAsclin_Lin_initModuleConfig中默认config->data.checksum= IfxAsclin_Checksum_enhanced; 所以是增强校验
    • 先自己发送一帧ID为0x11的帧
    • 再等待直到接收ID为0x3A的帧, 这个函数可以稍微修改一下, 毕竟LIN的速率很慢, 19200bps, 8字节数据, 也得大概5~10ms了(有点宽泛), 总之, 等着不是长久之计, 或许可以发完header后轮询判断 g_lin->acknowledgmentFlags.rxResponseEnd == 1 后再进行接收响应

    USB分析仪设置为从机, 19200波特率

    在这里插入图片描述

    从机写配置如下

    在这里插入图片描述

    在Aurix Development Studio中仿真, 可以看到确实收到了USB-LIN分析仪发出的数据

    在这里插入图片描述

    参考

    如下:

    欢迎关注微信公众号:
    在这里插入图片描述

    展开全文
  • TC397 CANFD 用例分析

    千次阅读 2021-02-25 16:24:04
    目录前言位速率和采样点设置Message RAM滤波器设置初始化部分代码汇总Bus-Off中断处理发送函数接收中断处理测试微信公众号 ...本篇写TC397的CANFD的使用. TC397有3路MCMCAN外设(CAN0/1/2), 每路MCMC

    前言

    参考前几篇:

    本篇写TC397的CANFD的使用. TC397有3路MCMCAN组件(CAN0/1/2), 每路MCMCAN组件又支持4个节点, 所以, 共计支持12路CANFD, 资源如下, TC39x-B specific configuration of CAN:

    ParameterCAN0CAN1CAN2
    Node size in byte102410241024
    Number of CAN Nodes444
    Number of TTCAN Nodes1
    RAM size in byte327681638416384
    Maximum Number of Standard ID Filter Messages per node128128128
    Maximum Number of Extended ID Filter Messages per node646464
    Maximum Number of RxFIFO structures per node222
    Maximum Number of Messages in a Rx buffer per node646464
    Maximum Number of Tx Event Messages per node323232
    Maximum Number of Tx Messages in a Tx Buffer per node323232
    Maximum number of trigger messages per TTCAN node64

    其中:

    • CAN0组件支持TTCAN
    • 正常每个MCMCAN组件4个节点(4路CANFD, M_CAN)共用的Message RAM大小为 16384 bytes = 4096 words = 16 KB, 相比之下, STM32H7所有FDCAN(目前最多3路)共用10KB

    本篇使用TC397的CAN2中0~3节点中的CAN22, 连接到Xavier的CAN0, 仲裁段500K, 采样点0.8; 数据段2M, 采样点0.75.

    位速率和采样点设置

    TC397的相关计算:

        /*
         * Bit timing & sampling
         * Tq = (BRP+1)/Fcan if DIV8 = 0
         * Tq = 8*(BRP+1)/Fcan if DIV8 = 1
         * TSync = 1.Tq
         * TSeg1 = (TSEG1+1)*Tq                >= 3Tq
         * TSeg2 = (TSEG2+1)*Tq                >= 2Tq
         * Bit Time = TSync + TSeg1 + TSeg2    >= 8Tq
         *
         * Resynchronization:
         *
         * Tsjw = (SJW + 1)*Tq
         * TSeg1 >= Tsjw + Tprop
         * TSeg2 >= Tsjw
         */
    

    主时钟频率来自IfxCan_getModuleFrequency()函数, 仿真或打印出来为 80MHz.

    有两种方法设置位速率和采样点:

    • 设置 位速率, 采样点, SJW, calculateBitTimingValues设为True, 然后初始化节点函数中会自动计算位时间填入寄存器
    • 设置 BRP, TSEG1, TSEG2, SJW, calculateBitTimingValues设为False, 然后初始化节点函数中会直接把这些值填入寄存器

    第一种的示例:

        g_mcmcan22.canNodeConfig.baudRate.baudrate = 500000;
        //10000*(1+TSeg1)/(1 + TSeg1 + TSeg2)     
        g_mcmcan22.canNodeConfig.baudRate.samplePoint = 10000*0.8;   
        //10000* TSeg2 / (1 + TSeg1 + TSeg2) = 10000 - samplePoint     
        g_mcmcan22.canNodeConfig.baudRate.syncJumpWidth = 2000;     
        g_mcmcan22.canNodeConfig.fastBaudRate.baudrate = 2000000;   
        g_mcmcan22.canNodeConfig.fastBaudRate.samplePoint = 10000*0.75;
        g_mcmcan22.canNodeConfig.fastBaudRate.syncJumpWidth = 2500;
        //TdcOffset default recommended value: DataTimeSeg1 * DataPrescaler
        g_mcmcan22.canNodeConfig.fastBaudRate.tranceiverDelayOffset = 28;
        g_mcmcan22.canNodeConfig.calculateBitTimingValues = TRUE;
    	
    	/*
        Ifx_Console_print(ENDLINE"moduleFreq: %.2f", IfxCan_getModuleFrequency());
        Ifx_Console_print(ENDLINE);
    
        Ifx_Console_print(ENDLINE"NBTP.B.NBRP = %d", g_mcmcan22.canNode.node->NBTP.B.NBRP);
        Ifx_Console_print(ENDLINE"NBTP.B.NSJW = %d", g_mcmcan22.canNode.node->NBTP.B.NSJW);
        Ifx_Console_print(ENDLINE"NBTP.B.NTSEG1 = %d", g_mcmcan22.canNode.node->NBTP.B.NTSEG1);
        Ifx_Console_print(ENDLINE"NBTP.B.NTSEG2 = %d", g_mcmcan22.canNode.node->NBTP.B.NTSEG2);
        Ifx_Console_print(ENDLINE);
    
        Ifx_Console_print(ENDLINE"DBTP.B.DBRP = %d", g_mcmcan22.canNode.node->DBTP.B.DBRP);
        Ifx_Console_print(ENDLINE"DBTP.B.DSJW = %d", g_mcmcan22.canNode.node->DBTP.B.DSJW);
        Ifx_Console_print(ENDLINE"DBTP.B.DTSEG1 = %d", g_mcmcan22.canNode.node->DBTP.B.DTSEG1);
        Ifx_Console_print(ENDLINE"DBTP.B.DTSEG2 = %d", g_mcmcan22.canNode.node->DBTP.B.DTSEG2);
        Ifx_Console_print(ENDLINE"DBTP.B.TDC = %d", g_mcmcan22.canNode.node->DBTP.B.TDC);
        Ifx_Console_print(ENDLINE"TDCR.B.TDCO = %d", g_mcmcan22.canNode.node->TDCR.B.TDCO);
        Ifx_Console_print(ENDLINE);
        */
    
        /*
         * moduleFreq   = 80000000.00
         * NBTP.B.NBRP   = 7
         * NBTP.B.NSJW   = 3
         * NBTP.B.NTSEG1 = 14
         * NBTP.B.NTSEG2 = 3
         * DBTP.B.DBRP   = 1
         * DBTP.B.DSJW   = 4
         * DBTP.B.DTSEG1 = 13
         * DBTP.B.DTSEG2 = 4
         * DBTP.B.TDC    = 1
         * TDCR.B.TDCO   = 28
        */
    

    第二种的示例:

        //https://www.kvaser.com/support/calculators/can-fd-bit-timing-calculator/
        g_mcmcan22.canNodeConfig.baudRate.prescaler = 2 - 1;
        g_mcmcan22.canNodeConfig.baudRate.syncJumpWidth = 16 - 1;
        g_mcmcan22.canNodeConfig.baudRate.timeSegment1 = 63 - 1;
        g_mcmcan22.canNodeConfig.baudRate.timeSegment2 = 16 - 1;
        g_mcmcan22.canNodeConfig.fastBaudRate.prescaler = 2 - 1;
        g_mcmcan22.canNodeConfig.fastBaudRate.syncJumpWidth = 5 - 1;
        g_mcmcan22.canNodeConfig.fastBaudRate.timeSegment1 = 14 - 1;
        g_mcmcan22.canNodeConfig.fastBaudRate.timeSegment2 = 5 - 1;
        g_mcmcan22.canNodeConfig.fastBaudRate.tranceiverDelayOffset = 28;
        g_mcmcan22.canNodeConfig.calculateBitTimingValues = FALSE;
    
        /*
         * moduleFreq   = 80000000.00
         * NBTP.B.NBRP   = 1
         * NBTP.B.NSJW   = 15
         * NBTP.B.NTSEG1 = 62
         * NBTP.B.NTSEG2 = 15
         * DBTP.B.DBRP   = 1
         * DBTP.B.DSJW   = 4
         * DBTP.B.DTSEG1 = 13
         * DBTP.B.DTSEG2 = 4
         * DBTP.B.TDC    = 1
         * TDCR.B.TDCO   = 28
        */
    

    用第二种时, iLLD TC39B Version: 1.0.1.12.0这个版本的IfxCan_Can_initNode()函数有点小bug, IfxCan_Can.c第140行由

    IfxCan_Node_setFastBitTimingValues(nodeSfr, config->baudRate.syncJumpWidth, config->baudRate.timeSegment2, config->baudRate.timeSegment1, config->baudRate.prescaler);
    

    改为

    IfxCan_Node_setFastBitTimingValues(nodeSfr, config->fastBaudRate.syncJumpWidth, config->fastBaudRate.timeSegment2, config->fastBaudRate.timeSegment1, config->fastBaudRate.prescaler);
    

    正常建议用第一种, 简单省心.

    Message RAM

    3个MCMCAN组件的起始和终止地址为:

    ModuleBase AddressEnd Address
    CAN00xF02000000xF0208FFF
    CAN10xF02100000xF0218FFF
    CAN20xF02200000xF0228FFF

    其中分配给Message RAM的空间为:

    • CAN0 Module的前0x8000 Bytes => 32768 Bytes 给了Message RAM
    • CAN1 Module的前0x4000 Bytes => 16384 Bytes 给了Message RAM
    • CAN2 Module的前0x4000 Bytes => 16384 Bytes 给了Message RAM

    每个MCMCAN组件共4个节点所能使用的最大Message RAM资源如图所示:

    在这里插入图片描述

    如果全部元素都启用, 将占用 128 + 128 + 1152 + 1152 + 1152 + 64 + 576 + 128 = 4480 words = 17920 Bytes = 17.5KB, 超过了16384 bytes = 4096 words = 16 KB的最大Ram限制. 所以还是要有所取舍, 用到的分配, 不用的不分配.

    下面会用到的参数总结如下:

    • 1 个 11-bit filter element => 1 words, 4个节点的11-bit filter element数量之和不超过128
    • 1 个 29-bit filter element => 2 words, 4个节点的29-bit filter element数量之和不超过64
    • 1 个 Rx FIFO 0 element => 18 words, 4个节点的Rx FIFO 0 element数量之和不超过64
    • 1 个 Tx Buffer element => 18 words, 4个节点的Tx Buffer element数量之和不超过32

    0x4000 Bytes空间可以对四路CAN节点平均分配, 每路0x1000 Bytes, 所有资源也可以平分, 每路可以分:

    • 32 个 11-bit filter element
    • 16 个 29-bit filter element
    • 16 个 Rx FIFO 0 element
    • 16 个 Rx FIFO 1 element
    • 8 个 Tx Buffer element

    当然一般不这么搞, 比如我这里只用了CAN22, 其它路不用, 完全可以分多点资源来用:

    • 32 个 11-bit filter elements
    • 16 个 29-bit filter elements
    • 20 个 Rx FIFO 0 elements
    • 20 个 Tx Buffer elements

    对应的代码如下:

    #define MODULE_CAN0_RAM    0xF0200000
    #define MODULE_CAN1_RAM    0xF0210000
    #define MODULE_CAN2_RAM    0xF0220000
    #define NODE0_RAM_OFFSET   0x0
    #define NODE1_RAM_OFFSET   0x1000
    #define NODE2_RAM_OFFSET   0x2000
    #define NODE3_RAM_OFFSET   0x3000
    
        g_mcmcan22.canNodeConfig.messageRAM.baseAddress = MODULE_CAN2_RAM;
        //Standard Frame, 32 elements => 32 words => 128 Bytes => 0x80
        g_mcmcan22.canNodeConfig.messageRAM.standardFilterListStartAddress = 0x0 + NODE2_RAM_OFFSET;
        //Extended Frame, 16 elements => 32 words => 128 Bytes => 0x80
        g_mcmcan22.canNodeConfig.messageRAM.extendedFilterListStartAddress = 0x80 + NODE2_RAM_OFFSET;
        //RxFIFO0, 20  elements => 360 words => 1440 Bytes => 0x5A0
        g_mcmcan22.canNodeConfig.messageRAM.rxBuffersStartAddress = 0x100 + NODE2_RAM_OFFSET;
        //Tx FIFO Buffers, 20  elements => 360 words => 1440 Bytes => 0x5A0
        g_mcmcan22.canNodeConfig.messageRAM.txBuffersStartAddress = 0x6A0 + NODE2_RAM_OFFSET;
        //Total: 128 + 128 + 1440 + 1440 = 3136 Bytes => 0xC40 Bytes
    

    对应的资源分配如图所示:

    在这里插入图片描述

    滤波器设置

    拿出1个标准帧滤波器+1个扩展帧滤波器, 用掩码的方式, 设置全接收到RxFIFO0中, 其它滤波器先不用:

        g_mcmcan22.canFilter.number = 0;
        g_mcmcan22.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxFifo0;
        g_mcmcan22.canFilter.type = IfxCan_FilterType_classic;
        g_mcmcan22.canFilter.id1 = 0;
        g_mcmcan22.canFilter.id2 = 0;
        g_mcmcan22.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
        IfxCan_Can_setStandardFilter(&(g_mcmcan22.canNode), &(g_mcmcan22.canFilter));
    
        g_mcmcan22.canFilter.number = 0;
        g_mcmcan22.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxFifo0;
        g_mcmcan22.canFilter.type = IfxCan_FilterType_classic;
        g_mcmcan22.canFilter.id1 = 0;
        g_mcmcan22.canFilter.id2 = 0;
        g_mcmcan22.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
        IfxCan_Can_setExtendedFilter(&(g_mcmcan22.canNode), &(g_mcmcan22.canFilter));
    

    初始化部分代码汇总

    #include "Ifx_Types.h"
    #include "IfxCan_Can.h"
    #include "IfxCan.h"
    
    #define CAN22_TOS          IfxSrc_Tos_cpu0
    
    #define MODULE_CAN0_RAM    0xF0200000
    #define MODULE_CAN1_RAM    0xF0210000
    #define MODULE_CAN2_RAM    0xF0220000
    #define NODE0_RAM_OFFSET   0x0
    #define NODE1_RAM_OFFSET   0x1000
    #define NODE2_RAM_OFFSET   0x2000
    #define NODE3_RAM_OFFSET   0x3000
    
    #define MAXIMUM_CAN_DATA_PAYLOAD      16    //words
    
    #define ISR_PRIORITY_CAN22_TX         121
    #define ISR_PRIORITY_CAN22_RX         122
    #define ISR_PRIORITY_CAN22_BUSOFF     135
    
    typedef struct
    {
        IfxCan_Can_Config canConfig;                /* CAN module configuration structure   */
        IfxCan_Can canModule;                       /* CAN module handle                    */
        IfxCan_Can_Node canNode;                    /* CAN source node handle data structure*/
        IfxCan_Can_NodeConfig canNodeConfig;        /* CAN node configuration structure     */
        IfxCan_Filter canFilter;                    /* CAN filter configuration structure   */
        IfxCan_Message txMsg;                       /* Transmitted CAN message structure    */
        IfxCan_Message rxMsg;                       /* Received CAN message structure       */
        uint32 txData[MAXIMUM_CAN_DATA_PAYLOAD];    /* Transmitted CAN data array           */
        uint32 rxData[MAXIMUM_CAN_DATA_PAYLOAD];    /* Received CAN data array              */
    } McmcanType;
    
    McmcanType g_mcmcan22;
    
    void init_can22_fd(void)
    {
        IfxCan_Can_initModuleConfig(&g_mcmcan22.canConfig, &MODULE_CAN2);
        IfxCan_Can_initModule(&g_mcmcan22.canModule, &g_mcmcan22.canConfig);
        IfxCan_Can_initNodeConfig(&g_mcmcan22.canNodeConfig, &g_mcmcan22.canModule);    //set default node value
    
        g_mcmcan22.canNodeConfig.nodeId = IfxCan_NodeId_2;  //4 node in 1 module
        g_mcmcan22.canNodeConfig.clockSource = IfxCan_ClockSource_both;
    
        g_mcmcan22.canNodeConfig.frame.type = IfxCan_FrameType_transmitAndReceive;
        g_mcmcan22.canNodeConfig.frame.mode = IfxCan_FrameMode_fdLongAndFast;  //CANFD Long Fast, FDF=1, BRS=1
    
        g_mcmcan22.canNodeConfig.txConfig.txMode = IfxCan_TxMode_fifo;
        g_mcmcan22.canNodeConfig.txConfig.txFifoQueueSize = 20;
        g_mcmcan22.canNodeConfig.txConfig.dedicatedTxBuffersNumber = 0;
        g_mcmcan22.canNodeConfig.txConfig.txEventFifoSize = 0;
        g_mcmcan22.canNodeConfig.txConfig.txBufferDataFieldSize = IfxCan_DataFieldSize_64;
    
        g_mcmcan22.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_fifo0;
        g_mcmcan22.canNodeConfig.rxConfig.rxFifo0Size = 20;
        g_mcmcan22.canNodeConfig.rxConfig.rxFifo0DataFieldSize = IfxCan_DataFieldSize_64;
        g_mcmcan22.canNodeConfig.rxConfig.rxFifo1Size = 0;
        g_mcmcan22.canNodeConfig.rxConfig.rxFifo1DataFieldSize = IfxCan_DataFieldSize_64;
        g_mcmcan22.canNodeConfig.rxConfig.rxBufferDataFieldSize = IfxCan_DataFieldSize_64;
        g_mcmcan22.canNodeConfig.rxConfig.rxFifo0WatermarkLevel = 0;    //event use
        g_mcmcan22.canNodeConfig.rxConfig.rxFifo1WatermarkLevel = 0;
        g_mcmcan22.canNodeConfig.rxConfig.rxFifo0OperatingMode = IfxCan_RxFifoMode_overwrite;   //or block
        g_mcmcan22.canNodeConfig.rxConfig.rxFifo1OperatingMode = IfxCan_RxFifoMode_overwrite;
    
        g_mcmcan22.canNodeConfig.filterConfig.messageIdLength = IfxCan_MessageIdLength_both;
        g_mcmcan22.canNodeConfig.filterConfig.standardListSize = 32;  //Standard Frame
        g_mcmcan22.canNodeConfig.filterConfig.extendedListSize = 16;  //Extended Frame
        g_mcmcan22.canNodeConfig.filterConfig.rejectRemoteFramesWithStandardId = TRUE;
        g_mcmcan22.canNodeConfig.filterConfig.rejectRemoteFramesWithExtendedId = TRUE;
        g_mcmcan22.canNodeConfig.filterConfig.standardFilterForNonMatchingFrames = IfxCan_NonMatchingFrame_reject;
        g_mcmcan22.canNodeConfig.filterConfig.extendedFilterForNonMatchingFrames = IfxCan_NonMatchingFrame_reject;
    
        //Message RAM
        g_mcmcan22.canNodeConfig.messageRAM.baseAddress = MODULE_CAN2_RAM;
        //Standard Frame, 32 elements => 32 words => 128 Bytes => 0x80
        g_mcmcan22.canNodeConfig.messageRAM.standardFilterListStartAddress = 0x0 + NODE2_RAM_OFFSET;
        //Extended Frame, 16 elements => 32 words => 128 Bytes => 0x80
        g_mcmcan22.canNodeConfig.messageRAM.extendedFilterListStartAddress = 0x80 + NODE2_RAM_OFFSET;
        //RxFIFO0, 20  elements => 360 words => 1440 Bytes => 0x5A0
        //g_mcmcan22.canNodeConfig.messageRAM.rxBuffersStartAddress = 0x100 + NODE2_RAM_OFFSET;
        g_mcmcan22.canNodeConfig.messageRAM.rxFifo0StartAddress = 0x100 + NODE2_RAM_OFFSET;
        //Tx FIFO Buffers, 20  elements => 360 words => 1440 Bytes => 0x5A0
        g_mcmcan22.canNodeConfig.messageRAM.txBuffersStartAddress = 0x6A0 + NODE2_RAM_OFFSET;
        //Total: 128 + 128 + 1440 + 1440 = 3136 Bytes
    
        //transmit interrupt
        g_mcmcan22.canNodeConfig.interruptConfig.transmissionCompletedEnabled = TRUE;
        g_mcmcan22.canNodeConfig.interruptConfig.traco.priority = ISR_PRIORITY_CAN22_TX;
        g_mcmcan22.canNodeConfig.interruptConfig.traco.interruptLine = IfxCan_InterruptLine_4;
        g_mcmcan22.canNodeConfig.interruptConfig.traco.typeOfService = CAN22_TOS;
    
        //receive interrupt
        g_mcmcan22.canNodeConfig.interruptConfig.rxFifo0NewMessageEnabled = TRUE;
        g_mcmcan22.canNodeConfig.interruptConfig.rxf0n.priority = ISR_PRIORITY_CAN22_RX;
        g_mcmcan22.canNodeConfig.interruptConfig.rxf0n.interruptLine = IfxCan_InterruptLine_5;
        g_mcmcan22.canNodeConfig.interruptConfig.rxf0n.typeOfService = CAN22_TOS;
    
        //bus-off interrupt
        g_mcmcan22.canNodeConfig.interruptConfig.busOffStatusEnabled = TRUE;
        g_mcmcan22.canNodeConfig.interruptConfig.boff.priority = ISR_PRIORITY_CAN22_BUSOFF;
        g_mcmcan22.canNodeConfig.interruptConfig.boff.interruptLine = IfxCan_InterruptLine_10;
        g_mcmcan22.canNodeConfig.interruptConfig.boff.typeOfService = CAN22_TOS;
    
        //clock: 80M
        g_mcmcan22.canNodeConfig.baudRate.baudrate = 500000;    
        g_mcmcan22.canNodeConfig.baudRate.samplePoint = 10000*0.8;         
        g_mcmcan22.canNodeConfig.baudRate.syncJumpWidth = 2000;
        g_mcmcan22.canNodeConfig.fastBaudRate.baudrate = 2000000;   
        g_mcmcan22.canNodeConfig.fastBaudRate.samplePoint = 10000*0.75;
        g_mcmcan22.canNodeConfig.fastBaudRate.syncJumpWidth = 2500;
        g_mcmcan22.canNodeConfig.fastBaudRate.tranceiverDelayOffset = 28;
        g_mcmcan22.canNodeConfig.calculateBitTimingValues = TRUE;
    
        IFX_CONST IfxCan_Can_Pins can22_pins = {
               &IfxCan_TXD22_P22_8_OUT,   IfxPort_OutputMode_pushPull,
               &IfxCan_RXD22E_P22_9_IN,   IfxPort_InputMode_pullUp,
               IfxPort_PadDriver_cmosAutomotiveSpeed4
        };
        g_mcmcan22.canNodeConfig.pins = &can22_pins;
        IfxCan_Can_initNode(&g_mcmcan22.canNode, &g_mcmcan22.canNodeConfig);
    
        //std filter 0
        g_mcmcan22.canFilter.number = 0;
        g_mcmcan22.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxFifo0;
        g_mcmcan22.canFilter.type = IfxCan_FilterType_classic;
        g_mcmcan22.canFilter.id1 = 0;
        g_mcmcan22.canFilter.id2 = 0;
        g_mcmcan22.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;  //maybe need change
        IfxCan_Can_setStandardFilter(&(g_mcmcan22.canNode), &(g_mcmcan22.canFilter));
    
        g_mcmcan22.canFilter.number = 0;
        g_mcmcan22.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxFifo0;
        g_mcmcan22.canFilter.type = IfxCan_FilterType_classic;
        g_mcmcan22.canFilter.id1 = 0;
        g_mcmcan22.canFilter.id2 = 0;
        g_mcmcan22.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
        IfxCan_Can_setExtendedFilter(&(g_mcmcan22.canNode), &(g_mcmcan22.canFilter));
    
        g_mcmcan22.rxMsg.readFromRxFifo0 = TRUE;
    }
    

    Bus-Off中断处理

    如果CANH, CANL短接, 或者和其它节点的传输速率/采样点不一致, 会引发Bus-Off, 初始化开启了Bus-Off中断, 发生Bus-Off时, 直接在中断中初始化节点:

    IFX_INTERRUPT(can22IsrBusOffHandler, 0, ISR_PRIORITY_CAN22_BUSOFF);
    void can22IsrBusOffHandler(void)
    {
        IfxCan_Node_clearInterruptFlag(g_mcmcan22.canNode.node, IfxCan_Interrupt_busOffStatus);
        init_can22_fd();
    }
    

    发送函数

    开启了ESI和BRS.

    uint8 can22_send_fd(uint32 messageId, IfxCan_DataLengthCode lengthCode, uint32 t_data[])
    {
        static uint8 i;
        //                         {0,1,2,3,4,5,6,7,8,12,16,20,24,32,48,64};
        //static uint8 dlc2len[]  ={1,1,1,1,1,2,2,2,2,3, 4, 5, 6, 8, 12,16};
        IfxCan_Can_initMessage(&g_mcmcan22.txMsg);
    
        //g_mcmcan22.txMsg.bufferNumber = 0;
        g_mcmcan22.txMsg.messageId = messageId;
        if(messageId < 0x800) {
            g_mcmcan22.txMsg.messageIdLength=IfxCan_MessageIdLength_standard;
        } else {
            g_mcmcan22.txMsg.messageIdLength=IfxCan_MessageIdLength_extended;
        }
        g_mcmcan22.txMsg.errorStateIndicator = TRUE;
        g_mcmcan22.txMsg.dataLengthCode = lengthCode;
        g_mcmcan22.txMsg.frameMode = IfxCan_FrameMode_fdLongAndFast;    //FDF=1, BRS=1
        g_mcmcan22.txMsg.storeInTxFifoQueue = TRUE;
    
        //for(i = 0; i < dlc2len(lengthCode); i++) {
        for(i = 0; i < IfxCan_Node_getDataLength(lengthCode); i++) {
            g_mcmcan22.txData[i] = t_data[i];
        }
    
        if(IfxCan_Status_notSentBusy ==
                IfxCan_Can_sendMessage(&g_mcmcan22.canNode, &g_mcmcan22.txMsg, &g_mcmcan22.txData[0]))
        {
            return 1;   //not send
        }
        return 0;   //send success
    }
    

    如果不习惯word数组的方式发送, 可以用byte数组拼凑:

        uint32 t_data[64];
        g_mcmcan22.txData[0] = (t_data[3]<<24) | (t_data[2]<<16) | (t_data[1]<<8) | t_data[0];
        g_mcmcan22.txData[1] = (t_data[7]<<24) | (t_data[6]<<16) | (t_data[5]<<8) | t_data[4];
        g_mcmcan22.txData[2] = ...
        ...
    

    接收中断处理

    初始化中滤波器设置了全接收到RxFIFO0, 开启了RxFIFO0新消息中断, 这里中断中第 0 word加1后, 返回:

    IFX_INTERRUPT(can22IsrRxHandler, 0, ISR_PRIORITY_CAN22_RX);
    void can22IsrRxHandler(void)
    {
        IfxCan_Node_clearInterruptFlag(g_mcmcan22.canNode.node, IfxCan_Interrupt_rxFifo0NewMessage);
        //IfxCan_Node_clearRxBufferNewDataFlag(g_mcmcan22.canNode.node, g_mcmcan22.canFilter.rxBufferOffset);
        IfxCan_Can_readMessage(&g_mcmcan22.canNode, &g_mcmcan22.rxMsg, g_mcmcan22.rxData);
    
        ++g_mcmcan22.rxData[0];
        can22_send_fd(g_mcmcan22.rxMsg.messageId, g_mcmcan22.rxMsg.dataLengthCode, g_mcmcan22.rxData);
    }
    

    测试

    每10ms发送20帧, 发送1000次共20000帧:

    void core0_main(void)
    {
        ...
    
        uint32 t_data1[16] = {0x0,        0x9ABCDEF0,
                              0x12345678, 0x9ABCDEF0,
                              0x12345678, 0x9ABCDEF0,
                              0x12345678, 0x9ABCDEF0,
                              0x12345678, 0x9ABCDEF0,
                              0x12345678, 0x9ABCDEF0,
                              0x12345678, 0x9ABCDEF0,
                              0x12345678, 0x98765430};
    
        while(1)
        {
            if(time_flag && t_data1[0]<1000) {
                time_flag = 0;
                ++t_data1[0];
    
                can22_send_fd(0x110, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x109, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x108, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x107, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x106, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x105, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x104, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x103, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x102, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x101, IfxCan_DataLengthCode_64, t_data1);
    
                can22_send_fd(0x12345679, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345678, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345677, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345676, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345675, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345674, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345673, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345672, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345671, IfxCan_DataLengthCode_64, t_data1);
                can22_send_fd(0x12345670, IfxCan_DataLengthCode_64, t_data1);
    
                //will lost
                //can22_send_fd(0x12345671, t_data1);
    
            }
        }
    }
    

    把TC397的的CAN22连到Xavier的CAN0上, Xavier CAN0设置:

    #!/bin/sh
    
    sudo modprobe can
    sudo modprobe can_raw
    sudo modprobe mttcan
    
    sudo ip link set down can0
    sudo ip link set can0 type can bitrate 500000 sample-point 0.8 dbitrate 2000000 dsample-point 0.75 fd on restart-ms 100
    sudo ip link set up can0 
    sudo ifconfig can0 txqueuelen 1000
    

    Xavier也是仲裁段500Kbit/s, 采样点0.8, 数据段2Mbit/s, 采样点0.75.

    restart-ms 100设置总线Bus-Off时, 100ms后重启.

    设置完后查看设置状态 ip -details -statistics link show can0.

    使用 candump -ta -x can0 >50.dat, 这里-ta显示绝对时间, 然后下载程序运行, 上面的20000帧数据全部存到50.dat文件中了, 共计20000行这里截取首尾部分显示:

     (1614240518.371442)  can0  RX B E  110  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.371720)  can0  RX B E  109  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.372054)  can0  RX B E  108  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.372375)  can0  RX B E  107  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.372724)  can0  RX B E  106  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.373140)  can0  RX B E  105  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.373401)  can0  RX B E  104  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.373743)  can0  RX B E  103  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.374080)  can0  RX B E  102  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.374469)  can0  RX B E  101  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.374806)  can0  RX B E  12345679  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.375181)  can0  RX B E  12345678  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.375562)  can0  RX B E  12345677  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.375943)  can0  RX B E  12345676  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.376318)  can0  RX B E  12345675  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.376696)  can0  RX B E  12345674  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.377076)  can0  RX B E  12345673  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.377457)  can0  RX B E  12345672  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.377831)  can0  RX B E  12345671  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.378210)  can0  RX B E  12345670  [64]  01 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.381356)  can0  RX B E       110  [64]  02 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240518.381692)  can0  RX B E       109  [64]  02 00 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     
     ...
    
     (1614240528.360043)  can0  RX B E  12345670  [64]  E7 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.363191)  can0  RX B E       110  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.363530)  can0  RX B E       109  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.363872)  can0  RX B E       108  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.364214)  can0  RX B E       107  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.364589)  can0  RX B E       106  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.364922)  can0  RX B E       105  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.365249)  can0  RX B E       104  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.365582)  can0  RX B E       103  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.365922)  can0  RX B E       102  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.366264)  can0  RX B E       101  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.366642)  can0  RX B E  12345679  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.367020)  can0  RX B E  12345678  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.367398)  can0  RX B E  12345677  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.367776)  can0  RX B E  12345676  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.368154)  can0  RX B E  12345675  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.368532)  can0  RX B E  12345674  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.368909)  can0  RX B E  12345673  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.369289)  can0  RX B E  12345672  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.369666)  can0  RX B E  12345671  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
     (1614240528.370065)  can0  RX B E  12345670  [64]  E8 03 00 00 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 F0 DE BC 9A 78 56 34 12 30 54 76 98
    
    

    Xavier发送脚本, ##后面的3表示开启BRS和ESI:

    #!/bin/sh
    
    while true; do
        cansend can0 18FF0001##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16
        cansend can0 18FF0002##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16
        cansend can0 18FF0003##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16  
        cansend can0 18FF0004##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16
        cansend can0 18FF0005##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16
        cansend can0 18FF0006##3.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16  
        cansend can0 123##3.00.02
        cansend can0 123##1.00.00
        sleep 1
    done
    

    运行后查看接收:

    $ candump -ta -x can0
     (1614241024.270962)  can0  TX B E  18FF0001  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.271395)  can0  RX B E  18FF0001  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.273719)  can0  TX B E  18FF0002  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.274188)  can0  RX B E  18FF0002  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.276424)  can0  TX B E  18FF0003  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.276864)  can0  RX B E  18FF0003  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.280558)  can0  TX B E  18FF0004  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.281040)  can0  RX B E  18FF0004  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.286257)  can0  TX B E  18FF0005  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.286719)  can0  RX B E  18FF0005  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.289169)  can0  TX B E  18FF0006  [64]  01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.289623)  can0  RX B E  18FF0006  [64]  02 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16
     (1614241024.291607)  can0  TX B E       123  [02]  00 02
     (1614241024.291688)  can0  RX B E       123  [02]  01 02
     (1614241024.293145)  can0  TX B -       123  [02]  00 00
     (1614241024.293243)  can0  RX B E       123  [02]  01 00
    

    收到后立即返回.

    微信公众号

    欢迎扫描二维码关注本人微信公众号, 及时获取或者发送给我最新消息:
    在这里插入图片描述

    展开全文
  • AURIX TC397 Multicore 多核

    千次阅读 2020-11-06 18:08:30
    目录TC397 Multicore基础知识片上系统互联和桥多核操作遐想新工程Multicore Example微信公众号 TC397 Multicore基础知识 参考 Multicore_1 for KIT_AURIX_TC397_TFT: AURIX™ TC3xx微控制器架构具有多达6个独立的...

    TC397 Multicore基础知识

    在这里插入图片描述

    参考AURIX™ System ArchitectureMulticore_1 for KIT_AURIX_TC397_TFT:

    • AURIX™ TC3xx微控制器架构具有多达6个独立的处理器内核CPU0…CPU5, 可在一个统一平台上无缝托管多个应用程序和操作系统.
    • 由于实现了具有独立读取接口的多个程序Flash模块, 该架构支持进一步的实时处理.
    • AURIX™专为性能,安全性和安全性而设计,具有并行执行流程,锁步核心和进一步增强的硬件安全机制的功能

    CPU架构;

    • 32位, 六核(TC1.6.2P TriCore), 超标量哈佛(Superscalar Harvard)架构, 2.3 DMIPS/MHz, 6级流水线, 高达300 MHz
    • 所有CPU都有32位浮点单元, 符合IEEE-754的单精度, 每个周期2个FLOP(流水线)
    • 数据,存储器和CPU寄存器的小端字节顺序(Little-endian byte ordering)
    • 乘法和累加(MAC)指令:双16×16、16×32、32×32
    • 时间保护系统,允许有时间限制的实时操作

    TC1.6.2P实现:

    • 大多数指令在1个周期内执行
    • 1、2或3个周期的分支指令(使用动态分支预测)
    • 宽内存接口,用于快速上下文切换
    • 上下文自动进入保存和退出恢复:子例程,中断,陷阱
    • 六个存储器保护寄存器组
    • 双指令发布(并行进入整数管道和加载/存储管道)
    • 第三条流水线仅用于循环指令(零开销循环)
    • 单精度浮点单元(兼容IEEE-754)
    • 专用整数除法单元
    • 18个数据存储器保护范围,10个代码存储器保护范围,分为6组

    片上系统互联和桥

    这一部分手册的内容直接机翻了. 至于怎么用, 这节先不管, 有个概念即可.

    AURIX™ TC3xx平台具有三个独立的片上连接资源:

    • 系统资源互连结构(System Resource Interconnect Fabric, SRI Fabric)
    • 系统外设总线(System Peripheral Bus, SPB))
    • 骨干总线(Back Bone Bus, BBB)

    在这里插入图片描述

    SRI Fabric将TriCore CPU, DMA模块和其他高带宽请求者连接到高带宽存储器和其他资源用于指令提取和数据访问.

    SPB将TriCore CPU, DMA模块和其他SPB主设备连接到中低带宽外设, SPB主服务器不会直接连接到SRI Fabric,而是将通过SRI_F2S桥访问SRI附加的资源.

    BBB将TriCore CPU, DMA模块和SPB主站与ADAS资源相连. 主SRI不直接连接到BBB, 但通过SFI_S2F桥接器访问BBB连接的资源.

    SRI连接TriCore CPU和高性能模块如DMA等. 结构的关键组件是SRI交叉开关, 它将所有代理(agent)连接到一个SRI域. SRI交叉开关承载域的SRI主站和SRI从站之间的事务. SRI交叉开关支持不同SRI主代理和SRI从代理之间的并行事务. 除了并发请求的并行性, 它还支持从SRI主设备到SRI从设备的流水线请求. SRI功能概述:

    • 单次和突发读取和写入事务(最多4个64位突发)
    • 原子读取修改写入事务
    • 从SRI Masters到SRI Slave的管道事务(Pipelined transactions)
    • 每个SRI从站的仲裁器(Arbiter),具有单独的配置: 两个循环分组,高优先级和低优先级; 控制高优先级组的带宽
    • 从SRI主站传输到SRI从站的所有地址和控制信息上的EDC(错误检测代码): 从SRI主站传输到SRI从站以进行写入和RMW的所有数据和控制信息的EDC; 从SRI从站传输到SRI主站以进行读取和RMW的所有数据和控制信息的EDC

    与以前的基于AURIX™的产品相比,AURIX连接性的主要差异:

    • SRI Fabric现在可以包含一个或多个独立的交叉开关
    • SRI Crossbar仲裁方案简化为两层轮询(round-robin)

    在这里插入图片描述

    上图的解释:

    • SRI Fabric由一个或多个交叉开关组成, 这些交叉开关支持单次和突发数据传输. 如果有多个交叉开关, 它们通过桥连接(S2S桥).
    • 连接到同一交叉开关的SRI代理(主从))形成SRI域(domain), TC39xB有3个域: SRI0(4个CPU), SRI1(2个CPU), SRI2(ADAS/调试)
    • S2S桥的特殊之处在于它们存在于两个域中. 由于S2S桥接, 所有SRI主站都可以直接寻址(访问)大多数SRI从站(不是全部的原因: 即使在单个SRI域中, 也可能存在未连接的主从, 因为没有功能交流需求)

    在这里插入图片描述

    上图的解释:

    • SRI交叉开关提供SRI主连接接口(MCIx), 用于连接SRI主模块和SRI从站连接接口(SCIx)
    • SCIx用于将SRI从站模块连接到SRI交叉开关
    • 每个SRI Slave和结构的连接都有一个仲裁器, 用于读/写数据路径
    • SRI Fabric至少包括一个提供管家(housekeeping)功能的Slave, 主要目地是为了允许访问SRI Fabric控制和状态寄存器, 第二个目的是响应(有错误)所有不针对其他SRI Slave的SRI事务
    • 只需要实现系统所需的那些SRI主站到SRI从站连接功能, 例如, 来自另一个域的S2S Master不需要连接到连接回同一域的S2S Slave
    • SRI结构提供了仲裁功能,使每个SRI Master优先级配置不同于每一个SRI Slave. 为了支持系统级诊断, SRI Fabric包含捕获SRI错误和SRI Transaction ID错误

    名词的解释:

    TermDescription
    Agent 代理,媒介An SRI agent is any master or slave device which is connected to the SRI Fabric.
    Master 主An SRI master device is an SRI agent which is able to initiate transactions on the SRI Fabric.
    Slave 从An SRI slave device is an SRI agent which is not able to initiate transactions on the SRI. It is only able to respond to transactions operations that are directed to it by the SRI Fabric.
    SRI crossbar 交叉开关The SRI crossbar provides the interconnects between Masters and Slaves in the same domain. The SRI crossbar includes arbitration mechanisms and error capture capabilities.
    MCI 主连接接口Each Master is connected via one Master Connection Interface. The SRI Fabric contains control and status registers which affect MCI priority and provide related error information.
    SCI 从连接接口Each Slave is connected via one Slave Connection Interface. The SRI Fabric contains control and status registers which include control and error informations related to the SCI.
    Domain 域An SRI domain consists of those agents which are connected to a specific SRI crossbar. There will be at least one Master (or S2S bridge acting as a Master) and at least one Slave (or S2S bridge acting as a Slave), and an instance of a crossbarproviding full or partial connectivity between all the agents in the domain.
    Arbiter 仲裁If two (or more) Masters attempt to access the same Slave, the arbiter provides the decisions as to the order in which Masters gain access. The order is determined by the two-level round-robin mechanism implemented in the arbiter and the configuration programmed by the user.

    多核操作遐想

    拍脑袋能想出来的一般多核注意事项:

    • 外设是公共的, 被一个CPU占用, 其它CPU最好不占用该外设
    • 如果多个CPU共享一个外设, 外设只在一个CPU初始化后, 再在其它CPU进行操作. 最好不要同时写, 或者一个写其它读
    • 至少可以用共享内存的方法进行多核通信?

    英飞凌多和单片机应用技术一书中, 以TC2x举例:

    • 单核MCU工作模式有三种: 复位(Reset), 运行(Run), 待机(Idle)
    • 多核MCU工作模式有四种: 复位(Reset), HALT, 运行(Run), 待机(Idle)

    CPU0外的其它CPU上电后会保持在HALT暂停状态, 需要通过CPU0设置它们的PC程序指针寄存器, 设置HALT相应的位, 从HALT状态切换到RUN状态.

    新工程

    我们打开 AURIX Development Studio, File -> New -> New AURIX Project, 新建的空工程默认就有6个Main.c文件对应6个CPU:

    在这里插入图片描述

    Cpu0_Main.c 内容默认为:

    #include "Ifx_Types.h"
    #include "IfxCpu.h"
    #include "IfxScuWdt.h"
    
    IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
    
    void core0_main(void)
    {
        IfxCpu_enableInterrupts();
        
        /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
         * Enable the watchdogs and service them periodically if it is required
         */
        IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
        IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
        
        /* Wait for CPU sync event */
        IfxCpu_emitEvent(&g_cpuSyncEvent);
        IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
        
        while(1)
        {
        }
    }
    

    Cpu1_Main.c 内容默认为:

    #include "Ifx_Types.h"
    #include "IfxCpu.h"
    #include "IfxScuWdt.h"
    
    extern IfxCpu_syncEvent g_cpuSyncEvent;
    
    void core1_main(void)
    {
        IfxCpu_enableInterrupts();
        
        /* !!WATCHDOG1 IS DISABLED HERE!!
         * Enable the watchdog and service it periodically if it is required
         */
        IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
        
        /* Wait for CPU sync event */
        IfxCpu_emitEvent(&g_cpuSyncEvent);
        IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
        
        while(1)
        {
        }
    }
    

    其中:

    • IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0; 定义在CPU0的Main.c中, 在其它CPU中被引用. 一种共享内存的方法用于核间通信
    • 各个CPU进来先开中断, 关自己的看门狗
    • IfxCpu_waitEvent 该函数将一直等到所有内核在事件中都设置了它们相应的位. 该函数与IfxCpu_emitEvent一起用于实现已配置内核之间的同步, 默认情况下,为所有内核定义IFXCPU_CFG_ALLCORE_DONE
    • 如果一个外设被多个CPU用, 其初始化可以放在Cpu0_Main.c/* Wait for CPU sync event */ 注释上面的地方.

    Multicore Example

    点灯为例, 如果一个核操作一个LED翻转, 互不干涉, 直接在各个Cpux_Main.c初始化延时翻转即可, 不存在冲突. 官方给的这个例子是3个核控制一个LED:

    • 3个CPU都可以访问全局变量标志位
    • Cpu0在其他CPU RUN之前初始化LED, while中判断标志位打开LED
    • Cpu1 While中判断标志位关闭LED
    • Cpu3 While中延时翻转标志位

    Cpu0_Main.c 内容(注意LED初始化放到其它CPU初始化之前):

    #include "Ifx_Types.h"
    #include "IfxCpu.h"
    #include "IfxScuWdt.h"
    
    IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
    
    #define LED    &MODULE_P13, 0   /* LED D107 */
    uint16 g_turnLEDon = FALSE;     /* Variable for the LED, CPU0 and CPU1 are toggling the LED depending on its state  */
    
    void core0_main(void)
    {
        IfxCpu_enableInterrupts();
        
        /* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
         * Enable the watchdogs and service them periodically if it is required
         */
        IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
        IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
        
        //initLED
        IfxPort_setPinHigh(LED);
        IfxPort_setPinMode(LED, IfxPort_Mode_outputPushPullGeneral);
    
        //Initialize the time constants
        initTime();
    
        /* Wait for CPU sync event */
        IfxCpu_emitEvent(&g_cpuSyncEvent);
        IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
        
        while(1)
        {
            if(g_turnLEDon == TRUE)
            {
                IfxPort_setPinLow(LED);     /* Turn on the LED (LED is low-level active)    */
            }
        }
    }
    

    Cpu1_Main.c 内容:

    #include "Ifx_Types.h"
    #include "IfxCpu.h"
    #include "IfxScuWdt.h"
    
    extern IfxCpu_syncEvent g_cpuSyncEvent;
    
    #ifndef LED
    #define LED    &MODULE_P13, 0
    #endif
    extern uint16 g_turnLEDon;
    
    void core1_main(void)
    {
        IfxCpu_enableInterrupts();
        
        /* !!WATCHDOG1 IS DISABLED HERE!!
         * Enable the watchdog and service it periodically if it is required
         */
        IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
        
        /* Wait for CPU sync event */
        IfxCpu_emitEvent(&g_cpuSyncEvent);
        IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
        
        while(1)
        {
            if(g_turnLEDon == FALSE)
            {
                IfxPort_setPinHigh(LED);    /* Turn off the LED (LED is low-level active)   */
            }
        }
    }
    

    Cpu2_Main.c 内容:

    #include "Ifx_Types.h"
    #include "IfxCpu.h"
    #include "IfxScuWdt.h"
    
    extern IfxCpu_syncEvent g_cpuSyncEvent;
    
    #include "Bsp.h"
    #ifndef LED
    #define LED    &MODULE_P13, 0
    #endif
    extern uint16 g_turnLEDon;
    
    void core2_main(void)
    {
        IfxCpu_enableInterrupts();
        
        /* !!WATCHDOG2 IS DISABLED HERE!!
         * Enable the watchdog and service it periodically if it is required
         */
        IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
        
        /* Wait for CPU sync event */
        IfxCpu_emitEvent(&g_cpuSyncEvent);
        IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
        
        while(1)
        {
            g_turnLEDon = !g_turnLEDon;     /* Toggle the state of the global variable      */
            wait(TimeConst_1s);
        }
    }
    

    当然, define或者全局变量的extern可以放到一个公共的头文件如Multicore.h中, 然后所有.c包含即可.

    编译运行, LED每s翻转一次状态.

    微信公众号

    欢迎扫描关注我的微信公众号, 及时获取最新文章:
    在这里插入图片描述

    展开全文
  • AURIX TC397 环境搭建 延时 GPIO

    千次阅读 2020-10-26 16:50:10
    /* Wait 500 milliseconds*/ } 点击锤子形状的 Build Active Project, 编译完后提示: 点 Yes, 自动下载, 提示 Re-loading 'D:\CodeVarietyShop\AURIX-v1.2.2-workspace\TC397_Blink_LED\Debug\TC397_Blink_LED.elf'...
  • TC397开发板KIT_A2G_TC397_5V_TFT简介

    千次阅读 2020-10-26 16:23:44
    用的开发板是KIT_A2G_TC397_5V_TFT, 其实更推荐KIT_A2G_TC397_3V3_TFT, 售价¥ 1,670.59 照片 正面: 背面: 5V的板子和3.3V的板子主要是下面几个器件不同, 测量X103的PIN2即可知道是5V还是3.3V的板子: 资料 配套...
  • AURIX TC397 CAN MCMCAN

    千次阅读 热门讨论 2020-11-09 19:56:03
    目录TC397_CAN简介CAN Loop-BackCAN Transceiver微信公众号 TC397_CAN简介 不同于TC297的MultiCAN+, TC397的CAN模块唤作MCMCAN: 实现了Bosch的M_CAN, 遵循ISO 11898-1(Classical CAN, CAN FD)和ISO 11898-4(Time-...
  • AURIX TC397 Flash编程

    千次阅读 多人点赞 2020-11-06 15:03:14
    参考 Flash_Programming_1 for KIT_AURIX_TC397_TFT, 本例展示了如何烧写PFLASH(Program Flash memory) 和 DFLASH(Data Flash memory). 数据存储单元(DMU, Data Memory Unit)控制执行在PFLASH和DFLASH上的命令序列,...
  • AURIX TC397 ASCLIN UART

    千次阅读 2020-10-27 19:57:56
    目录ASCLIN硬件连接新建工程Debug PrintfASCLIN_UART 发送Ifx_Console_print接收中断TC397_UART工程下载ASCLIN_Shell_UART_1参考微信公众号 ASCLIN ASCLIN, Asynchronous Synchronous Interface, 3合1模块, 可以用...
  • TC397 WDG

    2022-03-24 20:07:53
    简介 watchdog(WD)一方面提供了一种高度可靠和安全的方法来检测软件或硬件故障并从中恢复,另一方面还提供了防止意外寄存器写入访问的保护。 看门狗有两种类型: Safety WD 可防止意外写入关键系统寄存器和存储器...
  • TC397 SPI开发笔记【持续更新中...】

    千次阅读 2021-09-15 14:33:59
    公司一个项目,要实现两个芯片之间的通讯,通讯方式选择SPI,其中主设备为TC397,从设备是TDA4和J3。 特性 Queued Synchronous Peripheral Interface (QSPI) 芯片手册的信息 QSPI模块的主要目的是利用时钟、数据...
  • TC397 MCMCAN

    2022-04-20 23:33:38
    寄存器 基地址 对于 MCMCAN 模块,所有寄存器的前缀为 CAN0_、CAN1_ 或 CAN2_,特定产品变体可能存在相应的模块。 寄存器分为三个不同的部分:
  • AURIX TC397 Timer PWM 之 STM GTM

    千次阅读 2020-11-02 19:46:50
    /* Initialize the STM with the user configuration */ while(1) { } } 参考自 STM_Interrupt_1 for KIT_AURIX_TC397_TFT STM_System_Time 另一个例子是 STM_System_Time_1, 用STM模块得到当前的开机时间(days:...
  • 英飞凌TC397移植FreeRTOS

    2021-12-21 17:55:33
    英飞凌TC397移植FreeRTOS一、准备工作1.FreeRTOS源码2.STM驱动代码3.中断相关配置文件4.AURIX Developement Studio初始工程二、配置port.c 一、准备工作 1.FreeRTOS源码 2.STM驱动代码 3.中断相关配置文件 4....
  • AURIX TC397 Timer PWM 之 GPT12 CCU6

    千次阅读 2020-11-02 19:50:23
    while(1) { } } GPT12_PWM_Generation 参考GPT12_PWM_Generation_1 for KIT_AURIX_TC397_TFT. 用GPT12产生固定频率的PWM和自定义的占空比: GPT1的T3配置为向下计数的定时器模式, 一旦T3下溢出, T3OTL(T3 Output ...
  • TriCore AURIX TC397一览

    万次阅读 2020-07-28 09:46:51
    目录选型Datasheet & Usermanual封装 选型 Datasheet & Usermanual TC397 Datasheet & Usermanual 封装 没找到…参考TC297吧, 封装一样, 但是原理图部分引脚不兼容.
  • AURIX TC397 Timer PWM 基础知识

    千次阅读 2020-10-30 16:32:20
    TC397有下列Timer/PWM资源: 6x STM GTM 1x GPT12 1x CCU6 STM STM, System Timer, 系统定时器, 64bit计数器, 6个STM意味着6个核每个都可以有自己的时基定时器, 用于各自的RTOS GTM GTM, Generic Timer Module, ...
  • AURIX TC397 SCU 之 ERU 外部中断

    千次阅读 2020-11-09 14:21:49
    参考 AURIX™ TC3xx User Manual Part-1 ERU, Event Request Unit, 外部请求单元. TC3XX User Manual 第9章System Control Units (SCU) 第5小节介绍了ERU. 先来看一下系统控制单元SCU, SCU是控制各种系统功能的子...
  • AURIX TC397 SCU 之 Watchdog 看门狗

    千次阅读 2020-11-10 13:28:35
    目录看门狗基础TC397 Watchdog微信公众号 看门狗基础 文档参阅 TC3XX User Manual 的9.4节, 看门狗Watchdog Timers (WDT)是System Control Units (SCU)六大模块之一. TC3xx包含以下看门狗定时器: 1个安全看门狗...
  • TC397 EVADC

    2022-04-14 21:19:37
    系统集成与通信 除了连接到外围总线,EVADC 还直接连接到 AURIX™ TC3xx 平台的其他硬件模块。 图 242 显示了这些互连的概览。 更多详细信息可在 EVADC 以及连接模块的系列文档中找到。 相关寄存器 EVADC 由一系列...
  • TC397 SPI(CPU)

    2022-02-14 21:09:11
    Hardware Setup 配置QSPI initQSPI() 函数初始化了Master和Slave端。 QSPI Slave initialization 相关操作在IfxQspi_SpiSlave.h中 ...QSPI 从模块的初始化是通过定义 IfxQspi_SpiSlave_Config 结构的实例来完成的。...
  • 文章目录 填入license
  • 参考TC3XX User Manual, 11.2.1.4小节, 11.2.3.6小节, 12.2.1.4小节, 12.2.3.6小节. DTS, Die Temperature Sensor, 核心温度传感器. 或者DTSC, Core Die Temperature Sensor. DTS直接产生当前温度的测量结果. DTS...
  • AURIX微控制器TC3xx系列具有高达六核的高性能架构及其在连接性、安全性和功能安全方面的先进特性,非常适合于广泛的汽车和工业应用领域。除了发动机管理和变速器控制外,目标动力总成应用还包括电气和混合驱动的新...
  • TC397 STM(System Timer)

    2022-03-26 12:40:25
    STM 专为需要高精度和长周期的整体系统计时应用而设计。STM 具有以下特点: 自由运行的 64 位计数器 所有 64 位可以同步读取 可以同步读取 64 位计数器的不同 32 位部分 基于与部分STM内容比较匹配的灵活服务请求...
  • TC397.zip

    2022-01-18 12:12:54
    TC397.zip TC39x_DS_v10.pdf TC39x user manual new.pdf
  • TC397A移植FreeRTOS

    千次阅读 2019-08-22 15:05:22
    Free RTOS移植到Infineon第二代Tricore处理器。主要完成三个工作:一、文件框架搭建;二、硬件移植文件修改;三、操作系统配置。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,266
精华内容 506
关键字:

TC397

友情链接: opc+ua.zip