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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [drivers/] [or1200/] [or1200-utils.c] - Blame information for rev 409

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

Line No. Rev Author Line
1 349 julius
#include "spr-defs.h"
2 393 julius
#include "or1200-utils.h"
3
#include "board.h" // For timer rate (IN_CLK, TICKS_PER_SEC)
4 349 julius
 
5
/* For writing into SPR. */
6
void mtspr(unsigned long spr, unsigned long value)
7
{
8
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
9
}
10
 
11
/* For reading SPR. */
12
unsigned long mfspr(unsigned long spr)
13
{
14
  unsigned long value;
15
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
16
  return value;
17
}
18
 
19
/* Print out a character via simulator */
20
void sim_putc(unsigned char c)
21
{
22
  asm("l.addi\tr3,%0,0": :"r" (c));
23
  asm("l.nop %0": :"K" (NOP_PUTC));
24
}
25
 
26
/* print long */
27
void report(unsigned long value)
28
{
29
  asm("l.addi\tr3,%0,0": :"r" (value));
30
  asm("l.nop %0": :"K" (NOP_REPORT));
31
}
32
 
33
/* Loops/exits simulation */
34
void exit (int i)
35
{
36
  asm("l.add r3,r0,%0": : "r" (i));
37
  asm("l.nop %0": :"K" (NOP_EXIT));
38
  while (1);
39
}
40
 
41 408 julius
/* Enable user interrupts */
42
void
43
cpu_enable_user_interrupts(void)
44
{
45
  /* Enable interrupts in supervisor register */
46
  mtspr (SPR_SR, mfspr (SPR_SR) | SPR_SR_IEE);
47
}
48 349 julius
 
49
/* Tick timer variable */
50
unsigned long timer_ticks;
51
 
52
/* Tick timer functions */
53
/* Enable tick timer and interrupt generation */
54
void enable_timer(void)
55
{
56
  mtspr(SPR_SR, SPR_SR_TEE | mfspr(SPR_SR));
57
  mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | ((IN_CLK/TICKS_PER_SEC) & SPR_TTMR_PERIOD));
58
}
59
 
60
/* Disable tick timer and interrupt generation */
61
void disable_timer(void)
62
{
63
  // Disable timer: clear it all!
64
  mtspr (SPR_SR, mfspr (SPR_SR) & ~SPR_SR_TEE);
65
  mtspr(SPR_TTMR, 0);
66
 
67
}
68
 
69
/* Timer increment - called by interrupt routine */
70
void timer_tick(void)
71
{
72
  timer_ticks++;
73
  mtspr(SPR_TTMR, SPR_TTMR_IE | SPR_TTMR_RT | ((IN_CLK/TICKS_PER_SEC) & SPR_TTMR_PERIOD));
74
}
75
 
76
/* Reset tick counter */
77
void clear_timer_ticks(void)
78
{
79
  timer_ticks=0;
80
}
81
 
82
/* Get tick counter */
83
unsigned long get_timer_ticks(void)
84
{
85
  return timer_ticks;
86
}
87
 
88
/* Wait for 10ms */
89
void wait_10ms(void)
90
{
91
  unsigned long first_time = get_timer_ticks();
92
  while (first_time == get_timer_ticks());
93
}
94
 

powered by: WebSVN 2.1.0

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