/** * brief Register a specific plic interrupt and register the handler * details * This function set priority and handler for plic interrupt * param [in] source interrupt source * param [in] priority interrupt priority * param [in] handler interrupt handler, if NULL, handler will not be installed * return -1 means invalid input parameter. 0 means successful. * remarks * - This function use to configure specific plic interrupt and register its interrupt handler and enable its interrupt. */ __enable_irq();int32_t PLIC_Register_IRQ(uint32_t source, uint8_t priority, void *handler){ if ((source >= __PLIC_INTNUM)) { return -1; } /* set interrupt priority */ PLIC_SetPriority(source, priority); if (handler != NULL) { /* register interrupt handler entry to external handlers */ Interrupt_Register_ExtIRQ(source, (unsigned long)handler); } /* enable interrupt */ PLIC_EnableInterrupt(source); //PLIC的每一个中断源的外部使能 __enable_ext_irq(); //Enable External IRQ Interrupts 打开外部中断使能 return 0;}
软件中断与计时器中断 clint
软件中断与计时器中断相当于在核内部的中断 中断源的ID与内部的异常在一起编码
/** * brief Register a riscv core interrupt and register the handler * details * This function set interrupt handler for core interrupt * param [in] irqn interrupt number * param [in] handler interrupt handler, if NULL, handler will not be installed * return -1 means invalid input parameter. 0 means successful. * remarks * - This function use to configure riscv core interrupt and register its interrupt handler and enable its interrupt. */int32_t Core_Register_IRQ(uint32_t irqn, void *handler){ if ((irqn > 10)) { return -1; } if (handler != NULL) { /* register interrupt handler entry to core handlers */ Interrupt_Register_CoreIRQ(irqn, (unsigned long)handler); } switch (irqn) { case SysTimerSW_IRQn: __enable_sw_irq(); break; case SysTimer_IRQn: __enable_timer_irq(); break; default: break; } return 0;}