1
0
mirror of https://github.com/myhdl/myhdl.git synced 2025-01-24 21:52:56 +08:00

Fix docstring for ModuleInstance; migrate example

This commit is contained in:
Jan Decaluwe 2016-02-15 17:19:21 +01:00
parent 8bbfd1f31a
commit 04b1ad949a
4 changed files with 20 additions and 13 deletions

View File

@ -1,6 +1,6 @@
// File: FramerCtrl.v // File: FramerCtrl.v
// Generated by MyHDL 0.8dev // Generated by MyHDL 1.0dev
// Date: Fri Dec 21 15:02:39 2012 // Date: Mon Feb 15 21:03:52 2016
`timescale 1ns/10ps `timescale 1ns/10ps
@ -35,7 +35,7 @@ reg [7:0] index;
always @(posedge clk, negedge reset_n) begin: FRAMERCTRL_FSM always @(posedge clk, negedge reset_n) begin: FRAMERCTRL_FSM
if ((reset_n == 0)) begin if ((reset_n == 1'b0)) begin
SOF <= 0; SOF <= 0;
index <= 0; index <= 0;
state <= 3'b001; state <= 3'b001;
@ -66,7 +66,7 @@ always @(posedge clk, negedge reset_n) begin: FRAMERCTRL_FSM
state <= 3'b001; state <= 3'b001;
end end
end end
SOF <= (index == (8 - 1)); SOF <= ($signed({1'b0, index}) == (8 - 1));
end end
default: begin default: begin
$finish; $finish;

View File

@ -1,11 +1,13 @@
-- File: FramerCtrl.vhd -- File: FramerCtrl.vhd
-- Generated by MyHDL 0.8dev -- Generated by MyHDL 1.0dev
-- Date: Fri Dec 21 15:02:39 2012 -- Date: Mon Feb 15 21:03:52 2016
package pck_FramerCtrl is package pck_FramerCtrl is
attribute enum_encoding: string;
type t_enum_t_State_1 is ( type t_enum_t_State_1 is (
SEARCH, SEARCH,
CONFIRM, CONFIRM,
@ -20,7 +22,7 @@ use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all; use IEEE.numeric_std.all;
use std.textio.all; use std.textio.all;
use work.pck_myhdl_08.all; use work.pck_myhdl_10.all;
use work.pck_FramerCtrl.all; use work.pck_FramerCtrl.all;
@ -43,6 +45,8 @@ end entity FramerCtrl;
architecture MyHDL of FramerCtrl is architecture MyHDL of FramerCtrl is
signal index: unsigned(7 downto 0); signal index: unsigned(7 downto 0);
begin begin
@ -50,18 +54,19 @@ begin
FRAMERCTRL_FSM: process (clk, reset_n) is FRAMERCTRL_FSM: process (clk, reset_n) is
begin begin
if (reset_n = '0') then if (reset_n = '0') then
SOF <= '0'; SOF <= '0';
index <= "00000000"; index <= to_unsigned(0, 8);
state <= SEARCH; state <= SEARCH;
elsif rising_edge(clk) then elsif rising_edge(clk) then
index <= ((index + 1) mod 8); index <= ((index + 1) mod 8);
SOF <= '0'; SOF <= '0';
case state is case state is
when SEARCH => when SEARCH =>
index <= "00000001"; index <= to_unsigned(1, 8);
if bool(syncFlag) then if bool(syncFlag) then
state <= CONFIRM; state <= CONFIRM;
end if; end if;

View File

@ -9,6 +9,7 @@ ACTIVE_LOW = bool(0)
FRAME_SIZE = 8 FRAME_SIZE = 8
t_State = enum('SEARCH', 'CONFIRM', 'SYNC', encoding="one_hot") t_State = enum('SEARCH', 'CONFIRM', 'SYNC', encoding="one_hot")
@module
def FramerCtrl(SOF, state, syncFlag, clk, reset_n): def FramerCtrl(SOF, state, syncFlag, clk, reset_n):
""" Framing control FSM. """ Framing control FSM.
@ -62,8 +63,8 @@ def main():
reset_n = Signal(bool(1)) reset_n = Signal(bool(1))
state = Signal(t_State.SEARCH) state = Signal(t_State.SEARCH)
toVerilog(FramerCtrl, SOF, state, syncFlag, clk, reset_n) toVerilog(FramerCtrl(SOF, state, syncFlag, clk, reset_n))
toVHDL(FramerCtrl, SOF, state, syncFlag, clk, reset_n) toVHDL(FramerCtrl(SOF, state, syncFlag, clk, reset_n))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -54,10 +54,10 @@ def _getCallInfo():
3: the function that defines instances 3: the function that defines instances
4: the caller of the module function, e.g. a ModuleInstance. 4: the caller of the module function, e.g. a ModuleInstance.
There is a complication when the decorator is used in on a method. There is a complication when the decorator is used on a method.
In this case, it is used as a descriptor, and there is an additional In this case, it is used as a descriptor, and there is an additional
stack level due to the __get__ method. The current hack is to check stack level due to the __get__ method. The current hack is to check
whether we are still in this Python module at level 3, and increment whether we are still in this module at level 3, and increment
all the subsequent levels. all the subsequent levels.
""" """
@ -117,6 +117,7 @@ class _ModuleInstance(object):
self.args = args self.args = args
self.kwargs = kwargs self.kwargs = kwargs
self.mod = mod self.mod = mod
self.__doc__ = mod.modfunc.__doc__
callinfo = _getCallInfo() callinfo = _getCallInfo()
self.callinfo = callinfo self.callinfo = callinfo
self.modctxt = callinfo.modctxt self.modctxt = callinfo.modctxt