function read_eeprom(addr); possible?

S

steve

Hi all,
I am trying to write a function which will accept an address and return the
8-bit value in an eeprom (SPI/Microwire). It seems that I can't toggle the
port i/o within the function. Like CS,SCK etc.
I was hoping to do something like this inside an init entity block:

-- pseudo code:
if reset then init<='0';
elsif(CLK'event and CLK='1') then
FirstVal=ReadByteEeprom(1);
SecondVal=ReadByteEeprom(2);
init<='1'; then this is a signal to the next block to initiate it's thing.
end if;
--

I get:"The target of this assignment must be a formal of the subprogram
"ReadByteEeprom" or one of its parents." for these lines --**
I basically wanted the function call since I could write them in order and
fill up the variables(or signals to other procedure blocks) used in the vhdl
from the eeprom. This is to be done once.
Should I really create a state machine or a procedure instead of a function?
I just liked the sequential ability of calling the function x times.

This code is quite incomplete, but maybe the idea will get across.
Please tell me how you guys/gals would usually do something like this.
Thankyou for your ideas. Steve

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.numeric_std.all;

entity Init is
port(
CLK : in std_logic;
RESET : in std_logic;
SO : in STD_LOGIC;
firstblock_verified : in std_logic;
SCK : out STD_LOGIC;
LOWCS : out STD_LOGIC;
SI : out STD_LOGIC;
LOWWP : out STD_LOGIC;
LOWHOLD : out STD_LOGIC;
init_verified : out std_logic
);
end Init;

architecture Init of Init is
--start of function
--impure to see CLK and RESET

impure function ReadByteEeprom (address : integer range 0 to 255) return
std_logic_vector is
variable BitCount:std_logic_vector(7 downto 0);
variable PulseCount:integer:=0;

begin
if (reset='0') then
BitCount:="00000000";
PulseCount:=0;
LOWCS<='1'; --** --haven't written any serial stuff yet.
elsif(CLK'event and CLK='1') then
LOWCS<='0'; --**
if(PulseCount=3)then
BitCount:="11110001";
elsif (address<=34)then
BitCount:="01010101";
end if;
PulseCount:=PulseCount+1;
end if;
return BitCount;

end;
--end of function

begin

LOWWP<='1'; -- allow writes
LOWHOLD<='1';
process (reset,firstblock_verified,CLK)
begin
if (reset='0') then --asynchronous RESET active low
LOWCS<='1'; --disable chip
init_verified<='0';
elsif(CLK'event and CLK='1') then

if( firstblock_verified='1')then

Red<=ReadByteEeprom(12);
--read constant array

init_verified<='1';
end if;

end if;

end process;

end Init;
 
M

Mike Treseler

steve said:
Hi all,
I am trying to write a function which will accept an address and return the
8-bit value in an eeprom (SPI/Microwire). It seems that I can't toggle the
port i/o within the function. Like CS,SCK etc.

That's correct. A function just returns a value.
You need a synchronous process to wiggle pins.

Here's an example that might get you on the
right track converting your scripts into control signals.

Even though this process is named "simulation" it
is written in synthesis style.

http://groups.google.com/groups?q=oe_demo


-- Mike Treseler
 
S

steve

Mike Treseler said:
That's correct. A function just returns a value.
You need a synchronous process to wiggle pins.

Here's an example that might get you on the
right track converting your scripts into control signals.

Even though this process is named "simulation" it
is written in synthesis style.

http://groups.google.com/groups?q=oe_demo


-- Mike Treseler
Thanks for the link Mike.
I've been writing with processes all along, but thought a function would be
better in this instance. I see a procedure may be able to do this as well,
but then attached are many gotchas which will not synthesize. I'll brute
force the process then like the rest of my design.
Thanks,
Steve
 
M

Mike Treseler

steve said:
Thanks for the link Mike.
I've been writing with processes all along, but thought a function would be
better in this instance. I see a procedure may be able to do this as well,
but then attached are many gotchas which will not synthesize.

Procedures are sometimes used in simulation
along with wait statements to wiggle pins.

I prefer to keep everything synchronous for sim and synth.

With wait statements excluded, procedures can
still be used to tidy up duplicated sequences of statements
inside a process.

-- Mike Treseler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top