임베디드 OS 개발 프로젝트 CH6-3

유형주·2021년 8월 23일
0

So far, I have examined Interrupt controller register and designed "Interrupt.c" performing to enable, disable Interrupt, and define handlers.
Eventhough I made Interrupt method, I can't utilize Interrupt without any hardware.
In CH6-3, I will set UART interrupt and define UART interrupt handlers.



Uart.c

void Hal_uart_init(void){
	Uart->uartcr.bits.UARTEN=0;
	Uart->uartcr.bits.TXE=1;
	Uart->uartcr.bits.RXE=1;
	Uart->uartcr.bits.UARTEN=1;

	Uart->uartimsc.bits.RXIM = 1;
    // enable input interrupt

	Hal_interrupt_enable(UART_INTERRUPT0);
	Hal_interrupt_register_handler(interrupt_handler, UART_INTERRUPT0);
}


static void interrupt_handler(void){
	uint8_t ch = Hal_uart_get_char();
	Hal_uart_put_char(ch);

}
  • I add 3 lines below to "Uart.c".
  • "Hal_interrupt_enable(UART_INTERRUPT0)" enables Uart interrupt. (defined in Interrupt.c)
  • "Hal_interrupt_register_handler(interrupt_handler, UART_INTERRUPT0)" regist a handler for Uart interrupt.



익셉션

  • When an IRQ interrupt invoked, the cpu changes its mode to the irq mode.
  • The first instruction after the change is the execption handler defined in "Entry.S".
  • I had set nothing to the IRQ execption handler.
#include "ARMv7AR.h"
#include "MemoryMap.h"

.text
	.code 32

	.global vector_start
	.global vector_end

	vector_start:
		LDR PC, reset_handler_addr
		LDR PC, undef_handler_addr
		LDR PC, svc_handler_addr
		LDR PC,	pftch_abt_handler_addr
		LDR PC,	data_abt_handler_addr
		B   .
		LDR PC,	irq_handler_addr
		LDR PC, fiq_handler_addr

		reset_handler_addr:	.word reset_handler
		undef_handler_addr:	.word dummy_handler
		svc_handler_addr:	.word dummy_handler
		pftch_abt_handler_addr:	.word dummy_handler
		data_abt_handler_addr:	.word dummy_handler
        
        // 여기를 바꿨다.
		irq_handler_addr:	.word Irq_Handler
		fiq_handler_addr:	.word Fiq_Handler
  • dummy_handler로 아무 일도 안했던 것을 "Irq_Handler"로 바꿧다.
  • Then I have to define what Irq_Handler do.
#include "stdbool.h"
#include "stdint.h"
#include "HalInterrupt.h"

__attribute__ ((interrupt("IRQ"))) void Irq_Handler(void){
	Hal_interrupt_run_handler();
}
  • It is a definition of the "Irq_Handler"
  • Hal_interrupt_run_handler is defined in "Interrupt.c"
  • It executes the handler routine mapped to the given interrupt number.

I' done now...
Keyboard input and display works well.

0개의 댓글

관련 채용 정보