Index: proj/include/errors.h
===================================================================
--- proj/include/errors.h	(revision 233)
+++ proj/include/errors.h	(revision 234)
@@ -4,7 +4,7 @@
 /** @brief Error Codes */
 enum errors {
     SUCCESS = 0,        /** @brief Sucessful */
-    NULL_PTR,           /** @brief Null Pointer Error */
+    NULL_PTR = 250,     /** @brief Null Pointer Error */
     LCF_ERROR,          /** @brief Error originated on LCF */
     SBCR_ERROR,         /** @brief Error on Subscribing Interrupt */
     UNSBCR_ERROR,       /** @brief Error on Unsubscring Interrupt*/
Index: proj/include/rtc.h
===================================================================
--- proj/include/rtc.h	(nonexistent)
+++ proj/include/rtc.h	(revision 234)
@@ -0,0 +1,46 @@
+#ifndef RTC_H_INCLUDED
+#define RTC_H_INCLUDED
+
+#include <stdint.h>
+
+/**
+ * @brief Subscribes RTC Interrupts
+ * @param interrupt_bit Bit of Interrupt Vector that will be set when RTC Interrupt is pending
+ * @param interrupt_id RTC Interrupt ID to specify the RTC Interrupt in other calls
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
+int (subscribe_rtc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
+
+int (rtc_read_register)(uint32_t reg, uint8_t *data);
+
+int (rtc_write_register)(uint32_t reg, uint8_t data);
+
+/**
+ * @brief Checks if there's an update in progress.
+ * @return  The value of the flag UIP, or ERROR_CODE if error occurs.
+ */
+int (rtc_check_update)(void);
+
+/**
+ * @brief Enables/Disables updates of time/date registers.
+ * @param   on  zero to disable, any other value to enable
+ * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int (rtc_set_updates)(int on);
+
+/**
+ * @brief Reads time from RTC.
+ * @param   time  Pointer to array of 3 bytes to store the information about time (hours, minutes, seconds)
+ * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int (rtc_read_time)(uint8_t *time);
+
+/**
+ * @brief Reads date from RTC.
+ * @param   date  Pointer to array of 4 bytes to store the information about date (year, month, day, weekday)
+ * @return  ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ */
+int (rtc_read_date)(uint8_t *date);
+
+#endif /* end of include guard: RTC_H_INCLUDED */

Property changes on: proj/include/rtc.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/include/rtc_macros.h
===================================================================
--- proj/include/rtc_macros.h	(nonexistent)
+++ proj/include/rtc_macros.h	(revision 234)
@@ -0,0 +1,62 @@
+#ifndef RTC_MACROS_H_INCLUDED
+#define RTC_MACROS_H_INCLUDED
+
+#include <lcom/lcf.h>
+
+// RTC IRQ Line
+
+#define KBC_IRQ   8  /* @brief KBC IRQ Line */
+
+// RTC Ports
+
+#define RTC_ADDR_REG        0x70
+#define RTC_DATA_REG        0x71
+
+// RTC Registers (Byte)
+
+#define RTC_SEC             0
+#define RTC_SEC_ALARM       1
+#define RTC_MIN             2
+#define RTC_MIN_ALARM       3
+#define RTC_HOUR            4
+#define RTC_HOUR_ALARM      5
+#define RTC_WEEK_DAY        6
+#define RTC_MONTH_DAY       7
+#define RTC_MONTH           8
+#define RTC_YEAR            9
+#define RTC_REG_A           10
+#define RTC_REG_B           11
+#define RTC_REG_C           12
+#define RTC_REG_D           13
+
+// Register A
+
+#define RS0     BIT(0)  /** @brief Rate selector */
+#define RS1     BIT(1)  /** @brief Rate selector */
+#define RS2     BIT(2)  /** @brief Rate selector */
+#define RS3     BIT(3)  /** @brief Rate selector */
+#define UIP     BIT(7)  /** @brief Update in progress */
+
+// Register B
+
+#define DSE             BIT(0)  /** @brief Enable Daylight Saving Time */
+#define HOUR_FORM       BIT(1)  /** @brief Set to 1 for 24h format (0-23), 0 to 12h format (1-12) */
+#define DM              BIT(2)  /** @brief Set to 1 if registers are in binary, 0 if in BCD */
+#define SQWE            BIT(3)  /** @brief Enable square wave generation */
+#define UIE             BIT(4)  /** @brief Enable Update interrupts */
+#define AIE             BIT(5)  /** @brief Enable alarm interrupts */
+#define PIE             BIT(6)  /** @brief Enable periodic interrupts */
+#define SET             BIT(7)  /** @brief Set to 1 to inhibit updates of time/date registers */
+
+// Register C
+
+#define UF      BIT(4)  /** @brief Update Interrupt Pending */
+#define AF      BIT(5)  /** @brief Alarm Interrupt Pending */
+#define PF      BIT(6)  /** @brief Periodic Interrupt Pending */
+#define IRQF    BIT(7)  /** @brief IRQ Line Active */
+
+// Register D
+
+#define VRT     BIT(7)  /** @brief Valid RAM/time - If set to 0 RTC reading aren't valid */
+
+#endif /* end of include guard: RTC_MACROS_H_INCLUDED */

Property changes on: proj/include/rtc_macros.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/include/utils.h
===================================================================
--- proj/include/utils.h	(revision 233)
+++ proj/include/utils.h	(revision 234)
@@ -1,6 +1,9 @@
 #ifndef UTILS_H_INCLUDED
 #define UTILS_H_INCLUDED
 
+#define BCD_FIRST(n)     (n >> 4)       /** @brief Get first digit (leftmost digit) of 8-bit BCD */
+#define BCD_SECOND(n)    (n & 0x0F)     /** @brief Get second digit (rightmost digit) of 8-bit BCD */
+
 /**
  * @brief Gets the least significant byte of a 16-bit variable
  * @param val 16-bit variable
Index: proj/src/proj.c
===================================================================
--- proj/src/proj.c	(revision 233)
+++ proj/src/proj.c	(revision 234)
@@ -11,6 +11,7 @@
 #include "keyboard.h"
 #include "mouse.h"
 #include "graph.h"
+#include "rtc.h"
 #include "interrupts_func.h"
 
 #include "graph.h"
@@ -84,6 +85,7 @@
     }
 
     #ifdef DIOGO
+        /*
         graph_clear_screen();
 
         rectangle_t *rect = rectangle_ctor(0,0,400,100);
@@ -132,8 +134,18 @@
         if(list_dtor(l)) printf("COULD NOT DESTRUCT LIST\n");
 
 
-        tickdelay(micros_to_ticks(1000000));
+        tickdelay(micros_to_ticks(1000000));*/
 
+        // RTC
+        uint8_t date[4], time[3];
+
+        if (rtc_read_time(time)) return 1;
+
+        if (rtc_read_date(date)) return 1;
+
+        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]);
     #endif
 
     #ifdef TELMO
Index: proj/src/rtc.c
===================================================================
--- proj/src/rtc.c	(nonexistent)
+++ proj/src/rtc.c	(revision 234)
@@ -0,0 +1,104 @@
+#include "rtc.h"
+#include "rtc_macros.h"
+
+#include <lcom/lcf.h>
+
+#include "utils.h"
+#include "errors.h"
+
+int (subscribe_rtc_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
+    if (interrupt_id == NULL) return NULL_PTR;
+    *interrupt_id = interrupt_bit;
+    if (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id)) return SBCR_ERROR;
+    return SUCCESS;
+}
+
+int (rtc_read_register)(uint32_t reg, uint8_t *data) {
+    if (sys_outb(RTC_ADDR_REG, reg)) return WRITE_ERROR;
+
+    if (util_sys_inb(RTC_DATA_REG, data)) return READ_ERROR;
+
+    return SUCCESS;
+}
+
+int (rtc_write_register)(uint32_t reg, uint8_t data) {
+    if (sys_outb(RTC_ADDR_REG, reg)) return WRITE_ERROR;
+
+    if (sys_outb(RTC_DATA_REG, data)) return WRITE_ERROR;
+
+    return SUCCESS;
+}
+
+int (rtc_check_update)(void) {
+    uint8_t data;
+    int r;
+
+    if ((r = rtc_read_register(RTC_REG_A, &data))) return r;
+
+    return (data & UIP) != 0;
+}
+
+int (rtc_set_updates)(int on) {
+    uint8_t data;
+    int r;
+    if (on) {
+        if ((r = rtc_read_register(RTC_REG_B, &data))) return r;
+
+        data &= ~SET;
+
+        if ((r = rtc_write_register(RTC_REG_B, data))) return r;
+
+    } else {
+        while (rtc_check_update());
+
+        if ((r = rtc_read_register(RTC_REG_B, &data))) return r;
+
+        data |= SET;
+
+        if ((r = rtc_write_register(RTC_REG_B, data))) return r;
+    }
+    return SUCCESS;
+}
+
+int (rtc_read_time)(uint8_t *time) {
+
+    int r;
+    //if ((r = rtc_set_updates(false))) return r;
+    while (rtc_check_update());
+
+    uint8_t hour, min, sec;
+
+    if ((r = rtc_read_register(RTC_SEC, &sec)))    return r;
+    if ((r = rtc_read_register(RTC_MIN, &min)))    return r;
+    if ((r = rtc_read_register(RTC_HOUR, &hour)))  return r;
+
+    //if ((r = rtc_set_updates(true))) return r;
+
+    time[0] = BCD_FIRST(sec)*10   + BCD_SECOND(sec);
+    time[1] = BCD_FIRST(min)*10   + BCD_SECOND(min);
+    time[2] = BCD_FIRST(hour)*10  + BCD_SECOND(hour);
+
+    return SUCCESS;
+}
+
+int (rtc_read_date)(uint8_t *date) {
+    int r;
+    //if ((r = rtc_set_updates(false))) return r;
+    while (rtc_check_update());
+
+    uint8_t year, month, day, weekday;
+
+    if ((r = rtc_read_register(RTC_WEEK_DAY,    &weekday)))     return r;
+    if ((r = rtc_read_register(RTC_MONTH_DAY,   &day)))         return r;
+    if ((r = rtc_read_register(RTC_MONTH,       &month)))       return r;
+    if ((r = rtc_read_register(RTC_YEAR,        &year)))        return r;
+
+    //if ((r = rtc_set_updates(true))) return r;
+
+    date[0] = weekday;
+    date[1] = BCD_FIRST(day)*10     + BCD_SECOND(day);
+    date[2] = BCD_FIRST(month)*10   + BCD_SECOND(month);
+    date[3] = BCD_FIRST(year)*10    + BCD_SECOND(year);
+
+    return SUCCESS;
+}

Property changes on: proj/src/rtc.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/DR.mk
===================================================================
--- proj/DR.mk	(revision 233)
+++ proj/DR.mk	(revision 234)
@@ -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
+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
 
 CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D DIOGO -D __LCOM_OPTIMIZED_
 
Index: proj/Makefile
===================================================================
--- proj/Makefile	(revision 233)
+++ proj/Makefile	(revision 234)
@@ -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
+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
 
 CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D __LCOM_OPTIMIZED_
 
Index: proj/TB.mk
===================================================================
--- proj/TB.mk	(revision 233)
+++ proj/TB.mk	(revision 234)
@@ -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
+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
 
 CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D TELMO #-D __LCOM_OPTIMIZED_
 
