Skip to content

Commit

Permalink
cpu/atmega_common: Add PM on peripherals
Browse files Browse the repository at this point in the history
Add PM blocks to adc/i2c/spi peripherals.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
  • Loading branch information
nandojve committed Jul 6, 2023
1 parent 60e83a3 commit e5c09bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cpu/atmega_common/periph/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "cpu.h"
#include "mutex.h"
#include "periph/adc.h"
#include "periph/pm.h"
#include "periph_conf.h"

#define ADC_MAX_CLK (200000U)
Expand All @@ -33,6 +34,7 @@ static mutex_t lock = MUTEX_INIT;

static inline void _prep(void)
{
pm_block(3); /* Require clkADC */
mutex_lock(&lock);
/* Enable ADC */
ADCSRA |= (1 << ADEN);
Expand All @@ -43,6 +45,7 @@ static inline void _done(void)
/* Disable ADC */
ADCSRA &= ~(1 << ADEN);
mutex_unlock(&lock);
pm_unblock(3);
}

int adc_init(adc_t line)
Expand Down
3 changes: 3 additions & 0 deletions cpu/atmega_common/periph/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "cpu.h"
#include "mutex.h"
#include "periph/i2c.h"
#include "periph/pm.h"
#include "periph_conf.h"

#define ENABLE_DEBUG 0
Expand Down Expand Up @@ -226,6 +227,7 @@ void i2c_acquire(i2c_t dev)
{
assert(dev < I2C_NUMOF);

pm_block(4); /* Require clkIO */
mutex_lock(&locks[dev]);
}

Expand All @@ -234,6 +236,7 @@ void i2c_release(i2c_t dev)
assert(dev < I2C_NUMOF);

mutex_unlock(&locks[dev]);
pm_unblock(4);
}

static void i2c_poweron(i2c_t dev)
Expand Down
3 changes: 3 additions & 0 deletions cpu/atmega_common/periph/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "cpu.h"
#include "mutex.h"
#include "periph/spi.h"
#include "periph/pm.h"

/**
* @brief Extract BR0, BR1 and SPI2X bits from speed value
Expand Down Expand Up @@ -89,6 +90,7 @@ void spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk)
assert(bus == SPI_DEV(0));

/* lock the bus and power on the SPI peripheral */
pm_block(4); /* Require clkIO */
mutex_lock(&lock);
#ifdef PRSPI
power_spi_enable();
Expand All @@ -112,6 +114,7 @@ void spi_release(spi_t bus)
power_spi_disable();
#endif
mutex_unlock(&lock);
pm_unblock(4);
}

void spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont,
Expand Down

0 comments on commit e5c09bf

Please sign in to comment.