From: lottaviano <lottaviano@38d2e660-2303-0410-9eaa-f027e97ec537>
Date: Sat, 9 Apr 2011 13:41:54 +0000 (+0000)
Subject: Add detect macros for AVR XMega MCU.
X-Git-Tag: 2.7.0~123
X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=2e1423c0e63c12bb4eb996480ec2a51f8899aa88;p=bertos.git

Add detect macros for AVR XMega MCU.

Hardware interrupts should be enabled separately by using the lines:
  #include <avr/io.h>
  PMIC.CTRL |= PMIC_LOLVLEX_bm | PMIC_MEDLVLEX_bm | PMIC_HILVLEX_bm;
These should go into a separate init file specific for AVR XMega.

Signed-off-by: Onno <developer@gorgoz.org>
Reviewed-by: Luca Ottaviano <lottaviano@develer.com>

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4843 38d2e660-2303-0410-9eaa-f027e97ec537
---

diff --git a/bertos/cpu/attr.h b/bertos/cpu/attr.h
index 5c2107a8..e0e97ef3 100644
--- a/bertos/cpu/attr.h
+++ b/bertos/cpu/attr.h
@@ -258,6 +258,8 @@
 		#define CPU_RAM_START       0x100
 	#elif CPU_AVR_ATMEGA1281 || CPU_AVR_ATMEGA1280 || CPU_AVR_ATMEGA2560
 		#define CPU_RAM_START       0x200
+	#elif CPU_AVR_XMEGA_D
+		#define CPU_RAM_START		0x2000
 	#else
 		#warning Fix CPU_RAM_START address for your AVR, default value set to 0x100
 		#define CPU_RAM_START       0x100
diff --git a/bertos/cpu/avr/hw/switch_ctx_avr.S b/bertos/cpu/avr/hw/switch_ctx_avr.S
index 7ee5a149..db80e943 100644
--- a/bertos/cpu/avr/hw/switch_ctx_avr.S
+++ b/bertos/cpu/avr/hw/switch_ctx_avr.S
@@ -78,6 +78,8 @@ asm_switch_context:
 	ld	r18,X+
 	ld	r19,X
 
+;FIXME: We probably need to safe the RAMP registers for some XMEGA devices / setups
+
 ; 	Set new stack pointer.
 ;	AVR is an 8 bit processor so
 ;	care must be taken when updating
diff --git a/bertos/cpu/detect.h b/bertos/cpu/detect.h
index d7ec6aad..739d3f61 100644
--- a/bertos/cpu/detect.h
+++ b/bertos/cpu/detect.h
@@ -402,6 +402,7 @@
 	#define CPU_CORE_NAME           "AVR"
 
 	#if defined(__AVR_ATmega32__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA32    1
 		#define CPU_NAME            "ATmega32"
 	#else
@@ -409,6 +410,7 @@
 	#endif
 
 	#if defined(__AVR_ATmega64__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA64    1
 		#define CPU_NAME            "ATmega64"
 	#else
@@ -416,6 +418,7 @@
 	#endif
 
 	#if defined(__AVR_ATmega103__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA103   1
 		#define CPU_NAME            "ATmega103"
 	#else
@@ -423,6 +426,7 @@
 	#endif
 
 	#if defined(__AVR_ATmega128__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA128   1
 		#define CPU_NAME            "ATmega128"
 	#else
@@ -430,6 +434,7 @@
 	#endif
 
 	#if defined(__AVR_ATmega8__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA8     1
 		#define CPU_NAME            "ATmega8"
 	#else
@@ -437,6 +442,7 @@
 	#endif
 
 	#if defined(__AVR_ATmega168__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA168   1
 		#define CPU_NAME            "ATmega168"
 	#else
@@ -444,6 +450,7 @@
 	#endif
 
 	#if defined(__AVR_ATmega328P__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA328P   1
 		#define CPU_NAME            "ATmega328P"
 	#else
@@ -451,6 +458,7 @@
 	#endif
 
 	#if defined(__AVR_ATmega1281__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA1281  1
 		#define CPU_NAME            "ATmega1281"
 	#else
@@ -458,6 +466,7 @@
 	#endif
 
 	#if defined(__AVR_ATmega1280__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA1280  1
 		#define CPU_NAME            "ATmega1280"
 	#else
@@ -465,19 +474,43 @@
 	#endif
 
 	#if defined(__AVR_ATmega2560__)
+		#define CPU_AVR_MEGA		1
 		#define CPU_AVR_ATMEGA2560  1
 		#define CPU_NAME            "ATmega2560"
 	#else
 		#define CPU_AVR_ATMEGA2560  0
 	#endif
 
+	#if defined(__AVR_ATxmega32D4__)
+		#define CPU_AVR_XMEGA		1
+		#define CPU_AVR_XMEGA_D		1
+		#define CPU_AVR_ATXMEGA32D4	1
+		#define CPU_NAME			"ATxmega32d4"
+	#else
+		#define CPU_AVR_ATXMEGA32D4	0
+	#endif
+
 	#if CPU_AVR_ATMEGA32 + CPU_AVR_ATMEGA64 + CPU_AVR_ATMEGA103 + CPU_AVR_ATMEGA128 \
 	  + CPU_AVR_ATMEGA8 + CPU_AVR_ATMEGA168 + CPU_AVR_ATMEGA328P + CPU_AVR_ATMEGA1281 \
-	  + CPU_AVR_ATMEGA1280 + CPU_AVR_ATMEGA2560 != 1
+	  + CPU_AVR_ATMEGA1280 + CPU_AVR_ATMEGA2560 + CPU_AVR_ATXMEGA32D4 != 1
 		#error AVR CPU configuration error
 	#endif
+
+	#if defined(CPU_AVR_XMEGA) && defined(CPU_AVR_MEGA)
+		#error CPU cannot be MEGA and XMEGA
+	#elif defined(CPU_AVR_MEGA)
+		#define CPU_AVR_XMEGA		0
+	#elif defined(CPU_AVR_XMEGA)
+		#define CPU_AVR_MEGA		0
+	#endif
+
+	#if CPU_AVR_MEGA + CPU_AVR_XMEGA != 1
+		#error AVR CPU configuration error
+	#endif
+
 #else
 	#define CPU_AVR                 0
+	#define CPU_AVR_MEGA			0
 	#define CPU_AVR_ATMEGA8         0
 	#define CPU_AVR_ATMEGA168       0
 	#define CPU_AVR_ATMEGA328P      0
@@ -488,6 +521,8 @@
 	#define CPU_AVR_ATMEGA1281      0
 	#define CPU_AVR_ATMEGA1280      0
 	#define CPU_AVR_ATMEGA2560      0
+	#define CPU_AVR_XMEGA			0
+	#define CPU_AVR_XMEGA_D			0
 #endif
 
 #if defined (__MSP430__)