⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tan_noc_worm_mesh_fifo_in_30.pr.c

📁 片上网络
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Process model C form file: tan_noc_worm_mesh_FIFO_in_30.pr.c */
/* Portions of this file copyright 1992-2004 by OPNET Technologies, Inc. */



/* This variable carries the header into the object file */
const char tan_noc_worm_mesh_FIFO_in_30_pr_c [] = "MIL_3_Tfile_Hdr_ 105A 30A modeler 7 49E6889A 49E6889A 1 05934b0918b5482 Administrator 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 a0a 3                                                                                                                                                                                                                                                                                                                                                                                             ";
#include <string.h>



/* OPNET system definitions */
#include <opnet.h>



/* Header Block */

#define QUEUE_EMPTY     (op_q_empty ())
#define PK_NUM          (op_q_stat(OPC_QSTAT_PKSIZE))

#define SVC_COMPLETION  op_intrpt_type () == OPC_INTRPT_SELF
#define ARRIVAL         op_intrpt_type () == OPC_INTRPT_STRM
#define FLOW_CONTROL    (op_intrpt_type () == OPC_INTRPT_STAT)

#define NEXT_FIFO_FULL_0 0
#define NEXT_FIFO_FULL_1 1
#define NEXT_FIFO_FULL_2 2
#define NEXT_FIFO_FULL_3 3
#define NEXT_FIFO_FULL_4 4



/*#define XMIT_LOW			(intrpt_type == OPC_INTRPT_STAT &&    \
							 op_intrpt_stat () == TRANSMITTING_INSTAT && \
							 op_stat_local_read (TRANSMITTING_INSTAT) == 0.0)*/
#define Local_X 0
#define Local_Y 3


#define hold_time_all 7

/* End of Header Block */


#if !defined (VOSD_NO_FIN)
#undef	BIN
#undef	BOUT
#define	BIN		FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_block_origin;
#define	BOUT	BIN
#define	BINIT	FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_block_origin = __LINE__;
#else
#define	BINIT
#endif /* #if !defined (VOSD_NO_FIN) */



/* State variable definitions */
typedef struct
	{
	/* Internal state tracking for FSM */
	FSM_SYS_STATE
	/* State Variables */
	int	                    		server_busy                                     ;
	double	                 		service_rate                                    ;
	Objid	                  		own_id                                          ;
	Stathandle	             		fifo_full                                       ;
	Stathandle	             		pk_destroy                                      ;
	int	                    		next_0                                          ;
	int	                    		next_1                                          ;
	int	                    		next_2                                          ;
	int	                    		next_3                                          ;
	int	                    		next_4                                          ;
	Stathandle	             		crossbar_busy_mid                               ;
	Stathandle	             		crossbar_busy_east                              ;
	Stathandle	             		crossbar_busy_south                             ;
	Stathandle	             		crossbar_busy_west                              ;
	Stathandle	             		crossbar_busy_north                             ;
	Stathandle	             		req_mid                                         ;
	int	                    		dir                                             ;
	Stathandle	             		req_east                                        ;
	Stathandle	             		req_south                                       ;
	Stathandle	             		req_west                                        ;
	Stathandle	             		req_north                                       ;
	int	                    		dest_address                                    ;
	} tan_noc_worm_mesh_FIFO_in_30_state;

#define pr_state_ptr            		((tan_noc_worm_mesh_FIFO_in_30_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define server_busy             		pr_state_ptr->server_busy
#define service_rate            		pr_state_ptr->service_rate
#define own_id                  		pr_state_ptr->own_id
#define fifo_full               		pr_state_ptr->fifo_full
#define pk_destroy              		pr_state_ptr->pk_destroy
#define next_0                  		pr_state_ptr->next_0
#define next_1                  		pr_state_ptr->next_1
#define next_2                  		pr_state_ptr->next_2
#define next_3                  		pr_state_ptr->next_3
#define next_4                  		pr_state_ptr->next_4
#define crossbar_busy_mid       		pr_state_ptr->crossbar_busy_mid
#define crossbar_busy_east      		pr_state_ptr->crossbar_busy_east
#define crossbar_busy_south     		pr_state_ptr->crossbar_busy_south
#define crossbar_busy_west      		pr_state_ptr->crossbar_busy_west
#define crossbar_busy_north     		pr_state_ptr->crossbar_busy_north
#define req_mid                 		pr_state_ptr->req_mid
#define dir                     		pr_state_ptr->dir
#define req_east                		pr_state_ptr->req_east
#define req_south               		pr_state_ptr->req_south
#define req_west                		pr_state_ptr->req_west
#define req_north               		pr_state_ptr->req_north
#define dest_address            		pr_state_ptr->dest_address

/* These macro definitions will define a local variable called	*/
/* "op_sv_ptr" in each function containing a FIN statement.	*/
/* This variable points to the state variable data structure,	*/
/* and can be used from a C debugger to display their values.	*/
#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE
#if defined (OPD_PARALLEL)
#  define FIN_PREAMBLE_DEC	tan_noc_worm_mesh_FIFO_in_30_state *op_sv_ptr; OpT_Sim_Context * tcontext_ptr;
#  define FIN_PREAMBLE_CODE	\
		if (VosS_Mt_Perform_Lock) \
			VOS_THREAD_SPECIFIC_DATA_GET (VosI_Globals.simi_mt_context_data_key, tcontext_ptr, SimT_Context *); \
		else \
			tcontext_ptr = VosI_Globals.simi_sequential_context_ptr; \
		op_sv_ptr = ((tan_noc_worm_mesh_FIFO_in_30_state *)(tcontext_ptr->mod_state_ptr));
#else
#  define FIN_PREAMBLE_DEC	tan_noc_worm_mesh_FIFO_in_30_state *op_sv_ptr;
#  define FIN_PREAMBLE_CODE	op_sv_ptr = pr_state_ptr;
#endif


/* No Function Block */


#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ };
#endif

/* Undefine optional tracing in FIN/FOUT/FRET */
/* The FSM has its own tracing code and the other */
/* functions should not have any tracing.		  */
#undef FIN_TRACING
#define FIN_TRACING

#undef FOUTRET_TRACING
#define FOUTRET_TRACING

#if defined (__cplusplus)
extern "C" {
#endif
	void tan_noc_worm_mesh_FIFO_in_30 (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Obtype tan_noc_worm_mesh_FIFO_in_30_init (int * init_block_ptr);
	VosT_Address tan_noc_worm_mesh_FIFO_in_30_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
	void tan_noc_worm_mesh_FIFO_in_30_diag (OP_SIM_CONTEXT_ARG_OPT);
	void tan_noc_worm_mesh_FIFO_in_30_terminate (OP_SIM_CONTEXT_ARG_OPT);
	void tan_noc_worm_mesh_FIFO_in_30_svar (void *, const char *, void **);


	VosT_Obtype Vos_Define_Object_Prstate (const char * _op_name, unsigned int _op_size);
	VosT_Address Vos_Alloc_Object_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype _op_ob_hndl);
	VosT_Fun_Status Vos_Poolmem_Dealloc_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Address _op_ob_ptr);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
tan_noc_worm_mesh_FIFO_in_30 (OP_SIM_CONTEXT_ARG_OPT)
	{

#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	FIN_MT (tan_noc_worm_mesh_FIFO_in_30 ());
		{
		/* Temporary Variables */
		Packet*          pkptr;
		OpT_Packet_Size  pk_len;
		double           pk_svc_time;
		int              insert_ok;
		
		int              flag;
		int              X,Y, hold_time;
		/* End of Temporary Variables */


		FSM_ENTER ("tan_noc_worm_mesh_FIFO_in_30")

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_FORCED_NOLABEL (0, "init", "tan_noc_worm_mesh_FIFO_in_30 [init enter execs]")
				FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [init enter execs]", state0_enter_exec)
				{
				/* initially the server is idle 	*/
				server_busy = 0;
				
				/* get queue module's own object id	*/
				own_id = op_id_self ();
				  						
				/* get assigned value of server 	*/
				/* processing rate 					*/
				op_ima_obj_attr_get (own_id, "service_rate", &service_rate);
				
				
				
				
				
				
				
				
				/* regdit a stathand of Local fifo full */
				fifo_full = op_stat_reg ("FULL", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				
				pk_destroy = op_stat_reg ("PK_DES", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				
				crossbar_busy_mid = op_stat_reg ("CRO_BUSY_mid", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				crossbar_busy_east = op_stat_reg ("CRO_BUSY_east", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				crossbar_busy_south = op_stat_reg ("CRO_BUSY_south", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				crossbar_busy_west = op_stat_reg ("CRO_BUSY_west", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				crossbar_busy_north = op_stat_reg ("CRO_BUSY_north", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				
				
				req_mid   = op_stat_reg ("REQUEST_mid", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				req_east  = op_stat_reg ("REQUEST_east", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				req_south = op_stat_reg ("REQUEST_south", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				req_west  = op_stat_reg ("REQUEST_west", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				req_north = op_stat_reg ("REQUEST_north", OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				
				next_0 = 0;
				next_1 = 0;
				next_2 = 0;
				next_3 = 0;
				next_4 = 0;
				
				dest_address = 0;
				
				//dir = 5;
				}
				FSM_PROFILE_SECTION_OUT (state0_enter_exec)

			/** state (init) exit executives **/
			FSM_STATE_EXIT_FORCED (0, "init", "tan_noc_worm_mesh_FIFO_in_30 [init exit execs]")


			/** state (init) transition processing **/
			FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [init trans conditions]", state0_trans_conds)
			FSM_INIT_COND (ARRIVAL)
			FSM_DFLT_COND
			FSM_TEST_LOGIC ("init")
			FSM_PROFILE_SECTION_OUT (state0_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "ARRIVAL", "", "init", "arrival")
				FSM_CASE_TRANSIT (1, 2, state2_enter_exec, ;, "default", "", "init", "idle")
				}
				/*---------------------------------------------------------*/



			/** state (arrival) enter executives **/
			FSM_STATE_ENTER_FORCED (1, "arrival", state1_enter_exec, "tan_noc_worm_mesh_FIFO_in_30 [arrival enter execs]")
				FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [arrival enter execs]", state1_enter_exec)
				{
				/* acquire the arriving packet 				*/
				/* multiple arriving streams are supported. */
				pkptr = op_pk_get (op_intrpt_strm ());
				
				
				
				//if (op_subq_stat (0,OPC_QSTAT_FREE_PKSIZE) == 0)
				//	fifo_full = 1;
				//else
				//	fifo_full = 0;
				//fifo_full = (op_subq_stat (0,OPC_QSTAT_FREE_PKSIZE) == 0);
				
				
				
				
				
				/* attempt to enqueue the packet at tail 	*/
				/* of subqueue 0.							*/
				if (op_subq_pk_insert (0, pkptr, OPC_QPOS_TAIL) != OPC_QINS_OK)
				    {
				    /* the inserton failed (due to to a 	*/
					/* full queue) deallocate the packet.	*/
				    op_pk_destroy (pkptr);
					
				    op_stat_write (pk_destroy, 1.0);
					
					/* set flag indicating insertion fail 	*/
					/* this flag is used to determine 		*/
					/* transition out of this state 		*/
				    insert_ok = 0;
				    }
				else{
					/* insertion was successful 			*/
				    insert_ok = 1;
				    }
				
				
				}
				FSM_PROFILE_SECTION_OUT (state1_enter_exec)

			/** state (arrival) exit executives **/
			FSM_STATE_EXIT_FORCED (1, "arrival", "tan_noc_worm_mesh_FIFO_in_30 [arrival exit execs]")
				FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [arrival exit execs]", state1_exit_exec)
				{
				op_stat_write (fifo_full, (op_subq_stat (0,OPC_QSTAT_FREE_PKSIZE) == 0));
				}
				FSM_PROFILE_SECTION_OUT (state1_exit_exec)


			/** state (arrival) transition processing **/
			FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [arrival trans conditions]", state1_trans_conds)
			FSM_INIT_COND ((PK_NUM > 1)&&server_busy)
			FSM_TEST_COND (PK_NUM == 1)
			FSM_TEST_COND ((PK_NUM > 1)&&(!server_busy))
			FSM_TEST_LOGIC ("arrival")
			FSM_PROFILE_SECTION_OUT (state1_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "(PK_NUM > 1)&&server_busy", "", "arrival", "idle")
				FSM_CASE_TRANSIT (1, 7, state7_enter_exec, ;, "PK_NUM == 1", "", "arrival", "req_get")
				FSM_CASE_TRANSIT (2, 5, state5_enter_exec, ;, "(PK_NUM > 1)&&(!server_busy)", "", "arrival", "wait")
				}
				/*---------------------------------------------------------*/



			/** state (idle) enter executives **/
			FSM_STATE_ENTER_UNFORCED (2, "idle", state2_enter_exec, "tan_noc_worm_mesh_FIFO_in_30 [idle enter execs]")

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (5,"tan_noc_worm_mesh_FIFO_in_30")


			/** state (idle) exit executives **/
			FSM_STATE_EXIT_UNFORCED (2, "idle", "tan_noc_worm_mesh_FIFO_in_30 [idle exit execs]")


			/** state (idle) transition processing **/
			FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [idle trans conditions]", state2_trans_conds)
			FSM_INIT_COND (ARRIVAL)
			FSM_TEST_COND (SVC_COMPLETION)
			FSM_TEST_COND (FLOW_CONTROL)
			FSM_TEST_LOGIC ("idle")
			FSM_PROFILE_SECTION_OUT (state2_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "ARRIVAL", "", "idle", "arrival")
				FSM_CASE_TRANSIT (1, 4, state4_enter_exec, ;, "SVC_COMPLETION", "", "idle", "svc_compl")
				FSM_CASE_TRANSIT (2, 6, state6_enter_exec, ;, "FLOW_CONTROL", "", "idle", "FLOW_CON")
				}
				/*---------------------------------------------------------*/



			/** state (svc_start) enter executives **/
			FSM_STATE_ENTER_FORCED (3, "svc_start", state3_enter_exec, "tan_noc_worm_mesh_FIFO_in_30 [svc_start enter execs]")
				FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [svc_start enter execs]", state3_enter_exec)
				{
				/* get a handle on packet at head of subqueue 0 */
				/* (this does not remove the packet) 			*/
				pkptr = op_subq_pk_access (0, OPC_QPOS_HEAD);
				
				/* determine the packets length (in bits) 		*/
				pk_len = op_pk_total_size_get (pkptr);
				
				/* determine the time required to complete 		*/
				/* service of the packet 						*/
				pk_svc_time = (double) pk_len / service_rate;
				
				
				
				if(op_intrpt_type () == OPC_INTRPT_STAT)
					{
					if(op_intrpt_stat ()==NEXT_FIFO_FULL_0)
						if(op_stat_local_read (NEXT_FIFO_FULL_0) == 1)
				            next_0=1;
				        else
					        next_0=0;
					if(op_intrpt_stat ()==NEXT_FIFO_FULL_1)
						if(op_stat_local_read (NEXT_FIFO_FULL_1) == 1)
				            next_1=1;
				        else
					        next_1=0;	
					if(op_intrpt_stat ()==NEXT_FIFO_FULL_2)
						if(op_stat_local_read (NEXT_FIFO_FULL_2) == 1)
				            next_2=1;
				        else
					        next_2=0;	
					if(op_intrpt_stat ()==NEXT_FIFO_FULL_3)
						if(op_stat_local_read (NEXT_FIFO_FULL_3) == 1)
				            next_3=1;
				        else
					        next_3=0;	
					if(op_intrpt_stat ()==NEXT_FIFO_FULL_4)
						if(op_stat_local_read (NEXT_FIFO_FULL_4) == 1)
				            next_4=1;
				        else
					        next_4=0;	
					}
				
				
				// 如果是包头,那么就加上hold_time,否则就不加。
				op_pk_nfd_get(pkptr, "flag", &flag);
				if(flag == 1) hold_time = hold_time_all;
				else hold_time = 0;
				
				
				
				
				if((next_0 == 1)&&dir==0)
				    {op_intrpt_schedule_self (op_sim_time () + pk_svc_time + hold_time, 0);
					op_stat_write(crossbar_busy_mid, 1);
					server_busy = 1;}
				else if((next_1 == 1)&&dir==1)
				    {op_intrpt_schedule_self (op_sim_time () + pk_svc_time + hold_time, 0);
					op_stat_write(crossbar_busy_east, 1);
					server_busy = 1;}
				else if((next_2 == 1)&&dir==2)
				    {op_intrpt_schedule_self (op_sim_time () + pk_svc_time + hold_time, 0);
					op_stat_write(crossbar_busy_south, 1);
					server_busy = 1;}
				else if((next_3 == 1)&&dir==3)
				    {op_intrpt_schedule_self (op_sim_time () + pk_svc_time + hold_time, 0);
					op_stat_write(crossbar_busy_west, 1);
					server_busy = 1;}
				else if((next_4 == 1)&&dir==4)
				    {op_intrpt_schedule_self (op_sim_time () + pk_svc_time + hold_time, 0);
					op_stat_write(crossbar_busy_north, 1);
					server_busy = 1;}
				else 
					server_busy = 0;
				
				
				
				/* schedule an interrupt for this process 		*/
				/* at the time where service ends. 				*/
				
				
				/* the server is now busy. 						*/
				
				
				
				}
				FSM_PROFILE_SECTION_OUT (state3_enter_exec)

			/** state (svc_start) exit executives **/
			FSM_STATE_EXIT_FORCED (3, "svc_start", "tan_noc_worm_mesh_FIFO_in_30 [svc_start exit execs]")


			/** state (svc_start) transition processing **/
			FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [svc_start trans conditions]", state3_trans_conds)
			FSM_INIT_COND (server_busy)
			FSM_TEST_COND (!server_busy)
			FSM_TEST_LOGIC ("svc_start")
			FSM_PROFILE_SECTION_OUT (state3_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "server_busy", "", "svc_start", "idle")
				FSM_CASE_TRANSIT (1, 5, state5_enter_exec, ;, "!server_busy", "", "svc_start", "wait")
				}
				/*---------------------------------------------------------*/



			/** state (svc_compl) enter executives **/
			FSM_STATE_ENTER_FORCED (4, "svc_compl", state4_enter_exec, "tan_noc_worm_mesh_FIFO_in_30 [svc_compl enter execs]")
				FSM_PROFILE_SECTION_IN ("tan_noc_worm_mesh_FIFO_in_30 [svc_compl enter execs]", state4_enter_exec)
				{
				pkptr = op_subq_pk_remove (0, OPC_QPOS_HEAD);   
				op_pk_send_forced (pkptr, dir);
				
				
				

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -