#NEWLINE# def mkUserlogic( ) : #NEWLINE# #INDENT# m = Module ( 'userlogic' ) #NEWLINE# data_width = m . Parameter ( 'DATA_WIDTH' , 32 ) #NEWLINE# addr_len = m . Parameter ( 'ADDR_LEN' , 10 ) #NEWLINE# clk = m . Input ( 'CLK' ) #NEWLINE# rst = m . Input ( 'RST' ) #NEWLINE# mem_addr = m . OutputReg ( 'mem_addr' , addr_len , initval = 0 ) #NEWLINE# mem_wdata = m . OutputReg ( 'mem_wdata' , data_width , initval = 0 ) #NEWLINE# mem_rdata = m . Input ( 'mem_rdata' , data_width ) #NEWLINE# mem_wvalid = m . OutputReg ( 'mem_wvalid' , initval = 0 ) #NEWLINE# mem_rvalid = m . OutputReg ( 'mem_rvalid' , initval = 0 ) #NEWLINE# ch_wdata = m . OutputReg ( 'ch_wdata' , data_width , initval = 0 ) #NEWLINE# ch_enq = m . OutputReg ( 'ch_enq' , initval = 0 ) #NEWLINE# ch_almfull = m . Input ( 'ch_almfull' ) #NEWLINE# ch_rdata = m . Input ( 'ch_rdata' , data_width ) #NEWLINE# ch_deq = m . OutputReg ( 'ch_deq' , initval = 0 ) #NEWLINE# ch_empty = m . Input ( 'ch_empty' ) #NEWLINE# fsm = FSM ( m , 'fsm' , clk , m ) #NEWLINE# read_count = m . Reg ( 'read_count' , width = 32 , initval = 0 ) #NEWLINE# sum = m . Reg ( 'sum' , width = 32 , initval = 0 ) #NEWLINE# size = m . Reg ( 'size' , width = 32 , initval = 0 ) #NEWLINE# fsm . goto_next ( ) #NEWLINE# fsm . goto_next ( ) #NEWLINE# start = fsm . current ( ) #NEWLINE# fsm . add ( ch_deq ( 1 ) , cond = Not ( ch_empty ) ) #NEWLINE# fsm . add ( ch_deq ( 0 ) , delay = 1 ) #NEWLINE# fsm . add ( size ( ch_rdata ) , delay = 2 ) #NEWLINE# fsm . goto_next ( cond = Not ( ch_empty ) ) #NEWLINE# fsm . add ( mem_addr ( ( - Int ( 1 ) ) ) ) #NEWLINE# fsm . goto_next ( ) #NEWLINE# fsm . add ( mem_rvalid ( 1 ) , mem_addr . inc ( ) , read_count . inc ( ) ) #NEWLINE# fsm . add ( mem_rvalid ( 0 ) , delay = 1 ) #NEWLINE# fsm . add ( sum . add ( mem_rdata ) , delay = 2 ) #NEWLINE# fsm . goto_next ( cond = ( read_count == ( size - 1 ) ) ) #NEWLINE# fsm . add ( Systask ( 'display' , 'sum=%d' , sum ) , delay = 2 ) #NEWLINE# fsm . add ( ch_enq ( 1 ) , cond = Not ( ch_almfull ) ) #NEWLINE# fsm . add ( ch_enq ( 0 ) , delay = 1 ) #NEWLINE# fsm . add ( ch_wdata ( sum ) ) #NEWLINE# fsm . goto ( start ) #NEWLINE# fsm . make_always ( reset = m . make_reset ( ) ) #NEWLINE# return m