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

Last change on this file since 166 was 165, checked in by alain, 12 years ago

Introducing various modifications in kernel initialisation

File size: 8.1 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 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
41// during system initialisation.
42///////////////////////////////////////////////////////////////////////////////////
43void _int_demux(void)
44{
45    int                         interrupt_index;
46    _isr_func_t         isr;
47    unsigned int        pid = _procid();
48
49    // retrieves the highest priority active interrupt index
50    if (!_icu_read( pid / NB_PROCS,
51                    pid % NB_PROCS,
52                    ICU_IT_VECTOR,
53                    (unsigned int*)&interrupt_index ) )
54    {
55        if (interrupt_index == -1)      // no interrupt is active
56            return;
57
58        isr = _interrupt_vector[interrupt_index];
59        isr();
60    }
61    else
62    {
63        _puts("\n[GIET ERROR] In _demux function : wrong arguments in _icu_read()\n");
64        _exit();
65    }
66}
67///////////////////////////////////////////////////////////////////////////////////
68//      _isr_default()
69// The default ISR is called when no specific ISR has been installed in the
70// interrupt vector. It simply displays a message on TTY0.
71///////////////////////////////////////////////////////////////////////////////////
72void _isr_default()
73{
74    _puts("\n\n!!! Default ISR !!!\n");
75}
76
77///////////////////////////////////////////////////////////////////////////////////
78//      _isr_dma()
79// This ISR handles up to 8 IRQs generated by 8 independant channels of the
80// multi_dma component. It acknowledges the interrupt and reset the synchronisation
81// variable _dma_busy[i], after copying the status into the _dma_status[i] variable.
82///////////////////////////////////////////////////////////////////////////////////
83void _isr_dma_indexed( unsigned int dma_id )
84{
85    volatile unsigned int* dma_address;
86
87    dma_address = (unsigned int*)&seg_dma_base + (dma_id * DMA_SPAN);
88
89    dma_address[DMA_RESET] = 0;                                 /* reset IRQ */
90
91    _dma_status[dma_id] = dma_address[DMA_LEN]; /* save status */
92    _dma_busy[dma_id] = 0;                      /* release DMA */
93}
94
95void _isr_dma_0() { _isr_dma_indexed(0); }
96void _isr_dma_1() { _isr_dma_indexed(1); }
97void _isr_dma_2() { _isr_dma_indexed(2); }
98void _isr_dma_3() { _isr_dma_indexed(3); }
99void _isr_dma_4() { _isr_dma_indexed(4); }
100void _isr_dma_5() { _isr_dma_indexed(5); }
101void _isr_dma_6() { _isr_dma_indexed(6); }
102void _isr_dma_7() { _isr_dma_indexed(7); }
103
104///////////////////////////////////////////////////////////////////////////////////
105//      _isr_ioc()
106// There is only one IOC controler shared by all tasks. It acknowledge the IRQ
107// using the ioc base address, save the status, and set the _ioc_done variable
108// to signal completion.
109///////////////////////////////////////////////////////////////////////////////////
110void _isr_ioc()
111{
112    volatile unsigned int* ioc_address;
113
114    ioc_address = (unsigned int*)&seg_ioc_base;
115
116    _ioc_status = ioc_address[BLOCK_DEVICE_STATUS]; /* save status & reset IRQ */
117    _ioc_done   = 1;                                /* signals completion */
118}
119
120///////////////////////////////////////////////////////////////////////////////////
121//      _isr_timer_* (* = 0,1,2,3,4,5,6,7)
122// This ISR handles up to 8 IRQs generated by 8 independant timers.
123// It acknowledges the IRQ on TIMER[*] and displays a message on TTY0
124///////////////////////////////////////////////////////////////////////////////////
125void _isr_timer_indexed(unsigned int timer_id)
126{
127    volatile unsigned int *timer_address;
128
129    timer_address = (unsigned int*)&seg_timer_base + (timer_id * TIMER_SPAN);
130
131    timer_address[TIMER_RESETIRQ] = 0; /* reset IRQ */
132
133    _puts("\n\n!!! Interrupt timer received from timer ");
134    _putw( timer_id );
135    _puts(" at cycle ");
136    _putw( _proctime() );
137    _puts("\n\n");
138}
139
140void _isr_timer_0()  { _isr_timer_indexed(0);  }
141void _isr_timer_1()  { _isr_timer_indexed(1);  }
142void _isr_timer_2()  { _isr_timer_indexed(2);  }
143void _isr_timer_3()  { _isr_timer_indexed(3);  }
144void _isr_timer_4()  { _isr_timer_indexed(4);  }
145void _isr_timer_5()  { _isr_timer_indexed(5);  }
146void _isr_timer_6()  { _isr_timer_indexed(6);  }
147void _isr_timer_7()  { _isr_timer_indexed(7);  }
148
149///////////////////////////////////////////////////////////////////////////////////
150// _isr_tty_get_* (* = 0,1,2,3,4,5,6,7,9,10,11,12,13,14,15)
151// The Giet supports up to 16 TTY terminals.
152// These 16 ISRs handle the up to 16 IRQs associated to 16 independant
153// terminals, signaling that a character is available.
154// There is one communication buffer _tty_get_buf[tty_id] per terminal.
155// The sychronisation variable _tty_get_full[tty_id], is set by the ISR,
156// and reset by the OS.
157// A character is lost if the buffer is full when the ISR is executed.
158///////////////////////////////////////////////////////////////////////////////////
159void _isr_tty_get_indexed(unsigned int tty_id)
160{
161    volatile unsigned int *tty_address;
162
163    /* compute terminal base address */
164    tty_address = (unsigned int*)&seg_tty_base + (tty_id * TTY_SPAN);
165
166    /* save character and reset IRQ */
167    _tty_get_buf[tty_id] = (unsigned char)tty_address[TTY_READ];
168
169    /* signals character available */
170    _tty_get_full[tty_id] = 1;
171}
172
173void _isr_tty_get_0()  { _isr_tty_get_indexed(0);  }
174void _isr_tty_get_1()  { _isr_tty_get_indexed(1);  }
175void _isr_tty_get_2()  { _isr_tty_get_indexed(2);  }
176void _isr_tty_get_3()  { _isr_tty_get_indexed(3);  }
177void _isr_tty_get_4()  { _isr_tty_get_indexed(4);  }
178void _isr_tty_get_5()  { _isr_tty_get_indexed(5);  }
179void _isr_tty_get_6()  { _isr_tty_get_indexed(6);  }
180void _isr_tty_get_7()  { _isr_tty_get_indexed(7);  }
181void _isr_tty_get_8()  { _isr_tty_get_indexed(8);  }
182void _isr_tty_get_9()  { _isr_tty_get_indexed(9);  }
183void _isr_tty_get_10() { _isr_tty_get_indexed(10); }
184void _isr_tty_get_11() { _isr_tty_get_indexed(11); }
185void _isr_tty_get_12() { _isr_tty_get_indexed(12); }
186void _isr_tty_get_13() { _isr_tty_get_indexed(13); }
187void _isr_tty_get_14() { _isr_tty_get_indexed(14); }
188void _isr_tty_get_15() { _isr_tty_get_indexed(15); }
189
190/////////////////////////////////////////////////////////////////////////////////////
191// _isr_switch
192// This ISR is in charge of context switch.
193// It acknowledges the IRQ on TIMER[proc_id] and calls the _ctx_switch() function.
194/////////////////////////////////////////////////////////////////////////////////////
195void _isr_switch()
196{
197    volatile unsigned int *timer_address;
198    unsigned int proc_id;
199
200    proc_id = _procid();
201    timer_address = (unsigned int*)&seg_timer_base + (proc_id * TIMER_SPAN);
202
203    timer_address[TIMER_RESETIRQ] = 0; /* reset IRQ */
204    _ctx_switch();
205}
206
Note: See TracBrowser for help on using the repository browser.