Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cpu/stm32l1: Use {} notation for empty while loops
  • Loading branch information
Joakim Nohlgård committed Mar 3, 2016
1 parent 7a72020 commit 5bfd4a5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions cpu/stm32l1/cpu.c
Expand Up @@ -68,7 +68,7 @@ static void clk_init(void)
RCC->CR |= CLOCK_CR_SOURCE;
/* Wait till the high speed clock source is ready
* NOTE: the MCU will stay here forever if you use an external clock source and it's not connected */
while (!(RCC->CR & CLOCK_CR_SOURCE_RDY));
while (!(RCC->CR & CLOCK_CR_SOURCE_RDY)) {}
FLASH->ACR |= FLASH_ACR_ACC64;
/* Enable Prefetch Buffer */
FLASH->ACR |= FLASH_ACR_PRFTEN;
Expand All @@ -79,7 +79,7 @@ static void clk_init(void)
/* Select the Voltage Range 1 (1.8 V) */
PWR->CR = PWR_CR_VOS_0;
/* Wait Until the Voltage Regulator is ready */
while((PWR->CSR & PWR_CSR_VOSF) != 0);
while((PWR->CSR & PWR_CSR_VOSF) != 0) {}
/* HCLK = SYSCLK */
RCC->CFGR |= (uint32_t)CLOCK_AHB_DIV;
/* PCLK2 = HCLK */
Expand All @@ -92,10 +92,10 @@ static void clk_init(void)
/* Enable PLL */
RCC->CR |= RCC_CR_PLLON;
/* Wait till PLL is ready */
while ((RCC->CR & RCC_CR_PLLRDY) == 0);
while ((RCC->CR & RCC_CR_PLLRDY) == 0) {}
/* Select PLL as system clock source */
RCC->CFGR &= ~((uint32_t)(RCC_CFGR_SW));
RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL);
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL) {}
}
32 changes: 16 additions & 16 deletions cpu/stm32l1/periph/i2c.c
Expand Up @@ -171,13 +171,13 @@ int i2c_read_bytes(i2c_t dev, uint8_t address, char *data, int length)

DEBUG("Wait for RXNE == 1\n");

while (!(i2c->SR1 & I2C_SR1_RXNE));
while (!(i2c->SR1 & I2C_SR1_RXNE)) {}

DEBUG("Read received data\n");
*data = (char)i2c->DR;

/* wait until STOP is cleared by hardware */
while (i2c->CR1 & I2C_CR1_STOP);
while (i2c->CR1 & I2C_CR1_STOP) {}

/* reset ACK to be able to receive new data */
i2c->CR1 |= (I2C_CR1_ACK);
Expand All @@ -196,7 +196,7 @@ int i2c_read_bytes(i2c_t dev, uint8_t address, char *data, int length)

DEBUG("Wait for transfer to be completed\n");

while (!(i2c->SR1 & I2C_SR1_BTF));
while (!(i2c->SR1 & I2C_SR1_BTF)) {}

DEBUG("Crit block: set STOP and read first byte\n");
state = disableIRQ();
Expand All @@ -209,7 +209,7 @@ int i2c_read_bytes(i2c_t dev, uint8_t address, char *data, int length)

DEBUG("wait for STOP bit to be cleared again\n");

while (i2c->CR1 & I2C_CR1_STOP);
while (i2c->CR1 & I2C_CR1_STOP) {}

DEBUG("reset POS = 0 and ACK = 1\n");
i2c->CR1 &= ~(I2C_CR1_POS);
Expand All @@ -224,15 +224,15 @@ int i2c_read_bytes(i2c_t dev, uint8_t address, char *data, int length)
while (i < (length - 3)) {
DEBUG("Wait until byte was received\n");

while (!(i2c->SR1 & I2C_SR1_RXNE));
while (!(i2c->SR1 & I2C_SR1_RXNE)) {}

DEBUG("Copy byte from DR\n");
data[i++] = (char)i2c->DR;
}

DEBUG("Reading the last 3 bytes, waiting for BTF flag\n");

while (!(i2c->SR1 & I2C_SR1_BTF));
while (!(i2c->SR1 & I2C_SR1_BTF)) {}

DEBUG("Disable ACK\n");
i2c->CR1 &= ~(I2C_CR1_ACK);
Expand All @@ -246,15 +246,15 @@ int i2c_read_bytes(i2c_t dev, uint8_t address, char *data, int length)
DEBUG("Read N-1 byte\n");
data[i++] = (char)i2c->DR;

while (!(i2c->SR1 & I2C_SR1_RXNE));
while (!(i2c->SR1 & I2C_SR1_RXNE)) {}

DEBUG("Read last byte\n");

data[i++] = (char)i2c->DR;

DEBUG("wait for STOP bit to be cleared again\n");

while (i2c->CR1 & I2C_CR1_STOP);
while (i2c->CR1 & I2C_CR1_STOP) {}

DEBUG("reset POS = 0 and ACK = 1\n");
i2c->CR1 &= ~(I2C_CR1_POS);
Expand Down Expand Up @@ -350,7 +350,7 @@ void i2c_poweron(i2c_t dev)
void i2c_poweroff(i2c_t dev)
{
if ((unsigned int)dev < I2C_NUMOF) {
while (i2c_config[dev].dev->SR2 & I2C_SR2_BUSY);
while (i2c_config[dev].dev->SR2 & I2C_SR2_BUSY) {}
RCC->APB1ENR &= ~(RCC_APB1ENR_I2C1EN << dev);
}
}
Expand All @@ -360,22 +360,22 @@ static void _start(I2C_TypeDef *i2c, uint8_t address, uint8_t rw_flag)
/* wait for device to be ready */
DEBUG("Wait for device to be ready\n");

while (i2c->SR2 & I2C_SR2_BUSY);
while (i2c->SR2 & I2C_SR2_BUSY) {}

/* generate start condition */
DEBUG("Generate start condition\n");
i2c->CR1 |= I2C_CR1_START;
DEBUG("Wait for SB flag to be set\n");

while (!(i2c->SR1 & I2C_SR1_SB));
while (!(i2c->SR1 & I2C_SR1_SB)) {}

/* send address and read/write flag */
DEBUG("Send address\n");
i2c->DR = (address << 1) | rw_flag;
/* clear ADDR flag by reading first SR1 and then SR2 */
DEBUG("Wait for ADDR flag to be set\n");

while (!(i2c->SR1 & I2C_SR1_ADDR));
while (!(i2c->SR1 & I2C_SR1_ADDR)) {}
}

static inline void _clear_addr(I2C_TypeDef *i2c)
Expand All @@ -395,7 +395,7 @@ static inline void _write(I2C_TypeDef *i2c, char *data, int length)
DEBUG("Written %i byte to data reg, now waiting for DR to be empty again\n", i);

/* wait for transfer to finish */
while (!(i2c->SR1 & I2C_SR1_TXE));
while (!(i2c->SR1 & I2C_SR1_TXE)) {}

DEBUG("DR is now empty again\n");
}
Expand All @@ -406,7 +406,7 @@ static inline void _stop(I2C_TypeDef *i2c)
/* make sure last byte was send */
DEBUG("Wait if last byte hasn't been sent\n");

while (!(i2c->SR1 & I2C_SR1_BTF));
while (!(i2c->SR1 & I2C_SR1_BTF)) {}

/* send STOP condition */
i2c->CR1 |= I2C_CR1_STOP;
Expand Down Expand Up @@ -439,7 +439,7 @@ void I2C_0_ERR_ISR(void)
if (state & I2C_SR1_SMBALERT) {
DEBUG("SMBALERT\n");
}
while (1);
while (1) {}
}
#endif /* I2C_0_EN */

Expand Down Expand Up @@ -470,7 +470,7 @@ void I2C_1_ERR_ISR(void)
if (state & I2C_SR1_SMBALERT) {
DEBUG("SMBALERT\n");
}
while (1);
while (1) {}
}
#endif /* I2C_1_EN */

Expand Down
8 changes: 4 additions & 4 deletions cpu/stm32l1/periph/spi.c
Expand Up @@ -195,11 +195,11 @@ int spi_transfer_byte(spi_t dev, char out, char *in)
}

/* wait for an eventually previous byte to be readily transferred */
while(!(spi->SR & SPI_SR_TXE));
while(!(spi->SR & SPI_SR_TXE)) {}
/* put next byte into the output register */
spi->DR = out;
/* wait until the current byte was successfully transferred */
while(!(spi->SR & SPI_SR_RXNE));
while(!(spi->SR & SPI_SR_RXNE)) {}
/* read response byte to reset flags */
tmp = spi->DR;
/* 'return' response byte if wished for */
Expand Down Expand Up @@ -245,13 +245,13 @@ void spi_poweroff(spi_t dev)
switch (dev) {
#if SPI_0_EN
case SPI_0:
while (SPI_0_DEV->SR & SPI_SR_BSY);
while (SPI_0_DEV->SR & SPI_SR_BSY) {}
SPI_0_CLKDIS();
break;
#endif
#if SPI_1_EN
case SPI_1:
while (SPI_1_DEV->SR & SPI_SR_BSY);
while (SPI_1_DEV->SR & SPI_SR_BSY) {}
SPI_1_CLKDIS();
break;
#endif
Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32l1/periph/uart.c
Expand Up @@ -158,7 +158,7 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len)
}

for (size_t i = 0; i < len; i++) {
while (!(dev->SR & USART_SR_TXE));
while (!(dev->SR & USART_SR_TXE)) {}
dev->DR = data[i];
}
}
Expand Down

0 comments on commit 5bfd4a5

Please sign in to comment.