]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/utils/ring.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / utils / ring.h
diff --git a/FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/utils/ring.h b/FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/utils/ring.h
new file mode 100644 (file)
index 0000000..4506f70
--- /dev/null
@@ -0,0 +1,81 @@
+/* ----------------------------------------------------------------------------\r
+ *         ATMEL Microcontroller Software Support\r
+ * ----------------------------------------------------------------------------\r
+ * Copyright (c) 2015, Atmel Corporation\r
+ *\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions are met:\r
+ *\r
+ * - Redistributions of source code must retain the above copyright notice,\r
+ * this list of conditions and the disclaimer below.\r
+ *\r
+ * Atmel's name may not be used to endorse or promote products derived from\r
+ * this software without specific prior written permission.\r
+ *\r
+ * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
+ * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * ----------------------------------------------------------------------------\r
+ */\r
+\r
+#ifndef _RING_H_\r
+#define _RING_H_\r
+\r
+#include "intmath.h"\r
+\r
+/*------------------------------------------------------------------------------\r
+ *         Exported functions\r
+ *------------------------------------------------------------------------------*/\r
+\r
+/** Return count in buffer */\r
+#define RING_CNT(head,tail,size) fixed_mod((head) - (tail), (size))\r
+\r
+/** Return space available, 0..size-1. always leave one free char as a\r
+ * completely full buffer has head == tail, which is the same as empty */\r
+#define RING_SPACE(head,tail,size) RING_CNT((tail),((head) + 1),(size))\r
+\r
+/** Return count up to the end of the buffer. Carefully avoid accessing head\r
+ * and tail more than once, so they can change underneath us without returning\r
+ * inconsistent results */\r
+#define RING_CNT_TO_END(head,tail,size) \\r
+     ({int end = (size) - (tail); \\r
+     int n = fixed_mod((head) + end, (size));   \\r
+     n < end ? n : end;})\r
+\r
+/** Return space available up to the end of the buffer */\r
+#define RING_SPACE_TO_END(head,tail,size) \\r
+   ({int end = (size) - 1 - (head); \\r
+     int n = fixed_mod(end + (tail), (size)); \\r
+     n <= end ? n : end+1;})\r
+\r
+/** Increment head or tail */\r
+#define RING_INC(headortail,size) \\r
+        (headortail)++; \\r
+        if((headortail) >= (size)) { \\r
+            (headortail) = 0; \\r
+        }\r
+\r
+/** Decrement head or tail */\r
+#define RING_DEC(headortail,size) \\r
+        if((headortail) == 0) { \\r
+            (headortail) = (size) - 1; \\r
+        } else { \\r
+            (headortail)--; \\r
+        }\r
+\r
+/** Circular buffer is empty ? */\r
+#define RING_EMPTY(head, tail) ((head) == (tail))\r
+\r
+/** Clear circular buffer */\r
+#define RING_CLEAR(head, tail) ((head) = (tail) = 0)\r
+\r
+#endif /* _RING_H_ */\r