This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F28377D:为 CAN 创建 SYS/BIOS HWI

Guru**** 2535750 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1425916/tms320f28377d-create-sys-bios-hwi-for-can

器件型号:TMS320F28377D

工具与软件:

大家好!

我需要一个帮助来创建一个处理 CAN 总线中断的 HwI/Swi 模块。

我的代码如下所示:

Void hwiCanHandler(xdc_UArg arg)
{
    //
    // Acknowledge this interrupt located in group 9
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
    CanHwiCounter++;
    Swi_post(Can_swi);
}

void CAN_INIT(uint32_t canX_base, uint32_t device_sysCLK_freq, uint32_t can_bitrate)
{
    Hwi_Params  hwiParams;
    Swi_Params  swiParams;
    Error_Block eb;
    uint32_t    interruptNumber;

    Error_init(&eb);
    Hwi_Params_init(&hwiParams);
    Swi_Params_init(&swiParams);

    // pass CAN module base address to interrupt handler
    hwiParams.arg = canX_base;
    hwiParams.enableInt = 1;
    swiParams.priority = 1;
    swiParams.arg0 = canX_base;


    // Function to turn on CAN peripherals, enabling reads and writes to the
    // CANs' registers.
    if(canX_base == CANA_BASE)
    {
        SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_CANA);

        // According to TI documentation: INT_CANA0 ==> id 100, INT_CANA1 ==> id 101
        interruptNumber = 100;
    }
    else if( canX_base == CANB_BASE)
    {
        SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_CANB);

        // According to TI documentation: INT_CANB0 ==> id 102, INT_CANA1 ==> id 103
        interruptNumber = 102;
    }
    else
    {
        ASSERT(0);
    }

    //
    // Initialize the CAN controller
    //
    // Puts the module in Initialization mode, Disables the parity function
    // Initializes the MBX RAM, Initiates a S/W reset of the module
    // Seeks write-access to configuration registers.
    //
    CAN_initModule(canX_base);

    //
    // Set up the CAN bus bit rate up to 1 Mbps
    // Refer to the Driver Library User Guide for information on how to set
    // tighter timing control. Additionally, consult the device data sheet
    // for more information about the CAN module clocking.
    //
    CAN_setBitRate(canX_base, device_sysCLK_freq, can_bitrate, 16);

    //
    // Enable interrupts on the CAN peripheral.
    // Enables Interrupt line 0, Error & Status Change interrupts in CAN_CTL
    // register.
    //
    CAN_enableInterrupt(canX_base, CAN_INT_IE0 | CAN_INT_ERROR |
                        CAN_INT_STATUS);


    // Enable the CAN interrupt signal
    CAN_enableInterrupt(canX_base, CAN_INT_IE0  | CAN_INT_ERROR | CAN_INT_STATUS);
    if(canX_base == CANA_BASE)
    {
        Interrupt_enable(INT_CANA0);
    }
    else
    {
        Interrupt_enable(INT_CANB0);
    }

    // create SYS/BIOS HWI
    Can_hwi = Hwi_create(interruptNumber, hwiCanHandler, &hwiParams, &eb);
    if (Can_hwi == NULL)
    {
        System_abort("Hwi create failed");
    }

    Error_init(&eb);
    Can_swi = Swi_create(swiCanHandler, &swiParams, &eb);
    if (Can_swi == NULL)
    {
        System_abort("Swi create failed");
    }

    Error_init(&eb);
    Can_event = Event_create(NULL, &eb);
    if (Can_event == NULL) {
        System_abort("Event create failed");
    }

    //
    // Start CAN module operations
    //
    CAN_startModule(canX_base);
}

我已经为 CAN 接口创建了一个消息框。
我在总线上发送 CAN 消息、并且我可以看到消息框已就绪、但较新地调用了中断例程。

我的代码中有哪些错误/缺失?

感谢您的帮助。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Fabrice:

    您使用的 SYS/BIOS 是否支持 F29377D 器件?

     调用 hwi_create()后、请检查 ISR 处理程序的地址是否写入向量表。 表地址为0xd00 + INT_NUMBER *2

    如果使用 CANA IE0、中断号为100、地址为0xd00 + 0x64*2 = 0xDC8

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢 QJ Wang 的帮助。

    我可以解决我的问题。

    问题是、我在设置消息目标之前启用了 CAN 模块。