Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs452Trainee
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Tom Feng
cs452Trainee
Commits
0c609031
Commit
0c609031
authored
6 years ago
by
Tom Feng
Browse files
Options
Downloads
Patches
Plain Diff
backup before pull
parent
479831c4
No related branches found
Branches containing commit
No related tags found
2 merge requests
!16
Withtime
,
!7
Pre k4 io
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/buffer.h
+8
-0
8 additions, 0 deletions
include/buffer.h
include/types.h
+14
-1
14 additions, 1 deletion
include/types.h
lib/buffer.c
+34
-0
34 additions, 0 deletions
lib/buffer.c
lib/ioserver.c
+95
-0
95 additions, 0 deletions
lib/ioserver.c
with
151 additions
and
1 deletion
include/buffer.h
+
8
−
0
View file @
0c609031
...
...
@@ -3,15 +3,23 @@
#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
);
// insert at the last
int
FeedBuffer
(
Buffer
*
Buf
,
void
*
Word
);
// insert a byte at the last
int
FeedBufferByte
(
Buffer
*
Buf
,
void
*
Byte
);
// Get from the start, does not change size
int
BufferFIFO
(
Buffer
*
Buf
,
void
*
Dest
);
// Get a single byte from the start, does not change size
int
BufferFIFOByte
(
BUffer
*
Buf
,
void
*
Dest
);
int
BufferPopHead
(
Buffer
*
Buf
);
// Get from the Last, does not change size
...
...
This diff is collapsed.
Click to expand it.
include/types.h
+
14
−
1
View file @
0c609031
...
...
@@ -50,7 +50,8 @@
#define TIMER3_INTERRUPT 51
#define IRQ_MAGIC 100
// I/O buffer things
#define BUFF_SIZE 256
typedef
struct
heapnode
{
int
DelayedTick
;
int
TaskID
;
...
...
@@ -136,6 +137,18 @@ typedef struct hash_table{
int
size
;
}
HT
;
typedef
enum
IOServerMessageType
{
IN
,
OUT
,
NIN
,
// notifier input
NOUT
,
// notifier output
}
IOType
;
typedef
struct
IOServerRequest
{
IOType
Type
;
char
Byte
;
}
IOReq
;
typedef
struct
NameServerMessage
{
char
Msg
[
NS_MESSAGE_MAX_LENGTH
+
1
];
}
NSMsg
;
...
...
This diff is collapsed.
Click to expand it.
lib/buffer.c
+
34
−
0
View file @
0c609031
...
...
@@ -3,6 +3,17 @@
#include
<error.h>
#include
<types.h>
int
InitBuffer
(
BUffer
*
Buf
,
void
*
Store
,
int
size
){
if
(
BUfferReady
(
Buf
)){
Buf
->
Storage
=
Store
;
Buf
->
Size
=
size
;
Buf
->
Length
=
0
;
Buf
->
Head
=
0
;
Buf
->
Tail
=
0
;
return
0
;
}
else
return
BUFF_NOTREADY
;
}
int
BufferReady
(
Buffer
*
Buf
){
int
ready
=
((
Buf
!=
NULL
)
&&
(
Buf
->
Size
>
0
))
?
1
:
0
;
return
ready
;
...
...
@@ -21,6 +32,18 @@ int FeedBuffer(Buffer* Buf,void* Word)
}
else
return
BUFF_NOTREADY
;
}
int
FeedBufferByte
(
Buffer
*
Buf
,
void
*
Byte
)
{
if
(
BufferReady
(
Buf
)){
if
(
Buf
->
Length
==
Buf
->
Size
)
return
BUFF_FULL
;
char
*
Store
=
(
char
*
)(
Buf
->
Storage
);
Store
[
Buf
->
Tail
]
=
(
char
)
Byte
;
Buf
->
Tail
=
(
Buf
->
Tail
+
1
)
%
(
Buf
->
Size
);
Buf
->
Length
=
Buf
->
Length
+
1
;
return
0
;
}
else
return
BUFF_NOTREADY
;
}
int
BufferFIFO
(
Buffer
*
Buf
,
void
*
Dest
)
{
if
(
BufferReady
(
Buf
)){
...
...
@@ -30,6 +53,17 @@ int BufferFIFO(Buffer* Buf,void* Dest)
return
0
;
}
else
return
BUFF_NOTREADY
;
}
int
BufferFIFOByte
(
Buffer
*
Buf
,
void
*
Dest
)
{
if
(
BufferReady
(
Buf
)){
if
(
Buf
->
Length
==
0
)
return
BUFF_EMPTY
;
char
*
Store
=
(
char
*
)(
Buf
->
Storage
);
*
(
int
*
)
Dest
=
Store
[
Buf
->
Head
];
return
0
;
}
else
return
BUFF_NOTREADY
;
}
int
BufferPopHead
(
Buffer
*
Buf
)
{
//bwprintf(COM2,"BufferPopHead: Buf is %d\n\r",Buf);
...
...
This diff is collapsed.
Click to expand it.
lib/ioserver.c
0 → 100644
+
95
−
0
View file @
0c609031
#include
<buffer.h>
#include
<nameserver.h>
#include
<syscall.h>
#include
<td-shared.h>
#include
<types.h>
void
IOServer
(
char
IO
,
IOType
Producer
,
IOType
Consumer
){
int
Result
;
char
ServerName
[]
=
"IServer"
;
ServerName
[
0
]
=
IO
;
Result
=
RegisterAs
(
Result
);
// 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);
Buffer
SendQ
;
Buffer
WaitList
;
Buffer
Buff
;
int
QStorage
[
MAX_NUM_TD
];
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
);
AllSendQ
[
MyIndex
]
=
&
SendQ
;
// some sort of while loop to receive and reply
int
TaskToReceive
;
IOReq
ReceiveSlot
;
int
WLResult
;
char
bIsWLTask
;
char
bPushToWL
;
char
bEmpty
=
1
;
char
bReceived
=
0
;
char
Byte
;
FOREVER
{
TaskToReceive
=
NULL
;
// if didn't wake up from block, first try to get one from wait list
if
(
bReceived
==
0
&&
bEmpty
){
WLResult
=
BufferFIFO
(
&
WaitList
,(
void
*
)
&
TaskToReceive
);
}
// if successfully get one from wait list, set config
if
(
WLResult
==
0
){
bReceived
=
1
;
bPushToWL
=
0
;
bIsWLTask
=
1
;
}
else
{
Result
=
BufferFIFO
(
&
SendQ
,(
void
*
)(
&
TaskToReceive
));
BufferPopHead
(
&
SendQ
);
}
if
(
TaskToReceive
!=
NULL
){
if
(
bReceived
==
0
){
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
){
// reset flag
bIsWLTask
=
0
;
// if IBuffer is empty,get the notifier input word
if
(
Buffer
.
Length
==
0
){
bEmpty
=
1
;
if
(
bPushToWL
)
FeedBuffer
(
&
WaitList
,(
void
*
)
TaskToReceive
);
continue
;
}
BufferFIFOByte
(
&
Buff
,
&
Byte
);
BufferPopHead
(
&
Buff
);
Reply
(
TaskToReceive
,(
void
*
)
Byte
,
sizeof
(
char
));
}
else
if
(
ReceiveSlot
.
Type
==
Producer
){
bEmpty
=
0
;
FeedBuffer
(
&
Buffer
,
(
void
*
)(
ReceiveSlot
.
Byte
));
Result
=
0
;
Reply
(
TaskToReceive
,(
void
*
)(
&
Result
),
sizeof
(
int
));
}
}
else
{
bReceived
=
1
;
Receive
(
TaskToReceive
,(
void
*
)
&
ReceiveSlot
,
sizeof
(
NSReq
));
}
}
}
void
IServer
(){
IOServer
(
'I'
,
IN
,
NIN
);
}
void
OServer
(){
IOServer
(
'O'
,
OUT
,
NOUT
);
}
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