Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART_17-18
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container 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
bbartels
MicroCART_17-18
Commits
7f958463
Commit
7f958463
authored
8 years ago
by
bbartels
Committed by
javey
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
uart: consolidate receive buffer variable names
parent
7254a0d2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
quad/sw/comm_dev/src/new_comm.c
+22
-18
22 additions, 18 deletions
quad/sw/comm_dev/src/new_comm.c
with
22 additions
and
18 deletions
quad/sw/comm_dev/src/new_comm.c
+
22
−
18
View file @
7f958463
...
...
@@ -23,12 +23,14 @@ void Handler(void *CallBackRef, u32 Event, unsigned int EventData);
// Pointer to the UART driver instance
static
XUartPs
*
uartInstPtr
;
static
u8
recvBuf
[
UART_BUF_SIZE
];
static
u8
recvBuf
[
UART_BUF_SIZE
+
MAX_PACKET_SIZE
];
static
volatile
size_t
recvBufBegin
=
0
;
static
volatile
size_t
recvBufEnd
=
0
;
static
volatile
size_t
received_in_buf
=
0
;
static
u8
secondaryBuf
[
UART_BUF_SIZE
+
MAX_PACKET_SIZE
];
static
volatile
size_t
secondaryEnd
=
0
;
// Index of start of valid data in the secondary buffer
static
size_t
secondaryBegin
=
0
;
// Index of one past end of valid data in the secondary buffer
//
static u8 secondaryBuf[UART_BUF_SIZE + MAX_PACKET_SIZE];
//
static volatile size_t secondaryEnd = 0; // Index of start of valid data in the secondary buffer
//
static size_t secondaryBegin = 0; // Index of one past end of valid data in the secondary buffer
int
initUartComms
()
{
uartInstPtr
=
uart0_init
(
COMM_UART_DEVICE_ID
,
BAUD_RATE
);
...
...
@@ -110,19 +112,19 @@ int process_packet(unsigned char* packet, modular_structs_t *structs) {
void
parse_available
(
modular_structs_t
*
structs
)
{
// Discard all data before packet begin character
while
(
s
ec
ondary
Begin
<
s
ec
ondary
End
&&
s
ec
ondary
Buf
[
s
ec
ondary
Begin
]
!=
BEGIN_CHAR
)
{
s
ec
ondary
Begin
++
;
while
(
r
ec
vBuf
Begin
<
r
ec
vBuf
End
&&
r
ec
v
Buf
[
r
ec
vBuf
Begin
]
!=
BEGIN_CHAR
)
{
r
ec
vBuf
Begin
++
;
}
// Minimum size of a packet (header + checksum)
int
min_packet_size
=
sizeof
(
metadata_t
)
+
1
;
// TODO: Loop limit?
while
(
s
ec
ondary
End
-
s
ec
ondary
Begin
>=
min_packet_size
)
{
unsigned
char
*
packet_header
=
s
ec
ondary
Buf
+
s
ec
ondary
Begin
;
while
(
r
ec
vBuf
End
-
r
ec
vBuf
Begin
>=
min_packet_size
)
{
unsigned
char
*
packet_header
=
r
ec
v
Buf
+
r
ec
vBuf
Begin
;
size_t
packet_len
=
(
packet_header
[
6
]
<<
8
)
|
(
packet_header
[
5
]);
if
(
s
ec
ondary
End
-
s
ec
ondary
Begin
>=
min_packet_size
+
packet_len
)
{
process_packet
(
s
ec
ondary
Buf
+
s
ec
ondary
Begin
,
structs
);
s
ec
ondary
Begin
+=
min_packet_size
+
packet_len
;
if
(
r
ec
vBuf
End
-
r
ec
vBuf
Begin
>=
min_packet_size
+
packet_len
)
{
process_packet
(
r
ec
v
Buf
+
r
ec
vBuf
Begin
,
structs
);
r
ec
vBuf
Begin
+=
min_packet_size
+
packet_len
;
}
else
{
// Not enough data for a packet
...
...
@@ -161,7 +163,7 @@ void process_received(modular_structs_t *structs) {
// received_in_buf = 0;
// // Re-enable interrupts and process copied data
// XUartPs_Recv(uartInstPtr, recvBuf, UART_BUF_SIZE);
if
(
s
ec
ondary
End
!=
0
)
{
if
(
r
ec
vBuf
End
!=
0
)
{
volatile
int
asdasdf
=
3
;
MIO7_led_off
();
}
...
...
@@ -171,10 +173,10 @@ void process_received(modular_structs_t *structs) {
u32
intr_state
=
disable_interrupts
();
// Move unprocessed bytes to front of secondary buffer
size_t
unprocessed_size
=
s
ec
ondary
End
-
s
ec
ondary
Begin
;
memmove
(
s
ec
ondary
Buf
,
s
ec
ondary
Buf
+
s
ec
ondary
Begin
,
unprocessed_size
);
s
ec
ondary
Begin
=
0
;
s
ec
ondary
End
=
unprocessed_size
;
size_t
unprocessed_size
=
r
ec
vBuf
End
-
r
ec
vBuf
Begin
;
memmove
(
r
ec
v
Buf
,
r
ec
v
Buf
+
r
ec
vBuf
Begin
,
unprocessed_size
);
r
ec
vBuf
Begin
=
0
;
r
ec
vBuf
End
=
unprocessed_size
;
restore_interrupts
(
intr_state
);
//unsigned char in_fifo = XUartPs_ReadReg(uartInstPtr->Config.BaseAddress, XUARTPS_FIFO_OFFSET);
...
...
@@ -199,12 +201,14 @@ void uartInterruptHandler(XUartPs *InstancePtr) {
* Read the Channel Status Register to determine if there is any data in
* the RX FIFO
*/
CsrRegister
=
XUartPs_ReadReg
(
InstancePtr
->
Config
.
BaseAddress
,
XUARTPS_SR_OFFSET
);
while
(
0
==
(
CsrRegister
&
XUARTPS_SR_RXEMPTY
))
{
secondaryBuf
[
secondaryEnd
]
=
XUartPs_ReadReg
(
InstancePtr
->
Config
.
BaseAddress
,
XUARTPS_FIFO_OFFSET
);
secondaryEnd
+=
1
;
recvBuf
[
recvBufEnd
]
=
XUartPs_ReadReg
(
InstancePtr
->
Config
.
BaseAddress
,
XUARTPS_FIFO_OFFSET
);
recvBufEnd
+=
1
;
CsrRegister
=
XUartPs_ReadReg
(
InstancePtr
->
Config
.
BaseAddress
,
XUARTPS_SR_OFFSET
);
MIO7_led_on
();
}
...
...
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