Syntax error near Entity in a Package body - syntax-error

I am trying to create a small package of gates and other components for a VHDL project. I have created my package and am instantiating a component from it in my test bench, but I am receiving this compiler error:
ERROR: [VRFC 10-1412] syntax error near entity [/home/< redacted name >/Documents/school/ECE581/projects/project1/project_1/project_1.srcs/sources_1/new/components.vhdl:23]
The Question
What is the cause of my syntax error, and how do I resolve it?
Package Code
package p1_components is
component cNAND
port ( inA, inB : in bit;
output : out bit);
end component;
end p1_components;
package body p1_components is
--------------------------------------------------------------------------
-- NAND implementation
--------------------------------------------------------------------------
entity cNAND is -- *** line 23 - error is reported here ***
port ( inA, inB : in bit;
output : out bit);
end cNAND;
architecture def of cNAND is
begin
def_proc : process(inA, inB)
begin
if (inA and inB) then
output <= transport '0' after 5 ns;
else
output <= transport '1' after 5 ns;
end if;
end def_proc;
end def;
end p1_components;
Debugging Efforts
I have been referencing some standard library code here and here to ensure my declarations and syntax are correct, and as far as I can tell, they are. I have also referenced a couple of other online resources, and I can't find any issue with my package, component, and entity declarations.
Other Notes
I am compiling with the Linux version of Xilinx Vivado v2014.4 (64-bit).
I am aware of the VHDL keywords like NAND, which in a real-world design would make my implementations redundant. But the project I'm working on is for school, and there is a requirement that we roll our own NAND implementation for this portion of the project.

Normally I don't put an entity inside a package but outside. Try this:
package p1_components is
component cNAND
port ( inA, inB : in bit;
output : out bit);
end component;
end p1_components;
package body p1_components is
end p1_components;
--------------------------------------------------------------------------
-- NAND implementation
--------------------------------------------------------------------------
entity cNAND is
port ( inA, inB : in bit;
output : out bit);
end cNAND;
architecture def of cNAND is
begin
def_proc : process(inA, inB)
begin
if (inA = '1' and inB = '1') then
output <= transport '0' after 5 ns;
else
output <= transport '1' after 5 ns;
end if;
end process def_proc;
end def;

Related

Typedef Enum - Instantiation at top module and port connection

I am trying to instantiate a state machine at top level module and connect the states at top level ports to probe them as part of debug. I am trying something like this as in example below:
.state[0](DEBUG_1),
.state[1](DEBUG_2),
DEBUG_1 and DEBUG_2 are output ports in the top level module, and I want to probe these signals at the top logic.
The above is not working in SystemVerilog and gives errors. How else can this be done?
package states;
typedef enum logic [2:0] {RE = 3'b000,
NOR = 3'b001,
WD = 3'b011,
TO = 3'b010,
EVL = 3'b110,
DEC = 3'b111} state_t;
endpackage
import states::*;
module fsm (
input clk,
input reset,
output state_t state
);
import rtl_pkg::*;
import states::*;
module top (
output logic DEBUG_1,
output logic DEBUG_2
);
fsm fsm_inst (
.clk(sys_clk),
.reset(sys_reset),
.state[0](DEBUG_1),
.state[1](DEBUG_2),
.state[2](DEBUG_3),
);
ERROR - (VERI-1137) syntax error near '['
ERROR - module top ignored due to previous errors
Here is one way to get rid of the compile errors:
module top (
output logic DEBUG_1,
output logic DEBUG_2, DEBUG_3
);
// ... signal declarations
fsm fsm_inst (
.clk (sys_clk),
.reset (sys_reset),
.state ({DEBUG_3, DEBUG_2, DEBUG_1})
);
endmodule
Concatenate the 3 DEBUG bits using {}, then connect it directly to the state port.

Getting TNS :Connect timeout occurred in Oracle

I have the below function and I am quite frequently getting the below errors when front end ( ADF ) calls this function to get count.
Different errors comes at different times.
I think sometimes the listener is down so it might occur but other errors ?It happens when user from front end click on the link and that link in turn calls this database function.
I'm not able to find the issue in the function :-(
1) error "-12170 : ORA-12170: TNS:Connect timeout occurred"
2) error "-12571 : ORA-12571: TNS:packet writer failure"
3) error "-12541 : ORA-12541: TNS:no listener
4) error "-12514 : ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
5) error "-3113 : ORA-03113: end-of-file on communication channel
ORA-02063: preceding line from DBLINK"
6) error "-2051 : ORA-02051: another session or branch in same transaction failed or finalized
ORA-02063: preceding line from DBLINK"
FUNCTION GET_A (p_in IN VARCHAR2) RETURN NUMBER
AS
PRAGMA AUTONOMOUS_TRANSACTION;
PRE_COUNT NUMBER := NULL;
BEGIN
SELECT GET_B#DBLINK (p_in,NULL)INTO PRE_COUNT FROM dual;
COMMIT;
-- dbms_lock.sleep(2);
DBMS_SESSION.CLOSE_DATABASE_LINK('DBLINK');
COMMIT;
RETURN PRE_COUNT;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
LOG_ERR ( p_cd => SQLCODE,p_msg => SQLERRM);
RETURN -1;
END GET_A;

Synch / asynch d-type flip flop in vhdl

I've some problems with VHDL's configuration.
I should make a simple D-TYPE FLIP FLOP with two different architectures. One should be synchronous and the other asynchronous. The code of the entity is
entity FD is
Port ( D: In std_logic;
CK: In std_logic;
RESET: In std_logic;
Q: Out std_logic);
end FD;
architecture SYNCH of FD is
begin
PSYNCH: process(CK,RESET)
begin
if CK'event and CK='1' then
if RESET='1' then
Q <= '0';
else
Q <= D;
end if;
end if;
end process;
end SYNCH;
architecture ASYNCH of FD is
begin
PASYNCH: process(CK,RESET)
begin
if RESET='1' then
Q <= '0';
elsif CK'event and CK='1' then
Q <= D;
end if;
end process;
end ASYNCH;
configuration CFG_FD_ASYNCH of FD is
for ASYNCH
end for;
end CFG_FD_ASYNCH;
configuration CFG_FD_SYNCH of FD is
for SYNCH
end for;
end CFG_FD_SYNCH;
The code of the test bench is
entity TBFD is
end TBFD;
architecture TEST of TBFD is
signal CK: std_logic :='0';
signal RESET: std_logic :='0';
signal D: std_logic :='0';
signal QSYNCH: std_logic;
signal QASYNCH: std_logic;
component FD
Port ( CK: In std_logic;
RESET: In std_logic;
D: In std_logic;
Q: Out std_logic);
end component;
begin
FD_SYNCH : FD
Port Map ( CK, RESET, D, QSYNCH);
FD_ASYNCH : FD
Port Map ( CK, RESET, D, QASYNCH);
RESET <= '0', '1' after 0.6 ns, '0' after 1.1 ns, '1' after 2.2 ns, '0' after 3.2 ns;
D <= '0', '1' after 0.4 ns, '0' after 1.1 ns, '1' after 1.4 ns, '0' after 1.7 ns, '1' after 1.9 ns;
PCLOCK : process(CK)
begin
CK <= not(CK) after 0.5 ns;
end process;
end TEST;
configuration FDTEST of TBFD is
for TEST
for FD_SYNCH : FD
use configuration WORK.CFG_FD_SYNCH;
end for;
for FD_ASYNCH : FD
use configuration WORK.CFG_FD_ASYNCH;
end for;
end for;
end FDTEST;
The problem is during the test bench. The waveform of the synchronous part ( QSYNCH signal wave) is always equal to the asynchronous one ( QASYNCH signal wave). How can I solve this problem?
In the absence of a binding indication in the two FD configurations the architecture used will be the last analyzed - the default binding. (This says you CFD_FD_ASYNCH and CFD_FD_SYNCH, which supply no useful information aren't necessary other than to satisfy your original FD_TEST configuration specification).
This works as an alternative from the top level:
configuration FDTEST of TBFD is
for TEST
for FD_SYNCH : FD
use entity work.FD(synch);
end for;
for FD_ASYNCH : FD
use entity work.FD(asynch);
end for;
end for;
end FDTEST;
And when FDTEST is simulated yields:
I was wrong about your problem
After your comment that QSYNCH and QASYNCH were still the same ( nothing changed) I took a harder look and found out there was nothing wrong with your original configuration.
The configuration declarations found in the configuration specifications CFG_FD_SYNCH and CFG_FD_ASYNCH are perfectly capable of declaring the architecture used in their respective FDTEST configuration specification instances.
It's legal VHDL (you'll notice it has no analysis errors). I originally mistook the block configurations for something else from lack of attention while multitasking.
That said your problem isn't configuration but lies somewhere else. Either your original configuration specifications or the one I demonstrated are both capable of doing the right thing. When you commented that it made no difference and you were apparently still getting QASYNCH waveform results on both flip flops I did a quick search on how that could happen.
Unfortunately I got busy before I could document it properly, but the only way I found that you could get both waveforms showing QASYNCH behavior (asynchronous reset) is because you aren't elaborating and simulating the configuration FDTEST, instead you are elaborating and simulating TBFD (the test bench).
Both Flip Flops outputs show the asynchronous reset behavior because the ASYNCH architecture is the last analyzed and you aren't simulating the elaborated configuration. Under those conditions it doesn't matter if the configuration specifications are present in the working library or not, you aren't using them.
And that appears to be the actual problem.
Elaborating and simulating TBFD instead of FDTEST you get a waveform that looks like this:
Which should match what you've been relating to us.
Elaborating and simulating FDTEST using your original code gives a waveform identical to the first one shown above.
You haven't indicated which VHDL tool you're using making it hard to tell you how to elaborate and simulate the configuration FDTEST. You might need a manual, cheat sheet or other source demonstrating how to elaborate a configuration (which is a primary unit) and invoke it for simulation.
Remove RESET signal from the sensitivity list for the D Filp Flop Asynchronous Program. If you add reset signal in sensitivity list then the changes in reset signal is sensitive to clock change.

Runtime error with no apparent cause

I'm working with files in free pascal and I'm trying to open a file, but if it doesn't exists then I create it.
This is my code:
program messages;
const PATH_ = 'data/messages/';
type messageFields =
record
date : String
; viewed : Boolean
; text : String
; sender : String [ 8 ]
end
; messagesFile = file of messageFields
;
procedure openMessagesFile ( var _file: messagesFile; _fileName: String; var error: Boolean );
begin
error := false;
assign ( _file, PATH_+_fileName );
{$I-}
reset ( _file );
{$I+}
if ( ioResult <> 0 ) then
error := true;
end;
var _file: messagesFile
; fileName: String
; error: boolean;
begin
readln(filename);
openMessageFile(_file, filename, error);
if ( error ) then
rewrite(_file);
end.
The first time that I execute the program, since the file doesn't exists, throw me an exception.
The second time, works fine!
This is the exception:
An unhandled exception occurred at $00401759 :
EInOutError : Access denied
Have you reproduced this error with the exact code you've posted and I really can't see it causing the error you're getting. I cannot reproduce it and since you haven't included uses SysUtils you should get Runtime error 5 instead of EInOutError.
One thing that's terribly wrong with your code is that you're not closing the file after opening/creating it (although OS usually cleans it up after program finishes). Given this and the fact that you're getting EInOutError instead of Runtime error 5 I believe that your (real, bigger) program keeps the file open after creating it and trying to open it later, but fails since the file is already opened. The second time you run the program the file is already created so it's only opened once (for reading).
The code is a bit atypical, but Windows is known to keep fleeting locks on files for a few seconds even after they are closed and Dos originating code like this might suffer from that.
Maybe using FPC's FileExist() directly works better (IIRC on windows it is findfirst based, and not createfile based)

cannot generate code for file

Please have a look at the following code
Formula.ads
package Formula is
procedure CalculateFormula;
end Formula;
Formula.adb
with Ada.Text_IO; use Ada.Text_IO;
with Formula; use Formula;
package body Formula is
procedure CalculateFormula is
package fom_io is new Ada.Float_Text_IO(Float);
use fom_io;
u : Float;
t : Float;
a : Float;
answer : Float;
begin
put_line("Enter 'U'");
get(u);
put_line("Enter 'T'");
get(t);
put_line("Enter 'A'");
get(a);
answer = (u*t)+ 0.5(a(t*t));
put("Answer is: ");
put(answer,Fore => 1,Aft => 1,Exp => 1);
end CalclualeFormula;
end Formula;
When I run this code, I get the following error
gnatmake -d -PC:\Users\yohan\Documents\Ada\Formula\formula.gpr
gcc -c -I- -gnatA C:\Users\yohan\Documents\Ada\Formula\formula.ads
cannot generate code for file formula.ads (package spec)
gnatmake: "C:\Users\yohan\Documents\Ada\Formula\formula.ads" compilation error
[2013-04-06 03:18:22] process exited with status 4 (elapsed time: 00.22s)
I am very new to Ada. Started coding few hours back. Please help me to get rid of the above issue. Thank you.
EDIT
formula.gpr
project Formula is
for Main use ("formula.ads");
end Formula;
The GPR file shows that you are trying to use a package specification as a main program unit - that doesn't work.
Two ways to fix this: The simplest one is to make "CalculateFormula" a standalone main program in a file "calculateformula.adb" and set this in your project file:
for Main use ("calculateformula.adb");
But if you want to see how packages work, there is a "better" way (in that it gets you to understand what packages are for and how they are used...)
Packages are reusable components : the package spec is all you need to see in order to use them ... but you actually use them in another program. So in this case you would create a main program
with Formula; use Formula;
procedure MyMain is
begin
CalculateFormula;
end MyMain;
and in the .gpr file,
for Main use ("mymain.adb");
And then the compiler will automatically compile the correct packages and find the other issues that Shark has pointed out.
You really don't need a separate Main here, as the "hello world" example showed. However such trivial "main subprograms" (in the correct Ada lingo) are not so unusual, especially for purposes like unit testing packages to be used in more complex apps later.
This is puzzling because there are some big errors that the compiler should be flagging, like:
package fom_io is new Ada.Float_Text_IO(Float);
which isn't withed, and
answer = (u*t)+ 0.5(a(t*t));
because:
= is not the assignment operator; you need :=.
0.5(XXXX) isn't valid multiplication.
Also, there's exponentiation in Ada, so t**2 can replace t*t.
formula.adb
with
Ada.Float_Text_IO,
Ada.Text_IO;
use
Ada.Text_IO;
package body Formula is
procedure CalculateFormula is
use Ada.Float_Text_IO;
u, t, a, answer : Float;
Procedure Prompt( Item : out Float; Name : String ) is
begin
put_line("Enter '"& Name &"'");
get(Item);
end prompt;
begin
prompt( u, "U" );
prompt( t, "T" );
prompt( a, "A" );
answer:= (u*t) + 0.5*( a*t**2 );
put("Answer is: ");
put(answer,Fore => 1,Aft => 1,Exp => 1);
New_Line;
end CalculateFormula;
end Formula;
This corrects the syntax errors you had. The other answer seems right in that this ["cannot generate code for" error] seems to be a problem with the gpr-file rather than the source itself.