OOStuBS - Technische Informatik II (TI-II)
2.4
Hauptseite
Zusätzliche Informationen
Klassen
Dateien
Auflistung der Dateien
Datei-Elemente
src
machine
serial.cc
gehe zur Dokumentation dieser Datei
1
#include "
machine/serial.h
"
2
#include "
locking/scopedLock.h
"
3
#include "
object/lock.h
"
4
5
Serial::Serial
(): transmitPort(address+0),
6
divisorLowPort(address+0),
7
divisorHighPort(address+1),
8
controlPort(address+3),
9
statusPort(address+5){
10
11
ControlByte
controlByte;
12
controlByte.
size
=
ControlByte::_8Bits
;
13
controlByte.
stopBits
=
ControlByte::One
;
14
controlByte.
parity
=
ControlByte::none
;
15
controlByte.
breakEnable
=
false
;
16
controlByte.
divisorAccess
=
false
;
17
18
control
(controlByte);
19
baudRate
(115200);
20
}
21
22
Serial::~Serial
(){
23
print
(
"Operating system ended"
, 22);
24
}
25
26
void
Serial::print
(
const
char
*
string
,
unsigned
int
n){
27
for
(
unsigned
int
i=0;i<n;i++){
28
transmit
(
string
[i]);
29
while
(!
status
().transmitBufferEmpty);
30
}
31
}
32
33
Serial::StatusByte
Serial::status
(){
34
union
{
35
unsigned
char
buffer;
36
StatusByte
statusByte;
37
} u;
38
u.buffer=
statusPort
.
inb
();
39
return
u.statusByte;
40
}
41
42
void
Serial::control
(
Serial::ControlByte
controlByte){
43
union
{
44
unsigned
char
buffer;
45
ControlByte
controlByte;
46
} u;
47
u.controlByte = controlByte;
48
controlPort
.
outb
(u.buffer);
49
}
50
51
Serial::ControlByte
Serial::control
(){
52
union
{
53
unsigned
char
buffer;
54
ControlByte
controlByte;
55
} u;
56
u.buffer =
controlPort
.
inb
();
57
return
u.controlByte;
58
}
59
60
unsigned
int
Serial::baudRate
(){
61
ScopedLock
sLock(
lock
);
62
union
{
63
unsigned
char
buffer[2];
64
unsigned
short
divisor;
65
} u;
66
ControlByte
controlByte=
control
();
67
controlByte.
divisorAccess
=
true
;
68
control
(controlByte);
69
u.buffer[0]=
divisorLowPort
.
inb
();
70
u.buffer[1]=
divisorHighPort
.
inb
();
71
controlByte.
divisorAccess
=
false
;
72
control
(controlByte);
73
return
maxBaudRate
/u.divisor;
74
}
75
76
unsigned
int
Serial::baudRate
(
unsigned
int
baudRate){
77
ScopedLock
sLock(
lock
);
78
union
{
79
unsigned
char
buffer[2];
80
unsigned
short
divisor;
81
} u;
82
u.divisor =
maxBaudRate
/
baudRate
;
83
ControlByte
controlByte=
control
();
84
controlByte.
divisorAccess
=
true
;
85
control
(controlByte);
86
divisorLowPort
.
outb
(u.buffer[0]);
87
divisorLowPort
.
outb
(u.buffer[1]);
88
controlByte.
divisorAccess
=
false
;
89
control
(controlByte);
90
return
maxBaudRate
%
baudRate
;
91
}
92
93
void
Serial::transmit
(
char
c){
94
union
{
95
unsigned
char
buffer;
96
char
character;
97
} u;
98
u.character=c;
99
transmitPort
.
outb
(u.buffer);
100
}
Erzeugt am Mon Jun 30 2014 07:13:28 für OOStuBS - Technische Informatik II (TI-II) von
1.8.1.2