X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fatm128%2Fatm128hardware.h;h=b412d90fe1a7c74c1110d130db91151f39f1a317;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=cfc7eaf7f372ce17ef5c38c0dbaf1a5898878611;hpb=742710ed9accc709978cba77d81f1fb2c77cd48c;p=tinyos-2.x.git diff --git a/tos/chips/atm128/atm128hardware.h b/tos/chips/atm128/atm128hardware.h index cfc7eaf7..b412d90f 100644 --- a/tos/chips/atm128/atm128hardware.h +++ b/tos/chips/atm128/atm128hardware.h @@ -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, @@ -79,11 +79,11 @@ #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,17 +100,19 @@ 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(); + asm volatile("" : : : "memory"); /* ensure atomic section effect visibility */ return result; } /* 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; } #endif @@ -129,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