Skip to content

Commit

Permalink
rtc basics #125
Browse files Browse the repository at this point in the history
  • Loading branch information
double-fault committed Jan 1, 2017
1 parent f9b5aa2 commit 7c0e2cf
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/sh/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
#include <poweroff/sbin_cmd_poweroff.h>
#include <boneshell/boneshell.h>
#include <assertk.h>
#include <drv/driver.h>
#include <drv/driver.h>
#include <drv/rtc/rtc.h>
#include <sh/built-in/exit/exit.h>


Expand Down Expand Up @@ -82,7 +83,7 @@ void init_terminal()
assertkm(device_initalized(KBD_DRIVER_INDEX) , "Keyboard not intalized for starting shell!");
TERMINAL_MODE=true;
//cmds[CMD_BONEOS_LOGO_INDEX]->handler("boneos_logo");
printk ("%s release %s started.\n", VAR_OSNAME, VAR_RELEASE);
printk ("%s release %s started at %x:%x:%x UTC.\n", VAR_OSNAME, VAR_RELEASE, rtc_get_hour(), rtc_get_minute(), rtc_get_second());
cmds[CMD_BONESHELL_INDEX]->handler("boneshell");
TERMINAL_MODE=false;
}
Expand Down
12 changes: 12 additions & 0 deletions include/platform/pc/drv/rtc/rtc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _DRV_RTC_H_
#define _DRV_RTC_H_

uint8_t rtc_get_year();
uint8_t rtc_get_month();
uint8_t rtc_get_day();
uint8_t rtc_get_hour();
uint8_t rtc_get_minute ();
uint8_t rtc_get_second();
void rtc_print_time ();

#endif // _DRV_RTC_H_
1 change: 1 addition & 0 deletions platform/pc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CSRCS = \
drv/ps2/kbd/scancodes.c \
drv/ps2/kbd/kbd_layouts/scancodes_usa.c \
drv/ps2/kbd/utils.c \
drv/rtc/rtc.c \
io/io.c


Expand Down
77 changes: 77 additions & 0 deletions platform/pc/drv/rtc/rtc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
** This file is part of BoneOS.
**
** BoneOS is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
** BoneOS is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with BoneOS. If not, see <http://www.gnu.org/licenses/>.
**
** @main_author : Ashish Ahuja
**
** @contributors:
** Ashish Ahuja<Fortunate-MAN>: start
**/

#include <cpu/interrupts/interrupts.h>
#include <misc/status_codes.h>
#include <cpu/interrupts/irq.h>
#include <libc/unistd/sleep/sleep.h>
#include <libc/stdlib/stdlib.h>
#include <stdio/stdio.h>
#include <drv/driver.h>
#include <drv/rtc/rtc.h>
#include <io/io.h>
#include <stdint.h>
#include <stddef.h>

uint8_t rtc_get_year()
{
outb(0x70, 0x09);
return inb(0x71);
}

uint8_t rtc_get_month()
{
outb(0x70, 0x08);
return inb(0x71);
}

uint8_t rtc_get_day()
{
outb(0x70, 0x07);
return inb(0x71);
}

uint8_t rtc_get_hour()
{
outb(0x70, 0x04);
return inb(0x71);
}

uint8_t rtc_get_minute ()
{
outb(0x70, 0x02);
return inb (0x71);
}

uint8_t rtc_get_second()
{
outb(0x70, 0x00);
return inb(0x71);
}

void rtc_print_time ()
{
printk("20%x, %x. %x. %x:%x:%x\n",
rtc_get_year(), rtc_get_month(), rtc_get_day(),
rtc_get_hour(), rtc_get_minute(), rtc_get_second());
}

0 comments on commit 7c0e2cf

Please sign in to comment.