Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Killer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Vytor Calixto
Killer
Commits
05b7ee74
Commit
05b7ee74
authored
10 years ago
by
Israel Barreto Sant'Anna
Browse files
Options
Downloads
Patches
Plain Diff
Implementadas funções proberx e probetx
Signed-off-by:
Israel B. Sant'Anna
<
ibsa14@inf.ufpr.br
>
parent
954c0f55
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cMIPS/tests/uart.c
+25
-17
25 additions, 17 deletions
cMIPS/tests/uart.c
with
25 additions
and
17 deletions
cMIPS/tests/uart.c
+
25
−
17
View file @
05b7ee74
...
@@ -23,7 +23,6 @@ typedef struct status { // status register fields (uses only ls byte)
...
@@ -23,7 +23,6 @@ typedef struct status { // status register fields (uses only ls byte)
#define RXfull 0x00000020
#define RXfull 0x00000020
#define TXempty 0x00000040
#define TXempty 0x00000040
typedef
union
ctlStat
{
// control + status on same address
typedef
union
ctlStat
{
// control + status on same address
Tcontrol
ctl
;
// write-only
Tcontrol
ctl
;
// write-only
Tstatus
stat
;
// read-only
Tstatus
stat
;
// read-only
...
@@ -40,27 +39,28 @@ typedef struct serial {
...
@@ -40,27 +39,28 @@ typedef struct serial {
}
Tserial
;
}
Tserial
;
typedef
struct
{
typedef
struct
{
char
rx_q
ueue
[
16
];
// reception queue
and pointers
char
rx_q
[
16
];
// reception queue
int
rx_hd
;
int
rx_hd
;
// reception queue head index
int
rx_tl
;
int
rx_tl
;
// reception queue tail index
char
tx_q
ueue
[
16
];
// transmission queue
and pointers
char
tx_q
[
16
];
// transmission queue
int
tx_hd
;
int
tx_hd
;
// transmission queue head index
int
tx_tl
;
int
tx_tl
;
// transmission queue tail index
int
nrx
;
// characters in RX_queue
int
nrx
;
// characters in RX_queue
int
ntx
;
// spaces left in TX_queue
int
ntx
;
// spaces left in TX_queue
}
UartControl
;
}
UARTDriver
;
#define EOF -1
int
proberx
(
void
);
// retorna nrx
int
proberx
(
void
);
// retorna nrx
int
probetx
(
void
);
// retorna ntx
int
probetx
(
void
);
// retorna ntx
int
iostat
(
void
);
// retorna inteiro com status no byte menos sign
int
iostat
(
void
);
// retorna inteiro com status no byte menos sign
void
ioctl
(
int
);
// escreve byte menos sign no reg de controle
void
ioctl
(
int
);
// escreve byte menos sign no reg de controle
char
getc
(
void
);
// retorna caractere na fila, decrementa nrx
char
getc
(
void
);
// retorna caractere na fila, decrementa nrx
int
uart_putc
(
char
);
// insere caractere na fila, decrementa ntx
int
Putc
(
char
);
// insere caractere na fila, decrementa ntx
int
wrtc
(
char
);
// escreve caractere diretamente em txreg
extern
U
artControl
Ud
;
extern
U
ARTDriver
Ud
;
int
main
(
void
){
int
main
(){
int
i
;
int
i
;
volatile
int
state
;
// tell GCC not to optimize away code
volatile
int
state
;
// tell GCC not to optimize away code
volatile
Tserial
*
uart
;
volatile
Tserial
*
uart
;
...
@@ -77,7 +77,7 @@ int main(void){
...
@@ -77,7 +77,7 @@ int main(void){
char
c
;
char
c
;
while
((
c
=
getc
())
!=
'\0'
)
while
((
c
=
getc
())
!=
'\0'
)
uart_p
utc
(
c
);
P
utc
(
c
);
return
0
;
return
0
;
}
}
...
@@ -85,21 +85,21 @@ int main(void){
...
@@ -85,21 +85,21 @@ int main(void){
char
getc
(){
char
getc
(){
char
c
;
char
c
;
if
(
Ud
.
nrx
>
0
){
if
(
Ud
.
nrx
>
0
){
c
=
Ud
.
rx_q
ueue
[
Ud
.
rx_hd
];
c
=
Ud
.
rx_q
[
Ud
.
rx_hd
];
Ud
.
rx_hd
=
(
Ud
.
rx_hd
+
1
)
%
16
;
Ud
.
rx_hd
=
(
Ud
.
rx_hd
+
1
)
%
16
;
disableInterr
();
disableInterr
();
Ud
.
nrx
--
;
Ud
.
nrx
--
;
enableInterr
();
enableInterr
();
}
else
{
}
else
{
c
=
-
1
;
c
=
EOF
;
}
}
return
c
;
return
c
;
}
}
int
uart_p
utc
(
char
c
){
int
P
utc
(
char
c
){
int
sent
;
int
sent
;
if
(
Ud
.
ntx
>
0
){
if
(
Ud
.
ntx
>
0
){
Ud
.
tx_q
ueue
[
Ud
.
tx_tl
]
=
c
;
Ud
.
tx_q
[
Ud
.
tx_tl
]
=
c
;
Ud
.
tx_tl
=
(
Ud
.
tx_tl
+
1
)
%
16
;
Ud
.
tx_tl
=
(
Ud
.
tx_tl
+
1
)
%
16
;
disableInterr
();
disableInterr
();
Ud
.
ntx
--
;
Ud
.
ntx
--
;
...
@@ -110,3 +110,11 @@ int uart_putc(char c){
...
@@ -110,3 +110,11 @@ int uart_putc(char c){
}
}
return
sent
;
return
sent
;
}
}
int
proberx
(){
return
Ud
.
nrx
;
}
int
probetx
(){
return
Ud
.
ntx
;
}
\ No newline at end of file
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