Index: lab7/lab7
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/x-executable
Index: lab7/lab7
===================================================================
--- lab7/lab7	(nonexistent)
+++ lab7/lab7	(revision 252)

Property changes on: lab7/lab7
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+application/x-executable
\ No newline at end of property
Index: lab7/lab7.conf
===================================================================
--- lab7/lab7.conf	(nonexistent)
+++ lab7/lab7.conf	(revision 252)
@@ -0,0 +1,32 @@
+service lab7
+{
+	system
+		DEVIO
+		IRQCTL
+		IOPENABLE
+		;
+	ipc
+		SYSTEM
+		rs
+		vm
+		pm
+		vfs
+		;
+	io
+		40:4
+		60
+		61
+		64
+		70:2
+		3f8:8
+		;		
+	irq
+		0         # TIMER 0 IRQ 
+		1         # KBD IRQ
+		4         # COM1
+		8         # RTC_IRQ
+		12        # AUX IRQ
+		;	
+	uid	0		
+		;
+};

Property changes on: lab7/lab7.conf
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/include/uart.h
===================================================================
--- proj/include/uart.h	(revision 251)
+++ proj/include/uart.h	(revision 252)
@@ -35,20 +35,19 @@
 } 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     );
 
+int uart_enable_int_rx (int base_addr);
+int uart_disable_int_rx(int base_addr);
+int uart_enable_int_tx (int base_addr);
+int uart_disable_int_tx(int base_addr);
+
 int uart_get_char_poll   (int base_addr, uint8_t *p);
 int uart_send_char_poll  (int base_addr, uint8_t  c);
-int uart_send_memory_poll(int base_addr, void *str, size_t n);
 
 #endif //UART_H_INCLUDED
Index: proj/src/proj.c
===================================================================
--- proj/src/proj.c	(revision 251)
+++ proj/src/proj.c	(revision 252)
@@ -162,11 +162,11 @@
         unsigned long stop = 2;
         long parity = 0;
         unsigned long rate = 9600;
-        unsigned char tx = 1;
-        int stringc = 2;
+        unsigned char tx = 0; (void)tx;
+        int stringc = 2; (void)stringc;
         char *strings[] = {"Hello", "world"}; (void)strings;
+        //if((r = ser_test_set(COM1_ADDR, bits, stop, parity, rate))) return r;
         //if((r = ser_test_conf(COM1_ADDR))) return r;
-        //if((r = ser_test_set(COM1_ADDR, bits, stop, parity, rate))) return r;
         if((r = ser_test_poll(COM1_ADDR, tx, bits, stop, parity, rate, stringc, strings))) return r;
         printf("DONE\n");
     #endif
Index: proj/src/test7.c
===================================================================
--- proj/src/test7.c	(revision 251)
+++ proj/src/test7.c	(revision 252)
@@ -34,6 +34,8 @@
                     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;
 		if((ret = uart_get_char_poll(base_addr, &c))) return ret;
@@ -44,11 +46,13 @@
 		printf("%c\n", (char)c);
 	}else{
 		for(int i = 0; i < stringc; ++i){
-			size_t sz = strlen(strings[i]);
-			if((ret = uart_send_memory_poll(base_addr, strings[i], sz))) return ret;
-			if(i+1 != stringc) if((ret = uart_send_memory_poll(base_addr, " ", 1))) return ret;
+			for(int j = 0; strings[i][j] != 0; ++j)
+				if((ret = uart_send_char_poll(base_addr, strings[i][j])))
+					return ret;
+			if(i+1 != stringc)
+				if((ret = uart_send_char_poll(base_addr, ' '))) return ret;
 		}
-		if((ret = uart_send_memory_poll(base_addr, ".", 1))) return ret;
+		if((ret = uart_send_char_poll(base_addr, '.'))) return ret;
 	}
 	return SUCCESS;
 }
Index: proj/src/uart.c
===================================================================
--- proj/src/uart.c	(revision 251)
+++ proj/src/uart.c	(revision 252)
@@ -44,20 +44,20 @@
 #define UART_GET_DLM(n)                         (((n)>>8)&0xFF)
 
 /// IER
-#define UART_INT_EN_RECEIVED_DATA_POS           0
-#define UART_INT_EN_TRANSMITTER_EMPTY_POS       1
+#define UART_INT_EN_RX_POS                      0
+#define UART_INT_EN_TX_POS                      1
 #define UART_INT_EN_RECEIVER_LINE_STAT_POS      2
 #define UART_INT_EN_MODEM_STAT_POS              3
 
-#define UART_INT_EN_RECEIVED_DATA               (BIT(0))
-#define UART_INT_EN_TRANSMITTER_EMPTY           (BIT(1))
+#define UART_INT_EN_RX                          (BIT(0))
+#define UART_INT_EN_TX                          (BIT(1))
 #define UART_INT_EN_RECEIVER_LINE_STAT          (BIT(2))
 #define UART_INT_EN_MODEM_STAT                  (BIT(3))
 
-#define UART_INT_EN_GET_RECEIVED_DATA(n)        (((n)&UART_INT_EN_RECEIVED_DATA     )>>UART_INT_EN_RECEIVED_DATA_POS     )
-#define UART_INT_EN_GET_TRANSMITTER_EMPTY(n)    (((n)&UART_INT_EN_TRANSMITTER_EMPTY )>>UART_INT_EN_TRANSMITTER_EMPTY_POS )
-#define UART_INT_EN_GET_RECEIVER_LINE_STAT(n)   (((n)&UART_INT_EN_RECEIVER_LINE_STAT)>>UART_INT_EN_RECEIVER_LINE_STAT_POS)
-#define UART_INT_EN_GET_MODEM_STAT(n)           (((n)&UART_INT_EN_MODEM_STAT        )>>UART_INT_EN_MODEM_STAT_POS        )
+#define UART_GET_INT_EN_RX(n)                   (((n)&UART_INT_EN_RX                )>>UART_INT_EN_RX_POS                )
+#define UART_GET_INT_EN_TX(n)                   (((n)&UART_INT_EN_TX                )>>UART_INT_EN_TX_POS                )
+#define UART_GET_INT_EN_RECEIVER_LINE_STAT(n)   (((n)&UART_INT_EN_RECEIVER_LINE_STAT)>>UART_INT_EN_RECEIVER_LINE_STAT_POS)
+#define UART_GET_INT_EN_MODEM_STAT(n)           (((n)&UART_INT_EN_MODEM_STAT        )>>UART_INT_EN_MODEM_STAT_POS        )
 
 /// LSR
 #define UART_RECEIVER_READY_POS                 0
@@ -69,14 +69,64 @@
 #define UART_GET_RECEIVER_READY(n)              (((n)&UART_RECEIVER_READY           )>>UART_RECEIVER_READY_POS           )
 #define UART_GET_TRANSMITTER_EMPTY(n)           (((n)&UART_TRANSMITTER_EMPTY        )>>UART_TRANSMITTER_EMPTY_POS        )
 
+static void uart_parse_config(uart_config *config){
+    /// LCR
+    config->bits_per_char          = UART_GET_BITS_PER_CHAR     (config->lcr);
+    config->stop_bits              = UART_GET_STOP_BITS         (config->lcr);
+    config->parity                 = UART_GET_PARITY            (config->lcr); if((config->parity & BIT(0)) == 0) config->parity = uart_parity_none;
+    config->break_control          = UART_GET_BREAK_CONTROL     (config->lcr);
+    config->dlab                   = UART_GET_DLAB              (config->lcr);
+    /// IER
+    config->received_data_int      = UART_GET_INT_EN_RX                (config->ier);
+    config->transmitter_empty_int  = UART_GET_INT_EN_TX                (config->ier);
+    config->receiver_line_stat_int = UART_GET_INT_EN_RECEIVER_LINE_STAT(config->ier);
+    config->modem_stat_int         = UART_GET_INT_EN_MODEM_STAT        (config->ier);
+    /// DIV LATCH
+    config->divisor_latch          = UART_GET_DIV_LATCH(config->dlm, config->dll);
+}
+
+static int uart_get_lcr(int base_addr, uint8_t *p){
+    return util_sys_inb(base_addr+UART_LCR, p);
+}
+static int uart_set_lcr(int base_addr, uint8_t config){
+    if(sys_outb(base_addr+UART_LCR, config)) return WRITE_ERROR;
+    return SUCCESS;
+}
+static int uart_get_lsr(int base_addr, uint8_t *p){
+    return util_sys_inb(base_addr+UART_LSR, p);
+}
+
+static int uart_enable_divisor_latch(int base_addr){
+    int ret = SUCCESS;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
+    return uart_set_lcr(base_addr, conf | UART_DLAB);
+}
+static int uart_disable_divisor_latch(int base_addr){
+    int ret = SUCCESS;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
+    return uart_set_lcr(base_addr, conf & (~UART_DLAB));
+}
+
+static int uart_get_ier(int base_addr, uint8_t *p){
+    int ret;
+    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
+    return util_sys_inb(base_addr+UART_IER, p);
+}
+static int uart_set_ier(int base_addr, uint8_t n){
+    int ret;
+    if((ret = uart_disable_divisor_latch(base_addr))) return ret;
+    if(sys_outb(base_addr+UART_IER, n)) return WRITE_ERROR;
+    return SUCCESS;
+}
+
 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->lcr))) return ret;
+    if((ret = uart_get_lcr(base_addr, &config->lcr))) return ret;
 
-    if((ret = util_sys_inb(base_addr+UART_IER, &config->ier))) return ret;
+    if((ret = uart_get_ier(base_addr, &config->ier))) 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;
@@ -86,21 +136,6 @@
     uart_parse_config(config);
     return ret;
 }
-void uart_parse_config(uart_config *config){
-    /// LCR
-    config->bits_per_char          = UART_GET_BITS_PER_CHAR     (config->lcr);
-    config->stop_bits              = UART_GET_STOP_BITS         (config->lcr);
-    config->parity                 = UART_GET_PARITY            (config->lcr); if((config->parity & BIT(0)) == 0) config->parity = uart_parity_none;
-    config->break_control          = UART_GET_BREAK_CONTROL     (config->lcr);
-    config->dlab                   = UART_GET_DLAB              (config->lcr);
-    /// IER
-    config->received_data_int      = UART_INT_EN_GET_RECEIVED_DATA     (config->ier);
-    config->transmitter_empty_int  = UART_INT_EN_GET_TRANSMITTER_EMPTY (config->ier);
-    config->receiver_line_stat_int = UART_INT_EN_GET_RECEIVER_LINE_STAT(config->ier);
-    config->modem_stat_int         = UART_INT_EN_GET_MODEM_STAT        (config->ier);
-    /// DIV LATCH
-    config->divisor_latch          = UART_GET_DIV_LATCH(config->dlm, config->dll);
-}
 void uart_print_config(uart_config config){
 
     printf("%s configuration:\n", (config.base_addr == COM1_ADDR ? "COM1" : "COM2"));
@@ -119,28 +154,13 @@
         (config.transmitter_empty_int ? "ENABLED":"DISABLED"));
 }
 
-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){
-    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;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
     conf = (conf & (~UART_BITS_PER_CHAR)) | bits_per_char;
-    return uart_write_config(base_addr, conf);
+    return uart_set_lcr(base_addr, conf);
 }
 int uart_set_stop_bits(int base_addr, uint8_t stop){
     if(stop != 1 && stop != 2) return INVALID_ARG;
@@ -147,16 +167,16 @@
     int ret = SUCCESS;
     stop -= 1;
     stop = (stop&1)<<2;
-    uint8_t conf; if((ret = util_sys_inb(base_addr+UART_LCR, &conf))) return ret;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
     conf = (conf & (~UART_STOP_BITS)) | stop;
-    return uart_write_config(base_addr, conf);
+    return uart_set_lcr(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;
+    uint8_t conf; if((ret = uart_get_lcr(base_addr, &conf))) return ret;
     conf = (conf & (~UART_PARITY)) | parity;
-    return uart_write_config(base_addr, conf);
+    return uart_set_lcr(base_addr, conf);
 }
 int uart_set_bit_rate(int base_addr, float bit_rate){
     int ret = SUCCESS;
@@ -170,35 +190,57 @@
     return SUCCESS;
 }
 
-/// PRIVATE
-int uart_get_lsr(int base_addr, uint8_t *p){
-    return util_sys_inb(base_addr+UART_LSR, p);
-}
-/**
- * @brief Get char from RBR.
- */
-int uart_get_char(int base_addr, uint8_t *p){
+static int uart_get_char(int base_addr, uint8_t *p){
     int ret;
     if((ret = uart_disable_divisor_latch(base_addr))) return ret;
     return util_sys_inb(base_addr+UART_RBR, p);
 }
-int uart_send_char(int base_addr, uint8_t c){
+static int uart_send_char(int base_addr, uint8_t c){
     int ret;
     if((ret = uart_disable_divisor_latch(base_addr))) return ret;
-    if(sys_outb(base_addr, c)) return WRITE_ERROR;
+    if(sys_outb(base_addr+UART_THR, c)) return WRITE_ERROR;
     return SUCCESS;
 }
-int uart_receiver_ready(int base_addr){
+static int uart_receiver_ready(int base_addr){
     uint8_t lsr;
     if(uart_get_lsr(base_addr, &lsr)) return false;
     return UART_GET_RECEIVER_READY(lsr);
 }
-int uart_transmitter_empty(int base_addr){
+static int uart_transmitter_empty(int base_addr){
     uint8_t lsr;
     if(uart_get_lsr(base_addr, &lsr)) return false;
     return UART_GET_TRANSMITTER_EMPTY(lsr);
 }
-///PUBLIC
+
+int uart_enable_int_rx(int base_addr){
+    int ret;
+    uint8_t ier;
+    if((ret = uart_get_ier(base_addr, &ier))) return ret;
+    ier |= UART_INT_EN_RX;
+    return uart_set_ier(base_addr, ier);
+}
+int uart_disable_int_rx(int base_addr){
+    int ret;
+    uint8_t ier;
+    if((ret = uart_get_ier(base_addr, &ier))) return ret;
+    ier &= ~UART_INT_EN_RX;
+    return uart_set_ier(base_addr, ier);
+}
+int uart_enable_int_tx(int base_addr){
+    int ret;
+    uint8_t ier;
+    if((ret = uart_get_ier(base_addr, &ier))) return ret;
+    ier |= UART_INT_EN_TX;
+    return uart_set_ier(base_addr, ier);
+}
+int uart_disable_int_tx(int base_addr){
+    int ret;
+    uint8_t ier;
+    if((ret = uart_get_ier(base_addr, &ier))) return ret;
+    ier &= ~UART_INT_EN_TX;
+    return uart_set_ier(base_addr, ier);
+}
+
 int uart_get_char_poll(int base_addr, uint8_t *p){
     int ret;
     while(!uart_receiver_ready(base_addr)){}
@@ -211,11 +253,3 @@
     if((ret = uart_send_char(base_addr, c))) return ret;
     return SUCCESS;
 }
-int uart_send_memory_poll(int base_addr, void *str, size_t n){
-    int ret;
-    uint8_t *p = str;
-    for(size_t i = 0; i < n; ++i, ++p){
-        if((ret = uart_send_char_poll(base_addr, *p))) return ret;
-    }
-    return SUCCESS;
-}
Index: proj/protocol2.md
===================================================================
--- proj/protocol2.md	(nonexistent)
+++ proj/protocol2.md	(revision 252)
@@ -0,0 +1,47 @@
+# Non-critical serial port protocol
+
+Transmission/reception is processed at 38400 bps, with chars of 8 bits and even parity.
+
+OK = 0xFF
+
+FAIL = 0x00
+
+## Transmission
+
+Transmission is performed on request by the program. It is done in a synchronous fashion. When starting a transmission, reception interrupt notifications are suspended. On ending, reception interrupt notifications are re-activated.
+
+### Transmission of a char
+
+1. 1 polls the readiness of THR in intervals of 10 microseconds, one at the beginning and up to 2 retries (up to 3 polling operations, and 20 microseconds). If after all the retries 1 has not yet sent the char, transmission is aborted.
+
+2. If the char is transmitted, 1 expects 2 to answer with OK. 1 polls the fullness of RBR in intervals of 10 microseconds, one at the beginning and up to 2 retries. If after all the retries 1 has not yet received the answer, transmission is aborted.
+
+3. If 1 gets the answer, it counts the number of 1s. If #1 > 4, it is considered that it was accepted. Otherwise, it attempts to resend another 2 times.
+
+### Transmission of a string
+
+If the string has more than 1024 chars, transmission is not even started.
+
+1. For each char in the string, transmit them, plus a start symbol 0x80 and an end symbol 0xEF. If transmission fails for a given char, transmission of the string is aborted, and none of the following chars in the same transmission request are transmitted. The transmitter waits at least
+
+2. If all symbols are transmitted correctly, transmission is successfully terminated.
+
+## Reception
+
+Reception is made through interrupts. On a reception interrupt, 2 must handle the interrupt. On a reception interrupt, reception interrupt notifications are suspended, and on ending a reception notifications are re-activated.
+
+### Reception of a char
+
+1. Upon getting a reception interrupt, 2 grabs the char, and then polls the readiness of the THR in intervals of 10 microseconds, one at the beginning and up to 2 retries. If after 2 retries 2 has not sent the char, transmission is aborted.
+
+2. If transmission is successful, 2 expects 1 to answer the OK symbol 0xFF, using only step 1. to get the OK. If the received symbol has less or equal to 4 bits set to 1, transmission is aborted.
+
+3. If the received OK has at least 4 bits set to 1 then it is accepted.
+
+### Reception of a string
+
+1. 2 expects the first char to be the start char. If it is not, transmission is aborted.
+
+2. If the first char is correct, all chars are received. If one of the char receptions fails (timeout), reception fails. If after receiving 1024 chars the end symbol is not received, transmission is aborted.
+
+3. If all receptions are successful and the end symbol is received, transmission is successful.

Property changes on: proj/protocol2.md
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
