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

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [orp/] [orp_soc/] [sw/] [orp_mon/] [camera_test.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 748 lampret
#include "spr_defs.h"
2
 
3
/* Camera and CRT test.
4
   Draws gray cross across the screen, few color boxes at top left and moves around camera captured screen left/right
5
   in the middle. */
6
 
7
#define CAMERA_BASE     0x88000000
8
#define CRT_BASE        0xc0000000
9
#define VIDEO_RAM_START 0xa8000000      /* till including a83ffffc */
10
 
11
#define SCREEN_X        640
12
#define SCREEN_Y        480
13
 
14
#define CAMERA_X        352
15
#define CAMERA_Y        288
16
 
17
#define CAMERA_BUF(idx) (VIDEO_RAM_START + (idx) * CAMERA_X * CAMERA_Y)
18
#define FRAME_BUF       (CAMERA_BUF(2))
19
 
20
#define CAMERA_POS      (camera_pos_x + ((SCREEN_Y - CAMERA_Y) / 2) * SCREEN_X)
21
 
22
#define MIN(x,y)        ((x) < (y) ? (x) : (y))
23
 
24
#define set_mem32(addr,val)  (*((unsigned long *) (addr)) = (val))
25
#define get_mem32(addr)  (*((unsigned long *) (addr)))
26
#define set_palette(idx,r,g,b) set_mem32 (CRT_BASE + 0x400 + (idx) * 4, (((r) >> 3) << 11) | (((g) >> 2) << 5) | (((b) >> 3) << 0))
27
#define put_pixel(xx,yy,idx)   (*(unsigned char *)(FRAME_BUF + (xx) + (yy) * SCREEN_X) = (idx))
28
 
29
 
30
/* For writing into SPR. */
31
void mtspr(unsigned long spr, unsigned long value)
32
{
33
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
34
}
35
 
36
/* For reading SPR. */
37
unsigned long mfspr(unsigned long spr)
38
{
39
  unsigned long value;
40
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
41
  return value;
42
}
43
 
44
int camera_pos_x;
45
int camera_move_speed = 1;
46
int current_buf;
47
 
48
void int_main ()
49
{
50
  /* Change base addresse of camera */
51
  set_mem32 (CAMERA_BASE, CAMERA_BUF(current_buf)); /* Set address to store to */
52
 
53
  /* Change base addresse of crt */
54
  set_mem32 (CRT_BASE + 8, CAMERA_BUF(1 - current_buf)); /* Tell CRT when camera buffer is */
55
  uart_print_str("\n ");
56
  uart_print_long(CAMERA_BUF(current_buf));
57
  uart_print_str("\n ");
58
 
59
  current_buf = 1 - current_buf;
60
 
61
  /* move the camera screen around */
62
  camera_pos_x += camera_move_speed;
63
  if (camera_pos_x >= SCREEN_X - CAMERA_X || camera_pos_x <= 0)
64
    camera_move_speed = -camera_move_speed;
65
  mtspr(SPR_PICSR, 0);
66
}
67
 
68
void crt_enable ()
69
{
70
  int i, x, y;
71
  /* Init CRT */
72
  set_mem32 (CRT_BASE + 4, FRAME_BUF); /* Frame buffer start */
73
  set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) | 1);          /* Enable CRT only */
74
 
75
  /* Init palette */
76
  for (i = 0; i < 32; i++) {
77
    set_palette (8 * i + 0, 0x00, 0x00, 0x00); /* black */
78
    set_palette (8 * i + 1, 0xff, 0xff, 0xff); /* white */
79
    set_palette (8 * i + 2, 0x7f, 0x7f, 0x7f); /* gray */
80
    set_palette (8 * i + 3, 0xff, 0x00, 0x00); /* red */
81
    set_palette (8 * i + 4, 0x00, 0xff, 0x00); /* green */
82
    set_palette (8 * i + 5, 0x00, 0x00, 0xff); /* blue */
83
    set_palette (8 * i + 6, 0x00, 0xff, 0xff); /* cyan */
84
    set_palette (8 * i + 7, 0xff, 0x00, 0xff); /* purple */
85
  }
86
  for (x = 0; x < SCREEN_X; x++)
87
    for (y = 0; y < SCREEN_Y; y++)
88
      put_pixel(x, y, 3);
89
}
90
 
91
void crt_test ()
92
{
93
  int i, x, y;
94
  for (x = 0; x < SCREEN_X; x++)
95
    for (y = 0; y < SCREEN_Y; y++)
96
      put_pixel(x, y, 0);
97
 /* Draw gray X */
98
  for (i = 0; i < SCREEN_Y; i++) {
99
    put_pixel (i, i, 2);
100
    put_pixel (SCREEN_X - i - 1, i, 1);
101
  }
102
 
103
  /* Draw color boxes */
104
  for (y = 0; y < 50; y++)
105
    for (x = 0; x < 50; x++)
106
        for (i = 0; i < 8; i++)
107
          put_pixel (i * 50 + x, y, i);
108
}
109
 
110
void crt_disable ()
111
{
112
  set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) & ~1);             /* Disable CRT */
113
}
114
 
115
void camera_enable ()
116
{
117
  /* Init Camera */
118
  set_mem32 (CAMERA_BASE, CAMERA_BUF(current_buf = 0)); /* Set address to store to */
119
  set_mem32 (CAMERA_BASE + 4, 1);         /* Enable it */
120
 
121
  /* Init CRT to display camera */
122
  set_mem32 (CRT_BASE + 8, CAMERA_BUF(1 - current_buf)); /* Tell CRT when camera buffer is */
123
  camera_pos_x = 0;
124
  set_mem32 (CRT_BASE + 0xc, CAMERA_POS);
125
  set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) | 2);         /* Enable camera overlay */
126
 
127
  /* Enable interrupts */
128
  mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
129
  mtspr (SPR_PICMR, mfspr(SPR_PICSR) | (1 << 13));
130
}
131
 
132
void camera_disable ()
133
{
134
  /* Disable interrupts */
135
  mtspr (SPR_SR, mfspr(SPR_SR) & ~SPR_SR_IEE);
136
  mtspr (SPR_PICMR, mfspr(SPR_PICSR) & ~(1 << 13));
137
 
138
  /* Disable Camera */
139
  set_mem32 (CAMERA_BASE + 4, 1);         /* Enable it */
140
  set_mem32 (CRT_BASE, get_mem32 (CRT_BASE) & ~2);                           /* Disable camera overlay */
141
}

powered by: WebSVN 2.1.0

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