Ejemplo n.º 1
0
int main(int argc , char ** argv)
{
  int sendMQ, recvMQ;	/* id of MQ's */
  char buffer[BUFFER_SIZE];
  int pid, i;

  pid = Get_PID();
  Print ("Starting process %d (%s)...\n", pid, sending) ;

  sendMQ = Message_Queue_Create("ping_MQ", MAILBOX_SIZE);
  recvMQ = Message_Queue_Create("pong_MQ", MAILBOX_SIZE);

  for (i=0; i < NR_MESSAGES; i++) 
    {
      Message_Queue_Send(sendMQ, sending, (BUFFER_SIZE - 1));
      Message_Queue_Receive(recvMQ, buffer, (BUFFER_SIZE - 1));

      buffer[BUFFER_SIZE - 1] = '\0';

      Print("Process %d sent %s, awaiting %s, got '%s'\n", pid, sending, awaiting, buffer);
    }

  Message_Queue_Destroy(sendMQ);
  Message_Queue_Destroy(recvMQ);

  Print ("\nProcess %d (%s) is done !\n", pid, sending) ;

  return (0);

}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
	char commandBuf[BUFSIZE + 1];
	struct Process proc;
	char path[BUFSIZE + 1] = DEFAULT_PATH;
	char *command;
	int detached;

	/* Set attribute to gray on black. */
	Print("\x1B[37m");

	while (true) {
		/* Print shell prompt (bright cyan on black background) */
		Print("\x1B[1;36m$\x1B[37m ");

		/* Read a line of input */
		Read_Line(commandBuf, sizeof(commandBuf));
		command = Strip_Leading_Whitespace(commandBuf);
		Trim_Newline(command);
		detached = isDetached(command);

		/*
		 * Handle some special commands
		 */
		if (strcmp(command, "exit") == 0) {
			/* Exit the shell */
			break;
		} else if (strcmp(command, "pid") == 0) {
			/* Print the pid of this process */
			Print("%d\n", Get_PID());
			continue;
		} else if (strcmp(command, "exitCodes") == 0) {
			/* Print exit codes of spawned processes. */
			exitCodes = 1;
			continue;
		} else if (strncmp(command, "path=", 5) == 0) {
			/* Set the executable search path */
			strcpy(path, command + 5);
			continue;
		} else if (strcmp(command, "") == 0) {
			/* Blank line. */
			continue;
		}

		proc.command = Strip_Leading_Whitespace(command);
		if (!Copy_Token(proc.program, proc.command)) {
			Print("Error: invalid command\n");
			continue;
		}

		Spawn_Single_Command(&proc, path, detached);
		if (detached && proc.pid > 0)
			Print("[%d]\n", proc.pid);

	}

	Print_String("DONE!\n");
	return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    int nproc;
    char commandBuf[BUFSIZE+1];
    struct Process procList[MAXPROC];
    char path[BUFSIZE+1] = DEFAULT_PATH;
    char *command;

    /* Set attribute to gray on black. */
    Print("\x1B[37m");

    while (true) {
	/* Print shell prompt (bright cyan on black background) */
	Print("\x1B[1;36m$\x1B[37m ");

	/* Read a line of input */
	Read_Line(commandBuf, sizeof(commandBuf));
	command = Strip_Leading_Whitespace(commandBuf);
	Trim_Newline(command);

	/*
	 * Handle some special commands
	 */
	if (strcmp(command, "exit") == 0) {
	    /* Exit the shell */
	    break;
	} else if (strcmp(command, "pid") == 0) {
	    /* Print the pid of this process */
	    Print("%d\n", Get_PID());
	    continue;
	} else if (strcmp(command, "exitCodes") == 0) {
	    /* Print exit codes of spawned processes. */
	    exitCodes = 1;
	    continue;
	} else if (strncmp(command, "path=", 5) == 0) {
	    /* Set the executable search path */
	    strcpy(path, command + 5);
	    continue;
	} else if (strcmp(command, "") == 0) {
	    /* Blank line. */
	    continue;
	}

	/*
	 * Parse the command string and build array of
	 * Process structs representing a pipeline of commands.
	 */
	nproc = Build_Pipeline(command, procList);
	if (nproc <= 0)
	    continue;

	Spawn_Pipeline(procList, nproc, path);
    }

    Print_String("DONE!\n");
    return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
    int n = 0;
    int child_pid = 0;
    Print("original\n");
    child_pid = Fork();
    n++;
    global ++;
    if(child_pid > 0) {
        Print("parent n=%d, global=%d, child_pid=%d, my_pid=%d\n", n,
              global, child_pid, Get_PID());
    } else if(child_pid == 0) {
        Print("child n=%d, global=%d, child_pid=%d, my_pid=%d\n", n,
              global, child_pid, Get_PID());
    } else {
        Print("fork failed: %s (%d)\n", Get_Error_String(child_pid),
              child_pid);
    }

    return 0;
}
Ejemplo n.º 5
0
//! @brief In host mode, display basic low level information about the device connected
//!
//! @note The device should be supported by the host (configured)
//!
void ushell_cmdusb_ls(void)
{
   uint8_t i,j;

   // Check USB host status
   if( (!Is_host_ready()) && (!Is_host_suspended()) )
   {
      fputs(MSG_NO_DEVICE, stdout);
      return;
   }
   if( Is_host_suspended() )
   {
      fputs(MSG_USB_SUSPENDED, stdout);
   }

   printf("VID:%04X, PID:%04X, ",Get_VID(),Get_PID());
   printf("MaxPower is %imA, ",2*Get_maxpower());
   if (Is_device_self_powered())
   {  fputs(MSG_SELF_POWERED, stdout);}
   else
   {  fputs(MSG_BUS_POWERED, stdout); }
   if (Is_usb_full_speed_mode())
   {  fputs(MSG_DEVICE_FULL_SPEED, stdout);}
   else
#if (USB_HIGH_SPEED_SUPPORT==false)
   {  fputs(MSG_DEVICE_LOW_SPEED, stdout); }
#else
   {  fputs(MSG_DEVICE_HIGH_SPEED, stdout); }
#endif
   if (Is_device_supports_remote_wakeup())
   {  fputs(MSG_REMOTE_WAKEUP_OK, stdout);}
   else
   {  fputs(MSG_REMOTE_WAKEUP_KO, stdout); }
   printf("Supported interface(s):%02i\n\r",Get_nb_supported_interface());
   for(i=0;i<Get_nb_supported_interface();i++)
   {
      printf("Interface nb:%02i, AltS nb:%02i, Class:%02i, SubClass:%02i, Protocol:%02i\n\r",\
         Get_interface_number(i), Get_altset_nb(i), Get_class(i), Get_subclass(i), Get_protocol(i));
      printf(" Endpoint(s) Addr:");
      if(Get_nb_ep(i))
      {
         for(j=0;j<Get_nb_ep(i);j++)
         {
            printf(" %02lX", Get_ep_nbr(i,j));
         }
      }
      else
      {
         printf("None");
      }
      putchar(ASCII_CR);putchar(ASCII_LF);
   }
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
  int i, j ;     	/* loop index */
  Print("Start Long\n");

  for (i=0; i < 400; i++) {
      for (j=0 ; j < 10000 ; j++) ;
      Get_PID();
      Print("%d\n",i);
  }
  Print("End Long\n");

  return 0;
}
Ejemplo n.º 7
0
/*!
 *  \brief In host mode, display basic low-level information about the connected device.
 *  The device should be supported by the host (configured).
 *         No parameters.
 *         Format: lsusb
 *
 *  \note  This function must be of the type pfShellCmd defined by the shell module.
 *
 *  \param xModId         Input. The module that is calling this function.
 *  \param FsNavId        Ignored.
 *  \param ac             Input. The argument counter. Ignored.
 *  \param av             Input. The argument vector. Ignored
 *  \param ppcStringReply Input/Output. The response string.
 *                        If Input is NULL, no response string will be output.
 *                        Else a malloc for the response string is performed here;
 *                        the caller must free this string.
 *
 *  \return the status of the command execution.
 */
eExecStatus e_usbsys_lsusb( eModId xModId, signed short FsNavId,
                       int ac, signed portCHAR *av[],
                       signed portCHAR **ppcStringReply )
{
#if USB_HOST_FEATURE == true
   signed portCHAR *pcStringToPrint;
   U8 i, j;


   if( NULL != ppcStringReply )
      *ppcStringReply = NULL;

   if (!Is_host_ready() && !Is_host_suspended())
   {
      v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE );
      return SHELL_EXECSTATUS_KO;
   }

   pcStringToPrint = (signed portCHAR *)pvPortMalloc( SHELL_MAX_MSGOUT_LEN ); // Alloc
   if( NULL == pcStringToPrint )
   {
      return( SHELL_EXECSTATUS_KO );
   }

   if (Is_host_suspended())
   {
      v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_USB_SUSPENDED CRLF );
   }

   sprintf( (char *)pcStringToPrint, "VID: 0x%.4X, PID: 0x%.4X\r\n"
            "Device MaxPower is %d mA\r\n"
            "%s"
            "%s",
            Get_VID(), Get_PID(),
            2 * Get_maxpower(),
            Is_device_self_powered() ? MSG_SELF_POWERED : MSG_BUS_POWERED,
            Is_usb_full_speed_mode() ? MSG_DEVICE_FULL_SPEED : MSG_DEVICE_LOW_SPEED );
   v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
   sprintf( (char *)pcStringToPrint, "%s"
            "Supported interface(s): %u",
            Is_device_supports_remote_wakeup() ? MSG_REMOTE_WAKEUP_OK : MSG_REMOTE_WAKEUP_KO,
            Get_nb_supported_interface() );
   v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );

   for (i = 0; i < Get_nb_supported_interface(); i++)
   {
      sprintf( (char *)pcStringToPrint, "\r\nInterface nb: %u, AltS nb: %u, Class: 0x%.2X,"
               " SubClass: 0x%.2X, Protocol: 0x%.2X\r\n" "\tAssociated Ep Nbrs:",
               Get_interface_number(i), Get_altset_nb(i), Get_class(i),
               Get_subclass(i), Get_protocol(i) );
      v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );

      if (Get_nb_ep(i))
      {
         for (j = 0; j < Get_nb_ep(i); j++)
         {
            sprintf( (char *)pcStringToPrint, " %u", (U16)Get_ep_nbr(i, j) );
            v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
         }
      }
      else
      {
         v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)"None" );
      }
   }

   vPortFree( pcStringToPrint );

   v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)CRLF );
#else
   v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE );
#endif
   return( SHELL_EXECSTATUS_OK );
}