Index: proj/include/test7.h
===================================================================
--- proj/include/test7.h	(revision 274)
+++ proj/include/test7.h	(nonexistent)
@@ -1,18 +0,0 @@
-#ifndef TEST7_H_INCLUDED
-#define TEST7_H_INCLUDED
-
-#include "uart.h"
-
-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 */);
-
-#endif //TEST7_H_INCLUDED

Property changes on: proj/include/test7.h
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/src/test7.c
===================================================================
--- proj/src/test7.c	(revision 274)
+++ proj/src/test7.c	(nonexistent)
@@ -1,69 +0,0 @@
-#include <lcom/lcf.h>
-
-#include "errors.h"
-#include "nctp.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;
-	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_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[]) {
-	int ret = SUCCESS;
-    if((ret = ser_test_set(base_addr, bits, stop, parity, rate))) return ret;
-	if((ret = uart_disable_int_rx(base_addr))) return ret;
-	if((ret = uart_disable_int_tx(base_addr))) return ret;
-	if(tx == 0){
-		uint8_t c = ' ';
-		int r;
-		while(c != '.'){
-			r = nctp_get_char_poll(base_addr, &c);
-			if(r == TIMEOUT_ERROR) continue;
-			else if(r != SUCCESS ) return r;
-			printf("%c", c);
-		}
-	}else{
-		for(int i = 0; i < stringc; ++i){
-			for(int j = 0; strings[i][j] != 0; ++j)
-				if((ret = nctp_send_char_poll(base_addr, strings[i][j])))
-					return ret;
-			if(i+1 != stringc)
-				if((ret = nctp_send_char_poll(base_addr, ' '))) return ret;
-		}
-		if((ret = nctp_send_char_poll(base_addr, '.'))) return ret;
-	}
-	return SUCCESS;
-}
-
-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
___________________________________________________________________
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Index: proj/include/hltp.h
===================================================================
--- proj/include/hltp.h	(revision 274)
+++ proj/include/hltp.h	(revision 275)
@@ -3,8 +3,6 @@
 
 #include "nctp.h"
 
-int hltp_send_string(int base_addr, const char *p);
+int hltp_send_string(const char *p);
 
-int hltp_get_string(int base_addr, char **p);
-
 #endif //HLTP_H_INCLUDED
Index: proj/include/list.h
===================================================================
--- proj/include/list.h	(revision 274)
+++ proj/include/list.h	(revision 275)
@@ -18,7 +18,11 @@
 list_node_t* (list_begin )(list_t *l);
 list_node_t* (list_end   )(list_t *l);
 size_t       (list_size  )(const list_t *l);
+int          (list_empty )(const list_t *l);
 list_node_t* (list_insert)(list_t *l, list_node_t *position, void *val);
 void*        (list_erase )(list_t *l, list_node_t *position);
+void         (list_push_back)(list_t *l, void *val);
+void**       (list_front)(list_t *l);
+void         (list_pop_front)(list_t *l);
 
 #endif //LIST_H_INCLUDED
Index: proj/include/nctp.h
===================================================================
--- proj/include/nctp.h	(revision 274)
+++ proj/include/nctp.h	(revision 275)
@@ -3,16 +3,12 @@
 
 #include "uart.h"
 
-int nctp_get_char_poll   (int base_addr, uint8_t *p);
-int nctp_send_char_poll  (int base_addr, uint8_t  c);
+int nctp_init(void);
+int nctp_free(void);
 
-/**
- * @brief Send stuff to COM #port.
- * @param   port    Port to send message to
- * @param   num     Number of pairs of address/numbytes to send
- */
-int nctp_send(int base_addr, size_t num, uint8_t* ptr[], size_t sz[]);
+int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]);
 
-int nctp_get (int base_addr, uint8_t **dest);
+int nctp_ih_err;
+void nctp_ih(void);
 
 #endif //NCTP_H_INCLUDED
Index: proj/src/hltp.c
===================================================================
--- proj/src/hltp.c	(revision 274)
+++ proj/src/hltp.c	(revision 275)
@@ -3,13 +3,3 @@
 #include "hltp.h"
 
 #include "nctp.h"
-
-int hltp_send_string(int base_addr, const char *p){
-    uint8_t* ptr[1]; ptr[0] = (uint8_t*)p;
-    size_t    sz[1]; sz[0] = strlen(p)+1;
-    return nctp_send(base_addr, 1, ptr, sz);
-}
-
-int hltp_get_string(int base_addr, char **p){
-    return nctp_get(base_addr, (uint8_t**)p);
-}
Index: proj/src/interrupts_func.c
===================================================================
--- proj/src/interrupts_func.c	(revision 274)
+++ proj/src/interrupts_func.c	(revision 275)
@@ -5,7 +5,7 @@
 #include "i8254.h"
 #include "keyboard.h"
 #include "mouse.h"
-#include "uart.h"
+#include "nctp.h"
 #include "utils.h"
 #include "errors.h"
 
@@ -106,12 +106,13 @@
     uart_set_parity            (COM1_ADDR, uart_parity_even);
     uart_set_bit_rate          (COM1_ADDR, 38400);
     uart_enable_int_rx (COM1_ADDR);
-    uart_disable_int_tx(COM1_ADDR);
+    uart_enable_int_tx(COM1_ADDR);
     if(subscribe_uart_interrupt(COM1_IRQ, &uart_id)) {
         printf("%s: failed to subscribe UART interrupts.\n", __func__);
         return SBCR_ERROR;
     }
     uart_subscribed = 1;
+    nctp_init();
 
     return SUCCESS;
 }
@@ -168,6 +169,7 @@
         uart_enable_int_tx(COM1_ADDR);
         uart_subscribed = 0;
     }
+    nctp_free();
 
     return r;
 }
Index: proj/src/list.c
===================================================================
--- proj/src/list.c	(revision 274)
+++ proj/src/list.c	(revision 275)
@@ -52,6 +52,7 @@
 list_node_t* (list_begin )(      list_t *l){ return l->begin_->n; }
 list_node_t* (list_end   )(      list_t *l){ return l->end_; }
 size_t       (list_size  )(const list_t *l){ return l->sz; }
+int          (list_empty )(const list_t *l){ return !(l->sz); }
 list_node_t* (list_insert)(list_t *l, list_node_t *position, void *val){
     list_node_t *node = list_node_ctor(position->p, position, val);
     position->p->n = node;
@@ -67,3 +68,12 @@
     --l->sz;
     return ret;
 }
+void         (list_push_back)(list_t *l, void *val){
+    list_insert(l, list_end(l), val);
+}
+void**       (list_front)(list_t *l){
+    return list_node_val(list_begin(l));
+}
+void         (list_pop_front)(list_t *l){
+    list_erase(l, list_begin(l));
+}
Index: proj/src/proj.c
===================================================================
--- proj/src/proj.c	(revision 274)
+++ proj/src/proj.c	(revision 275)
@@ -209,7 +209,7 @@
                                         buffer[buffer_pos] = '\0';
                                         printf("\nSending string -%s-", buffer);
                                         printf(" (output: %d)\n",
-                                            hltp_send_string(COM1_ADDR, buffer));
+                                            hltp_send_string(buffer));
                                         buffer_pos = 0;
                                     }
                                     else {
@@ -262,12 +262,8 @@
                             #endif
                             #ifdef DIOGO
                             case COM1_IRQ:
-                                {
-                                    printf("You've got mail");
-                                    int r = hltp_get_string(COM1_ADDR, &s);
-                                    printf(" (return code %d)", r);
-                                    printf(": -%s-\n", s);
-                                }break;
+                                nctp_ih();
+                                break;
                             #endif
                             }
                         }
Index: proj/src/uart.c
===================================================================
--- proj/src/uart.c	(revision 274)
+++ proj/src/uart.c	(revision 275)
@@ -2,6 +2,7 @@
 
 #include "uart.h"
 
+#include "queue.h"
 #include "errors.h"
 
 #define UART_BITRATE                            115200
@@ -78,6 +79,12 @@
 #define UART_GET_FRAMING_ERROR                  (((n)&UART_FRAMING_ERROR            )>>UART_FRAMING_ERROR_POS            )
 #define UART_GET_TRANSMITTER_EMPTY(n)           (((n)&UART_TRANSMITTER_EMPTY        )>>UART_TRANSMITTER_EMPTY_POS        )
 
+/// IIR
+#define UART_GET_IF_INT_PEND(n)                 (!((n)&1))
+#define UART_GET_INT_PEND(n)                    (((n)&0xE)>>1)
+#define UART_INT_RX                             0x2 //0b010
+#define UART_INT_TX                             0x1 //0b001
+
 int (subscribe_uart_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
     if (interrupt_id == NULL) return 1;
     *interrupt_id = interrupt_bit;
@@ -110,6 +117,9 @@
 static int uart_get_lsr(int base_addr, uint8_t *p){
     return util_sys_inb(base_addr+UART_LSR, p);
 }
+static int uart_get_iir(int base_addr, uint8_t *p){
+    return util_sys_inb(base_addr+UART_IIR, p);
+}
 
 static int uart_enable_divisor_latch(int base_addr){
     int ret = SUCCESS;
@@ -256,73 +266,35 @@
     return uart_set_ier(base_addr, ier);
 }
 
-/*static*/ int uart_has_communication_error(int base_addr){
-    int ret;
-    uint8_t lsr;
-    if((ret = uart_get_lsr(base_addr, &lsr))) return 1;
-    lsr &= (UART_OVERRUN_ERROR &
-            UART_PARITY_ERROR  &
-            UART_FRAMING_ERROR);
-    return (lsr ? 1 : 0);
-}
-
 #include "nctp.h"
 
 #define NCTP_START      0x80
 #define NCTP_END        0xFF
-#define NCTP_TRIES      3
 #define NCTP_OK         0xFF
 #define NCTP_NOK        0x00
 #define NCTP_MAX_SIZE   1024 //in bytes
 
-int nctp_send_char_poll(int base_addr, uint8_t  c){
-    for(int i = 0; i < NCTP_TRIES; ++i)
-        if(uart_transmitter_empty(base_addr))
-            return uart_send_char(base_addr, c);
-    return TIMEOUT_ERROR;
-}
-int nctp_get_char_poll (int base_addr, uint8_t *p){
-    for(int i = 0; i < NCTP_TRIES; ++i)
-        if(uart_receiver_ready(base_addr))
-            return uart_get_char(base_addr, p);
-    return TIMEOUT_ERROR;
-}
+queue_t *out = NULL;
+queue_t *in  = NULL;
 
-int nctp_expect_ok(int base_addr){
-    int ret;
-    uint8_t ok;
-    if((ret = nctp_get_char_poll(base_addr, &ok))) return ret;
-    int cnt = 0;
-    while(ok){
-        cnt += ok&1;
-        ok >>= 1;
-    }
-    if(cnt > 4) return SUCCESS;
-    else        return NOK;
+int nctp_init(void){
+    out = queue_ctor(); if(out == NULL) return NULL_PTR;
+    in  = queue_ctor(); if(in  == NULL) return NULL_PTR;
+    return SUCCESS;
 }
-
-int nctp_send_char_try(int base_addr, uint8_t  c){
-    int ret;
-    for(size_t k = 0; k < NCTP_TRIES; ++k){
-        if((ret = nctp_send_char_poll(base_addr, c))) return ret;
-        return SUCCESS;
-        //if(nctp_expect_ok(base_addr) == SUCCESS) return SUCCESS;
+int nctp_free(void){
+    while(!queue_empty(out)){
+        free(queue_top(out));
+        queue_pop(out);
     }
-    return TRANS_FAILED;
-}
-int nctp_get_char_try (int base_addr, uint8_t *p){
-    int ret;
-    for(size_t k = 0; k < NCTP_TRIES; ++k){
-        if((ret = nctp_get_char_poll (base_addr, p))) return ret;
-        return SUCCESS;
-        //if(!uart_has_communication_error(base_addr))
-            //return nctp_send_char_try(base_addr, NCTP_OK ); //If it does not have any errors
+    while(!queue_empty(in)){
+        free(queue_top(in));
+        queue_pop(in);
     }
-    if((ret = nctp_send_char_poll(base_addr, NCTP_NOK))) return ret;
-    return TRANS_FAILED;
+    return SUCCESS;
 }
 
-static int nctp_send_inner(int base_addr, size_t num, uint8_t* ptr[], size_t sz[]){
+int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]){
     {
         int cnt = 0;
         for(size_t i = 0; i < num; ++i){
@@ -330,50 +302,66 @@
             if(cnt > NCTP_MAX_SIZE) return TRANS_REFUSED;
         }
     }
-
     int ret;
-
-    if((ret = nctp_send_char_try(base_addr, NCTP_START))) return ret;
+    uint8_t *tmp;
+    tmp = malloc(sizeof(uint8_t)); *tmp = NCTP_START; queue_push(out, tmp);
     for(size_t i = 0; i < num; ++i){
         uint8_t *p = ptr[i]; size_t s = sz[i];
-        for(size_t j = 0; j < s; ++j, ++p)
-            if((ret = nctp_send_char_try(base_addr, *p)))
-                return ret;
+        for(size_t j = 0; j < s; ++j, ++p){
+            tmp = malloc(sizeof(uint8_t)); *tmp = *p; queue_push(out, tmp);
+        }
     }
-    if((ret = nctp_send_char_try(base_addr, NCTP_END))) return ret;
-
+    tmp = malloc(sizeof(uint8_t)); *tmp = NCTP_END; queue_push(out, tmp);
+    if(uart_transmitter_empty(COM1_ADDR)){
+        if((ret = uart_send_char(COM1_ADDR, *(uint8_t*)queue_top(out)))) return ret;
+        queue_pop(out);
+    }
     return SUCCESS;
 }
-int nctp_send(int base_addr, size_t num, uint8_t* ptr[], size_t sz[]){
-    int ret;
-    if((ret = uart_disable_int_rx(base_addr))) return ret;
-    if((ret = uart_disable_int_tx(base_addr))) return ret;
-    int r = nctp_send_inner(base_addr, num, ptr, sz);
-    if((ret = uart_enable_int_rx(base_addr))) return ret;
-    if((ret = uart_disable_int_tx(base_addr))) return ret;
-    return r;
+
+static int nctp_transmit(void){
+    if(!queue_empty(out)){
+        int ret = uart_send_char(COM1_ADDR, *(uint8_t*)queue_top(out));
+        queue_pop(out);
+        return ret;
+    }else return SUCCESS;
 }
-
-static int nctp_get_inner(int base_addr, uint8_t **dest){
+static void process(){
+    free(queue_top(in)); queue_pop(in);
+    while(*(uint8_t*)queue_top(in) != NCTP_END){
+        printf("%c", *(uint8_t*)queue_top(in));
+        free(queue_top(in)); queue_pop(in);
+    }
+    free(queue_top(in)); queue_pop(in);
+}
+static int nctp_receive(void){
     int ret;
-    free(*dest);
-    *dest = malloc(NCTP_MAX_SIZE*sizeof(uint8_t)); size_t i = 0;
-    if(*dest == NULL) return NULL_PTR;
     uint8_t c;
-    if((ret = nctp_get_char_try (base_addr, &c     ))) return ret;
-    while(true){
-        if(i >= NCTP_MAX_SIZE) return TRANS_REFUSED;
-        if((ret = nctp_get_char_try (base_addr, &c))) return ret;
-        if(c == NCTP_END) return SUCCESS;
-        else              (*dest)[i++] = c;
+    while(uart_receiver_ready(COM1_ADDR)){
+        if((ret = uart_get_char(COM1_ADDR, &c))) return ret;
+        uint8_t *tmp = malloc(sizeof(uint8_t)); *tmp = c;
+        queue_push(in, tmp);
+        if(c == NCTP_END) process();
     }
+    return SUCCESS;
 }
-int nctp_get(int base_addr, uint8_t **dest){
-    int ret;
-    if((ret = uart_disable_int_rx(base_addr))) return ret;
-    if((ret = uart_disable_int_tx(base_addr))) return ret;
-    int r = nctp_get_inner(base_addr, dest);
-    if((ret = uart_enable_int_rx(base_addr))) return ret;
-    if((ret = uart_disable_int_tx(base_addr))) return ret;
-    return r;
+
+int nctp_ih_err = SUCCESS;
+void nctp_ih(void){
+    uint8_t iir;
+    if((nctp_ih_err = uart_get_iir(COM1_ADDR, &iir))) return;
+    if(UART_GET_IF_INT_PEND(iir)){
+        switch(UART_GET_INT_PEND(iir)){
+            case UART_INT_RX: nctp_receive (); break;
+            case UART_INT_TX: nctp_transmit(); break;
+            default: break;
+        }
+    }
 }
+
+/// HLTP
+int hltp_send_string(const char *p){
+    uint8_t* ptr[1]; ptr[0] = (uint8_t*)p;
+    size_t    sz[1]; sz[0] = strlen(p)+1;
+    return nctp_send(1, ptr, sz);
+}
Index: proj/DR.mk
===================================================================
--- proj/DR.mk	(revision 274)
+++ proj/DR.mk	(revision 275)
@@ -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 test7.c uart.c hltp.c makecode_map.c
+SRCS= proj.c list.c queue.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 uart.c hltp.c makecode_map.c
 
 CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D DIOGO #-D __LCOM_OPTIMIZED_
 
Index: proj/Makefile
===================================================================
--- proj/Makefile	(revision 274)
+++ proj/Makefile	(revision 275)
@@ -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 test7.c uart.c hltp.c makecode_map.c
+SRCS= proj.c list.c queue.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 uart.c hltp.c makecode_map.c
 
 CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D __LCOM_OPTIMIZED_
 
Index: proj/TB.mk
===================================================================
--- proj/TB.mk	(revision 274)
+++ proj/TB.mk	(revision 275)
@@ -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 test7.c uart.c hltp.c makecode_map.c
+SRCS= proj.c list.c queue.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 uart.c hltp.c makecode_map.c
 
 CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D TELMO #-D __LCOM_OPTIMIZED_
 
