Project

General

Profile

Revision 4

All functions running, review code

View differences:

lab2.c
4 4
#include <stdbool.h>
5 5
#include <stdint.h>
6 6

  
7
extern unsigned int count;
7 8

  
8 9
int main(int argc, char *argv[]) {
9 10
  // sets the language of LCF messages (can be either EN-US or PT-PT)
......
29 30
  return 0;
30 31
}
31 32

  
33

  
32 34
int(timer_test_read_config)(uint8_t timer, enum timer_status_field field) {
33
  /* To be implemented by the students */
34
  printf("%s is not yet implemented!\n", __func__);
35 35

  
36
  return 1;
36
  uint8_t st;
37

  
38
  if(timer<0|timer>2){                      //tests for error in timer selection
39
    printf("Error selecting timer\n");
40
    return 1;
41
  }
42
  else if(timer_get_conf(timer, &st)==1){
43
    printf("Error getting configuration\n");
44
    return 1;
45
  }
46
  else if(timer_display_conf(timer, st, field)==1){
47
    printf("Error getting display configuration\n");
48
    return 1;
49
  }
50
  return 0;
37 51
}
38 52

  
39 53
int(timer_test_time_base)(uint8_t timer, uint32_t freq) {
40
  /* To be implemented by the students */
41
  printf("%s is not yet implemented!\n", __func__);
42 54

  
43
  return 1;
55
  if(timer_set_frequency(timer, freq)==1){                      //tests for error
56
    printf("Error testing time base\n");
57
    return 1;
58
  }
59
  return 0;
44 60
}
45 61

  
46 62
int(timer_test_int)(uint8_t time) {
47
  /* To be implemented by the students */
48
  printf("%s is not yet implemented!\n", __func__);
63
  int r, ipc_status;
64
  uint8_t irq_set;
65
  message msg;
49 66

  
50
  return 1;
67
  if(timer_subscribe_int(&irq_set)==1){
68
    printf("Error subscribing int\n");
69
    return 1;
70
  }
71

  
72
  while(count/60.0<time){                                     //looping until counter reaches the same value as time
73
    if ((r = driver_receive(ANY, &msg, &ipc_status))!=0){ 
74
      printf("driver_receive failed with: %d",r);
75
      continue;
76
    }
77
    if (is_ipc_notify(ipc_status)){                             //received notification
78
      switch (_ENDPOINT_P(msg.m_source)){
79
        case HARDWARE:                                          //hardware interrupt notification				
80
                if (msg.m_notify.interrupts &irq_set){          // subscribed interrupt
81
                  
82
                  timer_int_handler();
83

  
84
                  if((count%60)==0){
85
                    timer_print_elapsed_time();                 //prints message each second;
86
                  }
87
                }
88
               break;
89
        default:
90
              break;                                            //no other notifications expected: do nothing	
91
        }
92
    } 
93
    else {                                                      //received a standard message, not a notification
94
                                                                //no standard messages expected: do nothing
95
    }
96
  }
97
  
98
  if(timer_unsubscribe_int()==1){
99
    printf("Error unsubscribing int\n");
100
    return 1;
101
  }
102
  return 0;
51 103
}

Also available in: Unified diff