OSSS

Warning: Attempt to modify property of non-object in /home/ssynth/dokuwiki/lib/plugins/pageredirect/action.php on line 97

Synchronous Parallel Register

Online Synthesis Demo

Want to see this code in VHDL? Try our free online synthesiser!

Description

This design shows a very simple register collection in SystemC. It's a fully parallel register of a parametrised size (and datatype), with one-hot encoded write-enable signals and a synchronous reset.

It is implemented with an SC_METHOD() process for best simulation performance. This is the simplest implementation, since no internal FSM is required.

Source

#include <systemc.h>
 
template< typename DataType, unsigned Size = 8 >
SC_MODULE( sync_register )
{
  typedef DataType  value_type;
 
  sc_in<bool> clock;
  sc_in<bool> reset;
  /* ----- input ports ----- */
  sc_in< sc_uint<Size> >     in_wen;
  sc_in< value_type >        in_data;
 
  /* ----- output ports ----- */
  sc_out< value_type >       data[Size];
 
  /* ----- constructor ----- */
  SC_CTOR( sync_register )
  {
     /* ----- process definitions ----- */
     SC_METHOD( processing );
     sensitive << clock.pos();
  }
 
private:
  /* ----- process(es) ----- */
  void processing();
 
}; // sync_register
 
/* ----- process body ----- */
template< typename DataType, unsigned Size >
void
sync_register<DataType,Size>::processing()
{
  sc_uint<10> wen  = in_wen.read();
 
  for(unsigned i=0; i<Size; ++i)
  {
    if( reset.read() ) {
      data[i].write( 0 );
    } else if( wen[i].to_bool() ) {
      data[i].write( in_data );
    }
  }
} // sync_register::processing()
 
/* ----- sc_main() -----
 *
 * We need an explicit main, since we have to
 * instantiate our templated module here.
 */
int sc_main( int, char*[] )
{
  sync_register< sc_uint<32>, 4 > top( "top" );
  return 0;
}
examples/000-systemc/002-simpleregister.txt · Last modified: 2009/05/08 14:26 by Philipp A. Hartmann
  • © 2008 OFFIS Institute for Information Technology
  • Escherweg 2
  • 26121 Oldenburg
  • Germany
  • Imprint
  • Top of page