OpenCores
URL https://opencores.org/ocsvn/minsoc/minsoc/trunk

Subversion Repositories minsoc

[/] [minsoc/] [trunk/] [sw/] [support/] [int.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rfajardo
/* This file is part of test microkernel for OpenRISC 1000. */
2
/* (C) 2001 Simon Srot, srot@opencores.org */
3
 
4
#include "support.h"
5
#include "spr_defs.h"
6
#include "int.h"
7
 
8
#ifdef OR1K
9
 
10
/* Interrupt handlers table */
11
struct ihnd int_handlers[MAX_INT_HANDLERS];
12
 
13
/* Initialize routine */
14
int int_init()
15
{
16
  int i;
17
 
18
  for(i = 0; i < MAX_INT_HANDLERS; i++) {
19
    int_handlers[i].handler = 0;
20
    int_handlers[i].arg = 0;
21
  }
22
  mtspr(SPR_PICMR, 0x00000000);
23
 
24
  //set OR1200 to accept exceptions
25
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
26
 
27
  return 0;
28
}
29
 
30
/* Add interrupt handler */
31
int int_add(unsigned long vect, void (* handler)(void *), void *arg)
32
{
33
  if(vect >= MAX_INT_HANDLERS)
34
    return -1;
35
 
36
  int_handlers[vect].handler = handler;
37
  int_handlers[vect].arg = arg;
38
 
39
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
40
 
41
  return 0;
42
}
43
 
44
/* Disable interrupt */
45
int int_disable(unsigned long vect)
46
{
47
  if(vect >= MAX_INT_HANDLERS)
48
    return -1;
49
 
50
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(0x00000001L << vect));
51
 
52
  return 0;
53
}
54
 
55
/* Enable interrupt */
56
int int_enable(unsigned long vect)
57
{
58
  if(vect >= MAX_INT_HANDLERS)
59
    return -1;
60
 
61
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
62
 
63
  return 0;
64
}
65
 
66
/* Main interrupt handler */
67
void int_main()
68
{
69 11 rfajardo
  unsigned long picsr = mfspr(SPR_PICSR);   //process only the interrupts asserted at signal catch, ignore all during process
70 2 rfajardo
  unsigned long i = 0;
71
 
72
  while(i < 32) {
73
    if((picsr & (0x01L << i)) && (int_handlers[i].handler != 0)) {
74
      (*int_handlers[i].handler)(int_handlers[i].arg);
75
    }
76
    i++;
77
  }
78 11 rfajardo
 
79
  mtspr(SPR_PICSR, 0);      //clear interrupt status: all modules have level interrupts, which have to be cleared by software,
80
}                           //thus this is safe, since non processed interrupts will get re-asserted soon enough
81
 
82 2 rfajardo
 
83
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.