Skip to content

Commit

Permalink
Merge pull request #8489 from basilfx/feature/efm32_i2c_mutex
Browse files Browse the repository at this point in the history
cpu: efm32: use static mutex initialization.
  • Loading branch information
basilfx committed Feb 14, 2018
2 parents 4947e8a + 76ca2c9 commit 2b7dc32
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cpu/efm32/periph/i2c.c
Expand Up @@ -34,7 +34,14 @@

static volatile I2C_TransferReturn_TypeDef i2c_progress[I2C_NUMOF];

static mutex_t i2c_lock[I2C_NUMOF];
/**
* @brief Initialized bus locks (we have a maximum of three devices)
*/
static mutex_t i2c_lock[] = {
MUTEX_INIT,
MUTEX_INIT,
MUTEX_INIT
};

/**
* @brief Start and track an I2C transfer.
Expand Down Expand Up @@ -63,14 +70,14 @@ static void _transfer(i2c_t dev, I2C_TransferSeq_TypeDef *transfer)

int i2c_init_master(i2c_t dev, i2c_speed_t speed)
{
/* assert number of locks */
assert(I2C_NUMOF <= (sizeof(i2c_lock) / sizeof(i2c_lock[0])));

/* check if device is valid */
if (dev >= I2C_NUMOF) {
return -1;
}

/* initialize lock */
mutex_init(&i2c_lock[dev]);

/* enable clocks */
CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(i2c_config[dev].cmu, true);
Expand Down

0 comments on commit 2b7dc32

Please sign in to comment.