mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cpu/periph/i2c: update implementations to new I2C API
Make all `spi_acquire` implementations return `void` and add assertions to check for valid device identifier where missing.
This commit is contained in:
parent
3d93b2bcf0
commit
007e29ebb5
@ -22,11 +22,12 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "mutex.h"
|
||||
#include "assert.h"
|
||||
#include "periph/i2c.h"
|
||||
#include "periph_conf.h"
|
||||
|
||||
@ -219,12 +220,11 @@ int i2c_write_bytes(i2c_t dev, uint16_t addr, const void *data, size_t len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
mutex_lock(&locks[dev]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -18,6 +18,7 @@
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "cpu.h"
|
||||
@ -74,10 +75,7 @@ void i2c_init(i2c_t i2c)
|
||||
{
|
||||
uint8_t baudrate;
|
||||
|
||||
if (i2c >= I2C_NUMOF) {
|
||||
DEBUG("[i2c] init: dev is invalid.\n");
|
||||
return;
|
||||
}
|
||||
assert((unsigned)i2c < I2C_NUMOF);
|
||||
|
||||
baudrate = _i2c_calc_baud(i2c);
|
||||
if (baudrate == 0) {
|
||||
@ -97,12 +95,14 @@ void i2c_init(i2c_t i2c)
|
||||
|
||||
void i2c_init_pins(i2c_t i2c)
|
||||
{
|
||||
assert((unsigned)i2c < I2C_NUMOF);
|
||||
gpio_init(i2c_config[i2c].sda_pin, GPIO_OPC_WRD_AND_PULL);
|
||||
gpio_init(i2c_config[i2c].scl_pin, GPIO_OPC_WRD_AND_PULL);
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t i2c)
|
||||
void i2c_acquire(i2c_t i2c)
|
||||
{
|
||||
assert((unsigned)i2c < I2C_NUMOF);
|
||||
DEBUG("acquire\n");
|
||||
pm_block(3);
|
||||
mutex_lock(&i2c_ctx[i2c].locks);
|
||||
@ -113,12 +113,11 @@ int i2c_acquire(i2c_t i2c)
|
||||
| TWI_MASTER_WIEN_bm
|
||||
| TWI_MASTER_ENABLE_bm;
|
||||
dev(i2c)->MASTER.STATUS = TWI_MASTER_BUSSTATE_IDLE_gc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t i2c)
|
||||
{
|
||||
assert((unsigned)i2c < I2C_NUMOF);
|
||||
dev(i2c)->MASTER.CTRLA = 0;
|
||||
pm_periph_disable(i2c_config[i2c].pwr);
|
||||
mutex_unlock(&i2c_ctx[i2c].locks);
|
||||
@ -129,6 +128,8 @@ void i2c_release(i2c_t i2c)
|
||||
static int _i2c_transaction(i2c_t i2c, uint16_t addr, const void *data,
|
||||
size_t len, uint8_t flags, bool is_read)
|
||||
{
|
||||
assert((unsigned)i2c < I2C_NUMOF);
|
||||
|
||||
if (flags & I2C_ADDR10) {
|
||||
DEBUG("[i2c] xfer: no 10 bit address support.\n");
|
||||
return -EOPNOTSUPP;
|
||||
@ -238,6 +239,8 @@ static inline void _i2c_read_handler(int i2c)
|
||||
*/
|
||||
static inline void isr_handler(int i2c)
|
||||
{
|
||||
assert((unsigned)i2c < I2C_NUMOF);
|
||||
|
||||
avr8_enter_isr();
|
||||
|
||||
int8_t const m_status = dev(i2c)->MASTER.STATUS;
|
||||
|
@ -231,14 +231,12 @@ void i2c_init(i2c_t dev)
|
||||
DEBUG(" - I2C master status (0x%x).\n", _i2c_master_stat_get());
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
(void)dev;
|
||||
assert(dev < I2C_NUMOF);
|
||||
DEBUG("%s\n", __FUNCTION__);
|
||||
if (dev < I2C_NUMOF) {
|
||||
mutex_lock(&lock);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
mutex_lock(&lock);
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -126,12 +126,11 @@ void i2c_init(i2c_t devnum)
|
||||
I2C->MTPR = MTPR_TPR_100KHZ;
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
(void)dev;
|
||||
assert(dev < I2C_NUMOF);
|
||||
mutex_lock(&_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -142,15 +142,15 @@ void i2c_init(i2c_t dev)
|
||||
I2C_Enable(i2c_config[dev].dev, true);
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
/* acquire lock */
|
||||
mutex_lock(&i2c_lock[dev]);
|
||||
|
||||
/* power peripheral */
|
||||
CMU_ClockEnable(i2c_config[dev].cmu, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -145,7 +145,7 @@ static inline void _i2c_delay (uint32_t delay);
|
||||
|
||||
void i2c_init(i2c_t dev)
|
||||
{
|
||||
CHECK_PARAM (dev < I2C_NUMOF)
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
if (i2c_config[dev].speed == I2C_SPEED_FAST_PLUS ||
|
||||
i2c_config[dev].speed == I2C_SPEED_HIGH) {
|
||||
@ -156,7 +156,7 @@ void i2c_init(i2c_t dev)
|
||||
|
||||
mutex_init(&_i2c_bus[dev].lock);
|
||||
|
||||
i2c_acquire (dev);
|
||||
i2c_acquire(dev);
|
||||
|
||||
_i2c_bus[dev].cmd = 0;
|
||||
_i2c_bus[dev].data = 0;
|
||||
@ -262,20 +262,17 @@ void i2c_init(i2c_t dev)
|
||||
xt_set_interrupt_handler(CPU_INUM_I2C, _i2c_intr_handler, NULL);
|
||||
xt_ints_on(BIT(CPU_INUM_I2C));
|
||||
|
||||
i2c_release (dev);
|
||||
|
||||
return;
|
||||
i2c_release(dev);
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
DEBUG ("%s\n", __func__);
|
||||
|
||||
CHECK_PARAM_RET (dev < I2C_NUMOF, -1)
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
mutex_lock(&_i2c_bus[dev].lock);
|
||||
_i2c_reset_hw(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
@ -358,9 +355,9 @@ int i2c_read_bytes(i2c_t dev, uint16_t addr, void *data, size_t len, uint8_t fla
|
||||
DEBUG ("%s dev=%u addr=%02x data=%p len=%d flags=%01x\n",
|
||||
__func__, dev, addr, data, len, flags);
|
||||
|
||||
CHECK_PARAM_RET (dev < I2C_NUMOF, -EINVAL);
|
||||
CHECK_PARAM_RET (len > 0, -EINVAL);
|
||||
CHECK_PARAM_RET (data != NULL, -EINVAL);
|
||||
assert(dev < I2C_NUMOF);
|
||||
assert(len > 0);
|
||||
assert(data != NULL);
|
||||
|
||||
/* if I2C_NOSTART is not set, START condition and ADDR is used */
|
||||
if (!(flags & I2C_NOSTART)) {
|
||||
@ -445,9 +442,9 @@ int i2c_write_bytes(i2c_t dev, uint16_t addr, const void *data, size_t len, uint
|
||||
DEBUG ("%s dev=%u addr=%02x data=%p len=%d flags=%01x\n",
|
||||
__func__, dev, addr, data, len, flags);
|
||||
|
||||
CHECK_PARAM_RET (dev < I2C_NUMOF, -EINVAL);
|
||||
CHECK_PARAM_RET (len > 0, -EINVAL);
|
||||
CHECK_PARAM_RET (data != NULL, -EINVAL);
|
||||
assert(dev < I2C_NUMOF);
|
||||
assert(len > 0);
|
||||
assert(data != NULL);
|
||||
|
||||
/* if I2C_NOSTART is not set, START condition and ADDR is used */
|
||||
if (!(flags & I2C_NOSTART)) {
|
||||
|
@ -246,12 +246,11 @@ void i2c_init(i2c_t dev)
|
||||
return;
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
mutex_lock(&_i2c_bus[dev].lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -90,11 +90,10 @@ void i2c_init(i2c_t dev)
|
||||
DEBUG("[i2c] initialization done\n");
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
mutex_lock(&locks[dev]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -106,12 +106,11 @@ typedef struct {
|
||||
|
||||
static i2c_state_t i2c_state[I2C_NUMOF];
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert((unsigned)dev < I2C_NUMOF);
|
||||
mutex_lock(&i2c_state[dev].mtx);
|
||||
i2c_state[dev].pid = thread_getpid();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -103,14 +103,12 @@ static void poweroff(lpc23xx_i2c_t *i2c)
|
||||
}
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
mutex_lock(&ctx[dev].lock);
|
||||
poweron(i2c_config[dev].dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
@ -332,6 +330,8 @@ static void irq_handler(i2c_t dev)
|
||||
}
|
||||
|
||||
/* clear interrupt flag */
|
||||
/* cppcheck-suppress redundantAssignment
|
||||
* (reason: writing 1 to volatile register to clear the interrupt) */
|
||||
i2c->CONCLR = I2CONCLR_SIC;
|
||||
}
|
||||
|
||||
|
@ -132,12 +132,11 @@ void i2c_init(i2c_t dev)
|
||||
i2c(dev)->ENABLE = TWI_ENABLE_ENABLE_Enabled;
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
mutex_lock(&locks[dev]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -154,7 +154,7 @@ void i2c_deinit_pins(i2c_t dev)
|
||||
}
|
||||
#endif /* MODULE_PERIPH_I2C_RECONFIGURE */
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
@ -162,7 +162,6 @@ int i2c_acquire(i2c_t dev)
|
||||
bus(dev)->ENABLE = TWIM_ENABLE_ENABLE_Enabled;
|
||||
|
||||
DEBUG("[i2c] acquired dev %i\n", (int)dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -153,11 +153,10 @@ void i2c_deinit_pins(i2c_t dev)
|
||||
}
|
||||
#endif /* MODULE_PERIPH_I2C_RECONFIGURE */
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
mutex_lock(&locks[dev]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -194,11 +194,10 @@ void i2c_init(i2c_t dev)
|
||||
}
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
mutex_lock(&locks[dev]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -135,7 +135,7 @@ static void _i2c_init(I2C_TypeDef *i2c, uint32_t timing)
|
||||
i2c->CR1 |= I2C_CR1_PE;
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
@ -145,8 +145,6 @@ int i2c_acquire(i2c_t dev)
|
||||
|
||||
/* enable device */
|
||||
i2c_config[dev].dev->CR1 |= I2C_CR1_PE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
@ -180,7 +180,7 @@ static void _init(i2c_t dev)
|
||||
_i2c_init(i2c, i2c_config[dev].clk, ccr);
|
||||
}
|
||||
|
||||
int i2c_acquire(i2c_t dev)
|
||||
void i2c_acquire(i2c_t dev)
|
||||
{
|
||||
assert(dev < I2C_NUMOF);
|
||||
|
||||
@ -195,8 +195,6 @@ int i2c_acquire(i2c_t dev)
|
||||
|
||||
/* enable device */
|
||||
i2c_config[dev].dev->CR1 |= I2C_CR1_PE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_release(i2c_t dev)
|
||||
|
Loading…
Reference in New Issue
Block a user