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
3ddf463e
Commit
3ddf463e
authored
9 years ago
by
Cristian Maglie
Browse files
Options
Downloads
Patches
Plain Diff
USBDevice: added 'full' flag to USB buffer
This way all the 64 bytes available can be filled up
parent
44174a0a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cores/arduino/USB/CDC.cpp
+15
-14
15 additions, 14 deletions
cores/arduino/USB/CDC.cpp
with
15 additions
and
14 deletions
cores/arduino/USB/CDC.cpp
+
15
−
14
View file @
3ddf463e
...
...
@@ -37,8 +37,9 @@ struct ring_buffer {
uint8_t
buffer
[
CDC_SERIAL_BUFFER_SIZE
];
volatile
uint32_t
head
;
volatile
uint32_t
tail
;
volatile
bool
full
;
};
ring_buffer
cdc_rx_buffer
=
{
{
0
},
0
,
0
};
ring_buffer
cdc_rx_buffer
=
{
{
0
},
0
,
0
,
false
};
typedef
struct
{
uint32_t
dwDTERate
;
...
...
@@ -160,19 +161,22 @@ void Serial_::accept(void)
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
uint32_t
k
=
0
;
i
=
(
i
+
1
)
%
CDC_SERIAL_BUFFER_SIZE
;
while
((
i
!=
ringBuffer
->
tail
)
&&
(
len
>
0
))
{
while
(
len
>
0
&&
!
ringBuffer
->
full
)
{
len
--
;
ringBuffer
->
buffer
[
ringBuffer
->
head
]
=
buffer
[
k
++
];
ringBuffer
->
head
=
i
;
i
=
(
i
+
1
)
%
CDC_SERIAL_BUFFER_SIZE
;
ringBuffer
->
buffer
[
i
++
]
=
buffer
[
k
++
];
i
%=
CDC_SERIAL_BUFFER_SIZE
;
if
(
i
==
ringBuffer
->
tail
)
ringBuffer
->
full
=
true
;
}
ringBuffer
->
head
=
i
;
interrupts
();
}
int
Serial_
::
available
(
void
)
{
ring_buffer
*
buffer
=
&
cdc_rx_buffer
;
if
(
buffer
->
full
)
return
CDC_SERIAL_BUFFER_SIZE
;
if
(
buffer
->
head
==
buffer
->
tail
)
{
USB
->
DEVICE
.
DeviceEndpoint
[
2
].
EPINTENSET
.
reg
=
USB_DEVICE_EPINTENCLR_TRCPT
(
1
);
}
...
...
@@ -182,13 +186,9 @@ int Serial_::available(void)
int
Serial_
::
peek
(
void
)
{
ring_buffer
*
buffer
=
&
cdc_rx_buffer
;
if
(
buffer
->
head
==
buffer
->
tail
)
{
if
(
buffer
->
head
==
buffer
->
tail
&&
!
buffer
->
full
)
{
return
-
1
;
}
else
{
}
else
{
return
buffer
->
buffer
[
buffer
->
tail
];
}
}
...
...
@@ -203,12 +203,12 @@ int Serial_::read(void)
ring_buffer
*
buffer
=
&
cdc_rx_buffer
;
// if the head isn't ahead of the tail, we don't have any characters
if
(
buffer
->
head
==
buffer
->
tail
)
if
(
buffer
->
head
==
buffer
->
tail
&&
!
buffer
->
full
)
{
if
(
usb
.
available
(
CDC_ENDPOINT_OUT
))
accept
();
}
if
(
buffer
->
head
==
buffer
->
tail
)
if
(
buffer
->
head
==
buffer
->
tail
&&
!
buffer
->
full
)
{
return
-
1
;
}
...
...
@@ -216,6 +216,7 @@ int Serial_::read(void)
{
unsigned
char
c
=
buffer
->
buffer
[
buffer
->
tail
];
buffer
->
tail
=
(
uint32_t
)(
buffer
->
tail
+
1
)
%
CDC_SERIAL_BUFFER_SIZE
;
buffer
->
full
=
false
;
// if (usb.available(CDC_ENDPOINT_OUT))
// accept();
return
c
;
...
...
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