Project

General

Profile

Revision 10

Update timer.c

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
38
#define TIMER_INMODE_MASK 0x30      //0011 0000
39 39
#define TIMER_INMODE_POS  4
40 40

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

  
43 43
#define TIMER_SQR_WAVE (BIT(2) | BIT(1)) /**< @brief Mode 3: square wave generator */
44 44
#define TIMER_RATE_GEN BIT(2)            /**< @brief Mode 2: rate generator */
45
#define TIMER_MODE_MASK 0x0e             /**< @brief Mask for mode */
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 47

  
48 48
/* Counting mode: bit 0 */
lab2/timer.c
6 6
#include "i8254.h"
7 7

  
8 8
int (timer_set_frequency)(uint8_t timer, uint32_t freq) {
9
    /* To be implemented by the students */
10
    printf("%s is not yet implemented!\n", __func__);
11 9

  
10
    // counter_init = clock/feq
11

  
12
    uint8_t status = 0;
13

  
14
    if (timer_get_conf(timer, &status)) return 1;
15
    //Make command
16
    uint8_t write_cmd = 0;
17
    //Select timer
18
    switch(timer) {
19
        case 0: write_cmd |= TIMER_SEL0;
20
            break;
21
        case 1: write_cmd |= TIMER_SEL1;
22
            break;
23
        case 2: write_cmd |= TIMER_SEL2;
24
            break;
25
        default: return 1; break;
26
    }
27
    //Change both LSB and MSB
28
    write_cmd |= TIMER_LSB_MSB;
29
    //Keep 4 least significant bits
30
    write_cmd |= (status & (TIMER_MODE_MASK | TIMER_BCD));
31
    //Write cmd
32
    sys_outb(TIMER_CTRL, )
33

  
34

  
12 35
    return 1;
13 36
}
14 37

  
......
33 56

  
34 57
int (timer_get_conf)(uint8_t timer, uint8_t *st) {
35 58
    // Write read-back command to TIMER_CTRL
36
    int write_port = TIMER_CTRL;
37 59
    u32_t cmd = TIMER_RB_CMD | TIMER_RB_COUNT_ | TIMER_RB_SEL(timer);
38
    if(sys_outb(write_port, cmd)) return 1;
60
    if(sys_outb(TIMER_CTRL, cmd)) return 1;
39 61

  
40 62
    int read_port;
41 63
    switch(timer) {

Also available in: Unified diff