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

Last change on this file since 185 was 169, checked in by alain, 12 years ago

Introducing support for FBDMA (Frame Buffer using DMA)

File size: 8.3 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
[169]88    // compute DMA channel address
[165]89    dma_address = (unsigned int*)&seg_dma_base + (dma_id * DMA_SPAN);
[158]90
[169]91    // save DMA channel status 
92    _dma_status[dma_id] = dma_address[DMA_LEN]; /* save status */
93
94    // reset DMA channel
[165]95    dma_address[DMA_RESET] = 0;                                 /* reset IRQ */
96
[169]97    // release DMA channel
[165]98    _dma_busy[dma_id] = 0;                      /* release DMA */
[158]99}
[165]100
101void _isr_dma_0() { _isr_dma_indexed(0); }
102void _isr_dma_1() { _isr_dma_indexed(1); }
103void _isr_dma_2() { _isr_dma_indexed(2); }
104void _isr_dma_3() { _isr_dma_indexed(3); }
105void _isr_dma_4() { _isr_dma_indexed(4); }
106void _isr_dma_5() { _isr_dma_indexed(5); }
107void _isr_dma_6() { _isr_dma_indexed(6); }
108void _isr_dma_7() { _isr_dma_indexed(7); }
109
[158]110///////////////////////////////////////////////////////////////////////////////////
111//      _isr_ioc()
112// There is only one IOC controler shared by all tasks. It acknowledge the IRQ
113// using the ioc base address, save the status, and set the _ioc_done variable
114// to signal completion.
115///////////////////////////////////////////////////////////////////////////////////
116void _isr_ioc()
117{
118    volatile unsigned int* ioc_address;
119
120    ioc_address = (unsigned int*)&seg_ioc_base;
121
122    _ioc_status = ioc_address[BLOCK_DEVICE_STATUS]; /* save status & reset IRQ */
123    _ioc_done   = 1;                                /* signals completion */
124}
[165]125
[158]126///////////////////////////////////////////////////////////////////////////////////
127//      _isr_timer_* (* = 0,1,2,3,4,5,6,7)
128// This ISR handles up to 8 IRQs generated by 8 independant timers.
129// It acknowledges the IRQ on TIMER[*] and displays a message on TTY0
130///////////////////////////////////////////////////////////////////////////////////
131void _isr_timer_indexed(unsigned int timer_id)
132{
133    volatile unsigned int *timer_address;
134
135    timer_address = (unsigned int*)&seg_timer_base + (timer_id * TIMER_SPAN);
136
137    timer_address[TIMER_RESETIRQ] = 0; /* reset IRQ */
138
139    _puts("\n\n!!! Interrupt timer received from timer ");
140    _putw( timer_id );
141    _puts(" at cycle ");
142    _putw( _proctime() );
143    _puts("\n\n");
144}
145
146void _isr_timer_0()  { _isr_timer_indexed(0);  }
147void _isr_timer_1()  { _isr_timer_indexed(1);  }
148void _isr_timer_2()  { _isr_timer_indexed(2);  }
149void _isr_timer_3()  { _isr_timer_indexed(3);  }
150void _isr_timer_4()  { _isr_timer_indexed(4);  }
151void _isr_timer_5()  { _isr_timer_indexed(5);  }
152void _isr_timer_6()  { _isr_timer_indexed(6);  }
153void _isr_timer_7()  { _isr_timer_indexed(7);  }
154
155///////////////////////////////////////////////////////////////////////////////////
156// _isr_tty_get_* (* = 0,1,2,3,4,5,6,7,9,10,11,12,13,14,15)
157// The Giet supports up to 16 TTY terminals.
158// These 16 ISRs handle the up to 16 IRQs associated to 16 independant
159// terminals, signaling that a character is available.
160// There is one communication buffer _tty_get_buf[tty_id] per terminal.
161// The sychronisation variable _tty_get_full[tty_id], is set by the ISR,
162// and reset by the OS.
163// A character is lost if the buffer is full when the ISR is executed.
164///////////////////////////////////////////////////////////////////////////////////
165void _isr_tty_get_indexed(unsigned int tty_id)
166{
167    volatile unsigned int *tty_address;
168
169    /* compute terminal base address */
170    tty_address = (unsigned int*)&seg_tty_base + (tty_id * TTY_SPAN);
171
172    /* save character and reset IRQ */
173    _tty_get_buf[tty_id] = (unsigned char)tty_address[TTY_READ];
174
175    /* signals character available */
176    _tty_get_full[tty_id] = 1;
177}
178
179void _isr_tty_get_0()  { _isr_tty_get_indexed(0);  }
180void _isr_tty_get_1()  { _isr_tty_get_indexed(1);  }
181void _isr_tty_get_2()  { _isr_tty_get_indexed(2);  }
182void _isr_tty_get_3()  { _isr_tty_get_indexed(3);  }
183void _isr_tty_get_4()  { _isr_tty_get_indexed(4);  }
184void _isr_tty_get_5()  { _isr_tty_get_indexed(5);  }
185void _isr_tty_get_6()  { _isr_tty_get_indexed(6);  }
186void _isr_tty_get_7()  { _isr_tty_get_indexed(7);  }
187void _isr_tty_get_8()  { _isr_tty_get_indexed(8);  }
188void _isr_tty_get_9()  { _isr_tty_get_indexed(9);  }
189void _isr_tty_get_10() { _isr_tty_get_indexed(10); }
190void _isr_tty_get_11() { _isr_tty_get_indexed(11); }
191void _isr_tty_get_12() { _isr_tty_get_indexed(12); }
192void _isr_tty_get_13() { _isr_tty_get_indexed(13); }
193void _isr_tty_get_14() { _isr_tty_get_indexed(14); }
194void _isr_tty_get_15() { _isr_tty_get_indexed(15); }
195
196/////////////////////////////////////////////////////////////////////////////////////
197// _isr_switch
198// This ISR is in charge of context switch.
199// It acknowledges the IRQ on TIMER[proc_id] and calls the _ctx_switch() function.
200/////////////////////////////////////////////////////////////////////////////////////
201void _isr_switch()
202{
203    volatile unsigned int *timer_address;
204    unsigned int proc_id;
205
206    proc_id = _procid();
207    timer_address = (unsigned int*)&seg_timer_base + (proc_id * TIMER_SPAN);
208
209    timer_address[TIMER_RESETIRQ] = 0; /* reset IRQ */
210    _ctx_switch();
211}
212
Note: See TracBrowser for help on using the repository browser.