source: soft/giet_vm/sys/irq_handler.c @ 160

Last change on this file since 160 was 160, checked in by karaoui, 12 years ago

giet-vm new version

File size: 7.6 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : irq_handler.c
3// Date     : 01/04/2012
4// Author   : alain greiner and joel porquet
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The irq_handler.c and irq_handler.h files are part of the GIET nano-kernel.
8// They contain the code of the _int_demux function that handle
9// the ICU (Interupt Controler Unit), and the various ISRs associated
10// to the CoCLib peripherals.
11///////////////////////////////////////////////////////////////////////////////////
12
13#include <giet_config.h>
14#include <irq_handler.h>
15#include <sys_handler.h>
16#include <drivers.h>
17#include <common.h>
18#include <ctx_handler.h>
19#include <hwr_mapping.h>
20
21///////////////////////////////////////////////////////////////////////////////////
22// Initialize the whole interrupt vector with the default ISR
23///////////////////////////////////////////////////////////////////////////////////
24
25_isr_func_t _interrupt_vector[32] = { [0 ... 31] = &_isr_default };
26
27///////////////////////////////////////////////////////////////////////////////////
28//      _int_demux()
29// This functions uses an external ICU component (Interrupt Controler Unit)
30// that concentrates up to 32 input interrupts lines. This component
31// can support up to NB_PROCS_MAX output IRQ.
32//
33// This component returns the highest priority active interrupt index (smaller
34// indexes have the highest priority) by reading the ICU_IT_VECTOR register.
35// Any value larger than 31 means "no active interrupt", and the default ISR
36// (that does nothing) is executed.
37//
38// The interrupt vector (32 ISR addresses array stored at _interrupt_vector
39// address) is initialised with the default ISR address. The actual ISR
40// addresses are supposed to be written in the interrupt vector array by the
41// boot code.
42///////////////////////////////////////////////////////////////////////////////////
43void _int_demux(void)
44{
45    int interrupt_index;
46    _isr_func_t isr;
47
48    // interrupt vector initialisation
49
50
51    /* retrieves the highest priority active interrupt index */
52    if (!_icu_read(ICU_IT_VECTOR, (unsigned int*)&interrupt_index))
53    {
54        /* no interrupt is active */
55        if (interrupt_index == -1)
56            return;
57
58        /* call the ISR corresponding to this index */
59        isr = _interrupt_vector[interrupt_index];
60        isr();
61    }
62}
63///////////////////////////////////////////////////////////////////////////////////
64//      _isr_default()
65// The default ISR is called when no specific ISR has been installed in the
66// interrupt vector. It simply displays a message on TTY0.
67///////////////////////////////////////////////////////////////////////////////////
68void _isr_default()
69{
70    _puts("\n\n!!! Default ISR !!!\n");
71}
72///////////////////////////////////////////////////////////////////////////////////
73//      _isr_dma()
74// This ISR acknowledges the interrupt from the dma controller, depending on
75// the proc_id. It reset the global variable _dma_busy[i] for software
76// signaling, after copying the DMA status into the _dma_status[i] variable.
77///////////////////////////////////////////////////////////////////////////////////
78void _isr_dma()
79{
80    volatile unsigned int* dma_address;
81    unsigned int proc_id;
82
83    proc_id = _procid();
84    dma_address = (unsigned int*)&seg_dma_base + (proc_id * DMA_SPAN);
85
86    _dma_status[proc_id] = dma_address[DMA_LEN]; /* save status */
87    _dma_busy[proc_id] = 0;                      /* release DMA */
88    dma_address[DMA_RESET] = 0;                  /* reset IRQ */
89}
90///////////////////////////////////////////////////////////////////////////////////
91//      _isr_ioc()
92// There is only one IOC controler shared by all tasks. It acknowledge the IRQ
93// using the ioc base address, save the status, and set the _ioc_done variable
94// to signal completion.
95///////////////////////////////////////////////////////////////////////////////////
96void _isr_ioc()
97{
98    volatile unsigned int* ioc_address;
99
100    ioc_address = (unsigned int*)&seg_ioc_base;
101
102    _ioc_status = ioc_address[BLOCK_DEVICE_STATUS]; /* save status & reset IRQ */
103    _ioc_done   = 1;                                /* signals completion */
104}
105///////////////////////////////////////////////////////////////////////////////////
106//      _isr_timer_* (* = 0,1,2,3,4,5,6,7)
107// This ISR handles up to 8 IRQs generated by 8 independant timers.
108// It acknowledges the IRQ on TIMER[*] and displays a message on TTY0
109///////////////////////////////////////////////////////////////////////////////////
110void _isr_timer_indexed(unsigned int timer_id)
111{
112    volatile unsigned int *timer_address;
113
114    timer_address = (unsigned int*)&seg_timer_base + (timer_id * TIMER_SPAN);
115
116    timer_address[TIMER_RESETIRQ] = 0; /* reset IRQ */
117
118    _puts("\n\n!!! Interrupt timer received from timer ");
119    _putw( timer_id );
120    _puts(" at cycle ");
121    _putw( _proctime() );
122    _puts("\n\n");
123}
124
125void _isr_timer_0()  { _isr_timer_indexed(0);  }
126void _isr_timer_1()  { _isr_timer_indexed(1);  }
127void _isr_timer_2()  { _isr_timer_indexed(2);  }
128void _isr_timer_3()  { _isr_timer_indexed(3);  }
129void _isr_timer_4()  { _isr_timer_indexed(4);  }
130void _isr_timer_5()  { _isr_timer_indexed(5);  }
131void _isr_timer_6()  { _isr_timer_indexed(6);  }
132void _isr_timer_7()  { _isr_timer_indexed(7);  }
133
134///////////////////////////////////////////////////////////////////////////////////
135// _isr_tty_get_* (* = 0,1,2,3,4,5,6,7,9,10,11,12,13,14,15)
136// The Giet supports up to 16 TTY terminals.
137// These 16 ISRs handle the up to 16 IRQs associated to 16 independant
138// terminals, signaling that a character is available.
139// There is one communication buffer _tty_get_buf[tty_id] per terminal.
140// The sychronisation variable _tty_get_full[tty_id], is set by the ISR,
141// and reset by the OS.
142// A character is lost if the buffer is full when the ISR is executed.
143///////////////////////////////////////////////////////////////////////////////////
144void _isr_tty_get_indexed(unsigned int tty_id)
145{
146    volatile unsigned int *tty_address;
147
148    /* compute terminal base address */
149    tty_address = (unsigned int*)&seg_tty_base + (tty_id * TTY_SPAN);
150
151    /* save character and reset IRQ */
152    _tty_get_buf[tty_id] = (unsigned char)tty_address[TTY_READ];
153
154    /* signals character available */
155    _tty_get_full[tty_id] = 1;
156}
157
158void _isr_tty_get_0()  { _isr_tty_get_indexed(0);  }
159void _isr_tty_get_1()  { _isr_tty_get_indexed(1);  }
160void _isr_tty_get_2()  { _isr_tty_get_indexed(2);  }
161void _isr_tty_get_3()  { _isr_tty_get_indexed(3);  }
162void _isr_tty_get_4()  { _isr_tty_get_indexed(4);  }
163void _isr_tty_get_5()  { _isr_tty_get_indexed(5);  }
164void _isr_tty_get_6()  { _isr_tty_get_indexed(6);  }
165void _isr_tty_get_7()  { _isr_tty_get_indexed(7);  }
166void _isr_tty_get_8()  { _isr_tty_get_indexed(8);  }
167void _isr_tty_get_9()  { _isr_tty_get_indexed(9);  }
168void _isr_tty_get_10() { _isr_tty_get_indexed(10); }
169void _isr_tty_get_11() { _isr_tty_get_indexed(11); }
170void _isr_tty_get_12() { _isr_tty_get_indexed(12); }
171void _isr_tty_get_13() { _isr_tty_get_indexed(13); }
172void _isr_tty_get_14() { _isr_tty_get_indexed(14); }
173void _isr_tty_get_15() { _isr_tty_get_indexed(15); }
174
175/////////////////////////////////////////////////////////////////////////////////////
176// _isr_switch
177// This ISR is in charge of context switch.
178// It acknowledges the IRQ on TIMER[proc_id] and calls the _ctx_switch() function.
179/////////////////////////////////////////////////////////////////////////////////////
180void _isr_switch()
181{
182    volatile unsigned int *timer_address;
183    unsigned int proc_id;
184
185    proc_id = _procid();
186    timer_address = (unsigned int*)&seg_timer_base + (proc_id * TIMER_SPAN);
187
188    timer_address[TIMER_RESETIRQ] = 0; /* reset IRQ */
189    _ctx_switch();
190}
191
Note: See TracBrowser for help on using the repository browser.