Skip to content

Commit 613202a

Browse files
ArcaneNibbledlech
authored andcommitted
pbio/include/pbdrv/compiler.h: Move intrinsics into header
Currently contains a compiler memory barrier and fall-through marker. These operations will be needed throughout the driver layer.
1 parent 8345250 commit 613202a

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

lib/pbio/drv/block_device/block_device_ev3.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <pbdrv/block_device.h>
2626
#include <pbdrv/clock.h>
27+
#include <pbdrv/compiler.h>
2728
#include <pbdrv/gpio.h>
2829

2930
#include <tiam1808/edma.h>
@@ -486,8 +487,8 @@ static pbio_error_t spi_begin_for_flash(
486487

487488
spi_dev.status = SPI_STATUS_WAIT_TX | SPI_STATUS_WAIT_RX;
488489

489-
// TODO: pbio probably needs a framework for memory barriers and DMA cache management
490-
__asm__ volatile ("" ::: "memory");
490+
// TODO: eventually needs DMA cache management
491+
pbdrv_compiler_memory_barrier();
491492

492493
EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_CHA_SPI0_TX, EDMA3_TRIG_MODE_EVENT);
493494
EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_CHA_SPI0_RX, EDMA3_TRIG_MODE_EVENT);
@@ -805,8 +806,8 @@ static pbio_error_t pbdrv_block_device_ev3_spi_begin_for_adc(const uint32_t *cmd
805806

806807
spi_dev.status = SPI_STATUS_WAIT_TX | SPI_STATUS_WAIT_RX;
807808

808-
// TODO: pbio probably needs a framework for memory barriers and DMA cache management
809-
__asm__ volatile ("" ::: "memory");
809+
// TODO: eventually needs DMA cache management
810+
pbdrv_compiler_memory_barrier();
810811

811812
EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_CHA_SPI0_TX, EDMA3_TRIG_MODE_EVENT);
812813
EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_CHA_SPI0_RX, EDMA3_TRIG_MODE_EVENT);

lib/pbio/drv/reset/reset_ev3.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <stdbool.h>
1111

12+
#include <pbdrv/compiler.h>
1213
#include <pbdrv/reset.h>
1314
#include <pbdrv/gpio.h>
1415

@@ -63,7 +64,7 @@ void pbdrv_reset(pbdrv_reset_action_t action) {
6364
break;
6465
case PBDRV_RESET_ACTION_RESET_IN_UPDATE_MODE:
6566
ev3_persistent_data.bootloader_update_flag = BOOTLOADER_UPDATE_MODE_VALUE;
66-
__attribute__((fallthrough));
67+
PBDRV_FALL_THROUGH;
6768
default:
6869
// PBDRV_RESET_ACTION_RESET
6970

lib/pbio/include/pbdrv/compiler.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2025 The Pybricks Authors
3+
4+
#ifndef _PBDRV_COMPILER_H_
5+
6+
// Marks a switch case that intentionally falls through to the next one
7+
#define PBDRV_FALL_THROUGH __attribute__((fallthrough))
8+
9+
// Forces the compiler to not reorder memory access around this line
10+
#define pbdrv_compiler_memory_barrier() __asm__ volatile ("" ::: "memory")
11+
12+
#endif

0 commit comments

Comments
 (0)