2001-11-06 04:07:21 +01:00
|
|
|
#ifndef __event_H
|
|
|
|
|
#define __event_H
|
|
|
|
|
/*
|
2009-01-30 02:23:09 +01:00
|
|
|
* Copyright (c) 2004-2009 Stephen Williams (steve@icarus.com)
|
2001-11-06 04:07:21 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
# include "vvp_net.h"
|
|
|
|
|
# include "pointers.h"
|
2008-09-18 22:44:54 +02:00
|
|
|
# include "array.h"
|
2009-01-30 02:23:09 +01:00
|
|
|
# include "config.h"
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2008-09-11 04:37:11 +02:00
|
|
|
class evctl {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit evctl(unsigned long ecount);
|
2008-09-18 01:47:20 +02:00
|
|
|
bool dec_and_run();
|
|
|
|
|
virtual void run_run() = 0;
|
2008-09-11 04:37:11 +02:00
|
|
|
virtual ~evctl() {}
|
|
|
|
|
evctl*next;
|
|
|
|
|
|
2008-09-18 22:44:54 +02:00
|
|
|
private:
|
2008-09-11 04:37:11 +02:00
|
|
|
unsigned long ecount_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class evctl_real : public evctl {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit evctl_real(struct __vpiHandle*handle, double value,
|
|
|
|
|
unsigned long ecount);
|
|
|
|
|
virtual ~evctl_real() {}
|
2008-09-18 01:47:20 +02:00
|
|
|
void run_run();
|
2008-09-11 04:37:11 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
__vpiHandle*handle_;
|
|
|
|
|
double value_;
|
|
|
|
|
};
|
|
|
|
|
|
2008-09-18 01:47:20 +02:00
|
|
|
class evctl_vector : public evctl {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit evctl_vector(vvp_net_ptr_t ptr, const vvp_vector4_t&value,
|
|
|
|
|
unsigned off, unsigned wid, unsigned long ecount);
|
|
|
|
|
virtual ~evctl_vector() {}
|
|
|
|
|
void run_run();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vvp_net_ptr_t ptr_;
|
|
|
|
|
vvp_vector4_t value_;
|
|
|
|
|
unsigned off_;
|
|
|
|
|
unsigned wid_;
|
|
|
|
|
};
|
|
|
|
|
|
2008-09-18 22:44:54 +02:00
|
|
|
class evctl_array : public evctl {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit evctl_array(vvp_array_t memory, unsigned index,
|
|
|
|
|
const vvp_vector4_t&value, unsigned off,
|
|
|
|
|
unsigned long ecount);
|
|
|
|
|
virtual ~evctl_array() {}
|
|
|
|
|
virtual void run_run();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vvp_array_t mem_;
|
|
|
|
|
unsigned idx_;
|
|
|
|
|
vvp_vector4_t value_;
|
|
|
|
|
unsigned off_;
|
|
|
|
|
};
|
|
|
|
|
|
2009-09-03 05:04:34 +02:00
|
|
|
class evctl_array_r : public evctl {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit evctl_array_r(vvp_array_t memory, unsigned index,
|
|
|
|
|
double value, unsigned long ecount);
|
|
|
|
|
virtual ~evctl_array_r() {}
|
|
|
|
|
virtual void run_run();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vvp_array_t mem_;
|
|
|
|
|
unsigned idx_;
|
|
|
|
|
double value_;
|
|
|
|
|
};
|
|
|
|
|
|
2008-09-11 04:37:11 +02:00
|
|
|
extern void schedule_evctl(struct __vpiHandle*handle, double value,
|
|
|
|
|
vvp_net_t*event, unsigned long ecount);
|
|
|
|
|
|
2008-09-18 01:47:20 +02:00
|
|
|
extern void schedule_evctl(vvp_net_ptr_t ptr, const vvp_vector4_t&value,
|
|
|
|
|
unsigned offset, unsigned wid,
|
|
|
|
|
vvp_net_t*event, unsigned long ecount);
|
|
|
|
|
|
2008-09-18 22:44:54 +02:00
|
|
|
extern void schedule_evctl(vvp_array_t memory, unsigned index,
|
|
|
|
|
const vvp_vector4_t&value, unsigned offset,
|
|
|
|
|
vvp_net_t*event, unsigned long ecount);
|
|
|
|
|
|
2009-09-03 05:04:34 +02:00
|
|
|
extern void schedule_evctl(vvp_array_t memory, unsigned index,
|
|
|
|
|
double value,
|
|
|
|
|
vvp_net_t*event, unsigned long ecount);
|
|
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
/*
|
|
|
|
|
* Event / edge detection functors
|
|
|
|
|
*/
|
|
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
/*
|
|
|
|
|
* A "waitable" functor is one that the %wait instruction can wait
|
|
|
|
|
* on. This includes the infrastructure needed to hold threads.
|
|
|
|
|
*/
|
|
|
|
|
struct waitable_hooks_s {
|
2004-12-18 19:52:44 +01:00
|
|
|
|
2005-06-18 01:47:02 +02:00
|
|
|
public:
|
2008-10-28 18:52:39 +01:00
|
|
|
waitable_hooks_s() : event_ctls(0) { last = &event_ctls; }
|
|
|
|
|
|
|
|
|
|
virtual vthread_t add_waiting_thread(vthread_t thread) = 0;
|
|
|
|
|
|
2008-09-11 04:37:11 +02:00
|
|
|
evctl*event_ctls;
|
|
|
|
|
evctl**last;
|
2004-12-18 19:52:44 +01:00
|
|
|
|
|
|
|
|
protected:
|
2008-10-28 18:52:39 +01:00
|
|
|
void run_waiting_threads_(vthread_t&threads);
|
2008-09-27 01:54:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is the base object for storing state information for each instance
|
|
|
|
|
* of an automatically allocated event. In the general case, all that is
|
|
|
|
|
* needed is the list of threads waiting on that instance.
|
|
|
|
|
*/
|
|
|
|
|
struct waitable_state_s {
|
|
|
|
|
waitable_state_s() : threads(0) { }
|
2008-10-28 18:52:39 +01:00
|
|
|
|
2008-09-27 01:54:13 +02:00
|
|
|
vthread_t threads;
|
2001-11-06 04:07:21 +01:00
|
|
|
};
|
|
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
/*
|
|
|
|
|
* The vvp_fun_edge functor detects events that are edges of various
|
|
|
|
|
* types. This should be hooked to a vvp_net_t that is connected to
|
|
|
|
|
* the output of a signal that we wish to watch for edges.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_fun_edge : public vvp_net_fun_t, public waitable_hooks_s {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
typedef unsigned short edge_t;
|
2008-10-28 18:52:39 +01:00
|
|
|
explicit vvp_fun_edge(edge_t e);
|
2004-12-11 03:31:25 +01:00
|
|
|
virtual ~vvp_fun_edge();
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
protected:
|
|
|
|
|
bool recv_vec4_(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_bit4_t&old_bit, vthread_t&threads);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2009-07-27 00:43:38 +02:00
|
|
|
vvp_bit4_t bits_[4];
|
|
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
private:
|
|
|
|
|
edge_t edge_;
|
|
|
|
|
};
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
extern const vvp_fun_edge::edge_t vvp_edge_posedge;
|
|
|
|
|
extern const vvp_fun_edge::edge_t vvp_edge_negedge;
|
|
|
|
|
extern const vvp_fun_edge::edge_t vvp_edge_none;
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
/*
|
|
|
|
|
* Statically allocated vvp_fun_edge.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_fun_edge_sa : public vvp_fun_edge {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_fun_edge_sa(edge_t e);
|
|
|
|
|
virtual ~vvp_fun_edge_sa();
|
|
|
|
|
|
|
|
|
|
vthread_t add_waiting_thread(vthread_t thread);
|
|
|
|
|
|
|
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t context);
|
2009-09-12 04:42:30 +02:00
|
|
|
void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
unsigned base, unsigned wid, unsigned vwid,
|
|
|
|
|
vvp_context_t context);
|
2008-10-28 18:52:39 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vthread_t threads_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Automatically allocated vvp_fun_edge.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_fun_edge_aa : public vvp_fun_edge, public automatic_hooks_s {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_fun_edge_aa(edge_t e);
|
|
|
|
|
virtual ~vvp_fun_edge_aa();
|
|
|
|
|
|
|
|
|
|
void alloc_instance(vvp_context_t context);
|
|
|
|
|
void reset_instance(vvp_context_t context);
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void free_instance(vvp_context_t context);
|
|
|
|
|
#endif
|
2008-10-28 18:52:39 +01:00
|
|
|
|
|
|
|
|
vthread_t add_waiting_thread(vthread_t thread);
|
|
|
|
|
|
|
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t context);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct __vpiScope*context_scope_;
|
|
|
|
|
unsigned context_idx_;
|
|
|
|
|
};
|
|
|
|
|
|
2004-12-30 00:45:13 +01:00
|
|
|
/*
|
|
|
|
|
* The vvp_fun_anyedge functor checks to see if any value in an input
|
|
|
|
|
* vector changes. Unlike the vvp_fun_edge, which watches for the LSB
|
|
|
|
|
* of its inputs to change in a particular direction, the anyedge
|
|
|
|
|
* functor looks at the entire input vector for any change.
|
2006-12-09 20:06:53 +01:00
|
|
|
*
|
|
|
|
|
* The anyedge is also different in that it can receive real
|
2008-09-27 01:54:13 +02:00
|
|
|
* values. In this case, any detectable change in the real value leads
|
|
|
|
|
* to an event trigger.
|
2004-12-30 00:45:13 +01:00
|
|
|
*/
|
|
|
|
|
class vvp_fun_anyedge : public vvp_net_fun_t, public waitable_hooks_s {
|
|
|
|
|
|
|
|
|
|
public:
|
2008-10-28 18:52:39 +01:00
|
|
|
explicit vvp_fun_anyedge();
|
2004-12-30 00:45:13 +01:00
|
|
|
virtual ~vvp_fun_anyedge();
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
protected:
|
|
|
|
|
bool recv_vec4_(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_vector4_t&old_bits, vthread_t&threads);
|
|
|
|
|
bool recv_real_(vvp_net_ptr_t port, double bit,
|
|
|
|
|
double&old_bits, vthread_t&threads);
|
2009-07-27 00:43:38 +02:00
|
|
|
|
|
|
|
|
vvp_vector4_t bits_[4];
|
|
|
|
|
// In case I'm a real-valued event.
|
|
|
|
|
double bitsr_[4];
|
2008-10-28 18:52:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Statically allocated vvp_fun_anyedge.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_fun_anyedge_sa : public vvp_fun_anyedge {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_fun_anyedge_sa();
|
|
|
|
|
virtual ~vvp_fun_anyedge_sa();
|
2008-09-27 01:54:13 +02:00
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vthread_t add_waiting_thread(vthread_t thread);
|
|
|
|
|
|
|
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t context);
|
2009-09-12 04:42:30 +02:00
|
|
|
void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
unsigned base, unsigned wid, unsigned vwid,
|
|
|
|
|
vvp_context_t context);
|
2008-10-28 18:52:39 +01:00
|
|
|
|
|
|
|
|
void recv_real(vvp_net_ptr_t port, double bit,
|
|
|
|
|
vvp_context_t context);
|
2004-12-30 00:45:13 +01:00
|
|
|
|
|
|
|
|
private:
|
2008-10-28 18:52:39 +01:00
|
|
|
vthread_t threads_;
|
2004-12-30 00:45:13 +01:00
|
|
|
};
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
/*
|
|
|
|
|
* Automatically allocated vvp_fun_anyedge.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_fun_anyedge_aa : public vvp_fun_anyedge, public automatic_hooks_s {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_fun_anyedge_aa();
|
|
|
|
|
virtual ~vvp_fun_anyedge_aa();
|
|
|
|
|
|
|
|
|
|
void alloc_instance(vvp_context_t context);
|
|
|
|
|
void reset_instance(vvp_context_t context);
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void free_instance(vvp_context_t context);
|
|
|
|
|
#endif
|
2008-10-28 18:52:39 +01:00
|
|
|
|
|
|
|
|
vthread_t add_waiting_thread(vthread_t thread);
|
|
|
|
|
|
|
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t context);
|
|
|
|
|
|
|
|
|
|
void recv_real(vvp_net_ptr_t port, double bit,
|
|
|
|
|
vvp_context_t context);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct __vpiScope*context_scope_;
|
|
|
|
|
unsigned context_idx_;
|
|
|
|
|
};
|
|
|
|
|
|
2005-05-25 07:44:51 +02:00
|
|
|
/*
|
|
|
|
|
* This functor triggers anytime any input is set, no matter what the
|
|
|
|
|
* value. This is similar to a named event, but it has no handle.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_fun_event_or : public vvp_net_fun_t, public waitable_hooks_s {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_fun_event_or();
|
|
|
|
|
~vvp_fun_event_or();
|
2008-10-28 18:52:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Statically allocated vvp_fun_event_or.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_fun_event_or_sa : public vvp_fun_event_or {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_fun_event_or_sa();
|
|
|
|
|
~vvp_fun_event_or_sa();
|
|
|
|
|
|
|
|
|
|
vthread_t add_waiting_thread(vthread_t thread);
|
|
|
|
|
|
|
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t context);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vthread_t threads_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Automatically allocated vvp_fun_event_or.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_fun_event_or_aa : public vvp_fun_event_or, public automatic_hooks_s {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_fun_event_or_aa();
|
|
|
|
|
~vvp_fun_event_or_aa();
|
2005-05-25 07:44:51 +02:00
|
|
|
|
2008-09-27 01:54:13 +02:00
|
|
|
void alloc_instance(vvp_context_t context);
|
|
|
|
|
void reset_instance(vvp_context_t context);
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void free_instance(vvp_context_t context);
|
|
|
|
|
#endif
|
2008-09-27 01:54:13 +02:00
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vthread_t add_waiting_thread(vthread_t thread);
|
|
|
|
|
|
|
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t context);
|
2005-05-25 07:44:51 +02:00
|
|
|
|
|
|
|
|
private:
|
2008-10-28 18:52:39 +01:00
|
|
|
struct __vpiScope*context_scope_;
|
|
|
|
|
unsigned context_idx_;
|
2005-05-25 07:44:51 +02:00
|
|
|
};
|
|
|
|
|
|
2002-05-19 07:18:16 +02:00
|
|
|
/*
|
2004-12-18 19:52:44 +01:00
|
|
|
* A named event is simpler then a vvp_fun_edge in that it triggers on
|
|
|
|
|
* any input at all to port-0. The idea here is that behavioral code
|
|
|
|
|
* can use a %set/v instruction to trigger the event.
|
2002-05-19 07:18:16 +02:00
|
|
|
*/
|
2004-12-18 19:52:44 +01:00
|
|
|
class vvp_named_event : public vvp_net_fun_t, public waitable_hooks_s {
|
2002-05-19 07:18:16 +02:00
|
|
|
|
|
|
|
|
public:
|
2004-12-18 19:52:44 +01:00
|
|
|
explicit vvp_named_event(struct __vpiHandle*eh);
|
|
|
|
|
~vvp_named_event();
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
protected:
|
|
|
|
|
struct __vpiHandle*handle_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Statically allocated vvp_named_event.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_named_event_sa : public vvp_named_event {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_named_event_sa(struct __vpiHandle*eh);
|
|
|
|
|
~vvp_named_event_sa();
|
|
|
|
|
|
|
|
|
|
vthread_t add_waiting_thread(vthread_t thread);
|
|
|
|
|
|
|
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vthread_t threads_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Automatically allocated vvp_named_event.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_named_event_aa : public vvp_named_event, public automatic_hooks_s {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit vvp_named_event_aa(struct __vpiHandle*eh);
|
|
|
|
|
~vvp_named_event_aa();
|
|
|
|
|
|
2008-09-27 01:54:13 +02:00
|
|
|
void alloc_instance(vvp_context_t context);
|
|
|
|
|
void reset_instance(vvp_context_t context);
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void free_instance(vvp_context_t context);
|
|
|
|
|
#endif
|
2008-09-27 01:54:13 +02:00
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vthread_t add_waiting_thread(vthread_t thread);
|
|
|
|
|
|
|
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t context);
|
2002-05-19 07:18:16 +02:00
|
|
|
|
2004-12-18 19:52:44 +01:00
|
|
|
private:
|
2008-10-28 18:52:39 +01:00
|
|
|
unsigned context_idx_;
|
2002-05-19 07:18:16 +02:00
|
|
|
};
|
|
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
#endif // __event_H
|