Home Products News Services Place an Order Partners and Affiliations Site Map Contact us

Hardware in SystemC

(Hardware part of the fibonacci system is shown in red.)

//fibo_system.h

#ifndef fibo_system_H

#define fibo_system_H

#include "systemc.h"

 

SC_MODULE (fibo_system) {

 

// Port Declaration

sc_in clk;

sc_in en;

sc_in start;

sc_out fibo_added;

 

// Signal Declaration

sc_signal cnt;

sc_signal fibo_no;

 

// Process Declaration

void counter_process ();

void adder_process ();

void fibo_gen();

 

// Function Declaration

unsigned short Fibonacci(short N);

 

//Module Constructor

SC_CTOR(fibo_system) {

 

// Sensitivity List Declaration

SC_METHOD(counter_process);

sensitive << clk<< en<

 

SC_METHOD(adder_process);

sensitive << FIBO_NO << FONT;

 

SC_METHOD(fibo_gen);

sensitive << CNT << FONT;

}

};

#endif

 

 

 

 //fibo_system.cpp

 

#include "fibo_proc.h"

 

void fibo_system::counter_process()

{

if(clk.event() && clk.read() == '1')

{

if (start.read())

{

     cnt = 1;

}

else

{

     if (en.read())

     {

         cnt = cnt + 1;

     }

}

}

}

 

void fibo_system::adder_process()

{

    fibo_added = fibo_no + 2;

}

 

void fibo_system::fibo_gen()

{

     fibo_no = Fibonacci(cnt);

}

 

unsigned short fibo_system:: Fibonacci(short N)

{

// This function computes Nth Fibonacci number.

// Fibonacci series is as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...

 

unsigned short i, old_last, last, before_last;

last = 1;

before_last = 1;

for (i=2 ; i < N ; i++)

{

old_last = last;

last = last + before_last;

before_last = old_last;

}

return last;

}

Copyright 2005 . Digimics Corporation, All rights reserved.