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

problem with bufferfifobyte

parent 0c609031
Branches backup727
No related tags found
2 merge requests!16Withtime,!7Pre k4 io
#ifndef __IRQ_H__
#define __IRQ_H__
void ClearAllIRQ(int IRQ1, int IRQ2);
void ClearIRQ(int Source, int IRQ);
void DisableIRQ(int Source, int IRQ);
void EnableIRQ(int Source, int IRQ);
#endif
......@@ -3,11 +3,13 @@
#include <types.h>
// General Purpose buffer
int InitBuffer(Buffer* Buf, void* Store, int size);
// returns 1 if buffer is ready(not null, has memory)
int BufferReady(Buffer* Buf);
// Initialize buffer
int InitBuffer(Buffer* Buf, void* Store, int size);
// insert at the last
int FeedBuffer(Buffer* Buf,void* Word);
......@@ -18,7 +20,7 @@ int FeedBufferByte(Buffer* Buf, void* Byte);
int BufferFIFO(Buffer* Buf, void* Dest);
// Get a single byte from the start, does not change size
int BufferFIFOByte(BUffer* Buf,void* Dest);
int BufferFIFOByte(Buffer* Buf,void* Dest);
int BufferPopHead(Buffer* Buf);
......
......@@ -7,7 +7,7 @@ void InitWaitEventTable();
int IsValidEvent(int EventID);
int GetEventID(const int IRQCode);
int GetEventID(const int IRQ1, const int IRQ2);
int doAwaitEvent(KernelStruct* Colonel, int EventID);
......
......@@ -2,5 +2,5 @@
#define IDLE_TASK_H
void IdleTask();
#endif
\ No newline at end of file
void IdleTask1();
#endif
#ifndef __IO_API_H__
#define __IO_API_H__
void EnableUART(int uart);
int putc(char c);
char getc();
#endif
#ifndef __IOSERV_H__
#define __IOSERV_H__
void IServer();
void OServer();
#endif
#ifndef __K4_H__
#define __K4_H__
void FirstUserTask();
#endif
......@@ -2,6 +2,8 @@
#define NOTIFIER_H
void Notifier();
void ClockNotifier();
void InNotifier();
void OutNotifier();
#endif
......@@ -47,6 +47,8 @@
#define ANOTHER_WAITING -3
// from ep93xxs guide pg 166
#define UART2IN_INT 25
#define UART2OUT_INT 26
#define TIMER3_INTERRUPT 51
#define IRQ_MAGIC 100
......@@ -195,7 +197,9 @@ typedef enum syscall {
SYS_WHOIS,
SYS_REGAS,
SYS_SENDQ,
SYS_WAITEVENT
SYS_WAITEVENT,
SYS_GETC,
SYS_PUTC,
} Syscall;
......@@ -255,6 +259,8 @@ typedef struct kernel {
EventAwaitTask* WaitTable;
int NumTDsAvail;
int NameServerID;
int IServerID;
int OServerID;
} KernelStruct;
//static Buffer*** TotalSendQ;
......
0;136;0cma
\ No newline at end of file
#include <IRQ.h>
void ClearAllIRQ(int IRQ1, int IRQ2){
asm volatile(".VIC1ENCLR:\n\t"
".word 0x800b0014\n\t"
".VIC2ENCLR:\n\t"
".word 0x800c0014\n\t"
"ldr r2,.VIC1ENCLR\n\t"
"ldr r3,.VIC2ENCLR\n\t"
"str r0, [r2]\n\t"
"str r1, [r3]\n\t");
}
void ClearIRQ(int Source, int IRQ){
asm volatile("add r1, r1, #0x14\n\t"
"str r0, [r1]\n\t");
}
void DisableIRQ(int Source, int IRQ){
asm volatile("add r1, r1, #0x10\n\t"
"ldr r2, [r1]\n\t"
"bic r2, r2, r0\n\t"
"str r2, [r1]\n\t");
}
void EnableIRQ(int Source,int IRQ){
asm volatile("add r1, r1, #0x10\n\t"
"str r0, [r1]\n\t");
}
......@@ -39,12 +39,24 @@ hash-table.s: hash-table.c
idle-task.s: idle-task.c
$(XCC) -S $(CFLAGS) idle-task.c
io-api.s: io-api.c
$(XCC) -S $(CFLAGS) io-api.c
ioserver.s: ioserver.c
$(XCC) -S $(CFLAGS) ioserver.c
ipc.s: ipc.c
$(XCC) -S $(CFLAGS) ipc.c
IRQ.s: IRQ.c
$(XCC) -S $(CFLAGS) IRQ.c
k3.s: k3.c
$(XCC) -S $(CFLAGS) k3.c
k4.s: k4.c
$(XCC) -S $(CFLAGS) k4.c
kernel.s: kernel.c
$(XCC) -S $(CFLAGS) kernel.c
......@@ -110,12 +122,24 @@ hash-table.o: hash-table.s
idle-task.o: idle-task.s
$(AS) $(ASFLAGS) -o idle-task.o idle-task.s
io-api.o: io-api.s
$(AS) $(ASFLAGS) -o io-api.o io-api.s
ioserver.o: ioserver.s
$(AS) $(ASFLAGS) -o ioserver.o ioserver.s
ipc.o: ipc.s
$(AS) $(ASFLAGS) -o ipc.o ipc.s
IRQ.o: IRQ.s
$(AS) $(ASFLAGS) -o IRQ.o IRQ.s
k3.o: k3.s
$(AS) $(ASFLAGS) -o k3.o k3.s
k4.o: k4.s
$(AS) $(ASFLAGS) -o k4.o k4.s
kernel.o: kernel.s
$(AS) $(ASFLAGS) -o kernel.o kernel.s
......@@ -180,12 +204,24 @@ hash-table.a: hash-table.o
idle-task.a: idle-task.o
$(AR) $(ARFLAGS) $@ idle-task.o
io-api.a: io-api.o
$(AR) $(ARFLAGS) $@ io-api.o
ioserver.a: ioserver.o
$(AR) $(ARFLAGS) $@ ioserver.o
ipc.a: ipc.o
$(AR) $(ARFLAGS) $@ ipc.o
IRQ.a: IRQ.o
$(AR) $(ARFLAGS) $@ IRQ.o
k3.a: k3.o
$(AR) $(ARFLAGS) $@ k3.o
k4.a: k4.o
$(AR) $(ARFLAGS) $@ k4.o
kernel.a: kernel.o
$(AR) $(ARFLAGS) $@ kernel.o
......@@ -224,7 +260,7 @@ tools.a: tools.o
$(AR) $(ARFLAGS) $@ tools.o
install: buffer.a bwio.a clock-task.a clockserver-api.a context-switch.a event-itr.a hash-table.a idle-task.a ipc.a kernel.a k3.a min-heap.a nameserver.a notifier.a priority-q.a rps.a scheduler.a syscall.a syscall-handler.a td.a timer.a tools.a
install: buffer.a bwio.a clock-task.a clockserver-api.a context-switch.a event-itr.a hash-table.a idle-task.a io-api.a ioserver.a ipc.a IRQ.a kernel.a k3.a k4.a min-heap.a nameserver.a notifier.a priority-q.a rps.a scheduler.a syscall.a syscall-handler.a td.a timer.a tools.a
mv buffer.a libbuffer.a
mv bwio.a libbwio.a
mv clock-task.a libclktsk.a
......@@ -233,8 +269,12 @@ install: buffer.a bwio.a clock-task.a clockserver-api.a context-switch.a event-i
mv event-itr.a libei.a
mv hash-table.a libht.a
mv idle-task.a libidt.a
mv io-api.a libio.a
mv ioserver.a libiosv.a
mv ipc.a libipc.a
mv IRQ.a libIRQ.a
mv k3.a libk3.a
mv k4.a libk4.a
mv kernel.a libkernel.a
mv min-heap.a libmh.a
mv nameserver.a libns.a
......
......@@ -3,8 +3,15 @@
#include <error.h>
#include <types.h>
int InitBuffer(BUffer* Buf,void* Store,int size){
if(BUfferReady(Buf)){
int BufferReady(Buffer* Buf){
int ready = ((Buf!=NULL) &&(Buf->Size >0))? 1:0;
return ready;
}
int InitBuffer(Buffer* Buf,void* Store,int size){
if(Buf!=NULL){
Buf->Storage = Store;
Buf->Size = size;
Buf->Length = 0;
......@@ -14,11 +21,6 @@ int InitBuffer(BUffer* Buf,void* Store,int size){
}else return BUFF_NOTREADY;
}
int BufferReady(Buffer* Buf){
int ready = ((Buf!=NULL) &&(Buf->Size >0))? 1:0;
return ready;
}
int FeedBuffer(Buffer* Buf,void* Word)
{
......
......@@ -91,7 +91,7 @@ void ClockServer() {
case NOTIFIER:
//if (ClientID == NotifierID) {
SysTick++;
bwprintf(COM2,"CLKSERV: SysTick %d\n\r",SysTick);
//bwprintf(COM2,"CLKSERV: SysTick %d\n\r",SysTick);
ClearAllTimer();
TurnOnTimerIRQ();
ReplyMsg.Type = CONTINUE;
......
......@@ -34,7 +34,8 @@ int Time (int TaskID) {
int Res;
ClkMsg SendMsg, ReplyMsg;
SendMsg.Type = TIME;
//bwprintf(COM2,"Time: before send\n\r");
Res = Send(TaskID, (void*)(&SendMsg), sizeof(SendMsg), (void*)(&ReplyMsg), sizeof(ReplyMsg));
if (Res == TASK_DNE) {
bwprintf(COM2, "Time: The Clock Server Task ID is invalid \n\r.");
......
......@@ -15,22 +15,18 @@ int IsValidEvent(int EventID) {
return (EventID < NUM_EVENTS) && (EventID >= 0);
}
int GetEventID(const int IRQCode){
int code = IRQCode;
int Mask = 1<<31;
int base = 31;
while(base > 0 && !(Mask & code)){
base --;
code <<= 1;
}
return base;
int GetEventID(const int IRQ1, const int IRQ2){
int mask = 1;
if((mask<<25) & IRQ1) return 25;
if((mask<<26) & IRQ1) return 26;
if((mask<<19) & IRQ2) return 51;
}
int doAwaitEvent(KernelStruct* Colonel, int EventID) {
EventAwaitTask* WET = Colonel->WaitTable;
// check EventID's validity
if (!IsValidEvent(EventID)) {
bwprintf(COM2, "doAwaitEvent: Invalid Event\n\r");
//bwprintf(COM2, "doAwaitEvent: Invalid Event\n\r");
return INVALID_EVENT;
}
......@@ -38,10 +34,11 @@ int doAwaitEvent(KernelStruct* Colonel, int EventID) {
WET[EventID].AwaitTask = Colonel->Active;
Colonel->Active->TaskState = EventBlocked;
//bwprintf(COM2,"doAwaitEvent: Task: %d waiting on EventID: %d\n\r",WET[EventID].AwaitTask->TaskID,EventID);
//if(EventID == 26) EnableInterrupt(26);
return SUCCESS;
}
else {
bwprintf(COM2, "doAwaitEvent: Another Task is already waiting on this Event\n\r");
//bwprintf(COM2, "doAwaitEvent: Another Task is already waiting on this Event\n\r");
return ANOTHER_WAITING;
}
}
......@@ -49,10 +46,42 @@ 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, task:%d, EventID:%d \n\r",WET[EventID].AwaitTask->TaskID,EventID);
bwprintf(COM1,"PE: task:%d, EventID:%d \n\r",WET[EventID].AwaitTask->TaskID,EventID);
pushToScheduler(Colonel, WET[EventID].AwaitTask);
WET[EventID].AwaitTask = NULL;
}
void HandleEvents(KernelStruct* Colonel, int IRQ2,int IRQ1){
int code1 = IRQ1;
int code2 = IRQ2;
int Mask = 1<<31;
int base = 31;
// process all event in IRQ2
while(base > 0){
if(Mask & code2){/*
if(base+32 == UART2_INT){
int Flags = *(int *)(UART2_BASE | UART_FLAG_OFFSET);
int TrxMask = (int )(TXFE_MASK | CTS_MASK);
if(!(Flags & TrxMask)) {
base --;
code2 <<= 1;
continue;
}
}*/
ProcessEvent(Colonel,base+32);
}
base --;
code2 <<= 1;
}
base = 31;
while(base > 0){
if(Mask & code1){
ProcessEvent(Colonel, base);
}
base --;
code1 <<=1;
}
}
/*
int CheckItrEvent(int EventID) {
int Base;
......
......@@ -9,12 +9,28 @@ void IdleTask() {
unsigned int volatile CurrentTick = initTick;
unsigned int volatile Accum = 0;
float portion = 0.0;
bwprintf(COM2,"IdleTask: before into loop\n\r");
while(1){
CurrentTick = Time(ClockServerID);
Accum+=(CurrentTick - LastTick);
LastTick = CurrentTick;
//portion = (Accum / 1.0) / CurrentTick;
bwprintf(COM2,"IdleTask: %d:%d\n\r", Accum, CurrentTick);
bwprintf(COM2,"IdleTask: idleTask:Total %d:%d\n\r", Accum, CurrentTick);
//bwprintf(COM2,"IdleTask: IRQ: %d\n\r",*(int *)(VIC2_BASE));
}
}
void IdleTask1(){
int *int_contr = (int *)(UART2_BASE | UART_CTLR_OFFSET);
int i;
char bPrinted = 0;
while(1){
i = int_contr;
if(!bPrinted){
bwprintf(COM1,"IDT1: runs\n\r");
bPrinted = 1;
}
//if(i & (1<<4)) break;
//bwprintf(COM2,"IdleTask1: runs\n\r");
}
}
#include <bwio.h>
#include <io-api.h>
#include <ts7200.h>
#include <types.h>
void EnableUART(int uart){
int *Control;
int Mask;
switch (uart){
case 1:
Control = (int *)(UART2_BASE | UART_CTLR_OFFSET);
Mask = (1<<5 | 1<< 4);
//EnableInterrupt(25);
//EnableInterrupt(26);
*Control = Mask;
break;
}
}
int ActualPutC(AP* Args){
asm volatile ("swi 13\n\t");
register int r0 asm("r0");
int R = r0;
return R;
}
int ActualGetC(AP* Args){
asm volatile ("swi 12\n\t");
register int r0 asm("r0");
int R = r0;
return R;
}
int putc(char c){
IOReq SendReq;
SendReq.Byte = c;
SendReq.Type = OUT;
int Result, Reply;
AP Args;
Args.arg1 = (void *)(&SendReq);
Args.arg2 = (void *)sizeof(IOReq);
Args.arg3 = (void *)(&Reply);
Args.arg4 = (void *)sizeof(int);
Result = ActualPutC(&Args);
if(Result == sizeof(int)) return 1;
}
char getc(){
IOReq SendReq;
SendReq.Type = IN;
int Result;
char Byte;
AP Args;
Args.arg1 = (void *)(&SendReq);
Args.arg2 = (void *)sizeof(IOReq);
Args.arg3 = (void *)(&Byte);
Args.arg4 = (void *)sizeof(char);
//bwprintf(COM2,"getc:\n\r");
Result = ActualGetC(&Args);
//bwprintf(COM2,"getc: result %d\n\r",Result);
if(Result == sizeof(char)) return Byte;
}
#include <buffer.h>
#include <bwio.h>
#include <nameserver.h>
#include <syscall.h>
#include <td-shared.h>
......@@ -8,15 +9,15 @@ void IOServer(char IO, IOType Producer, IOType Consumer){
int Result;
char ServerName[] = "IServer";
ServerName[0] = IO;
Result = RegisterAs(Result);
Result = RegisterAs(ServerName);
// set up send q
int MyID = MyTid();
int MyIndex = GetMemoryIndexINT(MyID);
Buffer** AllSendQ = GetAllSendQ();
//bwprintf(COM2,"NS Index %d\n\r",MyIndex);
// bwprintf(COM2,"NS AllSendQ add%d\n\r",AllSendQ);
//bwprintf(COM1,"NS Index %d\n\r",MyIndex);
// bwprintf(COM1,"NS AllSendQ add%d\n\r",AllSendQ);
Buffer SendQ;
Buffer WaitList;
Buffer Buff;
......@@ -24,9 +25,10 @@ void IOServer(char IO, IOType Producer, IOType Consumer){
int WLStorage[MAX_NUM_TD];
int BStorage[BUFF_SIZE];
// need to check errors
Result = InitBuffer(&SendQ,(void *)QStorage,MAX_NUM_TD);
Result = InitBuffer(&WaitList,(void *)WLStorage,MAX_NUM_TD);
Result = InitBuffer(&Buff,(void *)BStorage,BUFF_SIZE);
Result = InitBuffer(&SendQ,(void *)QStorage,(int)(MAX_NUM_TD));
//bwprintf(COM1,"%s:SendQ.size %d\n\r",ServerName,SendQ.Size);
Result = InitBuffer(&WaitList,(void *)WLStorage,(int)(MAX_NUM_TD));
Result = InitBuffer(&Buff,(void *)BStorage,(int)(BUFF_SIZE));
AllSendQ[MyIndex] = &SendQ;
// some sort of while loop to receive and reply
......@@ -39,11 +41,14 @@ void IOServer(char IO, IOType Producer, IOType Consumer){
char bEmpty = 1;
char bReceived = 0;
char Byte;
//bwprintf(COM1,"%s: before loop\n\r",ServerName);
FOREVER{
TaskToReceive = NULL;
bPushToWL = 1;
// if didn't wake up from block, first try to get one from wait list
if(bReceived == 0 && bEmpty){
if(bReceived == 0 && !bEmpty){
WLResult = BufferFIFO(&WaitList,(void *)&TaskToReceive);
bwprintf(COM1,"%s: Get %d from WL result %d\n\r",ServerName,TaskToReceive,WLResult);
}
// if successfully get one from wait list, set config
if(WLResult == 0){
......@@ -52,42 +57,57 @@ void IOServer(char IO, IOType Producer, IOType Consumer){
bIsWLTask = 1;
}else{
Result = BufferFIFO(&SendQ,(void *)(&TaskToReceive));
bwprintf(COM1,"%s: From Send Q %d \n\r",ServerName,Result);
BufferPopHead(&SendQ);
}
if(TaskToReceive != NULL){
bwprintf(COM1,"%s: Got Task %d \n\r",ServerName,TaskToReceive);
if(bReceived == 0){
bwprintf(COM1,"%s: Receive %d\n\r",ServerName, TaskToReceive);
Result = Receive(TaskToReceive,(void*) &ReceiveSlot, sizeof(NSReq));
bPushToWL = 1;
}
bReceived = 0;
// if sender is getc or we got one from wait list, we do receive procedure
if(ReceiveSlot.Type == Consumer || bIsWLTask){
bwprintf(COM1,"%s: %d is Consumer %d or WLTask %d\n\r",ServerName,TaskToReceive,(ReceiveSlot.Type == NOUT || ReceiveSlot.Type == IN),bIsWLTask);
// reset flag
bIsWLTask = 0;
// if IBuffer is empty,get the notifier input word
if(Buffer.Length == 0){
// if Buffer is empty, put this on wait list
if(Buff.Length == 0){
bwprintf(COM1,"%s: Buffer Empty \n\r",ServerName);
bEmpty = 1;
if(bPushToWL)FeedBuffer(&WaitList,(void*) TaskToReceive);
if(bPushToWL){
FeedBuffer(&WaitList,(void*) TaskToReceive);
bwprintf(COM1,"%s: push %d to WL\n\r",ServerName,TaskToReceive);
}
continue;
}
BufferFIFOByte(&Buff, &Byte);
bwprintf(COM1,"%s: get a byte from buffer\n\r",ServerName);
Result = BufferFIFOByte(&Buff, &Byte);
bwprintf(COM1,"%s: pop byte result %d\n\r",ServerName,Result);
BufferPopHead(&Buff);
bwprintf(COM1,"%s: Ready To transmit %c to %d\n\r",ServerName,Byte,TaskToReceive);
Reply(TaskToReceive,(void *)Byte, sizeof(char));
}else if(ReceiveSlot.Type == Producer){
bwprintf(COM1,"%s: Producer gave me %c\n\r",ServerName, ReceiveSlot.Byte);
bEmpty = 0;
FeedBuffer(&Buffer, (void *)(ReceiveSlot.Byte));
FeedBufferByte(&Buff, (void *)(ReceiveSlot.Byte));
Result = 0;
Reply(TaskToReceive,(void *)(&Result), sizeof(int));
}
}else{
bReceived = 1;
WLResult = -1;
bwprintf(COM1,"%s: Receive from NULL %d\n\r",ServerName,TaskToReceive);
Receive(TaskToReceive,(void*) &ReceiveSlot, sizeof(NSReq));
//bwprintf(COM1,"%s: Back from Null Receive\n\r",ServerName);
}
}
}
void IServer(){
IOServer('I',IN,NIN);
IOServer('I',NIN,IN);
}
void OServer(){
......
......@@ -29,8 +29,8 @@ int doSend(KernelStruct* Colonel, int TaskID, void* Msg, int MsgLen, void* Reply
}
//bwprintf(COM2,"doSend: Task %d SendMsgLen:%d\n\r",SenderTask->TaskID,MsgLen);
int Result;
FeedBuffer(AllSendQ[TIDIndex],(void *)(SenderTask->TaskID));
int Result = FeedBuffer(AllSendQ[TIDIndex],(void *)(SenderTask->TaskID));
//bwprintf(COM2,"doSend: Task %d got recorded on %d sendQ, result %d\n\r",SenderTask->TaskID, TaskID, Result);
if (ReceiverTask->TaskState == SendBlocked) {
AP* Args = ReceiverTask->Args;
int *ReceiverSlot = (int *)Args->arg1;
......@@ -89,6 +89,7 @@ int doReceive(KernelStruct* Colonel, int TaskID, void* Msg, int MsgLen) {
//bwprintf(COM2,"doReceive: SendQ[%d] popped head\n\r",(ReceiverTask->TaskID));
Colonel->Active->RetVal = MsgLen;
}
//bwprintf(COM2,"doReceive: Returning with success\n\r");
return SUCCESS;
}
......
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