adaptivity.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * adaptivity.hpp -- Definition of some adaptive processes *
3  * *
4  * Author: Hosein Attarzadeh (shan2@kth.se) *
5  * *
6  * Purpose: Providing promitive element required for modeling *
7  * adaptive systems in ForSyDe-SystemC *
8  * *
9  * Usage: This file is included automatically *
10  * *
11  * License: BSD3 *
12  *******************************************************************/
13 
14 #ifndef ADAPTIVITY_HPP
15 #define ADAPTIVITY_HPP
16 
24 #include "sy_moc.hpp"
25 #include <functional>
26 
27 namespace ForSyDe
28 {
29 
30 namespace SY
31 {
32 
33 using namespace sc_core;
34 
35 // Auxilliary Macro definitions
36 #define WRITE_MULTIPORT(PORT,VAL) \
37  for (int WMPi=0;WMPi<PORT.size();WMPi++) PORT[WMPi]->write(VAL);
38 
39 
41 
45 template <class ITYP, class OTYP>
46 class apply : public sc_module
47 {
48 public:
51 
53  typedef std::function<abst_ext<OTYP>(const abst_ext<ITYP>&)> functype;
55 
57 
61  apply(sc_module_name _name) // module name
62  :sc_module(_name)
63  {
64  SC_THREAD(worker);
65  }
66 private:
67  SC_HAS_PROCESS(apply);
68 
70  void worker()
71  {
72  abst_ext<ITYP> in_val;
73  abst_ext<OTYP> out_val;
74  functype cur_f;
75  while (1)
76  {
77  in_val = iport.read(); // read from input
78  cur_f = unsafe_from_abst_ext(fport.read()); // read the function
79  out_val = cur_f(in_val);// do the calculation
80  WRITE_MULTIPORT(oport,out_val); // write to the output
81  }
82  }
83 };
84 
86 
92 template <class T0, template <class> class OIf,
93  class T1, template <class> class I1If,
94  template <class> class FIf>
95 inline apply<T0,T1>* make_apply(const std::string& pName,
96  OIf<T0>& outS,
97  I1If<T1>& inp1S,
98  FIf<typename apply<T0,T1>::functype>& fS
99  )
100 {
101  auto p = new apply<T0,T1>(pName.c_str());
102 
103  (*p).iport(inp1S);
104  (*p).oport(outS);
105  (*p).fport(fS);
106 
107  return p;
108 }
109 
110 }
111 }
112 
113 #endif
Implements the synchronous Model of Computation.
apply(sc_module_name _name)
The constructor requires the module name.
Definition: adaptivity.hpp:61
apply< T0, T1 > * make_apply(const std::string &pName, OIf< T0 > &outS, I1If< T1 > &inp1S, FIf< typename apply< T0, T1 >::functype > &fS)
Helper function to construct a comb process.
Definition: adaptivity.hpp:95
The namespace for ForSyDe.
Definition: abssemantics.hpp:30
SY_out< OTYP > oport
port for the output channel
Definition: adaptivity.hpp:50
SY_in< ITYP > iport
port for the input channel
Definition: adaptivity.hpp:49
Process constructor for a combinational adaptive process with one input and one output.
Definition: adaptivity.hpp:46
Absent-extended data types.
Definition: abst_ext.hpp:32
SY_in< functype > fport
port for the function channel
Definition: adaptivity.hpp:54
std::function< abst_ext< OTYP >const abst_ext< ITYP > &)> functype
Type of the function to be passed to the process constructor.
Definition: adaptivity.hpp:53