more work on timers

This commit is contained in:
Adrien Bourmault 2019-11-18 00:15:39 +01:00
parent 5d7374de80
commit f317310437
5 changed files with 69 additions and 44 deletions

View File

@ -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) \

View File

@ -48,21 +48,22 @@ struct Timer_t {
ulong sema;
} __attribute__((packed));
void KeSetupRTC(void);
void KeEnableRTC(void);
void KeSetupRTC(void);
void KeEnableRTC(void);
ulong KeGetTimeStamp(void);
ulong KeGetClockTicks(void);
Time_t *KeGetOriginTime(void);
void KeDelayExecution(uint);
ulong KeGetTimeStamp(void);
ulong KeGetClockTicks(void);
Time_t *KeGetOriginTime(void);
void KeDelayExecution(uint);
Time_t *KeGetCurTime(void);
char *KeFormatCurTime(void);
void KeSetCurTime(Time_t);
Time_t *KeGetCurTime(void);
char *KeFormatCurTime(void);
void KeSetCurTime(Time_t);
void KeEnablePIT(void);
void KeSleep(uint);
Timer_t *KeSetTimer(uint delay);
void KeEnablePIT(void);
void KeSleep(uint);
Timer_t *KeSetTimer(uint delay);
int KeGetTimer(Timer_t*);
//----------------------------------------------------------------------------//

View File

@ -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();

View File

@ -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)

View File

@ -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};
@ -213,7 +205,7 @@ error_t CmdPF(int argc, char **argv, char *cmdline)
error_t CmdPsTest(int argc, char **argv, char *cmdline)
{
// pstest();
// pstest();
return EOK;
}
@ -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 }
};