예제 #1
0
void main (int argc, char *argv[])
{
  missile_code mc;         // Used to access missile codes from mailbox
  mbox_t mbox_N;           // Handle to the mbox_N
  mbox_t mbox_O2;
  mbox_t mbox_NO2;
  sem_t s_procs_completed; // Semaphore to signal the original process that we're done

  if (argc != 5) { 
    Printf("Usage: %s <handle_to_mbox_N><handle_to_mbox_O2><handle_to_mbox_NO2> <handle_to_page_mapped_semaphore>\n"); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  mbox_N = dstrtol(argv[1], NULL, 10); // The "10" means base 10
  mbox_O2 = dstrtol(argv[2],NULL,10);
  mbox_NO2 = dstrtol(argv[3],NULL,10);

  s_procs_completed = dstrtol(argv[4], NULL, 10);

  // Open the mailbox
  if (mbox_open(mbox_N) == MBOX_FAIL) {
    Printf("Could not open the mbox_N!\n");
    Exit();
  }
  if (mbox_open(mbox_O2) == MBOX_FAIL) {
    Printf("Could not open the mbox_N!\n");
    Exit();
  }
  if (mbox_open(mbox_NO2) == MBOX_FAIL) {
    Printf("Could not open the mbox_N!\n");
    Exit();
  }

  // Wait for a message from the mailbox
  if (mbox_recv(mbox_N, sizeof(mc), (void *)&mc) == MBOX_FAIL) {
    Printf("Could not receive message from mbox_N!\n");
    Exit();
  }
  if (mbox_recv(mbox_O2, sizeof(mc), (void *)&mc) == MBOX_FAIL) {
    Printf("Could not receive message from mbox_O2!\n");
    Exit();
  }
  if (mbox_send(mbox_NO2, sizeof(missile_code), (void *)&mc) == MBOX_FAIL) {
    Printf("Could not send message to mbox_NO2!\n");
    Exit();
  }
  else Printf("Got 1 NO2!\n");
 
  // Now print a message to show that everything worked
 // Printf("spawn_me (%d): Received missile code: %c\n", getpid(), mc.really_important_char);

  // Signal the semaphore to tell the original process that we're done
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("spawn_me (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }

//  Printf("spawn_me (%d): Done!\n", getpid());
}
예제 #2
0
void mbox_test(void)
{
	int mbox_id = mbox_init(1);
	assert(mbox_id >= 0);

	struct mboxbuf __buf, *buf = &__buf;
	buf->size = 4096;
	buf->len = buf->size;
	buf->data = (void *)0xF0000000;
	assert(mbox_send(mbox_id, buf) < 0);

	buf->data = malloc(sizeof(char) * buf->size);
	assert(buf->data != NULL);

	char *data = (char *)(buf->data);
	int i;
	for (i = 0; i < buf->size; i++) {
		data[i] = (char)i;
	}
	buf->len = buf->size;

	unsigned int timeout = 100, saved_msec = gettime_msec();

	assert(mbox_send(mbox_id, buf) == 0);
	assert(mbox_send_timeout(mbox_id, buf, timeout) == -E_TIMEOUT);
	assert((unsigned int)(gettime_msec() - saved_msec) >= timeout);

	size_t saved_size = buf->size;
	buf->size = 100;
	assert(mbox_recv(mbox_id, buf) != 0);

	buf->size = saved_size - 1;
	assert(mbox_recv(mbox_id, buf) != 0);

	buf->size = saved_size;
	memset(buf->data, 0, sizeof(char) * buf->size);
	assert(mbox_recv(mbox_id, buf) == 0);

	assert(buf->size == saved_size && buf->len == saved_size);
	data = (char *)(buf->data);
	for (i = 0; i < buf->size; i++) {
		assert(data[i] == (char)i);
	}

	saved_msec = gettime_msec();
	assert(mbox_recv_timeout(mbox_id, buf, timeout) == -E_TIMEOUT);
	assert((unsigned int)(gettime_msec() - saved_msec) >= timeout);

	assert(mbox_free(mbox_id) == 0);
	assert(mbox_send(mbox_id, buf) != 0);

	exit(0);
}
예제 #3
0
/**
 * k3_sysctrler_start() - Start the remote processor
 *		Note that while technically the K3 system controller starts up
 *		automatically after its firmware got loaded we still want to
 *		utilize the rproc start operation for other startup-related
 *		tasks.
 * @dev:	device to operate upon
 *
 * Return: 0 if all went ok, else return appropriate error
 */
static int k3_sysctrler_start(struct udevice *dev)
{
	struct k3_sysctrler_privdata *priv = dev_get_priv(dev);
	struct k3_sec_proxy_msg msg;
	int ret;

	debug("%s(dev=%p)\n", __func__, dev);

	/* Receive the boot notification. Note that it is sent only once. */
	ret = mbox_recv(&priv->chan_rx, &msg, priv->desc->max_rx_timeout_us);
	if (ret) {
		dev_err(dev, "%s: Boot Notification response failed. ret = %d\n",
			__func__, ret);
		return ret;
	}

	/* Process the response */
	ret = k3_sysctrler_boot_notification_response(msg.buf);
	if (ret)
		return ret;

	debug("%s: Boot notification received successfully on dev %s\n",
	      __func__, dev->name);

	return 0;
}
예제 #4
0
/**
 * k3_sysctrler_load() - Loadup the K3 remote processor
 * @dev:	corresponding K3 remote processor device
 * @addr:	Address in memory where image binary is stored
 * @size:	Size in bytes of the image binary
 *
 * Return: 0 if all goes good, else appropriate error message.
 */
static int k3_sysctrler_load(struct udevice *dev, ulong addr, ulong size)
{
	struct k3_sysctrler_privdata *priv = dev_get_priv(dev);
	struct k3_sysctrler_load_msg firmware;
	struct k3_sec_proxy_msg msg;
	int ret;

	debug("%s: Loading binary from 0x%08lX, size 0x%08lX\n",
	      __func__, addr, size);

	memset(&firmware, 0, sizeof(firmware));
	memset(&msg, 0, sizeof(msg));

	/* Setup the message */
	k3_sysctrler_load_msg_setup(&firmware, priv, addr, size);
	msg.len = sizeof(firmware);
	msg.buf = (u32 *)&firmware;

	/* Send the message */
	ret = mbox_send(&priv->chan_tx, &msg);
	if (ret) {
		dev_err(dev, "%s: Firmware Loading failed. ret = %d\n",
			__func__, ret);
		return ret;
	}

	/* Receive the response */
	ret = mbox_recv(&priv->chan_rx, &msg, priv->desc->max_rx_timeout_us);
	if (ret) {
		dev_err(dev, "%s: Firmware Load response failed. ret = %d\n",
			__func__, ret);
		return ret;
	}

	/* Process the response */
	ret = k3_sysctrler_load_response(msg.buf);
	if (ret)
		return ret;

	debug("%s: Firmware Loaded successfully on dev %s\n",
	      __func__, dev->name);

	return 0;
}
예제 #5
0
void main (int argc, char *argv[])
{
  int ct;

  char h2o_buffer_1[H2O_SIZE];
  char h2o_buffer_2[H2O_SIZE];

  char h2_molecule[H2_SIZE] = {'H', '2'};
  char o2_molecule[O2_SIZE] = {'O', '2'};
  
  mbox_t h_mbox_h2o;           // Handle to the mailbox for h2o
  mbox_t h_mbox_h2;
  mbox_t h_mbox_o2;

  sem_t s_procs_completed; // Semaphore to signal the original process that we're done

  if (argc != 5) { 
    Printf("Usage: %s <mailbox h2o> <mailbox h2> <mailbox o2> <handle_to_page_mapped_semaphore>\n"); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  h_mbox_h2o = dstrtol(argv[1], NULL, 10); // The "10" means base 10
  h_mbox_h2 = dstrtol(argv[2], NULL, 10); // The "10" means base 10
  h_mbox_o2 = dstrtol(argv[3], NULL, 10); // The "10" means base 10

  s_procs_completed = dstrtol(argv[4], NULL, 10);

  // Open the h2o mailbox
  if (mbox_open(h_mbox_h2o) == MBOX_FAIL) {
    Printf("Reaction 1 (%d): Could not open the h2o mailbox!\n", getpid());
    Exit();
  }

  // Wait for the first h2o molecule from the mailbox
  if (mbox_recv(h_mbox_h2o, H2O_SIZE, (void *) h2o_buffer_1) == MBOX_FAIL) {
    Printf("Reaction 1 (%d): Could not receive message from the mbox %d!\n", getpid(), h_mbox_h2o);
    Exit();
  }

  // Wait for the second h2o molecule from the mailbox  
  if (mbox_recv(h_mbox_h2o, H2O_SIZE, (void *) h2o_buffer_2) == MBOX_FAIL) {
    Printf("Reaction 1 (%d): Could not receive message from the mbox %d!\n", getpid(), h_mbox_h2o);
    Exit();
  }

  // Close the h2o mailbox
  if (mbox_close(h_mbox_h2o) == MBOX_FAIL) {
    Printf("Reaction 1 (%d): Could not close the mailbox!\n", getpid());
    Exit();
  }

  // Open the h2 mailbox
  if (mbox_open(h_mbox_h2) == MBOX_FAIL) {
    Printf("Reaction 1 (%d): Could not open the h2 mailbox!\n", getpid());
    Exit();
  }


  // Send the first h2 to the h2 mailbox
  if (mbox_send(h_mbox_h2, H2_SIZE, (void *) h2_molecule) == MBOX_FAIL) {
    Printf("Generator h2 (%d): Could not send message to the mbox %d!\n", getpid(), h_mbox_h2);
    Exit();
  }

  // Send the second h2 to the h2 mailbox
  if (mbox_send(h_mbox_h2, H2_SIZE, (void *) h2_molecule) == MBOX_FAIL) {
    Printf("Generator h2 (%d): Could not send message to the mbox %d!\n", getpid(), h_mbox_h2);
    Exit();
  }


  // Close the h2 mailbox
  if (mbox_close(h_mbox_h2) == MBOX_FAIL) {
    Printf("Generator h2 (%d): Could not close the mailbox!\n", getpid());
    Exit();
  }


  // Open the o2 mailbox
  if (mbox_open(h_mbox_o2) == MBOX_FAIL) {
    Printf("Reaction 1 (%d): Could not open the o2 mailbox!\n", getpid());
    Exit();
  }
  

  // Send the o2 to the o2 mailbox
  if (mbox_send(h_mbox_o2, O2_SIZE, (void *) o2_molecule) == MBOX_FAIL) {
    Printf("Reaction o2 (%d): Could not send message to the mbox %d!\n", getpid(), h_mbox_o2);
    Exit();
  }

  // Close the o2 mailbox
  if (mbox_close(h_mbox_o2) == MBOX_FAIL) {
    Printf("Reaction o2 (%d): Could not close the mailbox!\n", getpid());
    Exit();
  }

  // Now print a message to show that everything worked
  Printf("Two molecules H2 has been generated\n");
  Printf("A molecule O2 has been generated\n");

  // Signal the semaphore to tell the original process that we're done
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("Reaction 1 (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }

  Printf("Reaction 1 (%d): Done!\n", getpid());
}
예제 #6
0
void main (int argc, char *argv[])
{
  message m;         // Used to access missile codes from mailbox
  mbox_t h_mbox;           // Handle to the mailbox
  sem_t s_procs_completed; // Semaphore to signal the original process that we're done
  int so4_mbox,so2_mbox,o2_mbox;

  if (argc != 5) {
    Printf("\tUsage: %s <handle_to_so4_mailbox> <handle_to_so2_mailbox> <handle_to_o2_mailbox> <handle_to_page_mapped_semaphore>\n");
    Exit();
  }

  // Convert the command-line strings into integers for use as handles
  so4_mbox = dstrtol(argv[1], NULL, 10); // The "10" means base 10
  so2_mbox = dstrtol(argv[2], NULL, 10);
  o2_mbox = dstrtol(argv[3], NULL, 10);
  s_procs_completed = dstrtol(argv[4], NULL, 10);


  // Open the mailbox
  if (mbox_open(so4_mbox) == MBOX_FAIL) {
    Printf("\tspawn_rx2 (%d): Could not open the so4 mailbox!\n", getpid());
    Exit();
  }
  if (mbox_open(so2_mbox) == MBOX_FAIL) {
    Printf("\tspawn_rx2 (%d): Could not open the so2 mailbox!\n", getpid());
    Exit();
  }
  if (mbox_open(o2_mbox) == MBOX_FAIL) {
    Printf("\tspawn_rx2 (%d): Could not open the o2 mailbox!\n", getpid());
    Exit();
  }


  // Wait for a message from the mailbox
  if (mbox_recv(so4_mbox, sizeof(m), (void *)&m) == MBOX_FAIL) {
    Printf("\tspawn_rx2 (%d): Could not map the virtual address to the memory!\n", getpid());
    Exit();
  }
  Printf("\tspawn_rx2 (%d): One SO4 molecule present. Begin reaction...\n", getpid());
//  sleep(1);
  if (mbox_send(so2_mbox, sizeof(m), (void *)&m) == MBOX_FAIL) {
    Printf("\tspawn_rx2 (%d): Could not map the virtual address to the memory!\n", getpid());
    Exit();
  }
  Printf("\tspawn_rx2 (%d):Created an SO2 molecule... continue\n", getpid());
//  sleep(1);
  if (mbox_send(o2_mbox, sizeof(m), (void *)&m) == MBOX_FAIL) {
    Printf("\tspawn_rx2 (%d): Could not map the virtual address to the memory!\n", getpid());
    Exit();
  }
  Printf("\tspawn_rx2 (%d):Created an O2 molecule\n", getpid());
  // Now print a message to show that everything worked

  //Printf("\tspawn_rx2 (%d): Reaction is process, will take %d seconds\n", getpid(),10);
  //sleep(10);
  Printf("\tspawn_rx2 (%d): Done!\n\n", getpid());
  // Signal the semaphore to tell the original process that we're done
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("\tspawn_rx2 (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }


}
예제 #7
0
void main (int argc, char *argv[])
{
  message m;         // Used to access missile codes from mailbox
  //mbox_t h_mbox;           // Handle to the mailbox
  sem_t s_procs_completed; // Semaphore to signal the original process that we're done
  int so2_mbox,h2_mbox,o2_mbox;

  if (argc != 5) {
    Printf("\tUsage: %s <handle_to_so2_mailbox> <handle_to_h2_mailbox> <handle_to_o2_mailbox> <handle_to_page_mapped_semaphore>\n");
    Exit();
  }

  // Convert the command-line strings into integers for use as handles
  so2_mbox = dstrtol(argv[1], NULL, 10); // The "10" means base 10
  h2_mbox = dstrtol(argv[2], NULL, 10);
  o2_mbox = dstrtol(argv[3], NULL, 10);
  s_procs_completed = dstrtol(argv[4], NULL, 10);


  // Open the mailbox
  if (mbox_open(so2_mbox) == MBOX_FAIL) {
    Printf("\tspawn_rx3 (%d): Could not open the so2 mailbox!\n", getpid());
    Exit();
  }
  if (mbox_open(h2_mbox) == MBOX_FAIL) {
    Printf("\tspawn_rx3 (%d): Could not open the h2 mailbox!\n", getpid());
    Exit();
  }
  if (mbox_open(o2_mbox) == MBOX_FAIL) {
    Printf("\tspawn_rx3 (%d): Could not open the o2 mailbox!\n", getpid());
    Exit();
  }


  // Wait for a message from the mailbox
  if (mbox_recv(so2_mbox, sizeof(m), (void *)&m) == MBOX_FAIL) {
    Printf("\tspawn_rx3 (%d): Could not map the virtual address to the memory!\n", getpid());
    Exit();
  }
  if (mbox_recv(h2_mbox, sizeof(m), (void *)&m) == MBOX_FAIL) {
    Printf("\tspawn_rx3 (%d): Could not map the virtual address to the memory!\n", getpid());
    Exit();
  }
  if (mbox_recv(o2_mbox, sizeof(m), (void *)&m) == MBOX_FAIL) {
    Printf("\tspawn_rx3 (%d): Could not map the virtual address to the memory!\n", getpid());
    Exit();
  }

  // Now print a message to show that everything worked
  Printf("\tspawn_rx3 (%d): 1 molcule of H2, SO2 and O2 are present. starting reaction 3\n", getpid());
  //Printf("\tspawn_rx3 (%d): Reaction in process, will take 2 yields.\n", getpid());
  //yield();
  //yield();
//  sleep(1);
  Printf("\tspawn_rx3 (%d): Consuming 1 molcule of H2, SO2 and O2.\n", getpid());
  Printf("\tspawn_rx3 (%d): H2SO4 molecule created.\n", getpid());


  Printf("\tspawn_rx3 (%d): Done!\n\n", getpid());
  // Signal the semaphore to tell the original process that we're done
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("\tspawn_rx3 (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }

}
예제 #8
0
void main (int argc, char *argv[])
{
  char h2_buffer[H2_SIZE];
  char o2_buffer[O2_SIZE];
  char so2_buffer[SO2_SIZE];

  char h2so4_molecule[H2SO4_SIZE] = {'H', '2', 'S', 'O', '4'};

  mbox_t h_mbox_h2;
  mbox_t h_mbox_o2;
  mbox_t h_mbox_so2;
  mbox_t h_mbox_h2so4;

  sem_t s_procs_completed; // Semaphore to signal the original process that we're done

  /* int ct; */
  /* Printf("argc = %d\n", argc); */
  /* for(ct = 0 ; ct < argc; ct++){ */
  /*   Printf("argv[%d] = %s\n", ct, argv[ct]); */
  /* } */

  if (argc != 6) { 
    Printf("Usage: %s <mailbox h2> <mailbox o2> <mailbox so2> <mailbox h2so4> <handle_to_page_mapped_semaphore>\n"); 
    Exit();
  } 

  // Convert the command-line strings into integers for use as handles
  h_mbox_h2 = dstrtol(argv[1], NULL, 10); // The "10" means base 10
  h_mbox_o2 = dstrtol(argv[2], NULL, 10); // The "10" means base 10
  h_mbox_so2 = dstrtol(argv[3], NULL, 10); // The "10" means base 10
  h_mbox_h2so4 = dstrtol(argv[4], NULL, 10); // The "10" means base 10


  s_procs_completed = dstrtol(argv[5], NULL, 10);

  // Open the h2 mailbox
  if (mbox_open(h_mbox_h2) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not open the so4 mailbox!\n", getpid());
    Exit();
  }

  // Wait for the h2 molecule from the mailbox
  if (mbox_recv(h_mbox_h2, H2_SIZE, (void *) h2_buffer) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not receive message from the mbox %d!\n", getpid(), h_mbox_h2);
    Exit();
  }

  // Close the h2 mailbox
  if (mbox_close(h_mbox_h2) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not close the mailbox!\n", getpid());
    Exit();
  }


  // Open the o2 mailbox
  if (mbox_open(h_mbox_o2) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not open the o2 mailbox!\n", getpid());
    Exit();
  }
  

  // Send the o2 to the o2 mailbox
  if (mbox_recv(h_mbox_o2, O2_SIZE, (void *) o2_buffer) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not send message to the mbox %d!\n", getpid(), h_mbox_o2);
    Exit();
  }

  // Close the o2 mailbox
  if (mbox_close(h_mbox_o2) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not close the mailbox!\n", getpid());
    Exit();
  }


  // Open the SO2 mailbox
  if (mbox_open(h_mbox_so2) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not open the so2 mailbox!\n", getpid());
    Exit();
  }

  // Send the SO2 to the SO2 mailbox
  if (mbox_recv(h_mbox_so2, SO2_SIZE, (void *) so2_buffer) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not send message to the mbox %d!\n", getpid(), h_mbox_so2);
    Exit();
  }

  // Close the SO2 mailbox
  if (mbox_close(h_mbox_so2) == MBOX_FAIL) {
    Printf("Reaction 2 (%d): Could not close the mailbox!\n", getpid());
    Exit();
  }

    // Open the h2so4 mailbox
  if (mbox_open(h_mbox_h2so4) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not open the h2so4 mailbox!\n", getpid());
    Exit();
  }
  

  // Send the h2so4 to the o2 mailbox
  if (mbox_send(h_mbox_h2so4, H2SO4_SIZE, (void *) h2so4_molecule) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not send message to the mbox %d!\n", getpid(), h_mbox_h2so4);
    Exit();
  }

  // Close the h2so4 mailbox
  if (mbox_close(h_mbox_h2so4) == MBOX_FAIL) {
    Printf("Reaction 3 (%d): Could not close the mailbox!\n", getpid());
    Exit();
  }



  // Now print a message to show that everything worked
  Printf("A molecule H2SO4 has been generated\n");

  // Signal the semaphore to tell the original process that we're done
  if(sem_signal(s_procs_completed) != SYNC_SUCCESS) {
    Printf("Reaction 3 (%d): Bad semaphore s_procs_completed (%d)!\n", getpid(), s_procs_completed);
    Exit();
  }

  Printf("Reaction 3 (%d): Done!\n", getpid());
}