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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [testbench/] [support/] [int.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 376 markom
/* 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 381 markom
#ifdef OR1K
9
 
10 376 markom
/* Interrupt handlers table */
11
struct ihnd int_handlers[MAX_INT_HANDLERS];
12
 
13
/* Initialize routine */
14 378 markom
int int_init()
15 376 markom
{
16 378 markom
  int i;
17 376 markom
 
18 378 markom
  for(i = 0; i < MAX_INT_HANDLERS; i++) {
19
    int_handlers[i].handler = 0;
20
    int_handlers[i].arg = 0;
21
  }
22
 
23
  return 0;
24 376 markom
}
25
 
26
/* Add interrupt handler */
27 600 simons
int int_add(unsigned long vect, void (* handler)(void *), void *arg)
28 376 markom
{
29 378 markom
  if(vect >= MAX_INT_HANDLERS)
30
    return -1;
31 376 markom
 
32 378 markom
  int_handlers[vect].handler = handler;
33
  int_handlers[vect].arg = arg;
34 376 markom
 
35 378 markom
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
36
 
37
  return 0;
38 376 markom
}
39
 
40
/* Disable interrupt */
41
int int_disable(unsigned long vect)
42
{
43 378 markom
  if(vect >= MAX_INT_HANDLERS)
44
    return -1;
45 376 markom
 
46 378 markom
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) & ~(0x00000001L << vect));
47
 
48
  return 0;
49 376 markom
}
50
 
51
/* Enable interrupt */
52
int int_enable(unsigned long vect)
53
{
54 378 markom
  if(vect >= MAX_INT_HANDLERS)
55
    return -1;
56 376 markom
 
57 378 markom
  mtspr(SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << vect));
58
 
59
  return 0;
60 376 markom
}
61
 
62
/* Main interrupt handler */
63 378 markom
void int_main()
64 376 markom
{
65 378 markom
  unsigned long picsr = mfspr(SPR_PICSR);
66
  unsigned long i = 0;
67 376 markom
 
68 378 markom
  mtspr(SPR_PICSR, 0);
69 376 markom
 
70 378 markom
  while(i < 32) {
71
    if((picsr & (0x01L << i)) && (int_handlers[i].handler != 0)) {
72
      (*int_handlers[i].handler)(int_handlers[i].arg);
73
      mtspr(SPR_PICSR, mfspr(SPR_PICSR) & ~(0x00000001L << i));
74
    }
75
    i++;
76
  }
77 376 markom
}
78 378 markom
 
79 381 markom
#endif

powered by: WebSVN 2.1.0

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