Skip to content
Snippets Groups Projects
Commit 88ff5d24 authored by Tom Feng's avatar Tom Feng
Browse files

works for slow ticks like 1sec tick

parent e3e267be
No related branches found
No related tags found
1 merge request!16Withtime
#ifndef TIMER_H
#define TIMER_H
#define CLOCK_LOAD_VALUE 508000
#define CLOCK_LOAD_VALUE 5080
#define SLOW_LOAD_VALUE 200
......
......@@ -11,7 +11,7 @@
void ClockServer() {
bwprintf(COM2,"CLKSERV: I get run time\n\r");
int Res, ClientID, ClockServerID, Index, NotifierID, SenderID;
int Res, ClientID, ClockServerID, Index, SenderID;
int SysTick, DelayedTick;
ClkMsg ReceiveMsg, ReplyMsg;
AP Args;
......@@ -45,10 +45,7 @@ void ClockServer() {
Index = GetMemoryIndexINT(ClockServerID);
AllSendQ[Index] = &SendQ;
Args.arg0 = (void*) 0;
Args.arg1 = (void*)(&Notifier);
NotifierID = Create(&Args);
HN* HeapStorage[MAX_NUM_TD];
Heap.Num = 0;
Heap.Last = 0;
......@@ -86,22 +83,26 @@ void ClockServer() {
Reply(ClientID, (void*)&ReplyMsg, sizeof(ReplyMsg));
break;
case NOTIFIER:
if (ClientID == NotifierID) {
bwprintf(COM2,"CLKSERV: Notified!\n\r");
SysTick++;
ReplyMsg.Type = CONTINUE;
Reply(ClientID, (void*)&ReplyMsg, sizeof(ReplyMsg));
// loops the heap till minTask's DelayedTick is no longer smaller than SysTick ;;; first Time in Do will Fail to execute
DelayedTick = SysTick;
while (GetMinMinHeap(&Heap, &SenderID, &DelayedTick)){
if (DelayedTick < SysTick){
RemoveMinMinHeap(&Heap);
ReplyMsg.Type = READY;
Reply(SenderID, (void*)&ReplyMsg, sizeof(ReplyMsg));
}
}
//if (ClientID == NotifierID) {
SysTick++;
bwprintf(COM2,"CLKSERV: Notified! SysTick %d\n\r",SysTick);
ReplyMsg.Type = CONTINUE;
Reply(ClientID, (void*)&ReplyMsg, sizeof(ReplyMsg));
// loops the heap till minTask's DelayedTick is no longer smaller than SysTick ;;; first Time in Do will Fail to execute
DelayedTick = SysTick;
bwprintf(COM2,"CLKSERV: before GetMin, SysTick:%d\n\r",SysTick);
while (Heap.Num>0){
Res = GetMinMinHeap(&Heap,&SenderID,&DelayedTick);
bwprintf(COM2,"CLKSERV: heap while result: %d\n\r",Res);
if (DelayedTick <= SysTick){
RemoveMinMinHeap(&Heap);
ReplyMsg.Type = READY;
Reply(SenderID, (void*)&ReplyMsg, sizeof(ReplyMsg));
}else break;
}
bwprintf(COM2,"CLKSERV: After GetMin\n\r");
//}
break;
default:
bwprintf(COM2, "ClockServer: ReceiveMsg Type is undefined.\n\r");
......@@ -111,7 +112,8 @@ void ClockServer() {
bwprintf(COM2,"CLKSRV: picked %d\n\r",ClientID);
if (Res < 0) bwprintf(COM2, "ClockServer: BufferEmpty.\n\r");
//Pass();
Receive(NotifierID, (void*)&ReceiveMsg, sizeof(ReceiveMsg));
bwprintf(COM2, "About to block\n\r");
Receive(ClientID, (void*)&ReceiveMsg, sizeof(ReceiveMsg));
bReceived = 1;
}
}
......
......@@ -50,7 +50,7 @@ int doAwaitEvent(KernelStruct* Colonel, int EventID) {
void ProcessEvent(KernelStruct* Colonel, int EventID) { //TODOTODO when use this
EventAwaitTask* WET = Colonel->WaitTable;
(WET[EventID].AwaitTask)->TaskState = Ready;
bwprintf(COM2,"PE: get task back to scheduler\n\r");
bwprintf(COM2,"PE: get task back to scheduler, task:%d\n\r",WET[EventID].AwaitTask->TaskID);
pushToScheduler(Colonel, WET[EventID].AwaitTask);
WET[EventID].AwaitTask = NULL;
}
......
......@@ -4,6 +4,7 @@
#include <idle-task.h>
#include <k3.h>
#include <nameserver.h>
#include <notifier.h>
#include <syscall.h>
#include <types.h>
......@@ -37,36 +38,43 @@ void FirstUserTask() {
Args.arg0 = (void*) 15;
Args.arg1 = (void*) (&IdleTask);
IdleTaskID = Create(&Args);
bwprintf(COM2,"FUT: idle task created \n\r");
bwprintf(COM2,"FUT: idle task created %d\n\r", IdleTaskID);
//notifier
Args.arg0 = (void *) 0;
Args.arg1 = (void *) (&Notifier);
int NotifierID = Create(&Args);
bwprintf(COM2,"FUT: Notifier created %d\n\r", NotifierID);
// ClockServer
Args.arg0 = (void*) 0;
Args.arg0 = (void*) 1;
Args.arg1 = (void*) (&ClockServer);
ClockServerID = Create(&Args);
bwprintf(COM2,"FUT: clock server created \n\r");
bwprintf(COM2,"FUT: clock server created %d\n\r", ClockServerID);
// ClockClient1
Args.arg0 = (void*) 3;
Args.arg1 = (void*) (&ClockClient1);
ClockClient1ID = Create(&Args);
bwprintf(COM2,"FUT: client 1 created \n\r");
bwprintf(COM2,"FUT: client 1 created %d\n\r", ClockClient1ID);
// ClockClient2
Args.arg0 = (void*) 4;
Args.arg1 = (void*) (&ClockClient2);
ClockClient2ID = Create(&Args);
bwprintf(COM2,"FUT: client 2 created \n\r");
bwprintf(COM2,"FUT: client 2 created %d\n\r", ClockClient2ID);
// ClockClient3
Args.arg0 = (void*) 5;
Args.arg1 = (void*) (&ClockClient3);
ClockClient3ID = Create(&Args);
bwprintf(COM2,"FUT: client 3 created \n\r");
bwprintf(COM2,"FUT: client 3 created %d\n\r", ClockClient3ID);
// ClockClient4
Args.arg0 = (void*) 6;
Args.arg1 = (void*) (&ClockClient4);
ClockClient4ID = Create(&Args);
bwprintf(COM2,"FUT: client 4 created \n\r");
bwprintf(COM2,"FUT: client 4 created %d\n\r", ClockClient4ID);
// Set up SendQ
Buffer SendQ;
......
......@@ -11,6 +11,7 @@ void Notifier() {
bwprintf(COM2,"Notifier: Parent is %d\n\r",ClockServerID);
FOREVER {
Res = AwaitEvent(TIMER3_INTERRUPT);
bwprintf(COM2,"Notifier: Result %d\n\r",Res);
if (Res > -1) {
SendMsg.Type = NOTIFIER;
Send(ClockServerID, (void*)&SendMsg, sizeof(SendMsg), (void*)&ReplyMsg, sizeof(ReplyMsg));
......
......@@ -104,6 +104,7 @@ void Handle(KernelStruct* Colonel, int n) {
int result;
switch(n) {
case IRQ_MAGIC:
bwprintf(COM2,"Handle: IRQ!!! Acitve: %d\n\r",Colonel->Active->TaskID);
pushToScheduler(Colonel,Colonel->Active);
Colonel->Active = NULL;
int IRQ2 = *(int *)(VIC2_BASE);
......
......@@ -32,6 +32,7 @@ void ClockUpdate(Clock *MyClock)
void ClearAllTimer()
{
bwprintf(COM2,"CLR: All Timer\n\r");
asm volatile(".T1CLR:\n\t"
".word 0x8081000c\n\t"
"ldr r0, .T1CLR\n\t"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment