Forum Discussion
Altera_Forum
Honored Contributor
11 years agoconverting java method to vhdl
Hello ,,
im facing problems converting my java code to vhdl any help ? my java code
public static int size(int index){
int size=0;
for(int t=index; t<index+9;t++)
if (Sudoku_array)
size++;
return size;
}
vhdl code
library ieee;
use ieee.std_logic_1164.all;
entity size is
port (
clk: in std_logic;
size: in integer;
index: in integer;
t: in integer
);
end entity;
architecture F of initalizeBoard is
variable a = sudoku_array'LENGTH;
begin
clock: process (clk)
Loop1: for t in index+9 LOOP
if (sudoku_array(t))then
size<=size+1;
end Loop1;
end F;
9 Replies
- Altera_Forum
Honored Contributor
What exactly is the problem, other than your VHDL being completly useless for hardware?
- Altera_Forum
Honored Contributor
--- Quote Start --- What exactly is the problem, other than your VHDL being completly useless for hardware? --- Quote End --- Hiii ... the problem is that I have errors and now I go confused Im converting my game Sudoku that is in java to vhdl. the method size is one of my methods. you think that it is not needed? here is my java code:
I decided to convert each method in a separate vhdl file and then one that have all the methods added as an componentpublic class Sudoku { static boolean empty = false; //static int fullSet; static int board; static int allowedSets; static boolean sudoku_array = new boolean ; public static void main(String args) { initializeBoard(); readGame(); boolean solved = solveGame(); if(!solved) printSets(); printGame(); } /** * Create board array and create and initialize sets for the * board squares. **/ public static void initializeBoard() { int counter = 0; board = new int; allowedSets = new int ; // Since no moves have been made, any number can go anywhere. // Start the sets out with all possibilities. for(int i = 0; i < 9; i++){ for( int j = 0; j < 9; j++){ allowedSets = counter; counter = counter + 9; } } for (int i = 0; i < sudoku_array.length; i++){ sudoku_array = true; } } /** * Output the sets to the command line. * Used when the solver fails to complete a game. **/ public static void printSets() { for(int i = 0; i < 9; i++){ for( int j = 0; j < 9; j++){ for (int k = allowedSets; k < allowedSets + 9; k++ ) { System.out.print("{"); if(sudoku_array) System.out.print((k)+", "); System.out.println("}"); } } } } /** * Place val into the (x,y) position on the board and update sets * to remove val as a possibility in row x, column y, and the box * containing (x,y). **/ public static void move(int x, int y, int val) { board = val; if(val == 0) // handle 0 moves for readGame() return; // clear everything out of set (x,y) for (int k = allowedSets; k < allowedSets + 9; k++ ) { sudoku_array = sudoku_array && empty; } for (int i = 0; i < 9; i++){ sudoku_array+(val-1)] = false; sudoku_array+(val-1)] = false; } int boxX = x/3; int boxY = y/3; // clear the box containing (x,y) for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) sudoku_array + (val-1)] = false; } /** * Read in a game from the command line and put moves on the board * **/ public static void readGame() { try { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader stdin = new BufferedReader(isr); String line = ""; for(int i = 0; i < 9; i++) { line = stdin.readLine(); for(int j = 0; j < 9; j++) move(i,j,line.charAt(j)-'0'); } } catch(java.io.IOException e) { System.out.println(e); } } /** * Get the first element of a set. * If the set has one element, return that element. **/ public static int getElement(int index) { for(int i = index; i < index + 9; i++) if(sudoku_array) return i; System.out.println("uh oh"); return 0; } public static boolean isEmpty(int index) { boolean empty = true; for(int i = index; i < index + 9; i++) empty = empty && !sudoku_array; return empty; } public static int size(int index) { int size = 0; for(int i = index; i < index + 9; i++) if(sudoku_array) size++; return size; } /** * Search the board for a space with only one possibility. If found, * place that move on the board and update sets. Continue until * either no move is made, or there are no possiblities in any squares. **/ public static boolean solveGame() { boolean solved = false; boolean moved = false; int moves = 0; while(!solved) { solved = true; moved = false; for(int i = 0; i < 9; i++) { for(int j = 0; j < 9; j++) { if(size(allowedSets) == 1) { move(i,j,getElement(allowedSets)); moved = true; moves++; } else if(!isEmpty(allowedSets)) solved = false; } } if(!moved) // Give up if no moves were found break; } System.out.println("moves made: " + moves); return solved; } /** * Output the current board position. * **/ public static void printGame() { System.out.println(); for(int i = 0; i < 9; i++) { for(int j = 0; j < 9; j++) System.out.print(board); System.out.println(); } } } - Altera_Forum
Honored Contributor
What is the end goal? a straight conversion will not work in an FPGA, because VHDL is NOT software. it is a hardware description language.
Have you got a circuit diagram that you expect to produce that you drew BEFORE you wrote any VHDL? This is usually the first step in digital logic design. - Altera_Forum
Honored Contributor
--- Quote Start --- What is the end goal? a straight conversion will not work in an FPGA, because VHDL is NOT software. it is a hardware description language. Have you got a circuit diagram that you expect to produce that you drew BEFORE you wrote any VHDL? This is usually the first step in digital logic design. --- Quote End --- the goal is to implement it on VHDL and I know it is not a software but this is what I need to do. I drew the datapath of my code: http://s21.postimg.org/lq0tc7zjb/image.jpg - Altera_Forum
Honored Contributor
--- Quote Start --- What is the end goal? a straight conversion will not work in an FPGA, because VHDL is NOT software. it is a hardware description language. Have you got a circuit diagram that you expect to produce that you drew BEFORE you wrote any VHDL? This is usually the first step in digital logic design. --- Quote End --- the goal of this is to implement the game to vhdl. I had the following methods drawn in a datapath 1- initializeBoard 2- readGame 3- getElement 4- isEmpty 5- size 6- main + I know that vhdl is not a software but that what I need to do and working on it. I got stuck and need help :) this is my datapath: http://i60.tinypic.com/2ds1bis.jpg - Altera_Forum
Honored Contributor
--- Quote Start --- the goal of this is to implement the game to vhdl. I had the following methods drawn in a datapath 1- initializeBoard 2- readGame 3- getElement 4- isEmpty 5- size 6- main + I know that vhdl is not a software but that what I need to do and working on it. I got stuck and need help :) this is my datapath: http://i60.tinypic.com/2ds1bis.jpg --- Quote End --- Using FSM and Datapath will not create a Sudoku game. You need to use NIOS and QSYS. I think you are basically trying to convert your code into optimised hardware version, where you implement the computations only. Which can be done easily using state machines without a datapath. - Altera_Forum
Honored Contributor
--- Quote Start --- Using FSM and Datapath will not create a Sudoku game. You need to use NIOS and QSYS. I think you are basically trying to convert your code into optimised hardware version, where you implement the computations only. Which can be done easily using state machines without a datapath. --- Quote End --- What are you on about? This can be done without NIOS or QSYS with a pure hareware implementation. In this case you would need a FSM and some form of data path. - Altera_Forum
Honored Contributor
Hi Guys,
I need to generate vhdl code from java? Is there any way to do it? below is the general behavioral component vhdl program. How do i write in java this kind of vhdl template?please help me. LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY fsm is PORT ( global_clk : IN std_logic; reset : IN std_logic; a : IN std_logic; b : IN std_logic; c : OUT std_logic); END fsm; ARCHITECTURE fsm_A OF fsm IS type fsmstatetype is ( state1, state2, state3); BEGIN fsm_P : PROCESS (reset, global_clk) VARIABLE testvariable : std_logic := '0'; VARIABLE fsmstate : fsmstatetype:= state1; BEGIN IF (reset = '1') THEN testvariable:= '0'; fsmstate := state1; ELSIF (global_clk'event and global_clk = '1') THEN CASE fsmstate IS WHEN state1 => IF (a='1') THEN and not (b='1') THEN testvariable := '1'; fsmstate := state2; ELSE fsmstate := state1; END IF; WHEN state2 => IF (a='1') THEN and (b='1') THEN testvariable := '0'; fsmstate := state3; ELSE fsmstate := state2; END IF; WHEN state3 => IF not (a='1') THEN and not (b='1') THEN testvariable := '1'; fsmstate := state1; ELSE fsmstate := state3; END IF; END CASE; END IF; c <= testvariable; END PROCESS; END fsm_A; - Altera_Forum
Honored Contributor
Java and vhdl are very different things. One is a hardware description language, the other is a software language. What is the reason for wanting to convert between them?