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

Subversion Repositories ca_prng

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 1 to Rev 2
    Reverse comparison

Rev 1 → Rev 2

/ca_prng/trunk/doc/ca_prng_description.txt
0,0 → 1,209
#=======================================================================
#
# ca_prng_description.txt
# -----------------------
# README file for the ca_prng IP-core. The file
# contains a brief introduction to cellular automata based pattern
# generation, a description of the core and how to use the core.
#
#
# Author: Joachim Strömbergson
# Copyright (c) 2008, InformAsic AB
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * 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 InformAsic AB ''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 InformAsic AB 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.
#
#=======================================================================
 
 
1: Introduction
---------------
A cellular automata CA) is a discrete model that consists of a grid (1D,
2D, 3D ) with objects called cells. Each cell can be in one of a given
set of states (on and off, different colours etc). Each cell has a set
of cells in close proximity. Given the current internal state of a cell,
the states of the cells in the close proximity and a given set of update
rules the next state of a cell can be determined. For more information
about cellular automata, se [1].
 
The ca_prng IP-core implements a 1D binary cellular automata with wrap
around at the edges (i.e. a ring). The update rules for a given
cell is based on the current state of the cell and the state of its
two nearest neighbours (left and right). The cell state for a given cell
(i), stored in the ca_state_reg register array can thus be given by
the state in cells (i-1), (i) and (i+1) as inputs to the update rule, se
figure 1.
 
---------------------
ca_state_reg: |...|i-1| i |i+1|...|
---------------------
\ | /
(update_rule)
|
---------------------
ca_state_new: |...|i-1| i |i+1|...|
---------------------
 
Figure 1: State update for a cell (i) based on neighbour cells
and the update rule.
 
With a three input, binary state the update rule set consists of eight
possible bit updates. In total the ca_prng supports 256 update
rules. For different rules and possible patterns, see [2].
 
The default update rule used in the ca_prng is rule30. Rule30 is an
uodate rule that when applied to the CA will produce a class III,
aperiodic, chaotic behaviour. The rule was discovered by Stephen Wolfram
[3].
 
 
2: IP-core description
----------------------
The ca_prng is a CA with 32 cells, implemented as a 32 bit wide
register. Each register has separate update logic that looks at the
current state of the register and its two nearest neighbours (with wrap
around). Register update latency is one cycle.
 
The actual update of the registers is controlled by external control
signals that allows a user to set the register initial pattern
(state) and request generation of new pattern.
 
Loading of initial pattern is is accomplished by setting the
input_patter_data port to the desired inital pattern and then
asserting the load_input_pattern port for one clock cycle.
 
Requesting a new pattern is accomplished by asserting the next_pattern
port.
 
After reset the ca_prng will use rule30 as the update rule. Changing the
rule is done by assigning the new rule to the update_rule port and then
asserting the load_update_rule for one clock cycle.
 
The generated pattern is available as a 32 bit value on the prng_data
port.
 
 
Figure 2 shows input and output ports of the ca_prng core.
 
 
––––––––––-
input_pattern_data | |
-------->| |
| |
load_init_pattern | |
------->| | prng_data
| |-------->
next_pattern | |
-------->| |
| |
update_rule | ca_prng |
-------->| |
| |
load_upate_rule | |
------->| |
| |
| |
| |
clk | |
-------->| |
| |
reset_n | |
-------->| |
|––––––––––-|
 
Figure 2: Input and output ports of the ca_prng core.
The ca_prng core is a positive edge triggered synchronous design. All
internal registers are equipped with a synhronous, active low reset.
 
 
3: IP-core delivery contents
----------------------------
The ca_prng is provided as RTL source code written in Verilog 2001
compliant code. The ca_prng delivery also contains a testbench that
verifies the functionality. Finally the core contains a functional model
written in Python as well as documentation (this file).
 
The provided testbench has been used to verify the core using the
ModelSim as well as the Icarus Verilog simulators.
 
The ca_prng core has been implemented in FPGA tools from Altera and
Xilinx. The following table lists the area and speed achieved.
 
Altera Devices (implemented using Quartus 9.0)
Stratix II
---------
Device: EP2S15
ALUT: 106
Reg: 40
Mem: 0
DSP: 0
fmax: 300 MHz
 
Cyclone III
-----------
Device: EP3C5
LE: 234
Reg: 40
Mem: 0
Mult: 0
fmax: 250 MHz
 
 
Xilinx Devices (implemented using ISE 11.0)
Spartan 3A
----------
Device: xc3s50a-5
Slices: 93
Reg: 48 (replicated update_rule_reg)
Mem: 0
Mult: 0
fmax: 250 MHz
 
Virtex-5
--------
Device: xc5vlx30-3
Slices: 42
Reg: 40
Mem: 0
Mult: 0
fmax: 400 MHz
 
 
4: References
-------------
[1] Wikipedia. Cellular Automaton. Web page. 2009.
http://en.wikipedia.org/wiki/Cellular_automaton
 
[2] Wolfram MathWorld. Elementary Cellular Automaton. Web
page. 2009.
http://mathworld.wolfram.com/ElementaryCellularAutomaton.html
 
[3] Wikipedia. Rule 30 description. Web page. 2009.
http://en.wikipedia.org/wiki/Rule_30
 
#=======================================================================
# EOF ca_prng_description.txt
#=======================================================================
 
/ca_prng/trunk/COPYING.txt
0,0 → 1,26
Copyright (c) 2008, InformAsic AB
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
 
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
 
* 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 InformAsic AB ''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 InformAsic AB 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.
/ca_prng/trunk/Changes.txt
0,0 → 1,51
#=======================================================================
#
# Changes.txt
# -----------
# Description of changes to the ca_prng core source and support files.
#
#
# Author: Joachim Strombergson
# Copyright (c) 2008, InformAsic AB
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * 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 InformAsic AB ''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 InformAsic AB 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.
#
#=======================================================================
 
2009-08-14
----------
First public release.
* Based on the previously released rule30 core, extended to support user
loadable update rules.
 
* Update of the documentation to better describe CA theory and core
functionality.
 
* Moved the core to the OpenCores web and SVN repo.
 
#=======================================================================
# EOF Changes.txt
#=======================================================================
/ca_prng/trunk/src/testbench/tb_ca_prng.v
0,0 → 1,386
//========================================================================
//
// tb_ca_prng.v
// ------------
// Testbench for the rule cellular automata based PRNG ca_prng.
// This version is for ca_prng with 32 bit pattern output.
//
//
// Author: Joachim Strombergson
// Copyright (c) 2008, InformAsic AB
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * 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 InformAsic AB ''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 InformAsic AB 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.
//
//========================================================================
 
//------------------------------------------------------------------
// Simulator directives
//
// Timescale etc.
//------------------------------------------------------------------
`timescale 1ns / 1ps
 
 
//------------------------------------------------------------------
// tb_rule30
//
// The self contained testbench module.
//------------------------------------------------------------------
module tb_ca_prng();
//----------------------------------------------------------------
// Parameter declarations
//----------------------------------------------------------------
// CLK_HALF_PERIOD
// Half period (assuming 50/50 duty cycle) in ns.
parameter CLK_HALF_PERIOD = 5;
 
// RULE_2
// This rule generates a single angled line.
// See the following link for more info:
// http://mathworld.wolfram.com/ElementaryCellularAutomaton.html
parameter [7 : 0] RULE_2 = 8'b00000010;
// RULE_90
// This rule generates Pascals triangle from a single
// bit input. See the following link for more info:
// http://mathworld.wolfram.com/ElementaryCellularAutomaton.html
parameter [7 : 0] RULE_90 = 8'b01011010;
 
// MIDDLE_BIT_INIT_PATTERN
// An initial bgit pattern with a single bit set in the middle
// of the 32 bit word.
parameter [31 : 0] MIDDLE_BIT_INIT_PATTERN = 32'b00000000000000010000000000000000;
 
// COMPLEX_INIT_PATTERN
// A more complex init pattern.
parameter [31 : 0] COMPLEX_INIT_PATTERN = 32'b01011000000000010000111000001100;
 
// TC1_RESPONSE
// Expected PRNG pattern response after TC1.
parameter [31 : 0] TC1_RESPONSE = 32'b01110001010110000000111010001001;
 
// TC2_RESPONSE
// Expected PRNG pattern response after TC2.
parameter [31 : 0] TC2_RESPONSE = 32'b10111101001101000001100001101001;
 
// TC3_RESPONSE
// Expected PRNG pattern response after TC3.
parameter [31 : 0] TC3_RESPONSE = 32'b00000000000000000001000000000000;
 
// TC4_RESPONSE
// Expected PRNG pattern response after TC4.
parameter [31 : 0] TC4_RESPONSE = 32'b10101010101010101010101010101010;
//----------------------------------------------------------------
// Wire declarations.
//----------------------------------------------------------------
// Wires needed to connect the DUT.
reg tb_clk;
reg tb_reset_n;
reg [31 : 0] tb_init_pattern_data;
reg tb_load_init_pattern;
reg tb_next_pattern;
reg [7 : 0] tb_update_rule;
reg tb_load_update_rule;
wire [31 : 0] tb_prng_data;
 
 
//----------------------------------------------------------------
// Testbench variables.
//----------------------------------------------------------------
// num_errors
// Number of errors detected.
integer num_errors;
 
//----------------------------------------------------------------
// ca_prng_dut
//
// Instantiation of the ca_prng core as device under test.
//----------------------------------------------------------------
ca_prng ca_prng_dut(
.clk(tb_clk),
.reset_n(tb_reset_n),
.init_pattern_data(tb_init_pattern_data),
.load_init_pattern(tb_load_init_pattern),
.next_pattern(tb_next_pattern),
 
.update_rule(tb_update_rule),
.load_update_rule(tb_load_update_rule),
 
.prng_data(tb_prng_data)
);
 
//----------------------------------------------------------------
// check_pattern
//
// Check that the reusult pattern matches the expected pattern.
// If the patterns don't match increase the error counter.
//----------------------------------------------------------------
task check_pattern;
input [31 : 0] expected_pattern;
input [31 : 0] result_pattern;
begin
if (expected_pattern != result_pattern)
begin
$display("Error: Expected %b, got: %b",
expected_pattern, result_pattern);
num_errors = num_errors + 1;
end
end
endtask // check_pattern
 
//----------------------------------------------------------------
// init_sim
//
// Initialize all DUT inputs variables, testbench variables etc
// to defined values.
//----------------------------------------------------------------
task init_sim;
begin
tb_clk = 0;
tb_reset_n = 0;
tb_init_pattern_data = MIDDLE_BIT_INIT_PATTERN;
tb_load_init_pattern = 1'b0;
tb_next_pattern = 1'b0;
tb_update_rule = 8'b00000000;
tb_load_update_rule = 1'b0;
num_errors = 0;
end
endtask // init_sim
//----------------------------------------------------------------
// end_sim
//
// Perform any clean up as needed and check the simulation
// results from the test cases, reporting number of errors etc.
//----------------------------------------------------------------
task end_sim;
begin
if (num_errors == 0)
begin
$display("Simulation completed ok.");
end
else
begin
$display("Simulation completed, but %d test cases had errors.", num_errors);
end
end
endtask // end_sim
 
//----------------------------------------------------------------
// release_reset
//
// Wait a few cycles and then release the reset in sync
// with the clock.
//----------------------------------------------------------------
task release_reset;
begin
#(20 * CLK_HALF_PERIOD);
@(negedge tb_clk)
tb_reset_n = 1'b1;
end
endtask // release_reset
 
//----------------------------------------------------------------
// test_tc1
//
// Verify that the default rule30 update rule uns ok from the
// start using a simple init pattern.
//----------------------------------------------------------------
task test_tc1;
begin
$display("TC1: Default rule30 update rule with simple init pattern.");
// Load the init pattern into the dut and then
// start asserting the next pattern pin for a while.
#(4 * CLK_HALF_PERIOD);
@(negedge tb_clk)
tb_load_init_pattern = 1'b1;
@(negedge tb_clk)
tb_load_init_pattern = 1'b0;
@(negedge tb_clk)
tb_next_pattern = 1'b1;
// Run the DUT for a number of cycles.
#(100 * CLK_HALF_PERIOD);
 
// Drop the next pattern signal and check the results.
@(negedge tb_clk)
tb_next_pattern = 1'b0;
check_pattern(TC1_RESPONSE, tb_prng_data);
end
endtask // test_tc1
//----------------------------------------------------------------
// test_tc2
//
// Verify that we can change state by changing the init pattern
// and get a new set of PRNG data.
//----------------------------------------------------------------
task test_tc2;
begin
$display("TC2: Default rule30 update rule with complex init pattern.");
// Load a new init pattern and run that pattern
@(negedge tb_clk)
tb_init_pattern_data = COMPLEX_INIT_PATTERN;
tb_load_init_pattern = 1'b1;
@(negedge tb_clk)
tb_load_init_pattern = 1'b0;
tb_next_pattern = 1'b1;
// Run the DUT for a number of cycles.
#(200 * CLK_HALF_PERIOD);
 
// Drop the next pattern signal and check the results.
@(negedge tb_clk)
tb_next_pattern = 1'b0;
check_pattern(TC2_RESPONSE, tb_prng_data);
end
endtask // test_tc2
 
 
//----------------------------------------------------------------
// test_tc3
//
// Verify that the we can change the rule and get another set
// of PRNG data.
//----------------------------------------------------------------
task test_tc3;
begin
$display("TC3: rule2 update rule with simple init pattern.");
// Change update rule to RULE_2 and the simple init pattern.
@(negedge tb_clk)
tb_update_rule = RULE_2;
tb_load_update_rule = 1'b1;
tb_init_pattern_data = MIDDLE_BIT_INIT_PATTERN;
tb_load_init_pattern = 1'b1;
@(negedge tb_clk)
tb_load_update_rule = 1'b0;
tb_load_init_pattern = 1'b0;
tb_next_pattern = 1'b1;
// Run the DUT for a number of cycles.
#(200 * CLK_HALF_PERIOD);
 
// Drop the next pattern signal and check the results.
@(negedge tb_clk)
tb_next_pattern = 1'b0;
check_pattern(TC3_RESPONSE, tb_prng_data);
end
endtask // test_tc3
 
 
//----------------------------------------------------------------
// test_tc4
//
// Verify that the we can generate Pascals triangle.
//----------------------------------------------------------------
task test_tc4;
begin
$display("TC4: rule90 (Pascals triangle) update rule with simple init pattern.");
// Change update rule to RULE_90 and the simple init pattern.
@(negedge tb_clk)
tb_update_rule = RULE_90;
tb_load_update_rule = 1'b1;
tb_init_pattern_data = MIDDLE_BIT_INIT_PATTERN;
tb_load_init_pattern = 1'b1;
@(negedge tb_clk)
tb_load_update_rule = 1'b0;
tb_load_init_pattern = 1'b0;
tb_next_pattern = 1'b1;
// Run the DUT for a number of cycles.
#(30 * CLK_HALF_PERIOD);
 
// Drop the next pattern signal and check the results.
@(negedge tb_clk)
tb_next_pattern = 1'b0;
check_pattern(TC4_RESPONSE, tb_prng_data);
end
endtask // test_tc4
 
//----------------------------------------------------------------
// clk_gen
//
// Clock generator process. 50/50 duty cycle.
//----------------------------------------------------------------
always
begin : clk_gen
#CLK_HALF_PERIOD tb_clk = !tb_clk;
end // clk_gen
//--------------------------------------------------------------------
// dut_monitor
//
// Monitor for observing the inputs and outputs to the dut.
//--------------------------------------------------------------------
always @ (posedge tb_clk)
begin : dut_monitor
$display("reset = %b, init_pattern = %b, load_init_pattern = %b, next_pattern = %b, prng_data = %b",
tb_reset_n, tb_init_pattern_data, tb_load_init_pattern, tb_next_pattern, tb_prng_data);
end // dut_monitor
 
//----------------------------------------------------------------
// ca_prng_test
//
// The main test logic. Basically calls the tasks to init the
// simulation, all test cases and finish the simulation.
//----------------------------------------------------------------
initial
begin : ca_prng_test
$display(" -- Testbench for for ca_prng module started --");
 
// Call tasks as needed to init and executing test cases.
init_sim;
release_reset;
 
test_tc1;
test_tc2;
test_tc3;
test_tc4;
 
end_sim;
$display(" -- Testbench for for ca_prng module stopped --");
$finish;
end // ca_prng_test
endmodule // tb_ca_prng
 
//========================================================================
// EOF tb_ca_prng.v
//========================================================================
/ca_prng/trunk/src/model/ca_prng.py
0,0 → 1,138
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#=======================================================================
#
# ca_prng.py
# ---------
# Fast and simple ca_prng conformant cellular automata model in
# Python. This model is actually implented as a general 1D CA class
# and the rule and size of the CA array is provided as parameters.
#
#
# Author: Joachim Strömbergson
# Copyright (c) 2008, Kryptologik
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * 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 Kryptologik ''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 Kryptologik 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.
#
#=======================================================================
 
#-------------------------------------------------------------------
# Python module imports.
#-------------------------------------------------------------------
import sys
import math
import optparse
 
 
#-------------------------------------------------------------------
# class CellularAutomata()
#
# This class implements a 1D cellular automata. The class expects
# to be initalized with an array of arbitrary length with initial
# cell state values (0 or 1) as well as an array with update rules.
#
# The update rule is expected to contain eight values (0 or 1)
# that define the update value for a cell given by the current
# state of the cell and two nearest neighbours. Note that nearest
# neighbour is calculated with wrap around, that is the cell
# array is treated as a ring.
#-------------------------------------------------------------------
class CellularAutomata():
def __init__(self, rule, init_state, verbosity):
self.my_rule = rule
self.my_state = init_state
self.verbose = verbosity
 
def print_state(self):
"""Print the current state of the cellular automata."""
print self.my_state
 
def update_ca_state(self):
"""Update the cells in the cellular automata array."""
 
# Create a new CA array to store the updated state.
new_state = [x for x in range(len(self.my_state))]
 
# For each cell we extract three consequtive bits from the
# current state and use wrap around at the edges.
for curr_bit in range(len(self.my_state)):
if curr_bit == 0:
bit_left = self.my_state[-1]
bit_mid = self.my_state[0]
bit_right = self.my_state[1]
elif curr_bit == (len(self.my_state) - 1):
bit_left = self.my_state[(curr_bit - 1)]
bit_mid = self.my_state[curr_bit]
bit_right = self.my_state[0]
else:
bit_left = self.my_state[(curr_bit - 1)]
bit_mid = self.my_state[curr_bit]
bit_right = self.my_state[(curr_bit + 1)]
# Use the extraxted bits to calculate an index for
# the update rule array and update the cell.
rule_index = 4 * bit_left + 2 * bit_mid + bit_right
if self.verbose:
print "rule_index = %d " % rule_index
new_state[curr_bit] = self.my_rule[rule_index]
# Replace the old state array with the new array.
self.my_state = new_state
 
 
#-------------------------------------------------------------------
# main()
#
# Main function.
#-------------------------------------------------------------------
def main():
# Create an update rule array. This is Wolframs rule 30.
# We also create a CA array with a given init state.
my_update_rules = [0, 1, 1, 1, 1, 0, 0, 0]
my_init_state = [1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0]
 
# Create a CA object.
my_ca = CellularAutomata(my_update_rules, my_init_state, False)
 
# Run a few iterations printing the state before each update.
for iteration in range(1000):
my_ca.print_state()
my_ca.update_ca_state()
 
 
#-------------------------------------------------------------------
# __name__
# Python thingy which allows the file to be run standalone as
# well as parsed from within a Python interpreter.
#-------------------------------------------------------------------
if __name__=="__main__":
# Run the main function.
sys.exit(main())
 
#=======================================================================
# EOF ca_prng.py
#=======================================================================
ca_prng/trunk/src/model/ca_prng.py Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: ca_prng/trunk/src/rtl/ca_prng.v =================================================================== --- ca_prng/trunk/src/rtl/ca_prng.v (nonexistent) +++ ca_prng/trunk/src/rtl/ca_prng.v (revision 2) @@ -0,0 +1,1311 @@ +//======================================================================== +// +// ca_prng.v +// --------- +// Cellular Automata (CA) PRNG. This version produces PRNG words +// with 32 bits. +// +// Version: v1.1, 2009-03-20 +// Generated by: gen_ca_prng_rtl.py v2.0, 2009-03-20 +// +// +// Author: Joachim Strombergson +// Copyright (c) 2008, InformAsic AB +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * 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 InformAsic AB ''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 InformAsic AB 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. +// +//======================================================================== + +module ca_prng( + input wire [31 : 0] init_pattern_data, + input wire load_init_pattern, + input wire next_pattern, + + input wire [7 : 0] update_rule, + input wire load_update_rule, + + output wire [31 : 0] prng_data, + + input wire clk, + input wire reset_n + ); + + + //-------------------------------------------------------------------- + // Constant declarations. + //-------------------------------------------------------------------- + // DEFAULT_RULE + // The Default update rule - rule 30. + parameter [7 : 0] DEFAULT_RULE = 8'b00011110; + + + //-------------------------------------------------------------------- + // Register declarations. + //-------------------------------------------------------------------- + // ca_state_reg + // State register for the CA cells, one bit for each cell. + reg [31 : 0] ca_state_reg; + reg [31 : 0] ca_state_new; + reg ca_state_we; + + // update_rule_reg + // Register for the update rule. + reg [7 : 0] update_rule_reg; + + + //-------------------------------------------------------------------- + // Wire declarations. + //-------------------------------------------------------------------- + // tmp_ca_state_new + // temporary update vector. Is muxed to the real update vector + // if the load_init_pattern control signal is not set. + reg [31 : 0] tmp_ca_state_new; + + + //-------------------------------------------------------------------- + // Assignments. + //-------------------------------------------------------------------- + // Connect the PRNG output port to the CA state registers. + assign prng_data = ca_state_reg; + + + //-------------------------------------------------------------------- + // reg_update + // + // This clocked process impement all register updates including + // synchronous, active low reset. + //-------------------------------------------------------------------- + always @ (posedge clk) + begin : reg_update + if (!reset_n) + begin + // Register reset. + update_rule_reg <= DEFAULT_RULE; + ca_state_reg <= 32'b00000000000000000000000000000000; + end + else + begin + // Normal register update. + + if (load_update_rule) + begin + update_rule_reg <= update_rule; + end + + if (ca_state_we) + begin + ca_state_reg <= ca_state_new; + end + end + end // reg_update + + + //-------------------------------------------------------------------- + // ca_state_update + // + // State update logic for the CA cells. This is where we implement + // the Rule 30-logic as well as init pattern assignment. + //-------------------------------------------------------------------- + always @* + begin : ca_state_update + // Update for ca_state_reg bit 0. + case({ca_state_reg[31], ca_state_reg[0], ca_state_reg[1]}) + 0: + begin + tmp_ca_state_new[0] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[0] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[0] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[0] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[0] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[0] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[0] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[0] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[0] + + // Update for ca_state_reg bit 1. + case({ca_state_reg[0], ca_state_reg[1], ca_state_reg[2]}) + 0: + begin + tmp_ca_state_new[1] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[1] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[1] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[1] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[1] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[1] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[1] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[1] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[1] + + // Update for ca_state_reg bit 2. + case({ca_state_reg[1], ca_state_reg[2], ca_state_reg[3]}) + 0: + begin + tmp_ca_state_new[2] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[2] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[2] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[2] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[2] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[2] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[2] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[2] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[2] + + // Update for ca_state_reg bit 3. + case({ca_state_reg[2], ca_state_reg[3], ca_state_reg[4]}) + 0: + begin + tmp_ca_state_new[3] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[3] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[3] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[3] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[3] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[3] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[3] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[3] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[3] + + // Update for ca_state_reg bit 4. + case({ca_state_reg[3], ca_state_reg[4], ca_state_reg[5]}) + 0: + begin + tmp_ca_state_new[4] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[4] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[4] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[4] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[4] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[4] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[4] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[4] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[4] + + // Update for ca_state_reg bit 5. + case({ca_state_reg[4], ca_state_reg[5], ca_state_reg[6]}) + 0: + begin + tmp_ca_state_new[5] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[5] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[5] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[5] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[5] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[5] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[5] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[5] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[5] + + // Update for ca_state_reg bit 6. + case({ca_state_reg[5], ca_state_reg[6], ca_state_reg[7]}) + 0: + begin + tmp_ca_state_new[6] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[6] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[6] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[6] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[6] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[6] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[6] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[6] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[6] + + // Update for ca_state_reg bit 7. + case({ca_state_reg[6], ca_state_reg[7], ca_state_reg[8]}) + 0: + begin + tmp_ca_state_new[7] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[7] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[7] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[7] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[7] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[7] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[7] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[7] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[7] + + // Update for ca_state_reg bit 8. + case({ca_state_reg[7], ca_state_reg[8], ca_state_reg[9]}) + 0: + begin + tmp_ca_state_new[8] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[8] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[8] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[8] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[8] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[8] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[8] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[8] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[8] + + // Update for ca_state_reg bit 9. + case({ca_state_reg[8], ca_state_reg[9], ca_state_reg[10]}) + 0: + begin + tmp_ca_state_new[9] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[9] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[9] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[9] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[9] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[9] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[9] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[9] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[9] + + // Update for ca_state_reg bit 10. + case({ca_state_reg[9], ca_state_reg[10], ca_state_reg[11]}) + 0: + begin + tmp_ca_state_new[10] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[10] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[10] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[10] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[10] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[10] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[10] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[10] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[10] + + // Update for ca_state_reg bit 11. + case({ca_state_reg[10], ca_state_reg[11], ca_state_reg[12]}) + 0: + begin + tmp_ca_state_new[11] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[11] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[11] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[11] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[11] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[11] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[11] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[11] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[11] + + // Update for ca_state_reg bit 12. + case({ca_state_reg[11], ca_state_reg[12], ca_state_reg[13]}) + 0: + begin + tmp_ca_state_new[12] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[12] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[12] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[12] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[12] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[12] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[12] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[12] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[12] + + // Update for ca_state_reg bit 13. + case({ca_state_reg[12], ca_state_reg[13], ca_state_reg[14]}) + 0: + begin + tmp_ca_state_new[13] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[13] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[13] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[13] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[13] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[13] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[13] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[13] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[13] + + // Update for ca_state_reg bit 14. + case({ca_state_reg[13], ca_state_reg[14], ca_state_reg[15]}) + 0: + begin + tmp_ca_state_new[14] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[14] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[14] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[14] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[14] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[14] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[14] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[14] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[14] + + // Update for ca_state_reg bit 15. + case({ca_state_reg[14], ca_state_reg[15], ca_state_reg[16]}) + 0: + begin + tmp_ca_state_new[15] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[15] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[15] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[15] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[15] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[15] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[15] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[15] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[15] + + // Update for ca_state_reg bit 16. + case({ca_state_reg[15], ca_state_reg[16], ca_state_reg[17]}) + 0: + begin + tmp_ca_state_new[16] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[16] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[16] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[16] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[16] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[16] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[16] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[16] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[16] + + // Update for ca_state_reg bit 17. + case({ca_state_reg[16], ca_state_reg[17], ca_state_reg[18]}) + 0: + begin + tmp_ca_state_new[17] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[17] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[17] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[17] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[17] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[17] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[17] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[17] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[17] + + // Update for ca_state_reg bit 18. + case({ca_state_reg[17], ca_state_reg[18], ca_state_reg[19]}) + 0: + begin + tmp_ca_state_new[18] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[18] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[18] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[18] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[18] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[18] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[18] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[18] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[18] + + // Update for ca_state_reg bit 19. + case({ca_state_reg[18], ca_state_reg[19], ca_state_reg[20]}) + 0: + begin + tmp_ca_state_new[19] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[19] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[19] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[19] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[19] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[19] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[19] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[19] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[19] + + // Update for ca_state_reg bit 20. + case({ca_state_reg[19], ca_state_reg[20], ca_state_reg[21]}) + 0: + begin + tmp_ca_state_new[20] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[20] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[20] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[20] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[20] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[20] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[20] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[20] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[20] + + // Update for ca_state_reg bit 21. + case({ca_state_reg[20], ca_state_reg[21], ca_state_reg[22]}) + 0: + begin + tmp_ca_state_new[21] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[21] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[21] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[21] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[21] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[21] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[21] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[21] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[21] + + // Update for ca_state_reg bit 22. + case({ca_state_reg[21], ca_state_reg[22], ca_state_reg[23]}) + 0: + begin + tmp_ca_state_new[22] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[22] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[22] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[22] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[22] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[22] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[22] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[22] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[22] + + // Update for ca_state_reg bit 23. + case({ca_state_reg[22], ca_state_reg[23], ca_state_reg[24]}) + 0: + begin + tmp_ca_state_new[23] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[23] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[23] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[23] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[23] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[23] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[23] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[23] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[23] + + // Update for ca_state_reg bit 24. + case({ca_state_reg[23], ca_state_reg[24], ca_state_reg[25]}) + 0: + begin + tmp_ca_state_new[24] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[24] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[24] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[24] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[24] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[24] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[24] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[24] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[24] + + // Update for ca_state_reg bit 25. + case({ca_state_reg[24], ca_state_reg[25], ca_state_reg[26]}) + 0: + begin + tmp_ca_state_new[25] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[25] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[25] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[25] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[25] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[25] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[25] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[25] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[25] + + // Update for ca_state_reg bit 26. + case({ca_state_reg[25], ca_state_reg[26], ca_state_reg[27]}) + 0: + begin + tmp_ca_state_new[26] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[26] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[26] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[26] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[26] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[26] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[26] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[26] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[26] + + // Update for ca_state_reg bit 27. + case({ca_state_reg[26], ca_state_reg[27], ca_state_reg[28]}) + 0: + begin + tmp_ca_state_new[27] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[27] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[27] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[27] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[27] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[27] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[27] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[27] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[27] + + // Update for ca_state_reg bit 28. + case({ca_state_reg[27], ca_state_reg[28], ca_state_reg[29]}) + 0: + begin + tmp_ca_state_new[28] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[28] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[28] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[28] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[28] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[28] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[28] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[28] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[28] + + // Update for ca_state_reg bit 29. + case({ca_state_reg[28], ca_state_reg[29], ca_state_reg[30]}) + 0: + begin + tmp_ca_state_new[29] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[29] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[29] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[29] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[29] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[29] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[29] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[29] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[29] + + // Update for ca_state_reg bit 30. + case({ca_state_reg[29], ca_state_reg[30], ca_state_reg[31]}) + 0: + begin + tmp_ca_state_new[30] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[30] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[30] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[30] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[30] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[30] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[30] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[30] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[30] + + // Update for ca_state_reg bit 31. + case({ca_state_reg[30], ca_state_reg[31], ca_state_reg[0]}) + 0: + begin + tmp_ca_state_new[31] = update_rule_reg[0]; + end + 1: + begin + tmp_ca_state_new[31] = update_rule_reg[1]; + end + 2: + begin + tmp_ca_state_new[31] = update_rule_reg[2]; + end + 3: + begin + tmp_ca_state_new[31] = update_rule_reg[3]; + end + 4: + begin + tmp_ca_state_new[31] = update_rule_reg[4]; + end + 5: + begin + tmp_ca_state_new[31] = update_rule_reg[5]; + end + 6: + begin + tmp_ca_state_new[31] = update_rule_reg[6]; + end + 7: + begin + tmp_ca_state_new[31] = update_rule_reg[7]; + end + endcase // tmp_ca_state_new[31] + + + if (load_init_pattern) + begin + ca_state_new = init_pattern_data; + end + else + begin + ca_state_new = tmp_ca_state_new; + end + + // Should an init pattern or the next pattern be stored in + // the CA array? + if (load_init_pattern || next_pattern) + begin + ca_state_we = 1; + end + else + begin + ca_state_we = 0; + end + end // ca_state_update + + +endmodule // ca_prng +//======================================================================== +// EOF ca_prng.v +//======================================================================== Index: ca_prng/trunk/README.txt =================================================================== --- ca_prng/trunk/README.txt (nonexistent) +++ ca_prng/trunk/README.txt (revision 2) @@ -0,0 +1,16 @@ + + + Welcome to the ca_prng IP-core! + =============================== + +This directory contains the IP-core for a cellular automata based +pattern generator suitable for integration in FPGAs and ASICs. + +For documnentation, please check in the doc directory. For changes, see +Changes.txt and for licensing information see the file COPYING.txt + +Have fun! + + +Joachim Strombergson +(c) InformAsic AB 2009

powered by: WebSVN 2.1.0

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