Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Giulia Facchi
Skyward Boardcore
Commits
4d5bc87f
Commit
4d5bc87f
authored
1 year ago
by
Emilio Corigliano
Committed by
Matteo Pignataro
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
[USART] Improved clearQueue method for flushing the internal receiver queue
parent
5690377e
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
src/shared/drivers/usart/USART.cpp
+8
-1
8 additions, 1 deletion
src/shared/drivers/usart/USART.cpp
src/tests/drivers/usart/test-usart.cpp
+39
-3
39 additions, 3 deletions
src/tests/drivers/usart/test-usart.cpp
with
47 additions
and
4 deletions
src/shared/drivers/usart/USART.cpp
+
8
−
1
View file @
4d5bc87f
...
...
@@ -595,7 +595,14 @@ void USART::writeString(const char *buffer)
};
}
void
USART
::
clearQueue
()
{
rxQueue
.
reset
();
}
void
USART
::
clearQueue
()
{
char
buf
[
usart_queue_default_capacity
];
rxQueue
.
reset
();
while
(
read
(
buf
,
usart_queue_default_capacity
))
;
rxQueue
.
reset
();
}
STM32SerialWrapper
::
STM32SerialWrapper
(
USARTType
*
usart
,
int
baudrate
)
:
USARTInterface
(
usart
,
baudrate
)
...
...
This diff is collapsed.
Click to expand it.
src/tests/drivers/usart/test-usart.cpp
+
39
−
3
View file @
4d5bc87f
...
...
@@ -203,6 +203,40 @@ bool testCommunicationSequential(USARTInterface *src, USARTInterface *dst)
return
passed
;
}
bool
testClearQueue
(
USART
*
src
,
USART
*
dst
)
{
char
buf
[
128
];
size_t
nReads
{
0
};
src
->
writeString
(
"Transmitting useless stuff!"
);
// miosix::delayUs(1000);
dst
->
clearQueue
();
// Can be commented to test without read
if
(
dst
->
read
(
buf
,
128
,
nReads
))
{
printf
(
"### read something after the clearQueue: %s (%zu bytes)
\n
"
,
buf
,
nReads
);
// Shouldn't read anything
return
false
;
}
src
->
writeString
(
"Now transmitting the juicy stuff :P"
);
dst
->
readBlocking
(
buf
,
128
,
nReads
);
// After the clearQueue we should only read the things written after
if
(
strcmp
(
buf
,
"Now transmitting the juicy stuff :P"
)
!=
0
)
{
printf
(
"### read something different than the things sent: %s (%zu "
"bytes)
\n
"
,
buf
,
nReads
);
return
false
;
}
printf
(
"*** clearQueue test passed
\n
"
);
return
true
;
}
/* Available default pins:
* - USART1: tx=PA9 rx=PA10
* - USART2: tx=PA2 rx=PA3
...
...
@@ -242,17 +276,19 @@ int main()
// usartx.setWordLength(USART::WordLength::BIT8);
// usartx.setParity(USART::ParityBit::NO_PARITY);
//
USART usarty(UART4, baudrate);
STM32SerialWrapper
usarty
(
UART4
,
baudrate
,
u4rx2
::
getPin
(),
u4tx2
::
getPin
());
USART
usarty
(
UART4
,
baudrate
);
//
STM32SerialWrapper usarty(UART4, baudrate, u4rx2::getPin(),
//
u4tx2::getPin());
// testing transmission (both char and binary) "serial 1 <- serial
// 2"
testPassed
&=
testCommunicationSequential
(
&
usartx
,
&
usarty
);
testPassed
&=
testClearQueue
(
&
usartx
,
&
usarty
);
// testing transmission (both char and binary) "serial 1 -> serial
// 2"
testPassed
&=
testCommunicationSequential
(
&
usarty
,
&
usartx
);
testPassed
&=
testClearQueue
(
&
usarty
,
&
usartx
);
}
if
(
testPassed
)
...
...
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