1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/nrf9160: add locking for shared peripherals

This commit is contained in:
Benjamin Valentin 2022-08-19 15:23:46 +02:00
parent 5129d249e9
commit 14b5eca22d
2 changed files with 55 additions and 0 deletions

View File

@ -208,6 +208,34 @@ void spi_twi_irq_register_spi(NRF_SPIM_Type *bus,
void spi_twi_irq_register_i2c(NRF_TWIM_Type *bus,
spi_twi_irq_cb_t cb, void *arg);
/**
* @brief Acquire the shared I2C/SPI peripheral in I2C mode
*
* @param bus bus to acquire exclusive access on
*/
void nrf5x_i2c_acquire(NRF_TWIM_Type *bus);
/**
* @brief Release the shared I2C/SPI peripheral in I2C mode
*
* @param bus bus to release exclusive access on
*/
void nrf5x_i2c_release(NRF_TWIM_Type *bus);
/**
* @brief Acquire the shared I2C/SPI peripheral in SPI mode
*
* @param bus bus to acquire exclusive access on
*/
void nrf5x_spi_release(NRF_SPIM_Type *bus);
/**
* @brief Acquire the shared I2C/SPI peripheral in SPI mode
*
* @param bus bus to release exclusive access on
*/
void nrf5x_spi_acquire(NRF_SPIM_Type *bus);
#ifdef __cplusplus
}
#endif

View File

@ -24,12 +24,15 @@
#include <assert.h>
#include "cpu.h"
#include "mutex.h"
#include "periph_cpu.h"
#include "periph_conf.h"
static spi_twi_irq_cb_t _irq[TWIM_COUNT];
static void *_irq_arg[TWIM_COUNT];
static mutex_t _locks[SPIM_COUNT];
#if TWIM_COUNT != SPIM_COUNT
#error Possible configuration issue, please update this file
#endif
@ -88,6 +91,30 @@ void spi_twi_irq_register_i2c(NRF_TWIM_Type *bus,
NVIC_EnableIRQ(_isr[num]);
}
void nrf5x_i2c_acquire(NRF_TWIM_Type *bus)
{
size_t num = _i2c_dev2num(bus);
mutex_lock(&_locks[num]);
}
void nrf5x_spi_acquire(NRF_SPIM_Type *bus)
{
size_t num = _spi_dev2num(bus);
mutex_lock(&_locks[num]);
}
void nrf5x_i2c_release(NRF_TWIM_Type *bus)
{
size_t num = _i2c_dev2num(bus);
mutex_unlock(&_locks[num]);
}
void nrf5x_spi_release(NRF_SPIM_Type *bus)
{
size_t num = _spi_dev2num(bus);
mutex_unlock(&_locks[num]);
}
/* Check if UART driver doesn't already use the same IRQ */
#ifndef UART_0_ISR
void isr_uarte0_spim0_spis0_twim0_twis0(void)