more work on timers
This commit is contained in:
parent
5d7374de80
commit
f317310437
9
Makefile
9
Makefile
|
@ -22,7 +22,7 @@
|
|||
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
|
||||
#=----------------------------------------------------------------------------=#
|
||||
|
||||
.PHONY: all test test32 debug gdb install dust clean OS/K
|
||||
.PHONY: all test test32 debug gdb install dust clean OS/K run
|
||||
.DELETE_ON_ERROR: $(BINDIR)/kaleid
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
|
@ -119,9 +119,6 @@ KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
|
|||
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
|
||||
KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources))
|
||||
|
||||
all :
|
||||
@make OS/K -j 8
|
||||
|
||||
## MISC MAKEFILE ------------------------------------------------------------- #
|
||||
|
||||
./ProjectTree: ./.stylehlp_sh
|
||||
|
@ -263,6 +260,8 @@ $(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm $(LOADERDIR)/*/*.inc
|
|||
OS/K: $(dep) ./ProjectTree $(BINDIR)/kaleid
|
||||
@echo ${CL2}[[$@]] ${NC} OS/K successfully made, $(mode) mode.${CL3}
|
||||
|
||||
all :
|
||||
@make OS/K -j 8
|
||||
## QEMU/DEBUG RELATED
|
||||
|
||||
testkvm: all install
|
||||
|
@ -270,6 +269,8 @@ testkvm: all install
|
|||
-rtc base=localtime -m $(ram) -hda $(installdisk) \
|
||||
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
|
||||
|
||||
run: test
|
||||
|
||||
test: all install
|
||||
@qemu-system-x86_64 -vga std -cpu $(cpu) -soundhw pcspk -s \
|
||||
-rtc base=localtime -m $(ram) -hda $(installdisk) \
|
||||
|
|
|
@ -63,6 +63,7 @@ void KeSetCurTime(Time_t);
|
|||
void KeEnablePIT(void);
|
||||
void KeSleep(uint);
|
||||
Timer_t *KeSetTimer(uint delay);
|
||||
int KeGetTimer(Timer_t*);
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <ke/idt.h>
|
||||
|
||||
#define COUNTDONE 1
|
||||
#define PIT_FREQUENCY 1000 // Hz = 10ms
|
||||
#define PIT_FREQUENCY 1000 // Hz = 1ms
|
||||
|
||||
static Timer_t Timer[20]; //20 concurrent sleep max
|
||||
static ulong Ticks = 0;
|
||||
|
@ -65,33 +65,41 @@ static Timer_t* KeFindTimerBlock(void)
|
|||
|
||||
void KeSleep(uint delay)
|
||||
{
|
||||
struct Timer_t *timerBlock;
|
||||
Timer_t *timerBlock;
|
||||
|
||||
if ((timerBlock = (Timer_t*)KeFindTimerBlock()) == NULL)
|
||||
return;
|
||||
|
||||
timerBlock->countDown = delay;
|
||||
timerBlock->countDown = delay * PIT_FREQUENCY / 1000;
|
||||
|
||||
while (!timerBlock->sema) {
|
||||
KeDelayExecution(1);
|
||||
KeRelaxCPU();
|
||||
}
|
||||
timerBlock->sema = 0;
|
||||
}
|
||||
|
||||
Timer_t *KeSetTimer(uint delay)
|
||||
{
|
||||
struct Timer_t *timerBlock;
|
||||
Timer_t *timerBlock;
|
||||
|
||||
if ((timerBlock = (Timer_t*)KeFindTimerBlock()) == NULL)
|
||||
return NULL;
|
||||
|
||||
timerBlock->countDown = delay;
|
||||
|
||||
DebugLog("Timer set %d ms", delay);
|
||||
timerBlock->countDown = delay * PIT_FREQUENCY / 1000;
|
||||
|
||||
return timerBlock;
|
||||
}
|
||||
|
||||
int KeGetTimer(Timer_t *timerBlock)
|
||||
{
|
||||
if (!(timerBlock->sema)) {
|
||||
return 0;
|
||||
} else {
|
||||
timerBlock->sema = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void KeEnablePIT(void)
|
||||
{
|
||||
ulong flags = KePauseIRQs();
|
||||
|
@ -99,15 +107,15 @@ void KeEnablePIT(void)
|
|||
|
||||
KeRegisterISR(HandlePIT, 0x20);
|
||||
|
||||
IoWriteByteOnPort(0x43, 0x36); // 0x34 = 00110100 for rate gen
|
||||
IoWriteByteOnPort(0x43, 0x36); // 0x36 for rate gen
|
||||
|
||||
IoWriteByteOnPort(0x40, (char)(divisor & 0xFF )); // low byte of freq
|
||||
IoWriteByteOnPort(0x40, (char)((divisor >> 8)& 0xFF)); // high byte of freq
|
||||
|
||||
// Setting up the IRQs
|
||||
// Setting up the IRQ line
|
||||
KeUnmaskIRQ(0);
|
||||
|
||||
DebugLog("\tPIT activated with rate generator mode %d ms\n", 1000/PIT_FREQUENCY);
|
||||
DebugLog("\tPIT activated with period %d ms\n", 1000/PIT_FREQUENCY);
|
||||
|
||||
KeRestoreIRQs(flags);
|
||||
KeEnableNMI();
|
||||
|
|
|
@ -189,9 +189,6 @@ void KeEnableRTC(void)
|
|||
KeRegisterISR(HandleRTC, 0x28);
|
||||
|
||||
// Setting up the register control and interrupt rates
|
||||
DebugLog("\tRTC interrupt frequency set to %d Hz\n",
|
||||
32768 >> (RTC_RATE - 1));
|
||||
|
||||
IoWriteByteOnPort(0x70, 0x8B);
|
||||
readRegister = IoReadByteFromPort(0x71);
|
||||
IoWriteByteOnPort(0x70, 0x8B); // Because reading flushes
|
||||
|
@ -204,10 +201,9 @@ void KeEnableRTC(void)
|
|||
IoWriteByteOnPort(0x70, 0x0C);
|
||||
IoReadByteFromPort(0x71); // Flush
|
||||
|
||||
// Setting up the IRQs
|
||||
// Setting up the IRQ line
|
||||
KeUnmaskIRQ(8);
|
||||
|
||||
|
||||
// Clean-up
|
||||
IoWriteByteOnPort(0x70, 0x0C); // Select status reg C
|
||||
IoReadByteFromPort(0x71); // Flush
|
||||
|
@ -217,6 +213,8 @@ void KeEnableRTC(void)
|
|||
KeEnableNMI();
|
||||
|
||||
srand(KeGetTimeStamp()); // Initializes the kernel number generator
|
||||
DebugLog("\tRTC interrupt frequency set to %d Hz\n",
|
||||
32768 >> (RTC_RATE - 1));
|
||||
}
|
||||
|
||||
void KeDelayExecution(uint time)
|
||||
|
|
|
@ -121,14 +121,6 @@ error_t CmdDate(int argc, char **argv, char *cmdline)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdSleep(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
int delay = ShAtoi(argv[1]);
|
||||
|
||||
KeSleep(delay);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdDumpATASect(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
char sector[512] = {0};
|
||||
|
@ -235,6 +227,14 @@ error_t CmdShell(int argc, char **argv, char *cmdline)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdSleep(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
int delay = ShAtoi(argv[1]);
|
||||
|
||||
KeSleep(delay);
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
CmdStackOverflow(0, 0, 0);
|
||||
|
@ -269,6 +269,22 @@ error_t CmdTime(int argc, char **argv, char *cmdline)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdTimerTest(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
int delay = ShAtoi(argv[1]);
|
||||
|
||||
Timer_t *timer = KeSetTimer(delay);
|
||||
|
||||
while(!(KeGetTimer(timer))) {
|
||||
bprintf(BStdOut,".");
|
||||
BStdOut->flusher(BStdOut);
|
||||
}
|
||||
|
||||
KernLog("Finished !\n");
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdVersion(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
int CH = VGA_COLOR_LIGHT_BLUE;
|
||||
|
@ -301,21 +317,22 @@ Command_t shcmdtable[] =
|
|||
{ "color", CmdColor, "Change shell text color" },
|
||||
{ "date", CmdDate, "Print date" },
|
||||
{ "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
|
||||
{ "exit", CmdQuit, "Initiate shutdown" },
|
||||
{ "help", CmdHelp, "Show this message" },
|
||||
{ "march", CmdStarWars, "Play the Imperial March" },
|
||||
{ "mmap", CmdMemMap, "Show memory map" },
|
||||
{ "musage", CmdMemUsage, "Show memory statistics" },
|
||||
{ "pfault", CmdPF, "Provoke a PF. Usage: pfault <address>"},
|
||||
{ "pstest", CmdPsTest, "Scheduler test routine" },
|
||||
{ "exit", CmdQuit, "Initiate shutdown" },
|
||||
{ "quit", CmdQuit, "Alias for 'exit'" },
|
||||
{ "rpag", CmdReloadPage, "Reload the pages directory" },
|
||||
{ "shell", CmdShell, "Start a new shell (nested)", },
|
||||
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
|
||||
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
|
||||
{ "march", CmdStarWars, "Play the Imperial March" },
|
||||
{ "sleep", CmdSleep, "Sleep x ms" },
|
||||
{ "testimer", CmdTimerTest, "test timer of x ms" },
|
||||
{ "time", CmdTime, "Print time" },
|
||||
{ "ver", CmdVersion, "Version and legal infos" },
|
||||
{ "sleep", CmdSleep, "Sleep x ms" },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue