<commit_before>/**
 * @file      ac_tlm2_nb_port.cpp
 * @author    <NAME>
 *
 * @author    The ArchC Team
 *            http://www.archc.org/
 *
 *            Computer Systems Laboratory (LSC)
 *            IC-UNICAMP
 *            http://www.lsc.ic.unicamp.br/
 * 
 * @date      22, October, 2012
 * @brief     Defines the ArchC TLM 2.0  port.

 *
 * @attention Copyright (C) 2002-2012 --- The ArchC Team
 *
 */

//////////////////////////////////////////////////////////////////////////////


// Standard includes

// SystemC includes

// ArchC includes
#include "ac_tlm2_nb_port.H"
#include "ac_tlm2_payload.H"


// If you want to debug TLM 2.0, please uncomment the next line

//#define debugTLM2 

// Constructors

/** 
 * Default constructor.
 * 
 * @param size Size or address range of the element to be attached.
 * 
 */
ac_tlm2_nb_port::ac_tlm2_nb_port(char const* nm, uint32_t sz) : name(nm), size(sz), LOCAL_init_socket() {

  LOCAL_init_socket.register_nb_transport_bw(this, &ac_tlm2_nb_port::nb_transport_bw);
  //payload_global = new ac_tlm2_payload();

}


tlm::tlm_sync_enum  ac_tlm2_nb_port::nb_transport_bw(ac_tlm2_payload &payload, tlm::tlm_phase &phase, sc_core::sc_time &time)
{

	#ifdef debugTLM2
	printf("\n\nNB_TRANSPORT_BW --> Processor is receiving a package");
	#endif

	/******/
 	payload_global = new ac_tlm2_payload();
 	

	unsigned char* data_pointer = payload.get_data_ptr();		 
	payload_global->set_data_ptr(data_pointer);
    

 	payload_global->deep_copy_from(payload);
	
 	#ifdef debugTLM2
	printf("\nAC_TLM2_NB_PORT NB_TRANSPORT_BW: command-->%d  data-->%d payload_global data->%d address-->%ld",payload_global->get_command(),*data_pointer,*(payload_global->get_data_ptr()),addr);        
	printf("\nNotifying a event in BW TRANSPORT");
        #endif

	this->wake_up.notify();

	phase = tlm::END_RESP;
	tlm::tlm_sync_enum status = tlm::TLM_COMPLETED;

	return status;
}


//////////////////////////////////////////////////////////////////////////////
/** 
 * Reads a single word.
 * 
 * @param buf Buffer into which the word will be copied.
 * @param address Address from where the word will be read.
 * @param wordsize Word size in bits.
 * 
 */
void ac_tlm2_nb_port::read(ac_ptr buf, uint32_t address, int wordsize,sc_core::sc_time &time_info,unsigned int procId)

{

	payload_global = new ac_tlm2_payload();

	tlm::tlm_phase phase = tlm::BEGIN_REQ;
	tlm::tlm_sync_enum status;

  	//sc_core::sc_time time_info = sc_core::sc_time(0, SC_NS);
	unsigned char p[32];

	payload_global->set_command(tlm::TLM_READ_COMMAND);
	payload_global->set_address((sc_dt::uint64)address);
	payload_global->set_data_ptr(p);
	
    if (wordsize == 8) payload_global->set_data_length(sizeof(uint8_t));
    else if (wordsize == 16) payload_global->set_data_length(sizeof(uint16_t));
    else if (wordsize == 32) payload_global->set_data_length(sizeof(uint32_t));
	else {
		printf("\n\nAC_TLM2_NB_PORT READ: wordsize not implemented");
		exit(0);
	}

 	/** IMPORTANT: The procId has been stored at the streaming_width payload field just to avoid an extention, */
    payload_global->set_streaming_width((const unsigned int)procId);
    /**/

	#ifdef debugTLM2 
	printf("\n\n*******AC_TLM2_NB_PORT READ: command-->%d address-->%ld",tlm::TLM_READ_COMMAND, address);
	#endif

	/**********
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	

	status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info);
	if(status != tlm::TLM_UPDATED)
	{
		printf("\nAC_TLM2_NB_PORT READ ERROR");
		exit(0);
	}

	/**** TENTATIVA PARA EVITAR MEMORY LEAK*/
	delete payload_global;


	wait(this->wake_up);
	
	
	uint8_t data8;
	uint16_t data16;
	uint32_t data32;

	   switch (wordsize) 
	   {
	      case 8:
	       	data8 = *((uint8_t*)payload_global->get_data_ptr());
		*(buf.ptr8) = ((uint8_t*)&data8)[0];
	        #ifdef debugTLM2 
		printf("\nAC_TLM2_NB_PORT READ: wordsize-->%d  data8-->%d data-->%d, address-->%ld",wordsize,data8,*(payload_global->get_data_ptr()),payload_global->get_address());
		#endif
	       	break;

	      case 16:
	      
		data16 = *((uint16_t*)payload_global->get_data_ptr());
		*(buf.ptr16) = ((uint16_t*)&data16)[0];

	  	#ifdef debugTLM2 
                printf("\nAC_TLM2_NB_PORT READ: wordsize-->%d  data16-->%d data-->%d, address-->%ld",wordsize,data16,*(payload_global->get_data_ptr()),payload_global->get_address());
		#endif
                break;
	      case 32:
	       
		data32 = *((uint32_t*)payload_global->get_data_ptr());

		*(buf.ptr32) = ((uint32_t*)&data32)[0];

        	#ifdef debugTLM2 
		printf("\nAC_TLM2_NB_PORT READ: wordsize-->%d  data32-->%d data-->%d, address-->%ld",wordsize,data32,*(payload_global->get_data_ptr()),payload_global->get_address());
		#endif
        	break;
	      case 64:
	      default:
        	printf("*** AC_TLM2_NB_PORT READ: wordsize-->%d not supported ****", wordsize);
		exit(0);
	        break;
	   }

	
	delete payload_global;
 	
}

/* read n_words */

void ac_tlm2_nb_port::read(ac_ptr buf, uint32_t address,
                         int wordsize, int n_words,sc_core::sc_time &time_info,unsigned int procId) {

	payload_global = new ac_tlm2_payload();

	tlm::tlm_phase phase = tlm::BEGIN_REQ;
	tlm::tlm_sync_enum status;

	//sc_core::sc_time time_info = sc_core::sc_time(0, SC_NS);
	payload_global->set_command(tlm::TLM_READ_COMMAND);
	
	/** IMPORTANT: The procId has been stored at the streaming_width payload field just to avoid an extention, */
    payload_global->set_streaming_width((const unsigned int)procId);
    /**/

	unsigned char p[32];
	int i;
	
	#ifdef debugTLM2 
	printf("\n\n*******AC_TLM2_NB_PORT READ N_WORDS: wordsize--> %d command-->%d address-->%ld",wordsize,tlm::TLM_READ_COMMAND, address);
	#endif

	/**********
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	


	switch (wordsize) 
	{
	    case 8:
   	       
		for( i=0; i<n_words; i++)
  		{	
			payload_global->set_address(address +i);
			payload_global->set_data_length(sizeof(uint8_t));
			payload_global->set_data_ptr(p);

			status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
			if(status != tlm::TLM_UPDATED)
			{
				printf("\nAC_TLM2_NB_PORT n_words READ ERROR");
				exit(0);
			}
			
			/**** TENTATIVA PARA EVITAR MEMORY LEAK*/
			delete payload_global;

			wait(this->wake_up);
			
	
			unsigned char* data_pointer = payload_global->get_data_ptr();		

			for (int j = 0; (i < n_words) && (j < 4); j++, i++) {
				(buf.ptr8)[i] = ((uint8_t*)data_pointer)[j];
			}
			i--;
			
   		}
		break;
   
 	  case 16:
		for( i=0; i<n_words; i++)
  		{
			payload_global->set_address(address + (i * sizeof(uint16_t)));
			payload_global->set_data_length(sizeof(uint16_t));
			payload_global->set_data_ptr(p);

			status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
			if(status != tlm::TLM_UPDATED)
			{
				printf("\nAC_TLM2_NB_PORT n_words READ ERROR");
				exit(0);
			}

			/**** TENTATIVA PARA EVITAR MEMORY LEAK*/
			delete payload_global;

	
			wait(this->wake_up);

    		unsigned char* data_pointer = payload_global->get_data_ptr();


			for (int j = 0; (i < n_words) && (j < 4); j++, i++) {
				buf.ptr16[i] = ((uint16_t*)data_pointer)[j];
			}
			i--;

		}
       		break;
	  case 32:
		
		for( i=0; i<n_words; i++)
  		{	
			payload_global->set_address(address + (i * sizeof(uint32_t)));
			payload_global->set_data_length(sizeof(uint32_t));
		        payload_global->set_data_ptr(p);

			status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
			if(status != tlm::TLM_UPDATED)
			{
				printf("\nAC_TLM2_NB_PORT n_words READ ERROR");
				exit(0);
			}
	

			/**** TENTATIVA PARA EVITAR MEMORY LEAK*/
			delete payload_global;


			wait(this->wake_up);

			unsigned char* data_pointer = payload_global->get_data_ptr();
			
			buf.ptr32[i] = *((uint32_t*)data_pointer);

   		}	
	
	        break;
  	  case 64:
	  default:
		printf("\n\nAC_TLM2_NB_PORT WRITE: wordsize not implemented");
		exit(0);	
		break;
        }
	 
	delete payload_global;
 		
}

/** 
 * Writes a single word.
 * 
 * @param buf Buffer from which the word will be copied.
 * @param address Address to where the word will be written.
 * @param wordsize Word size in bits.
 *
 */
void ac_tlm2_nb_port::write(ac_ptr buf, uint32_t address, int wordsize,sc_core::sc_time &time_info, unsigned int procId) {

  unsigned char p[32];
  
  unsigned char *ptr;

  payload_global = new ac_tlm2_payload();

  tlm::tlm_phase phase = tlm::BEGIN_REQ;
  tlm::tlm_sync_enum status;

  //sc_core::sc_time time_info = sc_core::sc_time(0, SC_NS);


  #ifdef debugTLM2 
  printf("\n\n*******AC_TLM2_NB_PORT WRITE: wordsize--> %d command-->%d address-->%ld",wordsize,tlm::TLM_WRITE_COMMAND, address);
  #endif

   /** IMPORTANT: The procId has been stored at the streaming_width payload field just to avoid an extention, */
   payload_global->set_streaming_width((const unsigned int)procId);
   /**/
	/**********
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	




  switch (wordsize) {
  case 8:
    payload_global->set_command(tlm::TLM_READ_COMMAND);
    payload_global->set_address((uint64_t)address);
    payload_global->set_data_length(sizeof(uint8_t));
    payload_global->set_data_ptr(p);
    
    status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    }
	
    #ifdef debugTLM2 
    printf("\n\nAC_TLM2_NB_PORT WRITE is waiting for wake_up event");
    #endif

    /*****/
    delete payload_global;

    wait(this->wake_up);

    
    payload_global->set_command(tlm::TLM_WRITE_COMMAND);

    ptr = payload_global->get_data_ptr();
    ((uint8_t*)ptr)[0] = *(buf.ptr8);

    payload_global->set_address((uint64_t)address);
    payload_global->set_data_ptr(ptr);

    
	/**********	
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	

    status =  LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    }

	/*****/
    delete payload_global;

    wait(this->wake_up);
    

	

    break;
  case 16:
    payload_global->set_command(tlm::TLM_READ_COMMAND);
    payload_global->set_address((uint64_t)address);
    payload_global->set_data_length(sizeof(uint16_t));
    payload_global->set_data_ptr(p);

    status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    }
	

	/*****/
    delete payload_global;

    wait(this->wake_up);
    
    payload_global->set_command(tlm::TLM_WRITE_COMMAND);
    ptr = payload_global->get_data_ptr();

    ((uint16_t*)ptr)[0] = *(buf.ptr16);
    payload_global->set_address((uint64_t)address);
    payload_global->set_data_ptr(ptr);

	/**********	
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	


    status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    } 
    
    /*****/
    delete payload_global;
    wait(this->wake_up);
    

    break;
 
 case 32:
    payload_global->set_address((uint64_t)address);
    payload_global->set_command(tlm::TLM_WRITE_COMMAND);
    payload_global->set_data_length(sizeof(uint32_t));

    ((uint32_t*)p)[0]=*(buf.ptr32);

    payload_global->set_data_ptr(p);    


    /**********	
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	
	
    status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 

    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    } 


   /*****/
    delete payload_global;
    wait(this->wake_up);
	

    break;
 
  case 64:
  default:
	printf("\n\nAC_TLM2_NB_PORT WRITE: wordsize not implemented");
	exit(0);
    break;
  }

  
  delete payload_global;
<commit_msg>TLM2 payloads must be incomplete<commit_after>/**
 * @file      ac_tlm2_nb_port.cpp
 * @author    <NAME>
 *
 * @author    The ArchC Team
 *            http://www.archc.org/
 *
 *            Computer Systems Laboratory (LSC)
 *            IC-UNICAMP
 *            http://www.lsc.ic.unicamp.br/
 * 
 * @date      22, October, 2012
 * @brief     Defines the ArchC TLM 2.0  port.

 *
 * @attention Copyright (C) 2002-2012 --- The ArchC Team
 *
 */

//////////////////////////////////////////////////////////////////////////////


// Standard includes

// SystemC includes

// ArchC includes
#include "ac_tlm2_nb_port.H"
#include "ac_tlm2_payload.H"


// If you want to debug TLM 2.0, please uncomment the next line

//#define debugTLM2 

// Constructors

/** 
 * Default constructor.
 * 
 * @param size Size or address range of the element to be attached.
 * 
 */
ac_tlm2_nb_port::ac_tlm2_nb_port(char const* nm, uint32_t sz) : name(nm), size(sz), LOCAL_init_socket() {

  LOCAL_init_socket.register_nb_transport_bw(this, &ac_tlm2_nb_port::nb_transport_bw);
  //payload_global = new ac_tlm2_payload();

}


tlm::tlm_sync_enum  ac_tlm2_nb_port::nb_transport_bw(ac_tlm2_payload &payload, tlm::tlm_phase &phase, sc_core::sc_time &time)
{

	#ifdef debugTLM2
	printf("\n\nNB_TRANSPORT_BW --> Processor is receiving a package");
	#endif

	/******/
 	payload_global = new ac_tlm2_payload();
 	

	unsigned char* data_pointer = payload.get_data_ptr();		 
	payload_global->set_data_ptr(data_pointer);
    

 	payload_global->deep_copy_from(payload);
	
 	#ifdef debugTLM2
	printf("\nAC_TLM2_NB_PORT NB_TRANSPORT_BW: command-->%d  data-->%d payload_global data->%d address-->%ld",payload_global->get_command(),*data_pointer,*(payload_global->get_data_ptr()),addr);        
	printf("\nNotifying a event in BW TRANSPORT");
        #endif

	this->wake_up.notify();

	phase = tlm::END_RESP;
	tlm::tlm_sync_enum status = tlm::TLM_COMPLETED;

	return status;
}


//////////////////////////////////////////////////////////////////////////////
/** 
 * Reads a single word.
 * 
 * @param buf Buffer into which the word will be copied.
 * @param address Address from where the word will be read.
 * @param wordsize Word size in bits.
 * 
 */
void ac_tlm2_nb_port::read(ac_ptr buf, uint32_t address, int wordsize,sc_core::sc_time &time_info,unsigned int procId)

{

	payload_global = new ac_tlm2_payload();

	tlm::tlm_phase phase = tlm::BEGIN_REQ;
	tlm::tlm_sync_enum status;

  	//sc_core::sc_time time_info = sc_core::sc_time(0, SC_NS);
	unsigned char p[32];

	payload_global->set_command(tlm::TLM_READ_COMMAND);
	payload_global->set_address((sc_dt::uint64)address);
	payload_global->set_data_ptr(p);
	
    if (wordsize == 8) payload_global->set_data_length(sizeof(uint8_t));
    else if (wordsize == 16) payload_global->set_data_length(sizeof(uint16_t));
    else if (wordsize == 32) payload_global->set_data_length(sizeof(uint32_t));
	else {
		printf("\n\nAC_TLM2_NB_PORT READ: wordsize not implemented");
		exit(0);
	}

 	/** IMPORTANT: The procId has been stored at the streaming_width payload field just to avoid an extention, */
    payload_global->set_streaming_width((const unsigned int)procId);
    /**/

	#ifdef debugTLM2 
	printf("\n\n*******AC_TLM2_NB_PORT READ: command-->%d address-->%ld",tlm::TLM_READ_COMMAND, address);
	#endif

	/**********
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
	payload_global->free_all_extensions();	

	status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info);
	if(status != tlm::TLM_UPDATED)
	{
		printf("\nAC_TLM2_NB_PORT READ ERROR");
		exit(0);
	}

	/**** TENTATIVA PARA EVITAR MEMORY LEAK*/
	delete payload_global;


	wait(this->wake_up);
	
	
	uint8_t data8;
	uint16_t data16;
	uint32_t data32;

	   switch (wordsize) 
	   {
	      case 8:
	       	data8 = *((uint8_t*)payload_global->get_data_ptr());
		*(buf.ptr8) = ((uint8_t*)&data8)[0];
	        #ifdef debugTLM2 
		printf("\nAC_TLM2_NB_PORT READ: wordsize-->%d  data8-->%d data-->%d, address-->%ld",wordsize,data8,*(payload_global->get_data_ptr()),payload_global->get_address());
		#endif
	       	break;

	      case 16:
	      
		data16 = *((uint16_t*)payload_global->get_data_ptr());
		*(buf.ptr16) = ((uint16_t*)&data16)[0];

	  	#ifdef debugTLM2 
                printf("\nAC_TLM2_NB_PORT READ: wordsize-->%d  data16-->%d data-->%d, address-->%ld",wordsize,data16,*(payload_global->get_data_ptr()),payload_global->get_address());
		#endif
                break;
	      case 32:
	       
		data32 = *((uint32_t*)payload_global->get_data_ptr());

		*(buf.ptr32) = ((uint32_t*)&data32)[0];

        	#ifdef debugTLM2 
		printf("\nAC_TLM2_NB_PORT READ: wordsize-->%d  data32-->%d data-->%d, address-->%ld",wordsize,data32,*(payload_global->get_data_ptr()),payload_global->get_address());
		#endif
        	break;
	      case 64:
	      default:
        	printf("*** AC_TLM2_NB_PORT READ: wordsize-->%d not supported ****", wordsize);
		exit(0);
	        break;
	   }

	
	delete payload_global;
 	
}

/* read n_words */

void ac_tlm2_nb_port::read(ac_ptr buf, uint32_t address,
                         int wordsize, int n_words,sc_core::sc_time &time_info,unsigned int procId) {

	payload_global = new ac_tlm2_payload();

	tlm::tlm_phase phase = tlm::BEGIN_REQ;
	tlm::tlm_sync_enum status;

	//sc_core::sc_time time_info = sc_core::sc_time(0, SC_NS);
	payload_global->set_command(tlm::TLM_READ_COMMAND);
	
	/** IMPORTANT: The procId has been stored at the streaming_width payload field just to avoid an extention, */
    payload_global->set_streaming_width((const unsigned int)procId);
    /**/

	unsigned char p[32];
	int i;
	
	#ifdef debugTLM2 
	printf("\n\n*******AC_TLM2_NB_PORT READ N_WORDS: wordsize--> %d command-->%d address-->%ld",wordsize,tlm::TLM_READ_COMMAND, address);
	#endif

	/**********
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	


	switch (wordsize) 
	{
	    case 8:
   	       
		for( i=0; i<n_words; i++)
  		{	
			payload_global->set_address(address +i);
			payload_global->set_data_length(sizeof(uint8_t));
			payload_global->set_data_ptr(p);

			payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
			status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
			if(status != tlm::TLM_UPDATED)
			{
				printf("\nAC_TLM2_NB_PORT n_words READ ERROR");
				exit(0);
			}
			
			/**** TENTATIVA PARA EVITAR MEMORY LEAK*/
			delete payload_global;

			wait(this->wake_up);
			
	
			unsigned char* data_pointer = payload_global->get_data_ptr();		

			for (int j = 0; (i < n_words) && (j < 4); j++, i++) {
				(buf.ptr8)[i] = ((uint8_t*)data_pointer)[j];
			}
			i--;
			
   		}
		break;
   
 	  case 16:
		for( i=0; i<n_words; i++)
  		{
			payload_global->set_address(address + (i * sizeof(uint16_t)));
			payload_global->set_data_length(sizeof(uint16_t));
			payload_global->set_data_ptr(p);

			payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
			status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
			if(status != tlm::TLM_UPDATED)
			{
				printf("\nAC_TLM2_NB_PORT n_words READ ERROR");
				exit(0);
			}

			/**** TENTATIVA PARA EVITAR MEMORY LEAK*/
			delete payload_global;

	
			wait(this->wake_up);

    		unsigned char* data_pointer = payload_global->get_data_ptr();


			for (int j = 0; (i < n_words) && (j < 4); j++, i++) {
				buf.ptr16[i] = ((uint16_t*)data_pointer)[j];
			}
			i--;

		}
       		break;
	  case 32:
		
		for( i=0; i<n_words; i++)
  		{	
			payload_global->set_address(address + (i * sizeof(uint32_t)));
			payload_global->set_data_length(sizeof(uint32_t));
		        payload_global->set_data_ptr(p);

			payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
			status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
			if(status != tlm::TLM_UPDATED)
			{
				printf("\nAC_TLM2_NB_PORT n_words READ ERROR");
				exit(0);
			}
	

			/**** TENTATIVA PARA EVITAR MEMORY LEAK*/
			delete payload_global;


			wait(this->wake_up);

			unsigned char* data_pointer = payload_global->get_data_ptr();
			
			buf.ptr32[i] = *((uint32_t*)data_pointer);

   		}	
	
	        break;
  	  case 64:
	  default:
		printf("\n\nAC_TLM2_NB_PORT WRITE: wordsize not implemented");
		exit(0);	
		break;
        }
	 
	delete payload_global;
 		
}

/** 
 * Writes a single word.
 * 
 * @param buf Buffer from which the word will be copied.
 * @param address Address to where the word will be written.
 * @param wordsize Word size in bits.
 *
 */
void ac_tlm2_nb_port::write(ac_ptr buf, uint32_t address, int wordsize,sc_core::sc_time &time_info, unsigned int procId) {

  unsigned char p[32];
  
  unsigned char *ptr;

  payload_global = new ac_tlm2_payload();

  tlm::tlm_phase phase = tlm::BEGIN_REQ;
  tlm::tlm_sync_enum status;

  //sc_core::sc_time time_info = sc_core::sc_time(0, SC_NS);


  #ifdef debugTLM2 
  printf("\n\n*******AC_TLM2_NB_PORT WRITE: wordsize--> %d command-->%d address-->%ld",wordsize,tlm::TLM_WRITE_COMMAND, address);
  #endif

   /** IMPORTANT: The procId has been stored at the streaming_width payload field just to avoid an extention, */
   payload_global->set_streaming_width((const unsigned int)procId);
   /**/
	/**********
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	




  switch (wordsize) {
  case 8:
    payload_global->set_command(tlm::TLM_READ_COMMAND);
    payload_global->set_address((uint64_t)address);
    payload_global->set_data_length(sizeof(uint8_t));
    payload_global->set_data_ptr(p);
    
    payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
    status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    }
	
    #ifdef debugTLM2 
    printf("\n\nAC_TLM2_NB_PORT WRITE is waiting for wake_up event");
    #endif

    /*****/
    delete payload_global;

    wait(this->wake_up);

    
    payload_global->set_command(tlm::TLM_WRITE_COMMAND);

    ptr = payload_global->get_data_ptr();
    ((uint8_t*)ptr)[0] = *(buf.ptr8);

    payload_global->set_address((uint64_t)address);
    payload_global->set_data_ptr(ptr);

    
	/**********	
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	

    payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
    status =  LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    }

	/*****/
    delete payload_global;

    wait(this->wake_up);
    

	

    break;
  case 16:
    payload_global->set_command(tlm::TLM_READ_COMMAND);
    payload_global->set_address((uint64_t)address);
    payload_global->set_data_length(sizeof(uint16_t));
    payload_global->set_data_ptr(p);

    payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
    status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    }
	

	/*****/
    delete payload_global;

    wait(this->wake_up);
    
    payload_global->set_command(tlm::TLM_WRITE_COMMAND);
    ptr = payload_global->get_data_ptr();

    ((uint16_t*)ptr)[0] = *(buf.ptr16);
    payload_global->set_address((uint64_t)address);
    payload_global->set_data_ptr(ptr);

	/**********	
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	


    payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
    status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 
    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    } 
    
    /*****/
    delete payload_global;
    wait(this->wake_up);
    

    break;
 
 case 32:
    payload_global->set_address((uint64_t)address);
    payload_global->set_command(tlm::TLM_WRITE_COMMAND);
    payload_global->set_data_length(sizeof(uint32_t));

    ((uint32_t*)p)[0]=*(buf.ptr32);

    payload_global->set_data_ptr(p);    


    /**********	
	To guarantee that there are no extensions in the payload
	**********/
	payload_global->free_all_extensions();	
	
    payload_global->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
    status = LOCAL_init_socket->nb_transport_fw(*payload_global, phase, time_info); 

    if(status != tlm::TLM_UPDATED)
    {
	printf("\nAC_TLM2_NB_PORT  WRITE ERROR");
	exit(0);
    } 


   /*****/
    delete payload_global;
    wait(this->wake_up);
	

    break;
 
  case 64:
  default:
	printf("\n\nAC_TLM2_NB_PORT WRITE: wordsize not implemented");
	exit(0);
    break;
  }

  
  delete payload_global;

{'fraction_non_alphanumeric': 0.15792596108210727, 'fraction_numerical': 0.018232874545166904, 'mean_word_length': 3.5517551755175516, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 226, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '913685', 'n_tokens_mistral': 10048, 'n_tokens_neox': 9197, 'n_words': 1645}