Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
abinade2
kernel
Commits
c9ffa12a
Commit
c9ffa12a
authored
7 years ago
by
Divyam Khandelwal
Browse files
Options
Downloads
Patches
Plain Diff
RTC virtualised
parent
17bd229f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
student-distrib/rtc.c
+83
-48
83 additions, 48 deletions
student-distrib/rtc.c
student-distrib/rtc.h
+8
-1
8 additions, 1 deletion
student-distrib/rtc.h
with
91 additions
and
49 deletions
student-distrib/rtc.c
+
83
−
48
View file @
c9ffa12a
#include
"rtc.h"
#include
"rtc.h"
/* Set interrupt flag */
/* Set interrupt flag */
//
interrupt_flag = 1;
interrupt_flag
=
1
;
/* For virtualisation */
rtc_active
[
MAX_TERMINAL
]
=
{
0
,
0
,
0
};
rtc_flag
[
MAX_TERMINAL
]
=
{
1
,
1
,
1
};
rtc_counter
[
MAX_TERMINAL
]
=
{
0
,
0
,
0
};
rtc_init_counter
[
MAX_TERMINAL
]
=
{
0
,
0
,
0
};
/* rtc_init()
/* rtc_init()
* Inputs: void
* Inputs: void
...
@@ -14,7 +19,7 @@ void rtc_init(void)
...
@@ -14,7 +19,7 @@ void rtc_init(void)
{
{
uint8_t
prev
;
uint8_t
prev
;
//int32_t freq;
//
int32_t freq;
/* select register B, and disable NMI */
/* select register B, and disable NMI */
outb
(
DISABLE_NMI_B
,
RTC_PORT
);
outb
(
DISABLE_NMI_B
,
RTC_PORT
);
...
@@ -26,6 +31,9 @@ void rtc_init(void)
...
@@ -26,6 +31,9 @@ void rtc_init(void)
outb
(
prev
|
BIT_SIX
,
RTC_DATA
);
outb
(
prev
|
BIT_SIX
,
RTC_DATA
);
/* Enable interrupts */
/* Enable interrupts */
// freq = 2;
// rtc_write(NULL, &freq, 4);
enable_irq
(
RTC_IRQ
);
enable_irq
(
RTC_IRQ
);
}
}
...
@@ -39,12 +47,26 @@ void rtc_init(void)
...
@@ -39,12 +47,26 @@ void rtc_init(void)
*/
*/
void
rtc_interrupt
(
void
)
void
rtc_interrupt
(
void
)
{
{
int
i
;
/* logic to enable more than one RTC interrupt */
/* logic to enable more than one RTC interrupt */
outb
(
0x0C
,
0x70
);
/* 0x0C = DATA to write, 0x70 = port */
outb
(
0x0C
,
0x70
);
/* 0x0C = DATA to write, 0x70 = port */
inb
(
0x71
);
/* read from port 0x71 (RTC Data port) */
inb
(
0x71
);
/* read from port 0x71 (RTC Data port) */
/* Clear interrupt flag */
/* Clear interrupt flag */
interrupt_flag
=
0
;
for
(
i
=
0
;
i
<
MAX_TERMINAL
;
i
++
)
{
rtc_counter
[
i
]
--
;
/* Check if counter has reached zero */
if
(
rtc_counter
[
i
]
==
0
)
{
/* Clear interrupt flag */
rtc_flag
[
i
]
=
0
;
/* Reset counter */
rtc_counter
[
i
]
=
rtc_init_counter
[
i
];
}
}
// interrupt_flag = 0;
return
;
return
;
}
}
...
@@ -58,11 +80,15 @@ void rtc_interrupt(void)
...
@@ -58,11 +80,15 @@ void rtc_interrupt(void)
*/
*/
int32_t
rtc_read
(
int32_t
fd
,
void
*
buf
,
int32_t
nbytes
)
int32_t
rtc_read
(
int32_t
fd
,
void
*
buf
,
int32_t
nbytes
)
{
{
/* Set flag */
/* Set flag */
interrupt_flag
=
1
;
rtc_flag
[
running_terminal
]
=
1
;
//interrupt_flag = 1;
sti
();
/* Wait until interrupt handler clears flag */
/* Wait until interrupt handler clears flag */
while
(
interrupt_flag
);
while
(
rtc_flag
[
running_terminal
]);
cli
();
return
0
;
return
0
;
}
}
...
@@ -103,37 +129,41 @@ int32_t rtc_write(int32_t fd, const void* buf, int32_t nbytes)
...
@@ -103,37 +129,41 @@ int32_t rtc_write(int32_t fd, const void* buf, int32_t nbytes)
if
(
valid_freq
!=
1
)
if
(
valid_freq
!=
1
)
return
-
1
;
return
-
1
;
/* Translate frequency to rate */
rtc_counter
[
running_terminal
]
=
INIT_FREQ
/
freq
;
temp_freq
=
freq
;
rtc_init_counter
[
running_terminal
]
=
rtc_counter
[
running_terminal
]
;
for
(
i
=
1
;
i
<=
MAX_FREQ_POW
;
i
++
)
// /* Translate frequency to rate */
{
temp_freq
=
temp_freq
>>
1
;
if
((
temp_freq
&
bit_mask
)
==
1
)
// temp_freq = freq;
{
rate
=
RATE_OFFSET
-
i
;
break
;
}
//temp_freq = temp_freq >> 1;
}
/* Set the rate */
// for (i = 1; i <= MAX_FREQ_POW; i++)
rate
&=
0x0F
;
// {
// temp_freq = temp_freq >> 1;
/* Disable interrupts */
// if ((temp_freq & bit_mask) == 1)
cli
();
// {
/* set index to register A, disable NMI */
// rate = RATE_OFFSET - i;
outb
(
DISABLE_NMI_A
,
RTC_PORT
);
// break;
/* get initial value of register A */
// }
prev
=
inb
(
RTC_DATA
);
// //temp_freq = temp_freq >> 1;
/* reset index to A */
// }
outb
(
DISABLE_NMI_A
,
RTC_PORT
);
/* write only our rate to A. Note, rate is the bottom 4 bits. */
// /* Set the rate */
outb
((
prev
&
0xF0
)
|
rate
,
RTC_DATA
);
// rate &= 0x0F;
/* Enable interrupts */
sti
();
// /* Disable interrupts */
// cli();
// /* set index to register A, disable NMI */
// outb(DISABLE_NMI_A, RTC_PORT);
// /* get initial value of register A */
// prev = inb(RTC_DATA);
// /* reset index to A */
// outb(DISABLE_NMI_A, RTC_PORT);
// /* write only our rate to A. Note, rate is the bottom 4 bits. */
// outb((prev & 0xF0) | rate, RTC_DATA);
// /* Enable interrupts */
// sti();
/* Return number of bytes written */
/* Return number of bytes written */
return
FOUR_BYTES
;
return
FOUR_BYTES
;
...
@@ -146,26 +176,31 @@ int32_t rtc_write(int32_t fd, const void* buf, int32_t nbytes)
...
@@ -146,26 +176,31 @@ int32_t rtc_write(int32_t fd, const void* buf, int32_t nbytes)
*/
*/
int32_t
rtc_open
(
const
uint8_t
*
filename
)
int32_t
rtc_open
(
const
uint8_t
*
filename
)
{
{
uint8_t
rate
,
prev
;
/* Set RTC to active for the running terminal */
rtc_active
[
running_terminal
]
=
1
;
return
0
;
/* Set the frequency to 2 Hz */
rate
=
TWO_HZ
;
rate
&=
0x0F
;
/* Disable interrupts */
// uint8_t rate, prev;
cli
();
/* set index to register A, disable NMI */
// /* Set the frequency to 2 Hz */
outb
(
DISABLE_NMI_A
,
RTC_PORT
);
// rate = TWO_HZ;
/* get initial value of register A */
// rate &= 0x0F;
prev
=
inb
(
RTC_DATA
);
/* reset index to A */
// /* Disable interrupts */
outb
(
DISABLE_NMI_A
,
RTC_PORT
);
// cli();
/* write only our rate to A. Note, rate is the bottom 4 bits. */
// /* set index to register A, disable NMI */
outb
((
prev
&
0xF0
)
|
rate
,
RTC_DATA
);
// outb(DISABLE_NMI_A, RTC_PORT);
/* Enable interrupts */
// /* get initial value of register A */
sti
();
// prev = inb(RTC_DATA);
// /* reset index to A */
// outb(DISABLE_NMI_A, RTC_PORT);
// /* write only our rate to A. Note, rate is the bottom 4 bits. */
// outb((prev & 0xF0) | rate, RTC_DATA);
// /* Enable interrupts */
// sti();
return
0
;
//
return 0;
}
}
/* rtc_close()
/* rtc_close()
...
...
This diff is collapsed.
Click to expand it.
student-distrib/rtc.h
+
8
−
1
View file @
c9ffa12a
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#define BIT_SIX 0x40
#define BIT_SIX 0x40
#define TWO_HZ 15
#define TWO_HZ 15
#define FREQ_MAX 8192
#define FREQ_MAX 8192
#define INIT_FREQ 1024
#define MAX_FREQ_POW 13
#define MAX_FREQ_POW 13
#define RATE_OFFSET 16
#define RATE_OFFSET 16
#define FOUR_BYTES 4
#define FOUR_BYTES 4
...
@@ -28,7 +29,13 @@
...
@@ -28,7 +29,13 @@
#define REGISTER_C 0x0C
#define REGISTER_C 0x0C
/* Interrupt flag for read() */
/* Interrupt flag for read() */
volatile
int
interrupt_flag
;
extern
int
interrupt_flag
;
/* Global Variables for Virtualization */
extern
int
rtc_active
[
MAX_TERMINAL
];
extern
int
rtc_flag
[
MAX_TERMINAL
];
extern
int
rtc_counter
[
MAX_TERMINAL
];
/*
/*
* rtc_init()
* rtc_init()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment