summaryrefslogtreecommitdiff
path: root/chip/nrf51
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2019-03-11 16:07:55 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-03-26 04:42:56 -0700
commitac77140b7f4f42075d2377fc9d956a636b05aacf (patch)
treec64c6a30916ff741a2ab235141f7bd071cd54483 /chip/nrf51
parentbb266fc26fc05d4ab22de6ad7bce5b477c9f9140 (diff)
downloadchrome-ec-ac77140b7f4f42075d2377fc9d956a636b05aacf.tar.gz
common: bit change 1 << constants with BIT(constants)
Mechanical replacement of bit operation where operand is a constant. More bit operation exist, but prone to errors. Reveal a bug in npcx: chip/npcx/system-npcx7.c:114:54: error: conversion from 'long unsigned int' to 'uint8_t' {aka 'volatile unsigned char'} changes value from '16777215' to '255' [-Werror=overflow] BUG=None BRANCH=None TEST=None Change-Id: I006614026143fa180702ac0d1cc2ceb1b3c6eeb0 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1518660 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'chip/nrf51')
-rw-r--r--chip/nrf51/bluetooth_le.c14
-rw-r--r--chip/nrf51/config_chip.h2
-rw-r--r--chip/nrf51/gpio.c2
-rw-r--r--chip/nrf51/ppi.c16
-rw-r--r--chip/nrf51/radio_test.c2
-rw-r--r--chip/nrf51/uart.c8
6 files changed, 22 insertions, 22 deletions
diff --git a/chip/nrf51/bluetooth_le.c b/chip/nrf51/bluetooth_le.c
index 7fe80ff8e1..f4747cf83e 100644
--- a/chip/nrf51/bluetooth_le.c
+++ b/chip/nrf51/bluetooth_le.c
@@ -48,20 +48,20 @@ static void nrf2ble_packet(struct ble_pdu *ble_p,
ble_p->header_type_adv = 1;
ble_p->header.adv.type = radio_p->s0 & 0xf;
ble_p->header.adv.txaddr = (radio_p->s0 &
- (1 << BLE_ADV_HEADER_TXADD_SHIFT)) != 0;
+ BIT(BLE_ADV_HEADER_TXADD_SHIFT)) != 0;
ble_p->header.adv.rxaddr = (radio_p->s0 &
- (1 << BLE_ADV_HEADER_RXADD_SHIFT)) != 0;
+ BIT(BLE_ADV_HEADER_RXADD_SHIFT)) != 0;
/* Length check? 6-37 Bytes */
ble_p->header.adv.length = radio_p->length;
} else {
ble_p->header_type_adv = 0;
ble_p->header.data.llid = radio_p->s0 & 0x3;
ble_p->header.data.nesn = (radio_p->s0 &
- (1 << BLE_DATA_HEADER_NESN_SHIFT)) != 0;
+ BIT(BLE_DATA_HEADER_NESN_SHIFT)) != 0;
ble_p->header.data.sn = (radio_p->s0 &
- (1 << BLE_DATA_HEADER_SN_SHIFT)) != 0;
+ BIT(BLE_DATA_HEADER_SN_SHIFT)) != 0;
ble_p->header.data.md = (radio_p->s0 &
- (1 << BLE_DATA_HEADER_MD_SHIFT)) != 0;
+ BIT(BLE_DATA_HEADER_MD_SHIFT)) != 0;
/* Length check? 0-31 Bytes */
ble_p->header.data.length = radio_p->length;
}
@@ -170,8 +170,8 @@ int ble_rx(struct ble_pdu *pdu, int timeout, int adv)
*/
ppi_channel_requested = NRF51_PPI_CH_RADIO_ADDR__TIMER0CC1;
if (ppi_request_channel(&ppi_channel_requested) == EC_SUCCESS) {
- NRF51_PPI_CHEN |= (1 << ppi_channel_requested);
- NRF51_PPI_CHENSET |= (1 << ppi_channel_requested);
+ NRF51_PPI_CHEN |= BIT(ppi_channel_requested);
+ NRF51_PPI_CHENSET |= BIT(ppi_channel_requested);
}
diff --git a/chip/nrf51/config_chip.h b/chip/nrf51/config_chip.h
index 374101d1bb..eb2ee93509 100644
--- a/chip/nrf51/config_chip.h
+++ b/chip/nrf51/config_chip.h
@@ -57,7 +57,7 @@
#undef CONFIG_UART_TX_BUF_SIZE
#define CONFIG_UART_TX_BUF_SIZE 1024
-#define GPIO_PIN(port, index) GPIO_##port, (1 << index)
+#define GPIO_PIN(port, index) GPIO_##port, BIT(index)
#define GPIO_PIN_MASK(p, m) .port = GPIO_##p, .mask = (m)
#endif /* __CROS_EC_CONFIG_CHIP_H */
diff --git a/chip/nrf51/gpio.c b/chip/nrf51/gpio.c
index 3ad55f2b38..a01ee49940 100644
--- a/chip/nrf51/gpio.c
+++ b/chip/nrf51/gpio.c
@@ -164,7 +164,7 @@ void gpio_set_alternate_function(uint32_t port, uint32_t mask, int func)
{
uint32_t bit = GPIO_MASK_TO_NUM(mask);
- ASSERT((~mask & (1 << bit)) == 0); /* Only one bit set. */
+ ASSERT((~mask & BIT(bit)) == 0); /* Only one bit set. */
ASSERT(port == GPIO_0);
ASSERT((func >= 0 && func < nrf51_alt_func_count) || func == -1);
diff --git a/chip/nrf51/ppi.c b/chip/nrf51/ppi.c
index d0be87f2ba..016cbf3008 100644
--- a/chip/nrf51/ppi.c
+++ b/chip/nrf51/ppi.c
@@ -18,10 +18,10 @@ int ppi_request_pre_programmed_channel(int ppi_chan)
ASSERT(ppi_chan >= NRF51_PPI_FIRST_PP_CH &&
ppi_chan <= NRF51_PPI_LAST_PP_CH);
- if (channels_in_use & (1 << ppi_chan))
+ if (channels_in_use & BIT(ppi_chan))
return EC_ERROR_BUSY;
- channels_in_use |= (1 << ppi_chan);
+ channels_in_use |= BIT(ppi_chan);
return EC_SUCCESS;
}
@@ -31,25 +31,25 @@ int ppi_request_channel(int *ppi_chan)
int chan;
for (chan = 0; chan < NRF51_PPI_NUM_PROGRAMMABLE_CHANNELS; chan++)
- if ((channels_in_use & (1 << chan)) == 0)
+ if ((channels_in_use & BIT(chan)) == 0)
break;
if (chan == NRF51_PPI_NUM_PROGRAMMABLE_CHANNELS)
return EC_ERROR_BUSY;
- channels_in_use |= (1 << chan);
+ channels_in_use |= BIT(chan);
*ppi_chan = chan;
return EC_SUCCESS;
}
void ppi_release_channel(int ppi_chan)
{
- channels_in_use &= ~(1 << ppi_chan);
+ channels_in_use &= ~BIT(ppi_chan);
}
void ppi_release_group(int ppi_group)
{
- channel_groups_in_use &= ~(1 << ppi_group);
+ channel_groups_in_use &= ~BIT(ppi_group);
}
int ppi_request_group(int *ppi_group)
@@ -57,13 +57,13 @@ int ppi_request_group(int *ppi_group)
int group;
for (group = 0; group < NRF51_PPI_NUM_GROUPS; group++)
- if ((channel_groups_in_use & (1 << group)) == 0)
+ if ((channel_groups_in_use & BIT(group)) == 0)
break;
if (group == NRF51_PPI_NUM_GROUPS)
return EC_ERROR_BUSY;
- channel_groups_in_use |= (1 << group);
+ channel_groups_in_use |= BIT(group);
*ppi_group = group;
return EC_SUCCESS;
}
diff --git a/chip/nrf51/radio_test.c b/chip/nrf51/radio_test.c
index 5afb30425b..6c20874f4e 100644
--- a/chip/nrf51/radio_test.c
+++ b/chip/nrf51/radio_test.c
@@ -145,7 +145,7 @@ int ble_test_rx_init(int chan)
int ble_test_tx_init(int chan, int len, int type)
{
- if (((1 << type) & BLE_TEST_TYPES_IMPLEMENTED) == 0 ||
+ if ((BIT(type) & BLE_TEST_TYPES_IMPLEMENTED) == 0 ||
(len < 0 || len > BLE_MAX_TEST_PAYLOAD_OCTETS))
return HCI_ERR_Invalid_HCI_Command_Parameters;
diff --git a/chip/nrf51/uart.c b/chip/nrf51/uart.c
index ab52c6ad9a..eb94e53c98 100644
--- a/chip/nrf51/uart.c
+++ b/chip/nrf51/uart.c
@@ -34,13 +34,13 @@ void uart_tx_start(void)
{
disable_sleep(SLEEP_MASK_UART);
should_stop = 0;
- NRF51_UART_INTENSET = (1 << NRF55_UART_TXDRDY_BIT);
+ NRF51_UART_INTENSET = BIT(NRF55_UART_TXDRDY_BIT);
task_trigger_irq(NRF51_PERID_USART);
}
void uart_tx_stop(void)
{
- NRF51_UART_INTENCLR = (1 << NRF55_UART_TXDRDY_BIT);
+ NRF51_UART_INTENCLR = BIT(NRF55_UART_TXDRDY_BIT);
should_stop = 1;
enable_sleep(SLEEP_MASK_UART);
}
@@ -96,7 +96,7 @@ void uart_interrupt(void)
#ifndef CONFIG_UART_TX_DMA
if (!should_stop)
- NRF51_UART_INTENSET = (1 << NRF55_UART_TXDRDY_BIT);
+ NRF51_UART_INTENSET = BIT(NRF55_UART_TXDRDY_BIT);
#endif /* CONFIG_UART_TX_DMA */
}
@@ -113,7 +113,7 @@ void uart_init(void)
task_enable_irq(NRF51_PERID_USART);
- NRF51_UART_INTENSET = (1 << NRF55_UART_RXDRDY_BIT);
+ NRF51_UART_INTENSET = BIT(NRF55_UART_RXDRDY_BIT);
NRF51_UART_STARTRX = 1;
init_done = 1;