Project

General

Profile

Revision 16

fixed stuff

View differences:

lab2/i8254.h
44 44
#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
45 45
#define TIMER_MODE_MASK 0x0E             /**< @brief Mask for mode */
46 46
#define TIMER_MODE_POS  1                /**< @brief Position of smallest bit from mode */
47
#define TIMER_MODE_RED2 0x03             /**< @brief Reduce 3-bit mode to 2-bit mode */
47 48

  
48 49
/* Counting mode: bit 0 */
49 50

  
lab2/timer.c
84 84
int (timer_display_conf)(uint8_t timer, uint8_t st, enum timer_status_field field) {
85 85
    union timer_status_field_val conf;
86 86
    uint8_t in_mode;
87
    if(field == tsf_initial){
88
        in_mode = (st & TIMER_INMODE_MASK) >> TIMER_INMODE_POS;
89
        switch(in_mode){
90
            case 0: conf.in_mode = INVAL_val    ; break; //000
91
            case 1: conf.in_mode = LSB_only     ; break; //001
92
            case 2: conf.in_mode = MSB_only     ; break; //010
93
            case 3: conf.in_mode = MSB_after_LSB; break; //011
94
            default: return 1; break;
95
        }
96
        if(timer_print_config(timer, field, conf)) return 1;
87
    switch(field){
88
        case tsf_all:
89
            conf.byte = st;
90
            break;
91
        case tsf_initial:
92
            in_mode = (st & TIMER_INMODE_MASK) >> TIMER_INMODE_POS;
93
            switch(in_mode){
94
                case 0: conf.in_mode = INVAL_val    ; break; //000
95
                case 1: conf.in_mode = LSB_only     ; break; //001
96
                case 2: conf.in_mode = MSB_only     ; break; //010
97
                case 3: conf.in_mode = MSB_after_LSB; break; //011
98
                default: return 1; break;
99
            }
100
            break;
101
        case tsf_mode:
102
            conf.count_mode = (st & TIMER_MODE_MASK)>>TIMER_MODE_POS;
103
            if(conf.count_mode == 0x6 || conf.count_mode == 0x7)
104
                conf.count_mode &= TIMER_MODE_RED2;
105
            break;
106
        case tsf_base:
107
            conf.bcd = st & TIMER_BCD;
108
            break;
109
        default: return 1; break;
97 110
    }
98
    if(field == tsf_mode){
99
        conf.count_mode = (st & TIMER_MODE_MASK)>>TIMER_MODE_POS;
100
        if(timer_print_config(timer, field, conf)) return 1;
101
    }
102
    if(field == tsf_base){
103
        conf.bcd = st & TIMER_BCD;
104
        if(timer_print_config(timer, field, conf)) return 1;
105
    }
111
    if(timer_print_config(timer, field, conf)) return 1;
106 112
    return 0;
107 113
}

Also available in: Unified diff