Esperan Logo
Esperan is internationally recognised as a high quality provider of training in VHDL, SystemVerilog, SystemC, PSL, SVA, OVM, TLM and for courses covering design, verification, and PCB methodologies.
Esperan Schedule Menu
Esperan Course Menu
Esperan Contact Menus
Esperan UK contact information Phone +44 1344 865436
Fax +44 1344 865347
Email:
info@esperan.com

Contacts for other regions
Free Tutorials

Hardware Modelling with C++


Introduction

This tutorial is an introduction to the use of C++ for describing hardware models. Essential constructs for the creation of SystemC models are also introduced.

Note this is a deliberately simplified description of C++. Full details on the language, coding styles; design guidelines can be found on the Essential C++ for SystemC class.

Introduction
C++ implements Object-Orientation on the C language. For most Hardware Engineers, the principles of Object-Orientation seem fairly remote from the creation of Hardware components. However, ironically, Object-Orientation was created from design techniques used in Hardware designs. Data abstraction is the central aspect of Object-Orientation which incidentally, is found in everyday hardware designs through the use of publicly visible “ports” and private “internal signals”. Furthermore, the principle of “composition” used in C++ for creating hierarchical design is almost identical to component instantiation found in hardware designs. The coming sections will introduce the basics of C++ by looking at the creation of a hardware comp



Tutorial

The class in C++ is called an Abstract Data Type (ADT). It defines both data members and access functions (also called methods). Both data members and access functions are said to be private by default. In other words, data members and access functions are not visible from the outside world. This ADT mechanism is analogous to a package and package body in VHDL. The designer is responsible for making publicly available the essential set of access functions for manipulating an ADT.

 

The semantics for a C++ class declaration is as follows:

 

class counter
{ int value;
public:
void do_reset() { value = 0 ; }
void do_count_up() { value++ ; } 

 

In this example we see the declaration of an ADT called counter with a data member value and publicly available access functions: do_reset,do_count_up and do_read. Although this class declaration is complete, a class declaration will commonly also contain specialized functions such as constructors and a destructor.

 

When constructors are used, they provide initial values for the ADT’s data members. This mechanism is the only allowed means for setting a default value to any data member.

 

A destructor is used to perform clean-up operations before an instance of the ADT becomes out of scope. Pragmatically, the destructor is used for closing previously opened files or de-allocating dynamically allocated memory.

 

class counter
{
int value;
public:
void do_reset() { value = 0 ; }
void do_count_up() { value++ ; }
int do_read() { return value; }
counter() {
cout << "Simple constructor" << endl;
value = 10;
} counter(int arg): value(arg) {
cout << "Interesting constructor" << endl;
} ~counter() { cout << "Destroying a counter object" << endl;


Previous Tutorial | Next Tutorial