Commit from zer0 on branch b_zer0 (2008-05-11 17:04 CEST)
=================================

fix compilation with gcc 4.3

  aversive  include/aversive.h                  1.1.2.5
  aversive  modules/encoding/hamming/hamming.c  1.2.4.4


===========================
aversive/include/aversive.h  (1.1.2.4 -> 1.1.2.5)
===========================

@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- *  Revision : $Id: aversive.h,v 1.1.2.4 2008-04-27 12:59:45 zer0 Exp $
+ *  Revision : $Id: aversive.h,v 1.1.2.5 2008-05-11 15:04:52 zer0 Exp $
  *
  */
 
@@ -110,24 +110,85 @@
 #define ABS(val) ( ((val) < 0) ? -(val) : (val) )
 
 
-/* byte extraction, not recommended for use
- *  use only if you need speed optimization !
- *  use ">>" instead for current operations 
- */
-#define extr16_08_0(i) (*(char *)(&i))         // LSB of a 16bit
-#define extr16_08_1(i) (*((char *)(&i)+1))     // MSB of a 16bit
-
-#define extr32_16_0(i) (*(int *)(&i))          // LSB of a 32 bit
-#define extr32_16_1(i) (* (((int *)(&i)) +1))  // MSB of a 32 bit
-#define extr32_16_23(i) (*((int *)((char *)(&i)+1))) // middle of a 32 bit
-
-#define extr32_08_0(i) (*(char *)(&i))         // same stuff
-#define extr32_08_1(i) (*((char *)(&i)+1))
-#define extr32_08_2(i) (*((char *)(&i)+2))
-#define extr32_08_3(i) (*((char *)(&i)+3))
+/* 
+ * Extract bytes and u16 from larger integer
+ */
+
+#if __BYTE_ORDER != __LITTLE_ENDIAN && __BYTE_ORDER != __BIG_ENDIAN
+# error        "Endianness not defined"
+#endif
+
+struct extract32 {
+       union {
+               struct {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+                       uint8_t u8_0;
+                       uint8_t u8_1;
+                       uint8_t u8_2;
+                       uint8_t u8_3;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+                       uint8_t u8_3;
+                       uint8_t u8_2;
+                       uint8_t u8_1;
+                       uint8_t u8_0;
+#endif
+               } __attribute__ ((packed)) u8;
+               struct {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+                       uint16_t u16_0;
+                       uint16_t u16_1;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+                       uint16_t u16_1;
+                       uint16_t u16_0;
+#endif
+               } __attribute__ ((packed)) u16;
+               struct {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+                       uint8_t u8_0;
+                       uint16_t u16_mid;
+                       uint8_t u8_3;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+                       uint8_t u8_3;
+                       uint16_t u16_mid;
+                       uint8_t u8_0;
+#endif
+               } __attribute__ ((packed)) u16_b;
+               uint32_t u32;
+       } __attribute__ ((packed)) u;
+} __attribute__ ((packed));
+
+#define extr32_08_0(i) ({ struct extract32 __x; __x.u.u32 = i; __x.u.u8.u8_0; 
})
+#define extr32_08_1(i) ({ struct extract32 __x; __x.u.u32 = i; __x.u.u8.u8_1; 
})
+#define extr32_08_2(i) ({ struct extract32 __x; __x.u.u32 = i; __x.u.u8.u8_2; 
})
+#define extr32_08_3(i) ({ struct extract32 __x; __x.u.u32 = i; __x.u.u8.u8_3; 
})
+
+#define extr32_16_0(i) ({ struct extract32 __x; __x.u.u32 = i; 
__x.u.u16.u16_0; })
+#define extr32_16_1(i) ({ struct extract32 __x; __x.u.u32 = i; 
__x.u.u16.u16_1; })
+#define extr32_16_mid(i) ({ struct extract32 __x; __x.u.u32 = i; 
__x.u.u16_b.u16_mid; })
+
+
+struct extract16 {
+       union {
+               struct {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+                       uint8_t u8_0;
+                       uint8_t u8_1;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+                       uint8_t u8_1;
+                       uint8_t u8_0;
+#endif
+               } __attribute__ ((packed)) u8;
+               uint16_t u16;
+       } __attribute__ ((packed)) u;
+} __attribute__ ((packed));
+
+#define extr16_08_0(i) ({ struct extract16 __x; __x.u.u16 = i; __x.u.u8.u8_0; 
})
+#define extr16_08_1(i) ({ struct extract16 __x; __x.u.u16 = i; __x.u.u8.u8_1; 
})
+
 
 
 /* a few asm utilities */
+
 #ifndef HOST_VERSION
 #ifndef nop
 #define nop() __asm__ __volatile__ ("NOP\n") /** nop instruction, 1 CPU cycle 
consumed */


===========================================
aversive/modules/encoding/hamming/hamming.c  (1.2.4.3 -> 1.2.4.4)
===========================================

@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- *  Revision : $Id: hamming.c,v 1.2.4.3 2007-08-19 10:39:31 zer0 Exp $
+ *  Revision : $Id: hamming.c,v 1.2.4.4 2008-05-11 15:04:53 zer0 Exp $
  *
  */
 
@@ -28,7 +28,7 @@
 /** \file hamming.c
  *  \brief Implementation for the Hamiing module.
  *
- *  \todo nothing.
+ *  \todo use progmem to store tables !
  *
  *  \test Seems to work
  *
@@ -125,16 +125,14 @@
 
   tmp = tab_abcd[(uint8_t)frame&0x0F];
   
-
-  tmp |= ((uint32_t)((uint8_t) (((uint16_t)frame)>>4) & 0x7F)) << 8;
+  tmp |= (frame & 0x7F0) << 4;
   
-
-  frame_middle = * (uint16_t *) ((uint8_t *)(&frame) + 1);
-  tmp |= ((uint32_t)((uint8_t)(frame_middle >> 3))) << 16;
+  frame_middle =  extr32_16_mid(frame);
+  tmp |= (uint32_t)(frame_middle & 0x7F8) << 13;
 
   
-  frame_last = * ((uint8_t *)(&frame) + 2);
-  tmp |= ((uint32_t)((uint8_t)(frame_last >> 3))) << 24 ;
+  frame_last = extr32_08_2(frame);
+  tmp |= (uint32_t)(frame_last >> 3) << 24 ;
 
   return tmp;
 }

_______________________________________________
Avr-list mailing list
Avr-list@droids-corp.org
CVSWEB : http://cvsweb.droids-corp.org/cgi-bin/viewcvs.cgi/aversive
WIKI : http://wiki.droids-corp.org/index.php/Aversive
DOXYGEN : http://zer0.droids-corp.org/doxygen_aversive/html/
BUGZILLA : http://bugzilla.droids-corp.org
COMMIT LOGS : http://zer0.droids-corp.org/aversive_commitlog

Répondre à