From 9c47f7151496b9b85c52b87162e7a58f005db7e3 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Sat, 15 Jan 2011 23:30:59 +0100 Subject: [PATCH] [avr] inline htob and btoh functions --- mote/v2/avr/encode.c | 27 --------------------------- mote/v2/avr/encode.h | 29 +++++++++++++++++++++++++++-- mote/v2/avr/makefile | 5 ++++- 3 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 mote/v2/avr/encode.c diff --git a/mote/v2/avr/encode.c b/mote/v2/avr/encode.c deleted file mode 100644 index 613ec33..0000000 --- a/mote/v2/avr/encode.c +++ /dev/null @@ -1,27 +0,0 @@ -#include - -// hex to binary/byte decoding -uint8_t htob(uint16_t hex) -{ - uint8_t low_hex = (uint8_t) hex; - uint8_t high_hex = (uint8_t) (hex >> 8); - uint8_t byte; - - byte = (high_hex > 0x40) ? (high_hex & 0x0F) + 9 : high_hex & 0x0F; - byte = byte << 4; - byte |= (low_hex > 0x40) ? (low_hex & 0x0F) + 9 : low_hex & 0x0F; - return byte; -} - -// binary/byte to hex encoding -uint16_t btoh(uint8_t byte) -{ - uint8_t low_nibble = (byte & 0x0F); - uint8_t high_nibble = (byte & 0xF0) >> 4; - uint16_t hex; - - hex = (high_nibble > 0x09) ? high_nibble - 9 + 0x60 : high_nibble + 0x30; - hex = hex << 8; - hex |= (low_nibble > 0x09) ? low_nibble - 9 + 0x60 : low_nibble + 0x30; - return hex; -} diff --git a/mote/v2/avr/encode.h b/mote/v2/avr/encode.h index 2d4bb5e..1c504c5 100644 --- a/mote/v2/avr/encode.h +++ b/mote/v2/avr/encode.h @@ -1,2 +1,27 @@ -uint8_t htob(uint16_t hex); -uint16_t btoh(uint8_t byte); +#include + +// hex to binary/byte decoding +static inline uint8_t htob(uint16_t hex) +{ + uint8_t low_hex = (uint8_t) hex; + uint8_t high_hex = (uint8_t) (hex >> 8); + uint8_t byte; + + byte = (high_hex > 0x40) ? (high_hex & 0x0F) + 9 : high_hex & 0x0F; + byte = byte << 4; + byte |= (low_hex > 0x40) ? (low_hex & 0x0F) + 9 : low_hex & 0x0F; + return byte; +} + +// binary/byte to hex encoding +static inline uint16_t btoh(uint8_t byte) +{ + uint8_t low_nibble = (byte & 0x0F); + uint8_t high_nibble = (byte & 0xF0) >> 4; + uint16_t hex; + + hex = (high_nibble > 0x09) ? high_nibble - 9 + 0x60 : high_nibble + 0x30; + hex = hex << 8; + hex |= (low_nibble > 0x09) ? low_nibble - 9 + 0x60 : low_nibble + 0x30; + return hex; +} diff --git a/mote/v2/avr/makefile b/mote/v2/avr/makefile index 0d728a4..72a9699 100644 --- a/mote/v2/avr/makefile +++ b/mote/v2/avr/makefile @@ -71,7 +71,7 @@ TARGET = main # List C source files here. (C dependencies are automatically generated.) -SRC = $(TARGET).c buffer.c uart.c spi.c ctrl.c encode.c +SRC = $(TARGET).c buffer.c uart.c spi.c ctrl.c # List Assembler source files here. @@ -119,6 +119,9 @@ CDEFS = -DF_CPU=$(F_CPU)UL DBG = 0 CDEFS += -D DBG=$(DBG) +# Warn when a function marked for inlining could not be substituted +CDEFS += -Winline + # uncomment and adapt these line if you want different UART library buffer size CDEFS += -DUART_RX_BUFFER_SIZE=64 CDEFS += -DUART_TX_BUFFER_SIZE=64