Index: proj/include/errors.h
===================================================================
--- proj/include/errors.h	(revision 234)
+++ proj/include/errors.h	(revision 235)
@@ -17,6 +17,7 @@
     OUT_OF_RANGE,       /** @brief Accessing area out of range of memory */
     ALLOC_ERROR,        /** @brief Memory allocation error */
     LOGIC_ERROR,        /** @brief Logic error */
+    INVALID_ARG,        /** @brief Invalid argument */
     OTHER_ERROR         /** @brief Unspecified error */
 };
 
Index: proj/include/test7.h
===================================================================
--- proj/include/test7.h	(nonexistent)
+++ proj/include/test7.h	(revision 235)
@@ -0,0 +1,11 @@
+int ser_test_conf(unsigned short base_addr);
+
+int ser_test_set(unsigned short base_addr, unsigned long bits, unsigned long stop,
+	     long parity, /* -1: none, 0: even, 1: odd */
+	     unsigned long rate);
+
+int ser_test_poll(unsigned short base_addr, unsigned char tx, unsigned long bits, 	unsigned long stop, long parity, unsigned long rate, int stringc, char *strings[]);
+
+int ser_test_int(/* details to be provided */) ;
+
+int ser_test_fifo(/* details to be provided */);

Property changes on: proj/include/test7.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/include/uart.h
===================================================================
--- proj/include/uart.h	(nonexistent)
+++ proj/include/uart.h	(revision 235)
@@ -0,0 +1,31 @@
+#ifndef UART_H_INCLUDED
+#define UART_H_INCLUDED
+
+#include "uart_macros.h"
+
+typedef struct {
+    int     base_addr;
+    uint8_t config;
+    uint8_t dll;
+    uint8_t dlm;
+    uint8_t bits_per_char;
+    uint8_t stop_bits;
+    uint8_t parity;
+    uint8_t break_control;
+    uint16_t divisor_latch;
+} uart_config;
+
+int uart_get_config(int base_addr, uart_config *config);
+void uart_parse_config(uart_config *config);
+void uart_print_config(uart_config config);
+
+int uart_enable_divisor_latch (int base_addr);
+int uart_disable_divisor_latch(int base_addr);
+
+int uart_write_config          (int base_addr, uint8_t     config       );
+int uart_set_bits_per_character(int base_addr, uint8_t     bits_per_char);
+int uart_set_stop_bits         (int base_addr, uint8_t     stop         );
+int uart_set_parity            (int base_addr, uart_parity par          );
+int uart_set_bit_rate          (int base_addr, float       bit_rate     );
+
+#endif //UART_H_INCLUDED

Property changes on: proj/include/uart.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/include/uart_macros.h
===================================================================
--- proj/include/uart_macros.h	(nonexistent)
+++ proj/include/uart_macros.h	(revision 235)
@@ -0,0 +1,54 @@
+#ifndef UART_MACROS_H_INCLUDED
+#define UART_MACROS_H_INCLUDED
+
+#define UART_BITRATE        115200
+
+#define COM1_ADDR           0x3F8
+#define COM2_ADDR           0x2F8
+#define COM1_IRQ            4
+#define COM2_IRQ            3
+#define COM1_VECTOR         0x0C
+#define COM2_VECTOR         0x0B
+
+#define UART_RBR            0
+#define UART_THR            0
+#define UART_IER            1
+#define UART_IIR            2
+#define UART_FCR            2
+#define UART_LCR            3
+#define UART_MCR            4
+#define UART_LSR            5
+#define UART_MSR            6
+#define UART_SR             7
+
+#define UART_DLL            0
+#define UART_DLM            1
+
+#define UART_BITS_PER_CHAR_POS 0
+#define UART_STOP_BITS_POS     2
+#define UART_PARITY_POS        3
+#define UART_BREAK_CONTROL_POS 6
+#define UART_DLAB_POS          7
+
+#define UART_BITS_PER_CHAR  (BIT(0) | BIT(1))
+#define UART_STOP_BITS      (BIT(2))
+#define UART_PARITY         (BIT(3) | BIT(4) | BIT(5))
+#define UART_BREAK_CONTROL  (BIT(6))
+#define UART_DLAB           (BIT(7))
+
+#define UART_GET_BITS_PER_CHAR(n) ((n)&UART_BITS_PER_CHAR + 5)
+#define UART_GET_STOP_BITS(n)     ((n)&UART_STOP_BITS? 2 : 1)
+#define UART_GET_PARITY(n)        (((n)&UART_PARITY       )>>UART_PARITY_POS       )
+#define UART_GET_BREAK_CONTROL(n) (((n)&UART_BREAK_CONTROL)>>UART_BREAK_CONTROL_POS)
+#define UART_GET_DLAB(n)          (((n)&UART_DLAB         )>>UART_DLAB_POS         )
+
+
+typedef enum {
+    uart_parity_none = 0x0,
+    uart_parity_odd  = 0x1,
+    uart_parity_even = 0x3,
+    uart_parity_par1 = 0x5,
+    uart_parity_par0 = 0x7
+} uart_parity;
+
+#endif //UART_MACROS_H_INCLUDED

Property changes on: proj/include/uart_macros.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/proj.c
===================================================================
--- proj/src/proj.c	(revision 234)
+++ proj/src/proj.c	(revision 235)
@@ -29,11 +29,16 @@
 
 #include "list.h"
 
+#ifdef DIOGO
+    #include "uart_macros.h"
+    #include "test7.h"
+#endif
+
 int main(int argc, char* argv[]) {
 
     lcf_set_language("EN-US");
 
-    //lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
+    lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
 
     lcf_log_output("/home/lcom/labs/proj/output.txt");
 
@@ -48,6 +53,15 @@
 
     int r;
 
+    #ifdef DIOGO
+        uint8_t conf;
+        if((r = util_sys_inb(0x3F8+3, &conf))) return 1; //printf("0x%02X\n", conf);
+        conf = 0x19; //00011001
+        //printf("0x%02X\n", conf);
+        if((r = sys_outb(0x3F8+3, conf))) return 1;
+        if((r = util_sys_inb(0x3F8+3, &conf))) return 1; //printf("0x%02X\n", conf);
+    #endif
+
     font_t *consolas = font_ctor("/home/lcom/labs/proj/media/font/Consolas/xpm2");
     if(consolas == NULL){ printf("Failed to load consolas\n"); return 1; }
 
@@ -137,6 +151,7 @@
         tickdelay(micros_to_ticks(1000000));*/
 
         // RTC
+        /*
         uint8_t date[4], time[3];
 
         if (rtc_read_time(time)) return 1;
@@ -146,6 +161,17 @@
         printf("Hour: %02d:%02d:%02d\n", time[2], time[1], time[0]);
 
         printf("Date: %d, %02d/%02d/%02d\n", date[0], date[1], date[2], date[3]);
+        */
+        //UART
+        /*
+        printf("got %d\n", ser_test_conf(COM1_ADDR));
+        printf("\n");
+        printf("got %d\n", ser_test_set(COM1_ADDR, 6, 1, 0, 9800));
+        tickdelay(micros_to_ticks(1000000));
+        printf("got %d\n", ser_test_conf(COM1_ADDR));
+        */
+
+
     #endif
 
     #ifdef TELMO
Index: proj/src/test7.c
===================================================================
--- proj/src/test7.c	(nonexistent)
+++ proj/src/test7.c	(revision 235)
@@ -0,0 +1,55 @@
+#include <lcom/lcf.h>
+
+#include "errors.h"
+#include "uart_macros.h"
+#include "uart.h"
+
+int ser_test_conf(unsigned short base_addr) {
+	int ret = SUCCESS;
+	uart_config conf;
+	if((ret = uart_get_config(base_addr, &conf))) return ret;
+	uart_print_config(conf);
+	return SUCCESS;
+}
+
+int ser_test_set(unsigned short base_addr, unsigned long bits, unsigned long stop,
+	           long parity, unsigned long rate) {
+    int par;
+   	switch(parity){
+		case -1: par = uart_parity_none; break;
+		case  0: par = uart_parity_even; break;
+		case +1: par = uart_parity_odd ; break;
+		default: return INVALID_ARG;
+   	}
+	int ret = SUCCESS;
+
+	uint8_t conf = 0;
+	conf |= (bits-5)<<UART_BITS_PER_CHAR_POS;
+	conf |= (stop-1)<<UART_STOP_BITS_POS;
+	conf |= par     <<UART_PARITY_POS;
+
+	//if((ret = uart_set_bits_per_character(base_addr, bits))) return ret; tickdelay(micros_to_ticks(100000));
+	//if((ret = uart_set_stop_bits         (base_addr, stop))) return ret; tickdelay(micros_to_ticks(100000));
+	//if((ret = uart_set_parity            (base_addr, par ))) return ret; tickdelay(micros_to_ticks(100000));
+	if((ret = uart_write_config(base_addr, conf))) return ret;
+	if((ret = uart_set_bit_rate          (base_addr, rate))) return ret; tickdelay(micros_to_ticks(100000));
+
+	return SUCCESS;
+}
+
+int ser_test_poll(unsigned short base_addr, unsigned char tx, unsigned long bits,
+                    unsigned long stop, long parity, unsigned long rate,
+                    int stringc, char *strings[]) {
+    /* To be completed */
+	return 1;
+}
+
+int ser_test_int(/* details to be provided */) {
+    /* To be completed */
+	return 1;
+}
+
+int ser_test_fifo(/* details to be provided */) {
+    /* To be completed */
+	return 1;
+}

Property changes on: proj/src/test7.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/src/uart.c
===================================================================
--- proj/src/uart.c	(nonexistent)
+++ proj/src/uart.c	(revision 235)
@@ -0,0 +1,100 @@
+#include <lcom/lcf.h>
+
+#include "uart.h"
+
+#include "errors.h"
+
+int uart_get_config(int base_addr, uart_config *config){
+    int ret = SUCCESS;
+
+    config->base_addr = base_addr;
+
+    if((ret = util_sys_inb(base_addr+UART_LCR, &config->config))) return ret;
+
+    if((ret = uart_enable_divisor_latch(base_addr))) return ret;
+    if((ret = util_sys_inb(base_addr+UART_DLL, &config->dll   ))) return ret;
+    if((ret = util_sys_inb(base_addr+UART_DLM, &config->dlm   ))) return ret;
+
+    uart_parse_config(config);
+    return ret;
+}
+void uart_parse_config(uart_config *config){
+    config->bits_per_char        = UART_GET_BITS_PER_CHAR(config->config);
+    config->stop_bits            = UART_GET_STOP_BITS    (config->config);
+    config->parity               = UART_GET_PARITY       (config->config);
+    config->break_control        = UART_GET_BREAK_CONTROL(config->config);
+    config->divisor_latch        = config->dlm<<8 | config->dll;
+}
+void uart_print_config(uart_config config){
+    printf("Base address: 0x%X\n", config.base_addr);
+    printf("Configuration: 0x%02X\n", config.config);
+    printf("Number of bits per char: %d\n", config.bits_per_char);
+    printf("Number of stop bits: %d\n", config.stop_bits);
+    printf("Parity: ");
+    if((config.parity&1) == 0) printf("no parity\n");
+    else switch(config.parity){
+        case uart_parity_odd : printf("odd parity\n"     ); break;
+        case uart_parity_even: printf("even parity\n"    ); break;
+        case uart_parity_par1: printf("parity bit is 1\n"); break;
+        case uart_parity_par0: printf("parity bit is 0\n"); break;
+        default              : printf("invalid\n"        ); break;
+    }
+    printf("Break control: %d\n", config.break_control);
+    printf("Divisor latch: %d\n", config.divisor_latch);
+    printf("Bit rate (x1000): %d\n", 1000*(uint32_t)UART_BITRATE/config.divisor_latch);
+}
+
+int uart_enable_divisor_latch(int base_addr){
+    int ret = SUCCESS;
+    uint8_t conf; if((ret = util_sys_inb(base_addr+UART_LCR, &conf))) return ret;
+    return uart_write_config(base_addr, conf | UART_DLAB);
+}
+int uart_disable_divisor_latch(int base_addr){
+    int ret = SUCCESS;
+    uint8_t conf; if((ret = util_sys_inb(base_addr+UART_LCR, &conf))) return ret;
+    return uart_write_config(base_addr, conf & (~UART_DLAB));
+}
+
+int uart_write_config(int base_addr, uint8_t config){
+    printf("WRITING CONFIG 0x%02X TO 0x%X\n", config, base_addr);
+    if(sys_outb(base_addr+UART_LCR, config)) return WRITE_ERROR;
+    return SUCCESS;
+}
+int uart_set_bits_per_character(int base_addr, uint8_t bits_per_char){
+    if(bits_per_char < 5 || bits_per_char > 8) return INVALID_ARG;
+    int ret = SUCCESS;
+    bits_per_char = (bits_per_char-5)&0x3;
+    uint8_t conf; if((ret = util_sys_inb(base_addr+UART_LCR, &conf))) return ret;
+    conf = (conf & (~UART_BITS_PER_CHAR)) | bits_per_char;
+    return uart_write_config(base_addr, conf);
+}
+int uart_set_stop_bits(int base_addr, uint8_t stop){
+    if(stop != 1 && stop != 2) return INVALID_ARG;
+    int ret = SUCCESS;
+    stop -= 1;
+    stop = (stop&1)<<2;
+    uint8_t conf; if((ret = util_sys_inb(base_addr+UART_LCR, &conf))) return ret;
+    conf = (conf & (~UART_STOP_BITS)) | stop;
+    return uart_write_config(base_addr, conf);
+}
+int uart_set_parity(int base_addr, uart_parity par){
+    int ret = SUCCESS;
+    uint8_t parity = par << 3;
+    uint8_t conf; if((ret = util_sys_inb(base_addr+UART_LCR, &conf))) return ret;
+    conf = (conf & (~UART_PARITY)) | parity;
+    return uart_write_config(base_addr, conf);
+}
+int uart_set_bit_rate(int base_addr, float bit_rate){ printf("%s, L82\n", __func__);
+    int ret = SUCCESS;
+    uint16_t latch = UART_BITRATE/bit_rate;
+    uint8_t dll = latch&0xFF;
+    uint8_t dlm = (latch>>8)&0xFF;
+    if((ret = uart_enable_divisor_latch(base_addr))) return ret;
+    printf("dlm,dll=0x%02X%02X\n", dlm, dll);
+    if(sys_outb(base_addr+UART_DLL, dll)) return WRITE_ERROR;
+    if(sys_outb(base_addr+UART_DLM, dlm)) return WRITE_ERROR;
+    if((ret = util_sys_inb(base_addr+UART_DLM, &dlm))) return ret;
+    printf("dlm=0x%02X\n", dlm);
+    printf("%s, L91\n", __func__);
+    return SUCCESS;
+}

Property changes on: proj/src/uart.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/DR.mk
===================================================================
--- proj/DR.mk	(revision 234)
+++ proj/DR.mk	(revision 235)
@@ -2,9 +2,9 @@
 
 .PATH: ${.CURDIR}/src
 
-SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c
+SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c
 
-CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D DIOGO -D __LCOM_OPTIMIZED_
+CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D DIOGO #-D __LCOM_OPTIMIZED_
 
 DPADD += ${LIBLCF}
 LDADD += -llcf
Index: proj/Makefile
===================================================================
--- proj/Makefile	(revision 234)
+++ proj/Makefile	(revision 235)
@@ -2,7 +2,7 @@
 
 .PATH: ${.CURDIR}/src
 
-SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c
+SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c
 
 CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D __LCOM_OPTIMIZED_
 
Index: proj/TB.mk
===================================================================
--- proj/TB.mk	(revision 234)
+++ proj/TB.mk	(revision 235)
@@ -2,7 +2,7 @@
 
 .PATH: ${.CURDIR}/src
 
-SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c
+SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c
 
 CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D TELMO #-D __LCOM_OPTIMIZED_
 
