Index: lab2/lab2.c
===================================================================
--- lab2/lab2.c	(revision 4)
+++ lab2/lab2.c	(revision 5)
@@ -52,7 +52,11 @@
 
 int(timer_test_time_base)(uint8_t timer, uint32_t freq) {
 
-  if(timer_set_frequency(timer, freq)==1){                      //tests for error
+  if(timer<0|timer>2){                                  //tests for error in timer selection
+    printf("Error selecting timer\n");
+    return 1;
+  }
+  if(timer_set_frequency(timer, freq)==1){              //tests for error
     printf("Error testing time base\n");
     return 1;
   }
@@ -64,13 +68,18 @@
   uint8_t irq_set;
   message msg;
 
+  if(timer_set_frequency(0, 60)==1){                    //tests for error
+    printf("Error setting frequency\n");
+    return 1;
+  }
+
   if(timer_subscribe_int(&irq_set)==1){
     printf("Error subscribing int\n");
     return 1;
   }
 
-  while(count/60.0<time){                                     //looping until counter reaches the same value as time
-    if ((r = driver_receive(ANY, &msg, &ipc_status))!=0){ 
+  while(count/sys_hz()<time){                                     //looping until counter reaches the same value as time
+    if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ 
       printf("driver_receive failed with: %d",r);
       continue;
     }
@@ -81,7 +90,7 @@
                   
                   timer_int_handler();
 
-                  if((count%60)==0){
+                  if((count%sys_hz())==0){
                     timer_print_elapsed_time();                 //prints message each second;
                   }
                 }
@@ -91,7 +100,7 @@
         }
     } 
     else {                                                      //received a standard message, not a notification
-                                                                //no standard messages expected: do nothing
+      //no standard messages expected: do nothing
     }
   }
   
Index: lab2/timer.c
===================================================================
--- lab2/timer.c	(revision 4)
+++ lab2/timer.c	(revision 5)
@@ -9,7 +9,12 @@
 int hook_id = TIMER0_IRQ;
 
 int (timer_set_frequency)(uint8_t timer, uint32_t freq) {
-  // freq=TIMER_FREQ/div, where TIMER_FREQ is the frequency of the clock and div os the value loaded nittially in the timer
+
+    if(freq<19){
+        return 1;
+    }
+
+    //freq=TIMER_FREQ/div, where TIMER_FREQ is the frequency of the clock and div os the value loaded nittially in the timer
     uint16_t div = (TIMER_FREQ /freq);
 
     uint8_t msb, lsb;
@@ -19,7 +24,7 @@
 
     uint8_t st;
 
-    if(timer_get_conf(timer,&st)!=0){
+    if(timer_get_conf(timer,&st)==1){
         printf("Error getting conf in frequency set\n");
         return 1;
     }
@@ -30,7 +35,7 @@
     else
     {
         if(timer==0){
-            st= ((st & 0x0F)|TIMER_LSB_MSB|TIMER_SEL0);               //The mask 0x0f is used so that the 4 LSBs are not changed
+            st= ((st & 0x0F)|TIMER_LSB_MSB|TIMER_SEL0);             //The mask 0x0F is used so that the 4 LSBs are not changed
             sys_outb(TIMER_CTRL,st);                                //Sends control word to program the timer
             sys_outb(TIMER_0,lsb);
             sys_outb(TIMER_0,msb);                                  //Both these functions program the timer
@@ -74,25 +79,25 @@
 
 int (timer_get_conf)(uint8_t timer, uint8_t *st) {
 
-    uint8_t read_back = TIMER_RB_CMD | TIMER_RB_COUNT_ | TIMER_RB_SEL(timer); //forming the read-back command (TIMER_RB_CMD (bit 7 and 6)
+    uint8_t read_back = (TIMER_RB_CMD | TIMER_RB_COUNT_ | TIMER_RB_SEL(timer)); //forming the read-back command (TIMER_RB_CMD (bit 7 and 6)
                                                                                 //TIMER_RB_COUNT (BIT 5) and TIMER_RB_SEL (bit timer+1)
 
-    if (sys_outb(TIMER_CTRL, read_back)!=1) {                            //testing for an error
+    if (sys_outb(TIMER_CTRL, read_back)==0) {                            //testing for an error
         switch (timer) {
             case 0:
-                if (util_sys_inb(TIMER_0, st)!=0) {               //tests if TIMER_0 was chosen
+                if (util_sys_inb(TIMER_0, st)==1) {               //tests if TIMER_0 was chosen
                     printf("Error selecting Timer 0\n");
                     return 1;
                 }
                 break;
             case 1:
-                if (util_sys_inb(TIMER_1, st)!=0) {               //tests if TIMER_1 was chosen
+                if (util_sys_inb(TIMER_1, st)==1) {               //tests if TIMER_1 was chosen
                     printf("Error selecting Timer 1\n");
                     return 1;
                 }
                 break;
             case 2:
-                if (util_sys_inb(TIMER_2, st)!=0) {               //tests if TIMER_2 was chosen
+                if (util_sys_inb(TIMER_2, st)==1) {               //tests if TIMER_2 was chosen
                     printf("Error selecting Timer 2\n");
                     return 1;
                 }
@@ -103,6 +108,7 @@
         }
         return 0;
     }
+    
     printf("Error in get config\n");
     return 1;
 }
@@ -109,16 +115,20 @@
 
 int(timer_display_conf)(uint8_t timer, uint8_t st, enum timer_status_field field){
 
-    if(timer < 0 | timer > 2)                           //tests if the timer has a correct value
-        return  1;
+    if(timer<0|timer>2){                                //tests for error in timer selection
+        printf("Error selecting timer\n");
+        return 1;
+    }
 
     union timer_status_field_val config;                //create union (needed for the function at the end)
     uint8_t aux;
     aux=st;
+
     switch(field){
         case tsf_all:
             config.byte=aux;
             break;
+
         case tsf_initial:                               //Checking init_mode (mask -> 0x30)
             if((aux & 0x30)==TIMER_LSB){                //if 0x10
                 config.in_mode=LSB_only;
@@ -135,23 +145,24 @@
                 return 1;
             }
             break;
+
         case tsf_mode:                                  //Checking count_mode (mask -> 0x0E)
             if((aux & 0x0E)==0){                        //if 0x00
                 config.count_mode=0;
             }
-            else if((aux & 0x0E)==2){
+            else if((aux & 0x0E)==2){                   //if 0x02
                 config.count_mode=1;
             }
-            else if((aux & 0x0E)==4|(aux & 0x0E)==12){
+            else if((aux & 0x0E)==4|(aux & 0x0E)==12){  //if 0x04 or 0x0C
                 config.count_mode=2;
             }
-            else if((aux & 0x0E)==6|(aux & 0x0E)==14){
+            else if((aux & 0x0E)==6|(aux & 0x0E)==14){  //if 0x06 or 0x0E
                 config.count_mode=3;
             }
-            else if((aux & 0x0E)==8){
+            else if((aux & 0x0E)==8){                   //if 0x08
                 config.count_mode=4;
             }
-            else if((aux & 0x0E)==10){
+            else if((aux & 0x0E)==10){                  //if 0x0A
                 config.count_mode=5;
             }
             else{
@@ -159,9 +170,10 @@
                 return 1;
             }
             break;
+
         case tsf_base:                                  //Checking bcd (mask -> 0x01)
             if((aux & 0x01)== TIMER_BCD){
-                config.bcd = true;                    //if the last bit is 1, it's bcd
+                config.bcd = true;                      //if the last bit is 1, it's bcd
             }
             else if((aux & 0x01)==TIMER_BIN){
                 config.bcd = false;                     //if the last bit is 0, it's binary
@@ -171,17 +183,16 @@
                 return 1;
             }
             break;
+
         default:
             return 1;
 
     }
 
-    if(timer_print_config(timer, field, config)!=0){
+    if(timer_print_config(timer, field, config)==1){   //function that prints the result
         printf("Error printing\n");
-        return 1;           //function that prints the result
+        return 1;                                           
     }
-        
 
     return 0;
-
 }
Index: lab2/utils.c
===================================================================
--- lab2/utils.c	(revision 4)
+++ lab2/utils.c	(revision 5)
@@ -17,13 +17,13 @@
 
 int (util_sys_inb)(int port, uint8_t *value) { //transform 8 bit into 32 bit
 
-  uint32_t new_val;             //initializing 32 bit variable
+  uint32_t new_val;                           //initializing 32 bit variable
 
-  if(sys_inb(port,&new_val)!=0){   //verifies if there is an error
+  if(sys_inb(port,&new_val)!=0){              //verifies if there is an error
       printf("Error in util_sys_inb\n");
       return 1;
   }
-  *value=new_val & 0xFF;        // dereferencing "value"
+  *value=new_val & 0xFF;                      //dereferencing "value"
 
   return 0;
 }
