]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - include/common.h
cmd_attach.c, cmd_boot.c, cmd_loadcpm3.c: use cmd_error()
[z180-stamp.git] / include / common.h
index cfbbae5c1fc1cf3185f18e67bb9983667d7f9080..12d87c48865a280eac621ba3e7df7ddc006b6e6b 100644 (file)
@@ -1,12 +1,24 @@
 /*
  * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 #ifndef COMMON_H
 #define COMMON_H
 
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+#include "errnum.h"
+
+#define GCC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
+
+#define USED __attribute__((used))
+#define UNUSED __attribute__((unused))
+
 #ifdef __AVR__
 #include <avr/io.h>
 #include <avr/pgmspace.h>
@@ -27,17 +39,18 @@ struct bits {
 
 #define SBIT(port,pin) ((*(volatile struct bits*)&port).b##pin)
 
-//TODO:
+//GCC bug PR61443
 //  Known to work: 4.8.4, 4.9.1
 //  Known to fail: 4.8.3, 4.9.0
+
+#if (GCC_VERSION < 40804) || (GCC_VERSION == 40900)
 #define GCC_BUG_61443 1
+#endif /* PR61443 */
 
 #else
 // TODO: stm32
 #endif /* __AVR__ */
 
-#include <stdio.h>
-
 #ifdef __FLASH
 #define FLASH __flash
 #define MEMX __memx
@@ -52,6 +65,12 @@ struct bits {
 #define FSTR(X) ((const FLASH char[]) { X } )
 #define ARRAY_SIZE(x)  (sizeof(x) / sizeof((x)[0]))
 
+#define MIN(a,b)    ({ typeof (a) _a = (a);                                    \
+                                               typeof (b) _b = (b);                                   \
+                                               _a < _b ? _a : _b; })
+#define MAX(a,b)    ({ typeof (a) _a = (a);                                    \
+                                               typeof (b) _b = (b);                                   \
+                                               _a > _b ? _a : _b; })
 
 #ifdef __AVR__
 #define Stat GPIOR0
@@ -64,18 +83,18 @@ extern volatile uint_least8_t Stat;
 #define S_CON_PENDING  (1<<2)
 
 static inline
-void my_puts(const char *s)
+int my_puts(const char *s)
 {
-       fputs(s, stdout);
+       return fputs(s, stdout);
 }
 
 static inline
-void my_puts_P(const char *s)
+int my_puts_P(const char *s)
 {
 #ifdef __AVR__
-       fputs_P(s, stdout);
+       return fputs_P(s, stdout);
 #else
-       fputs(s, stdout);
+       return fputs(s, stdout);
 #endif /* __AVR__ */
 }