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
f75149aa
Commit
f75149aa
authored
10 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
ctoi() implemented: character to integer
parent
1dd59a11
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cMIPS/serial.inp
+4
-5
4 additions, 5 deletions
cMIPS/serial.inp
cMIPS/tests/uart.c
+35
-18
35 additions, 18 deletions
cMIPS/tests/uart.c
with
39 additions
and
23 deletions
cMIPS/serial.inp
+
4
−
5
View file @
f75149aa
0
abcdef
00
012345
ffffffff
pqrstu
7C2
098765
This diff is collapsed.
Click to expand it.
cMIPS/tests/uart.c
+
35
−
18
View file @
f75149aa
...
@@ -57,6 +57,7 @@ int iostat(void); // returns integer with status at lsb
...
@@ -57,6 +57,7 @@ int iostat(void); // returns integer with status at lsb
void
ioctl
(
int
);
// write lsb in control register
void
ioctl
(
int
);
// write lsb in control register
char
getc
(
void
);
// returns char in queue, decrements nrx
char
getc
(
void
);
// returns char in queue, decrements nrx
int
Putc
(
char
);
// inserts char in queue, decrements ntx
int
Putc
(
char
);
// inserts char in queue, decrements ntx
int
ctoi
(
char
);
// converts a character to an integer
void
initUd
();
void
initUd
();
...
@@ -67,7 +68,7 @@ int main(){
...
@@ -67,7 +68,7 @@ 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
Tstatus
status
;
volatile
Tstatus
status
;
volatile
char
c
,
last
;
volatile
char
c
;
uart
=
(
void
*
)
IO_UART_ADDR
;
// bottom of UART address range
uart
=
(
void
*
)
IO_UART_ADDR
;
// bottom of UART address range
Tcontrol
ctrl
;
Tcontrol
ctrl
;
...
@@ -80,23 +81,23 @@ int main(){
...
@@ -80,23 +81,23 @@ int main(){
initUd
();
initUd
();
//uart->d.tx = 'a';
//print(lol);
/*while(c!='\n'){
/*to_stdout('X');
to_stdout('\n');
//print(lol);
c
=
getc
();
c
=
getc
();
}*/
while
(
c
!=
'\0'
)
{
last
=
'0'
;
while
((
c
=
getc
())
!=
'\0'
){
if
(
c
!=
EOF
)
{
if
(
c
!=
EOF
)
{
while
(
!
Putc
(
c
));
// Wait till there's space on queue
int
n
=
0
;
while
(
c
!=
'\n'
&&
c
!=
'\0'
)
{
int
h
=
ctoi
(
c
);
if
(
h
!=
EOF
)
{
n
=
n
*
16
+
h
;
}
c
=
getc
();
}
}
print
(
n
);
//while(!Putc(c)); // Wait till there's space on queue
}
}
Putc
(
c
);
// Sends '\0'
c
=
getc
();
}
Putc
(
c
);
// Sends EOF
return
0
;
return
0
;
}
}
...
@@ -124,9 +125,6 @@ char getc(){
...
@@ -124,9 +125,6 @@ char getc(){
//print(2);
//print(2);
c
=
EOF
;
c
=
EOF
;
}
}
//print((int)c);
// to_stdout(c);
// to_stdout('\n');
return
c
;
return
c
;
}
}
...
@@ -157,3 +155,22 @@ int proberx(){
...
@@ -157,3 +155,22 @@ int proberx(){
int
probetx
(){
int
probetx
(){
return
Ud
.
ntx
;
return
Ud
.
ntx
;
}
}
int
ctoi
(
char
c
)
{
// If it's a number
if
(
c
>=
0x30
&&
c
<
0x3a
)
{
return
((
int
)
c
)
-
0x30
;
}
// If it's an uppercase letter
if
(
c
>=
0x41
&&
c
<
0x47
)
{
return
((
int
)
c
)
-
0x37
;
// 0x40 - 0xa
}
// If it's a lowercase letter
if
(
c
>=
0x61
&&
c
<
0x67
)
{
return
((
int
)
c
)
-
0x57
;
//0x60 - 0xa
}
return
EOF
;
}
\ 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