Exemplo n.º 1
0
void start_a()
{
    while (1)
    {
        append_result();
        MsgEnv *env;
        switch(append_i)
        {
            case 1:
                env = receive_message();
                release_msg_env(env);
                break;
            case 10:
                trace(ALWAYS,"10");
                release_processor();
                break;
            default:
                trace_uint(ALWAYS,"append_i ", append_i);
                utest_assert(0, "b process append_i not recongized");
                break;
        }
        trace(ALWAYS,"end of loop");
        release_processor();
    }
}
Exemplo n.º 2
0
void start_c()
{
    while (1)
    {
        append_result();
        MsgEnv * env = receive_message();
        release_msg_env(env);
        utest_assert(0, "C should not run for a second time");
        release_processor();
    }
}
Exemplo n.º 3
0
void start_b()
{
    while (1)
    {
        append_result();
        MsgEnv *env;
        switch (append_i)
        {
            case 2:
                break;
            case 3:
                env = receive_message();
                release_msg_env(env);
                break;
            case 11:
                trace(ALWAYS,"doneee !!!");
                trace_ptr(ALWAYS,"rtx_strcmp ", rtx_strcmp);
                trace_ptr(ALWAYS,"result ", result);
                trace_ptr(ALWAYS,"expected ", expected);
                trace(ALWAYS,"result");
                trace(ALWAYS,result);
                trace(ALWAYS,"expected");
                trace(ALWAYS,expected);
                if (rtx_strcmp(result, expected) == 0)
                {
                    trace(ALWAYS,"YAY IT WORKS!!!");
                }
                utest_assert(rtx_strcmp(result, expected) == 0, "Result did not match expected sequence");
                if (rtx_strcmp(result, expected) != 0)
                {
                    trace_str(ALWAYS, "expected : ", expected);
                    trace_str(ALWAYS, "got      : ", result);
                }
                trace(ALWAYS,"test result timeee");

                utest_test_results();
                break;
            default:
                trace_uint(ALWAYS,"append_i ", append_i);
                utest_assert(0, "b process append_i not recongized");
                break;
        }
        release_processor();
    }
}
Exemplo n.º 4
0
void start_e()
{
    while (1)
    {
        append_result();
        MsgEnv *env;
        switch (append_i)
        {
            case 6:
                break;
            case 8:
                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();
    }
}
Exemplo n.º 5
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
}
Exemplo n.º 6
0
Arquivo: c.c Projeto: 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();
    }
}
Exemplo n.º 7
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();
        }
}
Exemplo n.º 8
0
Arquivo: pong.c Projeto: Hassaan/rtx
void update_board ()
{
    MsgEnv* message = receive_message();
    //release_msg_env(msg);
    init_pong();
    print_board();
    char cmd[100];
    void * params [11];
    request_delay(DELAY_AMOUNT, WAKEUP_10, message);
    while (1)
    {
        /*MsgEnv**/ message = receive_message();
        if (message->msg_type == CONSOLE_INPUT) // people moving their paddles
        {
            // Keys for left are A -> UP, S -> DOWN
            // Keys for right are K -> UP, L -> DOWN
            if ((message->msg[0] == 'a' || message->msg[0] == 'A') && (left_paddle_pos > 0))
            {
                board[left_paddle_pos+4][1] = ' ';
                left_paddle_pos--;
                board[left_paddle_pos][1] = 'M';
            }
            else if ((message->msg[0] == 's' || message->msg[0] == 'S') && (left_paddle_pos < BOARD_COLS-5))
            {
                board[left_paddle_pos+4][1] = ' ';
                left_paddle_pos++;
                board[left_paddle_pos][1] = 'M';
            }
            else if ((message->msg[0] == 'k' || message->msg[0] == 'K') && (right_paddle_pos > BOARD_COLS-5))
            {
                board[right_paddle_pos+4][BOARD_COLS-2] = ' ';
                right_paddle_pos--;
                board[right_paddle_pos][BOARD_COLS-2] = 'M';
            }
            else if ((message->msg[0] == 'l' || message->msg[0] == 'L') && (right_paddle_pos < 15))
            {
                board[right_paddle_pos+4][BOARD_COLS-2] = ' ';
                right_paddle_pos++;
                board[right_paddle_pos][BOARD_COLS-2] = 'M';
            }
            release_msg_env(message);
        }
        else if (message->msg_type == WAKEUP_10) // the timer, so update the ball;
        {
            if (ball_c == 0)
            {
                init_pong();// RIGHT PLAYER SCORED
                print_board();
                request_delay(DELAY_AMOUNT, WAKEUP_10, message);
                continue;
            }
            if (ball_c == BOARD_COLS-1)
            {
                init_pong();// LEFT PLAYER SCORED
                print_board();
                request_delay(DELAY_AMOUNT, WAKEUP_10, message);
                continue;
            }
            
            // bouncing checks
            if (ball_r == 1 || ball_r == BOARD_ROWS-2)
            {
                r_speed = r_speed * -1;
            }
            if (ball_c == 2 && board[ball_r+r_speed][1] == 'M')
            {
                c_speed = c_speed * -1;
            }
            else if (ball_c == BOARD_COLS-3 && board[ball_r+r_speed][BOARD_COLS-2] == 'M')
            {
                c_speed = c_speed * -1;
            }
            
            board[ball_r][ball_c] = ' ';
            ball_r += r_speed;
            ball_c += c_speed;
            board[ball_r][ball_c] = 'O';

            /*int prev_r = ball_r - r_speed;
            int prev_c = ball_c - c_speed;

            params[0] = &prev_r;
            params[1] = &prev_c;
            params[2] = &ball_r;
            params[3] = &ball_c;
            params[4] = NULL;
            rtx_sprintf(cmd, "\033[%d;%dH \033[%d;%dHO", params);
            MsgEnv* env = request_msg_env();
            env->msg = cmd;
            send_console_chars(env, FALSE);*/

            request_delay(DELAY_AMOUNT, WAKEUP_10, message);
        }        
        print_board();
    }
}
Exemplo n.º 9
0
Arquivo: c.c Projeto: 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();
    }
}