Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pete
firmware
Commits
8c9eca95
Commit
8c9eca95
authored
5 years ago
by
schneider
Browse files
Options
Downloads
Plain Diff
Merge branch 'rahix/flush' into 'master'
Add serial_flush function Closes
#164
See merge request
!314
parents
3a0b7452
86c8339e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
epicardium/modules/modules.h
+1
-0
1 addition, 0 deletions
epicardium/modules/modules.h
epicardium/modules/serial.c
+87
-35
87 additions, 35 deletions
epicardium/modules/serial.c
with
88 additions
and
35 deletions
epicardium/modules/modules.h
+
1
−
0
View file @
8c9eca95
...
...
@@ -29,6 +29,7 @@ void return_to_menu(void);
void
serial_init
();
void
vSerialTask
(
void
*
pvParameters
);
void
serial_enqueue_char
(
char
chr
);
void
serial_flush
(
void
);
extern
TaskHandle_t
serial_task_id
;
// For the eSetBit xTaskNotify task semaphore trigger
...
...
This diff is collapsed.
Click to expand it.
epicardium/modules/serial.c
+
87
−
35
View file @
8c9eca95
...
...
@@ -121,6 +121,92 @@ void epic_uart_write_str(const char *str, intptr_t length)
}
}
static
void
serial_flush_from_isr
(
void
)
{
uint8_t
rx_data
[
32
];
size_t
received_bytes
;
BaseType_t
resched
=
pdFALSE
;
BaseType_t
woken
=
pdFALSE
;
uint32_t
basepri
=
__get_BASEPRI
();
taskENTER_CRITICAL_FROM_ISR
();
do
{
received_bytes
=
xStreamBufferReceiveFromISR
(
write_stream_buffer
,
(
void
*
)
rx_data
,
sizeof
(
rx_data
),
&
woken
);
resched
|=
woken
;
if
(
received_bytes
==
0
)
{
break
;
}
/*
* The SDK-driver for UART is not reentrant
* which means we need to perform UART writes
* in a critical section.
*/
UART_Write
(
ConsoleUart
,
(
uint8_t
*
)
&
rx_data
,
received_bytes
);
}
while
(
received_bytes
>
0
);
taskEXIT_CRITICAL_FROM_ISR
(
basepri
);
portYIELD_FROM_ISR
(
&
resched
);
}
static
void
serial_flush_from_thread
(
void
)
{
uint8_t
rx_data
[
32
];
size_t
received_bytes
;
do
{
taskENTER_CRITICAL
();
received_bytes
=
xStreamBufferReceive
(
write_stream_buffer
,
(
void
*
)
rx_data
,
sizeof
(
rx_data
),
0
);
taskEXIT_CRITICAL
();
if
(
received_bytes
==
0
)
{
break
;
}
/*
* The SDK-driver for UART is not reentrant
* which means we need to perform UART writes
* in a critical section.
*/
taskENTER_CRITICAL
();
UART_Write
(
ConsoleUart
,
(
uint8_t
*
)
&
rx_data
,
received_bytes
);
taskEXIT_CRITICAL
();
cdcacm_write
((
uint8_t
*
)
&
rx_data
,
received_bytes
);
ble_uart_write
((
uint8_t
*
)
&
rx_data
,
received_bytes
);
}
while
(
received_bytes
>
0
);
}
/*
* Flush all characters which are currently waiting to be printed.
*
* If this function is called from an ISR, it will only flush to hardware UART
* while a call from thread mode will flush to UART, CDC-ACM, and BLE Serial.
*/
void
serial_flush
(
void
)
{
if
(
xPortIsInsideInterrupt
())
{
serial_flush_from_isr
();
}
else
{
serial_flush_from_thread
();
}
}
/*
* API-call to read a character from the queue.
*/
...
...
@@ -217,9 +303,6 @@ void vSerialTask(void *pvParameters)
.
callback
=
uart_callback
,
};
uint8_t
rx_data
[
20
];
size_t
received_bytes
;
while
(
1
)
{
int
ret
=
UART_ReadAsync
(
ConsoleUart
,
&
read_req
);
if
(
ret
!=
E_NO_ERROR
&&
ret
!=
E_BUSY
)
{
...
...
@@ -230,38 +313,7 @@ void vSerialTask(void *pvParameters)
ret
=
ulTaskNotifyTake
(
pdTRUE
,
portMAX_DELAY
);
if
(
ret
&
SERIAL_WRITE_NOTIFY
)
{
do
{
received_bytes
=
xStreamBufferReceive
(
write_stream_buffer
,
(
void
*
)
rx_data
,
sizeof
(
rx_data
),
0
);
if
(
received_bytes
==
0
)
{
break
;
}
/*
* The SDK-driver for UART is not reentrant
* which means we need to perform UART writes
* in a critical section.
*/
taskENTER_CRITICAL
();
UART_Write
(
ConsoleUart
,
(
uint8_t
*
)
&
rx_data
,
received_bytes
);
taskEXIT_CRITICAL
();
cdcacm_write
(
(
uint8_t
*
)
&
rx_data
,
received_bytes
);
ble_uart_write
(
(
uint8_t
*
)
&
rx_data
,
received_bytes
);
}
while
(
received_bytes
>
0
);
serial_flush_from_thread
();
}
if
(
ret
&
SERIAL_READ_NOTIFY
)
{
...
...
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