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.

tm4c123gh6pm中断优先级的问题

请问如何设置中断优先? void IntPrioritySet(uint32_t ui32Interrupt, uint8_t ui8Priority),这个函数怎么用?参数分别是什么?大神可否给个例子?谢谢

  • 请参考TivaWare中的文档:

    C:\ti\TivaWare_C_Series-2.1.0.12573\docs\SW-TM4C-DRL-UG-2.1.0.12573.pdf中360页

    有详细的描述,参数说明和例子。

  • Parameters: ui32Interrupt specifies the interrupt in question. ui8Priority specifies the priority of the interrupt.

    Description: This function is used to set the priority of an interrupt. When multiple interrupts are asserted simultaneously, the ones with the highest priority are processed before the lower priority interrupts. Smaller numbers correspond to higher interrupt priorities; priority 0 is the highest interrupt priority. The hardware priority mechanism only looks at the upper N bits of the priority level (where N is 3 for the Tiva C and E Series family), so any prioritization must be performed in those bits. The remaining bits can be used to sub-prioritize the interrupt sources, and may be used by the hardware priority mechanism on a future part. This arrangement allows priorities to migrate to different NVIC implementations without changing the gross prioritization of the interrupts.

    请问是这个吗?这个还是不很明白ui8Priority怎么用。例子好像是

    // The interrupt handler function.

    // extern void IntHandler(void); //

     // Register the interrupt handler function for interrupt 5.

    // IntRegister(5, IntHandler); //

     // Enable interrupt 5.

     // IntEnable(5); //

     // Enable interrupt 5.

     // IntMasterEnable();

    我的是SW-TM4C-DRL-UG-2.0.1.11577这个版本,莫非孙工的2.1.0.12573有中断优先级的描述?

  • 你不是已经贴出来了吗?

     Smaller numbers correspond to higher interrupt priorities; priority 0 is the highest interrupt priority.

    翻译过来:

    小的数字相当于高的优先级。0是最高的优先级。

    还有一句话,The hardware priority mechanism only looks at the upper N bits of the priority level (where N is 3 for the Tiva C and E Series family)

    也就是说3bit数据来表征优先级,就是共8个优先级。.

    也都有宏定义。

    你的例子哪里来的?

    2.1.0.12573文档的360页:

    Example: Set priorities for UART 0 and USB interrupts.
    //
    // Set the UART 0 interrupt priority to the lowest priority.
    //
    IntPrioritySet(INT_UART0, 0xE0);
    //
    // Set the USB 0 interrupt priority to the highest priority.
    //
    IntPrioritySet(INT_USB0, 0);

  • Datasheet中也有关于优先级更加详细的描述,感兴趣可以去翻看一下。

  • 再来一个例程把,看的清楚:

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\dk-tm4c123g\interrupts

    这里有如何设置优先级。

  • 我的版本低了点,谢谢啊!

  • 请问为什么0xE0表示的是3bit时最低的优先级呢?还有INT_UART0这种中断类型是在什么头文件里定义的?

  • INT_UART0在hw_ints.h中定义的,给你个hw_ints.h的说明

    / hw_ints.h - Macros that define the interrupt assignment on Tiva C Series
    // MCUs.


  • IntPrioritySet(uint32_t ui32Interrupt, uint8_t ui8Priority)
    {
        uint32_t ui32Temp;
    
        //
        // Check the arguments.
        //
        ASSERT((ui32Interrupt >= 4) && (ui32Interrupt < NUM_INTERRUPTS));
    
        //
        // Set the interrupt priority.
        //
        ui32Temp = HWREG(g_pui32Regs[ui32Interrupt >> 2]);
        ui32Temp &= ~(0xFF << (8 * (ui32Interrupt & 3)));
        ui32Temp |= ui8Priority << (8 * (ui32Interrupt & 3));
        HWREG(g_pui32Regs[ui32Interrupt >> 2]) = ui32Temp;
    }

    你对着寄存器看看就知道了