Example #1
0
File: cci.c Project: y36ding/Barby2
void cci_print(const char* print)
{
	sprintf(CCI_DISPLAY_ENV->data, "%s", print);
	int ret = send_console_chars(CCI_DISPLAY_ENV);
	if (ret==SUCCESS)
	{
            CCI_DISPLAY_ENV = receive_message();
	}
}
Example #2
0
File: pong.c Project: Hassaan/rtx
void print_board ()
{
    MsgEnv* msg = request_msg_env();
    rtx_strcpy(msg->msg, "\033[0;0H", 1024);
    send_console_chars(msg, FALSE);
    int r, c;
    for (r = 0; r < BOARD_ROWS; r++)
    {
        MsgEnv* message = request_msg_env();
        for (c = 0; c < BOARD_COLS; c++)
        {
            message->msg[c] = board[r][c];
        }
        message->msg[BOARD_COLS] = '\n';
        message->msg[BOARD_COLS+1] = '\r';
        message->msg[BOARD_COLS+2] = '\0';
        send_console_chars(message, FALSE);
    }
}
Example #3
0
int k_change_priority(int new_priority, int target_process_id) {
	if (new_priority > 3 || new_priority < 0) {
		MsgEnv *output;
		sprintf(output->msg, "KERNEL ERROR: Priority is out of bounds\n");			
		send_console_chars(output);
		return 1;
	} else {
		PCB * pcb = getPCB(target_process_id);
		pcb->priority = new_priority;
	}
	return 0;
}
Example #4
0
void clock_process() {

	envQ = MsgEnvQ_create();
	clockDisplayRequest = 0;
	clockTime = 0;
	timeoutEnv = (MsgEnv*) request_msg_env();
	displayEnv = (MsgEnv*) request_msg_env();

	checkBit = request_delay(1,WAKEUP10,timeoutEnv);
	if (checkBit!=SUCCESS) {
		ps("Message couldnt be sent to timer iproc from clock process");
	}


	while (1) {
		if (MsgEnvQ_is_empty(envQ))
			generalEnv = receive_message();
		else
			generalEnv = MsgEnvQ_dequeue(envQ);


		if (generalEnv->msg_type==DISPLAY_ACK) {
			displayEnv = generalEnv;
			continue;
		}

		//envelope from timing services
		if (generalEnv->msg_type == WAKEUP10) {
			//release_message_env(generalEnv);
			timeoutEnv = generalEnv;
			checkBit = request_delay(1, WAKEUP10, timeoutEnv);
			if (checkBit != SUCCESS) {
				ps("Message couldnt be sent to timer iproc from clock process");
			}
			//86400 = 24hrs in secs
			clockTime++;//(int32_t)((clock_get_system_time()-ref)/10+offset)%SEC_IN_HR;
			if (clockDisplayRequest) {
				/*int hours = clockTime%3600;
				int mins = (clockTime - hours*60*60)%60;
				int secs = (clockTime - hours*60*60 - mins*60)%60;*/
				int hours = clockTime/3600;
				int mins = (clockTime%3600)/60;
				int secs = clockTime%60; // whatever is remainder is seconds

				sprintf(displayEnv->data,"\n%02i:%02i:%02i",hours,mins,secs);
				send_console_chars(displayEnv);
			}
		}
	}
	release_processor();
}
Example #5
0
File: utils.c Project: Hassaan/rtx
MsgEnv * print_ack(char * msg, MsgEnv* print_env, msg_env_queue_t *queue)
{
    rtx_strcpy(print_env->msg, msg, 1024);
    send_console_chars(print_env, TRUE);
    
    while (1)
    {
        MsgEnv *env = receive_message();
        if (env->msg_type == DISPLAY_ACK)
        {
            return env;
        }
        else
        {
            msg_env_queue_enqueue(queue, env);
        }
    }
    return NULL;
}
Example #6
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();
	}
}
Example #7
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
}
Example #8
0
File: c.c Project: 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();
    }
}
Example #9
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();
        }
	}
}
Example #10
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();
        }
}
Example #11
0
File: c.c Project: 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();
    }
}