mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-08 17:08:28 -04:00
AP_HAL_PX4 : make UARTDriver capable to be called from different threads.
The modification allows the read and write functions to be called by any thread but the calling thread must be the last one that called the begin() function.
This commit is contained in:
parent
154bf51279
commit
1d3a49e466
@ -150,6 +150,8 @@ void PX4UARTDriver::begin(uint32_t b, uint16_t rxS, uint16_t txS)
|
||||
}
|
||||
_initialised = true;
|
||||
}
|
||||
_uart_owner_pid = getpid();
|
||||
|
||||
}
|
||||
|
||||
void PX4UARTDriver::set_flow_control(enum flow_control flow_control)
|
||||
@ -275,6 +277,9 @@ int16_t PX4UARTDriver::txspace()
|
||||
int16_t PX4UARTDriver::read()
|
||||
{
|
||||
uint8_t c;
|
||||
if (_uart_owner_pid != getpid()){
|
||||
return -1;
|
||||
}
|
||||
if (!_initialised) {
|
||||
try_initialise();
|
||||
return -1;
|
||||
@ -295,12 +300,11 @@ int16_t PX4UARTDriver::read()
|
||||
*/
|
||||
size_t PX4UARTDriver::write(uint8_t c)
|
||||
{
|
||||
if (!_initialised) {
|
||||
try_initialise();
|
||||
if (_uart_owner_pid != getpid()){
|
||||
return 0;
|
||||
}
|
||||
if (hal.scheduler->in_timerprocess()) {
|
||||
// not allowed from timers
|
||||
if (!_initialised) {
|
||||
try_initialise();
|
||||
return 0;
|
||||
}
|
||||
uint16_t _head;
|
||||
@ -321,14 +325,13 @@ size_t PX4UARTDriver::write(uint8_t c)
|
||||
*/
|
||||
size_t PX4UARTDriver::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
if (_uart_owner_pid != getpid()){
|
||||
return 0;
|
||||
}
|
||||
if (!_initialised) {
|
||||
try_initialise();
|
||||
return 0;
|
||||
}
|
||||
if (hal.scheduler->in_timerprocess()) {
|
||||
// not allowed from timers
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_nonblocking_writes) {
|
||||
/*
|
||||
|
@ -75,6 +75,9 @@ private:
|
||||
uint32_t _total_read;
|
||||
uint32_t _total_written;
|
||||
enum flow_control _flow_control;
|
||||
|
||||
pid_t _uart_owner_pid;
|
||||
|
||||
};
|
||||
|
||||
#endif // __AP_HAL_PX4_UARTDRIVER_H__
|
||||
|
Loading…
Reference in New Issue
Block a user