Re: [myhdl-list] TypeError: Unexpected type
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2015-03-24 15:10:06
|
On 3/24/2015 9:30 AM, Guy Eschemann wrote: > from myhdl import * > > def mpegChannel(clk, rst): > > s_tx_data_xor_mask_r = Signal(intbv(0)[1 + 31:]) > > @always_seq(clk.posedge, rst) > def fsm_seq(): > for i in range(4): > if i == 0: > s_tx_data_xor_mask_r.next[1 + 7:0] = 0 > elif i == 1: > s_tx_data_xor_mask_r.next[1 + 15:8] = 1 > elif i == 2: > s_tx_data_xor_mask_r.next[1 + 23:16] = 2 > else: > s_tx_data_xor_mask_r.next[1 + 31:24] = 3 > > return instances() I think this is a bug / limitation and an issue should to be created (but there might be a good reason for the limitation that I can't think of right now). You can work around it with: In [5]: from myhdl import * ...: ...: def mpegChannel(clk, rst): ...: ...: s_tx_data_xor_mask_r = Signal(intbv(0)[1 + 31:]) ...: # *** limited range type for switch *** ...: full_case = intbv(0, min=0, max=4) ...: @always_seq(clk.posedge, rst) ...: def fsm_seq(): ...: for i in range(4): ...: full_case[:] = i ...: if full_case == 0: ...: s_tx_data_xor_mask_r.next[1 + 7:0] = 0 ...: elif full_case == 1: ...: s_tx_data_xor_mask_r.next[1 + 15:8] = 1 ...: elif full_case == 2: ...: s_tx_data_xor_mask_r.next[1 + 23:16] = 2 ...: else: ...: s_tx_data_xor_mask_r.next[1 + 31:24] = 3 ...: ...: return instances() The limitation is, when evaluating an if-else structure the conversion code wants to determine if it full-case or not, because the variable switched on is an `int` it throws the type error. But the code example seems reasonable, I think? Regards, Chris |