mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
IO: Move to semaphore abstraction
This commit is contained in:
parent
039b72788c
commit
aba2d007df
@ -116,10 +116,10 @@ private:
|
||||
volatile unsigned _rx_dma_status;
|
||||
|
||||
/** bus-ownership lock */
|
||||
sem_t _bus_semaphore;
|
||||
px4_sem_t _bus_semaphore;
|
||||
|
||||
/** client-waiting lock/signal */
|
||||
sem_t _completion_semaphore;
|
||||
px4_sem_t _completion_semaphore;
|
||||
|
||||
/**
|
||||
* Start the transaction with IO and wait for it to complete.
|
||||
@ -177,8 +177,8 @@ PX4IO_serial::PX4IO_serial() :
|
||||
_tx_dma(nullptr),
|
||||
_rx_dma(nullptr),
|
||||
_rx_dma_status(_dma_status_inactive),
|
||||
_bus_semaphore(SEM_INITIALIZER(0)),
|
||||
_completion_semaphore(SEM_INITIALIZER(0)),
|
||||
_bus_semaphore(px4_sem_initIALIZER(0)),
|
||||
_completion_semaphore(px4_sem_initIALIZER(0)),
|
||||
_pc_txns(perf_alloc(PC_ELAPSED, "io_txns ")),
|
||||
_pc_dmasetup(perf_alloc(PC_ELAPSED, "io_dmasetup ")),
|
||||
_pc_retries(perf_alloc(PC_COUNT, "io_retries ")),
|
||||
@ -219,8 +219,8 @@ PX4IO_serial::~PX4IO_serial()
|
||||
stm32_unconfiggpio(PX4IO_SERIAL_RX_GPIO);
|
||||
|
||||
/* and kill our semaphores */
|
||||
sem_destroy(&_completion_semaphore);
|
||||
sem_destroy(&_bus_semaphore);
|
||||
px4_sem_destroy(&_completion_semaphore);
|
||||
px4_sem_destroy(&_bus_semaphore);
|
||||
|
||||
perf_free(_pc_txns);
|
||||
perf_free(_pc_dmasetup);
|
||||
@ -280,8 +280,8 @@ PX4IO_serial::init()
|
||||
rCR1 = USART_CR1_RE | USART_CR1_TE | USART_CR1_UE | USART_CR1_IDLEIE;
|
||||
|
||||
/* create semaphores */
|
||||
sem_init(&_completion_semaphore, 0, 0);
|
||||
sem_init(&_bus_semaphore, 0, 1);
|
||||
px4_sem_init(&_completion_semaphore, 0, 0);
|
||||
px4_sem_init(&_bus_semaphore, 0, 1);
|
||||
|
||||
|
||||
/* XXX this could try talking to IO */
|
||||
@ -366,7 +366,7 @@ PX4IO_serial::write(unsigned address, void *data, unsigned count)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
sem_wait(&_bus_semaphore);
|
||||
px4_sem_wait(&_bus_semaphore);
|
||||
|
||||
int result;
|
||||
|
||||
@ -403,7 +403,7 @@ PX4IO_serial::write(unsigned address, void *data, unsigned count)
|
||||
perf_count(_pc_retries);
|
||||
}
|
||||
|
||||
sem_post(&_bus_semaphore);
|
||||
px4_sem_post(&_bus_semaphore);
|
||||
|
||||
if (result == OK) {
|
||||
result = count;
|
||||
@ -423,7 +423,7 @@ PX4IO_serial::read(unsigned address, void *data, unsigned count)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
sem_wait(&_bus_semaphore);
|
||||
px4_sem_wait(&_bus_semaphore);
|
||||
|
||||
int result;
|
||||
|
||||
@ -468,7 +468,7 @@ PX4IO_serial::read(unsigned address, void *data, unsigned count)
|
||||
perf_count(_pc_retries);
|
||||
}
|
||||
|
||||
sem_post(&_bus_semaphore);
|
||||
px4_sem_post(&_bus_semaphore);
|
||||
|
||||
if (result == OK) {
|
||||
result = count;
|
||||
@ -551,7 +551,7 @@ PX4IO_serial::_wait_complete()
|
||||
int ret;
|
||||
|
||||
for (;;) {
|
||||
ret = sem_timedwait(&_completion_semaphore, &abstime);
|
||||
ret = px4_sem_timedwait(&_completion_semaphore, &abstime);
|
||||
|
||||
if (ret == OK) {
|
||||
/* check for DMA errors */
|
||||
@ -627,7 +627,7 @@ PX4IO_serial::_do_rx_dma_callback(unsigned status)
|
||||
rCR3 &= ~(USART_CR3_DMAT | USART_CR3_DMAR);
|
||||
|
||||
/* complete now */
|
||||
sem_post(&_completion_semaphore);
|
||||
px4_sem_post(&_completion_semaphore);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user