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

Last change on this file since 168 was 167, checked in by alain, 12 years ago

Fix several bugs to use the vci_block_device with MMU activated

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