Skip to content

Commit f4e07d1

Browse files
cfriedtdleach02
authored andcommitted
sys: util: define bits per byte, nibble, and nibbles per byte
Collect some common bit-widths redefined in various locations and put them under sys/util.h . Signed-off-by: Chris Friedt <[email protected]>
1 parent b40cb4c commit f4e07d1

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

drivers/clock_control/clock_control_litex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#ifndef LITEX_MMCM_H
88
#define LITEX_MMCM_H
99

10+
#include <zephyr/sys/util.h>
1011
#include <zephyr/types.h>
1112

1213
/* Common values */
13-
#define PICOS_IN_SEC 1000000000000
14-
#define BITS_PER_BYTE 8
14+
#define PICOS_IN_SEC 1000000000000
1515

1616
/* MMCM specific numbers */
1717
#define CLKOUT_MAX 7

drivers/fpga/fpga_ice40.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <zephyr/kernel.h>
2020
#include <zephyr/logging/log.h>
2121
#include <zephyr/sys/crc.h>
22+
#include <zephyr/sys/util.h>
2223

2324
/*
2425
* Note: When loading a bitstream, the iCE40 has a 'quirk' in that the CS
@@ -50,18 +51,6 @@
5051
#define FPGA_ICE40_LOAD_MODE_SPI 0
5152
#define FPGA_ICE40_LOAD_MODE_GPIO 1
5253

53-
#ifndef BITS_PER_NIBBLE
54-
#define BITS_PER_NIBBLE 4
55-
#endif
56-
57-
#ifndef BITS_PER_BYTE
58-
#define BITS_PER_BYTE 8
59-
#endif
60-
61-
#ifndef NIBBLES_PER_BYTE
62-
#define NIBBLES_PER_BYTE (BITS_PER_BYTE / BITS_PER_NIBBLE)
63-
#endif
64-
6554
/*
6655
* Values in Hz, intentionally to be comparable with the spi-max-frequency
6756
* property from DT bindings in spi-device.yaml.

include/zephyr/sys/util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ extern "C" {
5757
# error Missing required predefined macros for BITS_PER_LONG calculation
5858
#endif
5959

60+
/** Number of bits in a byte. */
61+
#define BITS_PER_BYTE (__CHAR_BIT__)
62+
63+
/** Number of bits in a nibble. */
64+
#define BITS_PER_NIBBLE (__CHAR_BIT__ / 2)
65+
66+
/** Number of nibbles in a byte. */
67+
#define NIBBLES_PER_BYTE (BITS_PER_BYTE / BITS_PER_NIBBLE)
68+
6069
/** Number of bits in a long int. */
6170
#define BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__)
6271

subsys/shell/modules/devmem_service.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <zephyr/device.h>
1919
#include <zephyr/shell/shell.h>
2020
#include <zephyr/sys/byteorder.h>
21+
#include <zephyr/sys/util.h>
2122

2223
#ifndef CONFIG_NATIVE_LIBC
2324
extern void getopt_init(void);
@@ -39,10 +40,6 @@ static bool littleendian;
3940
#define CHAR_CAN 0x18
4041
#define CHAR_DC1 0x11
4142

42-
#ifndef BITS_PER_BYTE
43-
#define BITS_PER_BYTE 8
44-
#endif
45-
4643
static int memory_dump(const struct shell *sh, mem_addr_t phys_addr, size_t size, uint8_t width)
4744
{
4845
uint32_t value;

0 commit comments

Comments
 (0)