diff --git a/chronos/board_init.c b/chronos/board_init.c
index 95e5dfd3a704785b8ededc0e291b152110dfebf3..db2326701f25caab99f79886b223e828204dfb7b 100644
--- a/chronos/board_init.c
+++ b/chronos/board_init.c
@@ -3,7 +3,8 @@
 #include <cpu.h>
 #include <irq.h>
 
-void cc430_cpu_init(void) {
+void cc430_cpu_init(void)
+{
     volatile uint16_t i;
     volatile unsigned char *ptr;
 
@@ -11,7 +12,7 @@ void cc430_cpu_init(void) {
     WDTCTL = WDTPW + WDTHOLD;
 
     // ---------------------------------------------------------------------
-    // Enable 32kHz ACLK    
+    // Enable 32kHz ACLK
     P5SEL |= 0x03;                            // Select XIN, XOUT on P5.0 and P5.1
     UCSCTL6 &= ~XT1OFF;                       // XT1 On, Highest drive strength
     UCSCTL6 |= XCAP_3;                        // Internal load cap
@@ -31,15 +32,15 @@ void cc430_cpu_init(void) {
     // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
     // UG for optimization.
     // 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
-	for (i = 0xFF; i > 0; i--); // Time for flag to set
+    for (i = 0xFF; i > 0; i--); // Time for flag to set
 
-    // Loop until XT1 & DCO stabilizes, use do-while to insure that 
+    // Loop until XT1 & DCO stabilizes, use do-while to insure that
     // body is executed at least once
-    do
-    {
+    do {
         UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
         SFRIFG1 &= ~OFIFG;                      // Clear fault flags
-    } while ((SFRIFG1 & OFIFG));
+    }
+    while ((SFRIFG1 & OFIFG));
 
     // Disable all interrupts
     __disable_interrupt();
@@ -50,25 +51,26 @@ void cc430_cpu_init(void) {
 
     // P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output)
     ptr  = &P2MAP0;
-    *(ptr+7) = PM_TA1CCR0A;
+    *(ptr + 7) = PM_TA1CCR0A;
     P2OUT &= ~BIT7;
     P2DIR |= BIT7;
 
     // P1.5 = SPI MISO input
     ptr  = &P1MAP0;
-    *(ptr+5) = PM_UCA0SOMI;
+    *(ptr + 5) = PM_UCA0SOMI;
     // P1.6 = SPI MOSI output
-    *(ptr+6) = PM_UCA0SIMO;
+    *(ptr + 6) = PM_UCA0SIMO;
     // P1.7 = SPI CLK output
-    *(ptr+7) = PM_UCA0CLK;
+    *(ptr + 7) = PM_UCA0CLK;
 
     // Disable write-access to port mapping registers:
     PMAPPWD = 0;
     // Re-enable all interrupts
     enableIRQ();
- 
+
 }
 
-void board_init(void) {
+void board_init(void)
+{
     cc430_cpu_init();
 }
diff --git a/chronos/drivers/battery.c b/chronos/drivers/battery.c
index 6ca24a3b67c0e07305538265c48e6e82e9a7b630..13e50dc102d5dfb3ac4667a431dd7b39e13cf399 100644
--- a/chronos/drivers/battery.c
+++ b/chronos/drivers/battery.c
@@ -2,12 +2,13 @@
 #include <cc430f6137.h>
 #include <cc430-adc.h>
 
-uint32_t battery_get_voltage(void) {
+uint32_t battery_get_voltage(void)
+{
     uint32_t voltage;
     voltage = adc12_single_conversion(REFVSEL_1, ADC12SHT0_10, ADC12INCH_11);
 
     /* Ideally we have A11=0->AVCC=0V ... A11=4095(2^12-1)->AVCC=4V
      * --> (A11/4095)*4V=AVCC --> AVCC=(A11*4)/4095 */
-    voltage = (voltage * 2 * 2 * 1000) / 4095;  
+    voltage = (voltage * 2 * 2 * 1000) / 4095;
     return voltage;
 }
diff --git a/chronos/drivers/buzzer.c b/chronos/drivers/buzzer.c
index b8f53274501d17004894cce1acba400b7cb33f21..3d4d15061dc977fa20523d46ac8a97884b167998 100644
--- a/chronos/drivers/buzzer.c
+++ b/chronos/drivers/buzzer.c
@@ -3,11 +3,12 @@
 #include <hwtimer.h>
 #include <cc430f6137.h>
 
-void buzzer_beep(uint8_t pitch, uint16_t duration) {
-    // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK 
+void buzzer_beep(uint8_t pitch, uint16_t duration)
+{
+    // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK
     TA1CTL = TACLR | MC_1 | TASSEL__ACLK;
 
-    // Set PWM frequency 
+    // Set PWM frequency
     TA1CCR0 = pitch;
 
     // Enable IRQ, set output mode "toggle"
@@ -18,11 +19,11 @@ void buzzer_beep(uint8_t pitch, uint16_t duration) {
 
     hwtimer_wait(duration);
 
-    // Stop PWM timer 
+    // Stop PWM timer
     TA1CTL &= ~(BIT4 | BIT5);
 
     // Reset and disable buzzer PWM output
     P2OUT &= ~BIT7;
     P2SEL &= ~BIT7;
-    TA1CCTL0 &= ~CCIE; 
+    TA1CCTL0 &= ~CCIE;
 }
diff --git a/chronos/drivers/cc430-cc110x.c b/chronos/drivers/cc430-cc110x.c
index 0a38b68b7b1b835db932a156c068236abc3753e6..d606d5bfd5783dffb77dc06f2d6af324ad82e9c2 100644
--- a/chronos/drivers/cc430-cc110x.c
+++ b/chronos/drivers/cc430-cc110x.c
@@ -9,73 +9,86 @@
 #include <cc430f6137.h>
 //#include <msp430/rf1a.h>
 
-#define CC1100_GDO0     (RF1AIN & BIT0) 
+#define CC1100_GDO0     (RF1AIN & BIT0)
 #define CC1100_GDO1     (RF1AIN & BIT1)
 #define CC1100_GDO2     (RF1AIN & BIT2)
 
-int cc110x_get_gdo0(void) {
-	return 	CC1100_GDO0;
+int cc110x_get_gdo0(void)
+{
+    return 	CC1100_GDO0;
 }
 
-int cc110x_get_gdo1(void) {
-	return 	CC1100_GDO1;
+int cc110x_get_gdo1(void)
+{
+    return 	CC1100_GDO1;
 }
 
-int cc110x_get_gdo2(void) {
-	return 	CC1100_GDO2;
+int cc110x_get_gdo2(void)
+{
+    return 	CC1100_GDO2;
 }
 
 void cc110x_before_send(void)
 {
-	// Disable GDO2 interrupt before sending packet
-	cc110x_gdo2_disable();
+    // Disable GDO2 interrupt before sending packet
+    cc110x_gdo2_disable();
 }
 
 void cc110x_after_send(void)
 {
-	// Enable GDO2 interrupt after sending packet
-	cc110x_gdo2_enable();
+    // Enable GDO2 interrupt after sending packet
+    cc110x_gdo2_enable();
 }
 
-void cc110x_gdo0_enable(void) {
+void cc110x_gdo0_enable(void)
+{
     RF1AIFG &= ~BIT0;
     RF1AIE  |= BIT0;
 }
 
-void cc110x_gdo0_disable(void) {
+void cc110x_gdo0_disable(void)
+{
     RF1AIE  &= ~BIT0;
     RF1AIFG &= ~BIT0;
 }
 
-void cc110x_gdo2_disable(void) {
+void cc110x_gdo2_disable(void)
+{
     RF1AIFG &= ~BIT2;                         // Clear a pending interrupt
-    RF1AIE  &= ~BIT2;                          // Disable the interrupt 
+    RF1AIE  &= ~BIT2;                          // Disable the interrupt
 }
 
-void cc110x_gdo2_enable(void) {
+void cc110x_gdo2_enable(void)
+{
     RF1AIFG &= ~BIT2;                         // Clear a pending interrupt
-    RF1AIE  |= BIT2;                          // Enable the interrupt 
+    RF1AIE  |= BIT2;                          // Enable the interrupt
 }
 
-void cc110x_init_interrupts(void) {
-	uint8_t state = disableIRQ(); /* Disable all interrupts */
+void cc110x_init_interrupts(void)
+{
+    uint8_t state = disableIRQ(); /* Disable all interrupts */
     cc110x_gdo2_enable();
     cc110x_gdo0_disable();
-	restoreIRQ(state);  /* Enable all interrupts */
+    restoreIRQ(state);  /* Enable all interrupts */
 }
 
-interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc110x_isr(void){
+interrupt(CC1101_VECTOR) __attribute__((naked)) cc110x_isr(void)
+{
     __enter_isr();
- 	/* Check IFG */
-	if (RF1AIV == RF1AIV_RFIFG2) {
+
+    /* Check IFG */
+    if (RF1AIV == RF1AIV_RFIFG2) {
         while (RF1AIN & BIT2);
+
         /* discard all further interrupts */
         RF1AIV = 0;
-		cc110x_gdo2_irq();
+        cc110x_gdo2_irq();
     }
-	if (RF1AIV == RF1AIV_RFIFG0) {
+
+    if (RF1AIV == RF1AIV_RFIFG0) {
         cc110x_gdo0_irq();
         RF1AIE &= ~BIT0;
-	}
-	__exit_isr();
+    }
+
+    __exit_isr();
 }
diff --git a/chronos/drivers/display.c b/chronos/drivers/display.c
index f33cd6eaf1a9959654c4bd2eaf562445ab2260fd..b93c820e1e390423acfe05499b962285f53f6cea 100644
--- a/chronos/drivers/display.c
+++ b/chronos/drivers/display.c
@@ -1,34 +1,34 @@
 /* *************************************************************************************************
  *
- *	Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 
- *	 
- *	 
- *	  Redistribution and use in source and binary forms, with or without 
- *	  modification, are permitted provided that the following conditions 
+ *	Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *	  Redistribution and use in source and binary forms, with or without
+ *	  modification, are permitted provided that the following conditions
  *	  are met:
- *	
- *	    Redistributions of source code must retain the above copyright 
+ *
+ *	    Redistributions of source code must retain the above copyright
  *	    notice, this list of conditions and the following disclaimer.
- *	 
+ *
  *	    Redistributions in binary form must reproduce the above copyright
- *	    notice, this list of conditions and the following disclaimer in the 
- *	    documentation and/or other materials provided with the   
+ *	    notice, this list of conditions and the following disclaimer in the
+ *	    documentation and/or other materials provided with the
  *	    distribution.
- *	 
+ *
  *	    Neither the name of Texas Instruments Incorporated nor the names of
  *	    its contributors may be used to endorse or promote products derived
  *	    from this software without specific prior written permission.
- *	
- *	  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- *	  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *
+ *	  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *	  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  *	  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *	  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
- *	  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- *	  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *	  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *	  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *	  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  *	  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  *	  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *	  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- *	  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *	  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *	  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *	  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * *************************************************************************************************
@@ -62,322 +62,357 @@ volatile s_display_flags_t display;
 /* Global return string for itoa function */
 char itoa_str[8];
 
-void lcd_init(void) {
-	/* Clear entire display memory */
-	LCDBMEMCTL |= LCDCLRBM + LCDCLRM;
+void lcd_init(void)
+{
+    /* Clear entire display memory */
+    LCDBMEMCTL |= LCDCLRBM + LCDCLRM;
 
-	/* LCD_FREQ = ACLK/16/8 = 256Hz  */
-	/* Frame frequency = 256Hz/4 = 64Hz, LCD mux 4, LCD on */
-	LCDBCTL0 = (LCDDIV0 + LCDDIV1 + LCDDIV2 + LCDDIV3) | (LCDPRE0 + LCDPRE1) | LCD4MUX | LCDON;
+    /* LCD_FREQ = ACLK/16/8 = 256Hz  */
+    /* Frame frequency = 256Hz/4 = 64Hz, LCD mux 4, LCD on */
+    LCDBCTL0 = (LCDDIV0 + LCDDIV1 + LCDDIV2 + LCDDIV3) | (LCDPRE0 + LCDPRE1) | LCD4MUX | LCDON;
 
-	/* LCB_BLK_FREQ = ACLK/8/4096 = 1Hz */
-	LCDBBLKCTL = LCDBLKPRE0 | LCDBLKPRE1 | LCDBLKDIV0 | LCDBLKDIV1 | LCDBLKDIV2 | LCDBLKMOD0; 
+    /* LCB_BLK_FREQ = ACLK/8/4096 = 1Hz */
+    LCDBBLKCTL = LCDBLKPRE0 | LCDBLKPRE1 | LCDBLKDIV0 | LCDBLKDIV1 | LCDBLKDIV2 | LCDBLKMOD0;
 
-	/* I/O to COM outputs */
-	P5SEL |= (BIT5 | BIT6 | BIT7);
-	P5DIR |= (BIT5 | BIT6 | BIT7);
-  
-	/* Activate LCD output */
-	LCDBPCTL0 = 0xFFFF;                         /* Select LCD segments S0-S15 */
-	LCDBPCTL1 = 0x00FF;                         /* Select LCD segments S16-S22 */
+    /* I/O to COM outputs */
+    P5SEL |= (BIT5 | BIT6 | BIT7);
+    P5DIR |= (BIT5 | BIT6 | BIT7);
+
+    /* Activate LCD output */
+    LCDBPCTL0 = 0xFFFF;                         /* Select LCD segments S0-S15 */
+    LCDBPCTL1 = 0x00FF;                         /* Select LCD segments S16-S22 */
 
 #ifdef USE_LCD_CHARGE_PUMP
-	/* Charge pump voltage generated internally, internal bias (V2-V4) generation */
-	LCDBVCTL = LCDCPEN | VLCD_2_72;
+    /* Charge pump voltage generated internally, internal bias (V2-V4) generation */
+    LCDBVCTL = LCDCPEN | VLCD_2_72;
 #endif
 }
 
-void clear_display_all(void) {
-	// Clear generic content
-	clear_line(LINE1);
-	clear_line(LINE2);
+void clear_display_all(void)
+{
+    // Clear generic content
+    clear_line(LINE1);
+    clear_line(LINE2);
 }
 
-void clear_display(void) {
-	clear_line(LINE1);
-	clear_line(LINE2);
+void clear_display(void)
+{
+    clear_line(LINE1);
+    clear_line(LINE2);
 }
 
-void clear_line(uint8_t line) {
-	display_chars(switch_seg(line, LCD_SEG_L1_3_0, LCD_SEG_L2_5_0), NULL, SEG_OFF);
-	if (line == LINE1) {
-		display_symbol(LCD_SEG_L1_DP1, SEG_OFF);
-		display_symbol(LCD_SEG_L1_DP0, SEG_OFF);
-		display_symbol(LCD_SEG_L1_COL, SEG_OFF);
-	}
+void clear_line(uint8_t line)
+{
+    display_chars(switch_seg(line, LCD_SEG_L1_3_0, LCD_SEG_L2_5_0), NULL, SEG_OFF);
+
+    if (line == LINE1) {
+        display_symbol(LCD_SEG_L1_DP1, SEG_OFF);
+        display_symbol(LCD_SEG_L1_DP0, SEG_OFF);
+        display_symbol(LCD_SEG_L1_COL, SEG_OFF);
+    }
     /* line == LINE2 */
-	else  {
-		display_symbol(LCD_SEG_L2_DP, SEG_OFF);
-		display_symbol(LCD_SEG_L2_COL1, SEG_OFF);
-		display_symbol(LCD_SEG_L2_COL0, SEG_OFF);
-	}
+    else  {
+        display_symbol(LCD_SEG_L2_DP, SEG_OFF);
+        display_symbol(LCD_SEG_L2_COL1, SEG_OFF);
+        display_symbol(LCD_SEG_L2_COL0, SEG_OFF);
+    }
 }
 
-void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state) {
-	if (state == SEG_ON) {
-		/* Clear segments before writing */
-		*lcdmem = (uint8_t)(*lcdmem & ~bitmask);
-	
-		/* Set visible segments */
-		*lcdmem = (uint8_t)(*lcdmem | bits);
-	}
-	else if (state == SEG_OFF) {
-		/* Clear segments */
-		*lcdmem = (uint8_t)(*lcdmem & ~bitmask);
-	}
-	else if (state == SEG_ON_BLINK_ON) {
-		/* Clear visible / blink segments before writing */
-		*lcdmem 		= (uint8_t)(*lcdmem & ~bitmask);
-		*(lcdmem+0x20) 	= (uint8_t)(*(lcdmem+0x20) & ~bitmask);
-	
-		/* Set visible / blink segments */
-		*lcdmem 		= (uint8_t)(*lcdmem | bits);
-		*(lcdmem+0x20) 	= (uint8_t)(*(lcdmem+0x20) | bits);
-	}
-	else if (state == SEG_ON_BLINK_OFF) {
-		/* Clear visible segments before writing */
-		*lcdmem = (uint8_t)(*lcdmem & ~bitmask);
-	
-		/* Set visible segments */
-		*lcdmem = (uint8_t)(*lcdmem | bits);
-
-		/* Clear blink segments */
-		*(lcdmem+0x20) 	= (uint8_t)(*(lcdmem+0x20) & ~bitmask);
-	}
-	else if (state == SEG_OFF_BLINK_OFF) {
-		/* Clear segments */
-		*lcdmem = (uint8_t)(*lcdmem & ~bitmask);
-
-		/* Clear blink segments */
-		*(lcdmem+0x20) 	= (uint8_t)(*(lcdmem+0x20) & ~bitmask);
-	}
+void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state)
+{
+    if (state == SEG_ON) {
+        /* Clear segments before writing */
+        *lcdmem = (uint8_t)(*lcdmem & ~bitmask);
+
+        /* Set visible segments */
+        *lcdmem = (uint8_t)(*lcdmem | bits);
+    }
+    else if (state == SEG_OFF) {
+        /* Clear segments */
+        *lcdmem = (uint8_t)(*lcdmem & ~bitmask);
+    }
+    else if (state == SEG_ON_BLINK_ON) {
+        /* Clear visible / blink segments before writing */
+        *lcdmem 		= (uint8_t)(*lcdmem & ~bitmask);
+        *(lcdmem + 0x20) 	= (uint8_t)(*(lcdmem + 0x20) & ~bitmask);
+
+        /* Set visible / blink segments */
+        *lcdmem 		= (uint8_t)(*lcdmem | bits);
+        *(lcdmem + 0x20) 	= (uint8_t)(*(lcdmem + 0x20) | bits);
+    }
+    else if (state == SEG_ON_BLINK_OFF) {
+        /* Clear visible segments before writing */
+        *lcdmem = (uint8_t)(*lcdmem & ~bitmask);
+
+        /* Set visible segments */
+        *lcdmem = (uint8_t)(*lcdmem | bits);
+
+        /* Clear blink segments */
+        *(lcdmem + 0x20) 	= (uint8_t)(*(lcdmem + 0x20) & ~bitmask);
+    }
+    else if (state == SEG_OFF_BLINK_OFF) {
+        /* Clear segments */
+        *lcdmem = (uint8_t)(*lcdmem & ~bitmask);
+
+        /* Clear blink segments */
+        *(lcdmem + 0x20) 	= (uint8_t)(*(lcdmem + 0x20) & ~bitmask);
+    }
 }
 
-char *itoa(uint32_t n, uint8_t digits, uint8_t blanks) {
-	uint8_t i;
-	uint8_t digits1 = digits;
-	
-	/* Preset result string */
-	memcpy(itoa_str, "0000000", 7);
+char *itoa(uint32_t n, uint8_t digits, uint8_t blanks)
+{
+    uint8_t i;
+    uint8_t digits1 = digits;
 
-	/* Return empty string if number of digits is invalid (valid range for digits: 1-7) */
-	if ((digits == 0) || (digits > 7))  {
+    /* Preset result string */
+    memcpy(itoa_str, "0000000", 7);
+
+    /* Return empty string if number of digits is invalid (valid range for digits: 1-7) */
+    if ((digits == 0) || (digits > 7))  {
         return (itoa_str);
     }
-	
-	/* Numbers 0 .. 180 can be copied from itoa_conversion_table without conversion */
-	if (n <= 180) {
-		if (digits >= 3) {
-			memcpy(itoa_str+(digits-3), itoa_conversion_table[n], 3);
-		}
+
+    /* Numbers 0 .. 180 can be copied from itoa_conversion_table without conversion */
+    if (n <= 180) {
+        if (digits >= 3) {
+            memcpy(itoa_str + (digits - 3), itoa_conversion_table[n], 3);
+        }
         /* digits == 1 || 2   */
         else {
-			memcpy(itoa_str, itoa_conversion_table[n]+(3-digits), digits);
-		}
-	}
+            memcpy(itoa_str, itoa_conversion_table[n] + (3 - digits), digits);
+        }
+    }
     /* For n > 180 need to calculate string content */
-	else {
-		/* Calculate digits from least to most significant number */
-		do {     
-			itoa_str[digits-1] = n % 10 + '0';   	
-			n /= 10;
-		} while (--digits > 0);  		
-	}
-
-	/* Remove specified number of leading '0', always keep last one */
-	i = 0;	
-	while ((itoa_str[i] == '0') && (i < digits1-1))	{
-		if (blanks > 0) {
-			/* Convert only specified number of leading '0' */
-			itoa_str[i]=' ';
-			blanks--;
-		}
-		i++;
-	}
-	return (itoa_str);	
-} 
-
-void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) {
-	char *str;
-
-	str = itoa(value, digits, blanks);
-
-	/* Display string in blink mode */
-	display_chars(segments, str, disp_mode);
+    else {
+        /* Calculate digits from least to most significant number */
+        do {
+            itoa_str[digits - 1] = n % 10 + '0';
+            n /= 10;
+        }
+        while (--digits > 0);
+    }
+
+    /* Remove specified number of leading '0', always keep last one */
+    i = 0;
+
+    while ((itoa_str[i] == '0') && (i < digits1 - 1))	{
+        if (blanks > 0) {
+            /* Convert only specified number of leading '0' */
+            itoa_str[i] = ' ';
+            blanks--;
+        }
+
+        i++;
+    }
+
+    return (itoa_str);
+}
+
+void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode)
+{
+    char *str;
+
+    str = itoa(value, digits, blanks);
+
+    /* Display string in blink mode */
+    display_chars(segments, str, disp_mode);
 }
 
-void display_symbol(uint8_t symbol, uint8_t mode) {
-	uint8_t *lcdmem;
-	uint8_t bits;
-	uint8_t bitmask;
-	
-	if (symbol <= LCD_SEG_L2_DP) {
-		/* Get LCD memory address for symbol from table */
-		lcdmem 	= (uint8_t*)segments_lcdmem[symbol];
-	
-		/* Get bits for symbol from table */
-		bits 	= segments_bitmask[symbol];
-		
-		/* Bitmask for symbols equals bits */
-		bitmask = bits;
-	
-		/* Write LCD memory 	 */
-		write_lcd_mem(lcdmem, bits, bitmask, mode);
-	}
+void display_symbol(uint8_t symbol, uint8_t mode)
+{
+    uint8_t *lcdmem;
+    uint8_t bits;
+    uint8_t bitmask;
+
+    if (symbol <= LCD_SEG_L2_DP) {
+        /* Get LCD memory address for symbol from table */
+        lcdmem 	= (uint8_t *)segments_lcdmem[symbol];
+
+        /* Get bits for symbol from table */
+        bits 	= segments_bitmask[symbol];
+
+        /* Bitmask for symbols equals bits */
+        bitmask = bits;
+
+        /* Write LCD memory 	 */
+        write_lcd_mem(lcdmem, bits, bitmask, mode);
+    }
 }
 
-void display_char(uint8_t segment, char chr, uint8_t mode) {
-	uint8_t *lcdmem;			/* Pointer to LCD memory */
-	uint8_t bitmask;			/* Bitmask for character */
-	uint8_t bits, bits1;		/* Bits to write */
-	
-	/* Write to single 7-segment character */
-	if ((segment >= LCD_SEG_L1_3) && (segment <= LCD_SEG_L2_DP)) {
-		/* Get LCD memory address for segment from table */
-		lcdmem = (uint8_t*)segments_lcdmem[segment];
-
-		/* Get bitmask for character from table */
-		bitmask = segments_bitmask[segment];
-		
-		/* Get bits from font set */
-		if ((chr >= 0x30) && (chr <= 0x5A)) {
-			/* Use font set */
-			bits = lcd_font[chr-0x30];
-		}
-		else if (chr == 0x2D) {
-			/* '-' not in font set */
-			bits = BIT1;
-		}
-		else {
-			/* Other characters map to ' ' (blank) */
-			bits = 0;
-		}
-
-		/* When addressing LINE2 7-segment characters need to swap high- and low-nibble, */
-		/* because LCD COM/SEG assignment is mirrored against LINE1 */
-		if (segment >= LCD_SEG_L2_5) {
-			bits1 = ((bits << 4) & 0xF0) | ((bits >> 4) & 0x0F);
-			bits = bits1;
-
-			/* When addressing LCD_SEG_L2_5, need to convert ASCII '1' and 'L' to 1 bit, */
-			/* because LCD COM/SEG assignment is special for this incomplete character */
-			if (segment == LCD_SEG_L2_5) {
-				if ((chr == '1') || (chr == 'L')) bits = BIT7;
-			}
-		}
-		
-		/* Physically write to LCD memory		 */
-		write_lcd_mem(lcdmem, bits, bitmask, mode);
-	}
-}	
-
-void display_chars(uint8_t segments, char *str, uint8_t mode) {
-	uint8_t i;
-	uint8_t length = 0;			/* Write length */
-	uint8_t char_start = 0;			/* Starting point for consecutive write */
-	
-	switch (segments) {
-		/* LINE1 */
-		case LCD_SEG_L1_3_0:	
-            length=4; 
-            char_start=LCD_SEG_L1_3; 
+void display_char(uint8_t segment, char chr, uint8_t mode)
+{
+    uint8_t *lcdmem;			/* Pointer to LCD memory */
+    uint8_t bitmask;			/* Bitmask for character */
+    uint8_t bits, bits1;		/* Bits to write */
+
+    /* Write to single 7-segment character */
+    if ((segment >= LCD_SEG_L1_3) && (segment <= LCD_SEG_L2_DP)) {
+        /* Get LCD memory address for segment from table */
+        lcdmem = (uint8_t *)segments_lcdmem[segment];
+
+        /* Get bitmask for character from table */
+        bitmask = segments_bitmask[segment];
+
+        /* Get bits from font set */
+        if ((chr >= 0x30) && (chr <= 0x5A)) {
+            /* Use font set */
+            bits = lcd_font[chr - 0x30];
+        }
+        else if (chr == 0x2D) {
+            /* '-' not in font set */
+            bits = BIT1;
+        }
+        else {
+            /* Other characters map to ' ' (blank) */
+            bits = 0;
+        }
+
+        /* When addressing LINE2 7-segment characters need to swap high- and low-nibble, */
+        /* because LCD COM/SEG assignment is mirrored against LINE1 */
+        if (segment >= LCD_SEG_L2_5) {
+            bits1 = ((bits << 4) & 0xF0) | ((bits >> 4) & 0x0F);
+            bits = bits1;
+
+            /* When addressing LCD_SEG_L2_5, need to convert ASCII '1' and 'L' to 1 bit, */
+            /* because LCD COM/SEG assignment is special for this incomplete character */
+            if (segment == LCD_SEG_L2_5) {
+                if ((chr == '1') || (chr == 'L')) {
+                    bits = BIT7;
+                }
+            }
+        }
+
+        /* Physically write to LCD memory		 */
+        write_lcd_mem(lcdmem, bits, bitmask, mode);
+    }
+}
+
+void display_chars(uint8_t segments, char *str, uint8_t mode)
+{
+    uint8_t i;
+    uint8_t length = 0;			/* Write length */
+    uint8_t char_start = 0;			/* Starting point for consecutive write */
+
+    switch (segments) {
+            /* LINE1 */
+        case LCD_SEG_L1_3_0:
+            length = 4;
+            char_start = LCD_SEG_L1_3;
             break;
-		case LCD_SEG_L1_2_0:	
-            length=3; 
-            char_start=LCD_SEG_L1_2; 
+
+        case LCD_SEG_L1_2_0:
+            length = 3;
+            char_start = LCD_SEG_L1_2;
             break;
-		case LCD_SEG_L1_1_0: 	
-            length=2; 
-            char_start=LCD_SEG_L1_1; 
+
+        case LCD_SEG_L1_1_0:
+            length = 2;
+            char_start = LCD_SEG_L1_1;
             break;
-		case LCD_SEG_L1_3_1: 	
-            length=3; 
-            char_start=LCD_SEG_L1_3; 
+
+        case LCD_SEG_L1_3_1:
+            length = 3;
+            char_start = LCD_SEG_L1_3;
             break;
-		case LCD_SEG_L1_3_2: 	
-            length=2; 
-            char_start=LCD_SEG_L1_3; 
+
+        case LCD_SEG_L1_3_2:
+            length = 2;
+            char_start = LCD_SEG_L1_3;
             break;
 
-		/* LINE2 */
-		case LCD_SEG_L2_5_0:	
-            length=6; 
-            char_start=LCD_SEG_L2_5; 
+            /* LINE2 */
+        case LCD_SEG_L2_5_0:
+            length = 6;
+            char_start = LCD_SEG_L2_5;
             break;
-		case LCD_SEG_L2_4_0:	
-            length=5; 
-            char_start=LCD_SEG_L2_4; 
+
+        case LCD_SEG_L2_4_0:
+            length = 5;
+            char_start = LCD_SEG_L2_4;
             break;
-		case LCD_SEG_L2_3_0:	
-            length=4; 
-            char_start=LCD_SEG_L2_3; 
+
+        case LCD_SEG_L2_3_0:
+            length = 4;
+            char_start = LCD_SEG_L2_3;
             break;
-		case LCD_SEG_L2_2_0:	
-            length=3; 
-            char_start=LCD_SEG_L2_2; 
+
+        case LCD_SEG_L2_2_0:
+            length = 3;
+            char_start = LCD_SEG_L2_2;
             break;
-		case LCD_SEG_L2_1_0: 	
-            length=2; 
-            char_start=LCD_SEG_L2_1; 
+
+        case LCD_SEG_L2_1_0:
+            length = 2;
+            char_start = LCD_SEG_L2_1;
             break;
-		case LCD_SEG_L2_5_4:	
-            length=2; 
-            char_start=LCD_SEG_L2_5; 
+
+        case LCD_SEG_L2_5_4:
+            length = 2;
+            char_start = LCD_SEG_L2_5;
             break;
-		case LCD_SEG_L2_5_2:	
-            length=4; 
-            char_start=LCD_SEG_L2_5; 
+
+        case LCD_SEG_L2_5_2:
+            length = 4;
+            char_start = LCD_SEG_L2_5;
             break;
-		case LCD_SEG_L2_3_2:	
-            length=2; 
-            char_start=LCD_SEG_L2_3; 
+
+        case LCD_SEG_L2_3_2:
+            length = 2;
+            char_start = LCD_SEG_L2_3;
             break;
-		case LCD_SEG_L2_4_2: 	
-            length=3; 
-            char_start=LCD_SEG_L2_4; 
+
+        case LCD_SEG_L2_4_2:
+            length = 3;
+            char_start = LCD_SEG_L2_4;
             break;
-	}
-	
-	/* Write to consecutive digits */
-	for(i=0; i<length; i++) {
-		/* Use single character routine to write display memory */
-		display_char(char_start+i, *(str+i), mode);
-	}
+    }
+
+    /* Write to consecutive digits */
+    for (i = 0; i < length; i++) {
+        /* Use single character routine to write display memory */
+        display_char(char_start + i, *(str + i), mode);
+    }
 }
 
-uint8_t switch_seg(uint8_t line, uint8_t index1, uint8_t index2) {
-	if (line == LINE1) {
-		return index1;
-	}
+uint8_t switch_seg(uint8_t line, uint8_t index1, uint8_t index2)
+{
+    if (line == LINE1) {
+        return index1;
+    }
     /* line == LINE2 */
-	else {
-		return index2;
-	}
+    else {
+        return index2;
+    }
 }
 
-void start_blink(void) {
-	LCDBBLKCTL |= LCDBLKMOD0;
+void start_blink(void)
+{
+    LCDBBLKCTL |= LCDBLKMOD0;
 }
 
-void stop_blink(void) {
-	LCDBBLKCTL &= ~LCDBLKMOD0;
+void stop_blink(void)
+{
+    LCDBBLKCTL &= ~LCDBLKMOD0;
 }
 
-void clear_blink_mem(void) {
-	LCDBMEMCTL |= LCDCLRBM;	
+void clear_blink_mem(void)
+{
+    LCDBMEMCTL |= LCDCLRBM;
 }
 
-void set_blink_rate(uint8_t bits) {
-	LCDBBLKCTL &= ~(BIT7 | BIT6 | BIT5);	
-	LCDBBLKCTL |= bits;	
+void set_blink_rate(uint8_t bits)
+{
+    LCDBBLKCTL &= ~(BIT7 | BIT6 | BIT5);
+    LCDBBLKCTL |= bits;
 }
 
-void display_all_off(void) {
-	uint8_t *lcdptr = (uint8_t*)0x0A20;
-	uint8_t i;
-	
-	for (i=1; i<=12; i++) {
-		*lcdptr = 0x00; 
-		lcdptr++;
-	}
+void display_all_off(void)
+{
+    uint8_t *lcdptr = (uint8_t *)0x0A20;
+    uint8_t i;
+
+    for (i = 1; i <= 12; i++) {
+        *lcdptr = 0x00;
+        lcdptr++;
+    }
 }
diff --git a/chronos/drivers/display1.c b/chronos/drivers/display1.c
index a45c74625e1a671b0734b25be5e2b8de70673404..461c0c0097d974556ee5272c643fadffb5fd7759 100644
--- a/chronos/drivers/display1.c
+++ b/chronos/drivers/display1.c
@@ -1,34 +1,34 @@
 /* *************************************************************************************************
  *
- *	Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 
- *	 
- *	 
- *	  Redistribution and use in source and binary forms, with or without 
- *	  modification, are permitted provided that the following conditions 
+ *	Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *	  Redistribution and use in source and binary forms, with or without
+ *	  modification, are permitted provided that the following conditions
  *	  are met:
- *	
- *	    Redistributions of source code must retain the above copyright 
+ *
+ *	    Redistributions of source code must retain the above copyright
  *	    notice, this list of conditions and the following disclaimer.
- *	 
+ *
  *	    Redistributions in binary form must reproduce the above copyright
- *	    notice, this list of conditions and the following disclaimer in the 
- *	    documentation and/or other materials provided with the   
+ *	    notice, this list of conditions and the following disclaimer in the
+ *	    documentation and/or other materials provided with the
  *	    distribution.
- *	 
+ *
  *	    Neither the name of Texas Instruments Incorporated nor the names of
  *	    its contributors may be used to endorse or promote products derived
  *	    from this software without specific prior written permission.
- *	
- *	  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- *	  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+ *
+ *	  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *	  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  *	  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *	  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
- *	  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- *	  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
+ *	  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *	  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *	  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  *	  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  *	  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *	  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- *	  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ *	  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *	  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *	  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * ************************************************************************************************/
@@ -52,157 +52,157 @@
 /* E   C */
 /*   D */
 const uint8_t lcd_font[] = {
-  SEG_A+SEG_B+SEG_C+SEG_D+SEG_E+SEG_F,           /* Displays "0" */
-        SEG_B+SEG_C,                             /* Displays "1" */
-  SEG_A+SEG_B+      SEG_D+SEG_E+      SEG_G,     /* Displays "2" */
-  SEG_A+SEG_B+SEG_C+SEG_D+            SEG_G,     /* Displays "3" */
-        SEG_B+SEG_C+            SEG_F+SEG_G,     /* Displays "4" */
-  SEG_A+      SEG_C+SEG_D+      SEG_F+SEG_G,     /* Displays "5" */
-  SEG_A+      SEG_C+SEG_D+SEG_E+SEG_F+SEG_G,     /* Displays "6" */
-  SEG_A+SEG_B+SEG_C,                             /* Displays "7" */
-  SEG_A+SEG_B+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G,     /* Displays "8" */
-  SEG_A+SEG_B+SEG_C+SEG_D+      SEG_F+SEG_G,     /* Displays "9" */
-  0                                        ,     /* Displays " " (:) */
-  0                                        ,     /* Displays " " (;) */
-  SEG_A+                        SEG_F+SEG_G,     /* Displays "<" as high c */
-                    SEG_D+            SEG_G,     /* Displays "=" */
-  0                                        ,     /* Displays " " (>) */
-  SEG_A+SEG_B+            SEG_E+      SEG_G,     /* Displays "?" */
-  0                                        ,     /* Displays " " (@) */
-  SEG_A+SEG_B+SEG_C+      SEG_E+SEG_F+SEG_G,     /* Displays "A" */
-              SEG_C+SEG_D+SEG_E+SEG_F+SEG_G,     /* Displays "b" */
-                    SEG_D+SEG_E+      SEG_G,     /* Displays "c" */
-        SEG_B+SEG_C+SEG_D+SEG_E+      SEG_G,     /* Displays "d" */
-  SEG_A+           +SEG_D+SEG_E+SEG_F+SEG_G,     /* Displays "E" */
-  SEG_A+                  SEG_E+SEG_F+SEG_G,     /* Displays "f" */
-  SEG_A+SEG_B+SEG_C+SEG_D+      SEG_F+SEG_G,     /* Displays "g" same as 9 */
-              SEG_C+      SEG_E+SEG_F+SEG_G,     /* Displays "h" */
-                          SEG_E            ,     /* Displays "i" */
-  SEG_A+SEG_B+SEG_C+SEG_D                  ,     /* Displays "J" */
-  		     		SEG_D+      SEG_F+SEG_G,     /* Displays "k" */
-                    SEG_D+SEG_E+SEG_F      ,     /* Displays "L" */
-  SEG_A+SEG_B+SEG_C+      SEG_E+SEG_F      ,     /* Displays "M" */
-              SEG_C+      SEG_E+      SEG_G,     /* Displays "n" */
-              SEG_C+SEG_D+SEG_E+      SEG_G,     /* Displays "o" */
-  SEG_A+SEG_B+            SEG_E+SEG_F+SEG_G,     /* Displays "P" */
-  SEG_A+SEG_B+SEG_C+            SEG_F+SEG_G,     /* Displays "q" */
-                          SEG_E+      SEG_G,     /* Displays "r" */
-  SEG_A+      SEG_C+SEG_D+      SEG_F+SEG_G,     /* Displays "S" same as 5 */
-                    SEG_D+SEG_E+SEG_F+SEG_G,     /* Displays "t" */
-              SEG_C+SEG_D+SEG_E            ,     /* Displays "u" */
-              SEG_C+SEG_D+SEG_E            ,     /* Displays "v" same as u */
-        SEG_B+SEG_C+SEG_D+SEG_E+SEG_F+SEG_G,     /* Displays "W" */
-        SEG_B+SEG_C+     +SEG_E+SEG_F+SEG_G,     /* Displays "X" as H */
-        SEG_B+SEG_C+SEG_D+      SEG_F+SEG_G,     /* Displays "Y" */
-  SEG_A+SEG_B+      SEG_D+SEG_E+      SEG_G,     /* Displays "Z" same as 2 */
+    SEG_A + SEG_B + SEG_C + SEG_D + SEG_E + SEG_F,          /* Displays "0" */
+    SEG_B + SEG_C,                                          /* Displays "1" */
+    SEG_A + SEG_B +         SEG_D + SEG_E +         SEG_G,  /* Displays "2" */
+    SEG_A + SEG_B + SEG_C + SEG_D +                 SEG_G,  /* Displays "3" */
+            SEG_B + SEG_C +                 SEG_F + SEG_G,  /* Displays "4" */
+    SEG_A +         SEG_C + SEG_D +         SEG_F + SEG_G,  /* Displays "5" */
+    SEG_A +         SEG_C + SEG_D + SEG_E + SEG_F + SEG_G,  /* Displays "6" */
+    SEG_A + SEG_B + SEG_C,                                  /* Displays "7" */
+    SEG_A + SEG_B + SEG_C + SEG_D + SEG_E + SEG_F + SEG_G,  /* Displays "8" */
+    SEG_A + SEG_B + SEG_C + SEG_D +         SEG_F + SEG_G,  /* Displays "9" */
+    0,                                                      /* Displays " " (:) */
+    0,                                                      /* Displays " " (;) */
+    SEG_A +                                 SEG_F + SEG_G,  /* Displays "<" as high c */
+    SEG_D +                                         SEG_G,  /* Displays "=" */
+    0,                                                      /* Displays " " (>) */
+    SEG_A + SEG_B +                 SEG_E +         SEG_G,  /* Displays "?" */
+    0,                                                      /* Displays " " (@) */
+    SEG_A + SEG_B + SEG_C +         SEG_E + SEG_F + SEG_G,  /* Displays "A" */
+                    SEG_C + SEG_D + SEG_E + SEG_F + SEG_G,  /* Displays "b" */
+                            SEG_D + SEG_E +         SEG_G,  /* Displays "c" */
+            SEG_B + SEG_C + SEG_D + SEG_E +         SEG_G,  /* Displays "d" */
+    SEG_A +                 SEG_D + SEG_E + SEG_F + SEG_G,  /* Displays "E" */
+    SEG_A +                         SEG_E + SEG_F + SEG_G,  /* Displays "f" */
+    SEG_A + SEG_B + SEG_C + SEG_D +         SEG_F + SEG_G,  /* Displays "g" same as 9 */
+    SEG_C +                         SEG_E + SEG_F + SEG_G,  /* Displays "h" */
+                                    SEG_E,                  /* Displays "i" */
+    SEG_A + SEG_B + SEG_C + SEG_D,                          /* Displays "J" */
+                            SEG_D +         SEG_F + SEG_G,  /* Displays "k" */
+                            SEG_D + SEG_E + SEG_F,          /* Displays "L" */
+    SEG_A + SEG_B + SEG_C +         SEG_E + SEG_F,          /* Displays "M" */
+                    SEG_C +         SEG_E +         SEG_G,  /* Displays "n" */
+                    SEG_C + SEG_D + SEG_E +         SEG_G,  /* Displays "o" */
+    SEG_A + SEG_B +                 SEG_E + SEG_F + SEG_G,  /* Displays "P" */
+    SEG_A + SEG_B + SEG_C +                 SEG_F + SEG_G,  /* Displays "q" */
+                                    SEG_E +         SEG_G,  /* Displays "r" */
+    SEG_A +         SEG_C + SEG_D +         SEG_F + SEG_G,  /* Displays "S" same as 5 */
+                            SEG_D + SEG_E + SEG_F + SEG_G,  /* Displays "t" */
+                    SEG_C + SEG_D + SEG_E,                  /* Displays "u" */
+                    SEG_C + SEG_D + SEG_E,                  /* Displays "v" same as u */
+            SEG_B + SEG_C + SEG_D + SEG_E + SEG_F + SEG_G,  /* Displays "W" */
+            SEG_B + SEG_C +         SEG_E + SEG_F + SEG_G,  /* Displays "X" as H */
+            SEG_B + SEG_C + SEG_D +         SEG_F + SEG_G,  /* Displays "Y" */
+    SEG_A + SEG_B +         SEG_D + SEG_E +         SEG_G,  /* Displays "Z" same as 2 */
 };
 
 /* Table with memory address for each display element  */
-const uint8_t * segments_lcdmem[] = {
-	LCD_SYMB_AM_MEM,
-	LCD_SYMB_PM_MEM,
-	LCD_SYMB_ARROW_UP_MEM,
-	LCD_SYMB_ARROW_DOWN_MEM,
-	LCD_SYMB_PERCENT_MEM,
-	LCD_SYMB_TOTAL_MEM,
-	LCD_SYMB_AVERAGE_MEM,
-	LCD_SYMB_MAX_MEM,
-	LCD_SYMB_BATTERY_MEM,
-	LCD_UNIT_L1_FT_MEM,
-	LCD_UNIT_L1_K_MEM,
-	LCD_UNIT_L1_M_MEM,
-	LCD_UNIT_L1_I_MEM,
-	LCD_UNIT_L1_PER_S_MEM,
-	LCD_UNIT_L1_PER_H_MEM,
-	LCD_UNIT_L1_DEGREE_MEM,
-	LCD_UNIT_L2_KCAL_MEM,
-	LCD_UNIT_L2_KM_MEM,
-	LCD_UNIT_L2_MI_MEM,
-	LCD_ICON_HEART_MEM,
-	LCD_ICON_STOPWATCH_MEM,
-	LCD_ICON_RECORD_MEM,
-	LCD_ICON_ALARM_MEM,
-	LCD_ICON_BEEPER1_MEM,
-	LCD_ICON_BEEPER2_MEM,
-	LCD_ICON_BEEPER3_MEM,
-	LCD_SEG_L1_3_MEM,
-	LCD_SEG_L1_2_MEM,
-	LCD_SEG_L1_1_MEM,
-	LCD_SEG_L1_0_MEM,
-	LCD_SEG_L1_COL_MEM,
-	LCD_SEG_L1_DP1_MEM,
-	LCD_SEG_L1_DP0_MEM,
-	LCD_SEG_L2_5_MEM,
-	LCD_SEG_L2_4_MEM,
-	LCD_SEG_L2_3_MEM,
-	LCD_SEG_L2_2_MEM,
-	LCD_SEG_L2_1_MEM,
-	LCD_SEG_L2_0_MEM,
-	LCD_SEG_L2_COL1_MEM,
-	LCD_SEG_L2_COL0_MEM,
-	LCD_SEG_L2_DP_MEM,
+const uint8_t *segments_lcdmem[] = {
+    LCD_SYMB_AM_MEM,
+    LCD_SYMB_PM_MEM,
+    LCD_SYMB_ARROW_UP_MEM,
+    LCD_SYMB_ARROW_DOWN_MEM,
+    LCD_SYMB_PERCENT_MEM,
+    LCD_SYMB_TOTAL_MEM,
+    LCD_SYMB_AVERAGE_MEM,
+    LCD_SYMB_MAX_MEM,
+    LCD_SYMB_BATTERY_MEM,
+    LCD_UNIT_L1_FT_MEM,
+    LCD_UNIT_L1_K_MEM,
+    LCD_UNIT_L1_M_MEM,
+    LCD_UNIT_L1_I_MEM,
+    LCD_UNIT_L1_PER_S_MEM,
+    LCD_UNIT_L1_PER_H_MEM,
+    LCD_UNIT_L1_DEGREE_MEM,
+    LCD_UNIT_L2_KCAL_MEM,
+    LCD_UNIT_L2_KM_MEM,
+    LCD_UNIT_L2_MI_MEM,
+    LCD_ICON_HEART_MEM,
+    LCD_ICON_STOPWATCH_MEM,
+    LCD_ICON_RECORD_MEM,
+    LCD_ICON_ALARM_MEM,
+    LCD_ICON_BEEPER1_MEM,
+    LCD_ICON_BEEPER2_MEM,
+    LCD_ICON_BEEPER3_MEM,
+    LCD_SEG_L1_3_MEM,
+    LCD_SEG_L1_2_MEM,
+    LCD_SEG_L1_1_MEM,
+    LCD_SEG_L1_0_MEM,
+    LCD_SEG_L1_COL_MEM,
+    LCD_SEG_L1_DP1_MEM,
+    LCD_SEG_L1_DP0_MEM,
+    LCD_SEG_L2_5_MEM,
+    LCD_SEG_L2_4_MEM,
+    LCD_SEG_L2_3_MEM,
+    LCD_SEG_L2_2_MEM,
+    LCD_SEG_L2_1_MEM,
+    LCD_SEG_L2_0_MEM,
+    LCD_SEG_L2_COL1_MEM,
+    LCD_SEG_L2_COL0_MEM,
+    LCD_SEG_L2_DP_MEM,
 };
 
 /* Table with bit mask for each display element  */
 const uint8_t segments_bitmask[] = {
-	LCD_SYMB_AM_MASK,
-	LCD_SYMB_PM_MASK,
-	LCD_SYMB_ARROW_UP_MASK,
-	LCD_SYMB_ARROW_DOWN_MASK,
-	LCD_SYMB_PERCENT_MASK,
-	LCD_SYMB_TOTAL_MASK,
-	LCD_SYMB_AVERAGE_MASK,
-	LCD_SYMB_MAX_MASK,
-	LCD_SYMB_BATTERY_MASK,
-	LCD_UNIT_L1_FT_MASK,
-	LCD_UNIT_L1_K_MASK,
-	LCD_UNIT_L1_M_MASK,
-	LCD_UNIT_L1_I_MASK,
-	LCD_UNIT_L1_PER_S_MASK,
-	LCD_UNIT_L1_PER_H_MASK,
-	LCD_UNIT_L1_DEGREE_MASK,
-	LCD_UNIT_L2_KCAL_MASK,
-	LCD_UNIT_L2_KM_MASK,
-	LCD_UNIT_L2_MI_MASK,
-	LCD_ICON_HEART_MASK,
-	LCD_ICON_STOPWATCH_MASK,
-	LCD_ICON_RECORD_MASK,
-	LCD_ICON_ALARM_MASK,
-	LCD_ICON_BEEPER1_MASK,
-	LCD_ICON_BEEPER2_MASK,
-	LCD_ICON_BEEPER3_MASK,
-	LCD_SEG_L1_3_MASK,
-	LCD_SEG_L1_2_MASK,
-	LCD_SEG_L1_1_MASK,
-	LCD_SEG_L1_0_MASK,
-	LCD_SEG_L1_COL_MASK,
-	LCD_SEG_L1_DP1_MASK,
-	LCD_SEG_L1_DP0_MASK,
-	LCD_SEG_L2_5_MASK,
-	LCD_SEG_L2_4_MASK,
-	LCD_SEG_L2_3_MASK,
-	LCD_SEG_L2_2_MASK,
-	LCD_SEG_L2_1_MASK,
-	LCD_SEG_L2_0_MASK,
-	LCD_SEG_L2_COL1_MASK,
-	LCD_SEG_L2_COL0_MASK,
-	LCD_SEG_L2_DP_MASK,
+    LCD_SYMB_AM_MASK,
+    LCD_SYMB_PM_MASK,
+    LCD_SYMB_ARROW_UP_MASK,
+    LCD_SYMB_ARROW_DOWN_MASK,
+    LCD_SYMB_PERCENT_MASK,
+    LCD_SYMB_TOTAL_MASK,
+    LCD_SYMB_AVERAGE_MASK,
+    LCD_SYMB_MAX_MASK,
+    LCD_SYMB_BATTERY_MASK,
+    LCD_UNIT_L1_FT_MASK,
+    LCD_UNIT_L1_K_MASK,
+    LCD_UNIT_L1_M_MASK,
+    LCD_UNIT_L1_I_MASK,
+    LCD_UNIT_L1_PER_S_MASK,
+    LCD_UNIT_L1_PER_H_MASK,
+    LCD_UNIT_L1_DEGREE_MASK,
+    LCD_UNIT_L2_KCAL_MASK,
+    LCD_UNIT_L2_KM_MASK,
+    LCD_UNIT_L2_MI_MASK,
+    LCD_ICON_HEART_MASK,
+    LCD_ICON_STOPWATCH_MASK,
+    LCD_ICON_RECORD_MASK,
+    LCD_ICON_ALARM_MASK,
+    LCD_ICON_BEEPER1_MASK,
+    LCD_ICON_BEEPER2_MASK,
+    LCD_ICON_BEEPER3_MASK,
+    LCD_SEG_L1_3_MASK,
+    LCD_SEG_L1_2_MASK,
+    LCD_SEG_L1_1_MASK,
+    LCD_SEG_L1_0_MASK,
+    LCD_SEG_L1_COL_MASK,
+    LCD_SEG_L1_DP1_MASK,
+    LCD_SEG_L1_DP0_MASK,
+    LCD_SEG_L2_5_MASK,
+    LCD_SEG_L2_4_MASK,
+    LCD_SEG_L2_3_MASK,
+    LCD_SEG_L2_2_MASK,
+    LCD_SEG_L2_1_MASK,
+    LCD_SEG_L2_0_MASK,
+    LCD_SEG_L2_COL1_MASK,
+    LCD_SEG_L2_COL0_MASK,
+    LCD_SEG_L2_DP_MASK,
 };
 
-/* Quick integer to array conversion table for most common integer values 
+/* Quick integer to array conversion table for most common integer values
  * discarding this would save aprox. 600 bytes codespace but increase cpu time
  * for displaying values */
 const uint8_t itoa_conversion_table[][3] = {
-	"000", "001", "002", "003", "004", "005", "006", "007", "008", "009", "010", "011", "012", "013", "014", "015",
-	"016", "017", "018", "019", "020", "021", "022", "023", "024", "025", "026", "027", "028", "029", "030", "031",
-	"032", "033", "034", "035", "036", "037", "038", "039", "040", "041", "042", "043", "044", "045", "046", "047",
-	"048", "049", "050", "051", "052", "053", "054", "055", "056", "057", "058", "059", "060", "061", "062", "063",
-	"064", "065", "066", "067", "068", "069", "070", "071", "072", "073", "074", "075", "076", "077", "078", "079",
-	"080", "081", "082", "083", "084", "085", "086", "087", "088", "089", "090", "091", "092", "093", "094", "095",
-	"096", "097", "098", "099", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111",
-	"112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127",
-	"128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143",
-	"144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159",
-	"160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175",
-	"176", "177", "178", "179", "180",
+    "000", "001", "002", "003", "004", "005", "006", "007", "008", "009", "010", "011", "012", "013", "014", "015",
+    "016", "017", "018", "019", "020", "021", "022", "023", "024", "025", "026", "027", "028", "029", "030", "031",
+    "032", "033", "034", "035", "036", "037", "038", "039", "040", "041", "042", "043", "044", "045", "046", "047",
+    "048", "049", "050", "051", "052", "053", "054", "055", "056", "057", "058", "059", "060", "061", "062", "063",
+    "064", "065", "066", "067", "068", "069", "070", "071", "072", "073", "074", "075", "076", "077", "078", "079",
+    "080", "081", "082", "083", "084", "085", "086", "087", "088", "089", "090", "091", "092", "093", "094", "095",
+    "096", "097", "098", "099", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111",
+    "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127",
+    "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143",
+    "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159",
+    "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175",
+    "176", "177", "178", "179", "180",
 };
diff --git a/chronos/drivers/display_putchar.c b/chronos/drivers/display_putchar.c
index ca0e9b396b85ba4d3cb386af49b17d5d7ecd9317..95498ea8e07fb19f6f9c755179436500b2beecf5 100644
--- a/chronos/drivers/display_putchar.c
+++ b/chronos/drivers/display_putchar.c
@@ -9,12 +9,14 @@ static char display_buf[11];
 
 void putchar_to_display(int c);
 
-void init_display_putchar(void) {
-  memset(display_buf, '\0', 11);
-  _putchar = putchar_to_display;
+void init_display_putchar(void)
+{
+    memset(display_buf, '\0', 11);
+    _putchar = putchar_to_display;
 }
 
-void putchar_to_display(int c) {
+void putchar_to_display(int c)
+{
     if (c == '\n') {
         display_buf[4] = 1;
         return;
@@ -22,7 +24,8 @@ void putchar_to_display(int c) {
 
     if (display_buf[4]) {
         memset(display_buf, '\0', 11);
-    } else {
+    }
+    else {
         display_buf[0] = display_buf[1];
         display_buf[1] = display_buf[2];
         display_buf[2] = display_buf[3];
@@ -38,5 +41,5 @@ void putchar_to_display(int c) {
     clear_display_all();
 
     display_chars(LCD_SEG_L1_3_0, display_buf, SEG_ON);
-    display_chars(LCD_SEG_L2_5_0, display_buf+4, SEG_ON);
+    display_chars(LCD_SEG_L2_5_0, display_buf + 4, SEG_ON);
 }
diff --git a/chronos/drivers/include/battery.h b/chronos/drivers/include/battery.h
index c6381b721bd198c86f0788b69b72fc70946bb7f3..e1f1569799c36e6110948f64e9281f26cf1cdc85 100644
--- a/chronos/drivers/include/battery.h
+++ b/chronos/drivers/include/battery.h
@@ -1,5 +1,5 @@
 #ifndef BATTERY_H
-#define BATTERY_H 
+#define BATTERY_H
 
 uint32_t battery_get_voltage(void);
 
diff --git a/chronos/drivers/include/buzzer.h b/chronos/drivers/include/buzzer.h
index 1786b0c513fb889276c2aa8215ebb2f7b7ce4c37..47ccb81112cf720ca29ba1d4ac540819781d18ff 100644
--- a/chronos/drivers/include/buzzer.h
+++ b/chronos/drivers/include/buzzer.h
@@ -1,5 +1,5 @@
 #ifndef BUZZER_H
-#define BUZZER_H 
+#define BUZZER_H
 
 void buzzer_beep(uint8_t pitch, uint16_t duration);
 
diff --git a/chronos/drivers/include/display.h b/chronos/drivers/include/display.h
index 3b7c2e131fc175da1fbde51be1a08506ca64f609..533ce1e1db590d7832920cd673fa3118769fbe06 100644
--- a/chronos/drivers/include/display.h
+++ b/chronos/drivers/include/display.h
@@ -1,35 +1,35 @@
 /* *************************************************************************************************
  *
- *	Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/ 
- *	 
- *	 
- *	  Redistribution and use in source and binary forms, with or without 
- *	  modification, are permitted provided that the following conditions 
- *	  are met:
- *	
- *	    Redistributions of source code must retain the above copyright 
- *	    notice, this list of conditions and the following disclaimer.
- *	 
- *	    Redistributions in binary form must reproduce the above copyright
- *	    notice, this list of conditions and the following disclaimer in the 
- *	    documentation and/or other materials provided with the   
- *	    distribution.
- *	 
- *	    Neither the name of Texas Instruments Incorporated nor the names of
- *	    its contributors may be used to endorse or promote products derived
- *	    from this software without specific prior written permission.
- *	
- *	  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
- *	  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
- *	  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *	  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
- *	  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- *	  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
- *	  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *	  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *	  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
- *	  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
- *	  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *  Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ *
+ *    Redistribution and use in source and binary forms, with or without
+ *    modification, are permitted provided that the following conditions
+ *    are met:
+ *
+ *      Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *      Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the
+ *      distribution.
+ *
+ *      Neither the name of Texas Instruments Incorporated nor the names of
+ *      its contributors may be used to endorse or promote products derived
+ *      from this software without specific prior written permission.
+ *
+ *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * *************************************************************************************************
  * Basic display functions.
@@ -48,254 +48,254 @@
 
 /* Set of display flags */
 typedef union {
-  struct {
-  	/* Line1 + Line2 + Icons*/
-    uint16_t full_update      		: 1;    // 1 = Redraw all content
-    uint16_t partial_update      	: 1;    // 1 = Update changes
-  	
-  	// Line only
-    uint16_t line1_full_update     	: 1;    // 1 = Redraw Line1 content
-    uint16_t line2_full_update     	: 1;    // 1 = Redraw Line2 content
-
-	// Logic module data update flags
-    uint16_t update_time      		: 1;    // 1 = Time was updated 
-    uint16_t update_stopwatch     	: 1;    // 1 = Stopwatch was updated
-    uint16_t update_temperature   	: 1;    // 1 = Temperature was updated
-    uint16_t update_battery_voltage 	: 1;    // 1 = Battery voltage was updated
-    uint16_t update_date      		: 1;    // 1 = Date was updated
-    uint16_t update_alarm      		: 1;    // 1 = Alarm time was updated
-    uint16_t update_acceleration		: 1; 	// 1 = Acceleration data was updated
-  } flag;
-  uint16_t all_flags;            // Shortcut to all display flags (for reset)
+    struct {
+        /* Line1 + Line2 + Icons*/
+        uint16_t full_update            : 1;    /* 1 = Redraw all content */
+        uint16_t partial_update         : 1;    /* 1 = Update changes */
+
+        /* Line only */
+        uint16_t line1_full_update      : 1;    /* 1 = Redraw Line1 content */
+        uint16_t line2_full_update      : 1;    /* 1 = Redraw Line2 content */
+
+        /* Logic module data update flags */
+        uint16_t update_time            : 1;    /* 1 = Time was updated */
+        uint16_t update_stopwatch       : 1;    /* 1 = Stopwatch was updated */
+        uint16_t update_temperature     : 1;    /* 1 = Temperature was updated */
+        uint16_t update_battery_voltage : 1;    /* 1 = Battery voltage was updated */
+        uint16_t update_date            : 1;    /* 1 = Date was updated */
+        uint16_t update_alarm           : 1;    /* 1 = Alarm time was updated */
+        uint16_t update_acceleration    : 1;    /* 1 = Acceleration data was updated */
+    } flag;
+    uint16_t all_flags;            /* Shortcut to all display flags (for reset) */
 } s_display_flags_t;
 
 extern volatile s_display_flags_t display;
 
-// Constants defined in library
+/* Constants defined in library */
 extern const uint8_t lcd_font[];
 extern const uint8_t *segments_lcdmem[];
 extern const uint8_t segments_bitmask[];
 extern const uint8_t itoa_conversion_table[][3];
 
-// *************************************************************************************************
-// Defines section
-
-// Display function modes
-#define DISPLAY_LINE_UPDATE_FULL		(BIT0)
-#define DISPLAY_LINE_UPDATE_PARTIAL		(BIT1)
-#define DISPLAY_LINE_CLEAR				(BIT2)
-
-// Definitions for line view style
-#define DISPLAY_DEFAULT_VIEW			(0u)
-#define DISPLAY_ALTERNATIVE_VIEW		(1u)
-#define DISPLAY_ALTERNATIVE2_VIEW		(2u)
- 
-// Definitions for line access
-#define LINE1							(1u)
-#define LINE2							(2u)
-
-// LCD display modes
-#define SEG_OFF					(0u)
-#define	SEG_ON					(1u)
-#define SEG_ON_BLINK_ON			(2u)
-#define SEG_ON_BLINK_OFF		(3u)
-#define SEG_OFF_BLINK_OFF		(4u)
-
-// 7-segment character bit assignments
-#define SEG_A                	(BIT4)
-#define SEG_B                	(BIT5)
-#define SEG_C                	(BIT6)
-#define SEG_D                	(BIT7)
-#define SEG_E                	(BIT2)
-#define SEG_F                	(BIT0)
-#define SEG_G                	(BIT1)
+/* ************************************************************************************************* */
+/* Defines section */
+
+/* Display function modes */
+#define DISPLAY_LINE_UPDATE_FULL        (BIT0)
+#define DISPLAY_LINE_UPDATE_PARTIAL     (BIT1)
+#define DISPLAY_LINE_CLEAR              (BIT2)
+
+/* Definitions for line view style */
+#define DISPLAY_DEFAULT_VIEW            (0u)
+#define DISPLAY_ALTERNATIVE_VIEW        (1u)
+#define DISPLAY_ALTERNATIVE2_VIEW       (2u)
+
+/* Definitions for line access */
+#define LINE1                           (1u)
+#define LINE2                           (2u)
+
+/* LCD display modes */
+#define SEG_OFF                 (0u)
+#define SEG_ON                  (1u)
+#define SEG_ON_BLINK_ON         (2u)
+#define SEG_ON_BLINK_OFF        (3u)
+#define SEG_OFF_BLINK_OFF       (4u)
+
+/* 7-segment character bit assignments */
+#define SEG_A                   (BIT4)
+#define SEG_B                   (BIT5)
+#define SEG_C                   (BIT6)
+#define SEG_D                   (BIT7)
+#define SEG_E                   (BIT2)
+#define SEG_F                   (BIT0)
+#define SEG_G                   (BIT1)
 
 /* ------------------------------------------
  * LCD symbols for easier access
  *
- * xxx_SEG_xxx 		= Seven-segment character (sequence 5-4-3-2-1-0)
- * xxx_SYMB_xxx 	= Display symbol, e.g. "AM" for ante meridiem 
- * xxx_UNIT_xxx 	= Display unit, e.g. "km/h" for kilometers per hour
- * xxx_ICON_xxx 	= Display icon, e.g. heart to indicate reception of heart rate data
- * xxx_L1_xxx 		= Item is part of Line1 information 
- * xxx_L2_xxx 		= Item is part of Line2 information
+ * xxx_SEG_xxx      = Seven-segment character (sequence 5-4-3-2-1-0)
+ * xxx_SYMB_xxx     = Display symbol, e.g. "AM" for ante meridiem
+ * xxx_UNIT_xxx     = Display unit, e.g. "km/h" for kilometers per hour
+ * xxx_ICON_xxx     = Display icon, e.g. heart to indicate reception of heart rate data
+ * xxx_L1_xxx       = Item is part of Line1 information
+ * xxx_L2_xxx       = Item is part of Line2 information
  */
 
 //* Symbols for Line1 */
-#define LCD_SYMB_AM					0
-#define LCD_SYMB_PM					1
-#define LCD_SYMB_ARROW_UP			2
-#define LCD_SYMB_ARROW_DOWN			3
-#define LCD_SYMB_PERCENT			4
+#define LCD_SYMB_AM                 0
+#define LCD_SYMB_PM                 1
+#define LCD_SYMB_ARROW_UP           2
+#define LCD_SYMB_ARROW_DOWN         3
+#define LCD_SYMB_PERCENT            4
 
 /* Symbols for Line2 */
-#define LCD_SYMB_TOTAL				5
-#define LCD_SYMB_AVERAGE			6
-#define LCD_SYMB_MAX				7
-#define LCD_SYMB_BATTERY			8
+#define LCD_SYMB_TOTAL              5
+#define LCD_SYMB_AVERAGE            6
+#define LCD_SYMB_MAX                7
+#define LCD_SYMB_BATTERY            8
 
 /* Units for Line1 */
-#define LCD_UNIT_L1_FT				9
-#define LCD_UNIT_L1_K				10
-#define LCD_UNIT_L1_M				11
-#define LCD_UNIT_L1_I				12
-#define LCD_UNIT_L1_PER_S			13
-#define LCD_UNIT_L1_PER_H			14
-#define LCD_UNIT_L1_DEGREE			15
+#define LCD_UNIT_L1_FT              9
+#define LCD_UNIT_L1_K               10
+#define LCD_UNIT_L1_M               11
+#define LCD_UNIT_L1_I               12
+#define LCD_UNIT_L1_PER_S           13
+#define LCD_UNIT_L1_PER_H           14
+#define LCD_UNIT_L1_DEGREE          15
 
 /* Units for Line2 */
-#define LCD_UNIT_L2_KCAL			16
-#define LCD_UNIT_L2_KM				17
-#define LCD_UNIT_L2_MI				18
+#define LCD_UNIT_L2_KCAL            16
+#define LCD_UNIT_L2_KM              17
+#define LCD_UNIT_L2_MI              18
 
 /* Icons */
-#define LCD_ICON_HEART				19
-#define LCD_ICON_STOPWATCH			20
-#define LCD_ICON_RECORD				21
-#define LCD_ICON_ALARM				22
-#define LCD_ICON_BEEPER1			23
-#define LCD_ICON_BEEPER2			24
-#define LCD_ICON_BEEPER3			25
+#define LCD_ICON_HEART              19
+#define LCD_ICON_STOPWATCH          20
+#define LCD_ICON_RECORD             21
+#define LCD_ICON_ALARM              22
+#define LCD_ICON_BEEPER1            23
+#define LCD_ICON_BEEPER2            24
+#define LCD_ICON_BEEPER3            25
 
 /* Line1 7-segments */
-#define LCD_SEG_L1_3				26
-#define LCD_SEG_L1_2				27
-#define LCD_SEG_L1_1				28
-#define LCD_SEG_L1_0				29
-#define LCD_SEG_L1_COL				30
-#define LCD_SEG_L1_DP1				31
-#define LCD_SEG_L1_DP0				32
+#define LCD_SEG_L1_3                26
+#define LCD_SEG_L1_2                27
+#define LCD_SEG_L1_1                28
+#define LCD_SEG_L1_0                29
+#define LCD_SEG_L1_COL              30
+#define LCD_SEG_L1_DP1              31
+#define LCD_SEG_L1_DP0              32
 
 /* Line2 7-segments */
-#define LCD_SEG_L2_5				33
-#define LCD_SEG_L2_4				34
-#define LCD_SEG_L2_3				35
-#define LCD_SEG_L2_2				36
-#define LCD_SEG_L2_1				37
-#define LCD_SEG_L2_0				38
-#define LCD_SEG_L2_COL1				39
-#define LCD_SEG_L2_COL0				40
-#define LCD_SEG_L2_DP				41
+#define LCD_SEG_L2_5                33
+#define LCD_SEG_L2_4                34
+#define LCD_SEG_L2_3                35
+#define LCD_SEG_L2_2                36
+#define LCD_SEG_L2_1                37
+#define LCD_SEG_L2_0                38
+#define LCD_SEG_L2_COL1             39
+#define LCD_SEG_L2_COL0             40
+#define LCD_SEG_L2_DP               41
 
 /* Line1 7-segment arrays */
-#define LCD_SEG_L1_3_0				70
-#define LCD_SEG_L1_2_0				71
-#define LCD_SEG_L1_1_0				72
-#define LCD_SEG_L1_3_1				73
-#define LCD_SEG_L1_3_2				74
+#define LCD_SEG_L1_3_0              70
+#define LCD_SEG_L1_2_0              71
+#define LCD_SEG_L1_1_0              72
+#define LCD_SEG_L1_3_1              73
+#define LCD_SEG_L1_3_2              74
 
 /* Line2 7-segment arrays */
-#define LCD_SEG_L2_5_0				90
-#define LCD_SEG_L2_4_0				91
-#define LCD_SEG_L2_3_0				92
-#define LCD_SEG_L2_2_0				93
-#define LCD_SEG_L2_1_0				94
-#define LCD_SEG_L2_5_2				95
-#define LCD_SEG_L2_3_2				96
-#define LCD_SEG_L2_5_4				97
-#define LCD_SEG_L2_4_2				98
+#define LCD_SEG_L2_5_0              90
+#define LCD_SEG_L2_4_0              91
+#define LCD_SEG_L2_3_0              92
+#define LCD_SEG_L2_2_0              93
+#define LCD_SEG_L2_1_0              94
+#define LCD_SEG_L2_5_2              95
+#define LCD_SEG_L2_3_2              96
+#define LCD_SEG_L2_5_4              97
+#define LCD_SEG_L2_4_2              98
 
 /* LCD controller memory map */
-#define LCD_MEM_1          			((uint8_t*)0x0A20)
-#define LCD_MEM_2          			((uint8_t*)0x0A21)
-#define LCD_MEM_3          			((uint8_t*)0x0A22)
-#define LCD_MEM_4          			((uint8_t*)0x0A23)
-#define LCD_MEM_5          			((uint8_t*)0x0A24)
-#define LCD_MEM_6          			((uint8_t*)0x0A25)
-#define LCD_MEM_7          			((uint8_t*)0x0A26)
-#define LCD_MEM_8          	 		((uint8_t*)0x0A27)
-#define LCD_MEM_9          			((uint8_t*)0x0A28)
-#define LCD_MEM_10         			((uint8_t*)0x0A29)
-#define LCD_MEM_11         			((uint8_t*)0x0A2A)
-#define LCD_MEM_12         			((uint8_t*)0x0A2B)
+#define LCD_MEM_1                   ((uint8_t*)0x0A20)
+#define LCD_MEM_2                   ((uint8_t*)0x0A21)
+#define LCD_MEM_3                   ((uint8_t*)0x0A22)
+#define LCD_MEM_4                   ((uint8_t*)0x0A23)
+#define LCD_MEM_5                   ((uint8_t*)0x0A24)
+#define LCD_MEM_6                   ((uint8_t*)0x0A25)
+#define LCD_MEM_7                   ((uint8_t*)0x0A26)
+#define LCD_MEM_8                   ((uint8_t*)0x0A27)
+#define LCD_MEM_9                   ((uint8_t*)0x0A28)
+#define LCD_MEM_10                  ((uint8_t*)0x0A29)
+#define LCD_MEM_11                  ((uint8_t*)0x0A2A)
+#define LCD_MEM_12                  ((uint8_t*)0x0A2B)
 
 /* Memory assignment */
-#define LCD_SEG_L1_0_MEM			(LCD_MEM_6)
-#define LCD_SEG_L1_1_MEM			(LCD_MEM_4)
-#define LCD_SEG_L1_2_MEM			(LCD_MEM_3)
-#define LCD_SEG_L1_3_MEM			(LCD_MEM_2)
-#define LCD_SEG_L1_COL_MEM			(LCD_MEM_1)
-#define LCD_SEG_L1_DP1_MEM			(LCD_MEM_1)
-#define LCD_SEG_L1_DP0_MEM			(LCD_MEM_5)
-#define LCD_SEG_L2_0_MEM			(LCD_MEM_8)
-#define LCD_SEG_L2_1_MEM			(LCD_MEM_9)
-#define LCD_SEG_L2_2_MEM			(LCD_MEM_10)
-#define LCD_SEG_L2_3_MEM			(LCD_MEM_11)
-#define LCD_SEG_L2_4_MEM			(LCD_MEM_12)
-#define LCD_SEG_L2_5_MEM			(LCD_MEM_12)
-#define LCD_SEG_L2_COL1_MEM			(LCD_MEM_1)
-#define LCD_SEG_L2_COL0_MEM			(LCD_MEM_5)
-#define LCD_SEG_L2_DP_MEM			(LCD_MEM_9)
-#define LCD_SYMB_AM_MEM				(LCD_MEM_1)
-#define LCD_SYMB_PM_MEM				(LCD_MEM_1)
-#define LCD_SYMB_ARROW_UP_MEM		(LCD_MEM_1)
-#define LCD_SYMB_ARROW_DOWN_MEM		(LCD_MEM_1)
-#define LCD_SYMB_PERCENT_MEM		(LCD_MEM_5)
-#define LCD_SYMB_TOTAL_MEM			(LCD_MEM_11)
-#define LCD_SYMB_AVERAGE_MEM		(LCD_MEM_10)
-#define LCD_SYMB_MAX_MEM			(LCD_MEM_8)
-#define LCD_SYMB_BATTERY_MEM		(LCD_MEM_7)
-#define LCD_UNIT_L1_FT_MEM			(LCD_MEM_5)
-#define LCD_UNIT_L1_K_MEM			(LCD_MEM_5)
-#define LCD_UNIT_L1_M_MEM			(LCD_MEM_7)
-#define LCD_UNIT_L1_I_MEM			(LCD_MEM_7)
-#define LCD_UNIT_L1_PER_S_MEM		(LCD_MEM_5)
-#define LCD_UNIT_L1_PER_H_MEM		(LCD_MEM_7)
-#define LCD_UNIT_L1_DEGREE_MEM		(LCD_MEM_5)
-#define LCD_UNIT_L2_KCAL_MEM		(LCD_MEM_7)
-#define LCD_UNIT_L2_KM_MEM			(LCD_MEM_7)
-#define LCD_UNIT_L2_MI_MEM			(LCD_MEM_7)
-#define LCD_ICON_HEART_MEM			(LCD_MEM_2)
-#define LCD_ICON_STOPWATCH_MEM		(LCD_MEM_3)
-#define LCD_ICON_RECORD_MEM			(LCD_MEM_1)
-#define LCD_ICON_ALARM_MEM			(LCD_MEM_4)
-#define LCD_ICON_BEEPER1_MEM		(LCD_MEM_5)
-#define LCD_ICON_BEEPER2_MEM		(LCD_MEM_6)
-#define LCD_ICON_BEEPER3_MEM		(LCD_MEM_7)
+#define LCD_SEG_L1_0_MEM            (LCD_MEM_6)
+#define LCD_SEG_L1_1_MEM            (LCD_MEM_4)
+#define LCD_SEG_L1_2_MEM            (LCD_MEM_3)
+#define LCD_SEG_L1_3_MEM            (LCD_MEM_2)
+#define LCD_SEG_L1_COL_MEM          (LCD_MEM_1)
+#define LCD_SEG_L1_DP1_MEM          (LCD_MEM_1)
+#define LCD_SEG_L1_DP0_MEM          (LCD_MEM_5)
+#define LCD_SEG_L2_0_MEM            (LCD_MEM_8)
+#define LCD_SEG_L2_1_MEM            (LCD_MEM_9)
+#define LCD_SEG_L2_2_MEM            (LCD_MEM_10)
+#define LCD_SEG_L2_3_MEM            (LCD_MEM_11)
+#define LCD_SEG_L2_4_MEM            (LCD_MEM_12)
+#define LCD_SEG_L2_5_MEM            (LCD_MEM_12)
+#define LCD_SEG_L2_COL1_MEM         (LCD_MEM_1)
+#define LCD_SEG_L2_COL0_MEM         (LCD_MEM_5)
+#define LCD_SEG_L2_DP_MEM           (LCD_MEM_9)
+#define LCD_SYMB_AM_MEM             (LCD_MEM_1)
+#define LCD_SYMB_PM_MEM             (LCD_MEM_1)
+#define LCD_SYMB_ARROW_UP_MEM       (LCD_MEM_1)
+#define LCD_SYMB_ARROW_DOWN_MEM     (LCD_MEM_1)
+#define LCD_SYMB_PERCENT_MEM        (LCD_MEM_5)
+#define LCD_SYMB_TOTAL_MEM          (LCD_MEM_11)
+#define LCD_SYMB_AVERAGE_MEM        (LCD_MEM_10)
+#define LCD_SYMB_MAX_MEM            (LCD_MEM_8)
+#define LCD_SYMB_BATTERY_MEM        (LCD_MEM_7)
+#define LCD_UNIT_L1_FT_MEM          (LCD_MEM_5)
+#define LCD_UNIT_L1_K_MEM           (LCD_MEM_5)
+#define LCD_UNIT_L1_M_MEM           (LCD_MEM_7)
+#define LCD_UNIT_L1_I_MEM           (LCD_MEM_7)
+#define LCD_UNIT_L1_PER_S_MEM       (LCD_MEM_5)
+#define LCD_UNIT_L1_PER_H_MEM       (LCD_MEM_7)
+#define LCD_UNIT_L1_DEGREE_MEM      (LCD_MEM_5)
+#define LCD_UNIT_L2_KCAL_MEM        (LCD_MEM_7)
+#define LCD_UNIT_L2_KM_MEM          (LCD_MEM_7)
+#define LCD_UNIT_L2_MI_MEM          (LCD_MEM_7)
+#define LCD_ICON_HEART_MEM          (LCD_MEM_2)
+#define LCD_ICON_STOPWATCH_MEM      (LCD_MEM_3)
+#define LCD_ICON_RECORD_MEM         (LCD_MEM_1)
+#define LCD_ICON_ALARM_MEM          (LCD_MEM_4)
+#define LCD_ICON_BEEPER1_MEM        (LCD_MEM_5)
+#define LCD_ICON_BEEPER2_MEM        (LCD_MEM_6)
+#define LCD_ICON_BEEPER3_MEM        (LCD_MEM_7)
 
 /* Bit masks for write access */
-#define LCD_SEG_L1_0_MASK			(BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
-#define LCD_SEG_L1_1_MASK			(BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
-#define LCD_SEG_L1_2_MASK			(BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
-#define LCD_SEG_L1_3_MASK			(BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
-#define LCD_SEG_L1_COL_MASK			(BIT5)
-#define LCD_SEG_L1_DP1_MASK			(BIT6)
-#define LCD_SEG_L1_DP0_MASK			(BIT2)
-#define LCD_SEG_L2_0_MASK			(BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
-#define LCD_SEG_L2_1_MASK			(BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
-#define LCD_SEG_L2_2_MASK			(BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
-#define LCD_SEG_L2_3_MASK			(BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
-#define LCD_SEG_L2_4_MASK			(BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
-#define LCD_SEG_L2_5_MASK			(BIT7)
-#define LCD_SEG_L2_COL1_MASK		(BIT4)
-#define LCD_SEG_L2_COL0_MASK		(BIT0)
-#define LCD_SEG_L2_DP_MASK			(BIT7)
-#define LCD_SYMB_AM_MASK			(BIT1+BIT0)
-#define LCD_SYMB_PM_MASK			(BIT0)
-#define LCD_SYMB_ARROW_UP_MASK		(BIT2)
-#define LCD_SYMB_ARROW_DOWN_MASK	(BIT3)
-#define LCD_SYMB_PERCENT_MASK		(BIT4)
-#define LCD_SYMB_TOTAL_MASK			(BIT7)
-#define LCD_SYMB_AVERAGE_MASK		(BIT7)
-#define LCD_SYMB_MAX_MASK			(BIT7)
-#define LCD_SYMB_BATTERY_MASK		(BIT7)
-#define LCD_UNIT_L1_FT_MASK			(BIT5)
-#define LCD_UNIT_L1_K_MASK			(BIT6)
-#define LCD_UNIT_L1_M_MASK			(BIT1)
-#define LCD_UNIT_L1_I_MASK			(BIT0)
-#define LCD_UNIT_L1_PER_S_MASK		(BIT7)
-#define LCD_UNIT_L1_PER_H_MASK		(BIT2)
-#define LCD_UNIT_L1_DEGREE_MASK		(BIT1)
-#define LCD_UNIT_L2_KCAL_MASK		(BIT4)
-#define LCD_UNIT_L2_KM_MASK			(BIT5)
-#define LCD_UNIT_L2_MI_MASK			(BIT6)
-#define LCD_ICON_HEART_MASK			(BIT3)
-#define LCD_ICON_STOPWATCH_MASK		(BIT3)
-#define LCD_ICON_RECORD_MASK		(BIT7)
-#define LCD_ICON_ALARM_MASK			(BIT3)
-#define LCD_ICON_BEEPER1_MASK		(BIT3)
-#define LCD_ICON_BEEPER2_MASK		(BIT3)
-#define LCD_ICON_BEEPER3_MASK		(BIT3)
+#define LCD_SEG_L1_0_MASK           (BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
+#define LCD_SEG_L1_1_MASK           (BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
+#define LCD_SEG_L1_2_MASK           (BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
+#define LCD_SEG_L1_3_MASK           (BIT2+BIT1+BIT0+BIT7+BIT6+BIT5+BIT4)
+#define LCD_SEG_L1_COL_MASK         (BIT5)
+#define LCD_SEG_L1_DP1_MASK         (BIT6)
+#define LCD_SEG_L1_DP0_MASK         (BIT2)
+#define LCD_SEG_L2_0_MASK           (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
+#define LCD_SEG_L2_1_MASK           (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
+#define LCD_SEG_L2_2_MASK           (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
+#define LCD_SEG_L2_3_MASK           (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
+#define LCD_SEG_L2_4_MASK           (BIT3+BIT2+BIT1+BIT0+BIT6+BIT5+BIT4)
+#define LCD_SEG_L2_5_MASK           (BIT7)
+#define LCD_SEG_L2_COL1_MASK        (BIT4)
+#define LCD_SEG_L2_COL0_MASK        (BIT0)
+#define LCD_SEG_L2_DP_MASK          (BIT7)
+#define LCD_SYMB_AM_MASK            (BIT1+BIT0)
+#define LCD_SYMB_PM_MASK            (BIT0)
+#define LCD_SYMB_ARROW_UP_MASK      (BIT2)
+#define LCD_SYMB_ARROW_DOWN_MASK    (BIT3)
+#define LCD_SYMB_PERCENT_MASK       (BIT4)
+#define LCD_SYMB_TOTAL_MASK         (BIT7)
+#define LCD_SYMB_AVERAGE_MASK       (BIT7)
+#define LCD_SYMB_MAX_MASK           (BIT7)
+#define LCD_SYMB_BATTERY_MASK       (BIT7)
+#define LCD_UNIT_L1_FT_MASK         (BIT5)
+#define LCD_UNIT_L1_K_MASK          (BIT6)
+#define LCD_UNIT_L1_M_MASK          (BIT1)
+#define LCD_UNIT_L1_I_MASK          (BIT0)
+#define LCD_UNIT_L1_PER_S_MASK      (BIT7)
+#define LCD_UNIT_L1_PER_H_MASK      (BIT2)
+#define LCD_UNIT_L1_DEGREE_MASK     (BIT1)
+#define LCD_UNIT_L2_KCAL_MASK       (BIT4)
+#define LCD_UNIT_L2_KM_MASK         (BIT5)
+#define LCD_UNIT_L2_MI_MASK         (BIT6)
+#define LCD_ICON_HEART_MASK         (BIT3)
+#define LCD_ICON_STOPWATCH_MASK     (BIT3)
+#define LCD_ICON_RECORD_MASK        (BIT7)
+#define LCD_ICON_ALARM_MASK         (BIT3)
+#define LCD_ICON_BEEPER1_MASK       (BIT3)
+#define LCD_ICON_BEEPER2_MASK       (BIT3)
+#define LCD_ICON_BEEPER3_MASK       (BIT3)
 
 
 /* *************************************************************************************************
@@ -306,11 +306,11 @@ extern const uint8_t itoa_conversion_table[][3];
 /* *************************************************************************************************
  * @fn          write_segment
  * @brief       Write to one or multiple LCD segments
- * @param       lcdmem		Pointer to LCD byte memory
- *				bits		Segments to address
- *				bitmask		Bitmask for particular display item
- *				mode		On, off or blink segments
- * @return      
+ * @param       lcdmem      Pointer to LCD byte memory
+ *              bits        Segments to address
+ *              bitmask     Bitmask for particular display item
+ *              mode        On, off or blink segments
+ * @return
  * ************************************************************************************************/
 void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state);
 
@@ -318,7 +318,7 @@ void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state
 /* *************************************************************************************************
  * @fn          lcd_init
  * @brief       Erase LCD memory. Init LCD peripheral.
- * @param      	none
+ * @param       none
  * @return      none
  * ************************************************************************************************/
 void lcd_init(void);
@@ -326,7 +326,7 @@ void lcd_init(void);
 /* *************************************************************************************************
  * @fn          clear_display
  * @brief       Erase LINE1 and LINE2 segments. Keep icons.
- * @param      	none
+ * @param       none
  * @return      none
  * ************************************************************************************************/
 void clear_display(void);
@@ -334,7 +334,7 @@ void clear_display(void);
 /* *************************************************************************************************
  * @fn          clear_display_all
  * @brief       Erase LINE1 and LINE2 segments. Clear also function-specific content.
- * @param      	none
+ * @param       none
  * @return      none
  * ************************************************************************************************/
 void clear_display_all(void);
@@ -342,7 +342,7 @@ void clear_display_all(void);
 /* *************************************************************************************************
  * @fn          clear_line
  * @brief       Erase segments of a given line.
- * @param      	uint8_t line	LINE1, LINE2
+ * @param       uint8_t line    LINE1, LINE2
  * @return      none
  * ************************************************************************************************/
 void clear_line(uint8_t line);
@@ -350,7 +350,7 @@ void clear_line(uint8_t line);
 /* Blinking function */
 /* *************************************************************************************************
  * @fn          start_blink
- * @brief       Start blinking. 
+ * @brief       Start blinking.
  * @param       none
  * @return      none
  * ************************************************************************************************/
@@ -374,7 +374,7 @@ void clear_blink_mem(void);
 
 /* *************************************************************************************************
  * @fn          set_blink_rate
- * @brief       Set blink rate register bits. 
+ * @brief       Set blink rate register bits.
  * @param       none
  * @return      none
  * ************************************************************************************************/
@@ -384,9 +384,9 @@ void set_blink_rate(uint8_t bits);
 /* *************************************************************************************************
  * @fn          display_char
  * @brief       Write to 7-segment characters.
- * @param       uint8_t segment		A valid LCD segment 
- *				uint8_t chr			Character to display
- *				uint8_t mode		SEG_ON, SEG_OFF, SEG_BLINK
+ * @param       uint8_t segment     A valid LCD segment
+ *              uint8_t chr         Character to display
+ *              uint8_t mode        SEG_ON, SEG_OFF, SEG_BLINK
  * @return      none
  * ************************************************************************************************/
 void display_char(uint8_t segment, char chr, uint8_t mode);
@@ -394,9 +394,9 @@ void display_char(uint8_t segment, char chr, uint8_t mode);
 /* *************************************************************************************************
  * @FN          display_chars
  * @brief       Write to consecutive 7-segment characters.
- * @param       uint8_t segments	LCD segment array 
- *				uint8_t * str		Pointer to a string
- *				uint8_t mode		SEG_ON, SEG_OFF, SEG_BLINK
+ * @param       uint8_t segments    LCD segment array
+ *              uint8_t * str       Pointer to a string
+ *              uint8_t mode        SEG_ON, SEG_OFF, SEG_BLINK
  * @return      none
  * ************************************************************************************************/
 void display_chars(uint8_t segments, char *str, uint8_t mode);
@@ -404,8 +404,8 @@ void display_chars(uint8_t segments, char *str, uint8_t mode);
 /* *************************************************************************************************
  * @fn          display_symbol
  * @brief       Switch symbol on or off on LCD.
- * @param       uint8_t symbol		A valid LCD symbol (index 0..42)
- *				uint8_t state		SEG_ON, SEG_OFF, SEG_BLINK
+ * @param       uint8_t symbol      A valid LCD symbol (index 0..42)
+ *              uint8_t state       SEG_ON, SEG_OFF, SEG_BLINK
  * @return      none
  * ************************************************************************************************/
 void display_symbol(uint8_t symbol, uint8_t mode);
@@ -414,10 +414,10 @@ void display_symbol(uint8_t symbol, uint8_t mode);
 /* *************************************************************************************************
  * @fn          display_value1
  * @brief       Generic decimal display routine. Used exclusively by set_value function.
- * @param       uint8_t segments		LCD segments where value is displayed
- *				uint32_t value			Integer value to be displayed
- *				uint8_t digits			Number of digits to convert
- *				uint8_t blanks			Number of leadings blanks in itoa result string
+ * @param       uint8_t segments        LCD segments where value is displayed
+ *              uint32_t value          Integer value to be displayed
+ *              uint8_t digits          Number of digits to convert
+ *              uint8_t blanks          Number of leadings blanks in itoa result string
  * @return      none
  * ************************************************************************************************/
 void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode);
@@ -426,23 +426,23 @@ void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t bl
 /* *************************************************************************************************
  * @fn          itoa
  * @brief       Generic integer to array routine. Converts integer n to string.
- *				Default conversion result has leading zeros, e.g. "00123"
- *				Option to convert leading '0' into whitespace (blanks)
- * @param       uint32_t n			integer to convert
- *				uint8_t digits		number of digits
- *				uint8_t blanks		fill up result string with number of whitespaces instead of leading zeros  
- * @return      uint8_t				string
+ *              Default conversion result has leading zeros, e.g. "00123"
+ *              Option to convert leading '0' into whitespace (blanks)
+ * @param       uint32_t n          integer to convert
+ *              uint8_t digits      number of digits
+ *              uint8_t blanks      fill up result string with number of whitespaces instead of leading zeros
+ * @return      uint8_t             string
  * ************************************************************************************************/
 char *itoa(uint32_t n, uint8_t digits, uint8_t blanks);
 
 /* Segment index helper function */
 /* *************************************************************************************************
  * @fn          switch_seg
- * @brief       Returns index of 7-segment character. Required for display routines that can draw 
- *				information on both lines.
- * @param       uint8_t line		LINE1, LINE2
- *				uint8_t index1		Index of LINE1
- *				uint8_t index2		Index of LINE2
+ * @brief       Returns index of 7-segment character. Required for display routines that can draw
+ *              information on both lines.
+ * @param       uint8_t line        LINE1, LINE2
+ *              uint8_t index1      Index of LINE1
+ *              uint8_t index2      Index of LINE2
  * @return      uint8
  * ************************************************************************************************/
 uint8_t switch_seg(uint8_t line, uint8_t index1, uint8_t index2);
diff --git a/chronos/drivers/include/display_putchar.h b/chronos/drivers/include/display_putchar.h
index 504ece6ebdc7eb65b74707324b5129cf04cb326f..b903fc1db98c4705bdddcb104517c12b9fa0360a 100644
--- a/chronos/drivers/include/display_putchar.h
+++ b/chronos/drivers/include/display_putchar.h
@@ -1,5 +1,5 @@
 #ifndef __DISPLAY_PUTCHAR_H
-#define __DISPLAY_PUTCHAR_H 
+#define __DISPLAY_PUTCHAR_H
 
 void init_display_putchar(void);
 
diff --git a/chronos/putchar.c b/chronos/putchar.c
index 436d350f51dc1fb4c5945cd136c4415ff4d4d6e3..cefcb3281b806ac2cc1034724bae5553b285f277 100644
--- a/chronos/putchar.c
+++ b/chronos/putchar.c
@@ -1,4 +1,5 @@
-static void _dummy(int c) {
+static void _dummy(int c)
+{
 }
 
 void (*_putchar)(int c) = _dummy;
diff --git a/msb-430-common/board_config.c b/msb-430-common/board_config.c
index f22e513b20b8aa74d748a4d488168bc44165ff36..14b8d00e31a4d3763767ef7be9eb1865df9045ea 100644
--- a/msb-430-common/board_config.c
+++ b/msb-430-common/board_config.c
@@ -4,16 +4,18 @@
 #include <config.h>
 #include <flashrom.h>
 
-void config_load(void) {
-   if (*((uint16_t*) INFOMEM) ==  CONFIG_KEY) {
-       memcpy(&sysconfig, (char*) (INFOMEM + sizeof(CONFIG_KEY)), sizeof(sysconfig));
-   }
-   else {
-       config_save();
-   }
+void config_load(void)
+{
+    if (*((uint16_t *) INFOMEM) ==  CONFIG_KEY) {
+        memcpy(&sysconfig, (char *)(INFOMEM + sizeof(CONFIG_KEY)), sizeof(sysconfig));
+    }
+    else {
+        config_save();
+    }
 }
 
-uint8_t config_save(void) {
+uint8_t config_save(void)
+{
     configmem_t mem = { CONFIG_KEY, sysconfig  };
-    return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem)));
+    return (flashrom_erase((uint8_t *) INFOMEM) && flashrom_write((uint8_t *) INFOMEM, (char *) &mem, sizeof(mem)));
 }
diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c
index 56af75498d14e5d76b7507dbfa1bf710bbe62b8a..de2e5c01dc1f4eb6fde17be0a08681f1c0360dd0 100644
--- a/msb-430-common/board_init.c
+++ b/msb-430-common/board_init.c
@@ -7,201 +7,218 @@
 static volatile uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED;
 
 /*---------------------------------------------------------------------------*/
-static uint8_t calc_umctl(uint16_t br) {
-	// from TI slaa049
-	register uint8_t CMOD = 256 * br - 256 * (br + 1) / 2;
-	register uint8_t c = 0;
-	register int i = 0;
-	register uint8_t a = CMOD;
-	a <<= 1;
-	do {
-		if( a & 0x80 ) {		// Overflow to integer?
-			a = a - 128 + CMOD;	// Yes, subtract 1.000000
-			c |= 0x80;
-		} else {
-			a += CMOD;			// No, add fraction
-		}
-		if( i == 7 )
-			return c;
-		i++;
-		c >>= 1;
-	} while(1);
+static uint8_t calc_umctl(uint16_t br)
+{
+    // from TI slaa049
+    register uint8_t CMOD = 256 * br - 256 * (br + 1) / 2;
+    register uint8_t c = 0;
+    register int i = 0;
+    register uint8_t a = CMOD;
+    a <<= 1;
+
+    do {
+        if (a & 0x80) {		// Overflow to integer?
+            a = a - 128 + CMOD;	// Yes, subtract 1.000000
+            c |= 0x80;
+        }
+        else {
+            a += CMOD;			// No, add fraction
+        }
+
+        if (i == 7) {
+            return c;
+        }
+
+        i++;
+        c >>= 1;
+    }
+    while (1);
 }
 
 static void msb_ports_init(void)
 {
-	// Port 1: Free port, for energy saving all outputs are set to zero.
+    // Port 1: Free port, for energy saving all outputs are set to zero.
     P1SEL = 0x00;	// Port1 Zweitfunktion
     P1OUT = 0x00;	// Port1 Ausgangsregister: 00000000 = 0x00
     P1DIR = 0xFF;	// Port1 Direction: 11111111 = 0xFF
 
-	P2SEL = 0x20;	// Port2 Zweitfunktion
-	P2OUT = 0x00;	// Port2 Ausgangsregister: 00000000 = 0x00
-	P2DIR = 0x1C;	// Port2 Direction: 00011010 = 0x1C
-					//   0 - P2.0 [IN ] -
-					//   0 - P2.1 [OUT] -
-					//   1 - P2.2 [IN ] -
-					//   1 - P2.3 [OUT] -
-					//   1 - P2.4 [OUT] -
-					//   0 - P2.5 [IN ] -
-					//   0 - P2.6 [IN ] - SD-KARTE Protect
-					//   0 - P2.7 [IN ] - SD-KARTE Detect
-
-	P3SEL = 0xC0;	// Port3 Zweitfunktion
-	P3OUT = 0x09;	// Port3 Ausgangsregister: 00001001 = 0x09
-	P3DIR = 0x2B;	// Port3 Direction
-					//   1 - P3.0
-					//   1 - P3.1
-					//   0 - P3.2
-					//   1 - P3.3
-					//   0 - P3.4 [IN ] - SHT 11 DATA (OUT/IN)
-					//   1 - P3.5 [OUT] - SHT 11 CLK
-					//   0 - P3.6 [2-Funktion] - RS232_RxD
-					//   0 - P3.7 [2-Funktion] - RS232_TxD
-
-	// Port 4: Free port, for energy saving all outputs are set to zero.
-	P4SEL = 0x00;	// Port4 Zweitfunktion
-	P4OUT = 0x00;	// Port4 Ausgangsregister: 00000000 = 0x00
-	P4DIR = 0xFF;	// Port4 Direction: 11111111 = 0xFF
-					//   1 - P4.0 [OUT] - unused
-					//   1 - P4.1 [OUT] - unused
-					//   1 - P4.2 [OUT] - unused
-					//   1 - P4.3 [OUT] - unused
-					//   1 - P4.4 [OUT] - unused
-					//   1 - P4.5 [OUT] - unused
-					//   1 - P4.6 [OUT] - unused
-					//   1 - P4.7 [OUT] - unused
-
-	P5SEL = 0x00;	// Port5 Zweitfunktion: 00000000 = 0x00
-	P5OUT = 0x80;	// Port5 Ausgangsregister: 00001001 = 0x09
-	P5DIR = 0xFF;	// Port5 Direction: 11111011 = 0xFB
-					//   1 - P5.0 [OUT] - SD-KARTE /CS
-					//   1 - P5.1 [OUT] - SD-KARTE DI
-					//   0 - P5.2 [IN ] - SD-KARTE DO
-					//   1 - P5.3 [OUT] - SD-KARTE DCLK
-					//   1 - P5.4 [OUT] - MMA GS1
-					//   1 - P5.5 [OUT] - MMA GS2
-					//   1 - P5.6 [OUT] - MMA /SLEEP
-					//   1 - P5.7 [OUT] - LED_ROT 0-an, 1-aus
-
-	P6SEL = 0x00;	// Port6 Zweitfunktion = 0x07
-	P6OUT = 0x00;	// Port6 Ausgangsregister: 00000000 = 0x00
-	P6DIR = 0xFF;	// Port6 Direction: 11111000 = 0xF8
-					//   0 - P6.0 [AD-IN] - MMA X-Achse
-					//   0 - P6.1 [AD-IN] - MMA Y-Achse
-					//   0 - P6.2 [AD-IN] - MMA Z-Achse
-					//   1 - P6.3 [OUT] - unused
-					//   1 - P6.4 [OUT] - unused
-					//   1 - P6.5 [OUT] - unused
-					//   1 - P6.6 [OUT] - unused
-					//   1 - P6.7 [OUT] - unused
+    P2SEL = 0x20;	// Port2 Zweitfunktion
+    P2OUT = 0x00;	// Port2 Ausgangsregister: 00000000 = 0x00
+    P2DIR = 0x1C;	// Port2 Direction: 00011010 = 0x1C
+    //   0 - P2.0 [IN ] -
+    //   0 - P2.1 [OUT] -
+    //   1 - P2.2 [IN ] -
+    //   1 - P2.3 [OUT] -
+    //   1 - P2.4 [OUT] -
+    //   0 - P2.5 [IN ] -
+    //   0 - P2.6 [IN ] - SD-KARTE Protect
+    //   0 - P2.7 [IN ] - SD-KARTE Detect
+
+    P3SEL = 0xC0;	// Port3 Zweitfunktion
+    P3OUT = 0x09;	// Port3 Ausgangsregister: 00001001 = 0x09
+    P3DIR = 0x2B;	// Port3 Direction
+    //   1 - P3.0
+    //   1 - P3.1
+    //   0 - P3.2
+    //   1 - P3.3
+    //   0 - P3.4 [IN ] - SHT 11 DATA (OUT/IN)
+    //   1 - P3.5 [OUT] - SHT 11 CLK
+    //   0 - P3.6 [2-Funktion] - RS232_RxD
+    //   0 - P3.7 [2-Funktion] - RS232_TxD
+
+    // Port 4: Free port, for energy saving all outputs are set to zero.
+    P4SEL = 0x00;	// Port4 Zweitfunktion
+    P4OUT = 0x00;	// Port4 Ausgangsregister: 00000000 = 0x00
+    P4DIR = 0xFF;	// Port4 Direction: 11111111 = 0xFF
+    //   1 - P4.0 [OUT] - unused
+    //   1 - P4.1 [OUT] - unused
+    //   1 - P4.2 [OUT] - unused
+    //   1 - P4.3 [OUT] - unused
+    //   1 - P4.4 [OUT] - unused
+    //   1 - P4.5 [OUT] - unused
+    //   1 - P4.6 [OUT] - unused
+    //   1 - P4.7 [OUT] - unused
+
+    P5SEL = 0x00;	// Port5 Zweitfunktion: 00000000 = 0x00
+    P5OUT = 0x80;	// Port5 Ausgangsregister: 00001001 = 0x09
+    P5DIR = 0xFF;	// Port5 Direction: 11111011 = 0xFB
+    //   1 - P5.0 [OUT] - SD-KARTE /CS
+    //   1 - P5.1 [OUT] - SD-KARTE DI
+    //   0 - P5.2 [IN ] - SD-KARTE DO
+    //   1 - P5.3 [OUT] - SD-KARTE DCLK
+    //   1 - P5.4 [OUT] - MMA GS1
+    //   1 - P5.5 [OUT] - MMA GS2
+    //   1 - P5.6 [OUT] - MMA /SLEEP
+    //   1 - P5.7 [OUT] - LED_ROT 0-an, 1-aus
+
+    P6SEL = 0x00;	// Port6 Zweitfunktion = 0x07
+    P6OUT = 0x00;	// Port6 Ausgangsregister: 00000000 = 0x00
+    P6DIR = 0xFF;	// Port6 Direction: 11111000 = 0xF8
+    //   0 - P6.0 [AD-IN] - MMA X-Achse
+    //   0 - P6.1 [AD-IN] - MMA Y-Achse
+    //   0 - P6.2 [AD-IN] - MMA Z-Achse
+    //   1 - P6.3 [OUT] - unused
+    //   1 - P6.4 [OUT] - unused
+    //   1 - P6.5 [OUT] - unused
+    //   1 - P6.6 [OUT] - unused
+    //   1 - P6.7 [OUT] - unused
 }
 
 void msp430_set_cpu_speed(uint32_t speed)
 {
-	dint();
-	__msp430_cpu_speed = speed;
-	msp430_init_dco();
-	uint16_t br;
+    dint();
+    __msp430_cpu_speed = speed;
+    msp430_init_dco();
+    uint16_t br;
     UCTL1 = SWRST | CHAR;		// 8-bit character
     UTCTL1 |= SSEL1 | URXSE;	// UCLK = MCLK
     // activate
     U1ME |= UTXE1 | URXE1;		// Enable USART1 TXD/RXD
-	br = (uint16_t)(__msp430_cpu_speed / 115200uL);
-	UBR01  = br;				// set baudrate
-	UBR11  = br>>8;
-	UMCTL1 = calc_umctl(br);	// set modulation
-
-	UCTL1 &= ~SWRST;
-	//clock_init();
-	eint();
+    br = (uint16_t)(__msp430_cpu_speed / 115200uL);
+    UBR01  = br;				// set baudrate
+    UBR11  = br >> 8;
+    UMCTL1 = calc_umctl(br);	// set modulation
+
+    UCTL1 &= ~SWRST;
+    //clock_init();
+    eint();
 }
 
 /*---------------------------------------------------------------------------*/
 void
 msp430_init_dco()
 {
-  #if MSP430_HAS_EXTERNAL_CRYSTAL
-  /*------------------ use external oszillator -----------------------*/
-  uint16_t i;
-
-  // Stop watchdog
-  WDTCTL = WDTPW + WDTHOLD;
-
-  //Init crystal for mclk
-  //XT2 = HF XTAL
-  BCSCTL1 = RSEL2;
-
-  // Wait for xtal to stabilize
-  do {
-	IFG1 &= ~OFIFG;				// Clear oscillator fault flag
-	for (i = 0xFF; i > 0; i--); // Time for flag to set
-  }
-  while ((IFG1 & OFIFG) != 0);	// Oscillator fault flag still set?
-  BCSCTL2 = SELM_2 + SELS;		// MCLK und SMCLK = XT2 (safe)
-  #else
-  /* Thdeltais code taken from the FU Berlin sources and reformatted. */
-  int delta = __msp430_cpu_speed >> 12;
-  //#define DELTA    600
-
-  unsigned int compare, oldcapture = 0;
-  unsigned int i;
-
-
-  BCSCTL1 = 0xa4; /* ACLK is devided by 4. RSEL=6 no division for MCLK
+#if MSP430_HAS_EXTERNAL_CRYSTAL
+    /*------------------ use external oszillator -----------------------*/
+    uint16_t i;
+
+    // Stop watchdog
+    WDTCTL = WDTPW + WDTHOLD;
+
+    //Init crystal for mclk
+    //XT2 = HF XTAL
+    BCSCTL1 = RSEL2;
+
+    // Wait for xtal to stabilize
+    do {
+        IFG1 &= ~OFIFG;				// Clear oscillator fault flag
+
+        for (i = 0xFF; i > 0; i--); // Time for flag to set
+    }
+    while ((IFG1 & OFIFG) != 0);	// Oscillator fault flag still set?
+
+    BCSCTL2 = SELM_2 + SELS;		// MCLK und SMCLK = XT2 (safe)
+#else
+    /* Thdeltais code taken from the FU Berlin sources and reformatted. */
+    int delta = __msp430_cpu_speed >> 12;
+    //#define DELTA    600
+
+    unsigned int compare, oldcapture = 0;
+    unsigned int i;
+
+
+    BCSCTL1 = 0xa4; /* ACLK is devided by 4. RSEL=6 no division for MCLK
 		     and SSMCLK. XT2 is off. */
 
-  // Init FLL to desired frequency using the 32762Hz crystal
-  #if MSP430_HAS_DCOR
-  BCSCTL2 = 0x01;
-  #else
-  BCSCTL2 = 0x00;
-  #endif
-
-  WDTCTL = WDTPW + WDTHOLD;             /* Stop WDT */
-  BCSCTL1 |= DIVA1 + DIVA0;             /* ACLK = LFXT1CLK/8 */
-  for(i = 0xffff; i > 0; i--);          /* Delay for XTAL to settle */
-
-  CCTL2 = CCIS0 + CM0 + CAP;            // Define CCR2, CAP, ACLK
-  TACTL = TASSEL1 + TACLR + MC1;        // SMCLK, continous mode
-
-
-  while(1) {
-
-    while((CCTL2 & CCIFG) != CCIFG);    /* Wait until capture occured! */
-    CCTL2 &= ~CCIFG;                    /* Capture occured, clear flag */
-    compare = CCR2;                     /* Get current captured SMCLK */
-    compare = compare - oldcapture;     /* SMCLK difference */
-    oldcapture = CCR2;                  /* Save current captured SMCLK */
-
-    if(delta == compare) {
-      break;                            /* if equal, leave "while(1)" */
-    } else if(delta < compare) {        /* DCO is too fast, slow it down */
-      DCOCTL--;
-      if(DCOCTL == 0xFF) {              /* Did DCO role under? */
-	BCSCTL1--;
-      }
-    } else {                            /* -> Select next lower RSEL */
-      DCOCTL++;
-      if(DCOCTL == 0x00) {              /* Did DCO role over? */
-	BCSCTL1++;
-      }
-                                        /* -> Select next higher RSEL  */
+    // Init FLL to desired frequency using the 32762Hz crystal
+#if MSP430_HAS_DCOR
+    BCSCTL2 = 0x01;
+#else
+    BCSCTL2 = 0x00;
+#endif
+
+    WDTCTL = WDTPW + WDTHOLD;             /* Stop WDT */
+    BCSCTL1 |= DIVA1 + DIVA0;             /* ACLK = LFXT1CLK/8 */
+
+    for (i = 0xffff; i > 0; i--);         /* Delay for XTAL to settle */
+
+    CCTL2 = CCIS0 + CM0 + CAP;            // Define CCR2, CAP, ACLK
+    TACTL = TASSEL1 + TACLR + MC1;        // SMCLK, continous mode
+
+
+    while (1) {
+
+        while ((CCTL2 & CCIFG) != CCIFG);   /* Wait until capture occured! */
+
+        CCTL2 &= ~CCIFG;                    /* Capture occured, clear flag */
+        compare = CCR2;                     /* Get current captured SMCLK */
+        compare = compare - oldcapture;     /* SMCLK difference */
+        oldcapture = CCR2;                  /* Save current captured SMCLK */
+
+        if (delta == compare) {
+            break;                            /* if equal, leave "while(1)" */
+        }
+        else if (delta < compare) {         /* DCO is too fast, slow it down */
+            DCOCTL--;
+
+            if (DCOCTL == 0xFF) {             /* Did DCO role under? */
+                BCSCTL1--;
+            }
+        }
+        else {                              /* -> Select next lower RSEL */
+            DCOCTL++;
+
+            if (DCOCTL == 0x00) {             /* Did DCO role over? */
+                BCSCTL1++;
+            }
+
+            /* -> Select next higher RSEL  */
+        }
     }
-  }
 
-  CCTL2 = 0;                            /* Stop CCR2 function */
-  TACTL = 0;                            /* Stop Timer_A */
+    CCTL2 = 0;                            /* Stop CCR2 function */
+    TACTL = 0;                            /* Stop Timer_A */
 
-  BCSCTL1 &= ~(DIVA1 + DIVA0);          /* remove /8 divisor from ACLK again */
-  #endif
+    BCSCTL1 &= ~(DIVA1 + DIVA0);          /* remove /8 divisor from ACLK again */
+#endif
 }
 
-void board_init() {
+void board_init()
+{
     msp430_cpu_init();
     msb_ports_init();
-    
+
     LED_RED_ON;
-   
+
     msp430_set_cpu_speed(7372800uL);
 }
diff --git a/msb-430-common/include/board-conf.h b/msb-430-common/include/board-conf.h
index e85c3128f26d3d8f2911e54d2947ec66569904f9..9db51d94546a06a707407f8e9a335674c8d58052 100644
--- a/msb-430-common/include/board-conf.h
+++ b/msb-430-common/include/board-conf.h
@@ -1,5 +1,5 @@
 #ifndef BOARD_CONF_H
-#define BOARD_CONF_H 
+#define BOARD_CONF_H
 
 #define INFOMEM     (0x1000)
 
diff --git a/msb-430-common/uart1.c b/msb-430-common/uart1.c
index 7abad1d4e3a8b65e6df443e1a50cb24873b50b49..2b22b3171b2ca7f7efd5afbff0d1af316c9dab3d 100644
--- a/msb-430-common/uart1.c
+++ b/msb-430-common/uart1.c
@@ -9,7 +9,7 @@ int putchar(int c)
 {
     UART1_TX = c;
     UART1_WAIT_TXDONE();
-    
+
     if (c == 10) {
         UART1_TX = 13;
         UART1_WAIT_TXDONE();
diff --git a/msb-430h/driver_cc110x.c b/msb-430h/driver_cc110x.c
index 9316e8bf564f22ab373af045aa295a972d730076..deb6835fd29c96a37ea49e20af1e7c3fac959c46 100644
--- a/msb-430h/driver_cc110x.c
+++ b/msb-430h/driver_cc110x.c
@@ -41,51 +41,54 @@ volatile int retry_count = 0;
 
 void cc110x_gdo0_enable(void)
 {
-	P2IFG &= ~0x02;     /* Clear IFG for GDO0 */
-	P2IE |= 0x02;       /* Enable interrupt for GDO0 */ 
+    P2IFG &= ~0x02;     /* Clear IFG for GDO0 */
+    P2IE |= 0x02;       /* Enable interrupt for GDO0 */
 }
 
 void cc110x_gdo0_disable(void)
 {
-	P2IE &= ~0x02;      /* Disable interrupt for GDO0 */
-	P2IFG &= ~0x02;     /* Clear IFG for GDO0 */
+    P2IE &= ~0x02;      /* Disable interrupt for GDO0 */
+    P2IFG &= ~0x02;     /* Clear IFG for GDO0 */
 }
 
 void cc110x_gdo2_enable(void)
 {
-	P2IFG &= ~0x01;     /* Clear IFG for GDO2 */
-	P2IE |= 0x01;       /* Enable interrupt for GDO2 */ 
+    P2IFG &= ~0x01;     /* Clear IFG for GDO2 */
+    P2IE |= 0x01;       /* Enable interrupt for GDO2 */
 }
 
 void cc110x_gdo2_disable(void)
 {
-	P2IE &= ~0x01;      /* Disable interrupt for GDO2 */
-	P2IFG &= ~0x01;     /* Clear IFG for GDO2 */
+    P2IE &= ~0x01;      /* Disable interrupt for GDO2 */
+    P2IFG &= ~0x01;     /* Clear IFG for GDO2 */
 }
 
 void cc110x_before_send(void)
 {
-	// Disable GDO2 interrupt before sending packet
-	cc110x_gdo2_disable();
+    // Disable GDO2 interrupt before sending packet
+    cc110x_gdo2_disable();
 }
 
 void cc110x_after_send(void)
 {
-	// Enable GDO2 interrupt after sending packet
-	cc110x_gdo2_enable();
+    // Enable GDO2 interrupt after sending packet
+    cc110x_gdo2_enable();
 }
 
 
-int cc110x_get_gdo0(void) {
-        return  CC1100_GDO0;
+int cc110x_get_gdo0(void)
+{
+    return  CC1100_GDO0;
 }
 
-int cc110x_get_gdo1(void) {
-        return  CC1100_GDO1;
+int cc110x_get_gdo1(void)
+{
+    return  CC1100_GDO1;
 }
 
-int cc110x_get_gdo2(void) {
-        return  CC1100_GDO2;
+int cc110x_get_gdo2(void)
+{
+    return  CC1100_GDO2;
 }
 
 void cc110x_spi_cs(void)
@@ -95,78 +98,90 @@ void cc110x_spi_cs(void)
 
 uint8_t cc110x_txrx(uint8_t data)
 {
-	/* Ensure TX Buf is empty */
-	long c = 0;
-	IFG1 &= ~UTXIFG0;
-	IFG1 &= ~URXIFG0;
-	TXBUF0 = data;
-	while(!(IFG1 & UTXIFG0))
-	{
-		if (c++ == 1000000) 
-			puts("cc110x_txrx alarm()");	
-	}
-	/* Wait for Byte received */
-	c = 0;
-	while(!(IFG1 & URXIFG0))
-	{
-		if (c++ == 1000000) 
-			puts("cc110x_txrx alarm()");	
-	}
-	return RXBUF0;
+    /* Ensure TX Buf is empty */
+    long c = 0;
+    IFG1 &= ~UTXIFG0;
+    IFG1 &= ~URXIFG0;
+    TXBUF0 = data;
+
+    while (!(IFG1 & UTXIFG0)) {
+        if (c++ == 1000000) {
+            puts("cc110x_txrx alarm()");
+        }
+    }
+
+    /* Wait for Byte received */
+    c = 0;
+
+    while (!(IFG1 & URXIFG0)) {
+        if (c++ == 1000000) {
+            puts("cc110x_txrx alarm()");
+        }
+    }
+
+    return RXBUF0;
 }
 
 
 void cc110x_spi_select(void)
 {
-	// Switch to GDO mode
-	P3SEL &= ~0x04;
-	P3DIR &= ~0x04;
-	cs_low:
-	// CS to low
-	abort_count = 0;
-	CC1100_CS_LOW;
-	// Wait for SO to go low (voltage regulator
-	// has stabilized and the crystal is running)
-	loop:
-//	asm volatile ("nop");
-	if (CC1100_GDO1) {
-		abort_count++;
-		if (abort_count > CC1100_GDO1_LOW_COUNT) {
-			retry_count++;
-			if (retry_count > CC1100_GDO1_LOW_RETRY) {
-				puts("[CC1100 SPI] fatal error\n");
-				goto final;
-			}
-			CC1100_CS_HIGH;
+    // Switch to GDO mode
+    P3SEL &= ~0x04;
+    P3DIR &= ~0x04;
+cs_low:
+    // CS to low
+    abort_count = 0;
+    CC1100_CS_LOW;
+    // Wait for SO to go low (voltage regulator
+    // has stabilized and the crystal is running)
+loop:
+
+    //	asm volatile ("nop");
+    if (CC1100_GDO1) {
+        abort_count++;
+
+        if (abort_count > CC1100_GDO1_LOW_COUNT) {
+            retry_count++;
+
+            if (retry_count > CC1100_GDO1_LOW_RETRY) {
+                puts("[CC1100 SPI] fatal error\n");
+                goto final;
+            }
+
+            CC1100_CS_HIGH;
             goto cs_low;		// try again
-		}
-		goto loop;
-	}
-	final:
-	/* Switch to SPI mode */
-	P3SEL |= 0x04;
+        }
+
+        goto loop;
+    }
+
+final:
+    /* Switch to SPI mode */
+    P3SEL |= 0x04;
 }
 
-void cc110x_spi_unselect(void) {
+void cc110x_spi_unselect(void)
+{
     CC1100_CS_HIGH;
 }
 
 void cc110x_init_interrupts(void)
 {
-	unsigned int state = disableIRQ(); /* Disable all interrupts */
-	P2SEL = 0x00;       /* must be <> 1 to use interrupts */
-	P2IES |= 0x01;      /* Enables external interrupt on low edge (for GDO2) */
+    unsigned int state = disableIRQ(); /* Disable all interrupts */
+    P2SEL = 0x00;       /* must be <> 1 to use interrupts */
+    P2IES |= 0x01;      /* Enables external interrupt on low edge (for GDO2) */
     P2IE |= 0x01;       /* Enable interrupt */
     P2IFG &= ~0x01;     /* Clears the interrupt flag */
-	P2IE &= ~0x02;      /* Disable interrupt for GDO0 */
-	P2IFG &= ~0x02;     /* Clear IFG for GDO0 */
-	restoreIRQ(state);  /* Enable all interrupts */
+    P2IE &= ~0x02;      /* Disable interrupt for GDO0 */
+    P2IFG &= ~0x02;     /* Clear IFG for GDO0 */
+    restoreIRQ(state);  /* Enable all interrupts */
 }
 
 void cc110x_spi_init(uint8_t clockrate)
 {
     // Switch off async UART
-    while(!(UTCTL0 & TXEPT));   // Wait for empty UxTXBUF register
+    while (!(UTCTL0 & TXEPT));  // Wait for empty UxTXBUF register
+
     IE1 &= ~(URXIE0 + UTXIE0);  // Disable USART0 receive&transmit interrupt
     ME1 &= ~(UTXE0 + URXE0);
     P3SEL |= 0x0E;              // Set pin as SPI
@@ -178,14 +193,14 @@ void cc110x_spi_init(uint8_t clockrate)
     // CKPL works also, but not CKPH+CKPL or none of them!!
     UCTL0 |= CHAR + SYNC + MM;
     UTCTL0 = CKPH + SSEL1 + SSEL0 + STC;
-    
+
     // Ignore clockrate argument for now, just use clock source/2
     // SMCLK = 7,3728 MHz
     UBR00 = 0x02;  // Ensure baud rate >= 2
     UBR10 = 0x00;
     UMCTL0 = 0x00; // No modulation
     URCTL0 = 0x00; // Reset Receive Control Register
-   
+
     // Enable SPI mode
     ME1 |= USPIE0;
 
@@ -194,30 +209,30 @@ void cc110x_spi_init(uint8_t clockrate)
 }
 
 
-// #include <msp430x16x.h> 
+// #include <msp430x16x.h>
 // #include <signal.h>
 // #include "type.h"
 // #include "cc110x_defines.h"
 // #include "driver_cc110x.h"
 // #include "driver_system.h"
 // #include "spi0.h"
-// 
-// static callback_t _paket_cb; 
+//
+// static callback_t _paket_cb;
 // static callback_t _cs_cb;
-// 
+//
 // //-------------------------------------------------------------------------------------------------------
 // // Public CC1100 communication functions (SPI)
 // //-------------------------------------------------------------------------------------------------------
-// 
+//
 // //-------------------------------------------------------------------------------------------------------
 // //  void spiInitTrx(void)
 // //
 // //  DESCRIPTION:
 // //		This function puts the cc110x into spi mode. You have to call this bevore every spi transaction.
-// //  
+// //
 // //-------------------------------------------------------------------------------------------------------
-// 
-// 
+//
+//
 // void drivercc110x_spiwriteburstreg(uint8_t addr, unsigned char *buffer, uint8_t count)
 // {
 // 	uint8_t i;
@@ -233,7 +248,7 @@ void cc110x_spi_init(uint8_t clockrate)
 // 		/* Wait for TX to finish */
 // 		while(!(IFG1 & UTXIFG0))
 // 		{
-// 			if (c++ == 1000000) 
+// 			if (c++ == 1000000)
 // 				alarm();
 // 		}
 // 	}
@@ -241,12 +256,12 @@ void cc110x_spi_init(uint8_t clockrate)
 // 	c = 0;
 // 	while(!(IFG1 & URXIFG0))
 // 	{
-// 		if (c++ == 1000000) 
+// 		if (c++ == 1000000)
 // 			alarm();
 // 	}
 // 	CC1100_CS_HIGH;
 // }
-// 
+//
 // void drivercc110x_spireadburstreg(uint8_t addr, char *buffer, uint8_t count)
 // {
 // 	uint8_t i;
@@ -260,35 +275,35 @@ void cc110x_spi_init(uint8_t clockrate)
 // 		TXBUF0 = NOBYTE;
 // 		while(!(IFG1 & UTXIFG0))
 // 		{
-// 			if (c++ == 1000000) 
+// 			if (c++ == 1000000)
 // 				alarm();
 // 		}
 // 		/* Wait for Byte received */
 // 		c = 0;
 // 		while(!(IFG1 & URXIFG0))
 // 		{
-// 			if (c++ == 1000000) 
+// 			if (c++ == 1000000)
 // 				alarm();
 // 		}
 // 		buffer[i] = RXBUF0;
 // 	}
 // 	CC1100_CS_HIGH;
 // }
-// 
+//
 // void drivercc110x_load(callback_t cs_cb,callback_t paket_cb)
 // {
 // 	_paket_cb = paket_cb;
 // 	_cs_cb = cs_cb;
-// 	spi0_init(0);	
+// 	spi0_init(0);
 // }
-// 
+//
 // void drivercc110x_aftersend(void)
 // {
-//     CLEAR(P2IFG, 0x01);	
+//     CLEAR(P2IFG, 0x01);
 // 	SET(P2IE, 0x01); /* Enable interrupts on port 2 pin 0 */
 // 	CLEAR(P4OUT, 0x08); /* Turn off Sending Led*/
 // }
-// 
+//
 // void drivercc110x_initinterrupts(void)
 // {
 // 	_DINT(); /* Disable all interrupts */
@@ -300,7 +315,7 @@ void cc110x_spi_init(uint8_t clockrate)
 // 	CLEAR(P2IFG, 0x02); /* Clear IFG for GDO0 */
 // 	_EINT(); /* Enable all interrupts */
 // }
-// 
+//
 // void drivercc110x_beforesend(void)
 // {
 // 	/* Turn on Led while sending paket for debug reasons */
@@ -308,35 +323,39 @@ void cc110x_spi_init(uint8_t clockrate)
 // 	/* Disable interrupts on port 2 pin 0 */
 // 	CLEAR(P2IE, 0x01);
 // }
-// 
-// 
+//
+//
 // /*
 //  * Private functions
 //  */
-// 
-// 
+//
+//
 
 /*
  * CC1100 receive interrupt
  */
-interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc110x_isr(void){
+interrupt(PORT2_VECTOR) __attribute__((naked)) cc110x_isr(void)
+{
     __enter_isr();
-puts("cc110x_isr()");
-//	if (system_state.POWERDOWN) SPI_INIT; /* Initialize SPI after wakeup */
- 	/* Check IFG */
-	if ((P2IFG & 0x01) != 0) {
-		P2IFG &= ~0x01;
-		cc110x_gdo2_irq();
-	}
-	else if ((P2IFG & 0x02) != 0) {
+    puts("cc110x_isr()");
+
+    //	if (system_state.POWERDOWN) SPI_INIT; /* Initialize SPI after wakeup */
+    /* Check IFG */
+    if ((P2IFG & 0x01) != 0) {
+        P2IFG &= ~0x01;
+        cc110x_gdo2_irq();
+    }
+    else if ((P2IFG & 0x02) != 0) {
         cc110x_gdo0_irq();
-		P2IE &= ~0x02;	            // Disable interrupt for GDO0
-   		P2IFG &= ~0x02;	            // Clear IFG for GDO0
-	} else {
+        P2IE &= ~0x02;	            // Disable interrupt for GDO0
+        P2IFG &= ~0x02;	            // Clear IFG for GDO0
+    }
+    else {
         puts("cc110x_isr(): unexpected IFG!");
-		/* Should not occur - only Port 2 Pin 0 interrupts are enabled */
-//		CLEAR(P2IFG, 0xFF);	/* Clear all flags */
-	}
-//	if (system_state.POWERDOWN != 0) END_LPM3;
-	__exit_isr();
+        /* Should not occur - only Port 2 Pin 0 interrupts are enabled */
+        //		CLEAR(P2IFG, 0xFF);	/* Clear all flags */
+    }
+
+    //	if (system_state.POWERDOWN != 0) END_LPM3;
+    __exit_isr();
 }
diff --git a/msba2-common/board_common_init.c b/msba2-common/board_common_init.c
index 7e4eb2c1262ea1cb7e6ba47338f6aa2ced5a8248..a437cce2b72f590348cfa93ecc8f987b2c563146 100644
--- a/msba2-common/board_common_init.c
+++ b/msba2-common/board_common_init.c
@@ -81,7 +81,8 @@ void init_clks1(void)
     pllfeed();
 
     SCS |= 0x20;                        // Enable main OSC
-    while( !(SCS & 0x40) );             // Wait until main OSC is usable
+
+    while (!(SCS & 0x40));              // Wait until main OSC is usable
 
     /* select main OSC, 16MHz, as the PLL clock source */
     CLKSRCSEL = 0x0001;
@@ -102,9 +103,10 @@ void init_clks1(void)
 #endif
 }
 
-void init_clks2(void){
+void init_clks2(void)
+{
     // Wait for the PLL to lock to set frequency
-    while(!(PLLSTAT & BIT26));
+    while (!(PLLSTAT & BIT26));
 
     // Connect the PLL as the clock source
     PLLCON = 0x0003;
diff --git a/msba2-common/board_config.c b/msba2-common/board_config.c
index 496a07796173cd46f5f8d37adf42861c1b219149..a7207c895d3b3135f5ec90ad4e43fa4a708e09d6 100644
--- a/msba2-common/board_config.c
+++ b/msba2-common/board_config.c
@@ -3,10 +3,12 @@
 #include <config.h>
 #include <flashrom.h>
 
-void config_load(void) {
+void config_load(void)
+{
     extern char configmem[];
     /* cast it here for strict-aliasing */
-    uint16_t* tmp = (uint16_t*) configmem;
+    uint16_t *tmp = (uint16_t *) configmem;
+
     if (*tmp ==  CONFIG_KEY) {
         memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig));
     }
@@ -15,7 +17,8 @@ void config_load(void) {
     }
 }
 
-uint8_t config_save(void) {
+uint8_t config_save(void)
+{
     configmem_t mem = { CONFIG_KEY, sysconfig  };
-    return (flashrom_erase((uint8_t*) &configmem) && flashrom_write((uint8_t*) &configmem, (char*) &mem, sizeof(mem)));
+    return (flashrom_erase((uint8_t *) &configmem) && flashrom_write((uint8_t *) &configmem, (char *) &mem, sizeof(mem)));
 }
diff --git a/msba2-common/drivers/include/uart0.h b/msba2-common/drivers/include/uart0.h
index 0c580becc23d9c09da4ac9d830d7ce4e2298658e..b0861b2b15e8f0e7836201828007e7e2b3a916e8 100644
--- a/msba2-common/drivers/include/uart0.h
+++ b/msba2-common/drivers/include/uart0.h
@@ -1,5 +1,5 @@
 #ifndef __UART0_H
-#define __UART0_H 
+#define __UART0_H
 
 #define UART0_BUFSIZE 32
 
diff --git a/msba2-common/drivers/msba2-cc110x.c b/msba2-common/drivers/msba2-cc110x.c
index b0a58544464e0e5c0df2361d01bfbefd5b73d2c5..b5bde7cbfc8d5159a19f51c6f10eb05f5a21feff 100644
--- a/msba2-common/drivers/msba2-cc110x.c
+++ b/msba2-common/drivers/msba2-cc110x.c
@@ -58,7 +58,7 @@ and the mailinglist (subscription via web site)
 
 #define CC1100_GDO1_LOW_RETRY		 (100)		// max. retries for GDO1 to go low
 #define CC1100_GDO1_LOW_COUNT		(2700)		// loop count (timeout ~ 500 us) to wait
-												// for GDO1 to go low when CS low
+// for GDO1 to go low when CS low
 
 //#define DEBUG
 #ifdef DEBUG
@@ -67,178 +67,204 @@ and the mailinglist (subscription via web site)
 
 static unsigned long time_value;
 
-static void set_time(void) {
-	time_value = 0;
+static void set_time(void)
+{
+    time_value = 0;
 }
 
-static int test_time(int code) {
-	time_value++;
-	if (time_value > 10000000) {
-		printf("CC1100 SPI alarm: %u!\n", code);
-		time_value = 0;
-		return 1;
-	}
-	return 0;
+static int test_time(int code)
+{
+    time_value++;
+
+    if (time_value > 10000000) {
+        printf("CC1100 SPI alarm: %u!\n", code);
+        time_value = 0;
+        return 1;
+    }
+
+    return 0;
 }
 #endif
 
-int cc110x_get_gdo0(void) {
-	return 	CC1100_GDO0;
+int cc110x_get_gdo0(void)
+{
+    return 	CC1100_GDO0;
 }
 
-int cc110x_get_gdo1(void) {
-	return 	CC1100_GDO1;
+int cc110x_get_gdo1(void)
+{
+    return 	CC1100_GDO1;
 }
 
-int cc110x_get_gdo2(void) {
-	return 	CC1100_GDO2;
+int cc110x_get_gdo2(void)
+{
+    return 	CC1100_GDO2;
 }
 
 void cc110x_spi_init(void)
 {
-	// configure chip-select
-	FIO1DIR |= BIT21;
-	FIO1SET = BIT21;
-
-	// Power
-	PCONP |= PCSSP0;								// Enable power for SSP0 (default is on)
-
-	// PIN Setup
-	PINSEL3 |= BIT8 + BIT9; 						// Set CLK function to SPI
-	PINSEL3 |= BIT14 + BIT15;						// Set MISO function to SPI
-	PINSEL3 |= BIT16 + BIT17; 						// Set MOSI function to SPI
-
-	// Interface Setup
-	SSP0CR0 = 7;
-
-	// Clock Setup
-	uint32_t pclksel;
-	uint32_t cpsr;
-	lpc2387_pclk_scale(F_CPU/1000, 6000, &pclksel, &cpsr);
-	PCLKSEL1 &= ~(BIT10|BIT11);						// CCLK to PCLK divider
-	PCLKSEL1 |= pclksel << 10;
-	SSP0CPSR = cpsr;
-
-	// Enable
-	SSP0CR1 |= BIT1; 								// SSP-Enable
-	int dummy;
-	// Clear RxFIFO:
-	while( SPI_RX_AVAIL ) {						// while RNE (Receive FIFO Not Empty)...
-		dummy = SSP0DR;							// read data
-	}
+    // configure chip-select
+    FIO1DIR |= BIT21;
+    FIO1SET = BIT21;
+
+    // Power
+    PCONP |= PCSSP0;								// Enable power for SSP0 (default is on)
+
+    // PIN Setup
+    PINSEL3 |= BIT8 + BIT9; 						// Set CLK function to SPI
+    PINSEL3 |= BIT14 + BIT15;						// Set MISO function to SPI
+    PINSEL3 |= BIT16 + BIT17; 						// Set MOSI function to SPI
+
+    // Interface Setup
+    SSP0CR0 = 7;
+
+    // Clock Setup
+    uint32_t pclksel;
+    uint32_t cpsr;
+    lpc2387_pclk_scale(F_CPU / 1000, 6000, &pclksel, &cpsr);
+    PCLKSEL1 &= ~(BIT10 | BIT11);						// CCLK to PCLK divider
+    PCLKSEL1 |= pclksel << 10;
+    SSP0CPSR = cpsr;
+
+    // Enable
+    SSP0CR1 |= BIT1; 								// SSP-Enable
+    int dummy;
+
+    // Clear RxFIFO:
+    while (SPI_RX_AVAIL) {						// while RNE (Receive FIFO Not Empty)...
+        dummy = SSP0DR;							// read data
+    }
+
     /* to suppress unused-but-set-variable */
     (void) dummy;
 }
 
-uint8_t cc110x_txrx(uint8_t c) {
-	uint8_t result;
-	SSP0DR = c;
+uint8_t cc110x_txrx(uint8_t c)
+{
+    uint8_t result;
+    SSP0DR = c;
 #ifdef DEBUG
-	set_time();
+    set_time();
 #endif
-	while (!SPI_TX_EMPTY) {
+
+    while (!SPI_TX_EMPTY) {
 #ifdef DEBUG
-		test_time(0);
+        test_time(0);
 #endif
-	}
+    }
+
 #ifdef DEBUG
-	set_time();
+    set_time();
 #endif
-	while (SPI_BUSY) {
+
+    while (SPI_BUSY) {
 #ifdef DEBUG
-		test_time(1);
+        test_time(1);
 #endif
-	}
+    }
+
 #ifdef DEBUG
-	set_time();
+    set_time();
 #endif
-	while (!SPI_RX_AVAIL) {
+
+    while (!SPI_RX_AVAIL) {
 #ifdef DEBUG
-		test_time(2);
+        test_time(2);
 #endif
-	}
-	result = (uint8_t)SSP0DR;
-	return result;
+    }
+
+    result = (uint8_t)SSP0DR;
+    return result;
 }
 
 void cc110x_spi_cs(void)
 {
-	FIO1CLR = BIT21;
+    FIO1CLR = BIT21;
 }
 
 void
 cc110x_spi_select(void)
 {
-	volatile int retry_count = 0;
-	volatile int abort_count;
-	// Switch to GDO mode input
-	PINSEL3 &= ~(BIT14 + BIT15);// Set MISO function to GPIO
-	FIO1DIR &= ~BIT23;
-	cs_low:
-	// CS to low
-	abort_count = 0;
-	FIO1CLR = BIT21;
-	// Wait for SO to go low (voltage regulator
-	// has stabilized and the crystal is running)
-	loop:
-	asm volatile ("nop");
-	if (CC1100_GDO1) {
-		abort_count++;
-		if (abort_count > CC1100_GDO1_LOW_COUNT) {
-			retry_count++;
-			if (retry_count > CC1100_GDO1_LOW_RETRY) {
-				puts("[CC1100 SPI] fatal error\n");
-				goto final;
-			}
-			FIO1SET = BIT21;	// CS to high
-			goto cs_low;		// try again
-		}
-		goto loop;
-	}
-	final:
-	// Switch to SPI mode
-	PINSEL3 |= (BIT14 + BIT15);	// Set MISO function to SPI
+    volatile int retry_count = 0;
+    volatile int abort_count;
+    // Switch to GDO mode input
+    PINSEL3 &= ~(BIT14 + BIT15);// Set MISO function to GPIO
+    FIO1DIR &= ~BIT23;
+cs_low:
+    // CS to low
+    abort_count = 0;
+    FIO1CLR = BIT21;
+    // Wait for SO to go low (voltage regulator
+    // has stabilized and the crystal is running)
+loop:
+    asm volatile("nop");
+
+    if (CC1100_GDO1) {
+        abort_count++;
+
+        if (abort_count > CC1100_GDO1_LOW_COUNT) {
+            retry_count++;
+
+            if (retry_count > CC1100_GDO1_LOW_RETRY) {
+                puts("[CC1100 SPI] fatal error\n");
+                goto final;
+            }
+
+            FIO1SET = BIT21;	// CS to high
+            goto cs_low;		// try again
+        }
+
+        goto loop;
+    }
+
+final:
+    // Switch to SPI mode
+    PINSEL3 |= (BIT14 + BIT15);	// Set MISO function to SPI
 }
 
 void
 cc110x_spi_unselect(void)
 {
-	FIO1SET = BIT21;
+    FIO1SET = BIT21;
 }
 
 void cc110x_before_send(void)
 {
-	// Disable GDO2 interrupt before sending packet
-	cc110x_gdo2_disable();
+    // Disable GDO2 interrupt before sending packet
+    cc110x_gdo2_disable();
 }
 
 void cc110x_after_send(void)
 {
-	// Enable GDO2 interrupt after sending packet
-	cc110x_gdo2_enable();
+    // Enable GDO2 interrupt after sending packet
+    cc110x_gdo2_enable();
 }
 
-void cc110x_gdo0_enable(void) {
+void cc110x_gdo0_enable(void)
+{
     gpioint_set(0, BIT27, GPIOINT_RISING_EDGE, &cc110x_gdo0_irq);
 }
 
-void cc110x_gdo0_disable(void) {
-	gpioint_set(0, BIT27, GPIOINT_DISABLE, NULL);
+void cc110x_gdo0_disable(void)
+{
+    gpioint_set(0, BIT27, GPIOINT_DISABLE, NULL);
 }
 
-void cc110x_gdo2_disable(void) {
-	gpioint_set(0, BIT28, GPIOINT_DISABLE, NULL);
+void cc110x_gdo2_disable(void)
+{
+    gpioint_set(0, BIT28, GPIOINT_DISABLE, NULL);
 }
 
-void cc110x_gdo2_enable(void) {
-	gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc110x_gdo2_irq);
+void cc110x_gdo2_enable(void)
+{
+    gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc110x_gdo2_irq);
 }
 
 void cc110x_init_interrupts(void)
 {
     // Enable external interrupt on low edge (for GDO2)
-	FIO0DIR &= ~BIT28;
-	cc110x_gdo2_enable();
-	// Enable external interrupt on low edge (for GDO0)
-	FIO0DIR &= ~BIT27;
+    FIO0DIR &= ~BIT28;
+    cc110x_gdo2_enable();
+    // Enable external interrupt on low edge (for GDO0)
+    FIO0DIR &= ~BIT27;
 }
diff --git a/msba2-common/drivers/msba2-ltc4150.c b/msba2-common/drivers/msba2-ltc4150.c
index 4e6534c02230f74a1b3e08e91315c72c4734c2ee..aba9085189ed72261a1d1237ced09aad9f066dc3 100644
--- a/msba2-common/drivers/msba2-ltc4150.c
+++ b/msba2-common/drivers/msba2-ltc4150.c
@@ -45,21 +45,25 @@ and the mailinglist (subscription via web site)
 #include "ltc4150_arch.h"
 #include "gpioint.h"
 
-void __attribute__((__no_instrument_function__)) ltc4150_disable_int(void) {
-	gpioint_set(0, BIT4, GPIOINT_DISABLE, NULL);
+void __attribute__((__no_instrument_function__)) ltc4150_disable_int(void)
+{
+    gpioint_set(0, BIT4, GPIOINT_DISABLE, NULL);
 }
 
-void __attribute__((__no_instrument_function__)) ltc4150_enable_int(void) {
-	gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, &ltc4150_interrupt);
+void __attribute__((__no_instrument_function__)) ltc4150_enable_int(void)
+{
+    gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, &ltc4150_interrupt);
 }
 
-void __attribute__((__no_instrument_function__)) ltc4150_sync_blocking(void) {
-	while(!(FIO0PIN & BIT4)) {};
+void __attribute__((__no_instrument_function__)) ltc4150_sync_blocking(void)
+{
+    while (!(FIO0PIN & BIT4)) {};
 }
 
-void __attribute__((__no_instrument_function__)) ltc4150_arch_init() {
+void __attribute__((__no_instrument_function__)) ltc4150_arch_init()
+{
     FIO0DIR |= BIT5;
-	FIO0SET = BIT5;
+    FIO0SET = BIT5;
 }
 
 /** @} */
diff --git a/msba2-common/drivers/msba2-uart0.c b/msba2-common/drivers/msba2-uart0.c
index ccfc6d8e04cb534c66fef83f5fa16612ab7c9b62..5db2ca0da92c8cb27a62ffdc180a7af4171a740c 100644
--- a/msba2-common/drivers/msba2-uart0.c
+++ b/msba2-common/drivers/msba2-uart0.c
@@ -52,10 +52,10 @@ and the mailinglist (subscription via web site)
 typedef struct toprint_t {
     unsigned int len;
     char content[];
-}toprint_t;
+} toprint_t;
 
 #define QUEUESIZE 255
-static volatile toprint_t* queue[QUEUESIZE];
+static volatile toprint_t *queue[QUEUESIZE];
 static volatile unsigned char queue_head = 0;
 static volatile unsigned char queue_tail = 0;
 static volatile unsigned char queue_items = 0;
@@ -64,57 +64,71 @@ static volatile unsigned int actual_pos = 0;
 static volatile unsigned int running = 0;
 static volatile unsigned int fifo = 0;
 
-static volatile toprint_t* actual = NULL;
+static volatile toprint_t *actual = NULL;
 
-static inline void enqueue(void) {
+static inline void enqueue(void)
+{
     queue_items++;
     queue_tail++;
 }
 
-static inline void dequeue(void) {
+static inline void dequeue(void)
+{
     actual = (queue[queue_head]);
     queue_items--;
     queue_head++;
 }
 
-static void  push_queue(void) {
+static void  push_queue(void)
+{
     running = 1;
-	lpm_prevent_sleep |= LPM_PREVENT_SLEEP_UART;
+    lpm_prevent_sleep |= LPM_PREVENT_SLEEP_UART;
 start:
+
     if (!actual) {
         if (queue_items) {
             dequeue();
-        } else {
+        }
+        else {
             running = 0;
             lpm_prevent_sleep &= ~LPM_PREVENT_SLEEP_UART;
+
             if (!fifo)
-                while(!(U0LSR & BIT6)){};
+                while (!(U0LSR & BIT6)) {};
+
             return;
         }
     }
-    while ((actual_pos < actual->len)  && (fifo++ < 16)){
+
+    while ((actual_pos < actual->len)  && (fifo++ < 16)) {
         U0THR = actual->content[actual_pos++];
     }
+
     if (actual_pos == actual->len) {
-        free((void*)actual);
+        free((void *)actual);
         actual = NULL;
         actual_pos = 0;
         goto start;
     }
 }
 
-int uart_active(void){
+int uart_active(void)
+{
     return (running || fifo);
 }
 
 void stdio_flush(void)
 {
     U0IER &= ~BIT1;                             // disable THRE interrupt
-    while(running) {
-        while(!(U0LSR & (BIT5|BIT6))){};        // transmit fifo
-        fifo=0;
+
+    while (running) {
+        while (!(U0LSR & (BIT5 | BIT6))) {};    // transmit fifo
+
+        fifo = 0;
+
         push_queue();                           // dequeue to fifo
     }
+
     U0IER |= BIT1;                              // enable THRE interrupt
 }
 
@@ -124,9 +138,9 @@ void UART0_IRQHandler(void)
     int iir;
     iir = U0IIR;
 
-    switch(iir & UIIR_ID_MASK) {
+    switch (iir & UIIR_ID_MASK) {
         case UIIR_THRE_INT:               // Transmit Holding Register Empty
-            fifo=0;
+            fifo = 0;
             push_queue();
             break;
 
@@ -137,43 +151,51 @@ void UART0_IRQHandler(void)
                 do {
                     int c = U0RBR;
                     uart0_handle_incoming(c);
-                } while (U0LSR & ULSR_RDR);
+                }
+                while (U0LSR & ULSR_RDR);
+
                 uart0_notify_thread();
             }
+
 #endif
             break;
+
         default:
             U0LSR;
             U0RBR;
             break;
     } // switch
+
     VICVectAddr = 0;                    // Acknowledge Interrupt
 }
 
-static inline int uart0_puts(char *astring,int length)
+static inline int uart0_puts(char *astring, int length)
 {
-/*    while (queue_items == (QUEUESIZE-1)) {} ;
-    U0IER = 0;
-    queue[queue_tail] = malloc(length+sizeof(unsigned int));
-    queue[queue_tail]->len = length;
-    memcpy(&queue[queue_tail]->content,astring,length);
-    enqueue();
-    if (!running)
-        push_queue();
-    U0IER |= BIT0 | BIT1;       // enable RX irq
-*/
+    /*    while (queue_items == (QUEUESIZE-1)) {} ;
+        U0IER = 0;
+        queue[queue_tail] = malloc(length+sizeof(unsigned int));
+        queue[queue_tail]->len = length;
+        memcpy(&queue[queue_tail]->content,astring,length);
+        enqueue();
+        if (!running)
+            push_queue();
+        U0IER |= BIT0 | BIT1;       // enable RX irq
+    */
     /* alternative without queue:*/
     int i;
-    for (i=0;i<length;i++) {
-            while (!(U0LSR & BIT5));
-            U0THR = astring[i];
+
+    for (i = 0; i < length; i++) {
+        while (!(U0LSR & BIT5));
+
+        U0THR = astring[i];
     }
-/*    */
+
+    /*    */
 
     return length;
 }
 
-int fw_puts(char *astring,int length)
+int fw_puts(char *astring, int length)
 {
     return uart0_puts(astring, length);
 }
diff --git a/msba2-common/lpc2387-timer3.c b/msba2-common/lpc2387-timer3.c
index 3b404edd944815c081c0ffa53efcc07c1662c6f7..e070a156bcb2a909cee3398a348f8849b7b0f96a 100644
--- a/msba2-common/lpc2387-timer3.c
+++ b/msba2-common/lpc2387-timer3.c
@@ -11,26 +11,26 @@
 
 void  benchmark_init(void)
 {
-	PCLKSEL1 = (PCLKSEL1 & ~(BIT14|BIT15)) | (1 << 14);	// CCLK to PCLK divider
-	PCONP |= PCTIM3;
-	T3TCR = 0;											// disable timer
-	T3MCR = 0;											// disable interrupt
-	T3CCR = 0;											// capture is disabled.
-	T3EMR = 0;											// no external match output.
-	T3PR = 0;											// set prescaler
-	T3TC = 0;											// reset counter
+    PCLKSEL1 = (PCLKSEL1 & ~(BIT14 | BIT15)) | (1 << 14);	// CCLK to PCLK divider
+    PCONP |= PCTIM3;
+    T3TCR = 0;											// disable timer
+    T3MCR = 0;											// disable interrupt
+    T3CCR = 0;											// capture is disabled.
+    T3EMR = 0;											// no external match output.
+    T3PR = 0;											// set prescaler
+    T3TC = 0;											// reset counter
 }
 
 void  benchmark_reset_start(void)
 {
-	T3TCR = 0;												// disable timer
-	T3TC = 0;												// reset counter
-	T3TCR = BIT0;
+    T3TCR = 0;												// disable timer
+    T3TC = 0;												// reset counter
+    T3TCR = BIT0;
 }
 
 unsigned int  benchmark_read_stop(void)
 {
-	T3TCR = 0;												// disable timer
-	return T3TC;
+    T3TCR = 0;												// disable timer
+    return T3TC;
 }
 
diff --git a/msba2-common/tools/src/boot.h b/msba2-common/tools/src/boot.h
index 1560f1038044a0b3afd8be4efac0688c5fa969b0..ebca675db19e84706b81fe156c6073ebdd57ab2b 100644
--- a/msba2-common/tools/src/boot.h
+++ b/msba2-common/tools/src/boot.h
@@ -1,7 +1,7 @@
 
 typedef struct {
-	int size;
-	const int *prog;
+    int size;
+    const int *prog;
 } boot_t;
 
 
diff --git a/msba2-common/tools/src/boot_23xx.c b/msba2-common/tools/src/boot_23xx.c
index 9901171cc0bda49cbd51a0f5d05eb9044940e3c3..80fcb399d0cbf32af60660a78e8d8d342b3c430c 100644
--- a/msba2-common/tools/src/boot_23xx.c
+++ b/msba2-common/tools/src/boot_23xx.c
@@ -1,5 +1,5 @@
 /* automatically generated from boot_23xx.armasm */
 #include "boot_23xx.h"
 const unsigned int boot_23xx[] = {
-	20, 0xe28f0038, 0xe5901000, 0xe5902004, 0xe5903008, 0xe3a00001, 0xe5810000, 0xe3a040aa, 0xe3a05055, 0xe5820000, 0xe5834000, 0xe5835000, 0xe3a00000, 0xe5820000, 0xe5834000, 0xe5835000, 0xe3a0f000, 0xe01fc040, 0xe01fc080, 0xe01fc08c
+    20, 0xe28f0038, 0xe5901000, 0xe5902004, 0xe5903008, 0xe3a00001, 0xe5810000, 0xe3a040aa, 0xe3a05055, 0xe5820000, 0xe5834000, 0xe5835000, 0xe3a00000, 0xe5820000, 0xe5834000, 0xe5835000, 0xe3a0f000, 0xe01fc040, 0xe01fc080, 0xe01fc08c
 };
diff --git a/msba2-common/tools/src/boot_2xxx.c b/msba2-common/tools/src/boot_2xxx.c
index 4d9b367ebe5fdbcbe0c4b76d4471db8214639313..060db403543db6be7d961a434d9c21b3ded2de4c 100644
--- a/msba2-common/tools/src/boot_2xxx.c
+++ b/msba2-common/tools/src/boot_2xxx.c
@@ -1,5 +1,5 @@
 /* automatically generated from boot_2xxx.armasm */
 #include "boot_2xxx.h"
 const unsigned int boot_2xxx[] = {
-	7, 0xe28f000c, 0xe5901000, 0xe3a00001, 0xe5810000, 0xe3a0f000, 0xe01fc040
+    7, 0xe28f000c, 0xe5901000, 0xe3a00001, 0xe5810000, 0xe3a0f000, 0xe01fc040
 };
diff --git a/msba2-common/tools/src/chipinfo.c b/msba2-common/tools/src/chipinfo.c
index 4f3f1a9d7e5b4631a320c6c5c07c99588c016630..4c418379b8653e1b80f8bd811658791f259209b1 100644
--- a/msba2-common/tools/src/chipinfo.c
+++ b/msba2-common/tools/src/chipinfo.c
@@ -25,135 +25,132 @@
 
 
 struct sector_info_struct lpc2106_layout[] = {
-	{0x00000000, 0x2000},
-	{0x00002000, 0x2000},
-	{0x00004000, 0x2000},
-	{0x00006000, 0x2000},
-	{0x00008000, 0x2000},
-	{0x0000A000, 0x2000},
-	{0x0000C000, 0x2000},
-	{0x0000E000, 0x2000},
-	{0x00010000, 0x2000},
-	{0x00012000, 0x2000},
-	{0x00014000, 0x2000},
-	{0x00016000, 0x2000},
-	{0x00018000, 0x2000},
-	{0x0001A000, 0x2000},
-	{0x0001C000, 0x2000}
+    {0x00000000, 0x2000},
+    {0x00002000, 0x2000},
+    {0x00004000, 0x2000},
+    {0x00006000, 0x2000},
+    {0x00008000, 0x2000},
+    {0x0000A000, 0x2000},
+    {0x0000C000, 0x2000},
+    {0x0000E000, 0x2000},
+    {0x00010000, 0x2000},
+    {0x00012000, 0x2000},
+    {0x00014000, 0x2000},
+    {0x00016000, 0x2000},
+    {0x00018000, 0x2000},
+    {0x0001A000, 0x2000},
+    {0x0001C000, 0x2000}
 };
 
 struct sector_info_struct lpc2214_layout[] = {
-	{0x00000000, 0x2000},
-	{0x00002000, 0x2000},
-	{0x00004000, 0x2000},
-	{0x00006000, 0x2000},
-	{0x00008000, 0x2000},
-	{0x0000A000, 0x2000},
-	{0x0000C000, 0x2000},
-	{0x0000E000, 0x2000},
-	{0x00010000, 0x10000},
-	{0x00020000, 0x10000},
-	{0x00030000, 0x2000},
-	{0x00032000, 0x2000},
-	{0x00034000, 0x2000},
-	{0x00036000, 0x2000},
-	{0x00038000, 0x2000},
-	{0x0003A000, 0x2000},
-	{0x0003C000, 0x2000}
+    {0x00000000, 0x2000},
+    {0x00002000, 0x2000},
+    {0x00004000, 0x2000},
+    {0x00006000, 0x2000},
+    {0x00008000, 0x2000},
+    {0x0000A000, 0x2000},
+    {0x0000C000, 0x2000},
+    {0x0000E000, 0x2000},
+    {0x00010000, 0x10000},
+    {0x00020000, 0x10000},
+    {0x00030000, 0x2000},
+    {0x00032000, 0x2000},
+    {0x00034000, 0x2000},
+    {0x00036000, 0x2000},
+    {0x00038000, 0x2000},
+    {0x0003A000, 0x2000},
+    {0x0003C000, 0x2000}
 };
 
 struct sector_info_struct lpc2138_layout[] = {
-	{0x00000000, 0x1000},
-	{0x00001000, 0x1000},
-	{0x00002000, 0x1000},
-	{0x00003000, 0x1000},
-	{0x00004000, 0x1000},
-	{0x00005000, 0x1000},
-	{0x00006000, 0x1000},
-	{0x00007000, 0x1000},
-	{0x00008000, 0x8000},
-	{0x00010000, 0x8000},
-	{0x00018000, 0x8000},
-	{0x00020000, 0x8000},
-	{0x00028000, 0x8000},
-	{0x00030000, 0x8000},
-	{0x00038000, 0x8000},
-	{0x00040000, 0x8000},
-	{0x00048000, 0x8000},
-	{0x00050000, 0x8000},
-	{0x00058000, 0x8000},
-	{0x00060000, 0x8000},
-	{0x00068000, 0x8000},
-	{0x00070000, 0x8000},
-	{0x00078000, 0x1000},
-	{0x00079000, 0x1000},
-	{0x0007A000, 0x1000},
-	{0x0007B000, 0x1000},
-	{0x0007C000, 0x1000}
+    {0x00000000, 0x1000},
+    {0x00001000, 0x1000},
+    {0x00002000, 0x1000},
+    {0x00003000, 0x1000},
+    {0x00004000, 0x1000},
+    {0x00005000, 0x1000},
+    {0x00006000, 0x1000},
+    {0x00007000, 0x1000},
+    {0x00008000, 0x8000},
+    {0x00010000, 0x8000},
+    {0x00018000, 0x8000},
+    {0x00020000, 0x8000},
+    {0x00028000, 0x8000},
+    {0x00030000, 0x8000},
+    {0x00038000, 0x8000},
+    {0x00040000, 0x8000},
+    {0x00048000, 0x8000},
+    {0x00050000, 0x8000},
+    {0x00058000, 0x8000},
+    {0x00060000, 0x8000},
+    {0x00068000, 0x8000},
+    {0x00070000, 0x8000},
+    {0x00078000, 0x1000},
+    {0x00079000, 0x1000},
+    {0x0007A000, 0x1000},
+    {0x0007B000, 0x1000},
+    {0x0007C000, 0x1000}
 };
 
 
 
-// chunk_size is the number of bytes that will be sent with each
-// "C" (Copy RAM to Flash) command.  This must be one of the sizes
-// supported by that command.  Beware that different chips support
-// different sets of sizes, so check the user manual specific to
-// the chip.  You must choose a chunk_size which is an an integer
-// multiple of all the sector sizes, and it must be able to fit
-// entirely within the RAM (allowing for the bootloader memory and
-// stack usage).  Currently, all available chunk sizes meet these
-// requirements, but who knows what Philips will do in the future?
+/* chunk_size is the number of bytes that will be sent with each */
+/* "C" (Copy RAM to Flash) command.  This must be one of the sizes */
+/* supported by that command.  Beware that different chips support */
+/* different sets of sizes, so check the user manual specific to */
+/* the chip.  You must choose a chunk_size which is an an integer */
+/* multiple of all the sector sizes, and it must be able to fit */
+/* entirely within the RAM (allowing for the bootloader memory and */
+/* stack usage).  Currently, all available chunk sizes meet these */
+/* requirements, but who knows what Philips will do in the future? */
 //
-// ram_addr is the location in RAM where the chunks are sent by the
-// "W" (Write to RAM) command.
+/* ram_addr is the location in RAM where the chunks are sent by the */
+/* "W" (Write to RAM) command. */
 
 
 struct chip_info_struct chip_info[] = {
-//                                           chunk   num
-//part_number      id_string     ram_addr    _size   sec  sector layout  boot code
-{"LPC2104 (120k)", "4293984018", 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
-{"LPC2105 (120k)", "4293984034", 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
-{"LPC2106 (120k)", "4293984050", 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
-{"LPC2114 (120k)", "16908050",	 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
-{"LPC2119 (120k)", "33685266",	 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
-{"LPC2124 (120k)", "16908051",	 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
-{"LPC2129 (248k)", "33685267",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
-{"LPC2131 (32k)",  "196353",	 0x40000200, 0x1000,  8, lpc2138_layout, boot_2xxx},
-{"LPC2132 (64k)",  "196369",	 0x40000200, 0x1000,  9, lpc2138_layout, boot_2xxx},
-{"LPC2134 (128k)", "196370",	 0x40000200, 0x1000, 11, lpc2138_layout, boot_2xxx},
-{"LPC2136 (256k)", "196387",	 0x40000200, 0x1000, 15, lpc2138_layout, boot_2xxx},
-{"LPC2138 (500k)", "196389",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_2xxx},
-{"LPC2141 (32k)",  "67305217",	 0x40000200, 0x1000,  8, lpc2138_layout, boot_2xxx},
-{"LPC2142 (64k)",  "67305233",	 0x40000200, 0x1000,  9, lpc2138_layout, boot_2xxx},
-{"LPC2144 (128k)", "67305234",	 0x40000200, 0x1000, 11, lpc2138_layout, boot_2xxx},
-{"LPC2146 (256k)", "67305251",	 0x40000200, 0x1000, 15, lpc2138_layout, boot_2xxx},
-{"LPC2148 (500k)", "67305253",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_2xxx},
-{"LPC2194 (248k)", "50462483",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
-{"LPC2212 (248k)", "67239698",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
-{"LPC2214 (248k)", "100794131",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
-{"LPC2292 (248k)", "67239699",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
-{"LPC2294 (248k)", "84016915",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
-//{"LPC2101 (8k)",   "??????",	 0x40000200, 0x1000,  2, lpc2138_layout, boot_2xxx},
-//{"LPC2102 (16k)",  "??????",	 0x40000200, 0x1000,  4, lpc2138_layout, boot_2xxx},
-{"LPC2103 (32k)",  "327441",	 0x40000200, 0x1000,  8, lpc2138_layout, boot_2xxx},
-{"LPC2364 (128k)", "100924162",	 0x40000200, 0x1000, 11, lpc2138_layout, boot_23xx},
-{"LPC2366 (256k)", "100924195",	 0x40000200, 0x1000, 15, lpc2138_layout, boot_23xx},
-{"LPC2368 (500k)", "100924197",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
-{"LPC2378 (500k)", "117702437",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
-{"LPC2387 (500k)", "402716981",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
-{"LPC2387 (500k)", "385941301",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
-{"LPC2468 (500k)", "100925237",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
-{NULL, NULL, 0, 0, 0, NULL}
+    /* part_number     id_string     ram_addr    _size   sec  sector layout  boot code */
+    {"LPC2104 (120k)", "4293984018", 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
+    {"LPC2105 (120k)", "4293984034", 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
+    {"LPC2106 (120k)", "4293984050", 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
+    {"LPC2114 (120k)", "16908050",	 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
+    {"LPC2119 (120k)", "33685266",	 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
+    {"LPC2124 (120k)", "16908051",	 0x40000200, 0x2000, 15, lpc2106_layout, boot_2xxx},
+    {"LPC2129 (248k)", "33685267",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
+    {"LPC2131 (32k)",  "196353",	 0x40000200, 0x1000,  8, lpc2138_layout, boot_2xxx},
+    {"LPC2132 (64k)",  "196369",	 0x40000200, 0x1000,  9, lpc2138_layout, boot_2xxx},
+    {"LPC2134 (128k)", "196370",	 0x40000200, 0x1000, 11, lpc2138_layout, boot_2xxx},
+    {"LPC2136 (256k)", "196387",	 0x40000200, 0x1000, 15, lpc2138_layout, boot_2xxx},
+    {"LPC2138 (500k)", "196389",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_2xxx},
+    {"LPC2141 (32k)",  "67305217",	 0x40000200, 0x1000,  8, lpc2138_layout, boot_2xxx},
+    {"LPC2142 (64k)",  "67305233",	 0x40000200, 0x1000,  9, lpc2138_layout, boot_2xxx},
+    {"LPC2144 (128k)", "67305234",	 0x40000200, 0x1000, 11, lpc2138_layout, boot_2xxx},
+    {"LPC2146 (256k)", "67305251",	 0x40000200, 0x1000, 15, lpc2138_layout, boot_2xxx},
+    {"LPC2148 (500k)", "67305253",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_2xxx},
+    {"LPC2194 (248k)", "50462483",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
+    {"LPC2212 (248k)", "67239698",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
+    {"LPC2214 (248k)", "100794131",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
+    {"LPC2292 (248k)", "67239699",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
+    {"LPC2294 (248k)", "84016915",	 0x40000200, 0x2000, 17, lpc2214_layout, boot_2xxx},
+    {"LPC2103 (32k)",  "327441",	 0x40000200, 0x1000,  8, lpc2138_layout, boot_2xxx},
+    {"LPC2364 (128k)", "100924162",	 0x40000200, 0x1000, 11, lpc2138_layout, boot_23xx},
+    {"LPC2366 (256k)", "100924195",	 0x40000200, 0x1000, 15, lpc2138_layout, boot_23xx},
+    {"LPC2368 (500k)", "100924197",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
+    {"LPC2378 (500k)", "117702437",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
+    {"LPC2387 (500k)", "402716981",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
+    {"LPC2387 (500k)", "385941301",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
+    {"LPC2468 (500k)", "100925237",	 0x40000200, 0x1000, 27, lpc2138_layout, boot_23xx},
+    {NULL, NULL, 0, 0, 0, NULL}
 };
 
 
 
 char *lpc_return_strings[] = {
-	"CMD_SUCCESS", "INVALID_COMMAND", "SRC_ADDR_ERROR", "DST_ADDR_ERROR",
-	"SRC_ADDR_NOT_MAPPED", "DST_ADDR_NOT_MAPPED", "COUNT_ERROR", "INVALID_SECTOR",
-	"SECTOR_NOT_BLANK", "SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION", "COMPARE_ERROR",
-	"BUSY", "PARAM_ERROR", "ADDR_ERROR", "ADDR_NOT_MAPPED", "CMD_LOCKED",
-	"INVALID_CODE", "INVALID_BAUD_RATE", "INVALID_STOP_BIT",
-	"CODE_READ_PROTECTION_ENABLED"
+    "CMD_SUCCESS", "INVALID_COMMAND", "SRC_ADDR_ERROR", "DST_ADDR_ERROR",
+    "SRC_ADDR_NOT_MAPPED", "DST_ADDR_NOT_MAPPED", "COUNT_ERROR", "INVALID_SECTOR",
+    "SECTOR_NOT_BLANK", "SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION", "COMPARE_ERROR",
+    "BUSY", "PARAM_ERROR", "ADDR_ERROR", "ADDR_NOT_MAPPED", "CMD_LOCKED",
+    "INVALID_CODE", "INVALID_BAUD_RATE", "INVALID_STOP_BIT",
+    "CODE_READ_PROTECTION_ENABLED"
 };
 
diff --git a/msba2-common/tools/src/chipinfo.h b/msba2-common/tools/src/chipinfo.h
index 1b12bb366632982a5b59b89c1ad3fba634b5c471..8c49593296c955ffb16f6118ed05638ee79fb2c5 100644
--- a/msba2-common/tools/src/chipinfo.h
+++ b/msba2-common/tools/src/chipinfo.h
@@ -1,18 +1,18 @@
 extern char *lpc_return_strings[];
 
 struct sector_info_struct {	// an array of
-	int address;		// where each sector is located
-	int size;		// and how big it is
+    int address;		// where each sector is located
+    int size;		// and how big it is
 };
 
 struct chip_info_struct {
-	char *part_number;	// human readable part number
-	char *id_string;	// id string sent by "J" command
-	unsigned int ram_addr;	// where to download into RAM
-	int chunk_size;		// download to ram chunk size
-	int num_sector;		// number of flash sectors
-	struct sector_info_struct *layout;  // layout of sectors
-	const unsigned int *bootprog;	// code that boots into user program (NULL = DTR/RTS only)
+    char *part_number;	// human readable part number
+    char *id_string;	// id string sent by "J" command
+    unsigned int ram_addr;	// where to download into RAM
+    int chunk_size;		// download to ram chunk size
+    int num_sector;		// number of flash sectors
+    struct sector_info_struct *layout;  // layout of sectors
+    const unsigned int *bootprog;	// code that boots into user program (NULL = DTR/RTS only)
 };
 
 extern struct chip_info_struct chip_info[];
diff --git a/msba2-common/tools/src/cksum_test.c b/msba2-common/tools/src/cksum_test.c
index 8cff9b55e2fc7f05c5505a679f67d93488f63424..facd6a1f3a9fdd8a9161860d81628ab3e43edcb7 100644
--- a/msba2-common/tools/src/cksum_test.c
+++ b/msba2-common/tools/src/cksum_test.c
@@ -20,7 +20,7 @@
 
 /* If this code fails to build, please provide at least the following
  * information when requesting (free) technical support.
- * 
+ *
  * 1: Complete copy of all messages during the build.
  * 2: Output of "gtk-config --version"
  * 3: Output of "gtk-config --libs"
@@ -38,36 +38,45 @@
 #include "uuencode.h"
 
 
-unsigned int sum=0;
+unsigned int sum = 0;
 
 
 
 void cksum(const char *str)
 {
-	int num, i;
-	unsigned char data[256];
+    int num, i;
+    unsigned char data[256];
+
+    if (str == NULL) {
+        return;
+    }
+
+    num = uudecode(str, data, sizeof(data));
 
-	if (str == NULL) return;
-	num = uudecode(str, data, sizeof(data));
-	for (i=0; i<num; i++) {
-		sum += data[i];
-	}
+    for (i = 0; i < num; i++) {
+        sum += data[i];
+    }
 
 }
 
 
 int main()
 {
-	char buf[4096];
+    char buf[4096];
+
+    while (!feof(stdin)) {
+        fgets(buf, sizeof(buf), stdin);
+
+        if (strcmp(buf, "\n") == 0) {
+            break;
+        }
+
+        cksum(buf);
+    }
 
-	while (!feof(stdin)) {
-		fgets(buf, sizeof(buf), stdin);
-		if (strcmp(buf, "\n") == 0) break;
-		cksum(buf);
-	}
-	printf("sum = %u\n", sum);
+    printf("sum = %u\n", sum);
 
-	return 0;
+    return 0;
 }
 
 
diff --git a/msba2-common/tools/src/control_2xxx.c b/msba2-common/tools/src/control_2xxx.c
index 6843fec2041d7f85f21d20a2b15a687602dd08eb..581dd8e202948c8d5912a542e0095cd0b933cc80 100644
--- a/msba2-common/tools/src/control_2xxx.c
+++ b/msba2-common/tools/src/control_2xxx.c
@@ -8,33 +8,33 @@
 
 void hard_reset_to_bootloader(void)
 {
-/*	Use this lines for flashing a node with interrupted DTR line */
+    /*	Use this lines for flashing a node with interrupted DTR line */
     /*	printf("Press Reset - confirm with anykey\n");
     getchar();
     */
     printf("Reset CPU (into bootloader)\r\n");
-	set_rts(1);		// RTS (ttl level) connects to P0.14
+    set_rts(1);		// RTS (ttl level) connects to P0.14
     /* the next two lines should be commented for the prepared node */
-	set_dtr(1);		// DTR (ttl level) connects to RST
-	send_break_signal();	// or break detect circuit to RST
-	usleep(75000);
+    set_dtr(1);		// DTR (ttl level) connects to RST
+    send_break_signal();	// or break detect circuit to RST
+    usleep(75000);
     /*	Use this lines for flashing a node with interrupted DTR line */
     /* printf("Release Reset - confirm with anykey\n");
     getchar();
     */
-	set_dtr(0);		// allow the CPU to run:
-	set_baud(baud_rate);
-	set_rts(1);		// set RTS again (as it has been reset by set_baudrate) 
-	usleep(40000);
+    set_dtr(0);		// allow the CPU to run:
+    set_baud(baud_rate);
+    set_rts(1);		// set RTS again (as it has been reset by set_baudrate)
+    usleep(40000);
 }
 
 void hard_reset_to_user_code(void)
 {
-	printf("Reset CPU (into user code)\r\n");
-	set_rts(0);		// RTS (ttl level) connects to P0.14
-	set_dtr(1);		// DTR (ttl level) connects to RST
-	send_break_signal();	// or break detect circuit to RST
-	usleep(75000);
-	set_dtr(0);		// allow the CPU to run
-	usleep(40000);
+    printf("Reset CPU (into user code)\r\n");
+    set_rts(0);		// RTS (ttl level) connects to P0.14
+    set_dtr(1);		// DTR (ttl level) connects to RST
+    send_break_signal();	// or break detect circuit to RST
+    usleep(75000);
+    set_dtr(0);		// allow the CPU to run
+    usleep(40000);
 }
diff --git a/msba2-common/tools/src/download.c b/msba2-common/tools/src/download.c
index 5494661dfd55b2cb6c08c9e24fff67a48bc04d91..c7aab543a8174e4b38aef9d9c90f0cb1be0c39a0 100644
--- a/msba2-common/tools/src/download.c
+++ b/msba2-common/tools/src/download.c
@@ -20,7 +20,7 @@
 
 /* If this code fails to build, please provide at least the following
  * information when requesting (free) technical support.
- * 
+ *
  * 1: Complete copy of all messages during the build.
  * 2: Output of "gtk-config --version"
  * 3: Output of "gtk-config --libs"
@@ -60,21 +60,21 @@ static void mk_valid_code_vector(void);
 static unsigned int sum(unsigned char *data, int num);
 
 
-static int state=0;
-static int reboot_only=0;
+static int state = 0;
+static int reboot_only = 0;
 static char expected_echo_buf[4096];
-static char *expected_echo_ptr=NULL;
+static char *expected_echo_ptr = NULL;
 static char parsed_response_buf[4096];
-static char *parsed_response_ptr=NULL;
-static int response_timer=0;
+static char *parsed_response_ptr = NULL;
+static int response_timer = 0;
 
 extern int programming_done;
 extern int done_program(int);
 
 
-char* port_name = "/dev/ttyUSB1";
-char* file_name = "";
-char* crystal = "16";
+char *port_name = "/dev/ttyUSB1";
+char *file_name = "";
+char *crystal = "16";
 
 /****************************************************************/
 /*								*/
@@ -112,107 +112,117 @@ char* crystal = "16";
 
 
 
-int download_begin(char* file)
+int download_begin(char *file)
 {
-	int r;
+    int r;
 
     file_name = file;
 
-	printf("\r\nEntering Bootloader Mode\r\n");
-	hard_reset_to_bootloader();
-	printf("Read \"%s\"", file_name);
-	r = read_intel_hex(file_name);
-	if (r < 0) {
+    printf("\r\nEntering Bootloader Mode\r\n");
+    hard_reset_to_bootloader();
+    printf("Read \"%s\"", file_name);
+    r = read_intel_hex(file_name);
+
+    if (r < 0) {
         /* abort on ioerror */
         return 0;
-	}
-	printf(": %d bytes\r\n", r);
-	mk_valid_code_vector();
-	state = SYNC_1;
-	reboot_only = 0;
-	download_main(BEGIN);
+    }
+
+    printf(": %d bytes\r\n", r);
+    mk_valid_code_vector();
+    state = SYNC_1;
+    reboot_only = 0;
+    download_main(BEGIN);
     return 1;
 }
 
 
 void soft_reboot_begin(void)
 {
-	printf("\r\nEntering Bootloader Mode\r\n");
-	hard_reset_to_bootloader();
-	state = SYNC_1;
-	reboot_only = 1;
-	download_main(BEGIN);
+    printf("\r\nEntering Bootloader Mode\r\n");
+    hard_reset_to_bootloader();
+    state = SYNC_1;
+    reboot_only = 1;
+    download_main(BEGIN);
 }
 
 static void mk_valid_code_vector(void)
 {
-	unsigned char b[4];
-	unsigned int sum=0;
-	int addr;
-
-	for (addr=0; addr<0x20; addr+=4) {
-		if (addr != 0x14) {
-			get_ihex_data(addr, 4, b);
-			sum += (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24));
-		}
-	}
-	sum ^= 0xFFFFFFFF;
-	sum++;
-	b[0] = (sum >> 0) & 255;
-	b[1] = (sum >> 8) & 255;
-	b[2] = (sum >> 16) & 255;
-	b[3] = (sum >> 24) & 255;
-	put_ihex_data(0x14, 4, b);
+    unsigned char b[4];
+    unsigned int sum = 0;
+    int addr;
+
+    for (addr = 0; addr < 0x20; addr += 4) {
+        if (addr != 0x14) {
+            get_ihex_data(addr, 4, b);
+            sum += (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24));
+        }
+    }
+
+    sum ^= 0xFFFFFFFF;
+    sum++;
+    b[0] = (sum >> 0) & 255;
+    b[1] = (sum >> 8) & 255;
+    b[2] = (sum >> 16) & 255;
+    b[3] = (sum >> 24) & 255;
+    put_ihex_data(0x14, 4, b);
 }
 
 
 static unsigned int sum(unsigned char *data, int num)
 {
-	unsigned int sum=0;
+    unsigned int sum = 0;
+
+    while (num > 0) {
+        sum += *data++;
+        num--;
+    }
 
-	while (num > 0) {
-		sum += *data++;
-		num--;
-	}
-	return sum;
+    return sum;
 }
 
 
 static int num_lines(const char *buf)
 {
-	const char *p;
-	int count=0;
-
-	p = buf;
-	while (p != NULL) {
-		p = strstr(p, "\r\n");
-		if (p != NULL) {
-			count++;
-			p += 2;
-		}
-	}
-	return count;
+    const char *p;
+    int count = 0;
+
+    p = buf;
+
+    while (p != NULL) {
+        p = strstr(p, "\r\n");
+
+        if (p != NULL) {
+            count++;
+            p += 2;
+        }
+    }
+
+    return count;
 }
 
 void trim_crlf(char *str)
 {
-	char *p;
-	p = strstr(str, "\r\n");
-	if (p != NULL) *p = '\0';
+    char *p;
+    p = strstr(str, "\r\n");
+
+    if (p != NULL) {
+        *p = '\0';
+    }
 }
 
 void copy_boot_code_to_memory(struct chip_info_struct *chip)
 {
-	int i;
-	unsigned char c[4];
-
-	for (i=0; i < chip->bootprog[0]; i++) {
-		c[3] = (chip->bootprog[i+1] >> 24) & 255;
-		c[2] = (chip->bootprog[i+1] >> 16) & 255;
-		c[1] = (chip->bootprog[i+1] >> 8) & 255;
-		c[0] = (chip->bootprog[i+1]) & 255;
-		put_ihex_data(i * 4, 4, c);
-	}
+    int i;
+    unsigned char c[4];
+
+    for (i = 0; i < chip->bootprog[0]; i++) {
+        c[3] = (chip->bootprog[i + 1] >> 24) & 255;
+        c[2] = (chip->bootprog[i + 1] >> 16) & 255;
+        c[1] = (chip->bootprog[i + 1] >> 8) & 255;
+        c[0] = (chip->bootprog[i + 1]) & 255;
+        put_ihex_data(i * 4, 4, c);
+    }
 }
 
 
@@ -237,596 +247,792 @@ hardware you may be using.  Thanks :-)\r\n"
 
 static void download_main(int event)
 {
-	char buf[4096];
-	unsigned char bytes[256];
-	double xtal;
-	int n;
-	static unsigned int cksum;
-	static int retry=0;
-	static int sector;		// current sector we're doing
-	static int sector_offset;
-	static struct chip_info_struct *chip;	// which chip
-	static int current_addr, num_to_xmit, linecount;
+    char buf[4096];
+    unsigned char bytes[256];
+    double xtal;
+    int n;
+    static unsigned int cksum;
+    static int retry = 0;
+    static int sector;		// current sector we're doing
+    static int sector_offset;
+    static struct chip_info_struct *chip;	// which chip
+    static int current_addr, num_to_xmit, linecount;
 
 
     while (1) {
-	switch (state) {
-	  case SYNC_1:
-		switch (event) {
-		  case BEGIN:
-			printf("Attempting baud sync");
-			retry = 0;
-		  case RETRY:
-			printf(".");
-			fflush(stdout);
-			xmit_cmd("?", 2);
-			return;
-		  case RESPONSE:
-			if (strcmp(parsed_response_buf, "Synchronized\r\n") == 0) {
-				//printf("response: sync'd\n");
-				state = SYNC_2;
-				event = BEGIN;
-				break;
-			}
-			if (strcmp(parsed_response_buf, "?") == 0) {
-				//printf("response: echo only\n");
-				retry++;
-				if (retry > 150) {
-					download_cancel(NO_SYNC_ERR); return;
-				}
-				event = RETRY;
-				usleep(30000);
-				break;
-			}
-			snprintf(buf, sizeof(buf), "Unexpected response to sync, \"%s\"",
-				parsed_response_buf);
-			download_cancel(buf); return;
-		  case TIMEOUT:
-			if (retry < 100) {
-				retry++;
-				event = RETRY;
-				break;
-			}
-			download_cancel(NO_SYNC_ERR);
-			return;
-		}
-		break;
-
-
-	  case SYNC_2:
-		switch(event) {
-		  case BEGIN:
-			xmit_cmd("Synchronized\r\n", 3);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "OK\r\n") == 0) {
-				state = SYNC_3;
-				event = BEGIN;
-				break;
-			} else {
-				snprintf(buf, sizeof(buf), "Unable to complete baud sync, %s",
-					parsed_response_buf);
-				download_cancel(buf); return;
-			}
-			return;
-		  case TIMEOUT:
-			download_cancel("No response to complete baud sync"); return;
-		}
-		break;
-
-
-	  case SYNC_3:
-		switch(event) {
-		  case BEGIN:
-			if (sscanf(crystal, "%lf", &xtal) != 1) {
-				printf("\r\n");
-				download_cancel("Crystal frequency is required for 3rd step of baud rate sync");
-				return;
-			}
-			if (xtal < 10.0 || xtal > 25.0) {
-				printf("\r\n");
-				printf("Warning: crystal frequency out of range (10.0 to 25.0), continuing anyway! (hope you know what you're doing)\r\n");
-			}
-			snprintf(buf, sizeof(buf), "%d\r\n", (int)(xtal * 1000.0 + 0.5));
-			xmit_cmd(buf, 3);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "OK\r\n") == 0) {
-				printf("Baud sync sucessful\r\n");
-				state = CHIP_ID;
-				event = BEGIN;
-				break;
-			} else {
-				snprintf(buf, sizeof(buf), "wrong response to crystal: %s",
-					parsed_response_buf);
-				download_cancel(buf); return;
-			}
-			return;
-		  case TIMEOUT:
-			download_cancel("No response to crystal speed"); return;
-		}
-		break;
-
-
-	  case CHIP_ID:
-		switch(event) {
-		  case BEGIN:
-			xmit_cmd("J\r\n", 3);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) < 2) return;
-			if (strncmp(parsed_response_buf, "0\r\n", 3) == 0) {
-				trim_crlf(parsed_response_buf+3);
-				for (chip=chip_info; chip->part_number != NULL; chip++) {
-					if (strcmp(parsed_response_buf+3, chip->id_string) == 0)
-						break;
-				}
-				if (chip->part_number == NULL) {
-					snprintf(buf, sizeof(buf), UNKNOWN_CHIP_ERROR,
-						parsed_response_buf+3);
-					download_cancel(buf);
-					break;
-				}
-				printf("Found chip: \"%s\"\r\n", chip->part_number);
-				  //download_cancel("stop here, remove this later");
-				state = UNLOCK;
-				event = BEGIN;
-				break;
-			} else {
-				snprintf(buf, sizeof(buf), "wrong response to ID: %s",
-					parsed_response_buf);
-				download_cancel(buf); return;
-			}
-			return;
-		  case TIMEOUT:
-			download_cancel("No response to unlock command"); return;
-		}
-		break;
-
-
-	  case UNLOCK:
-		switch(event) {
-		  case BEGIN:
-			xmit_cmd("U 23130\r\n", 3);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "0\r\n") == 0) {
-				printf("Device Unlocked\r\n");
-				if (reboot_only) {
-					state = BOOT_SOFT;
-				} else {
-					state = BLANK_CHECK_SECTOR;
-					printf("Erasing....\r\n");
-					sector = 0;
-				}
-				event = BEGIN;
-				break;
-			} else {
-				snprintf(buf, sizeof(buf), "wrong response unlock: %s",
-					parsed_response_buf);
-				download_cancel(buf); return;
-			}
-			return;
-		  case TIMEOUT:
-			download_cancel("No response to unlock command"); return;
-		}
-		break;
-
-	
-	  case BLANK_CHECK_SECTOR:
-		switch(event) {
-		  case BEGIN:
-			if (sector >= chip->num_sector) {
-				printf("Programming....\r\n");
-				state = DOWNLOAD_CODE;
-				sector = sector_offset = 0;
-				event = BEGIN;
-				break;
-			}
-			printf("  Sector %2d: ", sector);
-			fflush(stdout);
-			if (!bytes_within_range(chip->layout[sector].address, 
-			   chip->layout[sector].address + chip->layout[sector].size - 1)) {
-				printf("not used\r\n");
-				sector++;
-				break;
-			}
-			if (sector == 0) {
-				// can't blank check sector 0, so always erase it
-				state = ERASE_PREPARE;
-				break;
-			}
-			snprintf(buf, sizeof(buf), "I %d %d\r\n", sector, sector);
-			xmit_cmd(buf, 5);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) == 1 &&
-			  strcmp(parsed_response_buf, "0\r\n") == 0) {
-				printf("already blank\r\n");
-				sector++;
-				event = BEGIN;
-				break;
-			} else {
-				if (num_lines(parsed_response_buf) < 3) return;
-				state = ERASE_PREPARE;
-				event = BEGIN;
-				break;
-			}
-		  case TIMEOUT:
-			download_cancel("No response to blank check"); return;
-		}
-		break;
-
-
-
-	  case ERASE_PREPARE:
-		switch(event) {
-		  case BEGIN:
-			printf("prep, ");
-			fflush(stdout);
-			snprintf(buf, sizeof(buf), "P %d %d\r\n", sector, sector);
-			xmit_cmd(buf, 8);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "0\r\n") == 0) {
-				state = ERASE_SECTOR;
-				event = BEGIN;
-				break;
-			} else {
-				download_cancel("Unable to prep for write"); return;
-			}
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-
-	  case ERASE_SECTOR:
-		switch(event) {
-		  case BEGIN:
-			printf("erase... ");
-			fflush(stdout);
-			snprintf(buf, sizeof(buf), "E %d %d\r\n", sector, sector);
-			xmit_cmd(buf, 25);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) < 1) return;
-			if (strcmp(parsed_response_buf, "0\r\n") == 0) {
-				printf("Ok\r\n");
-				sector++;
-				state = BLANK_CHECK_SECTOR;
-				event = BEGIN;
-				break;
-			} else {
-				printf("Error\r\n");
-				download_cancel("Unable to erase flash"); return;
-			}
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-
-	  case DOWNLOAD_CODE:
-		switch(event) {
-		  case BEGIN:
-			if (sector >= chip->num_sector) {
-				state = BOOT_HARD;
-				sector = 0;
-				event = BEGIN;
-				break;
-			}
-			printf("  Sector %2d (0x%08X-0x%08X): ", sector,
-				chip->layout[sector].address + sector_offset,
-				chip->layout[sector].address + sector_offset + chip->chunk_size - 1);
-			fflush(stdout);
-			if (!bytes_within_range(chip->layout[sector].address + sector_offset, 
-			   chip->layout[sector].address + sector_offset + chip->chunk_size - 1)) {
-				printf("not used\r\n");
-				sector_offset += chip->chunk_size;
-				if (sector_offset >= chip->layout[sector].size) {
-					sector_offset = 0;
-					sector++;
-				}
-				break;
-			}
-			snprintf(buf, sizeof(buf), "W %d %d\r\n", chip->ram_addr, chip->chunk_size);
-			xmit_cmd(buf, 4);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "0\r\n") == 0) {
-				state = XMIT_DATA;
-				printf("xmit");
-				current_addr = chip->layout[sector].address + sector_offset;
-				num_to_xmit = chip->chunk_size;
-				linecount = 0;
-				cksum = 0;
-				event = BEGIN;
-				break;
-			} else {
-				download_cancel("can't xmit to ram"); return;
-			}
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-	  case XMIT_DATA:
-		switch(event) {
-		  case BEGIN:
-			n = num_to_xmit;
-			if (n > 45) n = 45;
-			get_ihex_data(current_addr, n, bytes);
-			cksum += sum(bytes, n);
-			uuencode(buf, bytes, n);
-			current_addr += n;
-			num_to_xmit -= n;
-			linecount++;
-			xmit_cmd(buf, 5);
-			write_serial_port("\r\n", 2);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "\r\n") == 0) {
-				if (linecount >= 20 || num_to_xmit <= 0) {
-					state = XMIT_CKSUM;
-				}
-				event = BEGIN;
-				break;
-			} else {
-				download_cancel("data xmit did not echo"); return;
-			}
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-	  case XMIT_CKSUM:
-		switch(event) {
-		  case BEGIN:
-			snprintf(buf, sizeof(buf), "%d\r\n", cksum);
-			xmit_cmd(buf, 3);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "OK\r\n") == 0) {
-				if (num_to_xmit > 0) {
-					printf(".");
-					fflush(stdout);
-					state = XMIT_DATA;
-					event = BEGIN;
-					linecount = 0;
-					cksum = 0;
-					break;
-				}
-				state = WRITE_PREPARE;
-				event = BEGIN;
-				break;
-			} else {
-				download_cancel("bad checksum"); return;
-			}
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-	  case WRITE_PREPARE:
-		switch(event) {
-		  case BEGIN:
-			printf("prep, ");
-			fflush(stdout);
-			snprintf(buf, sizeof(buf), "P %d %d\r\n", sector, sector);
-			xmit_cmd(buf, 5);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "0\r\n") == 0) {
-				state = WRITE_SECTOR;
-				event = BEGIN;
-				break;
-			} else {
-				download_cancel("Unable to prep for write"); return;
-			}
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-	  case WRITE_SECTOR:
-		switch(event) {
-		  case BEGIN:
-			printf("write, ");
-			fflush(stdout);
-			snprintf(buf, sizeof(buf), "C %d %d %d\r\n",
-				chip->layout[sector].address + sector_offset,
-				chip->ram_addr, chip->chunk_size);
-			xmit_cmd(buf, 5);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "0\r\n") == 0) {
-				printf("Ok\r\n");
-				sector_offset += chip->chunk_size;
-				if (sector_offset >= chip->layout[sector].size) {
-					sector_offset = 0;
-					sector++;
-				}
-				state = DOWNLOAD_CODE;
-				event = BEGIN;
-			} else {
-				download_cancel("Unable to prep for write"); return;
-			}
-			break;
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-	  case BOOT_HARD:
-	//	if (chip->bootprog) {
-	//		state = BOOT_SOFT;
-	//		break;
-	//	} else {
-			printf("Booting (hardware reset)...\r\n\r\n");
-			hard_reset_to_user_code();
-			done_program(0);
-			return;
-	//	}
-
-	  case BOOT_SOFT:
-		switch(event) {
-		  case BEGIN:
-			printf("Booting (soft jump)...\r\n");
-			printf("loading jump code\r\n");
-			// would be nice if we could simply jump to the user's code, but
-			// Philips didn't think of that.  The interrupt vector table stays
-			// mapped to the bootloader, so jumping to zero only runs the
-			// bootloader again.  Intead, we need to download a tiny ARM
-			// program that reconfigures the hardware and then jumps to zero.
-			//snprintf(buf, sizeof(buf), "G %d A\r\n", 0);
-			snprintf(buf, sizeof(buf), "W %d %d\r\n", chip->ram_addr, chip->bootprog[0] * 4);
-			xmit_cmd(buf, 4);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) < 1) return;
-			if (strcmp(parsed_response_buf, "0\r\n") == 0) {
-				current_addr = 0;
-				num_to_xmit = chip->bootprog[0] * 4;
-				copy_boot_code_to_memory(chip);
-				linecount = 0;
-				cksum = 0;
-				state = BOOT_XMIT_DATA;
-				event = BEGIN;
-			} else {
-				download_cancel("can't xmit to ram"); return;
-			}
-			break;
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-	  case BOOT_XMIT_DATA:
-		switch(event) {
-		  case BEGIN:
-			n = num_to_xmit;
-			if (n > 45) n = 45;
-			get_ihex_data(current_addr, n, bytes);
-			cksum += sum(bytes, n);
-			uuencode(buf, bytes, n);
-			current_addr += n;
-			num_to_xmit -= n;
-			linecount++;
-			//printf("send: %s\r\n", buf);
-			xmit_cmd(buf, 5);
-			write_serial_port("\r\n", 2);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "\r\n") == 0) {
-				if (linecount >= 20 || num_to_xmit <= 0) {
-					state = BOOT_XMIT_CKSUM;
-				}
-				event = BEGIN;
-				break;
-			} else {
-				download_cancel("data xmit did not echo"); return;
-			}
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-	  case BOOT_XMIT_CKSUM:
-		switch(event) {
-		  case BEGIN:
-			snprintf(buf, sizeof(buf), "%d\r\n", cksum);
-			//printf("send: %s", buf);
-			xmit_cmd(buf, 3);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) != 1) return;
-			if (strcmp(parsed_response_buf, "OK\r\n") == 0) {
-				if (num_to_xmit > 0) {
-					printf(".");
-					fflush(stdout);
-					state = BOOT_XMIT_DATA;
-					event = BEGIN;
-					linecount = 0;
-					cksum = 0;
-					break;
-				}
-				state = BOOT_RUN_CODE;
-				event = BEGIN;
-				break;
-			} else {
-				download_cancel("bad checksum"); return;
-			}
-		  case TIMEOUT:
-			download_cancel("No response"); return;
-		}
-		break;
-
-
-	  case BOOT_RUN_CODE:
-		switch(event) {
-		  case BEGIN:
-			printf("jumping now!\r\n");
-			snprintf(buf, sizeof(buf), "G %d A\r\n", chip->ram_addr);
-			xmit_cmd(buf, 4);
-			return;
-		  case RESPONSE:
-			if (num_lines(parsed_response_buf) < 1) return;
-			if (strcmp(parsed_response_buf, "0\r\n") == 0) {
-				done_program(0);
-				return;
-			} else {
-				printf("response = %s", parsed_response_buf);
-				download_cancel("couldn't run program"); return;
-			}
-			break;
-		  case TIMEOUT:
-			done_program(0);
-			return;
-			// Philips user name says it responds, but it does not.
-			// It seems to just immediately jump to the code without
-			// any "0" response.
-			//download_cancel("No response"); return;
-		}
-		break;
-
-
-
-	  default:
-		  snprintf(buf, sizeof(buf), "unknown state %d\r\n", state);
-		  download_cancel(buf);
-		  return;
-	}
+        switch (state) {
+            case SYNC_1:
+                switch (event) {
+                    case BEGIN:
+                        printf("Attempting baud sync");
+                        retry = 0;
+
+                    case RETRY:
+                        printf(".");
+                        fflush(stdout);
+                        xmit_cmd("?", 2);
+                        return;
+
+                    case RESPONSE:
+                        if (strcmp(parsed_response_buf, "Synchronized\r\n") == 0) {
+                            //printf("response: sync'd\n");
+                            state = SYNC_2;
+                            event = BEGIN;
+                            break;
+                        }
+
+                        if (strcmp(parsed_response_buf, "?") == 0) {
+                            //printf("response: echo only\n");
+                            retry++;
+
+                            if (retry > 150) {
+                                download_cancel(NO_SYNC_ERR);
+                                return;
+                            }
+
+                            event = RETRY;
+                            usleep(30000);
+                            break;
+                        }
+
+                        snprintf(buf, sizeof(buf), "Unexpected response to sync, \"%s\"",
+                                 parsed_response_buf);
+                        download_cancel(buf);
+                        return;
+
+                    case TIMEOUT:
+                        if (retry < 100) {
+                            retry++;
+                            event = RETRY;
+                            break;
+                        }
+
+                        download_cancel(NO_SYNC_ERR);
+                        return;
+                }
+
+                break;
+
+
+            case SYNC_2:
+                switch (event) {
+                    case BEGIN:
+                        xmit_cmd("Synchronized\r\n", 3);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "OK\r\n") == 0) {
+                            state = SYNC_3;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            snprintf(buf, sizeof(buf), "Unable to complete baud sync, %s",
+                                     parsed_response_buf);
+                            download_cancel(buf);
+                            return;
+                        }
+
+                        return;
+
+                    case TIMEOUT:
+                        download_cancel("No response to complete baud sync");
+                        return;
+                }
+
+                break;
+
+
+            case SYNC_3:
+                switch (event) {
+                    case BEGIN:
+                        if (sscanf(crystal, "%lf", &xtal) != 1) {
+                            printf("\r\n");
+                            download_cancel("Crystal frequency is required for 3rd step of baud rate sync");
+                            return;
+                        }
+
+                        if (xtal < 10.0 || xtal > 25.0) {
+                            printf("\r\n");
+                            printf("Warning: crystal frequency out of range (10.0 to 25.0), continuing anyway! (hope you know what you're doing)\r\n");
+                        }
+
+                        snprintf(buf, sizeof(buf), "%d\r\n", (int)(xtal * 1000.0 + 0.5));
+                        xmit_cmd(buf, 3);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "OK\r\n") == 0) {
+                            printf("Baud sync sucessful\r\n");
+                            state = CHIP_ID;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            snprintf(buf, sizeof(buf), "wrong response to crystal: %s",
+                                     parsed_response_buf);
+                            download_cancel(buf);
+                            return;
+                        }
+
+                        return;
+
+                    case TIMEOUT:
+                        download_cancel("No response to crystal speed");
+                        return;
+                }
+
+                break;
+
+
+            case CHIP_ID:
+                switch (event) {
+                    case BEGIN:
+                        xmit_cmd("J\r\n", 3);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) < 2) {
+                            return;
+                        }
+
+                        if (strncmp(parsed_response_buf, "0\r\n", 3) == 0) {
+                            trim_crlf(parsed_response_buf + 3);
+
+                            for (chip = chip_info; chip->part_number != NULL; chip++) {
+                                if (strcmp(parsed_response_buf + 3, chip->id_string) == 0) {
+                                    break;
+                                }
+                            }
+
+                            if (chip->part_number == NULL) {
+                                snprintf(buf, sizeof(buf), UNKNOWN_CHIP_ERROR,
+                                         parsed_response_buf + 3);
+                                download_cancel(buf);
+                                break;
+                            }
+
+                            printf("Found chip: \"%s\"\r\n", chip->part_number);
+                            //download_cancel("stop here, remove this later");
+                            state = UNLOCK;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            snprintf(buf, sizeof(buf), "wrong response to ID: %s",
+                                     parsed_response_buf);
+                            download_cancel(buf);
+                            return;
+                        }
+
+                        return;
+
+                    case TIMEOUT:
+                        download_cancel("No response to unlock command");
+                        return;
+                }
+
+                break;
+
+
+            case UNLOCK:
+                switch (event) {
+                    case BEGIN:
+                        xmit_cmd("U 23130\r\n", 3);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            printf("Device Unlocked\r\n");
+
+                            if (reboot_only) {
+                                state = BOOT_SOFT;
+                            }
+                            else {
+                                state = BLANK_CHECK_SECTOR;
+                                printf("Erasing....\r\n");
+                                sector = 0;
+                            }
+
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            snprintf(buf, sizeof(buf), "wrong response unlock: %s",
+                                     parsed_response_buf);
+                            download_cancel(buf);
+                            return;
+                        }
+
+                        return;
+
+                    case TIMEOUT:
+                        download_cancel("No response to unlock command");
+                        return;
+                }
+
+                break;
+
+
+            case BLANK_CHECK_SECTOR:
+                switch (event) {
+                    case BEGIN:
+                        if (sector >= chip->num_sector) {
+                            printf("Programming....\r\n");
+                            state = DOWNLOAD_CODE;
+                            sector = sector_offset = 0;
+                            event = BEGIN;
+                            break;
+                        }
+
+                        printf("  Sector %2d: ", sector);
+                        fflush(stdout);
+
+                        if (!bytes_within_range(chip->layout[sector].address,
+                                                chip->layout[sector].address + chip->layout[sector].size - 1)) {
+                            printf("not used\r\n");
+                            sector++;
+                            break;
+                        }
+
+                        if (sector == 0) {
+                            // can't blank check sector 0, so always erase it
+                            state = ERASE_PREPARE;
+                            break;
+                        }
+
+                        snprintf(buf, sizeof(buf), "I %d %d\r\n", sector, sector);
+                        xmit_cmd(buf, 5);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) == 1 &&
+                            strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            printf("already blank\r\n");
+                            sector++;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            if (num_lines(parsed_response_buf) < 3) {
+                                return;
+                            }
+
+                            state = ERASE_PREPARE;
+                            event = BEGIN;
+                            break;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response to blank check");
+                        return;
+                }
+
+                break;
+
+
+
+            case ERASE_PREPARE:
+                switch (event) {
+                    case BEGIN:
+                        printf("prep, ");
+                        fflush(stdout);
+                        snprintf(buf, sizeof(buf), "P %d %d\r\n", sector, sector);
+                        xmit_cmd(buf, 8);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            state = ERASE_SECTOR;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            download_cancel("Unable to prep for write");
+                            return;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+
+            case ERASE_SECTOR:
+                switch (event) {
+                    case BEGIN:
+                        printf("erase... ");
+                        fflush(stdout);
+                        snprintf(buf, sizeof(buf), "E %d %d\r\n", sector, sector);
+                        xmit_cmd(buf, 25);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) < 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            printf("Ok\r\n");
+                            sector++;
+                            state = BLANK_CHECK_SECTOR;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            printf("Error\r\n");
+                            download_cancel("Unable to erase flash");
+                            return;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+
+            case DOWNLOAD_CODE:
+                switch (event) {
+                    case BEGIN:
+                        if (sector >= chip->num_sector) {
+                            state = BOOT_HARD;
+                            sector = 0;
+                            event = BEGIN;
+                            break;
+                        }
+
+                        printf("  Sector %2d (0x%08X-0x%08X): ", sector,
+                               chip->layout[sector].address + sector_offset,
+                               chip->layout[sector].address + sector_offset + chip->chunk_size - 1);
+                        fflush(stdout);
+
+                        if (!bytes_within_range(chip->layout[sector].address + sector_offset,
+                                                chip->layout[sector].address + sector_offset + chip->chunk_size - 1)) {
+                            printf("not used\r\n");
+                            sector_offset += chip->chunk_size;
+
+                            if (sector_offset >= chip->layout[sector].size) {
+                                sector_offset = 0;
+                                sector++;
+                            }
+
+                            break;
+                        }
+
+                        snprintf(buf, sizeof(buf), "W %d %d\r\n", chip->ram_addr, chip->chunk_size);
+                        xmit_cmd(buf, 4);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            state = XMIT_DATA;
+                            printf("xmit");
+                            current_addr = chip->layout[sector].address + sector_offset;
+                            num_to_xmit = chip->chunk_size;
+                            linecount = 0;
+                            cksum = 0;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            download_cancel("can't xmit to ram");
+                            return;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+            case XMIT_DATA:
+                switch (event) {
+                    case BEGIN:
+                        n = num_to_xmit;
+
+                        if (n > 45) {
+                            n = 45;
+                        }
+
+                        get_ihex_data(current_addr, n, bytes);
+                        cksum += sum(bytes, n);
+                        uuencode(buf, bytes, n);
+                        current_addr += n;
+                        num_to_xmit -= n;
+                        linecount++;
+                        xmit_cmd(buf, 5);
+                        write_serial_port("\r\n", 2);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "\r\n") == 0) {
+                            if (linecount >= 20 || num_to_xmit <= 0) {
+                                state = XMIT_CKSUM;
+                            }
+
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            download_cancel("data xmit did not echo");
+                            return;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+            case XMIT_CKSUM:
+                switch (event) {
+                    case BEGIN:
+                        snprintf(buf, sizeof(buf), "%d\r\n", cksum);
+                        xmit_cmd(buf, 3);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "OK\r\n") == 0) {
+                            if (num_to_xmit > 0) {
+                                printf(".");
+                                fflush(stdout);
+                                state = XMIT_DATA;
+                                event = BEGIN;
+                                linecount = 0;
+                                cksum = 0;
+                                break;
+                            }
+
+                            state = WRITE_PREPARE;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            download_cancel("bad checksum");
+                            return;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+            case WRITE_PREPARE:
+                switch (event) {
+                    case BEGIN:
+                        printf("prep, ");
+                        fflush(stdout);
+                        snprintf(buf, sizeof(buf), "P %d %d\r\n", sector, sector);
+                        xmit_cmd(buf, 5);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            state = WRITE_SECTOR;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            download_cancel("Unable to prep for write");
+                            return;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+            case WRITE_SECTOR:
+                switch (event) {
+                    case BEGIN:
+                        printf("write, ");
+                        fflush(stdout);
+                        snprintf(buf, sizeof(buf), "C %d %d %d\r\n",
+                                 chip->layout[sector].address + sector_offset,
+                                 chip->ram_addr, chip->chunk_size);
+                        xmit_cmd(buf, 5);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            printf("Ok\r\n");
+                            sector_offset += chip->chunk_size;
+
+                            if (sector_offset >= chip->layout[sector].size) {
+                                sector_offset = 0;
+                                sector++;
+                            }
+
+                            state = DOWNLOAD_CODE;
+                            event = BEGIN;
+                        }
+                        else {
+                            download_cancel("Unable to prep for write");
+                            return;
+                        }
+
+                        break;
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+            case BOOT_HARD:
+                //	if (chip->bootprog) {
+                //		state = BOOT_SOFT;
+                //		break;
+                //	} else {
+                printf("Booting (hardware reset)...\r\n\r\n");
+                hard_reset_to_user_code();
+                done_program(0);
+                return;
+                //	}
+
+            case BOOT_SOFT:
+                switch (event) {
+                    case BEGIN:
+                        printf("Booting (soft jump)...\r\n");
+                        printf("loading jump code\r\n");
+                        // would be nice if we could simply jump to the user's code, but
+                        // Philips didn't think of that.  The interrupt vector table stays
+                        // mapped to the bootloader, so jumping to zero only runs the
+                        // bootloader again.  Intead, we need to download a tiny ARM
+                        // program that reconfigures the hardware and then jumps to zero.
+                        //snprintf(buf, sizeof(buf), "G %d A\r\n", 0);
+                        snprintf(buf, sizeof(buf), "W %d %d\r\n", chip->ram_addr, chip->bootprog[0] * 4);
+                        xmit_cmd(buf, 4);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) < 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            current_addr = 0;
+                            num_to_xmit = chip->bootprog[0] * 4;
+                            copy_boot_code_to_memory(chip);
+                            linecount = 0;
+                            cksum = 0;
+                            state = BOOT_XMIT_DATA;
+                            event = BEGIN;
+                        }
+                        else {
+                            download_cancel("can't xmit to ram");
+                            return;
+                        }
+
+                        break;
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+            case BOOT_XMIT_DATA:
+                switch (event) {
+                    case BEGIN:
+                        n = num_to_xmit;
+
+                        if (n > 45) {
+                            n = 45;
+                        }
+
+                        get_ihex_data(current_addr, n, bytes);
+                        cksum += sum(bytes, n);
+                        uuencode(buf, bytes, n);
+                        current_addr += n;
+                        num_to_xmit -= n;
+                        linecount++;
+                        //printf("send: %s\r\n", buf);
+                        xmit_cmd(buf, 5);
+                        write_serial_port("\r\n", 2);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "\r\n") == 0) {
+                            if (linecount >= 20 || num_to_xmit <= 0) {
+                                state = BOOT_XMIT_CKSUM;
+                            }
+
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            download_cancel("data xmit did not echo");
+                            return;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+            case BOOT_XMIT_CKSUM:
+                switch (event) {
+                    case BEGIN:
+                        snprintf(buf, sizeof(buf), "%d\r\n", cksum);
+                        //printf("send: %s", buf);
+                        xmit_cmd(buf, 3);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) != 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "OK\r\n") == 0) {
+                            if (num_to_xmit > 0) {
+                                printf(".");
+                                fflush(stdout);
+                                state = BOOT_XMIT_DATA;
+                                event = BEGIN;
+                                linecount = 0;
+                                cksum = 0;
+                                break;
+                            }
+
+                            state = BOOT_RUN_CODE;
+                            event = BEGIN;
+                            break;
+                        }
+                        else {
+                            download_cancel("bad checksum");
+                            return;
+                        }
+
+                    case TIMEOUT:
+                        download_cancel("No response");
+                        return;
+                }
+
+                break;
+
+
+            case BOOT_RUN_CODE:
+                switch (event) {
+                    case BEGIN:
+                        printf("jumping now!\r\n");
+                        snprintf(buf, sizeof(buf), "G %d A\r\n", chip->ram_addr);
+                        xmit_cmd(buf, 4);
+                        return;
+
+                    case RESPONSE:
+                        if (num_lines(parsed_response_buf) < 1) {
+                            return;
+                        }
+
+                        if (strcmp(parsed_response_buf, "0\r\n") == 0) {
+                            done_program(0);
+                            return;
+                        }
+                        else {
+                            printf("response = %s", parsed_response_buf);
+                            download_cancel("couldn't run program");
+                            return;
+                        }
+
+                        break;
+
+                    case TIMEOUT:
+                        done_program(0);
+                        return;
+                        // Philips user name says it responds, but it does not.
+                        // It seems to just immediately jump to the code without
+                        // any "0" response.
+                        //download_cancel("No response"); return;
+                }
+
+                break;
+
+
+
+            default:
+                snprintf(buf, sizeof(buf), "unknown state %d\r\n", state);
+                download_cancel(buf);
+                return;
+        }
     }
 }
 
 
 void download_cancel(const char *mesg)
 {
-	printf("\r\nDownload Canceled");
-	if (mesg && *mesg) printf(": %s", mesg);
-	printf("\r\n");
-	// need to do some cleanup for various states???
-	done_program(1);
+    printf("\r\nDownload Canceled");
+
+    if (mesg && *mesg) {
+        printf(": %s", mesg);
+    }
+
+    printf("\r\n");
+    // need to do some cleanup for various states???
+    done_program(1);
 }
 
 
@@ -840,28 +1046,33 @@ void download_cancel(const char *mesg)
 
 static void xmit_cmd(const char *cmd, int max_time)
 {
-	int len;
+    int len;
+
+    if (cmd == NULL || *cmd == '\0') {
+        return;
+    }
 
-	if (cmd == NULL || *cmd == '\0') return;
-	len = strlen(cmd);
+    len = strlen(cmd);
 
 #ifdef PRINT_TX_RX_BYTES
-	printf("tx %d bytes: %s\n", len, cmd);
+    printf("tx %d bytes: %s\n", len, cmd);
 #endif
 
-	input_flush_serial_port();
+    input_flush_serial_port();
+
+    write_serial_port(cmd, len);
 
-	write_serial_port(cmd, len);
+    snprintf(expected_echo_buf, sizeof(expected_echo_buf), "%s", cmd);
 
-	snprintf(expected_echo_buf, sizeof(expected_echo_buf), "%s", cmd);
-	if (state == SYNC_1) {
-		// special case, baud sync doesn't echo
-		expected_echo_buf[0] = '\0';
-	}
-	expected_echo_ptr = expected_echo_buf;
-	parsed_response_ptr = parsed_response_buf;
+    if (state == SYNC_1) {
+        // special case, baud sync doesn't echo
+        expected_echo_buf[0] = '\0';
+    }
 
-	response_timer = max_time;
+    expected_echo_ptr = expected_echo_buf;
+    parsed_response_ptr = parsed_response_buf;
+
+    response_timer = max_time;
 }
 
 
@@ -883,61 +1094,70 @@ event.
 */
 void download_rx_port(const unsigned char *buf, int num)
 {
-	int i=0;
+    int i = 0;
 
-	if (num <= 0) return;
+    if (num <= 0) {
+        return;
+    }
 
-	// echo the data
-	//write(term_fd, buf, num);
+    // echo the data
+    //write(term_fd, buf, num);
 
 #ifdef PRINT_TX_RX_BYTES
-	printf("rx %d bytes:", num);
-	for (i=0; i<num; i++) {
-		printf(" %02X", *(buf + i));
-	}
-	printf("\r\n");
+    printf("rx %d bytes:", num);
+
+    for (i = 0; i < num; i++) {
+        printf(" %02X", *(buf + i));
+    }
+
+    printf("\r\n");
 #endif
 
-	// ignore extra incoming garbage we didn't expect
-	if (expected_echo_ptr == NULL) return;
-
-	// special case, echo of '?' during unsuccessful sync
-	if (state == SYNC_1 && num == 1 && buf[0] == '?') {
-		*parsed_response_ptr++ = '?';
-		*parsed_response_ptr = '\0';
-		response_timer = 0;
-		download_main(RESPONSE);
-		return;
-	}
-
-	// parse it
-	for (i=0; i<num; i++) {
-		// if we're still expecting the echo, gobble it up
-		if (*expected_echo_ptr) {
-			if (buf[i] != *expected_echo_ptr) {
+    // ignore extra incoming garbage we didn't expect
+    if (expected_echo_ptr == NULL) {
+        return;
+    }
+
+    // special case, echo of '?' during unsuccessful sync
+    if (state == SYNC_1 && num == 1 && buf[0] == '?') {
+        *parsed_response_ptr++ = '?';
+        *parsed_response_ptr = '\0';
+        response_timer = 0;
+        download_main(RESPONSE);
+        return;
+    }
+
+    // parse it
+    for (i = 0; i < num; i++) {
+        // if we're still expecting the echo, gobble it up
+        if (*expected_echo_ptr) {
+            if (buf[i] != *expected_echo_ptr) {
 #ifdef PRINT_TX_RX_BYTES
-				printf("  <echo_err>  ");
+                printf("  <echo_err>  ");
 #endif
-				// ignore incorrect echo (will timeout)
-				expected_echo_ptr = NULL;
-				return;
-			}
-			expected_echo_ptr++;
-			continue;
-		}
-		// store this into a parsed response buffer
-		*parsed_response_ptr++ = buf[i];
-	}
-
-	// if the last two characters of the response are "\r\n",
-	// then it's likely we've got a complete response.
-	*parsed_response_ptr = '\0';
-	if (parsed_response_ptr > parsed_response_buf + 1
-	   && *(parsed_response_ptr - 2) == '\r'
-	   && *(parsed_response_ptr - 1) == '\n') {
-		//response_timer = 0;
-		download_main(RESPONSE);
-	}
+                // ignore incorrect echo (will timeout)
+                expected_echo_ptr = NULL;
+                return;
+            }
+
+            expected_echo_ptr++;
+            continue;
+        }
+
+        // store this into a parsed response buffer
+        *parsed_response_ptr++ = buf[i];
+    }
+
+    // if the last two characters of the response are "\r\n",
+    // then it's likely we've got a complete response.
+    *parsed_response_ptr = '\0';
+
+    if (parsed_response_ptr > parsed_response_buf + 1
+        && *(parsed_response_ptr - 2) == '\r'
+        && *(parsed_response_ptr - 1) == '\n') {
+        //response_timer = 0;
+        download_main(RESPONSE);
+    }
 }
 
 
@@ -949,13 +1169,14 @@ is initialized to the maximum time we will wait.
 */
 void download_timer(void)
 {
-	if (response_timer > 0) {
-		response_timer--;
-		if (response_timer == 0) {
-			expected_echo_ptr = NULL;
-			download_main(TIMEOUT);
-		}
-	}
+    if (response_timer > 0) {
+        response_timer--;
+
+        if (response_timer == 0) {
+            expected_echo_ptr = NULL;
+            download_main(TIMEOUT);
+        }
+    }
 }
 
 /*
@@ -964,9 +1185,9 @@ to this function, instead of passing it to xterm for display
 */
 void download_rx_term(const unsigned char *buf, int num)
 {
-	// discard anything the user types into the terminal
-	// while we are in the middle of downloading.  Maybe
-	// we should look for CTRL-C and abort??
+    // discard anything the user types into the terminal
+    // while we are in the middle of downloading.  Maybe
+    // we should look for CTRL-C and abort??
 }
 
 
diff --git a/msba2-common/tools/src/download.h b/msba2-common/tools/src/download.h
index 4d57bfa5d05f91dc859947237ed2a344ed49b6df..b6b961049f224822dd021d8b8ff987049c7e519b 100644
--- a/msba2-common/tools/src/download.h
+++ b/msba2-common/tools/src/download.h
@@ -1,4 +1,4 @@
-extern int download_begin(char* file);
+extern int download_begin(char *file);
 extern void soft_reboot_begin(void);
 extern void hard_reset_to_bootloader(void);
 extern void hard_reset_to_user_code(void);
diff --git a/msba2-common/tools/src/gui.c b/msba2-common/tools/src/gui.c
index ce6d13c96e68d11d9a6222d10a9e4f74d64d2c19..0d4b18d8da3a7ff882eb1d0cc9c977cc7d9dd419 100644
--- a/msba2-common/tools/src/gui.c
+++ b/msba2-common/tools/src/gui.c
@@ -20,7 +20,7 @@
 
 /* If this code fails to build, please provide at least the following
  * information when requesting (free) technical support.
- * 
+ *
  * 1: Complete copy of all messages during the build.
  * 2: Output of "gtk-config --version"
  * 3: Output of "gtk-config --libs"
@@ -55,333 +55,368 @@ static GtkWidget *reboot_button, *bootloader_button, *quit_button;
 static GtkWidget *line1_hbox, *line2_hbox, *line3_hbox, *line4_hbox;
 static GtkWidget *main_vbox, *main_window;
 
-static int port_timeout=0;
-static int baud_timeout=0;
-static int download_in_progress=0;
+static int port_timeout = 0;
+static int baud_timeout = 0;
+static int download_in_progress = 0;
 
 gint do_quit(GtkWidget *widget, gpointer *data)
 {
-	gtk_main_quit();
-	return FALSE;
+    gtk_main_quit();
+    return FALSE;
 }
 
 gint do_program(GtkWidget *widget, gpointer *data)
 {
-	if (download_in_progress) {
-		// error... not supposed to get here
-		gtk_widget_set_sensitive(program_button, FALSE);
-		return FALSE;
-	}
-	download_in_progress = 1;
-	gtk_widget_set_sensitive(program_button, FALSE);
-	gtk_widget_set_sensitive(reboot_button, FALSE);
-	gtk_widget_set_sensitive(bootloader_button, TRUE);
-	download_begin();
-	return FALSE;
+    if (download_in_progress) {
+        // error... not supposed to get here
+        gtk_widget_set_sensitive(program_button, FALSE);
+        return FALSE;
+    }
+
+    download_in_progress = 1;
+    gtk_widget_set_sensitive(program_button, FALSE);
+    gtk_widget_set_sensitive(reboot_button, FALSE);
+    gtk_widget_set_sensitive(bootloader_button, TRUE);
+    download_begin();
+    return FALSE;
 }
 
 int file_exists(const char *filename)
 {
-	struct stat file_stats;
-	int r;
+    struct stat file_stats;
+    int r;
+
+    r = stat(filename, &file_stats);
+
+    if (r != 0) {
+        return 0;
+    }
 
-	r = stat(filename, &file_stats);
-	if (r != 0) return 0;
-	if (!S_ISREG(file_stats.st_mode)) return 0;
-	return 1;
+    if (!S_ISREG(file_stats.st_mode)) {
+        return 0;
+    }
+
+    return 1;
 }
 
 void done_program(int still_in_bootloader)
 {
-	download_in_progress = 0;
-
-	if (file_exists(gtk_entry_get_text(GTK_ENTRY(firmware_entry)))) {
-		gtk_widget_set_sensitive(program_button, TRUE);
-	} else {
-		gtk_widget_set_sensitive(program_button, FALSE);
-	}
-	gtk_widget_set_sensitive(bootloader_button, TRUE);
-	gtk_widget_set_sensitive(reboot_button, TRUE);
+    download_in_progress = 0;
+
+    if (file_exists(gtk_entry_get_text(GTK_ENTRY(firmware_entry)))) {
+        gtk_widget_set_sensitive(program_button, TRUE);
+    }
+    else {
+        gtk_widget_set_sensitive(program_button, FALSE);
+    }
+
+    gtk_widget_set_sensitive(bootloader_button, TRUE);
+    gtk_widget_set_sensitive(reboot_button, TRUE);
 }
 
 gint do_reboot(GtkWidget *widget, gpointer *data)
 {
-	if (download_in_progress) {
-		download_cancel(NULL);
-		gtk_widget_set_sensitive(program_button, FALSE);
-		gtk_widget_set_sensitive(reboot_button, FALSE);
-		gtk_widget_set_sensitive(bootloader_button, FALSE);
-	}
-	gtk_widget_set_sensitive(program_button, FALSE);
-	gtk_widget_set_sensitive(reboot_button, FALSE);
-	gtk_widget_set_sensitive(bootloader_button, FALSE);
-
-	hard_reset_to_user_code();
+    if (download_in_progress) {
+        download_cancel(NULL);
+        gtk_widget_set_sensitive(program_button, FALSE);
+        gtk_widget_set_sensitive(reboot_button, FALSE);
+        gtk_widget_set_sensitive(bootloader_button, FALSE);
+    }
+
+    gtk_widget_set_sensitive(program_button, FALSE);
+    gtk_widget_set_sensitive(reboot_button, FALSE);
+    gtk_widget_set_sensitive(bootloader_button, FALSE);
+
+    hard_reset_to_user_code();
 
 #if 0
-	download_in_progress = 1;
-	soft_reboot_begin();
+    download_in_progress = 1;
+    soft_reboot_begin();
 #endif
-	if (file_exists(gtk_entry_get_text(GTK_ENTRY(firmware_entry)))) {
-		gtk_widget_set_sensitive(program_button, TRUE);
-	} else {
-		gtk_widget_set_sensitive(program_button, FALSE);
-	}
-	gtk_widget_set_sensitive(bootloader_button, TRUE);
-	return FALSE;
+
+    if (file_exists(gtk_entry_get_text(GTK_ENTRY(firmware_entry)))) {
+        gtk_widget_set_sensitive(program_button, TRUE);
+    }
+    else {
+        gtk_widget_set_sensitive(program_button, FALSE);
+    }
+
+    gtk_widget_set_sensitive(bootloader_button, TRUE);
+    return FALSE;
 }
 
 gint do_bootloader(GtkWidget *widget, gpointer *data)
 {
-	if (download_in_progress) {
-		download_cancel(NULL);
-		gtk_widget_set_sensitive(program_button, FALSE);
-		gtk_widget_set_sensitive(reboot_button, FALSE);
-		gtk_widget_set_sensitive(bootloader_button, FALSE);
-	}
-
-	hard_reset_to_bootloader();
-
-	if (file_exists(gtk_entry_get_text(GTK_ENTRY(firmware_entry)))) {
-		gtk_widget_set_sensitive(program_button, TRUE);
-	} else {
-		gtk_widget_set_sensitive(program_button, FALSE);
-	}
-	gtk_widget_set_sensitive(reboot_button, TRUE);
-	gtk_widget_set_sensitive(bootloader_button, TRUE);
-	return FALSE;
+    if (download_in_progress) {
+        download_cancel(NULL);
+        gtk_widget_set_sensitive(program_button, FALSE);
+        gtk_widget_set_sensitive(reboot_button, FALSE);
+        gtk_widget_set_sensitive(bootloader_button, FALSE);
+    }
+
+    hard_reset_to_bootloader();
+
+    if (file_exists(gtk_entry_get_text(GTK_ENTRY(firmware_entry)))) {
+        gtk_widget_set_sensitive(program_button, TRUE);
+    }
+    else {
+        gtk_widget_set_sensitive(program_button, FALSE);
+    }
+
+    gtk_widget_set_sensitive(reboot_button, TRUE);
+    gtk_widget_set_sensitive(bootloader_button, TRUE);
+    return FALSE;
 }
 
 gint do_new_port(GtkWidget *widget, gpointer *data)
 {
-	port_timeout = 12;
-	return FALSE;
+    port_timeout = 12;
+    return FALSE;
 }
 
 gint do_new_baud(GtkWidget *widget, gpointer *data)
 {
-	baud_timeout = 7;
-	return FALSE;
+    baud_timeout = 7;
+    return FALSE;
 }
 
 gint do_new_file(GtkWidget *widget, gpointer *data)
 {
-	const char *filename;
-
-	filename = gtk_entry_get_text(GTK_ENTRY(firmware_entry));
-	if (file_exists(filename)) {
-		new_file_setting(filename);
-		if (download_in_progress) {
-			gtk_widget_set_sensitive(program_button, FALSE);
-		} else {
-			gtk_widget_set_sensitive(program_button, TRUE);
-		}
-	} else {
-		gtk_widget_set_sensitive(program_button, FALSE);
-	}
-	return FALSE;
+    const char *filename;
+
+    filename = gtk_entry_get_text(GTK_ENTRY(firmware_entry));
+
+    if (file_exists(filename)) {
+        new_file_setting(filename);
+
+        if (download_in_progress) {
+            gtk_widget_set_sensitive(program_button, FALSE);
+        }
+        else {
+            gtk_widget_set_sensitive(program_button, TRUE);
+        }
+    }
+    else {
+        gtk_widget_set_sensitive(program_button, FALSE);
+    }
+
+    return FALSE;
 }
 
 gint do_new_crystal(GtkWidget *widget, gpointer *data)
 {
-	const char *xtal;
+    const char *xtal;
 
-	xtal = gtk_entry_get_text(GTK_ENTRY(crystal_entry));
-	new_crystal_setting(xtal);
-	return FALSE;
+    xtal = gtk_entry_get_text(GTK_ENTRY(crystal_entry));
+    new_crystal_setting(xtal);
+    return FALSE;
 }
 
 
 gint do_timer(gpointer data)
 {
-	if (port_timeout && --port_timeout == 0) {
-		open_serial_port(gtk_entry_get_text(GTK_ENTRY(port_entry)));
-	}
-	if (baud_timeout && --baud_timeout == 0) {
-		change_baud(gtk_entry_get_text(GTK_ENTRY(
-			GTK_COMBO(baud_combo)->entry)));
-	}
-	if (download_in_progress) {
-		download_timer();
-	}
-	return TRUE;
+    if (port_timeout && --port_timeout == 0) {
+        open_serial_port(gtk_entry_get_text(GTK_ENTRY(port_entry)));
+    }
+
+    if (baud_timeout && --baud_timeout == 0) {
+        change_baud(gtk_entry_get_text(GTK_ENTRY(
+                                           GTK_COMBO(baud_combo)->entry)));
+    }
+
+    if (download_in_progress) {
+        download_timer();
+    }
+
+    return TRUE;
 }
 
 void do_term_input(gpointer data, int fd, GdkInputCondition cond)
 {
-	char buf[256];
-	int num, flags;
-
-	flags = fcntl(term_fd, F_GETFL);
-	fcntl(term_fd, F_SETFL, flags | O_NONBLOCK);
-	num = read(term_fd, buf, sizeof(buf));
-	fcntl(term_fd, F_SETFL, flags);
-	if (num > 0) {
-		if (download_in_progress) {
-			download_rx_term(buf, num);
-		} else {
-			write_serial_port(buf, num);
-		}
-	}
+    char buf[256];
+    int num, flags;
+
+    flags = fcntl(term_fd, F_GETFL);
+    fcntl(term_fd, F_SETFL, flags | O_NONBLOCK);
+    num = read(term_fd, buf, sizeof(buf));
+    fcntl(term_fd, F_SETFL, flags);
+
+    if (num > 0) {
+        if (download_in_progress) {
+            download_rx_term(buf, num);
+        }
+        else {
+            write_serial_port(buf, num);
+        }
+    }
 }
 
 void do_port_input(gpointer data, int fd, GdkInputCondition cond)
 {
-	char buf[256];
-	int num;
-
-	num = read_serial_port_nb((unsigned char *)buf, sizeof(buf));
-	if (num > 0) {
-		if (download_in_progress) {
-			download_rx_port(buf, num);
-		} else {
-			write(term_fd, buf, num);
-		}
-	}
+    char buf[256];
+    int num;
+
+    num = read_serial_port_nb((unsigned char *)buf, sizeof(buf));
+
+    if (num > 0) {
+        if (download_in_progress) {
+            download_rx_port(buf, num);
+        }
+        else {
+            write(term_fd, buf, num);
+        }
+    }
 }
 
 
 void run_gui(void)
 {
-	gtk_signal_connect(GTK_OBJECT(main_window), "delete_event",
-		GTK_SIGNAL_FUNC(do_quit), NULL);
-	gtk_signal_connect(GTK_OBJECT(quit_button), "pressed",
-		GTK_SIGNAL_FUNC(do_quit), NULL);
-	gtk_signal_connect(GTK_OBJECT(port_entry), "changed",
-		GTK_SIGNAL_FUNC(do_new_port), NULL);
-	gtk_signal_connect(GTK_OBJECT(GTK_COMBO(baud_combo)->entry), "changed",
-		GTK_SIGNAL_FUNC(do_new_baud), NULL);
-	gtk_signal_connect(GTK_OBJECT(firmware_entry), "changed",
-		GTK_SIGNAL_FUNC(do_new_file), NULL);
-	gtk_signal_connect(GTK_OBJECT(crystal_entry), "changed",
-		GTK_SIGNAL_FUNC(do_new_crystal), NULL);
-	gtk_signal_connect(GTK_OBJECT(program_button), "pressed",
-		GTK_SIGNAL_FUNC(do_program), NULL);
-	gtk_signal_connect(GTK_OBJECT(reboot_button), "pressed",
-		GTK_SIGNAL_FUNC(do_reboot), NULL);
-	gtk_signal_connect(GTK_OBJECT(bootloader_button), "pressed",
-		GTK_SIGNAL_FUNC(do_bootloader), NULL);
-
-	gtk_timeout_add(100, do_timer, NULL);
-	gdk_input_add(term_fd, GDK_INPUT_READ, do_term_input, NULL);
-	gdk_input_add(serial_port_fd(), GDK_INPUT_READ, do_port_input, NULL);
-
-	gtk_main();
+    gtk_signal_connect(GTK_OBJECT(main_window), "delete_event",
+                       GTK_SIGNAL_FUNC(do_quit), NULL);
+    gtk_signal_connect(GTK_OBJECT(quit_button), "pressed",
+                       GTK_SIGNAL_FUNC(do_quit), NULL);
+    gtk_signal_connect(GTK_OBJECT(port_entry), "changed",
+                       GTK_SIGNAL_FUNC(do_new_port), NULL);
+    gtk_signal_connect(GTK_OBJECT(GTK_COMBO(baud_combo)->entry), "changed",
+                       GTK_SIGNAL_FUNC(do_new_baud), NULL);
+    gtk_signal_connect(GTK_OBJECT(firmware_entry), "changed",
+                       GTK_SIGNAL_FUNC(do_new_file), NULL);
+    gtk_signal_connect(GTK_OBJECT(crystal_entry), "changed",
+                       GTK_SIGNAL_FUNC(do_new_crystal), NULL);
+    gtk_signal_connect(GTK_OBJECT(program_button), "pressed",
+                       GTK_SIGNAL_FUNC(do_program), NULL);
+    gtk_signal_connect(GTK_OBJECT(reboot_button), "pressed",
+                       GTK_SIGNAL_FUNC(do_reboot), NULL);
+    gtk_signal_connect(GTK_OBJECT(bootloader_button), "pressed",
+                       GTK_SIGNAL_FUNC(do_bootloader), NULL);
+
+    gtk_timeout_add(100, do_timer, NULL);
+    gdk_input_add(term_fd, GDK_INPUT_READ, do_term_input, NULL);
+    gdk_input_add(serial_port_fd(), GDK_INPUT_READ, do_port_input, NULL);
+
+    gtk_main();
 }
 
 
 void create_window(int *argc, char ***argv)
 {
-	GList *gtk_baud_list=NULL;
-	int i;
-
-	gtk_init(argc, argv);
-
-	firmware_label = gtk_label_new("Firmware:");
-	gtk_label_set_justify(GTK_LABEL(firmware_label), GTK_JUSTIFY_RIGHT);
-	gtk_widget_show(firmware_label);
-
-	firmware_entry = gtk_entry_new();
-	gtk_widget_set_usize(firmware_entry, 110, 0);
-	gtk_entry_set_text(GTK_ENTRY(firmware_entry), file_setting());
-	gtk_widget_show(firmware_entry);
-
-	program_button = gtk_button_new_with_label("Program Now");
-	if (file_exists(file_setting())) {
-		gtk_widget_set_sensitive(program_button, TRUE);
-	} else {
-		gtk_widget_set_sensitive(program_button, FALSE);
-	}
-	gtk_widget_show(program_button);
-
-	line1_hbox = gtk_hbox_new(FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(line1_hbox), firmware_label, FALSE, FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(line1_hbox), firmware_entry, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(line1_hbox), program_button, FALSE, FALSE, 2);
-	gtk_widget_show(line1_hbox);
-
-
-	port_label = gtk_label_new("Port:");
-	gtk_label_set_justify(GTK_LABEL(port_label), GTK_JUSTIFY_RIGHT);
-	gtk_widget_show(port_label);
-
-	port_entry = gtk_entry_new();
-	gtk_widget_set_usize(port_entry, 80, 0);
-	gtk_entry_set_text(GTK_ENTRY(port_entry), port_setting());
-	open_serial_port(port_setting());
-	gtk_widget_show(port_entry);
-
-	baud_label = gtk_label_new("Baud:");
-	gtk_label_set_justify(GTK_LABEL(baud_label), GTK_JUSTIFY_RIGHT);
-	gtk_widget_show(baud_label);
-	
-	baud_combo = gtk_combo_new();
-	for (i=0; baud_list[i] != NULL; i++) {
-		gtk_baud_list = g_list_append(gtk_baud_list, baud_list[i]);
-	}
-	gtk_combo_set_popdown_strings(GTK_COMBO(baud_combo), gtk_baud_list);
-	gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(baud_combo)->entry), FALSE);
-	gtk_widget_set_usize(baud_combo, 75, 0);
-	for (i=0; baud_list[i] != NULL; i++) {
-		if (strcmp(baud_list[i], baud_setting()) == 0) {
-			gtk_list_select_item(GTK_LIST(GTK_COMBO(baud_combo)->list), i);
-			break;
-		}
-	}
-	gtk_widget_show(baud_combo);
-
-	line2_hbox = gtk_hbox_new(FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(line2_hbox), port_label, FALSE, FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(line2_hbox), port_entry, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(line2_hbox), baud_label, FALSE, FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(line2_hbox), baud_combo, FALSE, FALSE, 2);
-	gtk_widget_show(line2_hbox);
-
-
-	crystal_label = gtk_label_new("Crystal:");
-	gtk_label_set_justify(GTK_LABEL(crystal_label), GTK_JUSTIFY_RIGHT);
-	gtk_widget_show(crystal_label);
-
-	crystal_entry = gtk_entry_new();
-	gtk_widget_set_usize(crystal_entry, 80, 0);
-	gtk_entry_set_text(GTK_ENTRY(crystal_entry), crystal_setting());
-	gtk_widget_show(crystal_entry);
-
-	mhz_label = gtk_label_new("(MHz)");
-	gtk_label_set_justify(GTK_LABEL(mhz_label), GTK_JUSTIFY_LEFT);
-	gtk_widget_show(mhz_label);
-
-	line3_hbox = gtk_hbox_new(FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(line3_hbox), crystal_label, FALSE, FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(line3_hbox), crystal_entry, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(line3_hbox), mhz_label, FALSE, FALSE, 2);
-	gtk_widget_show(line3_hbox);
-
-
-	reboot_button = gtk_button_new_with_label("Reboot");
-	gtk_widget_set_sensitive(reboot_button, TRUE);
-	gtk_widget_show(reboot_button);
-
-	bootloader_button = gtk_button_new_with_label("Booloader");
-	gtk_widget_show(bootloader_button);
-
-	quit_button = gtk_button_new_with_label("Quit");
-	gtk_widget_show(quit_button);
-
-	line4_hbox = gtk_hbox_new(TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(line4_hbox), reboot_button, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(line4_hbox), bootloader_button, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(line4_hbox), quit_button, TRUE, TRUE, 2);
-	gtk_widget_show(line4_hbox);
-
-	main_vbox = gtk_vbox_new(FALSE, 2);
-	gtk_box_pack_start(GTK_BOX(main_vbox), line1_hbox, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(main_vbox), line2_hbox, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(main_vbox), line3_hbox, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(main_vbox), line4_hbox, TRUE, TRUE, 2);
-	gtk_widget_show(main_vbox);
-
-	main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	gtk_container_add(GTK_CONTAINER(main_window), main_vbox);
-	gtk_widget_show(main_window);
+    GList *gtk_baud_list = NULL;
+    int i;
+
+    gtk_init(argc, argv);
+
+    firmware_label = gtk_label_new("Firmware:");
+    gtk_label_set_justify(GTK_LABEL(firmware_label), GTK_JUSTIFY_RIGHT);
+    gtk_widget_show(firmware_label);
+
+    firmware_entry = gtk_entry_new();
+    gtk_widget_set_usize(firmware_entry, 110, 0);
+    gtk_entry_set_text(GTK_ENTRY(firmware_entry), file_setting());
+    gtk_widget_show(firmware_entry);
+
+    program_button = gtk_button_new_with_label("Program Now");
+
+    if (file_exists(file_setting())) {
+        gtk_widget_set_sensitive(program_button, TRUE);
+    }
+    else {
+        gtk_widget_set_sensitive(program_button, FALSE);
+    }
+
+    gtk_widget_show(program_button);
+
+    line1_hbox = gtk_hbox_new(FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(line1_hbox), firmware_label, FALSE, FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(line1_hbox), firmware_entry, TRUE, TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(line1_hbox), program_button, FALSE, FALSE, 2);
+    gtk_widget_show(line1_hbox);
+
+
+    port_label = gtk_label_new("Port:");
+    gtk_label_set_justify(GTK_LABEL(port_label), GTK_JUSTIFY_RIGHT);
+    gtk_widget_show(port_label);
+
+    port_entry = gtk_entry_new();
+    gtk_widget_set_usize(port_entry, 80, 0);
+    gtk_entry_set_text(GTK_ENTRY(port_entry), port_setting());
+    open_serial_port(port_setting());
+    gtk_widget_show(port_entry);
+
+    baud_label = gtk_label_new("Baud:");
+    gtk_label_set_justify(GTK_LABEL(baud_label), GTK_JUSTIFY_RIGHT);
+    gtk_widget_show(baud_label);
+
+    baud_combo = gtk_combo_new();
+
+    for (i = 0; baud_list[i] != NULL; i++) {
+        gtk_baud_list = g_list_append(gtk_baud_list, baud_list[i]);
+    }
+
+    gtk_combo_set_popdown_strings(GTK_COMBO(baud_combo), gtk_baud_list);
+    gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(baud_combo)->entry), FALSE);
+    gtk_widget_set_usize(baud_combo, 75, 0);
+
+    for (i = 0; baud_list[i] != NULL; i++) {
+        if (strcmp(baud_list[i], baud_setting()) == 0) {
+            gtk_list_select_item(GTK_LIST(GTK_COMBO(baud_combo)->list), i);
+            break;
+        }
+    }
+
+    gtk_widget_show(baud_combo);
+
+    line2_hbox = gtk_hbox_new(FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(line2_hbox), port_label, FALSE, FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(line2_hbox), port_entry, TRUE, TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(line2_hbox), baud_label, FALSE, FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(line2_hbox), baud_combo, FALSE, FALSE, 2);
+    gtk_widget_show(line2_hbox);
+
+
+    crystal_label = gtk_label_new("Crystal:");
+    gtk_label_set_justify(GTK_LABEL(crystal_label), GTK_JUSTIFY_RIGHT);
+    gtk_widget_show(crystal_label);
+
+    crystal_entry = gtk_entry_new();
+    gtk_widget_set_usize(crystal_entry, 80, 0);
+    gtk_entry_set_text(GTK_ENTRY(crystal_entry), crystal_setting());
+    gtk_widget_show(crystal_entry);
+
+    mhz_label = gtk_label_new("(MHz)");
+    gtk_label_set_justify(GTK_LABEL(mhz_label), GTK_JUSTIFY_LEFT);
+    gtk_widget_show(mhz_label);
+
+    line3_hbox = gtk_hbox_new(FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(line3_hbox), crystal_label, FALSE, FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(line3_hbox), crystal_entry, TRUE, TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(line3_hbox), mhz_label, FALSE, FALSE, 2);
+    gtk_widget_show(line3_hbox);
+
+
+    reboot_button = gtk_button_new_with_label("Reboot");
+    gtk_widget_set_sensitive(reboot_button, TRUE);
+    gtk_widget_show(reboot_button);
+
+    bootloader_button = gtk_button_new_with_label("Booloader");
+    gtk_widget_show(bootloader_button);
+
+    quit_button = gtk_button_new_with_label("Quit");
+    gtk_widget_show(quit_button);
+
+    line4_hbox = gtk_hbox_new(TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(line4_hbox), reboot_button, TRUE, TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(line4_hbox), bootloader_button, TRUE, TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(line4_hbox), quit_button, TRUE, TRUE, 2);
+    gtk_widget_show(line4_hbox);
+
+    main_vbox = gtk_vbox_new(FALSE, 2);
+    gtk_box_pack_start(GTK_BOX(main_vbox), line1_hbox, TRUE, TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(main_vbox), line2_hbox, TRUE, TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(main_vbox), line3_hbox, TRUE, TRUE, 2);
+    gtk_box_pack_start(GTK_BOX(main_vbox), line4_hbox, TRUE, TRUE, 2);
+    gtk_widget_show(main_vbox);
+
+    main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_container_add(GTK_CONTAINER(main_window), main_vbox);
+    gtk_widget_show(main_window);
 }
diff --git a/msba2-common/tools/src/ihex.c b/msba2-common/tools/src/ihex.c
index cda37af66cfdeb558b05c500f9f6d2c5cc05057d..d5865a569a0b312195b1d55f649eb9c701a2bf70 100644
--- a/msba2-common/tools/src/ihex.c
+++ b/msba2-common/tools/src/ihex.c
@@ -20,7 +20,7 @@
 
 /* If this code fails to build, please provide at least the following
  * information when requesting (free) technical support.
- * 
+ *
  * 1: Complete copy of all messages during the build.
  * 2: Output of "gtk-config --version"
  * 3: Output of "gtk-config --libs"
@@ -45,7 +45,7 @@
 
 static unsigned char firmware_image[MAX_MEMORY_SIZE];
 static unsigned char firmware_mask[MAX_MEMORY_SIZE];
-static int end_record_seen=0;
+static int end_record_seen = 0;
 static int byte_count;
 static unsigned int extended_addr = 0;
 
@@ -63,38 +63,50 @@ static int parse_hex_line(char *line);
 
 int read_intel_hex(const char *filename)
 {
-	FILE *fp;
-	int i, lineno=0;
-	char buf[1024];
-
-	byte_count = 0;
-	end_record_seen = 0;
-	for (i=0; i<MAX_MEMORY_SIZE; i++) {
-		firmware_image[i] = 0xFF;
-		firmware_mask[i] = 0;
-	}
-	extended_addr = 0;
-
-	fp = fopen(filename, "r");
-	if (fp == NULL) {
-		printf("Unable to read file %s\n", filename);
-		return -1;
-	}
-	while (!feof(fp)) {
-		*buf = '\0';
-		fgets(buf, sizeof(buf), fp);
-		lineno++;
-		if (*buf) {
-			if (parse_hex_line(buf) == 0) {
-				printf("Warning, parse error line %d\n", lineno);
-				return -2;
-			}
-		}
-		if (end_record_seen) break;
-		if (feof(stdin)) break;
-	}
-	fclose(fp);
-	return byte_count;
+    FILE *fp;
+    int i, lineno = 0;
+    char buf[1024];
+
+    byte_count = 0;
+    end_record_seen = 0;
+
+    for (i = 0; i < MAX_MEMORY_SIZE; i++) {
+        firmware_image[i] = 0xFF;
+        firmware_mask[i] = 0;
+    }
+
+    extended_addr = 0;
+
+    fp = fopen(filename, "r");
+
+    if (fp == NULL) {
+        printf("Unable to read file %s\n", filename);
+        return -1;
+    }
+
+    while (!feof(fp)) {
+        *buf = '\0';
+        fgets(buf, sizeof(buf), fp);
+        lineno++;
+
+        if (*buf) {
+            if (parse_hex_line(buf) == 0) {
+                printf("Warning, parse error line %d\n", lineno);
+                return -2;
+            }
+        }
+
+        if (end_record_seen) {
+            break;
+        }
+
+        if (feof(stdin)) {
+            break;
+        }
+    }
+
+    fclose(fp);
+    return byte_count;
 }
 
 
@@ -109,112 +121,185 @@ int read_intel_hex(const char *filename)
 int
 parse_hex_line(char *line)
 {
-	int addr, code, num;
-        int sum, len, cksum, i;
-        char *ptr;
-        
-        num = 0;
-        if (line[0] != ':') return 0;
-        if (strlen(line) < 11) return 0;
-        ptr = line+1;
-        if (!sscanf(ptr, "%02x", &len)) return 0;
-        ptr += 2;
-        if (strlen(line) < (11 + (len * 2)) ) return 0;
-        if (!sscanf(ptr, "%04x", &addr)) return 0;
-        ptr += 4;
-          /* printf("Line: length=%d Addr=%d\n", len, addr); */
-        if (!sscanf(ptr, "%02x", &code)) return 0;
-	if (addr + extended_addr + len >= MAX_MEMORY_SIZE) return 0;
+    int addr, code, num;
+    int sum, len, cksum, i;
+    char *ptr;
+
+    num = 0;
+
+    if (line[0] != ':') {
+        return 0;
+    }
+
+    if (strlen(line) < 11) {
+        return 0;
+    }
+
+    ptr = line + 1;
+
+    if (!sscanf(ptr, "%02x", &len)) {
+        return 0;
+    }
+
+    ptr += 2;
+
+    if (strlen(line) < (11 + (len * 2))) {
+        return 0;
+    }
+
+    if (!sscanf(ptr, "%04x", &addr)) {
+        return 0;
+    }
+
+    ptr += 4;
+
+    /* printf("Line: length=%d Addr=%d\n", len, addr); */
+    if (!sscanf(ptr, "%02x", &code)) {
+        return 0;
+    }
+
+    if (addr + extended_addr + len >= MAX_MEMORY_SIZE) {
+        return 0;
+    }
+
+    ptr += 2;
+    sum = (len & 255) + ((addr >> 8) & 255) + (addr & 255) + (code & 255);
+
+    if (code != 0) {
+        if (code == 1) {
+            end_record_seen = 1;
+            return 1;
+        }
+
+        if (code == 2 && len == 2) {
+            if (!sscanf(ptr, "%04x", &i)) {
+                return 1;
+            }
+
+            ptr += 4;
+            sum += ((i >> 8) & 255) + (i & 255);
+
+            if (!sscanf(ptr, "%02x", &cksum)) {
+                return 1;
+            }
+
+            if (((sum & 255) + (cksum & 255)) & 255) {
+                return 1;
+            }
+
+            extended_addr = i << 4;
+            //printf("ext addr = %05X\n", extended_addr);
+        }
+
+        if (code == 4 && len == 2) {
+            if (!sscanf(ptr, "%04x", &i)) {
+                return 1;
+            }
+
+            ptr += 4;
+            sum += ((i >> 8) & 255) + (i & 255);
+
+            if (!sscanf(ptr, "%02x", &cksum)) {
+                return 1;
+            }
+
+            if (((sum & 255) + (cksum & 255)) & 255) {
+                return 1;
+            }
+
+            extended_addr = i << 16;
+            //printf("ext addr = %08X\n", extended_addr);
+        }
+
+        return 1;	// non-data line
+    }
+
+    byte_count += len;
+
+    while (num != len) {
+        if (sscanf(ptr, "%02x", &i) != 1) {
+            return 0;
+        }
+
+        i &= 255;
+        firmware_image[addr + extended_addr + num] = i;
+        firmware_mask[addr + extended_addr + num] = 1;
         ptr += 2;
-        sum = (len & 255) + ((addr >> 8) & 255) + (addr & 255) + (code & 255);
-	if (code != 0) {
-		if (code == 1) {
-			end_record_seen = 1;
-			return 1;
-		}
-		if (code == 2 && len == 2) {
-			if (!sscanf(ptr, "%04x", &i)) return 1;
-			ptr += 4;
-			sum += ((i >> 8) & 255) + (i & 255);
-        		if (!sscanf(ptr, "%02x", &cksum)) return 1;
-			if (((sum & 255) + (cksum & 255)) & 255) return 1;
-			extended_addr = i << 4;
-			//printf("ext addr = %05X\n", extended_addr);
-		}
-		if (code == 4 && len == 2) {
-			if (!sscanf(ptr, "%04x", &i)) return 1;
-			ptr += 4;
-			sum += ((i >> 8) & 255) + (i & 255);
-        		if (!sscanf(ptr, "%02x", &cksum)) return 1;
-			if (((sum & 255) + (cksum & 255)) & 255) return 1;
-			extended_addr = i << 16;
-			//printf("ext addr = %08X\n", extended_addr);
-		}
-		return 1;	// non-data line
-	}
-	byte_count += len;
-        while (num != len) {
-                if (sscanf(ptr, "%02x", &i) != 1) return 0;
-		i &= 255;
-		firmware_image[addr + extended_addr + num] = i;
-		firmware_mask[addr + extended_addr + num] = 1;
-                ptr += 2;
-                sum += i;
-                (num)++;
-                if (num >= 256) return 0;
+        sum += i;
+        (num)++;
+
+        if (num >= 256) {
+            return 0;
         }
-        if (!sscanf(ptr, "%02x", &cksum)) return 0;
-        if (((sum & 255) + (cksum & 255)) & 255) return 0; /* checksum error */
-        return 1;
+    }
+
+    if (!sscanf(ptr, "%02x", &cksum)) {
+        return 0;
+    }
+
+    if (((sum & 255) + (cksum & 255)) & 255) {
+        return 0;    /* checksum error */
+    }
+
+    return 1;
 }
 
 
 int bytes_within_range(int begin, int end)
 {
-	int i;
-
-	if (begin < 0 || begin >= MAX_MEMORY_SIZE ||
-	   end < 0 || end >= MAX_MEMORY_SIZE) {
-		return 0;
-	}
-	for (i=begin; i<=end; i++) {
-		if (firmware_mask[i]) return 1;
-	}
-	return 0;
+    int i;
+
+    if (begin < 0 || begin >= MAX_MEMORY_SIZE ||
+        end < 0 || end >= MAX_MEMORY_SIZE) {
+        return 0;
+    }
+
+    for (i = begin; i <= end; i++) {
+        if (firmware_mask[i]) {
+            return 1;
+        }
+    }
+
+    return 0;
 }
 
 void get_ihex_data(int addr, int len, unsigned char *bytes)
 {
-	int i;
-
-	if (addr < 0 || len < 0 || addr + len >= MAX_MEMORY_SIZE) {
-		for (i=0; i<len; i++) {
-			bytes[i] = 255;
-		}
-		return;
-	}
-	for (i=0; i<len; i++) {
-		if (firmware_mask[addr]) {
-			bytes[i] = firmware_image[addr];
-		} else {
-			bytes[i] = 255;
-		}
-		addr++;
-	}
+    int i;
+
+    if (addr < 0 || len < 0 || addr + len >= MAX_MEMORY_SIZE) {
+        for (i = 0; i < len; i++) {
+            bytes[i] = 255;
+        }
+
+        return;
+    }
+
+    for (i = 0; i < len; i++) {
+        if (firmware_mask[addr]) {
+            bytes[i] = firmware_image[addr];
+        }
+        else {
+            bytes[i] = 255;
+        }
+
+        addr++;
+    }
 }
 
 void put_ihex_data(int addr, int len, const unsigned char *bytes)
 {
-	int i;
-
-	if (addr < 0 || len < 0 || addr + len >= MAX_MEMORY_SIZE) {
-		return;
-	}
-	for (i=0; i<len; i++) {
-		firmware_image[addr] = bytes[i];
-		firmware_mask[addr] = 1;
-		addr++;
-	}
+    int i;
+
+    if (addr < 0 || len < 0 || addr + len >= MAX_MEMORY_SIZE) {
+        return;
+    }
+
+    for (i = 0; i < len; i++) {
+        firmware_image[addr] = bytes[i];
+        firmware_mask[addr] = 1;
+        addr++;
+    }
 }
 
 
diff --git a/msba2-common/tools/src/lpc2k_pgm.c b/msba2-common/tools/src/lpc2k_pgm.c
index 4891c55946b02e40e21fbaa485076749f0b18ce0..8c74429887ab526516e5feaf1fa8eafa4eae9b76 100644
--- a/msba2-common/tools/src/lpc2k_pgm.c
+++ b/msba2-common/tools/src/lpc2k_pgm.c
@@ -20,7 +20,7 @@
 
 /* If this code fails to build, please provide at least the following
  * information when requesting (free) technical support.
- * 
+ *
  * 1: Complete copy of all messages during the build.
  * 2: Output of "gtk-config --version"
  * 3: Output of "gtk-config --libs"
@@ -48,49 +48,54 @@
 
 int programming_done = 0;
 
-int done_program(int i) {
-	printf("Programming done.\n");
-	programming_done = 1;
-	return 0;
+int done_program(int i)
+{
+    printf("Programming done.\n");
+    programming_done = 1;
+    return 0;
 }
 
-void handle_port_input() {
-	unsigned char buf[256];
-	int num;
+void handle_port_input()
+{
+    unsigned char buf[256];
+    int num;
 
-	num = read_serial_port(buf, sizeof(buf));
-	if (num > 0) {
-			download_rx_port(buf, num);
-	}
+    num = read_serial_port(buf, sizeof(buf));
+
+    if (num > 0) {
+        download_rx_port(buf, num);
+    }
 }
 
-void usage() {
+void usage()
+{
     printf("usage: lpc2k_pgm <port> <ihex-file>\n");
 }
 
 int main(int argc, char **argv)
 {
-	if (argc < 3 ) {
-		usage();
-		exit(1);
-	}
+    if (argc < 3) {
+        usage();
+        exit(1);
+    }
 
-    char* port_name = argv[1];
-	char* file_name = argv[2];
+    char *port_name = argv[1];
+    char *file_name = argv[2];
 
     if (open_serial_port(port_name) < 0) {
-        return(1);
+        return (1);
     }
 
-	if (!download_begin(file_name)) {
+    if (!download_begin(file_name)) {
         return 1;
     }
-	while (!programming_done) {
-		handle_port_input();
-	}
-	
+
+    while (!programming_done) {
+        handle_port_input();
+    }
+
     close_serial_port();
 
-	return 0;
+    return 0;
 }
 
diff --git a/msba2-common/tools/src/pseudoterm.c b/msba2-common/tools/src/pseudoterm.c
index cf17d99703aed4b110ae2f0faa6b616d91537d60..24b2d33cb06b1b43ebe15b712002d50fd2222ae4 100644
--- a/msba2-common/tools/src/pseudoterm.c
+++ b/msba2-common/tools/src/pseudoterm.c
@@ -16,20 +16,24 @@
 
 int tty_fd;
 int stopped = 0;
-char* port_name = "/dev/ttyUSB1";
+char *port_name = "/dev/ttyUSB1";
 pthread_t serial_reader;
 
-void* serial_reader_func(void* arg) {
+void *serial_reader_func(void *arg)
+{
     unsigned char buf[255];
-    while(1) {
+
+    while (1) {
         int n = read_serial_port(buf, sizeof(buf));
+
         if (n > 0) {
             write(tty_fd, buf, n);
         }
     }
 }
 
-int init() {
+int init()
+{
     int result = open_serial_port(port_name);
     pthread_create(&serial_reader, NULL, serial_reader_func, NULL);
     hard_reset_to_user_code();
@@ -38,29 +42,34 @@ int init() {
 
 struct termios old_term_setting;
 
-void close_tty() {
-	tcsetattr(tty_fd, TCSANOW, &old_term_setting);
+void close_tty()
+{
+    tcsetattr(tty_fd, TCSANOW, &old_term_setting);
 }
 
-void sig_handler(int signal) {
+void sig_handler(int signal)
+{
     if (signal == SIGUSR1) {
         if (stopped) {
             stopped = 0;
             printf("\nSignal received, opening port.\r\n");
+
             if (init() < 0) {
                 printf("Cannot open port.\r\n");
                 close_tty();
                 exit(1);
             }
         }
-    } else if (signal == SIGUSR2) {
+    }
+    else if (signal == SIGUSR2) {
         if (!stopped) {
             stopped = 1;
             printf("\nSignal received, closing port. \r\n");
             pthread_cancel(serial_reader);
             close_serial_port();
         }
-    } else if (signal == SIGINT) {
+    }
+    else if (signal == SIGINT) {
         printf("SIGINT received, exiting...\n");
         pthread_cancel(serial_reader);
         close_serial_port();
@@ -71,35 +80,47 @@ void sig_handler(int signal) {
 
 int open_tty(void)
 {
-	int r, fd;
+    int r, fd;
     struct termios term_setting;
 
-	fd = open("/dev/tty", O_RDWR);
-	if (fd < 0) return -1;
-	r = tcgetattr(fd, &term_setting);
-	if (r != 0) return -2;
+    fd = open("/dev/tty", O_RDWR);
+
+    if (fd < 0) {
+        return -1;
+    }
+
+    r = tcgetattr(fd, &term_setting);
+
+    if (r != 0) {
+        return -2;
+    }
 
     old_term_setting = term_setting;
 
-	term_setting.c_oflag |= ( ONLRET );
-	term_setting.c_iflag |= (/*IGNBRK |*/ BRKINT | IGNPAR);
-	term_setting.c_iflag &= ~(ISTRIP);
-	term_setting.c_lflag &= ~(ICANON |/* ISIG |*/ ECHO);
-	term_setting.c_lflag |= ( ISIG );
-	term_setting.c_cflag |= CREAD;
-	term_setting.c_cc[VMIN] = 1;
-	term_setting.c_cc[VTIME] = 1;
-	r = tcsetattr(fd, TCSANOW, &term_setting);
-	if (r != 0) return -3;
-	return fd;
+    term_setting.c_oflag |= (ONLRET);
+    term_setting.c_iflag |= (/*IGNBRK |*/ BRKINT | IGNPAR);
+    term_setting.c_iflag &= ~(ISTRIP);
+    term_setting.c_lflag &= ~(ICANON |/* ISIG |*/ ECHO);
+    term_setting.c_lflag |= (ISIG);
+    term_setting.c_cflag |= CREAD;
+    term_setting.c_cc[VMIN] = 1;
+    term_setting.c_cc[VTIME] = 1;
+    r = tcsetattr(fd, TCSANOW, &term_setting);
+
+    if (r != 0) {
+        return -3;
+    }
+
+    return fd;
 }
 
-void install_sighandler() {
+void install_sighandler()
+{
     struct sigaction action;
-    sigemptyset (&action.sa_mask);
-    sigaddset( &action.sa_mask, SIGINT );
-    sigaddset( &action.sa_mask, SIGUSR1 );
-    sigaddset( &action.sa_mask, SIGUSR2 );
+    sigemptyset(&action.sa_mask);
+    sigaddset(&action.sa_mask, SIGINT);
+    sigaddset(&action.sa_mask, SIGUSR1);
+    sigaddset(&action.sa_mask, SIGUSR2);
     action.sa_flags = 0;
     action.sa_handler = sig_handler;
     sigaction(SIGINT, &action, NULL);
@@ -107,7 +128,8 @@ void install_sighandler() {
     sigaction(SIGUSR2, &action, NULL);
 }
 
-int main(int argc, char** argv) {
+int main(int argc, char **argv)
+{
     if (argc == 2) {
         port_name = argv[1];
     }
@@ -116,9 +138,10 @@ int main(int argc, char** argv) {
 
     char ttybuf[255];
     tty_fd = open_tty();
+
     if (tty_fd < 0) {
         printf("Error opening terminal.\n");
-        return(1);
+        return (1);
     }
 
     install_sighandler();
@@ -138,6 +161,7 @@ int main(int argc, char** argv) {
                 if (i > 0) {
                     write_serial_port(ttybuf, i);
                 }
+
                 close_serial_port();
                 close_tty();
                 system("tset -c");
@@ -145,7 +169,8 @@ int main(int argc, char** argv) {
             }
 
         }
-        write_serial_port(ttybuf,n);
+
+        write_serial_port(ttybuf, n);
     }
 
     close_tty();
diff --git a/msba2-common/tools/src/serial.c b/msba2-common/tools/src/serial.c
index 203af564dad6601b50ce4e71f9727f215c6f6a2d..9e7fee25f8d367d1522983ae75b556fe5befc525 100644
--- a/msba2-common/tools/src/serial.c
+++ b/msba2-common/tools/src/serial.c
@@ -50,52 +50,64 @@
 
 #include "serial.h"
 
-static int port_fd=-1;
+static int port_fd = -1;
 
 static tcflag_t baud_name_to_flags(const char *baud_name);
 static void report_open_error(const char *filename, int err);
 
-char* baud_rate = "115200";
+char *baud_rate = "115200";
 
 int open_serial_port(const char *port_name)
 {
-	int r;
-        struct termios term_setting;
-
-	if (port_fd >= 0) {
-		close(port_fd);
-	}
-	port_fd = open(port_name, O_RDWR);
-	if (port_fd < 0) {
-		report_open_error(port_name, errno);
-		return -1;
-	}
-
-        bzero(&term_setting, sizeof(term_setting));
-        term_setting.c_cflag = (CS8 | CREAD);
-	term_setting.c_cc[VMIN] = 1;
-	term_setting.c_cc[VTIME] = 1;
-	r = tcsetattr(port_fd, TCSANOW, &term_setting);
-	if (r != 0) return -1;
-
-	r = set_baud(baud_rate);
-	if (r == 0) {
-		printf("Port \"%s\" opened at %s baud\r\n",
-			port_name, baud_rate);
-	} else {
-		printf("Port \"%s\" opened, unable to set baud to %s\r\n",
-			port_name, baud_rate);
-	}
-	#ifdef LINUX
-	{
-		struct serial_struct kernel_serial_settings;
-		/* attempt to set low latency mode, but don't worry if we can't */
-		r = ioctl(port_fd, TIOCGSERIAL, &kernel_serial_settings);
-		if (r < 0) return 0;
-		kernel_serial_settings.flags |= ASYNC_LOW_LATENCY;
-		ioctl(port_fd, TIOCSSERIAL, &kernel_serial_settings);
-	}
-	#endif
+    int r;
+    struct termios term_setting;
+
+    if (port_fd >= 0) {
+        close(port_fd);
+    }
+
+    port_fd = open(port_name, O_RDWR);
+
+    if (port_fd < 0) {
+        report_open_error(port_name, errno);
+        return -1;
+    }
+
+    bzero(&term_setting, sizeof(term_setting));
+    term_setting.c_cflag = (CS8 | CREAD);
+    term_setting.c_cc[VMIN] = 1;
+    term_setting.c_cc[VTIME] = 1;
+    r = tcsetattr(port_fd, TCSANOW, &term_setting);
+
+    if (r != 0) {
+        return -1;
+    }
+
+    r = set_baud(baud_rate);
+
+    if (r == 0) {
+        printf("Port \"%s\" opened at %s baud\r\n",
+               port_name, baud_rate);
+    }
+    else {
+        printf("Port \"%s\" opened, unable to set baud to %s\r\n",
+               port_name, baud_rate);
+    }
+
+#ifdef LINUX
+    {
+        struct serial_struct kernel_serial_settings;
+        /* attempt to set low latency mode, but don't worry if we can't */
+        r = ioctl(port_fd, TIOCGSERIAL, &kernel_serial_settings);
+
+        if (r < 0) {
+            return 0;
+        }
+
+        kernel_serial_settings.flags |= ASYNC_LOW_LATENCY;
+        ioctl(port_fd, TIOCSSERIAL, &kernel_serial_settings);
+    }
+#endif
     return 0;
 }
 
@@ -105,196 +117,263 @@ int open_serial_port(const char *port_name)
  */
 static void report_open_error(const char *filename, int err)
 {
-	struct stat info;
-	uid_t my_uid;
-	gid_t my_gid;
-	char my_uname[64], my_gname[64], file_uname[64], file_gname[64];
-	struct passwd *p;
-	struct group *g;
-	mode_t perm;
-	int r, perm_ok=0;
-
-	printf("\r\n");
-	printf("Unable to open \"%s\"\r\n", filename);
-	if (err == EACCES) {
-		printf("You don't have permission to access %s\r\n", filename);
-	}
-	//printf("Attemping to find more information about %s....\r\n", filename);
-	r = stat(filename, &info);
-	if (r < 0) {
-		if (errno == ENOENT) {
-			printf("file %s does not exist\r\n", filename);
-		} else if (errno == ELOOP) {
-			printf("too many symbolic links\r\n");
-		} else if (errno == EACCES) {
-			printf("permission denied to get file status\r\n");
-		} else {
-			printf("Unable to get file status, err%d\r\n", errno);
-		}
-		return;
-	}
-	my_uid = getuid();
-	my_gid = getgid();
-
-	p = getpwuid(my_uid);
-	if (p) {
-		snprintf(my_uname, sizeof(my_uname),
-			"\"%s\" (gid=%d)", p->pw_name, (int)my_uid);
-	} else {
-		snprintf(my_uname, sizeof(my_uname),
-			"(gid=%d)", (int)my_uid);
-	}
-
-	p = getpwuid(info.st_uid);
-	if (p) {
-		snprintf(file_uname, sizeof(file_uname),
-			"\"%s\" (uid=%d)", p->pw_name, (int)info.st_uid);
-	} else {
-		snprintf(file_uname, sizeof(file_uname),
-			"(uid=%d)", (int)info.st_uid);
-	}
-
-	g = getgrgid(my_gid);
-	if (g) {
-		snprintf(my_gname, sizeof(my_gname),
-			"\"%s\" (gid=%d)", g->gr_name, (int)my_gid);
-	} else {
-		snprintf(my_gname, sizeof(my_gname),
-			"(gid=%d)", (int)my_gid);
-	}
-
-	g = getgrgid(info.st_gid);
-	if (g) {
-		snprintf(file_gname, sizeof(file_gname),
-			"\"%s\" (uid=%d)", g->gr_name, (int)info.st_gid);
-	} else {
-		snprintf(file_gname, sizeof(file_gname),
-			"(uid=%d)", (int)info.st_gid);
-	}
-
-	/* printf("%s is owned by: user %s, group %s\r\n",
-		filename, file_uname, file_gname); */
-
-	perm = info.st_mode;
-
-	if ((perm & S_IROTH) && (perm & S_IWOTH)) {
-		printf("%s has read/write permission for everybody\r\n",
-			filename);
-	} else {
-		printf("%s is not read/write for everybody, so\r\n", filename);
-		printf("  you must match either user or group permission\r\n");
-		if ((perm & S_IRUSR) && (perm & S_IWUSR)) {
-			printf("%s has read/write permission for user %s\r\n",
-				filename, file_uname);
-			perm_ok = 1;
-		}
-		if ((perm & S_IRGRP) && (perm & S_IWGRP)) {
-			printf("%s has read/write permission for group %s\r\n",
-				filename, file_gname);
-			perm_ok = 1;
-		}
-		if (perm_ok == 0) {
-			printf("%s does not read/write permission for user or group!\r\n",
-				filename);
-		} else {
-			printf("Your access privs: user %s, group %s\r\n",
-				my_uname, my_gname);
-		}
-	}
-	printf("\r\n");
+    struct stat info;
+    uid_t my_uid;
+    gid_t my_gid;
+    char my_uname[64], my_gname[64], file_uname[64], file_gname[64];
+    struct passwd *p;
+    struct group *g;
+    mode_t perm;
+    int r, perm_ok = 0;
+
+    printf("\r\n");
+    printf("Unable to open \"%s\"\r\n", filename);
+
+    if (err == EACCES) {
+        printf("You don't have permission to access %s\r\n", filename);
+    }
+
+    //printf("Attemping to find more information about %s....\r\n", filename);
+    r = stat(filename, &info);
+
+    if (r < 0) {
+        if (errno == ENOENT) {
+            printf("file %s does not exist\r\n", filename);
+        }
+        else if (errno == ELOOP) {
+            printf("too many symbolic links\r\n");
+        }
+        else if (errno == EACCES) {
+            printf("permission denied to get file status\r\n");
+        }
+        else {
+            printf("Unable to get file status, err%d\r\n", errno);
+        }
+
+        return;
+    }
+
+    my_uid = getuid();
+    my_gid = getgid();
+
+    p = getpwuid(my_uid);
+
+    if (p) {
+        snprintf(my_uname, sizeof(my_uname),
+                 "\"%s\" (gid=%d)", p->pw_name, (int)my_uid);
+    }
+    else {
+        snprintf(my_uname, sizeof(my_uname),
+                 "(gid=%d)", (int)my_uid);
+    }
+
+    p = getpwuid(info.st_uid);
+
+    if (p) {
+        snprintf(file_uname, sizeof(file_uname),
+                 "\"%s\" (uid=%d)", p->pw_name, (int)info.st_uid);
+    }
+    else {
+        snprintf(file_uname, sizeof(file_uname),
+                 "(uid=%d)", (int)info.st_uid);
+    }
+
+    g = getgrgid(my_gid);
+
+    if (g) {
+        snprintf(my_gname, sizeof(my_gname),
+                 "\"%s\" (gid=%d)", g->gr_name, (int)my_gid);
+    }
+    else {
+        snprintf(my_gname, sizeof(my_gname),
+                 "(gid=%d)", (int)my_gid);
+    }
+
+    g = getgrgid(info.st_gid);
+
+    if (g) {
+        snprintf(file_gname, sizeof(file_gname),
+                 "\"%s\" (uid=%d)", g->gr_name, (int)info.st_gid);
+    }
+    else {
+        snprintf(file_gname, sizeof(file_gname),
+                 "(uid=%d)", (int)info.st_gid);
+    }
+
+    /* printf("%s is owned by: user %s, group %s\r\n",
+    	filename, file_uname, file_gname); */
+
+    perm = info.st_mode;
+
+    if ((perm & S_IROTH) && (perm & S_IWOTH)) {
+        printf("%s has read/write permission for everybody\r\n",
+               filename);
+    }
+    else {
+        printf("%s is not read/write for everybody, so\r\n", filename);
+        printf("  you must match either user or group permission\r\n");
+
+        if ((perm & S_IRUSR) && (perm & S_IWUSR)) {
+            printf("%s has read/write permission for user %s\r\n",
+                   filename, file_uname);
+            perm_ok = 1;
+        }
+
+        if ((perm & S_IRGRP) && (perm & S_IWGRP)) {
+            printf("%s has read/write permission for group %s\r\n",
+                   filename, file_gname);
+            perm_ok = 1;
+        }
+
+        if (perm_ok == 0) {
+            printf("%s does not read/write permission for user or group!\r\n",
+                   filename);
+        }
+        else {
+            printf("Your access privs: user %s, group %s\r\n",
+                   my_uname, my_gname);
+        }
+    }
+
+    printf("\r\n");
 }
 
 
 
 int write_serial_port(const void *buf, int num)
 {
-	return(write(port_fd, buf, num));
+    return (write(port_fd, buf, num));
 }
 
 
 void input_flush_serial_port(void)
 {
-	tcflush(port_fd, TCIFLUSH);
+    tcflush(port_fd, TCIFLUSH);
 }
 
 
 int read_serial_port_nb(unsigned char *buf, int bufsize)
 {
-	int num, flags;
+    int num, flags;
 
-        flags = fcntl(port_fd, F_GETFL);
-        fcntl(port_fd, F_SETFL, flags | O_NONBLOCK);
-        num = read(port_fd, buf, bufsize);
-        fcntl(port_fd, F_SETFL, flags);
-	return num;
+    flags = fcntl(port_fd, F_GETFL);
+    fcntl(port_fd, F_SETFL, flags | O_NONBLOCK);
+    num = read(port_fd, buf, bufsize);
+    fcntl(port_fd, F_SETFL, flags);
+    return num;
 }
 
 int read_serial_port(unsigned char *buf, int bufsize)
 {
-	int num;
+    int num;
 
-        num = read(port_fd, buf, bufsize);
+    num = read(port_fd, buf, bufsize);
 
-	return num;
+    return num;
 }
 
 
 void send_break_signal(void)
 {
-	tcsendbreak(port_fd, 0);
+    tcsendbreak(port_fd, 0);
 }
 
 
 void close_serial_port(void)
 {
-	if (port_fd >= 0) {
-		close(port_fd);
-		port_fd = -1;
-	}
+    if (port_fd >= 0) {
+        close(port_fd);
+        port_fd = -1;
+    }
 }
 
 
 tcflag_t baud_name_to_flags(const char *baud_name)
 {
-	if (strcmp(baud_name, "230400") == 0) return B230400;
-	if (strcmp(baud_name, "115200") == 0) return B115200;
-	if (strcmp(baud_name, "57600") == 0) return B57600;
-	if (strcmp(baud_name, "38400") == 0) return B38400;
-	if (strcmp(baud_name, "19200") == 0) return B19200;
-	if (strcmp(baud_name, "9600") == 0) return B9600;
-	if (strcmp(baud_name, "4800") == 0) return B4800;
-	if (strcmp(baud_name, "2400") == 0) return B2400;
-	if (strcmp(baud_name, "1200") == 0) return B1200;
-	if (strcmp(baud_name, "300") == 0) return B300;
-	return B0;
+    if (strcmp(baud_name, "230400") == 0) {
+        return B230400;
+    }
+
+    if (strcmp(baud_name, "115200") == 0) {
+        return B115200;
+    }
+
+    if (strcmp(baud_name, "57600") == 0) {
+        return B57600;
+    }
+
+    if (strcmp(baud_name, "38400") == 0) {
+        return B38400;
+    }
+
+    if (strcmp(baud_name, "19200") == 0) {
+        return B19200;
+    }
+
+    if (strcmp(baud_name, "9600") == 0) {
+        return B9600;
+    }
+
+    if (strcmp(baud_name, "4800") == 0) {
+        return B4800;
+    }
+
+    if (strcmp(baud_name, "2400") == 0) {
+        return B2400;
+    }
+
+    if (strcmp(baud_name, "1200") == 0) {
+        return B1200;
+    }
+
+    if (strcmp(baud_name, "300") == 0) {
+        return B300;
+    }
+
+    return B0;
 }
 
 
 int set_baud(const char *baud_name)
 {
-	struct termios port_setting;
-	tcflag_t baud;
-	int r;
-
-	if (port_fd < 0) return -1;
-	baud = baud_name_to_flags(baud_name);
-	if (baud == B0) return -2;
-	r = tcgetattr(port_fd, &port_setting);
-	if (r != 0) return -3;
+    struct termios port_setting;
+    tcflag_t baud;
+    int r;
+
+    if (port_fd < 0) {
+        return -1;
+    }
+
+    baud = baud_name_to_flags(baud_name);
+
+    if (baud == B0) {
+        return -2;
+    }
+
+    r = tcgetattr(port_fd, &port_setting);
+
+    if (r != 0) {
+        return -3;
+    }
+
 #ifdef __APPLE__
-	cfsetspeed(&port_setting,baud);
-	port_setting.c_iflag = IGNBRK | IGNPAR;
-	port_setting.c_cflag =  CS8 | CREAD | HUPCL | CLOCAL;
+    cfsetspeed(&port_setting, baud);
+    port_setting.c_iflag = IGNBRK | IGNPAR;
+    port_setting.c_cflag =  CS8 | CREAD | HUPCL | CLOCAL;
 #else
-	port_setting.c_iflag = IGNBRK | IGNPAR;
-	port_setting.c_cflag = baud | CS8 | CREAD | HUPCL | CLOCAL;
+    port_setting.c_iflag = IGNBRK | IGNPAR;
+    port_setting.c_cflag = baud | CS8 | CREAD | HUPCL | CLOCAL;
 #endif
 
-	port_setting.c_oflag = 0;
-	port_setting.c_lflag = 0;
-	r = tcsetattr(port_fd, TCSAFLUSH, &port_setting);
-	if (r != 0) return -4;
-	return 0;
+    port_setting.c_oflag = 0;
+    port_setting.c_lflag = 0;
+    r = tcsetattr(port_fd, TCSAFLUSH, &port_setting);
+
+    if (r != 0) {
+        return -4;
+    }
+
+    return 0;
 }
 
 
@@ -303,31 +382,35 @@ int set_baud(const char *baud_name)
 // use of the serial port is supposed to happen in the file.
 int serial_port_fd(void)
 {
-	return port_fd;
+    return port_fd;
 }
 
 
 
 void set_rts(int val)
 {
-	int flags;
-	int result;
-
-	result = ioctl(port_fd, TIOCMGET, &flags);
-	if( result == -1 ) {
-		printf("Error %i while reading port io flags\n", errno);
-		return;
-	}
-
-	if (val) {
-		flags |= TIOCM_RTS;
-	} else {
-		flags &= ~(TIOCM_RTS);
-	}
-
-	result = ioctl(port_fd, TIOCMSET, &flags);
-	if( result == -1 )
-		printf("Error %i while setting port io flags\n", errno);
+    int flags;
+    int result;
+
+    result = ioctl(port_fd, TIOCMGET, &flags);
+
+    if (result == -1) {
+        printf("Error %i while reading port io flags\n", errno);
+        return;
+    }
+
+    if (val) {
+        flags |= TIOCM_RTS;
+    }
+    else {
+        flags &= ~(TIOCM_RTS);
+    }
+
+    result = ioctl(port_fd, TIOCMSET, &flags);
+
+    if (result == -1) {
+        printf("Error %i while setting port io flags\n", errno);
+    }
 }
 
 
@@ -338,24 +421,28 @@ void set_rts(int val)
 
 void set_dtr(int val)
 {
-	int flags;
-	int result;
-
-	result = ioctl(port_fd, TIOCMGET, &flags);
-	if( result == -1 ) {
-		printf("Error %i while reading port io flags\n", errno);
-		return;
-	}
-
-	if (val) {
-		flags |= TIOCM_DTR;
-	} else {
-		flags &= ~(TIOCM_DTR);
-	}
-
-	result = ioctl(port_fd, TIOCMSET, &flags);
-	if( result == -1 )
-		printf("Error %i while setting port io flags\n", errno);
+    int flags;
+    int result;
+
+    result = ioctl(port_fd, TIOCMGET, &flags);
+
+    if (result == -1) {
+        printf("Error %i while reading port io flags\n", errno);
+        return;
+    }
+
+    if (val) {
+        flags |= TIOCM_DTR;
+    }
+    else {
+        flags &= ~(TIOCM_DTR);
+    }
+
+    result = ioctl(port_fd, TIOCMSET, &flags);
+
+    if (result == -1) {
+        printf("Error %i while setting port io flags\n", errno);
+    }
 }
 
 
diff --git a/msba2-common/tools/src/serial.h b/msba2-common/tools/src/serial.h
index 4ef9a82e5bc151404d3f0ed23785ccadc4032bc3..3887a189473d1b0d8640474aa8e96c4380c095e2 100644
--- a/msba2-common/tools/src/serial.h
+++ b/msba2-common/tools/src/serial.h
@@ -1,7 +1,7 @@
 #ifndef SERIAL_H
 #define SERIAL_H
 
-extern char* baud_rate;
+extern char *baud_rate;
 
 int open_serial_port(const char *port_name);
 int write_serial_port(const void *buf, int num);
diff --git a/msba2-common/tools/src/settings.c b/msba2-common/tools/src/settings.c
index d52e24a03f5ccfba5a2b682e5062aa218ed916c2..405d648e1a1113ba8f7b8faa623bfe631e39184b 100644
--- a/msba2-common/tools/src/settings.c
+++ b/msba2-common/tools/src/settings.c
@@ -20,7 +20,7 @@
 
 /* If this code fails to build, please provide at least the following
  * information when requesting (free) technical support.
- * 
+ *
  * 1: Complete copy of all messages during the build.
  * 2: Output of "gtk-config --version"
  * 3: Output of "gtk-config --libs"
@@ -43,130 +43,167 @@
 #define DEFAULT_BAUD "115200"
 #define DEFAULT_CRYSTAL "16"
 
-char *baud_list[]={"115200", "57600", "38400",
-       "19200", "9600", "4800", "2400", "1200", "300", NULL};
+char *baud_list[] = {"115200", "57600", "38400",
+                     "19200", "9600", "4800", "2400", "1200", "300", NULL
+                    };
 
-static char file[128]={DEFAULT_FILE};
-static char port[64]={DEFAULT_PORT};
-static char baud[64]={DEFAULT_BAUD};
-static char crystal[64]={DEFAULT_CRYSTAL};
+static char file[128] = {DEFAULT_FILE};
+static char port[64] = {DEFAULT_PORT};
+static char baud[64] = {DEFAULT_BAUD};
+static char crystal[64] = {DEFAULT_CRYSTAL};
 
-static char settings_file[256]={'\0'};
+static char settings_file[256] = {'\0'};
 
 
 void init_settings(void)
 {
-	const char *home_dir;
-	FILE *fp;
-	char buf[1024], *p, *q;
-
-	home_dir = getenv("HOME");
-	if (home_dir && *home_dir) {
-		snprintf(settings_file, sizeof(settings_file),
-			"%s/.lpc2k_pgm", home_dir);
-		fp = fopen(settings_file, "r");
-		if (fp == NULL) return;
-		while (!feof(fp)) {
-			buf[0] = '\0';
-			fgets(buf, sizeof(buf), fp);
-			if (strncmp(buf, "file:", 5) == 0) {
-				for (p=buf+5; isspace(*p); p++) ;
-				q = rindex(p, '\n'); if (q) *q = '\0';
-				q = rindex(p, '\r'); if (q) *q = '\0';
-				snprintf(file, sizeof(file), "%s", p);
-			}
-			if (strncmp(buf, "port:", 5) == 0) {
-				for (p=buf+5; isspace(*p); p++) ;
-				q = rindex(p, '\n'); if (q) *q = '\0';
-				q = rindex(p, '\r'); if (q) *q = '\0';
-				snprintf(port, sizeof(port), "%s", p);
-			}
-			if (strncmp(buf, "baud:", 5) == 0) {
-				for (p=buf+5; isspace(*p); p++) ;
-				q = rindex(p, '\n'); if (q) *q = '\0';
-				q = rindex(p, '\r'); if (q) *q = '\0';
-				snprintf(baud, sizeof(baud), "%s", p);
-			}
-			if (strncmp(buf, "xtal:", 5) == 0) {
-				for (p=buf+5; isspace(*p); p++) ;
-				q = rindex(p, '\n'); if (q) *q = '\0';
-				q = rindex(p, '\r'); if (q) *q = '\0';
-				snprintf(crystal, sizeof(crystal), "%s", p);
-			}
-		}
-		fclose(fp);
-	}
+    const char *home_dir;
+    FILE *fp;
+    char buf[1024], *p, *q;
+
+    home_dir = getenv("HOME");
+
+    if (home_dir && *home_dir) {
+        snprintf(settings_file, sizeof(settings_file),
+                 "%s/.lpc2k_pgm", home_dir);
+        fp = fopen(settings_file, "r");
+
+        if (fp == NULL) {
+            return;
+        }
+
+        while (!feof(fp)) {
+            buf[0] = '\0';
+            fgets(buf, sizeof(buf), fp);
+
+            if (strncmp(buf, "file:", 5) == 0) {
+                for (p = buf + 5; isspace(*p); p++);
+                q = rindex(p, '\n');
+                if (q) {
+                    *q = '\0';
+                }
+                q = rindex(p, '\r');
+                if (q) {
+                    *q = '\0';
+                }
+                snprintf(file, sizeof(file), "%s", p);
+            }
+
+            if (strncmp(buf, "port:", 5) == 0) {
+                for (p = buf + 5; isspace(*p); p++);
+                q = rindex(p, '\n');
+                if (q) {
+                    *q = '\0';
+                }
+                q = rindex(p, '\r');
+                if (q) {
+                    *q = '\0';
+                }
+                snprintf(port, sizeof(port), "%s", p);
+            }
+
+            if (strncmp(buf, "baud:", 5) == 0) {
+                for (p = buf + 5; isspace(*p); p++);
+                q = rindex(p, '\n');
+                if (q) {
+                    *q = '\0';
+                }
+                q = rindex(p, '\r');
+                if (q) {
+                    *q = '\0';
+                }
+                snprintf(baud, sizeof(baud), "%s", p);
+            }
+
+            if (strncmp(buf, "xtal:", 5) == 0) {
+                for (p = buf + 5; isspace(*p); p++) ;
+                q = rindex(p, '\n');
+                if (q) {
+                    *q = '\0';
+                }
+                q = rindex(p, '\r');
+                if (q) {
+                    *q = '\0';
+                }
+                snprintf(crystal, sizeof(crystal), "%s", p);
+            }
+        }
+
+        fclose(fp);
+    }
 }
 
 void write_settings_file(void)
 {
-	FILE *fp;
-
-	if (settings_file[0] == '\0') return;
-	fp = fopen(settings_file, "w");
-	if (fp == NULL) return;
-	fprintf(fp, "file: %s\n", file);
-	fprintf(fp, "port: %s\n", port);
-	fprintf(fp, "baud: %s\n", baud);
-	fprintf(fp, "xtal: %s\n", crystal);
-	fflush(fp);
-	fclose(fp);
+    FILE *fp;
+
+    if (settings_file[0] == '\0') {
+        return;
+    }
+
+    fp = fopen(settings_file, "w");
+
+    if (fp == NULL) {
+        return;
+    }
+
+    fprintf(fp, "file: %s\n", file);
+    fprintf(fp, "port: %s\n", port);
+    fprintf(fp, "baud: %s\n", baud);
+    fprintf(fp, "xtal: %s\n", crystal);
+    fflush(fp);
+    fclose(fp);
 }
 
-const char * file_setting(void)
+const char *file_setting(void)
 {
-	return file;
+    return file;
 }
 
-const char * port_setting(void)
+const char *port_setting(void)
 {
-	return port;
+    return port;
 }
 
-const char * baud_setting(void)
+const char *baud_setting(void)
 {
-	return baud;
+    return baud;
 }
 
-const char * crystal_setting(void)
+const char *crystal_setting(void)
 {
-	return crystal;
+    return crystal;
 }
 
 void new_file_setting(const char *new_file)
 {
-	if (strcmp(file, new_file)) {
-		snprintf(file, sizeof(file), "%s", new_file);
-		write_settings_file();
-	}
+    if (strcmp(file, new_file)) {
+        snprintf(file, sizeof(file), "%s", new_file);
+        write_settings_file();
+    }
 }
 
 void new_port_setting(const char *new_port)
 {
-	if (strcmp(port, new_port)) {
-		snprintf(port, sizeof(port), "%s", new_port);
-		write_settings_file();
-	}
+    if (strcmp(port, new_port)) {
+        snprintf(port, sizeof(port), "%s", new_port);
+        write_settings_file();
+    }
 }
 
 void new_baud_setting(const char *new_baud)
 {
-	if (strcmp(baud, new_baud)) {
-		snprintf(baud, sizeof(baud), "%s", new_baud);
-		write_settings_file();
-	}
+    if (strcmp(baud, new_baud)) {
+        snprintf(baud, sizeof(baud), "%s", new_baud);
+        write_settings_file();
+    }
 }
 
 void new_crystal_setting(const char *new_xtal)
 {
-	if (strcmp(crystal, new_xtal)) {
-		snprintf(crystal, sizeof(crystal), "%s", new_xtal);
-		write_settings_file();
-	}
+    if (strcmp(crystal, new_xtal)) {
+        snprintf(crystal, sizeof(crystal), "%s", new_xtal);
+        write_settings_file();
+    }
 }
 
-
-
-
-
-
diff --git a/msba2-common/tools/src/settings.h b/msba2-common/tools/src/settings.h
index 20686821a4bc69bbc7e55124c1c39b31a93f3cf0..47356be96cef2869e7bbeecdeca44eb5a97dd13c 100644
--- a/msba2-common/tools/src/settings.h
+++ b/msba2-common/tools/src/settings.h
@@ -1,9 +1,9 @@
 
 extern void init_settings(void);
-extern const char * file_setting(void);
-extern const char * port_setting(void);
-extern const char * baud_setting(void);
-extern const char * crystal_setting(void);
+extern const char *file_setting(void);
+extern const char *port_setting(void);
+extern const char *baud_setting(void);
+extern const char *crystal_setting(void);
 extern void new_file_setting(const char *new_file);
 extern void new_port_setting(const char *new_port);
 extern void new_baud_setting(const char *new_baud);
diff --git a/msba2-common/tools/src/uuencode.c b/msba2-common/tools/src/uuencode.c
index 5cc76e796c6ece3203030aaa9dca1506b532a370..7b6856ab6408a4f824bef170776ac353d940f9b8 100644
--- a/msba2-common/tools/src/uuencode.c
+++ b/msba2-common/tools/src/uuencode.c
@@ -20,7 +20,7 @@
 
 /* If this code fails to build, please provide at least the following
  * information when requesting (free) technical support.
- * 
+ *
  * 1: Complete copy of all messages during the build.
  * 2: Output of "gtk-config --version"
  * 3: Output of "gtk-config --libs"
@@ -37,61 +37,86 @@ static char uuchar(unsigned int val);
 
 void uuencode(char *str, const unsigned char *data, int num)
 {
-	int i, n;
-	unsigned int val;
-
-	*str++ = uuchar(num);
-
-	n = (num + 2) / 3;
-	for (i=0; i<n; i++) {
-		val = ((data[0] & 0xFF) << 16)
-		   |  ((data[1] & 0xFF) << 8)
-		   |  ((data[2] & 0xFF) << 0);
-		*str++ = uuchar(val >> 18);
-		*str++ = uuchar(val >> 12);
-		*str++ = uuchar(val >>  6);
-		*str++ = uuchar(val >>  0);
-		data += 3;
-	}
-	*str = '\0';
+    int i, n;
+    unsigned int val;
+
+    *str++ = uuchar(num);
+
+    n = (num + 2) / 3;
+
+    for (i = 0; i < n; i++) {
+        val = ((data[0] & 0xFF) << 16)
+              | ((data[1] & 0xFF) << 8)
+              | ((data[2] & 0xFF) << 0);
+        *str++ = uuchar(val >> 18);
+        *str++ = uuchar(val >> 12);
+        *str++ = uuchar(val >>  6);
+        *str++ = uuchar(val >>  0);
+        data += 3;
+    }
+
+    *str = '\0';
 }
 
 int uudecode(const char *str, unsigned char *data, int max)
 {
-	int num=0;
-	int i, n;
-	unsigned int val;
-
-	if (*str == '\0') return 0;
-
-	num = *str++ - 32;
-	if (num < 1 || num > 45) return 0;
-
-	n = (num + 2) / 3;
-	for (i=0; i<n; i++) {
-		if (str[0] < 32 || str[0] > 96) return 0;
-		if (str[1] < 32 || str[1] > 96) return 0;
-		if (str[2] < 32 || str[2] > 96) return 0;
-		if (str[3] < 32 || str[3] > 96) return 0;
-		val = (((str[0] - 32) & 0x3F) << 18)
-		   |  (((str[1] - 32) & 0x3F) << 12)
-		   |  (((str[2] - 32) & 0x3F) << 6)
-		   |  (((str[3] - 32) & 0x3F) << 0);
-		*data++ = (val >> 16) & 0xFF;
-		*data++ = (val >> 8) & 0xFF;
-		*data++ = (val >> 0) & 0xFF;
-		str += 4;
-	}
-	return num;
+    int num = 0;
+    int i, n;
+    unsigned int val;
+
+    if (*str == '\0') {
+        return 0;
+    }
+
+    num = *str++ - 32;
+
+    if (num < 1 || num > 45) {
+        return 0;
+    }
+
+    n = (num + 2) / 3;
+
+    for (i = 0; i < n; i++) {
+        if (str[0] < 32 || str[0] > 96) {
+            return 0;
+        }
+
+        if (str[1] < 32 || str[1] > 96) {
+            return 0;
+        }
+
+        if (str[2] < 32 || str[2] > 96) {
+            return 0;
+        }
+
+        if (str[3] < 32 || str[3] > 96) {
+            return 0;
+        }
+
+        val = (((str[0] - 32) & 0x3F) << 18)
+              | (((str[1] - 32) & 0x3F) << 12)
+              | (((str[2] - 32) & 0x3F) << 6)
+              | (((str[3] - 32) & 0x3F) << 0);
+        *data++ = (val >> 16) & 0xFF;
+        *data++ = (val >> 8) & 0xFF;
+        *data++ = (val >> 0) & 0xFF;
+        str += 4;
+    }
+
+    return num;
 }
 
 
 static char uuchar(unsigned int val)
 {
-	val &= 0x3F;
-	val += 0x20;
-	if (val == 0x20) val = 0x60;
-	return val;
+    val &= 0x3F;
+    val += 0x20;
+
+    if (val == 0x20) {
+        val = 0x60;
+    }
+
+    return val;
 }
 
 
diff --git a/msba2/board_init.c b/msba2/board_init.c
index f250109c088efa568b75cce74b31d1d18fa55797..729854e433e811a8cd54f1f28a56889053ac9876 100644
--- a/msba2/board_init.c
+++ b/msba2/board_init.c
@@ -1,19 +1,22 @@
 #include <board.h>
 #include <cpu.h>
 
-void loop_delay(void) {
+void loop_delay(void)
+{
     volatile uint16_t i, j;
+
     for (i = 1; i < 30; i++) {
         for (j = 1; j != 0; j++) {
-            asm volatile (" nop ");
+            asm volatile(" nop ");
         }
     }
 }
 
-void bl_blink(void) {
+void bl_blink(void)
+{
     LED_RED_ON;
     LED_GREEN_ON;
-    
+
     loop_delay();
 
     LED_RED_OFF;
@@ -33,7 +36,7 @@ void bl_init_ports(void)
     FIO3DIR |= LED_GREEN_PIN;
     LED_RED_OFF;
     LED_GREEN_OFF;
-    
+
     /* short blinking of both of the LEDs on startup */
     bl_blink();
 }
diff --git a/msba2/include/board.h b/msba2/include/board.h
index 2b1f28fd2a622c4fdcb8ae9619b8e1bbf6aebbc2..398255ab4daca5d60fb7d24ee7cdcc50132dfff7 100644
--- a/msba2/include/board.h
+++ b/msba2/include/board.h
@@ -1,5 +1,5 @@
 #ifndef __BOARD_H
-#define __BOARD_H 
+#define __BOARD_H
 
 #include <msba2_common.h>
 #include <bitarithm.h>
diff --git a/native/drivers/native-ltc4150.c b/native/drivers/native-ltc4150.c
index 2f2d414cf80f35a1f5320c649f542b6739e88e47..babe801616bafd72e13da4d58c6413a5397f72a7 100644
--- a/native/drivers/native-ltc4150.c
+++ b/native/drivers/native-ltc4150.c
@@ -73,7 +73,8 @@ void ltc4150_enable_int(void)
 void ltc4150_sync_blocking(void)
 {
     DEBUG("ltc4150_sync_blocking()\n");
-    for(int i = native_ltc4150_startup_delay; i>0; i--);
+
+    for (int i = native_ltc4150_startup_delay; i > 0; i--);
 }
 
 /**
diff --git a/olimex_lpc2148/board_init.c b/olimex_lpc2148/board_init.c
index 874feb88120a0da24985d99c951bbf5d487f5da8..1d1746be4dfd1fa11ec6039860812d94a96fcc32 100644
--- a/olimex_lpc2148/board_init.c
+++ b/olimex_lpc2148/board_init.c
@@ -13,69 +13,69 @@
 
 static void feed(void)
 {
-	PLL0FEED = 0xAA;
-	PLL0FEED = 0x55;
+    PLL0FEED = 0xAA;
+    PLL0FEED = 0x55;
 }
 
 void bl_init_clks(void)
 {
 
-	// 				Setting the Phased Lock Loop (PLL)
-	//               ----------------------------------
-	//
-	// Olimex LPC-P2148 has a 12.0000 mhz crystal
-	//
-	// We'd like the LPC2148 to run at 60 mhz (has to be an even multiple of crystal)
-	//
-	// According to the Philips LPC2148 manual:   M = cclk / Fosc	where:	M    = PLL multiplier (bits 0-4 of PLLCFG)
-	//																		cclk = 60000000 hz
-	//																		Fosc = 12000000 hz
-	//
-	// Solving:	M = 60000000 / 12000000 = 5
-	//
-	//			Note: M - 1 must be entered into bits 0-4 of PLLCFG (assign 4 to these bits)
-	//
-	//
-	// The Current Controlled Oscilator (CCO) must operate in the range 156 mhz to 320 mhz
-	//
-	// According to the Philips LPC2148 manual:	Fcco = cclk * 2 * P    where:	Fcco = CCO frequency
-	//																			cclk = 60000000 hz
-	//																			P = PLL divisor (bits 5-6 of PLLCFG)
-	//
-	// Solving:	Fcco = 60000000 * 2 * P
-	//			P = 2  (trial value)
-	//			Fcco = 60000000 * 2 * 2
-	//			Fcc0 = 240000000 hz    (good choice for P since it's within the 156 mhz to 320 mhz range)
-	//
-	// From Table 22 (page 34) of Philips LPC2148 manual    P = 2, PLLCFG bits 5-6 = 1  (assign 1 to these bits)
-	//
-	// Finally:      PLLCFG = 0  01  00100  =  0x24
-	//
-	// Final note: to load PLLCFG register, we must use the 0xAA followed 0x55 write sequence to the PLLFEED register
-	//             this is done in the short function feed() below
-	//
-
-	// Setting Multiplier and Divider values
-  	PLL0CFG = 0x24;
-  	feed();
-
-	// Enabling the PLL */
-	PLL0CON = 0x1;
-	feed();
-
-	// Wait for the PLL to lock to set frequency
-	while(!(PLL0STAT & PLOCK)) ;
-
-	// Connect the PLL as the clock source
-	PLL0CON = 0x3;
-	feed();
-
-	// Enabling MAM and setting number of clocks used for Flash memory fetch
-	MAMTIM = 0x3;
-	MAMCR = 0x2;
-
-	// Setting peripheral Clock (pclk) to 1/2 System Clock (cclk)
-	VPBDIV = PCLK_DIV;
+    // 				Setting the Phased Lock Loop (PLL)
+    //               ----------------------------------
+    //
+    // Olimex LPC-P2148 has a 12.0000 mhz crystal
+    //
+    // We'd like the LPC2148 to run at 60 mhz (has to be an even multiple of crystal)
+    //
+    // According to the Philips LPC2148 manual:   M = cclk / Fosc	where:	M    = PLL multiplier (bits 0-4 of PLLCFG)
+    //																		cclk = 60000000 hz
+    //																		Fosc = 12000000 hz
+    //
+    // Solving:	M = 60000000 / 12000000 = 5
+    //
+    //			Note: M - 1 must be entered into bits 0-4 of PLLCFG (assign 4 to these bits)
+    //
+    //
+    // The Current Controlled Oscilator (CCO) must operate in the range 156 mhz to 320 mhz
+    //
+    // According to the Philips LPC2148 manual:	Fcco = cclk * 2 * P    where:	Fcco = CCO frequency
+    //																			cclk = 60000000 hz
+    //																			P = PLL divisor (bits 5-6 of PLLCFG)
+    //
+    // Solving:	Fcco = 60000000 * 2 * P
+    //			P = 2  (trial value)
+    //			Fcco = 60000000 * 2 * 2
+    //			Fcc0 = 240000000 hz    (good choice for P since it's within the 156 mhz to 320 mhz range)
+    //
+    // From Table 22 (page 34) of Philips LPC2148 manual    P = 2, PLLCFG bits 5-6 = 1  (assign 1 to these bits)
+    //
+    // Finally:      PLLCFG = 0  01  00100  =  0x24
+    //
+    // Final note: to load PLLCFG register, we must use the 0xAA followed 0x55 write sequence to the PLLFEED register
+    //             this is done in the short function feed() below
+    //
+
+    // Setting Multiplier and Divider values
+    PLL0CFG = 0x24;
+    feed();
+
+    // Enabling the PLL */
+    PLL0CON = 0x1;
+    feed();
+
+    // Wait for the PLL to lock to set frequency
+    while (!(PLL0STAT & PLOCK)) ;
+
+    // Connect the PLL as the clock source
+    PLL0CON = 0x3;
+    feed();
+
+    // Enabling MAM and setting number of clocks used for Flash memory fetch
+    MAMTIM = 0x3;
+    MAMCR = 0x2;
+
+    // Setting peripheral Clock (pclk) to 1/2 System Clock (cclk)
+    VPBDIV = PCLK_DIV;
 }
 
 
diff --git a/olimex_lpc2148/rs232.c b/olimex_lpc2148/rs232.c
index 43e70a00f21cf76d20e530490b663615087d0e5b..ac885b877f276c9131d78d0bb01e97ffde516528 100644
--- a/olimex_lpc2148/rs232.c
+++ b/olimex_lpc2148/rs232.c
@@ -1,65 +1,75 @@
-//rs232.c
-#include "rs232.h"
-
-unsigned int processorClockFrequency(void)
-{
-  //return real processor clock speed
-  return OSCILLATOR_CLOCK_FREQUENCY * (PLL0CON & 1 ? (PLL0CFG & 0xF) + 1 : 1);
-}
-
-unsigned int peripheralClockFrequency(void)
-{
-  //VPBDIV - determines the relationship between the processor clock (cclk)
-  //and the clock used by peripheral devices (pclk).
-  unsigned int divider = 0;
-  switch (VPBDIV & 3)
-  {
-    case 0: divider = 4;  break;
-    case 1: divider = 1;  break;
-    case 2: divider = 2;  break;
-  }
-  return processorClockFrequency() / divider;
-}
-
-/**** UART0 ****/
-void UART1Initialize(unsigned int baud)
-{
-  unsigned int divisor = peripheralClockFrequency() / (16 * baud);
-
-  //set Line Control Register (8 bit, 1 stop bit, no parity, enable DLAB)
-//  U0LCR_bit.WLS   = 0x3;    //8 bit
-//  U0LCR_bit.SBS   = 0x0;    //1 stop bit
-//  U0LCR_bit.PE    = 0x0;    //no parity
-//  U0LCR_bit.DLAB  = 0x1;    //enable DLAB
-  //with one row
-    U1LCR = 0x83;
-
-
-  //devisor
-  U1DLL = divisor & 0xFF;
-  U1DLM = (divisor >> 8) & 0xFF;
-  U1LCR &= ~0x80;
-
-  //set functionalite to pins:  port0.0 -> TX0,  port0.1 -> RXD0
-//  PINSEL0_bit.P0_0 = 0x1;
-//  PINSEL0_bit.P0_1 = 0x1;
-  //with one row
-  PINSEL0 |= BIT16;
-  PINSEL0 &= ~BIT17;
-
-}
-
-void UART1WriteChar(int ch0)
-{
-  while (!(U1LSR & BIT5));
-  U1THR = ch0;
-}
-
-unsigned char UART0ReadChar(void)
-{
-  //when U0LSR_bit.DR is 1 - U0RBR contains valid data
-//  while (U0LSR_bit.DR == 0);
-  return U0RBR;
-}
-
-
+//rs232.c
+#include "rs232.h"
+
+unsigned int processorClockFrequency(void)
+{
+    //return real processor clock speed
+    return OSCILLATOR_CLOCK_FREQUENCY * (PLL0CON & 1 ? (PLL0CFG & 0xF) + 1 : 1);
+}
+
+unsigned int peripheralClockFrequency(void)
+{
+    //VPBDIV - determines the relationship between the processor clock (cclk)
+    //and the clock used by peripheral devices (pclk).
+    unsigned int divider = 0;
+
+    switch (VPBDIV & 3) {
+        case 0:
+            divider = 4;
+            break;
+
+        case 1:
+            divider = 1;
+            break;
+
+        case 2:
+            divider = 2;
+            break;
+    }
+
+    return processorClockFrequency() / divider;
+}
+
+/**** UART0 ****/
+void UART1Initialize(unsigned int baud)
+{
+    unsigned int divisor = peripheralClockFrequency() / (16 * baud);
+
+    //set Line Control Register (8 bit, 1 stop bit, no parity, enable DLAB)
+    //  U0LCR_bit.WLS   = 0x3;    //8 bit
+    //  U0LCR_bit.SBS   = 0x0;    //1 stop bit
+    //  U0LCR_bit.PE    = 0x0;    //no parity
+    //  U0LCR_bit.DLAB  = 0x1;    //enable DLAB
+    //with one row
+    U1LCR = 0x83;
+
+
+    //devisor
+    U1DLL = divisor & 0xFF;
+    U1DLM = (divisor >> 8) & 0xFF;
+    U1LCR &= ~0x80;
+
+    //set functionalite to pins:  port0.0 -> TX0,  port0.1 -> RXD0
+    //  PINSEL0_bit.P0_0 = 0x1;
+    //  PINSEL0_bit.P0_1 = 0x1;
+    //with one row
+    PINSEL0 |= BIT16;
+    PINSEL0 &= ~BIT17;
+
+}
+
+void UART1WriteChar(int ch0)
+{
+    while (!(U1LSR & BIT5));
+
+    U1THR = ch0;
+}
+
+unsigned char UART0ReadChar(void)
+{
+    //when U0LSR_bit.DR is 1 - U0RBR contains valid data
+    //  while (U0LSR_bit.DR == 0);
+    return U0RBR;
+}
+
+
diff --git a/olimex_lpc2148/tick.c b/olimex_lpc2148/tick.c
index 4b8912607b4c3f7514e72cc4e979296f42291269..0d627069430b5a49e977ed265e268321fdae8357 100644
--- a/olimex_lpc2148/tick.c
+++ b/olimex_lpc2148/tick.c
@@ -23,7 +23,7 @@ Boston, MA 02111-1307, USA.  */
 #include "minimal_dbg_console.h"
 #include "VIC.h"
 
-void Timer0_IRQHandler (void) __attribute__((interrupt("IRQ")));
+void Timer0_IRQHandler(void) __attribute__((interrupt("IRQ")));
 
 extern void eINT();
 extern void dINT();
@@ -35,9 +35,9 @@ void driver_timer_load(void)
     T0PR  = 3000;               // Prescaler is set to relevant pclk , counter is incremented every T0PR tact.
     T0CCR = 0;                  // Capture is disabled.
     T0EMR = 0;                  // No external match output.
-    T0TC= 0;
-    T0MR0= 1000;
-    T0MCR|= BIT0 + BIT1;
+    T0TC = 0;
+    T0MR0 = 1000;
+    T0MCR |= BIT0 + BIT1;
     T0TCR = BIT0;               // Enable timer 0.
 
     dINT();                      // Disable all interrupts
@@ -49,15 +49,15 @@ void driver_timer_load(void)
 
 int counter = 0;
 
-void Timer0_IRQHandler (void)
+void Timer0_IRQHandler(void)
 {
     extern unsigned int sched_context_switch_request;
     counter++;
-	T0IR |= 0xff;											// reset timer1 interrupt flag
-	sl_printf("#");
+    T0IR |= 0xff;											// reset timer1 interrupt flag
+    sl_printf("#");
 
     sched_context_switch_request = 1;
 
-	VICVectAddr = 0;										// acknowledge interrupt (if using VIC IRQ)
+    VICVectAddr = 0;										// acknowledge interrupt (if using VIC IRQ)
 }
 
diff --git a/pttu/board_init.c b/pttu/board_init.c
index b5b78bde252621393a597df4613276d10e07d6b3..18ba75d8504efa10ea24015079b7ce7b0562a49d 100644
--- a/pttu/board_init.c
+++ b/pttu/board_init.c
@@ -47,117 +47,117 @@ and the mailinglist (subscription via web site)
 
 void bl_init_ports(void)
 {
-	SCS |= BIT0;											// Set IO Ports to fast switching mode
-
-	/* UART0 */
-	PINSEL0 |= BIT4 + BIT6;									// RxD0 and TxD0
-	PINSEL0 &= ~(BIT5 + BIT7);
-
-	/*Turn Board on*/
-	PINMODE0 |= BIT1;
-	FIO0DIR |= BIT27;
-	FIO0CLR = BIT27;
-
-	/* 5V*/
-	FIO1DIR |= BIT28; // Synch
-	FIO1SET = BIT28;  // No Powersave
-
-	FIO1DIR |= BIT27; // 5V off
-	FIO1CLR = BIT27;
-
-	/* Disable Resistors on Buttons */
-	PINMODE4 |= BIT9 + BIT11;
-
-	/* Disable Resistors on LED - and Ports to output*/
-	PINMODE7 |= BIT19 + BIT21;
-	PINMODE2 |= BIT1;
-	FIO1DIR |= BIT0;
-	FIO3DIR |= BIT25 + BIT26;
-	FIO1SET = BIT0;
-	FIO3SET = BIT25 + BIT26;
-
-	// Config and Disable PA
-	FIO1DIR |= BIT25 + BIT26 + BIT22;
-	FIO1SET = BIT26;
-	FIO1CLR = BIT25;
-	FIO1CLR = BIT22; // PA /Shutdown
-	FIO0DIR |= BIT26; // **  // Important: First put this Port as DA 2.0V and then turn on PA!!
-	FIO0SET = BIT26; // **
-
-	// Configure GPS
-	PINMODE3 |= BIT3 + BIT7; // No Pullup on 1.17 & 1.19
-	PINMODE9 |= BIT27 + BIT25; // No Pullup for Uart
-	FIO1DIR |= BIT17;
-	FIO1CLR = BIT17; // Turn off GPS
-	FIO1DIR |= BIT19;
-	FIO1CLR = BIT19; // Hold in Reset
-	PINSEL9 |= BIT24 + BIT25 + BIT26 + BIT27; //4.28 & 4.29 as Uart3
-
-	// Nanotron
-	FIO2DIR &= ~BIT8;	// nanotron uC IRQ as input
-	FIO1DIR |= BIT15;	// nanotron power on reset
-	FIO1DIR &= ~BIT14;	// nanotron uC RESET as input
-	FIO1DIR &= ~BIT10;	// nanotron uC Vcc as input
-	FIO1DIR |= BIT9;	// nanotron ENABLE as output
-	FIO1DIR &= ~BIT4;	// nanotron Rx/Tx as input
-
-	FIO1CLR = BIT15;
-	FIO1CLR = BIT9;		// Enable power
-
-	PINMODE1 |= BIT1;   // No Pullup for CS
-	FIO0DIR |= BIT16;   // CS as output
-	FIO0SET = BIT16;	// drive cs inactive
-	FIO0DIR |= BIT18 + BIT15;   // SPi Output
-
-	// RFID
-	FIO1DIR |= BIT1;    // RFID Power
-	FIO1CLR = BIT1;		//
-
-	FIO0DIR |= BIT1;    // RFID Reset
-	FIO0SET = BIT1;     // Hold in Reset
-
-	FIO0DIR &= ~BIT10;  // LED as INPUT
-	FIO0DIR &= ~BIT11;  // DATA as INPUT
-	PINMODE0 |= BIT19 + BIT21; // No Pullups
-
-	// LTC4150 ARM
-	FIO0DIR |= BIT5;
-	FIO0CLR = BIT5;
-
-	// LTC4150 System
-	FIO0DIR |= BIT24;
-	FIO0CLR = BIT24;
-
-	// Battery Voltage (AD)
-	PINMODE1 |= BIT19;
-	PINSEL1 &= ~BIT19;
-	PINSEL1 |= BIT18;
-
-	//cc1100
-	FIO0DIR |= BIT6 + BIT7 + BIT9;
-	FIO0SET = BIT6;
-	FIO0SET = BIT7 + BIT9;
-
-	//SD
-	FIO2DIR |= BIT12 + BIT13 + BIT11;
-	FIO0DIR |= BIT20 + BIT22 + BIT21;
-
-	//Tetra
-	FIO2DIR |= BIT0 + BIT7;
-
-
-	// No Pullups on any port
-	int nopullup = BIT1 + BIT3 + BIT5 + BIT7 + BIT9 + BIT11 + BIT13 + BIT15 + BIT17 + BIT19 + BIT21 + BIT23 + BIT25 + BIT27 + BIT29 + BIT31;
-	PINMODE0 = nopullup - BIT13 - BIT15 - BIT17 - BIT19;
-	PINMODE1 = BIT1 + BIT3 + BIT5 + BIT7 + BIT9 + BIT11 + BIT13 + BIT15 + BIT17 + BIT19 + BIT21;
-	PINMODE2 = nopullup;
-	PINMODE3 = nopullup;
-	PINMODE4 = nopullup;
-	PINMODE5 = nopullup;
-	PINMODE6 = nopullup;
-	PINMODE7 = nopullup;
-	PINMODE8 = nopullup;
-	PINMODE9 = nopullup;
+    SCS |= BIT0;											// Set IO Ports to fast switching mode
+
+    /* UART0 */
+    PINSEL0 |= BIT4 + BIT6;									// RxD0 and TxD0
+    PINSEL0 &= ~(BIT5 + BIT7);
+
+    /*Turn Board on*/
+    PINMODE0 |= BIT1;
+    FIO0DIR |= BIT27;
+    FIO0CLR = BIT27;
+
+    /* 5V*/
+    FIO1DIR |= BIT28; // Synch
+    FIO1SET = BIT28;  // No Powersave
+
+    FIO1DIR |= BIT27; // 5V off
+    FIO1CLR = BIT27;
+
+    /* Disable Resistors on Buttons */
+    PINMODE4 |= BIT9 + BIT11;
+
+    /* Disable Resistors on LED - and Ports to output*/
+    PINMODE7 |= BIT19 + BIT21;
+    PINMODE2 |= BIT1;
+    FIO1DIR |= BIT0;
+    FIO3DIR |= BIT25 + BIT26;
+    FIO1SET = BIT0;
+    FIO3SET = BIT25 + BIT26;
+
+    // Config and Disable PA
+    FIO1DIR |= BIT25 + BIT26 + BIT22;
+    FIO1SET = BIT26;
+    FIO1CLR = BIT25;
+    FIO1CLR = BIT22; // PA /Shutdown
+    FIO0DIR |= BIT26; // **  // Important: First put this Port as DA 2.0V and then turn on PA!!
+    FIO0SET = BIT26; // **
+
+    // Configure GPS
+    PINMODE3 |= BIT3 + BIT7; // No Pullup on 1.17 & 1.19
+    PINMODE9 |= BIT27 + BIT25; // No Pullup for Uart
+    FIO1DIR |= BIT17;
+    FIO1CLR = BIT17; // Turn off GPS
+    FIO1DIR |= BIT19;
+    FIO1CLR = BIT19; // Hold in Reset
+    PINSEL9 |= BIT24 + BIT25 + BIT26 + BIT27; //4.28 & 4.29 as Uart3
+
+    // Nanotron
+    FIO2DIR &= ~BIT8;	// nanotron uC IRQ as input
+    FIO1DIR |= BIT15;	// nanotron power on reset
+    FIO1DIR &= ~BIT14;	// nanotron uC RESET as input
+    FIO1DIR &= ~BIT10;	// nanotron uC Vcc as input
+    FIO1DIR |= BIT9;	// nanotron ENABLE as output
+    FIO1DIR &= ~BIT4;	// nanotron Rx/Tx as input
+
+    FIO1CLR = BIT15;
+    FIO1CLR = BIT9;		// Enable power
+
+    PINMODE1 |= BIT1;   // No Pullup for CS
+    FIO0DIR |= BIT16;   // CS as output
+    FIO0SET = BIT16;	// drive cs inactive
+    FIO0DIR |= BIT18 + BIT15;   // SPi Output
+
+    // RFID
+    FIO1DIR |= BIT1;    // RFID Power
+    FIO1CLR = BIT1;		//
+
+    FIO0DIR |= BIT1;    // RFID Reset
+    FIO0SET = BIT1;     // Hold in Reset
+
+    FIO0DIR &= ~BIT10;  // LED as INPUT
+    FIO0DIR &= ~BIT11;  // DATA as INPUT
+    PINMODE0 |= BIT19 + BIT21; // No Pullups
+
+    // LTC4150 ARM
+    FIO0DIR |= BIT5;
+    FIO0CLR = BIT5;
+
+    // LTC4150 System
+    FIO0DIR |= BIT24;
+    FIO0CLR = BIT24;
+
+    // Battery Voltage (AD)
+    PINMODE1 |= BIT19;
+    PINSEL1 &= ~BIT19;
+    PINSEL1 |= BIT18;
+
+    //cc1100
+    FIO0DIR |= BIT6 + BIT7 + BIT9;
+    FIO0SET = BIT6;
+    FIO0SET = BIT7 + BIT9;
+
+    //SD
+    FIO2DIR |= BIT12 + BIT13 + BIT11;
+    FIO0DIR |= BIT20 + BIT22 + BIT21;
+
+    //Tetra
+    FIO2DIR |= BIT0 + BIT7;
+
+
+    // No Pullups on any port
+    int nopullup = BIT1 + BIT3 + BIT5 + BIT7 + BIT9 + BIT11 + BIT13 + BIT15 + BIT17 + BIT19 + BIT21 + BIT23 + BIT25 + BIT27 + BIT29 + BIT31;
+    PINMODE0 = nopullup - BIT13 - BIT15 - BIT17 - BIT19;
+    PINMODE1 = BIT1 + BIT3 + BIT5 + BIT7 + BIT9 + BIT11 + BIT13 + BIT15 + BIT17 + BIT19 + BIT21;
+    PINMODE2 = nopullup;
+    PINMODE3 = nopullup;
+    PINMODE4 = nopullup;
+    PINMODE5 = nopullup;
+    PINMODE6 = nopullup;
+    PINMODE7 = nopullup;
+    PINMODE8 = nopullup;
+    PINMODE9 = nopullup;
 }
 
 /** @} */
diff --git a/redbee-econotag/Makefile b/redbee-econotag/Makefile
index 391c9bd42f07c4d2520fb080a1a3e1adec80b2fb..ae4ccfd0a780265afd897e9e6930b8b90f81579d 100644
--- a/redbee-econotag/Makefile
+++ b/redbee-econotag/Makefile
@@ -4,6 +4,12 @@ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines
 DEP = $(SRC:%.c=$(BINDIR)%.d)
 export ARCH = redbee-econotag_base.a
 
+INCLUDES += -I$(RIOTBOARD)/redbee-econotag/drivers/include
+INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include
+INCLUDES += -I$(RIOTBASE)/cpu/mc1322x/include
+
+.PHONY: $(BINDIR)/$(ARCH)
+
 all: $(BINDIR)$(ARCH)
 	$(MAKE) -C drivers
 
diff --git a/redbee-econotag/README b/redbee-econotag/README
new file mode 100644
index 0000000000000000000000000000000000000000..7cce0fdd0536ab9f6da6205048dc66f544f02f12
--- /dev/null
+++ b/redbee-econotag/README
@@ -0,0 +1,11 @@
+Flashing:
+tools/mc1322x-load.pl -f <path/to/binary> -t /dev/<tty-device>
+
+more information: https://github.com/malvira/libmc1322x/wiki/libmc1322x#loading-images-to-ram-with-mc1322x-loadpl
+
+Erase:
+cd tools/ftditools/
+make
+./bbmc -l redbee-econotag erase
+
+more information: https://github.com/malvira/libmc1322x/wiki/bbmc
\ No newline at end of file
diff --git a/redbee-econotag/board_init.c b/redbee-econotag/board_init.c
index 5a0b03177cb1366c47f0b445a2ba77d1ca91a537..7cafd1a0e2db4369a958bcbe7e9504ea45a416c6 100644
--- a/redbee-econotag/board_init.c
+++ b/redbee-econotag/board_init.c
@@ -6,6 +6,17 @@
  * Version 3.  See the file LICENSE for more details.
  */
 
-void board_init(void) {
+void board_init(void)
+{
     asm("nop");
 }
+
+void bl_init_clks(void)
+{
+    // dummy to compile
+}
+
+void bl_init_ports(void)
+{
+    // dummy to compile
+}
diff --git a/redbee-econotag/drivers/gpio.c b/redbee-econotag/drivers/gpio.c
new file mode 100644
index 0000000000000000000000000000000000000000..cc34e1508735dbc1ea00444cab5777fc2e688671
--- /dev/null
+++ b/redbee-econotag/drivers/gpio.c
@@ -0,0 +1,75 @@
+/*
+ * gpio.c - GPIO driver for redbee
+ * Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 3.  See the file LICENSE for more details.
+ *
+ * This file is part of RIOT.
+ */
+
+#include "gpio.h"
+
+inline void gpio_pad_dir(volatile uint64_t data)
+{
+    GPIO->PAD_DIR0 = (data & 0xffffffff);
+    GPIO->PAD_DIR1 = (data >> 32);
+}
+
+inline void gpio_data(volatile uint64_t data)
+{
+    GPIO->DATA0 = (data & 0xffffffff);
+    GPIO->DATA1 = (data >> 32);
+}
+
+inline uint64_t gpio_data_get(volatile uint64_t bits)
+{
+    uint64_t rdata = 0;
+
+    rdata = GPIO->DATA0 & (bits & 0xffffffff);
+    rdata |= (GPIO->DATA1 & (bits >> 32)) << 32;
+
+    return rdata;
+}
+
+inline void gpio_pad_pu_en(volatile uint64_t data)
+{
+    GPIO->PAD_PU_EN0 = (data & 0xffffffff);
+    GPIO->PAD_PU_EN1 = (data >> 32);
+}
+
+inline void gpio_data_sel(volatile uint64_t data)
+{
+    GPIO->DATA_SEL0 = (data & 0xffffffff);
+    GPIO->DATA_SEL1 = (data >> 32);
+}
+
+inline void gpio_pad_pu_sel(volatile uint64_t data)
+{
+    GPIO->PAD_PU_SEL0 = (data & 0xffffffff);
+    GPIO->PAD_PU_SEL1 = (data >> 32);
+}
+
+inline void gpio_data_set(volatile uint64_t data)
+{
+    GPIO->DATA_SET0 = (data & 0xffffffff);
+    GPIO->DATA_SET1 = (data >> 32);
+}
+
+inline void gpio_data_reset(volatile uint64_t data)
+{
+    GPIO->DATA_RESET0 = (data & 0xffffffff);
+    GPIO->DATA_RESET1 = (data >> 32);
+}
+
+inline void gpio_pad_dir_set(volatile uint64_t data)
+{
+    GPIO->PAD_DIR_SET0 = (data & 0xffffffff);
+    GPIO->PAD_DIR_SET1 = (data >> 32);
+}
+
+inline void gpio_pad_dir_reset(volatile uint64_t data)
+{
+    GPIO->PAD_DIR_RESET0 = (data & 0xffffffff);
+    GPIO->PAD_DIR_RESET1 = (data >> 32);
+}
\ No newline at end of file
diff --git a/redbee-econotag/drivers/include/gpio.h b/redbee-econotag/drivers/include/gpio.h
new file mode 100644
index 0000000000000000000000000000000000000000..595fa17c58c8aefd74fe0e28ee972398edf58e7f
--- /dev/null
+++ b/redbee-econotag/drivers/include/gpio.h
@@ -0,0 +1,159 @@
+/*
+ * gpio.h - GPIO driver for redbee
+ * Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 3.  See the file LICENSE for more details.
+ *
+ * This file is part of RIOT.
+ */
+
+#ifndef GPIO_H
+#define GPIO_H
+
+// TODO: why do we need to include this for macro expansion?
+#include "stdint.h"
+
+/* Structure-based GPIO access
+   Example usage:
+
+   GPIO->FUNC_SEL0 |= 0x00008000; // set a whole register
+
+   GPIO->FUNC_SEL_08 = 2;        // set just one pin
+
+   #define MY_PIN GPIO_08
+   GPIO->FUNC_SEL.MY_PIN = 2;    // same, to allow #define for pin names
+   GPIO->DATA.MY_PIN = 1;
+
+   gpio_set(GPIO_08);            // efficiently set or clear a single output bit
+   gpio_reset(GPIO_08);
+*/
+
+// GPIO to Function Alias macros:
+
+#define ADC0 GPIO_30
+#define ADC1 GPIO_31
+#define ADC2 GPIO_32
+#define ADC3 GPIO_33
+#define ADC4 GPIO_34
+#define ADC5 GPIO_35
+#define ADC6 GPIO_36
+#define ADC7 GPIO_37
+#define TDO GPIO_49
+#define TDI GPIO_48
+#define TCK GPIO_47
+#define TMS GPIO_46
+#define U2RTS GPIO_21
+#define U2CTS GPIO_20
+#define U2RX GPIO_19
+#define U2TX GPIO_18
+#define U1RTS GPIO_17
+#define U1CTS GPIO_16
+#define U1RX GPIO_15
+#define U1TX GPIO_14
+#define SDA GPIO_13
+#define SCL GPIO_12
+#define TMR3 GPIO_11
+#define TMR2 GPIO_10
+#define TMR1 GPIO_09
+#define TMR0 GPIO_08
+#define SCK GPIO_07
+#define MOSI GPIO_06
+#define MISO GPIO_05
+#define SS GPIO_04
+#define BTCK GPIO_03
+#define FSYN GPIO_02
+#define SSIRX GPIO_01
+#define SSITX GPIO_00
+#define KBI7 GPIO_29
+#define KBI6 GPIO_28
+#define KBI5 GPIO_27
+#define KBI4 GPIO_26
+#define KBI3 GPIO_25
+#define KBI2 GPIO_24
+#define KBI1 GPIO_23
+#define KBI0 GPIO_22
+#define TXON GPIO_44
+#define RXON GPIO_45
+#define ANT1 GPIO_42
+#define ANT2 GPIO_43
+#define VREF2H GPIO_38
+#define VREF2L GPIO_39
+#define VREF1H GPIO_40
+#define VREF1L GPIO_41
+#define MDO0 GPIO_51
+#define MDO1 GPIO_52
+#define MDO2 GPIO_53
+#define MDO3 GPIO_54
+#define MDO4 GPIO_55
+#define MDO5 GPIO_56
+#define MDO6 GPIO_57
+#define MDO7 GPIO_58
+#define MSEO0 GPIO_59
+#define MSEO1 GPIO_60
+#define RDY GPIO_61
+#define EVTO GPIO_62
+#define MCKO GPIO_50
+#define EVTI GPIO_63
+
+
+#define _V(x,n,i) uint32_t x##_##i : n;
+#define _REP(x,n) \
+        _V(x,n,00) _V(x,n,01) _V(x,n,02) _V(x,n,03) _V(x,n,04) _V(x,n,05) _V(x,n,06) _V(x,n,07) \
+        _V(x,n,08) _V(x,n,09) _V(x,n,10) _V(x,n,11) _V(x,n,12) _V(x,n,13) _V(x,n,14) _V(x,n,15) \
+        _V(x,n,16) _V(x,n,17) _V(x,n,18) _V(x,n,19) _V(x,n,20) _V(x,n,21) _V(x,n,22) _V(x,n,23) \
+        _V(x,n,24) _V(x,n,25) _V(x,n,26) _V(x,n,27) _V(x,n,28) _V(x,n,29) _V(x,n,30) _V(x,n,31) \
+        _V(x,n,32) _V(x,n,33) _V(x,n,34) _V(x,n,35) _V(x,n,36) _V(x,n,37) _V(x,n,38) _V(x,n,39) \
+        _V(x,n,40) _V(x,n,41) _V(x,n,42) _V(x,n,43) _V(x,n,44) _V(x,n,45) _V(x,n,46) _V(x,n,47) \
+        _V(x,n,48) _V(x,n,49) _V(x,n,50) _V(x,n,51) _V(x,n,52) _V(x,n,53) _V(x,n,54) _V(x,n,55) \
+        _V(x,n,56) _V(x,n,57) _V(x,n,58) _V(x,n,59) _V(x,n,60) _V(x,n,61) _V(x,n,62) _V(x,n,63)
+
+struct GPIO_struct {
+#define _IO(x) \
+        union { struct { uint32_t x##0; uint32_t x##1; }; \
+                struct { _REP(x, 1) };  \
+                struct GPIO_##x { _REP(GPIO, 1) } x; };
+#define _IO_2bit(x)     \
+        union { struct { uint32_t x##0; uint32_t x##1; uint32_t x##2; uint32_t x##3; }; \
+                struct { _REP(x, 2) };  \
+                struct GPIO_##x { _REP(GPIO, 2) } x; };
+
+    _IO(PAD_DIR);
+    _IO(DATA);
+    _IO(PAD_PU_EN);
+    _IO_2bit(FUNC_SEL);
+    _IO(DATA_SEL);
+    _IO(PAD_PU_SEL);
+    _IO(PAD_HYST_EN);
+    _IO(PAD_KEEP);
+    _IO(DATA_SET);
+    _IO(DATA_RESET);
+    _IO(PAD_DIR_SET);
+    _IO(PAD_DIR_RESET);
+};
+#undef _IO
+#undef _IO_2bit
+
+/* Build an enum lookup to map GPIO_08 -> 8 */
+#undef _V
+#define _V(x,n,i) __NUM_GPIO_GPIO_##i,
+enum { _REP(0, 0) };
+
+/* Macros to set or reset a data pin in the fastest possible way */
+#define gpio_set(gpio_xx) __gpio_set(gpio_xx)
+#define __gpio_set(gpio_xx)                                             \
+        ((__NUM_GPIO_##gpio_xx < 32)                                    \
+         ? (GPIO->DATA_SET0 = (1 << (__NUM_GPIO_##gpio_xx - 0)))        \
+         : (GPIO->DATA_SET1 = (1 << (__NUM_GPIO_##gpio_xx - 32))))
+#define gpio_reset(gpio_xx) __gpio_reset(gpio_xx)
+#define __gpio_reset(gpio_xx)                                           \
+        ((__NUM_GPIO_##gpio_xx < 32)                                    \
+         ? (GPIO->DATA_RESET0 = (1 << (__NUM_GPIO_##gpio_xx - 0)))      \
+         : (GPIO->DATA_RESET1 = (1 << (__NUM_GPIO_##gpio_xx - 32))))
+
+#undef _REP
+#undef _V
+
+static volatile struct GPIO_struct *const GPIO = (void *)(0x80000000);
+
+#endif
\ No newline at end of file
diff --git a/redbee-econotag/drivers/include/uart.h b/redbee-econotag/drivers/include/uart.h
new file mode 100644
index 0000000000000000000000000000000000000000..760fc45d044e5b374be3934e90d47cd864921f04
--- /dev/null
+++ b/redbee-econotag/drivers/include/uart.h
@@ -0,0 +1,139 @@
+/*
+ * uart.h - UART driver for redbee
+ * Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 3.  See the file LICENSE for more details.
+ *
+ * This file is part of RIOT.
+ */
+
+#ifndef UART_H
+#define UART_H
+
+/*-----------------------------------------------------------------*/
+/* UART */
+#define UART1_BASE      (0x80005000)
+#define UART2_BASE      (0x8000B000)
+
+struct UART_struct {
+    union {
+        uint32_t CON;
+        struct UART_CON {
+            uint32_t : 16;
+            uint32_t TST: 1;
+            uint32_t MRXR: 1;
+            uint32_t MTXR: 1;
+            uint32_t FCE: 1;
+            uint32_t FCP: 1;
+            uint32_t XTIM: 1;
+            uint32_t : 2;
+            uint32_t TXOENB: 1;
+            uint32_t CONTX: 1;
+            uint32_t SB: 1;
+            uint32_t ST2: 1;
+            uint32_t EP: 1;
+            uint32_t PEN: 1;
+            uint32_t RXE: 1;
+            uint32_t TXE: 1;
+        } CONbits;
+    };
+    union {
+        uint32_t STAT;
+        struct UART_STAT {
+            uint32_t : 24;
+            uint32_t TXRDY: 1;
+            uint32_t RXRDY: 1;
+            uint32_t RUE: 1;
+            uint32_t ROE: 1;
+            uint32_t TOE: 1;
+            uint32_t FE: 1;
+            uint32_t PE: 1;
+            uint32_t SE: 1;
+        } USTATbits;
+    };
+    union {
+        uint32_t DATA;
+        struct UART_DATA {
+            uint32_t : 24;
+            uint32_t DATA: 8;
+        } DATAbits;
+    };
+    union {
+        uint32_t RXCON;
+        struct UART_URXCON {
+            uint32_t : 26;
+            uint32_t LVL: 6;
+        } RXCONbits;
+    };
+    union {
+        uint32_t TXCON;
+        struct UART_TXCON {
+            uint32_t : 26;
+            uint32_t LVL: 6;
+        } TXCONbits;
+    };
+    union {
+        uint32_t CTS;
+        struct UART_CTS {
+            uint32_t : 27;
+            uint32_t LVL: 5;
+        } CTSbits;
+    };
+    union {
+        uint32_t BR;
+        struct UART_BR {
+            uint32_t INC: 16;
+            uint32_t MOD: 16;
+        } BRbits;
+    };
+};
+
+static volatile struct UART_struct *const UART1 = (void *)(UART1_BASE);
+static volatile struct UART_struct *const UART2 = (void *)(UART2_BASE);
+
+void uart_init(volatile struct UART_struct *uart, uint32_t baud);
+void uart_set_baudrate(volatile struct UART_struct *uart, uint32_t baud);
+void uart_flow_ctl(volatile struct UART_struct *uart, uint8_t on);
+
+
+/* The mc1322x has a 32 byte hardware FIFO for transmitted characters.
+ * Currently it is always filled from a larger RAM buffer. It would be
+ * possible to eliminate that overhead by filling directly from a chain
+ * of data buffer pointers, but printf's would be not so easy.
+ */
+#define UART1_TX_BUFFERSIZE 1024
+extern volatile uint32_t  u1_tx_head, u1_tx_tail;
+void uart1_putc(uint8_t c);
+
+/* The mc1322x has a 32 byte hardware FIFO for received characters.
+ * If a larger rx buffersize is specified the FIFO will be extended into RAM.
+ * RAM transfers will occur on interrupt when the FIFO is nearly full.
+ * If a smaller buffersize is specified hardware flow control will be
+ * initiated at that FIFO level.
+ * Set to 32 for no flow control or RAM buffer.
+ */
+#define UART1_RX_BUFFERSIZE 128
+#if UART1_RX_BUFFERSIZE > 32
+extern volatile uint32_t  u1_rx_head, u1_rx_tail;
+#define uart1_can_get() ((u1_rx_head!=u1_rx_tail) || (*UART1_URXCON > 0))
+#else
+#define uart1_can_get() (*UART1_URXCON > 0)
+#endif
+uint8_t uart1_getc(void);
+
+
+#define UART2_TX_BUFFERSIZE 1024
+extern volatile uint32_t  u2_tx_head, u2_tx_tail;
+void uart2_putc(uint8_t c);
+
+#define UART2_RX_BUFFERSIZE 128
+#if UART2_RX_BUFFERSIZE > 32
+extern volatile uint32_t  u2_rx_head, u2_rx_tail;
+#define uart2_can_get() ((u2_rx_head!=u2_rx_tail) || (*UART2_URXCON > 0))
+#else
+#define uart2_can_get() (*UART2_URXCON > 0)
+#endif
+uint8_t uart2_getc(void);
+
+#endif
\ No newline at end of file
diff --git a/redbee-econotag/drivers/redbee_uart.c b/redbee-econotag/drivers/redbee_uart.c
new file mode 100644
index 0000000000000000000000000000000000000000..bf467a137616b5ce347483739f45a68e03609a71
--- /dev/null
+++ b/redbee-econotag/drivers/redbee_uart.c
@@ -0,0 +1,212 @@
+/*
+ * redbee_uart.c - UART driver for redbee
+ * Copyright (C) 2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 3.  See the file LICENSE for more details.
+ *
+ * This file is part of RIOT.
+ */
+
+#include "mc1322x.h"
+#include "uart.h"
+#include "gpio.h"
+#include "io.h"
+
+#define MOD_ 9999
+#define CLK_ 24000000
+#define DIV_ 16 /* uart->CON.XTIM = 0 is 16x oversample (datasheet is incorrect) */
+#define BAUTRATE_UART1 115200
+#define BAUTRATE_UART2 115200
+
+void uart_set_baudrate(volatile struct UART_struct *uart, uint32_t baudrate)
+{
+    uint64_t inc = 0;
+
+    /* calculate inc following equation 13-1 from datasheet */
+    /* multiply by another 10 to get a fixed point*/
+    inc = ((uint64_t) baudrate * DIV_ * MOD_ * 10 / CLK_) - 10;
+    /* add 5 and div by 10 to get a rounding */
+    inc = (inc + 5) / 10;
+
+    /* disable UARTx to set baudrate */
+    uart->CONbits.TXE = 0;
+    uart->CONbits.RXE = 0;
+
+    /* set baudrate */
+    uart->BRbits.INC = inc;
+    uart->BRbits.MOD = MOD_;
+
+    /* reenable UARTx again */
+    /* uart->CON.XTIM = 0 is 16x oversample (datasheet is incorrect) */
+    uart->CONbits.XTIM = 0;
+    uart->CONbits.TXE = 1;
+    uart->CONbits.RXE = 1;
+}
+
+void uart_flow_ctl(volatile struct UART_struct *uart, uint8_t on)
+{
+    if (on) {
+        /* enable flow control */
+        if (uart == UART1) {
+            /* CTS and RTS directions */
+            GPIO->PAD_DIR_SET.U1CTS = 1;
+            GPIO->PAD_DIR_RESET.U1RTS = 1;
+            /* function select to uart */
+            GPIO->FUNC_SEL.U1CTS = 1;
+            GPIO->FUNC_SEL.U1RTS = 1;
+        }
+        else {
+            /* UART2 */
+            /* CTS and RTS directions */
+            GPIO->PAD_DIR_SET.U2CTS = 1;
+            GPIO->PAD_DIR_RESET.U2RTS = 1;
+            /* function select to uart */
+            GPIO->FUNC_SEL.U2CTS = 1;
+            GPIO->FUNC_SEL.U2RTS = 1;
+        }
+
+        /* enable flow control */
+        uart->CONbits.FCE = 1;
+    }
+    else {
+        /* disable flow control */
+        uart->CONbits.FCE = 0;
+
+        if (uart == UART1) {
+            /* CTS and RTS directions */
+            GPIO->PAD_DIR_RESET.U1CTS = 1;
+            GPIO->PAD_DIR_RESET.U1RTS = 1;
+            /* function select to GPIO */
+            GPIO->FUNC_SEL.U1CTS = 3;
+            GPIO->FUNC_SEL.U1RTS = 3;
+        }
+        else {
+            /* CTS and RTS directions */
+            GPIO->PAD_DIR_RESET.U2CTS = 1;
+            GPIO->PAD_DIR_RESET.U2RTS = 1;
+            /* function select to GPIO */
+            GPIO->FUNC_SEL.U2CTS = 3;
+            GPIO->FUNC_SEL.U2RTS = 3;
+        }
+    }
+}
+
+// TODO: clean from u*_(rx|tx)_(head|tail)
+void uart_init(volatile struct UART_struct *uart, uint32_t baudrate)
+{
+    /* enable the uart so we can set the gpio mode */
+    /* has to be enabled before setting the function with GPIO->FUNC_SEL */
+    uart->CONbits.TXE = 1;
+    uart->CONbits.RXE = 1;
+
+    /* interrupt when this or more bytes are free in the tx buffer */
+    uart->TXCON = 16;
+
+    if (uart == UART1) {
+        /* TX and RX direction */
+        GPIO->PAD_DIR_SET.U1TX = 1;
+        GPIO->PAD_DIR_RESET.U1RX = 1;
+
+        /* set function selection to UART */
+        GPIO->FUNC_SEL.U1TX = 1;
+        GPIO->FUNC_SEL.U1RX = 1;
+
+        UART1->CONbits.TXE = 1;                         /*< enable transmit */
+        UART1->CONbits.RXE = 1;                         /*< enable receive */
+#if UART1_RX_BUFFERSIZE > 32
+        UART1->RXCONbits.LVL = 30;                      /*< interrupt when fifo is nearly full */
+        //u1_rx_head = 0;
+        //u1_rx_tail = 0;
+#elif UART1_RX_BUFFERSIZE < 32
+        UART1->CONbits.FCE = 1;                         /*< enable flowcontrol */
+        UART1->CONbits.MRXR = 1;                        /*< disable Rx interrupt */
+        UART1->CTSbits.LVL = UART1_RX_BUFFERSIZE;       /*< drop cts when tx buffer at trigger level */
+        GPIO->FUNC_SEL1.U1CTS = 1;                      /*< set GPIO 16 to UART1 CTS */
+        GPIO->FUNC_SEL1.U1RTS = 1;                      /*< set GPIO 17 to UART1 RTS */
+#else
+        UART1->CONbits.MRXR = 1;                        /*< disable rx interrupt */
+#endif
+
+        //u1_tx_head = 0;
+        //u1_tx_tail = 0;
+
+        //enable_irq(UART1);
+        ITC->INTENABLEbits.UART1 = 1;
+    }
+    else {
+        /* UART2 */
+        /* TX and RX direction */
+        GPIO->PAD_DIR_SET.U2TX = 1;
+        GPIO->PAD_DIR_RESET.U2RX = 1;
+
+        /* set function selection to UART */
+        GPIO->FUNC_SEL.U2TX = 1;
+        GPIO->FUNC_SEL.U2RX = 1;
+
+        UART2->CONbits.TXE = 1;                         /*< enable transmit */
+        UART2->CONbits.RXE = 1;                         /*< enable receive */
+#if UART2_RX_BUFFERSIZE > 32
+        UART2->RXCONbits.LVL = 30;                      /*< interrupt when fifo is nearly full */
+        //u2_rx_head = 0;
+        //u2_rx_tail = 0;
+#elif UART2_RX_BUFFERSIZE < 32
+        UART2->CONbits.FCE = 1;                         /*< enable flowcontrol */
+        UART2->CONbits.MRXR = 1;                        /*< disable Rx interrupt */
+        UART2->CTSbits.LVL = UART2_RX_BUFFERSIZE;       /*< drop cts when tx buffer at trigger level */
+        GPIO->FUNC_SEL1.U1CTS = 1;                      /*< set GPIO 16 to UART2 CTS */
+        GPIO->FUNC_SEL1.U1RTS = 1;                      /*< set GPIO 17 to UART2 RTS */
+#else
+        UART2->CONbits.MRXR = 1;                        /*< disable rx interrupt */
+#endif
+
+        // u2_tx_head = 0;
+        //u2_tx_tail = 0;
+
+        //enable_irq(UART2);
+        ITC->INTENABLEbits.UART2 = 1;
+    }
+
+    uart_set_baudrate(uart, baudrate);
+}
+
+static inline uint32_t uart0_puts(uint8_t *astring, uint32_t length)
+{
+    uint32_t i = 0;
+
+    for (; i < length; i++) {
+        uart1_putc(astring[i]);
+    }
+
+    return i;
+}
+
+void stdio_flush(void)
+{
+    ITC->INTENABLEbits.UART1 = 0;
+    ITC->INTENABLEbits.UART2 = 0;
+
+    ITC->INTENABLEbits.UART1 = 1;
+    ITC->INTENABLEbits.UART2 = 1;
+    /** taken from msba2-uart0.c
+    U0IER &= ~BIT1;                             // disable THRE interrupt
+    while(running) {
+        while(!(U0LSR & (BIT5|BIT6))){};        // transmit fifo
+        fifo=0;
+        push_queue();                           // dequeue to fifo
+    }
+    U0IER |= BIT1;                              // enable THRE interrupt
+    */
+}
+
+
+int fw_puts(char *astring, int length)
+{
+    return uart0_puts((uint8_t *) astring, (uint32_t) length);
+}
+
+int bl_uart_init(void)
+{
+    uart_init(UART1, BAUTRATE_UART1);
+    uart_init(UART2, BAUTRATE_UART2);
+}
\ No newline at end of file
diff --git a/redbee-econotag/drivers/redbee_uart1.c b/redbee-econotag/drivers/redbee_uart1.c
index 046ed26ab16a5fb38278271fc944caef297e7ef0..cf7f9d015274144c6c0cded630d966f628deec44 100644
--- a/redbee-econotag/drivers/redbee_uart1.c
+++ b/redbee-econotag/drivers/redbee_uart1.c
@@ -1,6 +1,7 @@
 /*
- * redbee_uart1.c - UART1 driver for redbee
+ * uart1.c - UART1 driver for redbee
  * Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
+ *               2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
  *
  * This source code is licensed under the GNU General Public License,
  * Version 3.  See the file LICENSE for more details.
@@ -9,35 +10,47 @@
  */
 
 #include "mc1322x.h"
+#include "board_uart0.h"
+#include "uart.h"
 
-static volatile unsigned int running = 0;
-static volatile unsigned int fifo = 0;
-
-static inline int uart0_puts(char *astring, int length)
+void uart1_isr(void)
 {
-    int i;
-    for (i=0;i<length;i++) {
-        /* TODO: Fix me */
-        while(UART1->TXCON != 0);
-        UART1->DATA = astring[i];
+    if (UART1->USTATbits.RXRDY == 1) {
+#ifdef MODULE_UART0
+
+        if (uart0_handler_pid) {
+            while (UART1->RXCON != 0) {
+                uart0_handle_incoming(UART1->DATA);
+
+                if (++i >= UART0_BUFSIZE) {
+                    uart0_notify_thread();
+                    i = 0;
+                }
+            }
+
+            uart0_notify_thread();
+        }
+
+#endif
     }
-    return length;
 }
 
-int fw_puts(char *astring, int length)
+void uart1_putc(uint8_t c)
 {
-    return uart0_puts(astring, length);
+    /* while uart fifo is full */
+    while (UART1->TXCON == 0) {
+        /* wait */
+    }
+
+    UART1->DATA = c;
 }
 
-void stdio_flush(void)
+uint8_t uart1_getc(void)
 {
-    /* disable TX interrupt */
-    UART1->CONbits.MTXR = 1;
-    while(running) {
-        while(UART1->TXCON != 0);
-        fifo=0;
-        push_queue();                           // dequeue to fifo
+    /* while uart fifo is empty */
+    while (UART1->RXCON == 0) {
+        /* wait */
     }
-    /* enable TX interrupt */
-    UART1->CONbits.MTXR = 0;
-}
+
+    return UART1->DATA;
+}
\ No newline at end of file
diff --git a/redbee-econotag/drivers/redbee_uart2.c b/redbee-econotag/drivers/redbee_uart2.c
new file mode 100644
index 0000000000000000000000000000000000000000..a93c3f7137588459f869b1b4e48128500bcf44c1
--- /dev/null
+++ b/redbee-econotag/drivers/redbee_uart2.c
@@ -0,0 +1,58 @@
+/*
+ * uart1.c - UART1 driver for redbee
+ * Copyright (C) 2013 Oliver Hahm <oliver.hahm@inria.fr>
+ *               2013 Thomas Eichinger <thomas.eichinger@fu-berlin.de>
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 3.  See the file LICENSE for more details.
+ *
+ * This file is part of RIOT.
+ */
+
+#include "mc1322x.h"
+#include "board_uart0.h"
+#include "uart.h"
+
+void uart2_isr(void)
+{
+    int i = 0;
+
+    if (UART2->USTATbits.RXRDY == 1) {
+#ifdef MODULE_UART0
+
+        if (uart0_handler_pid) {
+            while (UART2->RXCON != 0) {
+                uart0_handle_incoming(UART2->DATA);
+
+                if (++i >= UART0_BUFSIZE) {
+                    uart0_notify_thread();
+                    i = 0;
+                }
+            }
+
+            uart0_notify_thread();
+        }
+
+#endif
+    }
+}
+
+void uart2_putc(uint8_t c)
+{
+    /* while uart fifo is full */
+    while (UART2->TXCON == 0) {
+        /* wait */
+    }
+
+    UART2->DATA = c;
+}
+
+uint8_t uart2_getc(void)
+{
+    /* while uart fifo is empty */
+    while (UART2->RXCON == 0) {
+        /* wait */
+    }
+
+    return UART2->DATA;
+}
\ No newline at end of file
diff --git a/redbee-econotag/tools/ftditools/Makefile b/redbee-econotag/tools/ftditools/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..521d7d14ff292bdadb245ce797f70ca696843a97
--- /dev/null
+++ b/redbee-econotag/tools/ftditools/Makefile
@@ -0,0 +1,17 @@
+INSTALL= /usr/local/bin
+
+################
+
+LDLIBS = -lftdi
+
+TARGETS = bbmc
+
+CFLAGS = -Wall -Wextra #-Werror
+
+all: $(TARGETS)
+
+clean:
+	-rm -f $(TARGETS)
+
+install: all
+	cp bbmc $(INSTALL)
\ No newline at end of file
diff --git a/redbee-econotag/tools/ftditools/bbmc.c b/redbee-econotag/tools/ftditools/bbmc.c
new file mode 100644
index 0000000000000000000000000000000000000000..f211f52eee9c2aa189007e3951c44b89acabc11c
--- /dev/null
+++ b/redbee-econotag/tools/ftditools/bbmc.c
@@ -0,0 +1,569 @@
+/*
+ * Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
+ * to the MC1322x project (http://mc1322x.devl.org)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of libmc1322x: see http://mc1322x.devl.org
+ * for details.
+ *
+ *
+ */
+
+/* control reset and VREF2 lines */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <ftdi.h>
+
+#define DEBUG 0
+
+#define low(x)  (1 << x)
+#define high(x) (1 << (x + 8))
+
+#define REDBEE_ECONOTAG_RESET    high(2)
+#define REDBEE_ECONOTAG_VREF2L   high(7)
+#define REDBEE_ECONOTAG_VREF2H   high(6)
+#define REDBEE_ECONOTAG_INTERFACE INTERFACE_A
+
+#define REDBEE_USB_RESET    high(2)
+#define REDBEE_USB_VREF2L   low(5)
+#define REDBEE_USB_VREF2H   low(6)
+#define REDBEE_USB_INTERFACE INTERFACE_B
+
+#define FLEXIBITY_USB_RESET    high(2)
+#define FLEXIBITY_USB_VREF2L   high(7)
+#define FLEXIBITY_USB_VREF2H   high(6)
+#define FLEXIBITY_USB_INTERFACE INTERFACE_A
+
+#define BOARD REDBEE_USB
+
+#define STR(x)         #x
+#define STR2(x)        STR(x)
+#define CAT(x,y)       x##y
+#define CAT2(x, y, z)  x##y##z
+
+#define dir(x)            ( CAT(x,_RESET) | CAT(x,_VREF2L) | CAT(x,_VREF2H))
+#define interface(x)      ( CAT(x,_INTERFACE) )
+#define reset_release(x)  ( CAT(x,_RESET)     )
+#define reset_set(x)      ( 0 )
+#define vref2_normal(x)   ( CAT(x,_VREF2H)    )
+#define vref2_erase(x)    ( CAT(x,_VREF2L)    )
+
+/* fgets input buffer length: for prompts and such */
+#define BUF_LEN 32
+
+struct layout {
+    char *name;
+    char *desc;
+    enum ftdi_interface interface;
+    uint16_t dir;
+    uint16_t reset_release;
+    uint16_t reset_set;
+    uint16_t vref2_normal;
+    uint16_t vref2_erase;
+};
+
+int print_and_prompt(struct ftdi_device_list *devlist);
+int bb_mpsee(struct ftdi_context *ftdic, uint16_t dir, uint16_t val);
+void reset(struct ftdi_context *ftdic, const struct layout *l);
+void erase(struct ftdi_context *ftdic, const struct layout *l);
+void usage(void);
+
+#define std_layout(x)                        \
+	.interface = interface(x),           \
+        .dir = dir(x),	                     \
+	.reset_release = reset_release(x),   \
+	.reset_set = reset_set(x),	     \
+	.vref2_normal = vref2_normal(x),     \
+	.vref2_erase = vref2_erase(x),
+
+static struct layout layouts[] = {
+    {
+        .name = "redbee-econotag",
+        .desc = "Redbee Econotag",
+        std_layout(REDBEE_ECONOTAG)
+    },
+    {
+        .name = "redbee-usb",
+        .desc = "Redbee USB stick",
+        std_layout(REDBEE_USB)
+    },
+    {
+        .name = "flexibity",
+        .desc = "Flexibity USB Interface",
+        std_layout(FLEXIBITY_USB)
+    },
+    { .name = NULL, /* end of table */ },
+};
+
+struct command {
+    char *name;
+    char *desc;
+    void (*cmd)(struct ftdi_context *ftdic, const struct layout *l);
+};
+
+static const struct command commands[] = {
+    {
+        .name = "reset",
+        .desc = "Toggles reset pin",
+        .cmd = reset,
+    },
+    {
+        .name = "erase",
+        .desc = "Sets VREF2 erase mode; toggles reset; waits 2 sec.; sets normal; toggles reset again",
+        .cmd = erase,
+    },
+    { .name = NULL, /* end of table */ },
+};
+
+struct layout *find_layout(char *str)
+{
+    uint32_t i = 0;
+
+    while (layouts[i].name != NULL) {
+        if (strcmp(layouts[i].name, str) == 0) {
+            return &layouts[i];
+        }
+
+        i++;
+    }
+
+    return NULL;
+}
+
+static uint32_t vendid = 0x0403;
+uint32_t prodid = 0x6010;
+
+#if __APPLE__
+static void restore_ftdi_kext(void)
+{
+    system("sudo kextload /System/Library/Extensions/FTDIUSBSerialDriver.kext");
+}
+#endif
+
+int main(int argc, char **argv)
+{
+    struct ftdi_context ftdic;
+    struct ftdi_device_list *devlist;
+    int dev_index = -1;
+    int num_devs;
+    char layout_str[BUF_LEN];
+    struct layout layout;
+    struct layout *l = NULL;
+    int i, ret;
+
+    /* overrides for layout parameters */
+    int interface      = -1;
+    int dir            = -1;
+    int reset_release  = -1;
+    int reset_set      = -1;
+    int vref2_normal   = -1;
+    int vref2_erase    = -1;
+
+    layout.name = NULL;
+
+    while (1) {
+        int c;
+        int option_index = 0;
+        static struct option long_options[] = {
+            {"layout",        required_argument, 0, 'l'},
+            {"index",         required_argument, 0, 'i'},
+            {"vendor",        required_argument, 0, 'v'},
+            {"product",       required_argument, 0, 'p'},
+            {"dir",           required_argument, 0,  0 },
+            {"reset_release", required_argument, 0,  0 },
+            {"reset_set",     required_argument, 0,  0 },
+            {"vref2_normal",  required_argument, 0,  0 },
+            {"vref2_erase",   required_argument, 0,  0 },
+            {"interface",     required_argument, 0,  0 },
+            {"help",          no_argument,       0, '?'},
+            {0, 0, 0, 0}
+        };
+
+        c = getopt_long(argc, argv, "i:l:v:p:",
+                        long_options, &option_index);
+
+        if (c == -1) {
+            break;
+        }
+
+        switch (c) {
+                /* process long opts */
+            case 0:
+                if (strcmp(long_options[option_index].name, "interface") == 0) {
+                    sscanf(optarg, "%i", &interface);
+                }
+
+                if (strcmp(long_options[option_index].name, "dir") == 0) {
+                    sscanf(optarg, "%i", &dir);
+                }
+
+                if (strcmp(long_options[option_index].name, "reset_release") == 0) {
+                    sscanf(optarg, "%i", &reset_release);
+                }
+
+                if (strcmp(long_options[option_index].name, "reset_set") == 0) {
+                    sscanf(optarg, "%i", &reset_set);
+                }
+
+                if (strcmp(long_options[option_index].name, "vref2_normal") == 0) {
+                    sscanf(optarg, "%i", &vref2_normal);
+                }
+
+                if (strcmp(long_options[option_index].name, "vref2_erase") == 0) {
+                    sscanf(optarg, "%i", &vref2_erase);
+                }
+
+                break;
+
+            case 'l':
+                strncpy(layout_str, optarg, BUF_LEN);
+                break;
+
+            case 'i':
+                dev_index = atoi(optarg);
+                break;
+
+            case 'v':
+                sscanf(optarg, "%i", &vendid);
+                break;
+
+            case 'p':
+                sscanf(optarg, "%i", &prodid);
+                break;
+
+            default:
+                usage();
+                break;
+        }
+    }
+
+    if (!(l = find_layout(layout_str)) &&
+        !((interface >= 0) &&
+          (dir >= 0) &&
+          (reset_release >= 0) &&
+          (reset_set >= 0) &&
+          (vref2_normal >= 0) &&
+          (vref2_erase >= 0))
+       ) {
+
+        printf("*** You must specify a layout or a complete set of overrides\n");
+        return EXIT_FAILURE;
+    }
+
+    if (l) {
+        memcpy(&layout, l, sizeof(struct layout));
+    }
+
+#define override(x) if(x > 0) { layout.x = x; }
+    override(interface);
+    override(dir);
+    override(reset_release);
+    override(reset_set);
+    override(vref2_normal);
+    override(vref2_erase);
+
+    if ((num_devs = ftdi_usb_find_all(&ftdic, &devlist, vendid, prodid)) < 0) {
+        fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n",
+                num_devs,
+                ftdi_get_error_string(&ftdic));
+        return EXIT_FAILURE;
+    }
+
+    if (ftdi_init(&ftdic) < 0) {
+        fprintf(stderr, "ftdi_init failed\n");
+        return EXIT_FAILURE;
+    }
+
+    if ((ret = ftdi_set_interface(&ftdic, layout.interface)) < 0) {
+        fprintf(stderr, "couldn't set interface %d, err %d (%s)\n", layout.interface, ret, ftdi_get_error_string(&ftdic));
+        return EXIT_FAILURE;
+    }
+
+    printf("Found %d devices with vendor id 0x%04x product id 0x%04x\n",
+           num_devs, vendid, prodid);
+
+    if (num_devs == 0) {
+        return EXIT_SUCCESS;
+    }
+
+    if (num_devs == 1) {
+        dev_index = 0;
+    }
+
+    while ((dev_index < 0) || (dev_index >= num_devs)) {
+        dev_index = print_and_prompt(devlist);
+    }
+
+    if (layout.name != NULL) {
+        printf("Opening device %d interface %d using layout %s\n",
+               dev_index, layout.interface, layout.name);
+    }
+    else {
+        printf("Opening device %d interface %d without a layout.\n",
+               dev_index, layout.interface);
+    }
+
+    if ((ret = ftdi_usb_open_desc_index(
+                   &ftdic,
+                   vendid,
+                   prodid,
+                   NULL,
+                   NULL,
+                   dev_index)) < 0) {
+#if __APPLE__
+
+        if ((ret == -5) && (0 == system("sudo kextunload /System/Library/Extensions/FTDIUSBSerialDriver.kext"))) {
+            // Try again without the FTDI kext loaded this time
+            atexit(&restore_ftdi_kext);
+            ret = ftdi_usb_open_desc_index(
+                      &ftdic,
+                      vendid,
+                      prodid,
+                      NULL,
+                      NULL,
+                      dev_index
+                  );
+        }
+
+        if (ret)
+#endif // __APPLE__
+        {
+            fprintf(stderr, "couldn't open dev_index %d, err %d (%s)\n", dev_index, ret, ftdi_get_error_string(&ftdic));
+            return EXIT_FAILURE;
+        }
+    }
+
+
+    for (i = 0; commands[i].name != NULL; i++) {
+        if ((argv[optind] != NULL) &&
+            (strcmp(commands[i].name, argv[optind]) == 0)) {
+            break;
+        }
+    }
+
+    if (commands[i].name != NULL) {
+        commands[i].cmd(&ftdic, &layout);
+    }
+    else {
+        printf("invalid command\n");
+
+        ftdi_list_free(&devlist);
+        ftdi_deinit(&ftdic);
+
+        return EXIT_FAILURE;
+    }
+
+    printf("done.\n");
+
+    ftdi_list_free(&devlist);
+    ftdi_deinit(&ftdic);
+
+    return EXIT_SUCCESS;
+}
+
+void usage(void)
+{
+    int i;
+    printf("Usage: bbmc [options|overrides] -l|--layout layout command \n");
+    printf("Commands:\n");
+
+    for (i = 0; commands[i].name != NULL; i++) {
+        printf("           %s: %s\n", commands[i].name, commands[i].desc);
+    }
+
+    printf("\n");
+    printf("Required options:\n");
+    printf("           -l|--layout\t specifiy which board layout to use\n");
+    printf("                      \t layout is not necessary with a full\n");
+    printf("                      \t set of overrides\n");
+    printf("\nLayout overrides:\n");
+    printf("           --interface\t\t FTDI interface to use\n");
+    printf("           --dir\t\t direction (1 is output)\n");
+    printf("           --reset_release\t reset release command\n");
+    printf("           --reset_set\t\t reset set command\n");
+    printf("           --vref2_normal\t vref2 normal\n");
+    printf("           --vref2_erase\t vref2 erase\n");
+    printf("\n");
+    printf("Layouts:\n");
+
+    for (i = 0; layouts[i].name != NULL; i++) {
+        printf("\t%s: %s\n", layouts[i].name, layouts[i].desc);
+        printf("\n");
+        printf("\t\tinterface: \t0x%04x\n", layouts[i].interface);
+        printf("\t\tdir: \t\t0x%04x\n", layouts[i].dir);
+        printf("\t\treset release: \t0x%04x\n", layouts[i].reset_release);
+        printf("\t\treset hold:    \t0x%04x\n", layouts[i].reset_set);
+        printf("\t\tvref2 normal:  \t0x%04x\n", layouts[i].vref2_normal);
+        printf("\t\tvref2 erase:   \t0x%04x\n", layouts[i].vref2_erase);
+        printf("\n");
+    }
+
+    printf("\n");
+    printf("Options:\n");
+    printf("           -i|--index     specifiy which device to use (default 0)\n");
+    printf("           -v|--vendor    set vendor id (default 0x0403)\n");
+    printf("           -p|--product   set vendor id (default 0x6010)\n");
+}
+
+int print_and_prompt(struct ftdi_device_list *devlist)
+{
+    int i, ret;
+    struct ftdi_context ftdic;
+    struct ftdi_device_list *curdev;
+    char manufacturer[128], description[128], serial[128];
+    char input[BUF_LEN];
+    char *s;
+    int sel = -1;
+
+    printf("\n");
+
+    i = 0;
+
+    for (curdev = devlist; curdev != NULL; i++) {
+        printf("  [%d]   ", i);
+
+        if (0 > (ret = ftdi_usb_get_strings(&ftdic,
+                                            curdev->dev,
+                                            manufacturer, 128,
+                                            description, 128,
+                                            serial, 128))) {
+            fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n",
+                    ret, ftdi_get_error_string(&ftdic));
+            return EXIT_FAILURE;
+        }
+
+        printf("Manufacturer: %s, Description: %s, Serial %s\n",
+               manufacturer, description, serial);
+        curdev = curdev->next;
+    }
+
+    printf("\nUse which device? ");
+
+    s = fgets(input, BUF_LEN, stdin);
+
+    if (s != NULL) {
+        size_t last = strlen(input) - 1;
+
+        if (input[last] == '\n') {
+            input[last] = '\0';
+        }
+    }
+
+    sscanf(s, "%i", &sel);
+
+    return sel;
+}
+
+void reset(struct ftdi_context *ftdic, const struct layout *l)
+{
+
+    /* using MPSSE since it give access to high GPIO*/
+    /* set as inputs for now */
+    ftdi_set_bitmode(ftdic, 0 , BITMODE_MPSSE);
+
+    printf("toggle reset\n");
+
+    bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal));
+    bb_mpsee(ftdic, l->dir, (l->reset_set     | l->vref2_normal));
+    bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal));
+
+    return;
+
+}
+
+
+void erase(struct ftdi_context *ftdic, const struct layout *l)
+{
+    printf("setting VREF2 erase\n");
+
+    /* using MPSSE since it give access to high GPIO*/
+    /* set as inputs for now */
+    ftdi_set_bitmode(ftdic, 0 , BITMODE_MPSSE);
+
+    bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal));
+    bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_erase));
+
+    printf("toggle reset\n");
+
+    bb_mpsee(ftdic, l->dir, (l->reset_set     | l->vref2_erase));
+    bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_erase));
+
+    printf("waiting for erase\n");
+
+    sleep(2);
+
+    printf("setting VREF2 normal\n");
+
+    bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal));
+
+    reset(ftdic, l);
+
+    return;
+
+}
+
+
+int bb_mpsee(struct ftdi_context *ftdic, uint16_t dir, uint16_t val)
+{
+    uint8_t buf[3];
+    int ret;
+
+    /* command "set data bits low byte" */
+    buf[0] = 0x80;
+    buf[1] = (val & 0xff);
+    buf[2] = dir & 0xff;
+#if DEBUG
+    fprintf(stderr, "write %x %x %x\n", buf[0], buf[1], buf[2]);
+#endif
+
+    if ((ret = (ftdi_write_data(ftdic, buf, 3))) < 0) {
+        perror("ft2232_write error");
+        fprintf(stderr, "ft2232_write command %x\n", buf[0]);
+        return EXIT_FAILURE;
+    }
+
+
+    /* command "set data bits high byte" */
+    buf[0] = 0x82;
+    buf[1] = (val >> 8);
+    buf[2] = dir >> 8;
+#if DEBUG
+    fprintf(stderr, "write %x %x %x\n", buf[0], buf[1], buf[2]);
+#endif
+
+    if ((ret = (ftdi_write_data(ftdic, buf, 3))) < 0) {
+        perror("ft2232_write error");
+        fprintf(stderr, "ft2232_write command %x\n", buf[0]);
+        return EXIT_FAILURE;
+    }
+
+    return 0;
+
+}
diff --git a/redbee-econotag/tools/mc1322x-load.c b/redbee-econotag/tools/mc1322x-load.c
new file mode 100644
index 0000000000000000000000000000000000000000..82c59520b9e3fc7079baf5741e37696e183f7061
--- /dev/null
+++ b/redbee-econotag/tools/mc1322x-load.c
@@ -0,0 +1,385 @@
+/*
+ * Copyright (c) 2012, Maxim Osipov <maxim.osipov@gmail.com>
+ * Copyright (c) 2010, Mariano Alvira <mar@devl.org> and other contributors
+ * to the MC1322x project (http://mc1322x.devl.org)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdint.h>
+
+
+char *filename;
+char *second;
+char *term = "/dev/ttyUSB0";
+int baud = B115200;
+int verbose = 0;
+char *rts = "rts";
+char *command;
+int first_delay = 50;
+int second_delay = 100;
+int do_exit = 0;
+int zerolen = 0;
+char *args = NULL;
+
+struct stat sbuf;
+struct termios options;
+char buf[256];
+int pfd;
+int ffd;
+int sfd;
+
+void help(void);
+
+int main(int argc, char **argv)
+{
+    int c = 0;
+    int r = 0;
+    int i = 0;
+    uint32_t s = 0;
+    opterr = 0;
+
+    /* Parse options */
+    while ((c = getopt(argc, argv, "f:s:zt:vu:r:c:a:b:eh")) != -1) {
+        switch (c) {
+            case 'f':
+                filename = optarg;
+                break;
+
+            case 's':
+                second = optarg;
+                break;
+
+            case 'z':
+                zerolen = 1;
+                break;
+
+            case 't':
+                term = optarg;
+                break;
+
+            case 'v':
+                verbose = 1;
+                break;
+
+            case 'u':
+                if (strcmp(optarg, "115200")) {
+                    baud = B115200;
+                }
+                else if (strcmp(optarg, "57600")) {
+                    baud = B115200;
+                }
+                else if (strcmp(optarg, "19200")) {
+                    baud = B19200;
+                }
+                else if (strcmp(optarg, "9600")) {
+                    baud = B9600;
+                }
+                else {
+                    printf("Unknown baud rate %s!\n", optarg);
+                    return -1;
+                }
+
+                break;
+
+            case 'r':
+                rts = optarg;
+                break;
+
+            case 'c':
+                command = optarg;
+                break;
+
+            case 'a':
+                first_delay = atoi(optarg);
+                break;
+
+            case 'b':
+                second_delay = atoi(optarg);
+                break;
+
+            case 'e':
+                do_exit = 1;
+                break;
+
+            case 'h':
+            case '?':
+                help();
+                return 0;
+
+            default:
+                abort();
+        }
+    }
+
+    /* Get other arguments */
+    if (optind < argc) {
+        args = argv[optind];
+    }
+
+    /* Print settings */
+    if (verbose) {
+        printf("Primary file (RAM): %s\n", filename);
+        printf("Secondary file (Flash): %s\n", second);
+        printf("Zero secondary file: %s\n", zerolen == 1 ? "Yes" : "No");
+        printf("Port: %s\n", term);
+        printf("Baud rate: %i\n", baud);
+        printf("Flow control: %s\n", rts);
+        printf("Reset command: %s\n", command);
+        printf("Exit after load: %s\n", do_exit == 1 ? "Yes" : "No");
+        printf("Delay 1: %i\n", first_delay);
+        printf("Delay 2: %i\n", second_delay);
+    }
+
+    /* Open and configure serial port */
+    pfd = open(term, O_RDWR | O_NOCTTY | O_NDELAY);
+
+    if (pfd == -1) {
+        printf("Cannot open serial port %s!\n", term);
+        return -1;
+    }
+
+    fcntl(pfd, F_SETFL, FNDELAY);
+    tcgetattr(pfd, &options);
+    cfsetispeed(&options, baud);
+    options.c_cflag |= (CLOCAL | CREAD);
+    options.c_cflag &= ~PARENB;
+    options.c_cflag &= ~CSTOPB;
+    options.c_cflag &= ~CSIZE;
+    options.c_cflag |= CS8;
+
+    if (strcmp(rts, "rts")) {
+        options.c_cflag &= ~CRTSCTS;
+    }
+    else {
+        options.c_cflag |= CRTSCTS;
+    }
+
+    options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+    options.c_oflag &= ~OPOST;
+    tcsetattr(pfd, TCSANOW, &options);
+
+    /* Reset the board if we can */
+    printf("Reset the board to enter bootloader (waiting for CONNECT)...\n");
+
+    if (command) {
+        printf("Performing reset: %s\n", command);
+        system(command);
+    }
+
+    /* Primary bootloader wait loop */
+    i = 0;
+
+    while (1) {
+        /* Wait for CONNECT */
+        r = write(pfd, (const void *)"\0", 1);
+        sleep(1);
+        r = read(pfd, &buf[i], sizeof(buf) - 1 - i);
+
+        if (r > 0) {
+            buf[i + r] = '\0';
+            printf("%s", &buf[i]);
+            fflush(stdout);
+
+            if (strstr(&buf[i], "CONNECT")) {
+                printf("\n");
+                break;
+            }
+
+            i += r;
+
+            if (i >= sizeof(buf) - 1) {
+                i = 0;
+            }
+        }
+        else {
+            printf(".");
+            fflush(stdout);
+        }
+    }
+
+    /* Send primary file */
+    if (!filename) {
+        printf("Please specify firmware file name (-f option)!\n");
+        return -1;
+    }
+
+    if (stat(filename, &sbuf)) {
+        printf("Cannot open firmware file %s!\n", filename);
+        return -1;
+    }
+
+    ffd = open(filename, O_RDONLY);
+
+    if (ffd == -1) {
+        printf("Cannot open firmware file %s!\n", filename);
+        return -1;
+    }
+
+    s = sbuf.st_size;
+    printf("Sending %s (%i bytes)...\n", filename, s);
+    r = write(pfd, (const void *)&s, 4);
+    i = 0;
+    r = read(ffd, buf, 1);
+
+    while (r > 0) {
+        do {
+            usleep(first_delay);
+            c = write(pfd, (const void *)buf, r);
+        }
+        while (c < r);
+
+        i += r;
+        printf("Written %i\r", i);
+        fflush(stdout);
+        r = read(ffd, buf, 1);
+    }
+
+    printf("\n");
+
+    /* Secondary loader wait loop */
+    if (second || zerolen) {
+        /* Wait for ready */
+        printf("Sending secondary file (waiting for ready)...\n");
+        i = 0;
+
+        while (1) {
+            sleep(1);
+            r = read(pfd, &buf[i], sizeof(buf) - 1 - i);
+
+            if (r > 0) {
+                buf[i + r] = '\0';
+                printf("%s", &buf[i]);
+                fflush(stdout);
+
+                if (strstr(buf, "ready")) {
+                    printf("\n");
+                    break;
+                }
+
+                i += r;
+
+                if (i >= sizeof(buf) - 1) {
+                    i = 0;
+                }
+            }
+            else {
+                printf(".");
+                fflush(stdout);
+            }
+        }
+
+        /* Send secondary file */
+        if (second) {
+            if (stat(second, &sbuf)) {
+                printf("Cannot open secondary file %s!\n", second);
+                return -1;
+            }
+
+            sfd = open(second, O_RDONLY);
+
+            if (sfd == -1) {
+                printf("Cannot open secondary file %s!\n", second);
+                return -1;
+            }
+
+            s = sbuf.st_size;
+            printf("Sending %s (%i bytes)...\n", second, s);
+            r = write(pfd, (const void *)&s, 4);
+            i = 0;
+            r = read(sfd, buf, 1);
+
+            while (r > 0) {
+                do {
+                    usleep(second_delay);
+                    c = write(pfd, (const void *)buf, r);
+                }
+                while (c < r);
+
+                i += r;
+                printf("Written %i\r", i);
+                fflush(stdout);
+                r = read(sfd, buf, 1);
+            }
+
+            printf("\n");
+        }
+        else if (zerolen) {
+            s = 0;
+            printf("Sending %i...\n", s);
+            write(pfd, (const void *)&s, 4);
+        }
+    }
+
+    /* Send the remaining arguments */
+    if (args) {
+        printf("Sending %s\n", args);
+        r = write(pfd, (const void *)args, strlen(args));
+        r = write(pfd, (const void *)",", 1);
+    }
+
+    /* Drop in echo mode */
+    if (!do_exit) {
+        while (1) {
+            r = read(pfd, buf, sizeof(buf));
+
+            if (r > 0) {
+                buf[r] = '\0';
+                printf("%s", buf);
+                fflush(stdout);
+            }
+        }
+    }
+}
+
+
+void help(void)
+{
+    printf("Example usage: mc1322x-load -f foo.bin -t /dev/ttyS0 -b 9600\n");
+    printf("          or : mc1322x-load -f flasher.bin -s flashme.bin  0x1e000,0x11223344,0x55667788\n");
+    printf("          or : mc1322x-load -f flasher.bin -z  0x1e000,0x11223344,0x55667788\n");
+    printf("       -f required: binary file to load\n");
+    printf("       -s optional: secondary binary file to send\n");
+    printf("       -z optional: send a zero length file as secondary\n");
+    printf("       -t, terminal default: /dev/ttyUSB0\n");
+    printf("       -u, baud rate default: 115200\n");
+    printf("       -r [none|rts] flow control default: rts\n");
+    printf("       -c command to run for autoreset: \n");
+    printf("              e.g. -c 'bbmc -l redbee-econotag -i 0 reset'\n");
+    printf("       -e exit instead of dropping to terminal display\n");
+    printf("       -a first  intercharacter delay, passed to usleep\n");
+    printf("       -b second intercharacter delay, passed to usleep\n");
+    printf("\n");
+    printf("Anything on the command line is sent after all of the files.\n\n");
+}
diff --git a/redbee-econotag/tools/mc1322x-load.pl b/redbee-econotag/tools/mc1322x-load.pl
new file mode 100755
index 0000000000000000000000000000000000000000..bfc1d1ffcdcfceb5a855e57de0017f04c42fd832
--- /dev/null
+++ b/redbee-econotag/tools/mc1322x-load.pl
@@ -0,0 +1,171 @@
+#!/usr/bin/perl -w
+
+use Device::SerialPort;
+use Term::ReadKey;
+use Getopt::Long;
+use Time::HiRes qw(usleep);
+
+use strict;
+
+my $filename = '';
+my $second = '';
+my $term = '/dev/ttyUSB0';
+my $baud = '115200';
+my $verbose;
+my $rts = 'rts';
+my $command = '';
+my $first_delay = 50;
+my $second_delay = 100;
+my $do_exit;
+my $zerolen;
+
+GetOptions ('file=s' => \$filename,
+	    'secondfile=s' => \$second,
+	    'zerolen' => \$zerolen,
+	    'terminal=s' => \$term, 
+	    'verbose' => \$verbose, 
+	    'u|baud=s' => \$baud,
+	    'rts=s' => \$rts,
+	    'command=s' => \$command,
+	    'a=s' => \$first_delay,
+	    'b=s' => \$second_delay,
+	    'exit' => \$do_exit,
+    ) or die 'bad options';
+
+$| = 1;
+
+if($filename eq '') {
+    print "Example usage: mc1322x-load.pl -f foo.bin -t /dev/ttyS0 -b 9600\n";
+    print "          or : mc1322x-load.pl -f flasher.bin -s flashme.bin  0x1e000,0x11223344,0x55667788\n";
+    print "          or : mc1322x-load.pl -f flasher.bin -z  0x1e000,0x11223344,0x55667788\n";
+    print "       -f required: binary file to load\n";
+    print "       -s optional: secondary binary file to send\n";
+    print "       -z optional: send a zero length file as secondary\n";
+    print "       -t, terminal default: /dev/ttyUSB0\n";
+    print "       -u, --baud baud rate default: 115200\n";
+    print "       -r [none|rts] flow control default: rts\n";
+    print "       -c command to run for autoreset: \n";
+    print "              e.g. -c 'bbmc -l redbee-econotag -i 0 reset'\n";
+    print "       -e exit instead of dropping to terminal display\n";
+    print "       -a first  intercharacter delay, passed to usleep\n";
+    print "       -b second intercharacter delay, passed to usleep\n";
+    print "\n";
+    print "anything on the command line is sent\n";
+    print "after all of the files.\n\n";
+    exit;
+}
+
+if (!(-e $filename)) { die "file $filename not found\n"; }
+if (($second ne '') && !(-e $second)) { die "secondary file $second not found\n"; }
+
+my $ob = Device::SerialPort->new ($term) or die "Can't start $term\n";
+    # next test will die at runtime unless $ob
+
+$ob->baudrate($baud);
+$ob->parity('none');
+$ob->databits(8);
+$ob->stopbits(1);
+if($rts eq 'rts') {
+    $ob->handshake('rts');
+} else {
+    $ob->handshake('none');
+}
+$ob->read_const_time(1000); # 1 second per unfulfilled "read" call
+$ob->rts_active(1);
+
+my $s = 0;
+my $reset = 0;
+my $size = 0;
+
+while(1) { 
+    
+    my $c; my $count; my $ret = ''; my $test='';
+    
+    if($s == 1) { print "secondary send...\n"; }
+    
+    $ob->write(pack('C','0'));
+
+    if(($command ne '') &&
+       ($reset eq 0)) {
+	$reset++;
+	system($command);
+    }
+
+    if($s == 1) { 
+	$test = 'ready'; 
+    } else {
+	$test = 'CONNECT';
+    }
+    
+    until($ret =~ /$test$/) {
+	($count,$c) = $ob->read(1);
+	if ($count == 0) { 
+	    print '.';
+	    $ob->write(pack('C','0')); 
+	    next;
+	}
+	$ret .= $c;
+    }
+    print $ret . "\n";
+    
+    if (-e $filename || (defined($zerolen) && ($s == 1))) {
+	
+	if(defined($zerolen) && ($s == 1)) {
+	    $size = 0;
+	} else {
+	    $size = -s $filename;
+	}
+
+	print ("Size: $size bytes\n");
+	$ob->write(pack('V',$size));
+
+	if(($s == 0) ||
+	   ((!defined($zerolen)) && ($s == 1))) {
+	    open(FILE, $filename) or die($!);
+	    print "Sending $filename\n";
+	    
+	    my $i = 1;
+	    while(read(FILE, $c, 1)) {
+		$i++;
+                usleep($first_delay)  if ( $s == 0 ) && ($first_delay != 0);
+                usleep($second_delay) if ( $s == 1 ) && ($second_delay != 0);
+		$ob->write($c);
+	    }
+	}
+    }
+    
+    last if ($s==1);
+    if((-e $second) || defined($zerolen)) {
+	$s=1; $filename = $second;
+    } else {
+	last;
+    }
+
+} 
+
+print "done sending files.\n";
+
+if(scalar(@ARGV)!=0) {
+    print "sending " ;
+    print @ARGV;
+    print ",\n";
+
+    $ob->write(@ARGV);
+    $ob->write(',');
+}
+
+if(defined($do_exit)) {
+    exit;
+}
+
+my $c; my $count;
+while(1) {
+    ($count, $c) = $ob->read(1);
+    print $c if (defined($count) && ($count != 0));
+}
+
+$ob -> close or die "Close failed: $!\n";
+ReadMode 0;
+undef $ob;  # closes port AND frees memory in perl
+exit;
+