void priority_switch_command_handler()
{
    // register the command
    MessageEnvelope * kcd_msg = (MessageEnvelope *)request_memory_block();
    kcd_msg->type = TYPE_REGISTER_CMD;
    kcd_msg->msg[0] = '%';
    kcd_msg->msg[1] = 'C';
    send_message(KCD_PID, kcd_msg);

    // loop waiting for messages from the KCD
    while (1) {
        MessageEnvelope * cmd = receive_message(NULL);

        if (cmd->msg[0] != '%' || cmd->msg[1] != 'C' || cmd->msg[2] != ' ') {
            str_copy((BYTE *)"Command was invalid\n\r", (BYTE *)cmd->msg);
            send_message(CRT_PID, cmd);
            continue;
        }

        UINT32 i;

        // find the space in the argument and put a null there so ascii_to_int
        // can parse the two numbers independently
        for (i = 3; cmd->msg[i] != NULL; i ++) {
            if (cmd->msg[i] == ' ') {
                cmd->msg[i] = NULL;
                break;
            }
        }

        SINT32 pid = ascii_to_int(&cmd->msg[3]);
        SINT32 priority = ascii_to_int(&cmd->msg[i + 1]);

        if (pid == -1) {
            str_copy((BYTE *)"PID was invalid\n\r", (BYTE *)cmd->msg);
            send_message(CRT_PID, cmd);
            continue;
        }

        if (priority == -1) {
            str_copy((BYTE *)"Priority was invalid\n\r", (BYTE *)cmd->msg);
            send_message(CRT_PID, cmd);
            continue;
        }

        //rtx_dbug_outs_int("PID: ", pid);
        //rtx_dbug_outs_int("Priority: ", priority);

        int success = set_process_priority(pid, priority);

        if (success != 0) {
            str_copy((BYTE *)"Cannot change that process to that priority\n\r", (BYTE *)cmd->msg);
            send_message(CRT_PID, cmd);
            continue;
        }

        str_copy((BYTE *)"Priority change successful\n\r", (BYTE *)cmd->msg);
        send_message(CRT_PID, cmd);
    }
}
Example #2
0
int main(int argc, char *argv[])
{
	wait_pager(0);
	char *parent_of_all;
	char pidbuf[10];

	//	printf("New task started: %d\n", __raw_tid(getpid()));

	/* Convert current pid to string */
	sprintf(pidbuf, "%d", getpid());

	if (strcmp(argv[0], "FIRST ARG") ||
	    strcmp(argv[1], "SECOND ARG") ||
	    strcmp(argv[2], "THIRD ARG") ||
	    strcmp(argv[3], "FOURTH ARG")) {
		printf("EXECVE TEST         -- FAILED --\n");
		goto out;
	}

	// printf("New task continues: %d\n", __raw_tid(getpid()));

	/* Get parent of all pid as a string from environment */
	parent_of_all = getenv("parent_of_all");
	pagerid = ascii_to_int(getenv("pagerid"));

	/* Compare two pid strings. We use strings because we dont have atoi() */
	if (!strcmp(pidbuf, parent_of_all)) {
		printf("EXECVE TEST         -- PASSED --\n");
		printf("\nThread (%x): Continues to sync with the pager...\n\n", __raw_tid(getpid()));
		while (1)
			wait_pager(pagerid);
	}
out:
	_exit(0);
}
Example #3
0
void set_time_from_string(char* timeString)
{
    struct tm newTime;
    char buffer[5];
    uint8_t i;

    for (i=0; i<4; i++) buffer[i] = timeString[i];
    buffer[4] = 0;
    newTime.tm_year = ascii_to_int(buffer)-1900;
    for (i=0; i<2; i++) buffer[i] = timeString[i+5];
    buffer[2] = 0;
    newTime.tm_mon = ascii_to_int(buffer)-1;
    for (i=0; i<2; i++) buffer[i] = timeString[i+8];
    newTime.tm_mday = ascii_to_int(buffer);
    for (i=0; i<2; i++) buffer[i] = timeString[i+11];
    newTime.tm_hour = ascii_to_int(buffer);
    for (i=0; i<2; i++) buffer[i] = timeString[i+14];
    newTime.tm_min = ascii_to_int(buffer);
    for (i=0; i<2; i++) buffer[i] = timeString[i+17];
    newTime.tm_sec = ascii_to_int(buffer);

    set_seconds_count((uint32_t)mktime(&newTime));
}
Example #4
0
/*
 * see <linux-kernel-source>/Documentation/usb/usbmon.txt and 
 * <linux-kernel-source>/drivers/usb/mon/mon_text.c for urb string 
 * format description
 */
static int
usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
{
	/* see:
	* /usr/src/linux/Documentation/usb/usbmon.txt 
	* for message format
	*/
	struct pcap_usb_linux *handlep = handle->private;
	unsigned timestamp;
	int tag, cnt, ep_num, dev_addr, dummy, ret, urb_len, data_len;
	char etype, pipeid1, pipeid2, status[16], urb_tag, line[USB_LINE_LEN];
	char *string = line;
	u_char * rawdata = handle->buffer;
	struct pcap_pkthdr pkth;
	pcap_usb_header* uhdr = (pcap_usb_header*)handle->buffer;
	u_char urb_transfer=0;
	int incoming=0;

	/* ignore interrupt system call errors */
	do {
		ret = read(handle->fd, line, USB_LINE_LEN - 1);
		if (handle->break_loop)
		{
			handle->break_loop = 0;
			return -2;
		}
	} while ((ret == -1) && (errno == EINTR));
	if (ret < 0)
	{
		if (errno == EAGAIN)
			return 0;	/* no data there */

		snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
		    "Can't read from fd %d: %s", handle->fd, strerror(errno));
		return -1;
	}

	/* read urb header; %n argument may increment return value, but it's 
	* not mandatory, so does not count on it*/
	string[ret] = 0;
	ret = sscanf(string, "%x %d %c %c%c:%d:%d %s%n", &tag, &timestamp, &etype, 
		&pipeid1, &pipeid2, &dev_addr, &ep_num, status, 
		&cnt);
	if (ret < 8)
	{
		snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
		    "Can't parse USB bus message '%s', too few tokens (expected 8 got %d)",
		    string, ret);
		return -1;
	}
	uhdr->id = tag;
	uhdr->device_address = dev_addr;
	uhdr->bus_id = handlep->bus_index;
	uhdr->status = 0;
	string += cnt;

	/* don't use usbmon provided timestamp, since it have low precision*/
	if (gettimeofday(&pkth.ts, NULL) < 0) 
	{
		snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
			"Can't get timestamp for message '%s' %d:%s", 
			string, errno, strerror(errno));
		return -1;
	}
	uhdr->ts_sec = pkth.ts.tv_sec;
	uhdr->ts_usec = pkth.ts.tv_usec;

	/* parse endpoint information */
	if (pipeid1 == 'C')
		urb_transfer = URB_CONTROL;
	else if (pipeid1 == 'Z')
		urb_transfer = URB_ISOCHRONOUS;
	else if (pipeid1 == 'I')
		urb_transfer = URB_INTERRUPT;
	else if (pipeid1 == 'B')
		urb_transfer = URB_BULK;
	if (pipeid2 == 'i') {
		ep_num |= URB_TRANSFER_IN;
		incoming = 1;
	}
	if (etype == 'C')
		incoming = !incoming;

	/* direction check*/
	if (incoming)
	{
		if (handle->direction == PCAP_D_OUT)
			return 0;
	}
	else
		if (handle->direction == PCAP_D_IN)
			return 0;
	uhdr->event_type = etype;
	uhdr->transfer_type = urb_transfer;
	uhdr->endpoint_number = ep_num;
	pkth.caplen = sizeof(pcap_usb_header);
	rawdata += sizeof(pcap_usb_header);

	/* check if this is a setup packet */
	ret = sscanf(status, "%d", &dummy);
	if (ret != 1)
	{
		/* this a setup packet, setup data can be filled with underscore if
		* usbmon has not been able to read them, so we must parse this fields as 
		* strings */
		pcap_usb_setup* shdr;
		char str1[3], str2[3], str3[5], str4[5], str5[5];
		ret = sscanf(string, "%s %s %s %s %s%n", str1, str2, str3, str4, 
		str5, &cnt);
		if (ret < 5)
		{
			snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
				"Can't parse USB bus message '%s', too few tokens (expected 5 got %d)",
				string, ret);
			return -1;
		}
		string += cnt;

		/* try to convert to corresponding integer */
		shdr = &uhdr->setup;
		shdr->bmRequestType = strtoul(str1, 0, 16);
		shdr->bRequest = strtoul(str2, 0, 16);
		shdr->wValue = htols(strtoul(str3, 0, 16));
		shdr->wIndex = htols(strtoul(str4, 0, 16));
		shdr->wLength = htols(strtoul(str5, 0, 16));

		uhdr->setup_flag = 0;
	}
	else 
		uhdr->setup_flag = 1;

	/* read urb data */
	ret = sscanf(string, " %d%n", &urb_len, &cnt);
	if (ret < 1)
	{
		snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
		  "Can't parse urb length from '%s'", string);
		return -1;
	}
	string += cnt;

	/* urb tag is not present if urb length is 0, so we can stop here 
	 * text parsing */
	pkth.len = urb_len+pkth.caplen;
	uhdr->urb_len = urb_len;
	uhdr->data_flag = 1;
	data_len = 0;
	if (uhdr->urb_len == 0)
		goto got;

	/* check for data presence; data is present if and only if urb tag is '=' */
	if (sscanf(string, " %c", &urb_tag) != 1)
	{
		snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
			"Can't parse urb tag from '%s'", string);
		return -1;
	}

	if (urb_tag != '=') 
		goto got;

	/* skip urb tag and following space */
	string += 3;

	/* if we reach this point we got some urb data*/
	uhdr->data_flag = 0;

	/* read all urb data; if urb length is greater then the usbmon internal 
	 * buffer length used by the kernel to spool the URB, we get only
	 * a partial information.
	 * At least until linux 2.6.17 there is no way to set usbmon intenal buffer
	 * length and default value is 130. */
	while ((string[0] != 0) && (string[1] != 0) && (pkth.caplen < handle->snapshot))
	{
		rawdata[0] = ascii_to_int(string[0]) * 16 + ascii_to_int(string[1]);
		rawdata++;
		string+=2;
		if (string[0] == ' ')
			string++;
		pkth.caplen++;
		data_len++;
	}

got:
	uhdr->data_len = data_len;
	if (pkth.caplen > handle->snapshot)
		pkth.caplen = handle->snapshot;

	if (handle->fcode.bf_insns == NULL ||
	    bpf_filter(handle->fcode.bf_insns, handle->buffer,
	      pkth.len, pkth.caplen)) {
		handlep->packets_read++;
		callback(user, &pkth, handle->buffer);
		return 1;
	}
	return 0;	/* didn't pass filter */
}
Example #5
0
// Parser fuer Komandoeingabe
// Syntax: <Befehl><Geraet>:[Subbefehl]<Parameter>
// Befehl "!" setzt Parameter
// Befehl "?" liest Parameter
// Ausgaben des mc werden mit "#" eingeleitet
// Gerät "An" ADC An (n=0..7)
// Gerät "S" Systemzeit, "Ln" LEDn, "V" Version
// !A0:1 --> ADC0 gibt im Sekundenrythmus Werte aus; !A0:0 stopped den ADC0
// !L2:t100 --> LED2 blinkt im 100ms Rhytmus
void parser(unsigned char* p_p)
{
   switch(*p_p) {

      // Parameter setzen mit "!"
      case '!':
      switch(*(++p_p)){    

         case 'A':                   // ADC Analog Digitalwandler *******************************
	 ++p_p;
	 if('0'<=*p_p && *p_p<='7'){                 // 0 <= n <=7
            ADMUX &= 0xF0;                           // MUX0..3 loeschen
            ADMUX |= (*p_p - 0x30);                  // AD-Wandler Nr. n (0..7) wählen
	    ++p_p;		                     // nächste Zeichen (:) ignorieren
            switch(*(++p_p)){
               case '0':
	       status_ADC='0';                       // ADC sperren
	       break;
               case '1':
               status_ADC='1';                       // ADC freigeben
               break;
	       default:
               buffer_write_s(put_bp, (unsigned char*)"#!:Error\n> ");
               beeps(100,2);
            }
	    buffer_write_s(put_bp, (unsigned char*)"#!:OK\n");
            beeps(100,1);
	 }
	 else{   
            buffer_write_s(put_bp, (unsigned char*)"#!:Error\n> ");
            beeps(100,2);
         }
	 break;                       // ende ADC

	 // LED setzen *********************************************
         case 'L':
           switch(*(++p_p)){
             case '2':                // LED2 -->
             ++p_p;                   // nächste Zeichen (:) ignorieren
             switch(*(++p_p)){

                case '0':
                PORTD &= ~(1<<PD6);   // LED2 aus
                status_LED2='0';
                break;

                case '1':
                PORTD |= 1<<PD6;      // LED2 an
                status_LED2='1';
                break;

                case 's':
                PORTD |= 1<<PD6;      // LED2 singleshot
                status_LED2='s';
                delay = ascii_to_int(++p_p);
                break;

                case 't':
                PORTD |= 1<<PD6;      // LED2 toggle
                status_LED2='t';
                delay = ascii_to_int(++p_p);
                break;

                default:
                buffer_write_s(put_bp, (unsigned char*)"#?:Error\n> ");
                beeps(100,2);
                break;
             }
             buffer_write_s(put_bp, (unsigned char*)"#!:OK\n> ");
             beeps(100,1);
	  }
	  break;
	  
	  // Systemzeit setzen *************************************
	  case 's':
          sekunden = ascii_to_int(++p_p);
          buffer_write_s(put_bp, (unsigned char*)"#!:OK\n> ");
          beeps(100,1);
          break;
          default:
          buffer_write_s(put_bp, (unsigned char*)"#: Error\n> ");
          beeps(100,2);
       }
       break;

       // Parameter abfragen
       case '?': switch(*(++p_p)){

	  // Systemzeit auslesen ***********************************
          case 's':
          buffer_write_s(put_bp, (unsigned char*)"#s: ");
	  unsigned char timestring[11];
          buffer_write_s(put_bp, int_to_ascii(sekunden, timestring));
          buffer_write_s(put_bp, (unsigned char*)"\n> ");
          beeps(100,1);
	  break;
             
	  // Soft- Hardwareversion auslesen
          case 'v':
          buffer_write_s(put_bp, (unsigned char*)"#v: ");
          buffer_write_s(put_bp, version);
          buffer_write_s(put_bp, (unsigned char*)"\n> ");
          beeps(100,1);
	  break;

	  // Hilfe ausgeben
	  case 'h':
          buffer_write_s(put_bp, (unsigned char*)"#h: <command><device><number>:<subcommand>[parameter]\n> ");
          beeps(100,1);
	  break;

	  default:
          buffer_write_s(put_bp, (unsigned char*)"#: Error\n> ");
          beeps(100,2);
       }
       break;

       case '0': buffer_write_s(put_bp, (unsigned char*)"Taste 0 wurde gedrückt - LED2 1000ms\n> ");
       beep(100);
       buffer_write_s(put_bp, (unsigned char*)"Ausgabe über Interruptserviceroutine\n> ");
       break;
       
       case '1': buffer_write_s(put_bp, (unsigned char*)"Taste 1 wurde gedrückt - LED2 100ms\n> ");
       beep(100);
       delay=100;
       break;
       
       // Hilfe ausgeben (mit ?h zusammenführen)
       case 'h':
       case 0:
       buffer_write_s(put_bp, (unsigned char*)"#h: <command><device><number>:<subcommand>[parameter]\n> ");
       beeps(100,2);
       break;
       
       default:
       buffer_write_s(put_bp, (unsigned char*)"#: unbekantes Zeichen: ");
       buffer_write(put_bp,*p_p);
       buffer_write_s(put_bp, (unsigned char*)"\n");
       beeps(100,2);
    }
}