Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class Template extends Thread
{ // CONSTANTS
private static final int PARALLEL = 1;
private static final int WIDTH = 512;
private static final int HEIGHT = 512;
private static final int INT_SIZE = 4;
private static final int HEIGHT_PLUS_PARALLEL = 513;
// AXI IO
public int waddr;
public int wdata;
public int wburst;
public boolean wreq;
public boolean wbusy;
public int raddr;
public int rdata;
public boolean rreq;
public boolean rbusy;
// user IO
public int gpio0; // fb_addr
public int gpio1; // line_bytes
public int gpio2; // mode
public int gpio3; // param_addr
private int fb_addr;
private int line_bytes;
private int page0;
private int page1;
private int cx;
private int cy;
private int dx;
private int speed;
private int mode;
private int param_addr;
public void run()
{
page0 = 0;
page1 = 1;
int sy = 0;
int addr = fb_addr;
int line_bytes_p = line_bytes * PARALLEL;
mandel0.dx = dx;
for (int i = 0; i < HEIGHT_PLUS_PARALLEL; i += PARALLEL)
{
mandel0.sy = sy;
mandel0.page = page0;
if (i < HEIGHT)
{ // job start
mandel0.req = true;
}
if (i >= PARALLEL)
{ // draw
int addr1 = addr;
int i_s, i_e;
if (page1 == 0)
{
i_s = 0;
}
else
{
i_s = WIDTH;
}
i_e = i_s + WIDTH;
for (int j = i_s; j < i_e; j++)
{
int addr0 = addr1;
write_data(addr0, mandel0.data[j], 0);
addr1 += INT_SIZE;
}
addr += line_bytes_p;
}
if (i < HEIGHT)
{ // job join
while (mandel0.ack == false)
{
yield();
}
mandel0.req = false;
while (mandel0.ack == true)
{
yield();
}
}
int p = page0;
page0 = page1;
page1 = p;
sy += PARALLEL;
}
dx = (dx * speed) >> 8 /*DX_BITS*/;
}
}
Mandel.java : マンデルブロ集合演算クラス
/*
Copyright (c) 2015, miya
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public class Mandel extends Thread
{
private static final int HALF_WIDTH = 256;
private static final int WIDTH = 512;
private static final int MAX_C = 32768 /*(4 << FIXED_BITS)*/;
public int cx;
public int cy;
public int sy;
public int dx;
public int page;
public final int[] data = new int[1024 /*BUF_SIZE*/];
public boolean req;
public boolean ack;
public boolean enable;
public int mode;
public void run()
{
while (true)
{
while ((req == false) && (enable == true))
{
yield();
}
if (enable == false)
{
break;
}
int x, x1, y, y1, calc_size;
calc_size = dx << 8 /*HALF_WIDTH_BITS*/;
x = cx - calc_size;
y = cy - calc_size + dx * sy;
int max_count = (mode >> 8) & 0xff;
y1 = y >> 13 /*FIXED_BITS*/;
for (int i = i_s; i < i_e; i++)
{
int a, b, a2, b2, c;
a = 0;
b = 0;
a2 = 0;
b2 = 0;
c = 0;
int count = max_count;
x1 = x >> 13 /*FIXED_BITS*/;
while ((c < MAX_C) && (count > 0))
{
b = ((a * b) >> 12 /*FIXED_BITS-1*/) - y1;
a = a2 - b2 - x1;
a2 = (a * a) >> 13 /*FIXED_BITS*/;
b2 = (b * b) >> 13 /*FIXED_BITS*/;
c = a2 + b2;
count--;
}
int color = 0;
color = 0xff000000 | ((count << 3) + (count << 10) + (count << 18));
data[i] = color;
x += dx;
}
ack = true;
while (req == true)
{
yield();
}
ack = false;
}
}
}
main.c : ドライバプログラム
/*
Copyright (c) 2015, miya
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/