]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/atm128/atm128hardware.h
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / chips / atm128 / atm128hardware.h
index 3e4bb03094a572b87d0e10ab43b96156219635d4..b412d90fe1a7c74c1110d130db91151f39f1a317 100644 (file)
@@ -1,6 +1,6 @@
 //  $Id$
 
-/*                                                                     tab:4
+/*                                                                     
  *  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.  By
  *  downloading, copying, installing or using the software you agree to
  *  this license.  If you do not agree to this license, do not download,
 #define READ_FLAG(port, flag) ((port) & (flag))
 
 /* Enables interrupts. */
-inline void __nesc_enable_interrupt() {
+inline void __nesc_enable_interrupt() @safe() {
     sei();
 }
 /* Disables all interrupts. */
-inline void __nesc_disable_interrupt() {
+inline void __nesc_disable_interrupt() @safe() {
     cli();
 }
 
@@ -100,7 +100,7 @@ void __nesc_atomic_end(__nesc_atomic_t original_SREG);
 
 /* Saves current interrupt mask state and disables interrupts. */
 inline __nesc_atomic_t 
-__nesc_atomic_start(void) @spontaneous()
+__nesc_atomic_start(void) @spontaneous() @safe()
 {
     __nesc_atomic_t result = SREG;
     __nesc_disable_interrupt();
@@ -110,7 +110,7 @@ __nesc_atomic_start(void) @spontaneous()
 
 /* Restores interrupt mask to original state. */
 inline void 
-__nesc_atomic_end(__nesc_atomic_t original_SREG) @spontaneous()
+__nesc_atomic_end(__nesc_atomic_t original_SREG) @spontaneous() @safe()
 {
   asm volatile("" : : : "memory"); /* ensure atomic section effect visibility */
   SREG = original_SREG;
@@ -131,10 +131,27 @@ enum {
 };
 
 /* Combine function.  */
-mcu_power_t mcombine(mcu_power_t m1, mcu_power_t m2) {
+mcu_power_t mcombine(mcu_power_t m1, mcu_power_t m2) @safe() {
   return (m1 < m2)? m1: m2;
 }
 
-#endif //_H_atmega128hardware_H
+/* Floating-point network-type support.
+   These functions must convert to/from a 32-bit big-endian integer that follows
+   the layout of Java's java.lang.float.floatToRawIntBits method.
+   Conveniently, for the AVR family, this is a straight byte copy...
+*/
+
+typedef float nx_float __attribute__((nx_base_be(afloat)));
+
+inline float __nesc_ntoh_afloat(const void *COUNT(sizeof(float)) source) @safe() {
+  float f;
+  memcpy(&f, source, sizeof(float));
+  return f;
+}
 
+inline float __nesc_hton_afloat(void *COUNT(sizeof(float)) target, float value) @safe() {
+  memcpy(target, &value, sizeof(float));
+  return value;
+}
 
+#endif //_H_atmega128hardware_H