Skip to content

Commit

Permalink
[sw] Add Header Extern Guards to DIFs and libbase
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Elliott <selliott@lowrisc.org>
  • Loading branch information
lenary authored and imphil committed May 29, 2020
1 parent f9f6dc9 commit 40d7428
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 6 deletions.
9 changes: 9 additions & 0 deletions sw/device/lib/base/bitfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

#include <stdint.h>

// 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.
*
Expand Down Expand Up @@ -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_
9 changes: 9 additions & 0 deletions sw/device/lib/base/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <stddef.h>
#include <stdint.h>

// 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.
*
Expand Down Expand Up @@ -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_
11 changes: 5 additions & 6 deletions sw/device/lib/base/mmio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#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.
Expand Down
9 changes: 9 additions & 0 deletions sw/device/lib/dif/dif_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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_
9 changes: 9 additions & 0 deletions sw/device/lib/dif/dif_plic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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_
9 changes: 9 additions & 0 deletions sw/device/lib/dif/dif_spi_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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_
9 changes: 9 additions & 0 deletions sw/device/lib/dif/dif_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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_

0 comments on commit 40d7428

Please sign in to comment.