Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quantum ring_buffer for ChibiOS #19683

Merged
merged 3 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions platforms/atomic_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
# define ATOMIC_BLOCK _Static_assert(0, "ATOMIC_BLOCK not implemented")
# define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE not implemented")
# define ATOMIC_BLOCK_FORCEON _Static_assert(0, "ATOMIC_BLOCK_FORCEON not implemented")
# define ATOMIC_FORCEON _Static_assert(0, "ATOMIC_FORCEON not implemented")
# define ATOMIC_RESTORESTATE _Static_assert(0, "ATOMIC_RESTORESTATE not implemented")
# endif
#else /* do nothing atomic macro */
# define ATOMIC_BLOCK for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0)
# define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK
# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK
# define ATOMIC_BLOCK(t) for (uint8_t __ToDo = 1; __ToDo; __ToDo = 0)
# define ATOMIC_FORCEON
# define ATOMIC_RESTORESTATE
# define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
# define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON)
#endif
17 changes: 14 additions & 3 deletions platforms/chibios/atomic_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@ static __inline__ void __interrupt_enable__(const uint8_t *__s) {
(void)__s;
}

#define ATOMIC_BLOCK(type) for (type, __ToDo = __interrupt_disable__(); __ToDo; __ToDo = 0)
#define ATOMIC_FORCEON uint8_t sreg_save __attribute__((__cleanup__(__interrupt_enable__))) = 0
static __inline__ syssts_t __interrupt_lock__(void) {
return chSysGetStatusAndLockX();
}

static __inline__ void __interrupt_unlock__(const syssts_t *__s) {
chSysRestoreStatusX(*__s);

__asm__ volatile("" ::: "memory");
}

#define ATOMIC_BLOCK(type) for (type, __ToDo = 1; __ToDo; __ToDo = 0)
#define ATOMIC_FORCEON uint8_t status_save __attribute__((__cleanup__(__interrupt_enable__))) = __interrupt_disable__()
#define ATOMIC_RESTORESTATE syssts_t status_save __attribute__((__cleanup__(__interrupt_unlock__))) = __interrupt_lock__()
tzarc marked this conversation as resolved.
Show resolved Hide resolved

#define ATOMIC_BLOCK_RESTORESTATE _Static_assert(0, "ATOMIC_BLOCK_RESTORESTATE not implemented")
#define ATOMIC_BLOCK_RESTORESTATE ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
#define ATOMIC_BLOCK_FORCEON ATOMIC_BLOCK(ATOMIC_FORCEON)
2 changes: 1 addition & 1 deletion quantum/ring_buffer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <util/atomic.h>
#include <stdint.h>
#include <stdbool.h>
#include "atomic_util.h"

#ifndef RBUF_SIZE
# define RBUF_SIZE 32
Expand Down