Project

General

Profile

Revision 242

working on uart. done with first and second test functions

View differences:

uart.c
39 39
#define UART_GET_DLL(n)           ((n)&0xFF)
40 40
#define UART_GET_DLM(n)           (((n)>>8)&0xFF)
41 41

  
42
#define UART_RECEIVED_DATA_POS      0
43
#define UART_TRANSMITTER_EMPTY_POS  1
44
#define UART_RECEIVER_LINE_STAT_POS 2
45
#define UART_MODEM_STAT_POS         3
46

  
47
#define UART_RECEIVED_DATA          (BIT(0))
48
#define UART_TRANSMITTER_EMPTY      (BIT(1))
49
#define UART_RECEIVER_LINE_STAT     (BIT(2))
50
#define UART_MODEM_STAT             (BIT(3))
51

  
52
#define UART_GET_RECEIVED_DATA(n)       (((n)&UART_RECEIVED_DATA     )>>UART_RECEIVED_DATA_POS     )
53
#define UART_GET_TRANSMITTER_EMPTY(n)   (((n)&UART_TRANSMITTER_EMPTY )>>UART_TRANSMITTER_EMPTY_POS )
54
#define UART_GET_RECEIVER_LINE_STAT(n)  (((n)&UART_RECEIVER_LINE_STAT)>>UART_RECEIVER_LINE_STAT_POS)
55
#define UART_GET_MODEM_STAT(n)          (((n)&UART_MODEM_STAT        )>>UART_MODEM_STAT_POS        )
56

  
42 57
int uart_get_config(int base_addr, uart_config *config){
43 58
    int ret = SUCCESS;
44 59

  
45 60
    config->base_addr = base_addr;
46 61

  
47
    if((ret = util_sys_inb(base_addr+UART_LCR, &config->config))) return ret;
62
    if((ret = util_sys_inb(base_addr+UART_LCR, &config->lcr))) return ret;
48 63

  
49
    if((ret = uart_enable_divisor_latch(base_addr))) return ret;
64
    if((ret = util_sys_inb(base_addr+UART_IER, &config->ier))) return ret;
65

  
66
    if((ret = uart_enable_divisor_latch (base_addr))) return ret;
50 67
    if((ret = util_sys_inb(base_addr+UART_DLL, &config->dll   ))) return ret;
51 68
    if((ret = util_sys_inb(base_addr+UART_DLM, &config->dlm   ))) return ret;
69
    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
52 70

  
53 71
    uart_parse_config(config);
54 72
    return ret;
55 73
}
56 74
void uart_parse_config(uart_config *config){
57
    config->bits_per_char        = UART_GET_BITS_PER_CHAR(config->config);
58
    config->stop_bits            = UART_GET_STOP_BITS    (config->config);
59
    config->parity               = UART_GET_PARITY       (config->config);
60
    config->break_control        = UART_GET_BREAK_CONTROL(config->config);
61
    config->dlab                 = UART_GET_DLAB         (config->config);
62
    config->divisor_latch        = UART_GET_DIV_LATCH    (config->dlm, config->dll);
75
    /// LCR
76
    config->bits_per_char          = UART_GET_BITS_PER_CHAR     (config->lcr);
77
    config->stop_bits              = UART_GET_STOP_BITS         (config->lcr);
78
    config->parity                 = UART_GET_PARITY            (config->lcr);
79
    config->break_control          = UART_GET_BREAK_CONTROL     (config->lcr);
80
    config->dlab                   = UART_GET_DLAB              (config->lcr);
81
    /// IER
82
    config->received_data_int      = UART_GET_RECEIVED_DATA     (config->ier);
83
    config->transmitter_empty_int  = UART_GET_TRANSMITTER_EMPTY (config->ier);
84
    config->receiver_line_stat_int = UART_GET_RECEIVER_LINE_STAT(config->ier);
85
    config->modem_stat_int         = UART_GET_MODEM_STAT        (config->ier);
86
    /// DIV LATCH
87
    config->divisor_latch          = UART_GET_DIV_LATCH(config->dlm, config->dll);
63 88
}
64 89
void uart_print_config(uart_config config){
65
    printf("Base address: 0x%X\n", config.base_addr);
66
    printf("Configuration: 0x%02X\n", config.config);
67
    printf("Number of bits per char: %d\n", config.bits_per_char);
68
    printf("Number of stop bits: %d\n", config.stop_bits);
69
    printf("Parity: ");
90
    printf("Base address                                   : 0x%X\n", config.base_addr);
91
    printf("    LCR configuration                          : 0x%02X\n", config.lcr);
92
    printf("        Number of bits per char                : %d\n", config.bits_per_char);
93
    printf("        Number of stop bits                    : %d\n", config.stop_bits);
94
    printf("        Parity                                 : ");
70 95
    if((config.parity&1) == 0) printf("no parity\n");
71 96
    else switch(config.parity){
72 97
        case uart_parity_odd : printf("odd parity\n"     ); break;
......
75 100
        case uart_parity_par0: printf("parity bit is 0\n"); break;
76 101
        default              : printf("invalid\n"        ); break;
77 102
    }
78
    printf("Break control: %d\n", config.break_control);
79
    printf("Divisor latch: %d\n", config.divisor_latch);
80
    printf("Bit rate: %d\n", UART_BITRATE/config.divisor_latch);
103
    printf("    Break control                              : %d\n", config.break_control);
104
    printf("    DLAB                                       : %d\n", config.dlab);
105

  
106
    printf("    IER configuration                          : 0x%02X\n", config.ier);
107
    printf("        Received data interrupts enabled       : %d\n", config.received_data_int);
108
    printf("        Transmitter empty interrupts enabled   : %d\n", config.transmitter_empty_int);
109
    printf("        Receiver line status interrupts enabled: %d\n", config.receiver_line_stat_int);
110
    printf("        Modem status interrupts enabled        : %d\n", config.modem_stat_int);
111

  
112
    printf("    Divisor latch (DLM & DLL)                  : %d\n", config.divisor_latch);
113
    printf("        Bit rate                               : %d\n", UART_BITRATE/config.divisor_latch);
81 114
}
82 115

  
83 116
int uart_enable_divisor_latch(int base_addr){

Also available in: Unified diff