Merge contributed patch to extend support of atxmega.
[bertos.git] / bertos / cpu / avr / drv / ser_xmega.h
index cad8b1e95b97b816523278d4525f102019ca1e0a..3dc58fc8293bc6c976af9f6f8bcececd886d7d07 100644 (file)
@@ -46,6 +46,7 @@
 
 #include <cfg/macros.h>   /* BV() */
 #include <cfg/compiler.h> /* uint8_t */
+#include "cfg/cfg_ser.h"   /* Serialport configuration settings */
 
 typedef uint8_t serstatus_t;
 
@@ -64,21 +65,100 @@ typedef uint8_t serstatus_t;
 #define SERRF_NOISEERROR     0      /**< Unsupported */
 
 /*
+ * XMEGA_D4 has 2 serial ports
+ * XMEGA_D3 has 3 serial ports
+ * XMEGA_A4 has 5 serial ports
+ * XMEGA_A3 has 7 serial ports
+ * XMEGA_A1 has 8 serial ports
+ *
+ * These serial ports can be enabled or disabled in the cfg_ser.h file
+ * Generate definitions whether a serial port needs to be implementend by
+ * the driver, depending on the type of XMega and the settings in cfg_ser.h
+ */
+#if CONFIG_UART0_ENABLED
+       #define IMPLEMENT_SER_UART0 1
+#else
+       #define IMPLEMENT_SER_UART0 0
+#endif
+#if CONFIG_UART1_ENABLED
+       #define IMPLEMENT_SER_UART1 1
+#else
+       #define IMPLEMENT_SER_UART1 0
+#endif
+#if (CPU_AVR_XMEGA_D3 || CPU_AVR_XMEGA_A4 || CPU_AVR_XMEGA_A3 || CPU_AVR_XMEGA_A1) && CONFIG_UART2_ENABLED
+       #define IMPLEMENT_SER_UART2 1
+#else
+       #define IMPLEMENT_SER_UART2 0
+#endif
+#if CPU_AVR_XMEGA_A4 || CPU_AVR_XMEGA_A3 || CPU_AVR_XMEGA_A1
+       #if CONFIG_UART3_ENABLED
+               #define IMPLEMENT_SER_UART3 1
+       #else
+               #define IMPLEMENT_SER_UART3 0
+       #endif
+       #if CONFIG_UART4_ENABLED
+               #define IMPLEMENT_SER_UART4 1
+       #else
+               #define IMPLEMENT_SER_UART4 0
+       #endif
+#else
+       #define IMPLEMENT_SER_UART3 0
+       #define IMPLEMENT_SER_UART4 0
+#endif
+#if CPU_AVR_XMEGA_A3 || CPU_AVR_XMEGA_A1
+       #if CONFIG_UART5_ENABLED
+               #define IMPLEMENT_SER_UART5 1
+       #else
+               #define IMPLEMENT_SER_UART5 0
+       #endif
+       #if CONFIG_UART6_ENABLED
+               #define IMPLEMENT_SER_UART6 1
+       #else
+               #define IMPLEMENT_SER_UART6 0
+       #endif
+#else
+       #define IMPLEMENT_SER_UART5 0
+       #define IMPLEMENT_SER_UART6 0
+#endif
+#if CPU_AVR_XMEGA_A1 && CONFIG_UART7_ENABLED
+       #define IMPLEMENT_SER_UART7 1
+#else
+       #define IMPLEMENT_SER_UART7 0
+#endif
+
+/*
+ *
  * \name Serial hw numbers
  *
  * \{
  */
 enum
 {
+#if IMPLEMENT_SER_UART0
        SER_UART0,
+#endif
+#if IMPLEMENT_SER_UART1
        SER_UART1,
-#ifdef CPU_AVR_XMEGA_A
-       //the XMEGA A Family have 5 USART ports
+#endif
+#if IMPLEMENT_SER_UART2
        SER_UART2,
+#endif
+#if IMPLEMENT_SER_UART3
        SER_UART3,
+#endif
+#if IMPLEMENT_SER_UART4
        SER_UART4,
 #endif
-       SER_CNT  /**< Number of serial ports */
+#if IMPLEMENT_SER_UART5
+       SER_UART5,
+#endif
+#if IMPLEMENT_SER_UART6
+       SER_UART6,
+#endif
+#if IMPLEMENT_SER_UART7
+       SER_UART7,
+#endif
+       SER_CNT /**< Number of serial ports implemented*/
 };
 /*\}*/