PolarFire® SoC mpfs-mmuart-interrupt 串口1 本地中断 初始化过程

 

#define MSS_PERIPH_MMUART_U54_1 MSS_PERIPH_MMUART1

 

1、首先 复位 串口1 

    (void) mss_config_clk_rst(MSS_PERIPH_MMUART_U54_1, (uint8_t) 1, PERIPHERAL_ON);

 

2、参数初始化 波特率,数据8bit , 无校验 1位停止位

MSS_UART_init(p_uartmap_u54_1, MSS_UART_115200_BAUD, MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT);

 

3、 中断初始化,并设置中断接收回调函数,接收触发等级为 1字节

MSS_UART_set_rx_handler(p_uartmap_u54_1, uart1_rx_handler, MSS_UART_FIFO_SINGLE_BYTE);

 

4、使能本地中断

    MSS_UART_enable_local_irq(p_uartmap_u54_1);

 

重点 看下  MSS_UART_enable_local_irq 函数

 

  // 关闭 该串口 对应的  平台中断

    disable_irq(this_uart);

  // 使能本地中断号 传进去 的 值 是 MMUART0_E51_INT 为 11

    __enable_local_irq((int8_t)MMUART0_E51_INT);

 

这里 设置 本地中断 LOCAL_INT_OFFSET_IN_MIE 值为 16

set_csr(mie, (0x1LLU << (int8_t)(local_interrupt + LOCAL_INT_OFFSET_IN_MIE))); /* mie Register- Machine Interrupt Enable Register */

 

所以 FreeRTOS 接管中断后,串口1接收中断,读取 mcause 寄存器的值 为  irq:0x800000000000001b 

0x1b  =  27 

 

问题: 本地中断号 27  , 为啥是 串口1 ? 换句话说 串口1的中断 如何 绑定到 本地中断号 27?

 

2025年9月17日 18点06分 下班

2025年9月18日 09点47分  上班

 

答案 在 PolarFire SoC MSS Technical Reference Manual 中  第五章节  Interrupts 中 表格 Table 5-1. Routing of Interrupts to Processor Cores

串口1对应,hart1 本地中断号 11 ,  11和 27 对不上,  这个需要 查看 表 Table 5-6. Interrupt Exception Codes

mcause  寄存器的 中断号  16 对应 本地中断0, 因此 从 mcause 获取到 的中断号  需要减去16  ; 27-16 =11 . 这样就理清了!

 

image

 

 

image

 

 

 

查了下代码,  找到 /mpfs-mmuart-interrupt/src/platform/mpfs_hal/common/mss_mtrap.c 文件中 

void trap_from_machine_mode(uintptr_t * regs, uintptr_t dummy, uintptr_t mepc) 函数;

找到 本地中断处理函数, 这里传入 参数 interrupt_no = 27

void handle_local_interrupt(uint8_t interrupt_no) 

该函数中, 换算本地中断号 - 16U

uint8_t local_interrupt_no = (uint8_t)(interrupt_no - 16U);

因此   local_interrupt_no = 27-16 =11;

对应  local_irq_handler_1_table 中断数组 如下:

/* U54 1 */
local_int_p_t local_irq_handler_1_table[E51_LOCAL_NUM_SOURCES] =
{
    /*reference multiple interrupts*/
    U54_spare_0_local_IRQHandler,
    U54_spare_1_local_IRQHandler,
    U54_spare_2_local_IRQHandler,

    /*parse hart ID to discover which mac is the source*/
    U54_1_mac0_mmsl_local_IRQHandler,
    U54_1_mac0_emac_local_IRQHandler,
    U54_1_mac0_queue3_local_IRQHandler,
    U54_1_mac0_queue2_local_IRQHandler,
    U54_1_mac0_queue1_local_IRQHandler,
    U54_1_mac0_int_local_IRQHandler,

    /*parse hart ID to discover which wdog is the source*/
    U54_1_wdog_tout_local_IRQHandler,
    U54_1_wdog_mvrp_local_IRQHandler,
    U54_1_mmuart1_local_IRQHandler,

    U54_spare_3_local_IRQHandler,
    U54_spare_4_local_IRQHandler,
    U54_spare_5_local_IRQHandler,
    U54_spare_6_local_IRQHandler,

    U54_f2m_0_local_IRQHandler,
    U54_f2m_1_local_IRQHandler,
    U54_f2m_2_local_IRQHandler,
    U54_f2m_3_local_IRQHandler,
    U54_f2m_4_local_IRQHandler,
    U54_f2m_5_local_IRQHandler,
    U54_f2m_6_local_IRQHandler,
    U54_f2m_7_local_IRQHandler,
    U54_f2m_8_local_IRQHandler,
    U54_f2m_9_local_IRQHandler,

    U54_f2m_10_local_IRQHandler,
    U54_f2m_11_local_IRQHandler,
    U54_f2m_12_local_IRQHandler,
    U54_f2m_13_local_IRQHandler,
    U54_f2m_14_local_IRQHandler,
    U54_f2m_15_local_IRQHandler,
    U54_f2m_16_local_IRQHandler,
    U54_f2m_17_local_IRQHandler,
    U54_f2m_18_local_IRQHandler,
    U54_f2m_19_local_IRQHandler,

    U54_f2m_20_local_IRQHandler,
    U54_f2m_21_local_IRQHandler,
    U54_f2m_22_local_IRQHandler,
    U54_f2m_23_local_IRQHandler,
    U54_f2m_24_local_IRQHandler,
    U54_f2m_25_local_IRQHandler,
    U54_f2m_26_local_IRQHandler,
    U54_f2m_27_local_IRQHandler,
    U54_f2m_28_local_IRQHandler,
    U54_f2m_29_local_IRQHandler,

    U54_f2m_30_local_IRQHandler,
    U54_f2m_31_local_IRQHandler
};

 

11 对应 的中断  就是   U54_1_mmuart1_local_IRQHandler

 

posted on 2025-09-17 17:58  所长  阅读(20)  评论(0)    收藏  举报

导航