From 40d7428156f70e1e1937a8b8d2f1fa9c0f19d388 Mon Sep 17 00:00:00 2001 From: Sam Elliott Date: Fri, 29 May 2020 17:12:28 +0100 Subject: [PATCH] [sw] Add Header Extern Guards to DIFs and libbase Signed-off-by: Sam Elliott --- sw/device/lib/base/bitfield.h | 9 +++++++++ sw/device/lib/base/memory.h | 9 +++++++++ sw/device/lib/base/mmio.h | 11 +++++------ sw/device/lib/dif/dif_gpio.h | 9 +++++++++ sw/device/lib/dif/dif_plic.h | 9 +++++++++ sw/device/lib/dif/dif_spi_device.h | 9 +++++++++ sw/device/lib/dif/dif_uart.h | 9 +++++++++ 7 files changed, 59 insertions(+), 6 deletions(-) diff --git a/sw/device/lib/base/bitfield.h b/sw/device/lib/base/bitfield.h index e96134ef59570..5261425d19c75 100644 --- a/sw/device/lib/base/bitfield.h +++ b/sw/device/lib/base/bitfield.h @@ -7,6 +7,11 @@ #include +// Header Extern Guard (so header can be used from C and C++) +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + /** * Masked field offset for 32-bit bitfields, with optional value. * @@ -63,4 +68,8 @@ inline uint32_t bitfield_set_field32(uint32_t bitfield, return bitfield; } +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + #endif // OPENTITAN_SW_DEVICE_LIB_BASE_BITFIELD_H_ diff --git a/sw/device/lib/base/memory.h b/sw/device/lib/base/memory.h index afab02a76fe44..1e0f277226e23 100644 --- a/sw/device/lib/base/memory.h +++ b/sw/device/lib/base/memory.h @@ -9,6 +9,11 @@ #include #include +// Header Extern Guard (so header can be used from C and C++) +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + /** * Load a word from memory directly, bypassing aliasing rules. * @@ -133,4 +138,8 @@ void *memchr(const void *ptr, int value, size_t len); */ void *memrchr(const void *ptr, int value, size_t len); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + #endif // OPENTITAN_SW_DEVICE_LIB_BASE_MEMORY_H_ diff --git a/sw/device/lib/base/mmio.h b/sw/device/lib/base/mmio.h index c13c9b54df552..575a036e70bb8 100644 --- a/sw/device/lib/base/mmio.h +++ b/sw/device/lib/base/mmio.h @@ -5,18 +5,17 @@ #ifndef OPENTITAN_SW_DEVICE_LIB_BASE_MMIO_H_ #define OPENTITAN_SW_DEVICE_LIB_BASE_MMIO_H_ -// This file is included in C and C++, and, as such, needs to be marked as -// extern "C" in C++ to make sure linking works out. -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - #include #include #include #include "sw/device/lib/base/bitfield.h" +// Header Extern Guard (so header can be used from C and C++) +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + /** * Memory-mapped IO functions, which either map to volatile accesses, or can be * replaced with instrumentation calls at compile time, for use with tests. diff --git a/sw/device/lib/dif/dif_gpio.h b/sw/device/lib/dif/dif_gpio.h index 82537031357e6..669e0e00c4cbc 100644 --- a/sw/device/lib/dif/dif_gpio.h +++ b/sw/device/lib/dif/dif_gpio.h @@ -10,6 +10,11 @@ #include "sw/device/lib/base/mmio.h" +// Header Extern Guard (so header can be used from C and C++) +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + /** * Configuration for initializing a GPIO device. */ @@ -343,4 +348,8 @@ dif_gpio_result_t dif_gpio_irq_trigger_masked_config(const dif_gpio_t *gpio, uint32_t mask, dif_gpio_irq_t config); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_GPIO_H_ diff --git a/sw/device/lib/dif/dif_plic.h b/sw/device/lib/dif/dif_plic.h index 0d71db506b643..bd5b8e61d8bd4 100644 --- a/sw/device/lib/dif/dif_plic.h +++ b/sw/device/lib/dif/dif_plic.h @@ -10,6 +10,11 @@ #include "sw/device/lib/base/mmio.h" +// Header Extern Guard (so header can be used from C and C++) +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + /** The lowest interrupt priority. */ extern const uint32_t kDifPlicMinPriority; @@ -203,4 +208,8 @@ dif_plic_result_t dif_plic_irq_complete(const dif_plic_t *plic, dif_plic_target_t target, const dif_plic_irq_id_t *complete_data); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_PLIC_H_ diff --git a/sw/device/lib/dif/dif_spi_device.h b/sw/device/lib/dif/dif_spi_device.h index 748fd3a2a9f14..5b3dc7f156045 100644 --- a/sw/device/lib/dif/dif_spi_device.h +++ b/sw/device/lib/dif/dif_spi_device.h @@ -10,6 +10,11 @@ #include "sw/device/lib/base/mmio.h" +// Header Extern Guard (so header can be used from C and C++) +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + /** * Represents a signal edge type. */ @@ -242,4 +247,8 @@ dif_spi_device_result_t dif_spi_device_send(const dif_spi_device_t *spi, const void *buf, size_t buf_len, size_t *bytes_sent); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_SPI_DEVICE_H_ diff --git a/sw/device/lib/dif/dif_uart.h b/sw/device/lib/dif/dif_uart.h index 36b4041d228ef..a27559d1fb5b9 100644 --- a/sw/device/lib/dif/dif_uart.h +++ b/sw/device/lib/dif/dif_uart.h @@ -10,6 +10,11 @@ #include "sw/device/lib/base/mmio.h" +// Header Extern Guard (so header can be used from C and C++) +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + // The size of UART TX and RX FIFOs in bytes. extern const uint32_t kDifUartFifoSizeBytes; @@ -339,4 +344,8 @@ dif_uart_result_t dif_uart_rx_bytes_available(const dif_uart_t *uart, dif_uart_result_t dif_uart_tx_bytes_available(const dif_uart_t *uart, size_t *num_bytes); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_UART_H_