Ejemplo n.º 1
0
void start_d()
{
    while (1)
    {
        append_result();
        MsgEnv *env;
        switch (append_i)
        {
            case 5:
                break;
            case 7:
                env = receive_message();
                release_msg_env(env);
                utest_assert(0, "D should not run for a second time");
                break;
            default:
                trace_uint(ALWAYS,"append_i ", append_i);
                utest_assert(0, "d process append_i not recongized");
                break;
        }
        release_processor();
    }
}
Ejemplo n.º 2
0
void proc6(void) {
	// OUTPUT PROCESS - gathers data from all the other processes and outputs to //uart0
	while (1) {
		int counter = 0;
		int total	= 5;
		int i = 0;
		int asciioffset = 48;
		
		//uart0_put_string("G021_test: START\n\r");
		//uart0_put_string("G021_test: total ");//uart0_put_char(total+asciioffset);//uart0_put_string(" tests\n\r");
		for (i = 1; i < total+1; i++) {
			//uart0_put_string("G021_test: test ");
			//uart0_put_char(i+asciioffset);
			
			if (is_process_blocked(i))
			{
				//uart0_put_string(" BLOCKED");
			}
			else
			{
				if (results[i] == 0) {
					//uart0_put_string(" FAIL");
				} else {
					//uart0_put_string(" OK");
					counter++;
				}
			}
			//uart0_put_string("\n\r");
		}
		//uart0_put_string("G021_test: ");//uart0_put_char(counter+asciioffset);//uart0_put_string("/");//uart0_put_char(total+asciioffset);//uart0_put_string(" tests OK\n\r");
		//uart0_put_string("G021_test: ");//uart0_put_char((total-counter)+asciioffset);//uart0_put_string("/");//uart0_put_char(total+asciioffset);//uart0_put_string(" tests FAIL\n\r");
		//uart0_put_string("G021_test: END\n\r");
		
		release_processor();
	}
}
Ejemplo n.º 3
0
/**
 * @brief: a process that prints five uppercase letters
 *         and then yields the cpu.
 */
void proc1(void)
{
	int i = 0;
	int ret_val = 10;
	while (1) {
		if ( i != 0 && i%5 == 0 ) {
			print_debug("\n\r");
	
			ret_val = release_processor();
			
			print_debug("Process 1 completed!\r\n");

			if (ret_val == -1) {
				print_debug("G021_test: test 1 FAIL\r\n");
				test_results[0] = 0;
			} else {
				print_debug("G021_test: test 1 OK\r\n");
			}
		}
		
		print_char_debug('A' + i%26);
		i++;
	}
}
Ejemplo n.º 4
0
void *s_request_memory_block()
{
    void *allocMem;
    mmu_blockdesc_t *b;
    if (!mmu_can_alloc_mem()) {
			current_process->state = BLOCKED;
			release_processor();
    }
    if (table.block->next) {
        allocMem = table.block->start;
        b = table.block;
        table.block = b->next;
        b->next = NULL;
    } else {
        allocMem = table.block->start;
        table.block->start += MMU_BLOCK_SIZE;

        if (table.block->start >= table.block->end) {
            table.block = NULL;
        }
    }
    set_bit(table.bitVector, getBitFromAddress(allocMem), 1);
    return allocMem;
}
/**
 * @brief: a process that prints 5x6 uppercase letters
 *         and then yields the cpu.
 */
void proc1(void)
{
	int i = 0;
	int ret_val = 10;
	int x = 0;

	while ( 1) {
		if ( i != 0 && i%5 == 0 ) {
			uart1_put_string("\n\r");
			
			if ( i%30 == 0 ) {
				ret_val = release_processor();
#ifdef DEBUG_0
				printf("proc1: ret_val=%d\n", ret_val);
			
#endif /* DEBUG_0 */
			}
			for ( x = 0; x < 500000; x++); // some artifical delay
		}
		uart1_put_char('A' + i%26);
		i++;
		
	}
}
Ejemplo n.º 6
0
void test_proc_p1_a_6(void) {
    while (1) {
        uart1_put_string("proc6: \n\r");
        release_processor();
    }
}
Ejemplo n.º 7
0
void proc6(void)
{
	while ( 1 ) {
		release_processor();
	}
}
Ejemplo n.º 8
0
void procC()
{
	//create local message queue to store msg envs in FIFO order
	MsgEnvQ *msgQueue = (MsgEnvQ*)MsgEnvQ_create();

	//initialize msg env pointers to keep track of messages
	ps("Proc C started!");
	MsgEnv *msg_env;
	while(1)
	{
		//while (MsgEnvQ_size(CURRENT_PROCESS->rcv_msg_queue) > 0 || MsgEnvQ_size(msgQueue) == 0)
		while(MsgEnvQ_size(msgQueue) == 0)
		{
			msg_env = (MsgEnv*)receive_message();
			MsgEnvQ_enqueue(msgQueue, msg_env);
		}

		msg_env = (MsgEnv*)MsgEnvQ_dequeue(msgQueue);

		if(msg_env->msg_type == COUNT_REPORT)
		{
			if( (atoi(msg_env->data)) % 20 == 0)
			//if( (msg_env->time_delay) % 20 == 0)
			{
				// BBJ. Don't use memcpy etc anymore, I think this is causing memory problems in OS since it crashes like 5-6 minutes in!!
				//char tempData[20] = "\nProcess C\0";
				//memcpy(msg_env->data,tempData,strlen(tempData)+1);
				sprintf(msg_env->data, "\nProcess C\n");
				send_console_chars(msg_env);

				//wait for output confirmation with 'DISPLAY_ACK' msg type
				while(1)
				{
					msg_env = (MsgEnv*)receive_message();
					if (msg_env->msg_type == DISPLAY_ACK)
					{
						if(request_delay(3, WAKEUP10, msg_env)!= SUCCESS)
						{
							ps("requesting delay for Process C went wrong");
						}
						while(1){
							msg_env = receive_message();
							if(msg_env->msg_type==WAKEUP10)
							{
								break;
							}else if(msg_env->msg_type == COUNT_REPORT){
								MsgEnvQ_enqueue(msgQueue, msg_env);
							}else{
								release_message_env(msg_env);
							}
						}
						break;
					}else if(msg_env->msg_type == COUNT_REPORT){
						//enqueue the msg env onto local msg queue if it originated from proc_A
						MsgEnvQ_enqueue(msgQueue, msg_env);
					}
					// random message. ignore
					else
						release_message_env(msg_env);
				}

			}
		}

		//deallocate message envelopes and release processor
        release_message_env(msg_env);

        if (MsgEnvQ_size(msgQueue) == 0) {
        	ps("Process C is releasing processor!");
        	release_processor();
        }
	}
}
Ejemplo n.º 9
0
Archivo: c.c Proyecto: Hassaan/rtx
void process_C()
{
    msg_env_queue_t* messageQueue = msg_env_queue_create();
    MsgEnv * timeout_msg = request_msg_env();
    while(1)
    {
        // setup variables that will be used by the process
        MsgEnv *deq_msg;
        // check if the process message queue is empty or not
        // if the queue is empty, then recieve a message env
        // and enqueue it!
        if(msg_env_queue_is_empty(messageQueue))
        {
            MsgEnv *received_msg = receive_message();
            msg_env_queue_enqueue(messageQueue, received_msg);
        }
        // dequeue a message env from the message queue
        deq_msg = msg_env_queue_dequeue(messageQueue);

        // check if the dequeued message type is a COUNT_REPORT
        if(deq_msg->msg_type == COUNT_REPORT)
        {
            //check if the message in the env is divisible by 20
            //if it is divisible, then continue into the if statement
            //otherwise release all envelopes and and yeild processor
            if (*((int *)(deq_msg->msg)) % 20 == 0)
            {
                //copys the 'Process C' string into the dequeued msg env
                rtx_strcpy(deq_msg->msg, "\r\nProcess C\r\n", 1024);
                //send the message env to the console for printing
                send_console_chars(deq_msg, 0);

                request_delay(1000, WAKEUP_10, timeout_msg);

                // "Go passive for 10 seconds" in the outline
                while(1)
                {
                    //recieve a message env
                    deq_msg = receive_message();
                    //if the recieved env is a type 'WAKEUP_10' then
                    //exit the while loop
                    //otherwise, enqueue the recieved message env back into the
                    //message env queue
                    if(deq_msg->msg_type == WAKEUP_10)
                    {
                        break;
                    }
                    else
                    {
                        msg_env_queue_enqueue(messageQueue, deq_msg);
                    }
                }
            }
            else
            {
                release_msg_env(deq_msg);
            }
        }
        else
        {
            trace(ERROR, "WTEDF");
            release_msg_env(deq_msg);
        }
        //release all the envelopes and yeild the processor
        release_processor();
    }
}
Ejemplo n.º 10
0
// *** PROCESS C *** PID 5
void ProcessC(){
    
    // init the local queue
    struct envQ* localQ = (struct envQ *) malloc (sizeof (struct envQ));
    if (localQ==NULL)
    {
        printf("localQ in Proc C not created properly");
        return;
    } // can we use the queue on the proc pcb instead?

    PCB* pC_pcb = convert_PID(5);
    
    msg_env* envC = request_msg_env();   
    // infinite loop of normal activity  
    while (1)
    {
        printf("A\n");
        int NUM =envC->msg_text[0];
        
        // if theres nothing the localQ, receive a message and enqueue it
        if (localQ->head == NULL)
        {
            envC = receive_message();    
            int H = env_ENQ(envC,localQ);
            if (H ==0)
               printf("Cannot enqueue on localQ");
        }
        
        // if there is something on the localQ, dequeue it
        else {
            envC = env_DEQ(localQ);
        }
            
        // if the message type is count report, and the value in msg_text is evenly divisible by 20, display "Process C"
        if (envC->msg_type == 2 && NUM % 20 == 0){
  
            // send the display message
            strcpy(envC->msg_text, "Process C\n\0");
            int W = send_console_chars(envC); // Returns confirmation of sending
            
            if (W==1)
            {
                // if it is the ack message request a delay of 10s, with wakeup code "wakeup10"
                int R = request_delay(10000, WAKEUP, envC); // request_delay returns an int
                if (R==0)
                   printf("Error with request_delay");
                   
                // wait for wakeup message
                envC = receive_message();
    
                // if its not the wakeup message put it on the local Q
                while (envC->msg_type != WAKEUP)
                {
                    envC = receive_message();
                    int XX = env_ENQ(envC,localQ);
                    if (XX==0)
                       printf("Error with putting message on local Q in Proc C");
                }   
            }
            else
               printf("Error sending 'Process C' to screen in Proc C");
            
        } 
        
        // deallocate envelopes
        int dun = release_msg_env(envC);
        if (dun==0)
           printf("ERROR IN DEALLOCATING ENVELOPE AT END OF Proc C");
        
        // release processor
        release_processor();
            
    }// end of infinite loop
}
void stress_a() {
	#ifdef _STRESS_DEBUG
	rtx_dbug_outs("Registering Stress Test A...\r\n");
	#endif
	
	struct MessageEnvelope * msg_rx;
	struct num_message * num_msg;
	struct MessageEnvelope * reg_cmd = (MessageEnvelope *)request_memory_block();
	reg_cmd->type = TYPE_REGISTER_CMD;
	str_copy((BYTE *) "%Z", (BYTE *)reg_cmd->msg);
	send_message(KCD_PID, reg_cmd);
		
	UINT32 num;
	
	while(1) {
		#ifdef _STRESS_DEBUG
		rtx_dbug_outs("Enter: Stress Test A - Loop 1\r\n");
		#endif
		
		msg_rx = (MessageEnvelope *)receive_message(NULL);
		
		#ifdef _STRESS_DEBUG
		rtx_dbug_outs("Stress Test A received a message in Loop 1\r\n");
		#endif		
		
		if(msg_rx->msg[0] == '%' && msg_rx->msg[1] == 'Z') {
			#ifdef _STRESS_DEBUG
			rtx_dbug_outs("Stress Test A received valid message - breaking out of loop\r\n");
			#endif
			release_memory_block((void *)msg_rx);
			break;
		}
		
		release_memory_block((void *)msg_rx);
	}
	
	num = 0;
	
	while(1) {
		#ifdef _STRESS_DEBUG
		rtx_dbug_outs("Enter: Stress Test A - Loop 2\r\n");
		#endif
		
		num_msg = (num_message *)request_memory_block();
		
		#ifdef _STRESS_DEBUG
		rtx_dbug_outs_int("Just got memory block for message num ", num);
		#endif
		
		num_msg->type = TYPE_COUNT_REPORT;
		num_msg->msg = num;
		send_message(STRESS_B_PID, num_msg);
		
		#ifdef _STRESS_DEBUG
		rtx_dbug_outs("Stress Test A sent message to Stress Test B\r\n");
		#endif
		
		num = num + 1;
		release_processor();
	
		#ifdef _STRESS_DEBUG
		rtx_dbug_outs("Stress Test A back from release processor\r\n");
		#endif
	}
}
void stress_c() {
	#ifdef _STRESS_DEBUG
	rtx_dbug_outs("Initializing: Stress Test C\r\n");
	#endif
	
	msgq_head = NULL;
	msgq_tail = NULL;
	
	struct num_message * msg_rx;
	struct num_message * msg_wake;
	struct MessageEnvelope * proc_c;
	struct num_message * hibernate;
		
	while(1) {
		#ifdef _STRESS_DEBUG
		rtx_dbug_outs("Enter: Stress Test C\r\n");
		#endif
		
		if(msgq_head == NULL) {
			// receive message
			msg_rx = (num_message *)receive_message(NULL);

			#ifdef _STRESS_DEBUG
			rtx_dbug_outs("Stress Test C received a message\r\n");
			#endif
		} else {
			// dequeue first message from local message queue
			msg_rx = msgq_head->env;
			msgq_head = msgq_head->next;

			if(msgq_head == NULL) {
				msgq_tail = NULL;
			}
			
			#ifdef _STRESS_DEBUG
			rtx_dbug_outs("Stress Test C dequeued a message\r\n");
			#endif
		}
		
		UINT32 type = msg_rx->type;
		UINT32 msg_data = msg_rx->msg;
		release_memory_block((void *)msg_rx);
		
		if(type == TYPE_COUNT_REPORT) {
			#ifdef _STRESS_DEBUG
			rtx_dbug_outs_int("Stress Test C got message ", msg_rx->msg);
			#endif
			
			if(msg_data%20 == 0) {
				proc_c = (MessageEnvelope *)request_memory_block();
				str_copy((BYTE *) "Process C\r\n", (BYTE *)proc_c->msg);
				send_message(CRT_PID, proc_c);

				#ifdef _STRESS_DEBUG
				rtx_dbug_outs("Stress Test C sent a message to CRT\r\n");
				#endif

				// hibernate for 10 seconds
				hibernate = (num_message *)request_memory_block();
				hibernate->type = TYPE_WAKEUP10;
				delayed_send(STRESS_C_PID, hibernate, 10000);
				
				while(1) {
					msg_wake = (num_message *)receive_message(NULL);
					if(msg_wake->type == TYPE_WAKEUP10) {
						break;
					} else {
						// enqueue the message into local queue
						enqueue_local_msg(msg_wake);
					}
				}
			}
		}
		
		release_memory_block((void *)hibernate);
		release_processor();
	}
}
Ejemplo n.º 13
0
void null_process() {
	while (1) {
		release_processor();
		//LOG("Running null process");
	}
}
Ejemplo n.º 14
0
VOID null_process(){
	while( 1 ){
		release_processor();
	}
}
Ejemplo n.º 15
0
void null process() {
		while(1) {
			release_processor();
		}
}
Ejemplo n.º 16
0
void null_proc(void) {
    uart1_put_string("Running null process\n\r");
    while(1) {
        release_processor();
    }
}
Ejemplo n.º 17
0
Archivo: c.c Proyecto: Hassaan/rtx
void process_C()
{
    msg_env_queue_t* messageQueue = msg_env_queue_create();
    while(1)
    {
        // setup variables that will be used by the process
        MsgEnv *deq_msg;
        MsgEnv *rec_msg = NULL;
        MsgEnv *rec_msg_2 = NULL;
        // check if the process message queue is empty or not
        // if the queue is empty, then recieve a message env
        // and enqueue it!
        if(msg_env_queue_is_empty(messageQueue))
        {
            MsgEnv *received_msg = receive_message();
            msg_env_queue_enqueue(messageQueue, received_msg);
        }
        // dequeue a message env from the message queue
        deq_msg = msg_env_queue_dequeue(messageQueue);

        // check if the dequeued message type is a COUNT_REPORT
        if(deq_msg->msg_type == COUNT_REPORT)
        {
            //check if the message in the env is divisible by 20
            //if it is divisible, then continue into the if statement
            //otherwise release all envelopes and and yeild processor
            if (*((int *)(deq_msg->msg)) % 20 == 0)
            {
                //copys the 'Process C' string into the dequeued msg env
                strcpy(deq_msg->msg, "\nProcess C\n");
                //send the message env to the console for printing
                send_console_chars(deq_msg);

                //loop forever (until 'breaked')
                while(1)
                {
                   //recieve a message
                   rec_msg = receive_message();
                   //check if the recieved message is a type "DISPLAY_ACK"
                   //if not then check if it is a type "COUNT_REPORT"
                   //and if that fails then we got a error and the RTX should report it!
                   if(rec_msg->msg_type == DISPLAY_ACK)
                   {
                       //check for an error case
                       if(request_delay(100, WAKEUP_10, rec_msg) != CODE_SUCCESS)
                       {
                       }
                       break;
                   }
                   else if (rec_msg->msg_type == COUNT_REPORT)
                   {
                       //enqueue the released env back into the message queue
                       msg_env_queue_enqueue(messageQueue, rec_msg);
                   }
                   else
                   {
                       assert(0);
                   }
                }

                // "Go passive for 10 seconds" in the outline
                while(1)
                {
                    //recieve a message env
                    rec_msg_2 = receive_message();
                    //if the recieved env is a type 'WAKEUP_10' then
                    //exit the while loop
                    //otherwise, enqueue the recieved message env back into the
                    //message env queue
                    if(rec_msg_2->msg_type == WAKEUP_10)
                    {
                        break;
                    }
                    else
                    {
                        msg_env_queue_enqueue(messageQueue, rec_msg_2);
                    }
                }
            }
        }
        //release all the envelopes and yeild the processor
        release_msg_env(rec_msg);
        release_msg_env(rec_msg_2);
        release_msg_env(deq_msg);
        release_processor();
    }
}
Ejemplo n.º 18
0
void CCI() 
{   
    
        //printf("You're in the CCI\n");
        int HH=0;
        int MM=0;
        int SS=0;
        int pri=0;
        int id=0;
        int U = 0;
        int dun = 0;
        
        msg_env* env = request_msg_env();
        msg_env* first = request_msg_env();
    
        while(1)
        {   
            // send the welcome message
/*
            if (first == NULL){
                terminate(1);
            }
            strcpy(first->msg_text, "Enter input for the CCI [s, ps, c [##:##:##], cd, ct, b, n [new_prio] [pid], e... , t]:\0");

            int F = 0;
            F = send_console_chars(first);

            if (F == 0){
                terminate(1);
            }
          
*/
         
            U = get_console_chars(env);   //keyboard input 
            //sleep(5);
            
            // only do this if there was input
            if (U==1)
            {
                env = receive_message();
                while (env->msg_type != CONSOLE_INPUT)
                {                
                        env = receive_message(); //***STOPS HERE TO WAIT FOR INPUT
                }
              
                char* input_txt = env->msg_text;
                
                // send envelope to Process A
                if (strcmp(input_txt,"s")==0) 
                { 
                    // printf("input was s\n");
                     //if the text in the field is "s"
                     env = request_msg_env(); //request an envelope
                     int Z =0;
                     Z = send_message(3,env); // send message to Process A
                }
                
                // display process status of all processes
                else if (strcmp(input_txt,"ps")==0) 
                { 
                    // printf("input was ps\n");
                     env = request_msg_env(); //request an envelope
                     int J=request_process_status(env);
                     if (J==0)
                        printf("Error with getting Process Status\n");                  
                }
                
                // allows time to be displayed on console and halts if getting ct
                else if (strcmp(input_txt,"cd")==0) 
                { 
                    // printf("input was cd\n");
                     
                    wallClockOut = 1;
                }
                else if (strcmp(input_txt,"ct")==0)
                {
                   // printf("input was ct\n");
                     wallClockOut = 0;
                }
    
                // set clock to any valid 24hr time
                else if (strncmp(input_txt,"c", 1)==0) 
                { 
                    // printf("input was c\n");
                     int HH = atoi(input_txt+2);
                     int MM = atoi(input_txt+5);
                     int SS = atoi(input_txt+8);
                     int R = clock_set(wallclock, HH, MM, SS);
                     
                     if (R==0)
                        printf("Error with setting clock in CCI\n");
                }
                
                // b displays past instances of send and receive messages
                else if (strcmp(input_txt,"b")==0) 
                { 
                   // printf("input was b\n");
                    env = request_msg_env(); //request an envelope
                    int U=get_trace_buffers(env);
                    
                    if (U==0)
                       printf("Error performing call on Trace Buffers\n");
               }
                
                // terminates RTX
                else if (strcmp(input_txt,"t")==0)
                { 
                    terminate(0);
                }
                
                // changes priority
                else if (strncmp(input_txt,"n",1)==0) 
                { 
                   //  printf("input was n\n");
                     int new_pri = atoi(input_txt+2);
                     int ID = atoi(input_txt+4);
                     int R = change_priority(new_pri, ID);
                     
                     if (R==0)
                            printf("Error with changing priority in CCI\n");
                }
                
                // echo the input back

                else if (strncmp(input_txt,"e", 1)==0) 
                { 
                   // printf("input was e\n");
                    env = request_msg_env(); //request an envelope
                    input_txt[0] = ' ';
                    strcat(input_txt, "\n\n");
                    strcpy(env->msg_text, "echo is: ");
                    strcpy(env->msg_text, input_txt);
                    int R = send_console_chars(env);
                    
                    if (R==0)
                            printf("Error with echoing to screen\n");
                }
                
                else 
                {
                     env = request_msg_env(); //request an envelope
                     char* temp = (char*) malloc(sizeof(SIZE));
                     sprintf(temp, "'%s' is not valid CCI input. Please try again.\n\n", input_txt);
                     strcpy(env->msg_text, temp);
                     int R = send_console_chars(env);
                    
                     if (R==0)
                         printf("Error with printing invalid input message\n");
                     
                    // printf("'%s' is not valid CCI input. Please try again.\n\n", input_txt);
                }

                
                dun = release_msg_env(env);

                if (dun == 0)
                {
                    env = request_msg_env(); //request an envelope
                    strcpy(env->msg_text, "ERROR IN DEALLOCATING ENVELOPE AT END OF CCI\n");
                    int R = send_console_chars(env);

                    if (R==0)
                          printf("Error with printing error message\n");
                }
                //else
                 //  printf("CCI finished, I think\n");
               
            }
         
        env = request_msg_env();
        
        // if there was no input
        release_processor();
        }
}
Ejemplo n.º 19
0
void procC()
{
	//create local message queue to store msg envs in FIFO order
	MsgEnvQ *msgQueue = (MsgEnvQ*)MsgEnvQ_create();

	//initialize msg env pointers to keep track of messages
	MsgEnv *msg_env;
	MsgEnv *msg_env2;
	//loop forever
	while(1)
	{
		//if the local msg queue is empty, then receive a message, enqueue it to avoid null pointers for deallocation

		if(msgQueue->head == NULL)
		{
			msg_env = (MsgEnv*)receive_message();
			MsgEnvQ_enqueue(msgQueue, msg_env);
		}

		//dequeue the first msg on the local msg queue
		msg_env = (MsgEnv*)MsgEnvQ_dequeue(msgQueue);


		//check if the dequeued msg type is 'COUNT_REPORT'
		if(msg_env->msg_type == COUNT_REPORT)
		{
			//the msg originated from proc_A, check if the data is divisible by 20
			//********check the line below plz*********
			if( (*(int*)msg_env->data) % 20 == 0)
			{
				//get a message envelope, set the data to 'Process C'
				//send it to display on the screen
				msg_env2 = (MsgEnv*)request_msg_env();
				char tempData[20] = "Process C";
				memcpy(msg_env2->data,tempData,strlen(tempData));
				//msg_env2->data = '\nProcess C\n';
				send_console_chars(msg_env2);

				//wait for output confirmation with 'DISPLAY_ACK' msg type
				while(1)
				{
					//receive message, possibly from send_console_chars or proc_B
					msg_env2 = (MsgEnv*)receive_message();

					//check for msg type 'env2LAY_ACK' or 'COUNT_REPORT'
					if (msg_env2->msg_type == DISPLAY_ACK)
					{
						//go passive for 10seconds, use the msg env we got back from send_console_chars
						int stat = request_delay(10000, WAKEUP10, msg_env2);
						//if the delay request fails
						//*****what do i do here?***** print error
						if(stat != SUCCESS)
						{
							printf("\nWHAT?!?! something went wrong with the delay request...\n");
						}

						//resume after getting a 10seconds delay request
						while(1)
						{
							//reuse the msg_env2 pointer to get returned msg env from delay request
							msg_env2 = (MsgEnv*)receive_message();

							//check if its msg_type is 'WAKEUP_10' or 'COUNT_REPORT'
							if(msg_env2->msg_type == WAKEUP10)
							{
								//get out of "waiting for delay finish' loop
								break;
							}else if(msg_env2->msg_type == COUNT_REPORT){
								//enqueue the msg env onto local msg queue if it originated from proc_A
								MsgEnvQ_enqueue(msgQueue, msg_env2);
							}else{
								//shouldn't get here, useless msg env to proc_c
							}
						}

						//get out of 'waiting for output confirmation' loop
						break;
					}else if(msg_env2->msg_type == COUNT_REPORT){
						//enqueue the msg env onto local msg queue if it originated from proc_A
						MsgEnvQ_enqueue(msgQueue, msg_env2);
					}else{
						//shouldn't get here, useless msg env to proc_c
					}
				}
			}
		}

		//deallocate message envelopes and release processor
        release_message_env(msg_env);
        release_message_env(msg_env2);
        release_processor();
	}
}
Ejemplo n.º 20
0
//Prints test results, 
//Test 1 sender (message can be accurately sent/recieved)
void proc1(void) {
    int failures = 0;
    int passes = 0;
    int destination = 2;
    int i;
    int all_tests_done = 0;
	  int pid = 1;

    int char_offset = 48;
    
    msgbuf *msg;

    crt_send_string("G007_test: START\n\r");
    
    //create a message to send to process 2
    msg = request_memory_block();
    msg->mtype = DEFAULT;
    msg->mtext[0] = MSG_TEXT_1;
    
    //send the message to process 2
    send_message(destination, msg);
    
    //mark tests 1 and 2 failed (process 2 will mark the tests passed later if sucessful)
    test_status[0] = TEST_FAILURE;
    test_status[1] = TEST_FAILURE;
    
    // wait for all the processes to finish
    set_process_priority(pid, LOWEST);
		
    while (!all_tests_done) {
        all_tests_done = 1;
        for (i = 0; i < NUM_TESTS; i++) {
            if (test_status[i] == TEST_PENDING) {
                all_tests_done = 0;
                release_processor();
            }
        }
      }

    // check statuses of all test processes
    for (i = 0; i < NUM_TESTS; i++) {
        crt_send_string("G007_test: test ");
        crt_send_char(i + 1 + 48);
        if (test_status[i] == TEST_SUCCESS) {
            crt_send_string(" OK\n\r");
            passes++;
        } else {
            crt_send_string(" FAIL\n\r");
            failures++;
        }
    }
    
    crt_send_string("G007_test: ");
    crt_send_char(passes + char_offset);
    crt_send_string("/");
    crt_send_char(NUM_TESTS + char_offset);
    crt_send_string(" tests OK\n\r");
    
    crt_send_string("G007_test: ");
    crt_send_char(failures + char_offset);
    crt_send_string("/");
    crt_send_char(NUM_TESTS + char_offset);
    crt_send_string(" tests FAIL\n\r");
    
    crt_send_string("G007_test: END\n\r");

#ifdef _DEBUG_HOTKEYS
    // Force this process to be BLOCKED_ON_MEMORY
      while (request_memory_block()) {
          //YOLO
				}
#endif // _DEBUG_HOTKEYS

    while (1) {
        release_processor();
    }
}