Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
353bf623
Commit
353bf623
authored
10 years ago
by
Jonathan BAUDIN
Browse files
Options
Downloads
Patches
Plain Diff
Reworking RingBuffer class
parent
55366f65
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cores/arduino/RingBuffer.cpp
+41
-3
41 additions, 3 deletions
cores/arduino/RingBuffer.cpp
cores/arduino/RingBuffer.h
+7
-0
7 additions, 0 deletions
cores/arduino/RingBuffer.h
cores/arduino/SERCOMUart.cpp
+3
-2
3 additions, 2 deletions
cores/arduino/SERCOMUart.cpp
with
51 additions
and
5 deletions
cores/arduino/RingBuffer.cpp
+
41
−
3
View file @
353bf623
...
...
@@ -22,13 +22,12 @@
RingBuffer
::
RingBuffer
(
void
)
{
memset
(
_aucBuffer
,
0
,
SERIAL_BUFFER_SIZE
)
;
_iHead
=
0
;
_iTail
=
0
;
clear
();
}
void
RingBuffer
::
store_char
(
uint8_t
c
)
{
int
i
=
(
uint32_t
)(
_iHead
+
1
)
%
SERIAL_BUFFER_SIZE
;
int
i
=
nextIndex
(
_iHead
)
;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
...
...
@@ -41,3 +40,42 @@ void RingBuffer::store_char( uint8_t c )
}
}
void
RingBuffer
::
clear
()
{
_iHead
=
0
;
_iTail
=
0
;
}
int
RingBuffer
::
read_char
()
{
if
(
_iTail
==
_iHead
)
return
-
1
;
int
value
=
_aucBuffer
[
_iTail
];
_iTail
=
nextIndex
(
_iTail
);
return
value
;
}
int
RingBuffer
::
available
()
{
int
delta
=
_iHead
-
_iTail
;
if
(
delta
<
0
)
return
SERIAL_BUFFER_SIZE
+
delta
;
else
return
delta
;
}
int
RingBuffer
::
peek
()
{
if
(
_iTail
==
_iHead
)
return
-
1
;
return
_aucBuffer
[
_iTail
];
}
int
RingBuffer
::
nextIndex
(
int
index
)
{
return
(
uint32_t
)(
index
+
1
)
%
SERIAL_BUFFER_SIZE
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
cores/arduino/RingBuffer.h
+
7
−
0
View file @
353bf623
...
...
@@ -37,6 +37,13 @@ class RingBuffer
public:
RingBuffer
(
void
)
;
void
store_char
(
uint8_t
c
)
;
void
clear
();
int
read_char
();
int
available
();
int
peek
();
private:
int
nextIndex
(
int
index
);
}
;
#endif
/* _RING_BUFFER_ */
This diff is collapsed.
Click to expand it.
cores/arduino/SERCOMUart.cpp
+
3
−
2
View file @
353bf623
...
...
@@ -20,7 +20,8 @@ void SERCOMUart::begin(uint16_t baudrate, uint8_t config)
sercom
->
enableUART
();
}
void
SERCOMUart
::
end
(){
void
SERCOMUart
::
end
()
{
sercom
->
resetUART
();
rxBuffer
.
clear
();
}
...
...
@@ -47,7 +48,7 @@ void SERCOMUart::IrqHandler()
bool
SERCOMUart
::
available
()
{
return
rxBuffer
.
available
_char
();
return
rxBuffer
.
available
();
}
int
SERCOMUart
::
peek
()
...
...
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