Project

General

Profile

Revision 6

some more advances in func 1

View differences:

lab2/i8254.h
35 35
#define TIMER_LSB     BIT(4)                  /**< @brief Initialize Counter LSB only */
36 36
#define TIMER_MSB     BIT(5)                  /**< @brief Initialize Counter MSB only */
37 37
#define TIMER_LSB_MSB (TIMER_LSB | TIMER_MSB) /**< @brief Initialize LSB first and MSB afterwards */
38
#define TIMER_INMODE_MASK 0x30
39
#define TIMER_INMODE_POS  4
38 40

  
39 41
/* Operating mode: bits 3, 2 and 1 */
40 42

  
41 43
#define TIMER_SQR_WAVE (BIT(2) | BIT(1)) /**< @brief Mode 3: square wave generator */
42 44
#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
45
#define TIMER_MODE_MASK 0x0e             /**< @brief Mask for mode */
46
#define TIMER_MODE_POS  1                /**< @brief Position of smallest bit from mode */
43 47

  
44 48
/* Counting mode: bit 0 */
45 49

  
lab2/lab2.c
29 29
  return 0;
30 30
}
31 31

  
32
int(timer_test_read_config)(uint8_t timer, enum timer_status_field field) {
33
    /* To be implemented by the students */
34

  
32
int(timer_test_read_config)(uint8_t timer, enum timer_status_field field){
35 33
    uint8_t state = 0;
36 34
    if(timer_get_conf(timer, &state)) return 1;
37
    //printf("%x\n", state);
38

  
35
    if(timer_display_conf(timer, state, field)) return 1;
39 36
    return 0;
40 37
}
41 38

  
lab2/timer.c
41 41
        case 0: read_port = TIMER_0; break;
42 42
        case 1: read_port = TIMER_1; break;
43 43
        case 2: read_port = TIMER_2; break;
44
        default: return 1;      break;
44
        default: return 1;           break;
45 45
    }
46 46
    if(util_sys_inb(read_port, st)) return 1;
47 47
    return 0;
48 48
}
49 49

  
50
int (timer_display_conf)(uint8_t timer, uint8_t st,
51
    enum timer_status_field field) {
52
        /* To be implemented by the students */
53
        printf("%s is not yet implemented!\n", __func__);
54

  
55
        return 1;
50
int (timer_display_conf)(uint8_t timer, uint8_t st, enum timer_status_field field) {
51
    union timer_status_field_val conf;
52
    uint8_t in_mode;
53
    if(field == tsf_all || field == tsf_initial){
54
        in_mode = (st & TIMER_INMODE_MASK) >> TIMER_INMODE_POS;
55
        switch(in_mode){
56
            case 0: conf.in_mode = INVAL_val    ; break;
57
            case 1: conf.in_mode = LSB_only     ; break;
58
            case 2: conf.in_mode = MSB_only     ; break;
59
            case 3: conf.in_mode = MSB_after_LSB; break;
60
            default: return 1; break;
61
        }
62
        if(timer_print_config(timer, field, conf)) return 1;
56 63
    }
64
    if(field == tsf_all || field == tsf_mode){
65
        conf.count_mode = (st & TIMER_MODE_MASK)>>TIMER_MODE_POS;
66
        if(timer_print_config(timer, field, conf)) return 1;
67
    }
68
    if(field == tsf_all || field == tsf_base){
69
        conf.bcd = st & TIMER_BCD;
70
        if(timer_print_config(timer, field, conf)) return 1;
71
    }
72
    return 0;
73
}

Also available in: Unified diff