組み込み型オペレーティングシステム開発プロジェクトCH 6

4050 ワード

インタラプトコントローラ

  • In this chapter, I will write Interrupt controler init code and handler mapping code.
  • My system starts from Entry.S to main function in main.c. Therefore I'll add spinning section (while loop) in main function after CH3~ CH5 settings for checking Interrupt to work well.
  • #include "stdint.h"
    #include "HalUart.h"
    #include "stdio.h"
    
    static void Hw_init();
    
    void main(void){
    	Hw_init();
    	
    	uint32_t i= 100;
    	while(i--){
    		Hal_uart_put_char('N');
    	}
    	putstr("\n");
    	
    	putstr("Jello world\n");			
    	i=10;
    	
    	char *str = "hihi first printf";
    	debug_printf("%u: %x %s\n",1,14,str);
    	
    	while(i--){
    		uint8_t c= Hal_uart_get_char();
    		
    		Hal_uart_put_char(c);
    	}
        
        while(true); // add here!
    }
    
    
    static void Hw_init(){
    	Hal_uart_init();
    }
  • I'm done settings, so I'll start Interrupt controler coding.
  • データテーブル

  • RealviewPB has an Interrupt controler named GIC. At now, I examin the GIC register and make a GIC struct.
  • CPU control register


    typedef union CpuControl_t
    {
        uint32_t all;
        struct {
            uint32_t Enable:1;          // 0
            uint32_t reserved:31;
        } bits;
    } CpuControl_t;
  • [31:1]
    - reserved
  • [0]
    - b0 = disable the CPU interface for this GIC
    - b1 = enable the CPU interface for this GIC
  • Priority Mask register.


    typedef union PriorityMask_t
    {
        uint32_t all;
        struct {
            uint32_t Reserved:4;        // 3:0
            uint32_t Prioritymask:4;    // 7:4
            uint32_t reserved:24;
        } bits;
    } PriorityMask_t;
  • The CPU Interface doesn't receive an Interrupt request if the priority of the Interrupt is equel to or greater than the mask set.
  • [31:8]
    - reserved
  • [7:4]
    -Priority Mask
  • [3:0]
    - reserved
  • BInsry Printer register


    typedef union BinaryPoint_t
    {
        uint32_t all;
        struct {
            uint32_t Binarypoint:3;     // 2:0
            uint32_t reserved:29;
        } bits;
    } BinaryPoint_t;
  • For the purpose of establishing the pre-emption criteria between Interrupts.
  • [31:3]
    - reserved
  • [2:0]
    - The criteria of comparing priority for pre-emption.
  • b011 : All priority bits are compared for pre-emption.
  • b100 : Only bits [7:5] of priority are compared.
  • b101 : Only bits [7:6] are compared.
  • b110 : Only bits [7] are.
  • b111 : No pre-emption is perfomed between Interrupts.
  • Interrupt acknowledge register


    typedef union InterruptAck_t
    {
        uint32_t all;
        struct {
            uint32_t InterruptID:10;    // 9:0
            uint32_t CPUsourceID:3;     // 12:10
            uint32_t reserved:19;
        } bits;
    } InterruptAck_t;
    
  • The cpu acuire the interrupt number by reading this register
  • [31:13]
    - reserved
  • [12:10]
    - CPU ID, reserved for multi processor.
  • [9:0]
    - The Interrupt number, read only.
  • End of Interrupt register


    typedef union EndOfInterrupt_t
    {
        uint32_t all;
        struct {
            uint32_t InterruptID:10;    // 9:0
            uint32_t CPUsourceID:3;     // 12:10
            uint32_t reserved:19;
        } bits;
    } EndOfInterrupt_t;
  • When the Interrupt complete its works, it writes the Interrupt number to this register.