From 0dd3b7a8929dd52fef02d301aa3f9865fcc9efe6 Mon Sep 17 00:00:00 2001 From: Bas Laarhoven Date: Sat, 13 Aug 2011 12:12:57 -0700 Subject: [PATCH] Allow for queue sizes that are not a power of 2. This prevents nasty surprises because this restriction is not mentioned in the configuration files. It also allows better tuning of performance against memory usage. Traumflug: costs 18 bytes flash, so it's bearable. --- dda_queue.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dda_queue.c b/dda_queue.c index cf76980..a0b50f7 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -32,12 +32,17 @@ uint8_t mb_tail = 0; /// once writing starts in interrupts on a specific slot, the /// slot will only be modified in interrupts until the slot is /// is no longer live. +/// The size does not need to be a power of 2 anymore! DDA movebuffer[MOVEBUFFER_SIZE] __attribute__ ((__section__ (".bss"))); /// check if the queue is completely full uint8_t queue_full() { MEMORY_BARRIER(); - return (((mb_tail - mb_head - 1) & (MOVEBUFFER_SIZE - 1)) == 0)?255:0; + if (mb_tail > mb_head) { + return ((mb_tail - mb_head - 1) == 0) ? 255 : 0; + } else { + return ((mb_tail + MOVEBUFFER_SIZE - mb_head - 1) == 0) ? 255 : 0; + } } /// check if the queue is completely empty