void K2DspLrtCommunicator::data_end_send(Fifo* f){
	/* Write back cache */
	Osal_qmssEndMemAccess(
			Platform::get()->virt_to_phy((void*)(f->alloc)),
			f->size);

	if(f->ntoken){
		Cppi_Desc *mono_pkt;
		int queueId = QUEUE_DATA_BASE+f->id;

		if(queueId < QUEUE_DATA_BASE || queueId > QUEUE_LAST )
			throw "Error: request queue out of bound\n";

		for(int i=0; i<f->ntoken; i++){
			do{
				mono_pkt = (Cppi_Desc*)Qmss_queuePop(QUEUE_FREE_DATA);
			}while(mono_pkt == 0);

			/* Get Packet info */
			int mono_pkt_size  = QMSS_DESC_SIZE(mono_pkt);
			mono_pkt = (Cppi_Desc*)QMSS_DESC_PTR (mono_pkt);

//			/* Clear Cache */
//			Osal_qmssBeginMemAccess(mono_pkt, mono_pkt_size);
//
//			/* Write back cache */
//			Osal_qmssEndMemAccess(mono_pkt, mono_pkt_size);

			/* Send Packet */
			Qmss_queuePushDesc(queueId, mono_pkt);
		}
	}
}
void K2ArmSpiderCommunicator::trace_end_recv(){
	if(cur_mono_trace_in){
		/* Send the descriptor */
		Osal_qmssEndMemAccess(cur_mono_trace_in, cur_mono_trace_in_size);
		Qmss_queuePushDesc(QUEUE_FREE_TRACE, cur_mono_trace_in);

		cur_mono_trace_in = 0;
		cur_mono_trace_in_size = 0;
	}else
		throw "SpiderCommunicator: Try to send a free'd message";
}
void K2ArmSpiderCommunicator::trace_end_send(int size){
	if(cur_mono_trace_out){
		/* Send the descriptor */
		Osal_qmssEndMemAccess(cur_mono_trace_out, cur_mono_trace_out_size);
		Qmss_queuePushDesc(QUEUE_TRACE, cur_mono_trace_out);

		cur_mono_trace_out = 0;
		cur_mono_trace_out_size = 0;
	}else
		throw "SpiderCommunicator: Try to send a free'd message";
}
void K2ArmSpiderCommunicator::ctrl_end_recv(int lrtIx){
	if(cur_mono_pkt_in[lrtIx]){
		/* Send the descriptor */
		Osal_qmssEndMemAccess(cur_mono_pkt_in[lrtIx], cur_mono_pkt_in_size[lrtIx]);
		Qmss_queuePushDesc(QUEUE_FREE_CTRL, cur_mono_pkt_in[lrtIx]);

		cur_mono_pkt_in[lrtIx] = 0;
		cur_mono_pkt_in_size[lrtIx] = 0;
	}else
		throw "SpiderCommunicator: Try to send a free'd message";
}
void K2ArmSpiderCommunicator::ctrl_end_send(int lrtIx, int size){
	if(cur_mono_pkt_out[lrtIx]){
		/* Send the descriptor */
		Osal_qmssEndMemAccess(cur_mono_pkt_out[lrtIx], cur_mono_pkt_out_size[lrtIx]);
		Qmss_queuePushDesc(CTRL_SPIDER_TO_LRT(lrtIx), (void*)cur_mono_pkt_out[lrtIx]);

		cur_mono_pkt_out[lrtIx] = 0;
		cur_mono_pkt_out_size[lrtIx] = 0;
	}else
		throw "SpiderCommunicator: Try to send a free'd message";
}
void K2DspLrtCommunicator::ctrl_end_recv(){
	if(cur_mono_pkt_in){
		/* Send the descriptor */
		Osal_qmssEndMemAccess(cur_mono_pkt_in, cur_mono_pkt_in_size);
		Qmss_queuePushDesc(QUEUE_FREE_CTRL, cur_mono_pkt_in);

		cur_mono_pkt_in = 0;
		cur_mono_pkt_in_size = 0;
	}else
		throw "LrtCommunicator: Try to send a free'd message";
}
void K2DspLrtCommunicator::ctrl_end_send(int size){
	if(cur_mono_pkt_out){
		/* Send the descriptor */
		Osal_qmssEndMemAccess(cur_mono_pkt_out, cur_mono_pkt_out_size);
		Qmss_queuePushDesc(CTRL_LRT_TO_SPIDER, (void*)cur_mono_pkt_out);

		cur_mono_pkt_out = 0;
		cur_mono_pkt_out_size = 0;
	}else
		throw "LrtCommunicator: Try to send a free'd message";
}