From 7e071464a8d5b6789a0b32b415a50e58171dbbab Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 22 Sep 2010 15:10:42 +0200 Subject: [PATCH 001/188] * import from old firekernel repository --- Jamfile | 3 + eZ430-Chronos/Jamfile | 10 + eZ430-Chronos/Jamrules.eZ430-Chronos | 12 + eZ430-Chronos/board_init.c | 2 + eZ430-Chronos/debug_uart.c | 21 + eZ430-Chronos/drivers/Jamfile | 5 + eZ430-Chronos/drivers/display.c | 519 +++++++++++++ eZ430-Chronos/drivers/display.h | 360 +++++++++ eZ430-Chronos/drivers/display1.c | 226 ++++++ eZ430-Chronos/include/board.h | 10 + msb-430h/Jamfile | 35 + msb-430h/Jamrules.msb-430h | 37 + msb-430h/board_init.c | 207 ++++++ msb-430h/debug_uart.c | 21 + msb-430h/driver_cc1100.c | 343 +++++++++ msb-430h/include/board.h | 69 ++ msba2/Jamfile | 35 + msba2/Jamfile.msba2 | 31 + msba2/Jamrules.msba2 | 33 + msba2/board_init.c | 156 ++++ msba2/drivers/Jamfile | 6 + msba2/drivers/include/hal-board.h | 68 ++ msba2/drivers/include/sht11-board.h | 63 ++ msba2/drivers/msba2-cc1100.c | 243 +++++++ msba2/drivers/msba2-ltc4150.c | 65 ++ msba2/drivers/msba2-uart0.c | 205 ++++++ msba2/include/board-conf.h | 68 ++ msba2/include/board.h | 62 ++ msba2/lpc2387-timer3.c | 37 + msba2/tools/CHANGES | 23 + msba2/tools/COPYING | 339 +++++++++ msba2/tools/Makefile | 43 ++ msba2/tools/README.txt | 144 ++++ msba2/tools/armtools.txt | 15 + msba2/tools/flash.cmd | 2 + msba2/tools/flashutil.sh | 113 +++ msba2/tools/mkbootc | 28 + msba2/tools/mkstaticlist | 47 ++ msba2/tools/obj/boot_23xx.d | 3 + msba2/tools/obj/boot_2xxx.d | 3 + msba2/tools/obj/chipinfo.d | 8 + msba2/tools/obj/control_2xxx.d | 6 + msba2/tools/obj/download.d | 19 + msba2/tools/obj/ihex.d | 3 + msba2/tools/obj/lpc2k_pgm.d | 8 + msba2/tools/obj/pseudoterm.d | 6 + msba2/tools/obj/serial.d | 3 + msba2/tools/obj/uuencode.d | 3 + msba2/tools/src/Jamfile | 9 + msba2/tools/src/boot.h | 9 + msba2/tools/src/boot_23xx.armasm | 32 + msba2/tools/src/boot_23xx.c | 5 + msba2/tools/src/boot_23xx.h | 2 + msba2/tools/src/boot_2xxx.armasm | 15 + msba2/tools/src/boot_2xxx.c | 5 + msba2/tools/src/boot_2xxx.h | 2 + msba2/tools/src/chipinfo.c | 159 ++++ msba2/tools/src/chipinfo.h | 20 + msba2/tools/src/cksum_test.c | 76 ++ msba2/tools/src/control_2xxx.c | 31 + msba2/tools/src/control_2xxx.h | 8 + msba2/tools/src/download.c | 972 +++++++++++++++++++++++++ msba2/tools/src/download.h | 8 + msba2/tools/src/gui.c | 387 ++++++++++ msba2/tools/src/gui.h | 3 + msba2/tools/src/ihex.c | 229 ++++++ msba2/tools/src/ihex.h | 7 + msba2/tools/src/lpc2k_pgm.c | 98 +++ msba2/tools/src/lpc2k_pgm.h | 12 + msba2/tools/src/pseudoterm.c | 135 ++++ msba2/tools/src/serial.c | 350 +++++++++ msba2/tools/src/serial.h | 19 + msba2/tools/src/settings.c | 172 +++++ msba2/tools/src/settings.h | 12 + msba2/tools/src/uuencode.c | 98 +++ msba2/tools/src/uuencode.h | 3 + msba2/tools/termctrl.sh | 22 + olimex_lpc2148/Jamfile | 10 + olimex_lpc2148/Jamfile.olimex_lpc2148 | 4 + olimex_lpc2148/Jamrules.olimex_lpc2148 | 9 + olimex_lpc2148/board_init.c | 88 +++ olimex_lpc2148/debug_uart.c | 14 + olimex_lpc2148/include/board.h | 1 + olimex_lpc2148/include/rs232.h | 40 + olimex_lpc2148/rs232.c | 65 ++ olimex_lpc2148/tick.c | 63 ++ olimex_lpc2148/tools/lpc2148_flash.gdb | 22 + pttu/Jamfile | 35 + pttu/Jamfile.pttu | 28 + pttu/Jamrules.pttu | 37 + pttu/board_init.c | 239 ++++++ pttu/drivers/Jamfile | 4 + pttu/drivers/pttu-uart0.c | 204 ++++++ pttu/include/board.h | 56 ++ pttu/tools/jtag.txt | 14 + pttu/tools/olimex-arm-usb-ocd.cfg | 9 + pttu/tools/openocd-pttu.cfg | 75 ++ pttu/tools/openocd-pttu.sh | 30 + pttu/tools/pttu_debug.gdb | 15 + 99 files changed, 7730 insertions(+) create mode 100644 Jamfile create mode 100644 eZ430-Chronos/Jamfile create mode 100644 eZ430-Chronos/Jamrules.eZ430-Chronos create mode 100644 eZ430-Chronos/board_init.c create mode 100644 eZ430-Chronos/debug_uart.c create mode 100644 eZ430-Chronos/drivers/Jamfile create mode 100644 eZ430-Chronos/drivers/display.c create mode 100644 eZ430-Chronos/drivers/display.h create mode 100644 eZ430-Chronos/drivers/display1.c create mode 100644 eZ430-Chronos/include/board.h create mode 100644 msb-430h/Jamfile create mode 100644 msb-430h/Jamrules.msb-430h create mode 100644 msb-430h/board_init.c create mode 100644 msb-430h/debug_uart.c create mode 100644 msb-430h/driver_cc1100.c create mode 100644 msb-430h/include/board.h create mode 100644 msba2/Jamfile create mode 100644 msba2/Jamfile.msba2 create mode 100644 msba2/Jamrules.msba2 create mode 100644 msba2/board_init.c create mode 100644 msba2/drivers/Jamfile create mode 100644 msba2/drivers/include/hal-board.h create mode 100644 msba2/drivers/include/sht11-board.h create mode 100644 msba2/drivers/msba2-cc1100.c create mode 100644 msba2/drivers/msba2-ltc4150.c create mode 100644 msba2/drivers/msba2-uart0.c create mode 100644 msba2/include/board-conf.h create mode 100644 msba2/include/board.h create mode 100644 msba2/lpc2387-timer3.c create mode 100644 msba2/tools/CHANGES create mode 100644 msba2/tools/COPYING create mode 100644 msba2/tools/Makefile create mode 100644 msba2/tools/README.txt create mode 100644 msba2/tools/armtools.txt create mode 100755 msba2/tools/flash.cmd create mode 100755 msba2/tools/flashutil.sh create mode 100644 msba2/tools/mkbootc create mode 100644 msba2/tools/mkstaticlist create mode 100644 msba2/tools/obj/boot_23xx.d create mode 100644 msba2/tools/obj/boot_2xxx.d create mode 100644 msba2/tools/obj/chipinfo.d create mode 100644 msba2/tools/obj/control_2xxx.d create mode 100644 msba2/tools/obj/download.d create mode 100644 msba2/tools/obj/ihex.d create mode 100644 msba2/tools/obj/lpc2k_pgm.d create mode 100644 msba2/tools/obj/pseudoterm.d create mode 100644 msba2/tools/obj/serial.d create mode 100644 msba2/tools/obj/uuencode.d create mode 100644 msba2/tools/src/Jamfile create mode 100644 msba2/tools/src/boot.h create mode 100644 msba2/tools/src/boot_23xx.armasm create mode 100644 msba2/tools/src/boot_23xx.c create mode 100644 msba2/tools/src/boot_23xx.h create mode 100644 msba2/tools/src/boot_2xxx.armasm create mode 100644 msba2/tools/src/boot_2xxx.c create mode 100644 msba2/tools/src/boot_2xxx.h create mode 100644 msba2/tools/src/chipinfo.c create mode 100644 msba2/tools/src/chipinfo.h create mode 100644 msba2/tools/src/cksum_test.c create mode 100644 msba2/tools/src/control_2xxx.c create mode 100644 msba2/tools/src/control_2xxx.h create mode 100644 msba2/tools/src/download.c create mode 100644 msba2/tools/src/download.h create mode 100644 msba2/tools/src/gui.c create mode 100644 msba2/tools/src/gui.h create mode 100644 msba2/tools/src/ihex.c create mode 100644 msba2/tools/src/ihex.h create mode 100644 msba2/tools/src/lpc2k_pgm.c create mode 100644 msba2/tools/src/lpc2k_pgm.h create mode 100644 msba2/tools/src/pseudoterm.c create mode 100644 msba2/tools/src/serial.c create mode 100644 msba2/tools/src/serial.h create mode 100644 msba2/tools/src/settings.c create mode 100644 msba2/tools/src/settings.h create mode 100644 msba2/tools/src/uuencode.c create mode 100644 msba2/tools/src/uuencode.h create mode 100755 msba2/tools/termctrl.sh create mode 100644 olimex_lpc2148/Jamfile create mode 100644 olimex_lpc2148/Jamfile.olimex_lpc2148 create mode 100644 olimex_lpc2148/Jamrules.olimex_lpc2148 create mode 100644 olimex_lpc2148/board_init.c create mode 100644 olimex_lpc2148/debug_uart.c create mode 100644 olimex_lpc2148/include/board.h create mode 100644 olimex_lpc2148/include/rs232.h create mode 100644 olimex_lpc2148/rs232.c create mode 100644 olimex_lpc2148/tick.c create mode 100644 olimex_lpc2148/tools/lpc2148_flash.gdb create mode 100644 pttu/Jamfile create mode 100644 pttu/Jamfile.pttu create mode 100644 pttu/Jamrules.pttu create mode 100644 pttu/board_init.c create mode 100644 pttu/drivers/Jamfile create mode 100644 pttu/drivers/pttu-uart0.c create mode 100644 pttu/include/board.h create mode 100644 pttu/tools/jtag.txt create mode 100644 pttu/tools/olimex-arm-usb-ocd.cfg create mode 100644 pttu/tools/openocd-pttu.cfg create mode 100755 pttu/tools/openocd-pttu.sh create mode 100644 pttu/tools/pttu_debug.gdb diff --git a/Jamfile b/Jamfile new file mode 100644 index 0000000000..ad37fbe5b6 --- /dev/null +++ b/Jamfile @@ -0,0 +1,3 @@ +SubDir TOP board ; + +SubInclude TOP board $(BOARD) ; diff --git a/eZ430-Chronos/Jamfile b/eZ430-Chronos/Jamfile new file mode 100644 index 0000000000..ea723c95a9 --- /dev/null +++ b/eZ430-Chronos/Jamfile @@ -0,0 +1,10 @@ +SubDir TOP board eZ430-Chronos ; + +HDRS += $(TOP)/board/$(CPU)/include ; + +Module board : debug_uart.c board_init.c ; +UseModule board ; + +SubInclude TOP board $(BOARD) drivers ; +SubInclude TOP cpu $(CPU) ; + diff --git a/eZ430-Chronos/Jamrules.eZ430-Chronos b/eZ430-Chronos/Jamrules.eZ430-Chronos new file mode 100644 index 0000000000..eef3a03017 --- /dev/null +++ b/eZ430-Chronos/Jamrules.eZ430-Chronos @@ -0,0 +1,12 @@ +# ****************************************************************************** +# Copyright 2010, Freie Universitaet Berlin (FUB). All rights reserved. +# ****************************************************************************** +# $Id$ + +BOARD = eZ430-Chronos ; +CPU = msp430 ; +MCU = cc430x6137 ; + +FLASHER ?= mspdebug ; +FLASHFLAGS ?= rf2500 ; + diff --git a/eZ430-Chronos/board_init.c b/eZ430-Chronos/board_init.c new file mode 100644 index 0000000000..aa52e65af9 --- /dev/null +++ b/eZ430-Chronos/board_init.c @@ -0,0 +1,2 @@ +void board_init() { +} diff --git a/eZ430-Chronos/debug_uart.c b/eZ430-Chronos/debug_uart.c new file mode 100644 index 0000000000..d80c9c6e83 --- /dev/null +++ b/eZ430-Chronos/debug_uart.c @@ -0,0 +1,21 @@ +#include +#include "board.h" + +#define UART1_TX TXBUF1 +#define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); } + + +int putchar(int c) +{ +// UART1_TX = c; +// UART1_WAIT_TXDONE(); +// +// if (c == 10) { +// UART1_TX = 13; +// UART1_WAIT_TXDONE(); +// } + + return c; +} + + diff --git a/eZ430-Chronos/drivers/Jamfile b/eZ430-Chronos/drivers/Jamfile new file mode 100644 index 0000000000..b2fb968fae --- /dev/null +++ b/eZ430-Chronos/drivers/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP board eZ430-Chronos drivers ; + +UseModule board_common ; + +Module board_common : display.c display1.c ; diff --git a/eZ430-Chronos/drivers/display.c b/eZ430-Chronos/drivers/display.c new file mode 100644 index 0000000000..c0418f544e --- /dev/null +++ b/eZ430-Chronos/drivers/display.c @@ -0,0 +1,519 @@ +// ************************************************************************************************* +// +// 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. +// +// ************************************************************************************************* +// Display functions. +// ************************************************************************************************* + + +// ************************************************************************************************* +// Include section + +// system +#include + +// driver +#include "cc430x613x.h" +#include "display.h" + + +// ************************************************************************************************* +// Prototypes section +void write_lcd_mem(uint8_t * lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); +void clear_line(uint8_t line); +void display_symbol(uint8_t symbol, uint8_t mode); +void display_char(uint8_t segment, uint8_t chr, uint8_t mode); +void display_chars(uint8_t segments, uint8_t * str, uint8_t mode); + + +// ************************************************************************************************* +// Defines section + + + +// ************************************************************************************************* +// Global Variable section + +// Display flags +volatile s_display_flags display; + +// Global return string for itoa function +uint8_t itoa_str[8]; + + + +// ************************************************************************************************* +// @fn lcd_init +// @brief Erase LCD memory. Init LCD peripheral. +// @param none +// @return none +// ************************************************************************************************* +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; + + // 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 + +#ifdef USE_LCD_CHARGE_PUMP + // Charge pump voltage generated internally, internal bias (V2-V4) generation + LCDBVCTL = LCDCPEN | VLCD_2_72; +#endif +} + + +// ************************************************************************************************* +// @fn clear_display_all +// @brief Erase LINE1 and LINE2 segments. Clear also function-specific content. +// @param none +// @return none +// ************************************************************************************************* +void clear_display_all(void) +{ + // Clear generic content + clear_line(LINE1); + clear_line(LINE2); + + +} + + +// ************************************************************************************************* +// @fn clear_display +// @brief Erase LINE1 and LINE2 segments. Keep icons. +// @param none +// @return none +// ************************************************************************************************* +void clear_display(void) +{ + clear_line(LINE1); + clear_line(LINE2); +} + + +// ************************************************************************************************* +// @fn clear_line +// @brief Erase segments of a given line. +// @param uint8_t line LINE1, LINE2 +// @return none +// ************************************************************************************************* +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); + } + else // line == LINE2 + { + display_symbol(LCD_SEG_L2_DP, SEG_OFF); + display_symbol(LCD_SEG_L2_COL1, SEG_OFF); + display_symbol(LCD_SEG_L2_COL0, SEG_OFF); + } +} + + +// ************************************************************************************************* +// @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 +// ************************************************************************************************* +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); + } +} + + +// ************************************************************************************************* +// @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 +// ************************************************************************************************* +uint8_t * 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); + + // 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); + } + else // digits == 1 || 2 + { + memcpy(itoa_str, itoa_conversion_table[n]+(3-digits), digits); + } + } + else // For n > 180 need to calculate string content + { + // 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); +} + + +// ************************************************************************************************* +// @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 +// @return none +// ************************************************************************************************* +void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) +{ + uint8_t * str; + + str = itoa(value, digits, blanks); + + // Display string in blink mode + display_chars(segments, str, disp_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 +// @return none +// ************************************************************************************************* +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); + } +} + + +// ************************************************************************************************* +// @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 +// @return none +// ************************************************************************************************* +void display_char(uint8_t segment, uint8_t 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); + } +} + + +// ************************************************************************************************* +// @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 +// @return none +// ************************************************************************************************* +void display_chars(uint8_t segments, uint8_t * 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; break; + 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; break; + 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; break; + 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; break; + 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; break; + 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; break; + 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; break; + } + + // Write to consecutive digits + for(i=0; i) + 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, +}; + + +// 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, +}; + + +// Quick integer to array conversion table for most common integer 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", +}; + diff --git a/eZ430-Chronos/include/board.h b/eZ430-Chronos/include/board.h new file mode 100644 index 0000000000..af0a99b5da --- /dev/null +++ b/eZ430-Chronos/include/board.h @@ -0,0 +1,10 @@ +#ifndef _MSB_BOARD_H +#define _MSB_BOARD_H + +#include + +#define MSP430_INITIAL_CPU_SPEED 7372800uL +#define MSP430_HAS_DCOR 1 +#define MSP430_HAS_EXTERNAL_CRYSTAL 1 + +#endif // _MSB_BOARD_H diff --git a/msb-430h/Jamfile b/msb-430h/Jamfile new file mode 100644 index 0000000000..b1181a57db --- /dev/null +++ b/msb-430h/Jamfile @@ -0,0 +1,35 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +SubDir TOP board msb-430h ; + +Module board : board_init.c debug_uart.c ; +UseModule board ; + +Module board_cc1100 : driver_cc1100.c ; + +SubInclude TOP cpu $(CPU) ; diff --git a/msb-430h/Jamrules.msb-430h b/msb-430h/Jamrules.msb-430h new file mode 100644 index 0000000000..41bf0779d9 --- /dev/null +++ b/msb-430h/Jamrules.msb-430h @@ -0,0 +1,37 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +BOARD = msb-430h ; +CPU = msp430 ; +MCU = msp430x1612 ; + +FLASH_PORT ?= /dev/ttyUSB0 ; +FLASHER ?= mspdebug ; +FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; + +RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; + diff --git a/msb-430h/board_init.c b/msb-430h/board_init.c new file mode 100644 index 0000000000..7dee70e3b1 --- /dev/null +++ b/msb-430h/board_init.c @@ -0,0 +1,207 @@ +#include "cpu.h" +#include "board.h" +#include "kernel_intern.h" +#include "msp430.h" +#include "debug.h" + +volatile static 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 void msb_ports_init(void) +{ + // 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 +} + +void msp430_set_cpu_speed(uint32_t speed) +{ + 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(); +} + +/*---------------------------------------------------------------------------*/ +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 + 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 */ + } + } + + CCTL2 = 0; /* Stop CCR2 function */ + TACTL = 0; /* Stop Timer_A */ + + BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ + #endif +} + +void board_init() { + msp430_cpu_init(); + msb_ports_init(); + + RED_ON; + + msp430_set_cpu_speed(7372800uL); +} diff --git a/msb-430h/debug_uart.c b/msb-430h/debug_uart.c new file mode 100644 index 0000000000..7abad1d4e3 --- /dev/null +++ b/msb-430h/debug_uart.c @@ -0,0 +1,21 @@ +#include "board.h" + +#define UART1_TX TXBUF1 +#define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); } + +#include + +int putchar(int c) +{ + UART1_TX = c; + UART1_WAIT_TXDONE(); + + if (c == 10) { + UART1_TX = 13; + UART1_WAIT_TXDONE(); + } + + return c; +} + + diff --git a/msb-430h/driver_cc1100.c b/msb-430h/driver_cc1100.c new file mode 100644 index 0000000000..9575bee6a5 --- /dev/null +++ b/msb-430h/driver_cc1100.c @@ -0,0 +1,343 @@ +/* Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will + +This file is part of the Micro-mesh SensorWeb Firmware. + +Micro-Mesh is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +Micro-Mesh is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Micro-Mesh; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include + +#include +#include +#include + +#include +#include + +#define CC1100_GDO0 (P2IN & 0x02) // read serial I/O (GDO0) +#define CC1100_GDO1 (P3IN & 0x04) // read serial I/O (GDO1) +#define CC1100_GDO2 (P2IN & 0x01) // read serial I/O (GDO2) + +#define CC1100_CS_LOW (P3OUT &= ~0x01) +#define CC1100_CS_HIGH (P3OUT |= 0x01) + +#define CC1100_GDO1_LOW_COUNT (2700) // loop count (timeout ~ 500 us) to wait +#define CC1100_GDO1_LOW_RETRY (100) // max. retries for GDO1 to go low + +volatile int abort_count; +volatile int retry_count = 0; + +void cc1100_gdo0_enable(void) +{ + P2IFG &= ~0x02; /* Clear IFG for GDO0 */ + P2IE |= 0x02; /* Enable interrupt for GDO0 */ +} + +void cc1100_gdo0_disable(void) +{ + P2IE &= ~0x02; /* Disable interrupt for GDO0 */ + P2IFG &= ~0x02; /* Clear IFG for GDO0 */ +} + +void cc1100_gdo2_enable(void) +{ + P2IFG &= ~0x01; /* Clear IFG for GDO2 */ + P2IE |= 0x01; /* Enable interrupt for GDO2 */ +} + +void cc1100_gdo2_disable(void) +{ + P2IE &= ~0x01; /* Disable interrupt for GDO2 */ + P2IFG &= ~0x01; /* Clear IFG for GDO2 */ +} + +void cc1100_before_send(void) +{ + // Disable GDO2 interrupt before sending packet + cc1100_gdo2_disable(); +} + +void cc1100_after_send(void) +{ + // Enable GDO2 interrupt after sending packet + cc1100_gdo2_enable(); +} + + +int cc1100_get_gdo0(void) { + return CC1100_GDO0; +} + +int cc1100_get_gdo1(void) { + return CC1100_GDO1; +} + +int cc1100_get_gdo2(void) { + return CC1100_GDO2; +} + +void cc1100_spi_cs(void) +{ + CC1100_CS_LOW; +} + +uint8_t cc1100_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("cc1100_txrx alarm()"); + } + /* Wait for Byte received */ + c = 0; + while(!(IFG1 & URXIFG0)) + { + if (c++ == 1000000) + puts("cc1100_txrx alarm()"); + } + return RXBUF0; +} + + +void cc1100_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; + goto cs_low; // try again + } + goto loop; + } + final: + /* Switch to SPI mode */ + P3SEL |= 0x04; +} + +void cc1100_spi_unselect(void) { + CC1100_CS_HIGH; +} + +void cc1100_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) */ + 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 */ +} + +void cc1100_spi_init(uint8_t clockrate) +{ + // Switch off async UART + 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 + + // Keep peripheral in reset state + UCTL0 = SWRST; + + // 8-bit SPI Master 3-pin mode, with SMCLK as clock source + // 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; + + // Release for operation + UCTL0 &= ~SWRST; +} + + +// #include +// #include +// #include "type.h" +// #include "cc1100_defines.h" +// #include "driver_cc1100.h" +// #include "driver_system.h" +// #include "spi0.h" +// +// static callback_t _paket_cb; +// static callback_t _cs_cb; +// +// //------------------------------------------------------------------------------------------------------- +// // Public CC1100 communication functions (SPI) +// //------------------------------------------------------------------------------------------------------- +// +// //------------------------------------------------------------------------------------------------------- +// // void spiInitTrx(void) +// // +// // DESCRIPTION: +// // This function puts the cc1100 into spi mode. You have to call this bevore every spi transaction. +// // +// //------------------------------------------------------------------------------------------------------- +// +// +// void drivercc1100_spiwriteburstreg(uint8_t addr, unsigned char *buffer, uint8_t count) +// { +// uint8_t i; +// long c; +// drivercc1100_spiinittrx(); +// drivercc1100_trxspi(addr | CC1100_WRITE_BURST); +// for (i = 0; i < count; i++) +// { +// c = 0; +// IFG1 &= ~UTXIFG0; +// IFG1 &= ~URXIFG0; +// TXBUF0 = buffer[i]; +// /* Wait for TX to finish */ +// while(!(IFG1 & UTXIFG0)) +// { +// if (c++ == 1000000) +// alarm(); +// } +// } +// /* Wait for Byte received */ +// c = 0; +// while(!(IFG1 & URXIFG0)) +// { +// if (c++ == 1000000) +// alarm(); +// } +// CC1100_CS_HIGH; +// } +// +// void drivercc1100_spireadburstreg(uint8_t addr, char *buffer, uint8_t count) +// { +// uint8_t i; +// drivercc1100_spiinittrx(); +// drivercc1100_trxspi(addr | CC1100_READ_BURST); +// for (i = 0; i < count; i++) +// { +// long c = 0; +// IFG1 &= ~UTXIFG0; +// IFG1 &= ~URXIFG0; +// TXBUF0 = NOBYTE; +// while(!(IFG1 & UTXIFG0)) +// { +// if (c++ == 1000000) +// alarm(); +// } +// /* Wait for Byte received */ +// c = 0; +// while(!(IFG1 & URXIFG0)) +// { +// if (c++ == 1000000) +// alarm(); +// } +// buffer[i] = RXBUF0; +// } +// CC1100_CS_HIGH; +// } +// +// void drivercc1100_load(callback_t cs_cb,callback_t paket_cb) +// { +// _paket_cb = paket_cb; +// _cs_cb = cs_cb; +// spi0_init(0); +// } +// +// void drivercc1100_aftersend(void) +// { +// CLEAR(P2IFG, 0x01); +// SET(P2IE, 0x01); /* Enable interrupts on port 2 pin 0 */ +// CLEAR(P4OUT, 0x08); /* Turn off Sending Led*/ +// } +// +// void drivercc1100_initinterrupts(void) +// { +// _DINT(); /* Disable all interrupts */ +// P2SEL = 0x00; /* must be <> 1 to use interrupts */ +// SET(P2IES, 0x01); /* Enables external interrupt on low edge (for GDO2) */ +// SET(P2IE, 0x01); /* Enable interrupt */ +// CLEAR(P2IFG, 0x01); /* Clears the interrupt flag */ +// CLEAR(P2IE, 0x02); /* Disable interrupt for GDO0 */ +// CLEAR(P2IFG, 0x02); /* Clear IFG for GDO0 */ +// _EINT(); /* Enable all interrupts */ +// } +// +// void drivercc1100_beforesend(void) +// { +// /* Turn on Led while sending paket for debug reasons */ +// SET(P4OUT, 0x08); +// /* Disable interrupts on port 2 pin 0 */ +// CLEAR(P2IE, 0x01); +// } +// +// +// /* +// * Private functions +// */ +// +// + +/* + * CC1100 receive interrupt + */ +interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ + __enter_isr(); +puts("cc1100_isr()"); +// if (system_state.POWERDOWN) SPI_INIT; /* Initialize SPI after wakeup */ + /* Check IFG */ + if ((P2IFG & 0x01) != 0) { + P2IFG &= ~0x01; + cc1100_gdo2_irq(); + } + else if ((P2IFG & 0x02) != 0) { + cc1100_gdo0_irq(); + P2IE &= ~0x02; // Disable interrupt for GDO0 + P2IFG &= ~0x02; // Clear IFG for GDO0 + } else { + puts("cc1100_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(); +} + diff --git a/msb-430h/include/board.h b/msb-430h/include/board.h new file mode 100644 index 0000000000..ef2bbb6585 --- /dev/null +++ b/msb-430h/include/board.h @@ -0,0 +1,69 @@ +/****************************************************************************** +Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef _MSB_BOARD_H +#define _MSB_BOARD_H + +/** + * @defgroup msb_430h ScatterWeb MSB-430H + * @ingroup msp430 + * +

Compontents

+\li MSP430 +\li CC1100 + +* @{ +*/ + +/** + * @file + * @brief MSB-430H Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @version $Revision$ + * + * @note $Id$ + */ + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 7372800uL +#define MSP430_HAS_DCOR 1 +#define MSP430_HAS_EXTERNAL_CRYSTAL 1 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x80 +#define LEDS_CONF_GREEN 0x00 +#define LEDS_CONF_YELLOW 0x00 + +#define RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define RED_OFF LEDS_PxOUT |= LEDS_CONF_RED + +#include + +/** @} */ +#endif // _MSB_BOARD_H diff --git a/msba2/Jamfile b/msba2/Jamfile new file mode 100644 index 0000000000..88106e45cb --- /dev/null +++ b/msba2/Jamfile @@ -0,0 +1,35 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +SubDir TOP board msba2 ; + +Module board : board_init.c ; +UseModule board ; +UseModule board_common ; + +SubInclude TOP board $(BOARD) drivers ; +SubInclude TOP cpu $(CPU) ; diff --git a/msba2/Jamfile.msba2 b/msba2/Jamfile.msba2 new file mode 100644 index 0000000000..44014a6c96 --- /dev/null +++ b/msba2/Jamfile.msba2 @@ -0,0 +1,31 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +#LinkLibraries $(BOARD).elf : sys-drivers.a net_mm.a sys-lib.a fat-lib.a +# cpu_drivers.a board_drivers.a cc110x.a hal.a hal_drivers.a lpc2387_hal.a ; + +include [ FPath $(TOP) cpu arm_common Jamfile.arm_common ] ; diff --git a/msba2/Jamrules.msba2 b/msba2/Jamrules.msba2 new file mode 100644 index 0000000000..fdcf4b6f65 --- /dev/null +++ b/msba2/Jamrules.msba2 @@ -0,0 +1,33 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +CPU = lpc2387 ; + +HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; + +FLASHER = $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; +FLASHFLAGS = --basedir $(TOP)/board/msba2/tools --id "MSB-A2" --ports "$(PORT)" ; diff --git a/msba2/board_init.c b/msba2/board_init.c new file mode 100644 index 0000000000..d12cc4058e --- /dev/null +++ b/msba2/board_init.c @@ -0,0 +1,156 @@ +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/** + * @ingroup pttu + * @{ + */ + +/** + * @file + * @brief MSB-A2 board initialization + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Kaspar Schleiser + * @author Michael Baar + * + * @note $Id$ + */ +#include +#include +#include "VIC.h" +#include "cpu.h" + +#define PCRTC BIT9 +#define CL_CPU_DIV 4 + +/*---------------------------------------------------------------------------*/ +/** + * @brief Enabling MAM and setting number of clocks used for Flash memory fetch + * @internal + */ +static void +init_mam(void) +{ + MAMCR = 0x0000; + MAMTIM = 0x0003; + MAMCR = 0x0002; +} +/*---------------------------------------------------------------------------*/ +static inline void +pllfeed(void) +{ + PLLFEED = 0xAA; + PLLFEED = 0x55; +} +/*---------------------------------------------------------------------------*/ +void init_clks1(void) +{ + // Disconnect PLL + PLLCON &= ~0x0002; + pllfeed(); + + // Disable PLL + PLLCON &= ~0x0001; + pllfeed(); + + SCS |= 0x20; // Enable main OSC + while( !(SCS & 0x40) ); // Wait until main OSC is usable + + /* select main OSC, 16MHz, as the PLL clock source */ + CLKSRCSEL = 0x0001; + + // Setting Multiplier and Divider values + PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz + pllfeed(); + + // Enabling the PLL */ + PLLCON = 0x0001; + pllfeed(); + + /* Set clock divider to 4 (value+1) */ + CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz + +#if USE_USB + USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ +#endif +} + +void init_clks2(void){ + // Wait for the PLL to lock to set frequency + while(!(PLLSTAT & BIT26)); + + // Connect the PLL as the clock source + PLLCON = 0x0003; + pllfeed(); + + /* Check connect bit status */ + while (!(PLLSTAT & BIT25)); +} + +void bl_init_clks(void) +{ + PCONP = PCRTC; // switch off everything except RTC + init_clks1(); + init_clks2(); + init_mam(); +} + +void bl_init_ports(void) +{ + SCS |= BIT0; // Set IO Ports to fast switching mode + + /* UART0 */ + PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 + PINSEL0 &= ~(BIT5 + BIT7); + + /* LEDS */ + FIO3DIR |= LED_RED_PIN; + FIO3DIR |= LED_GREEN_PIN; + LED_RED_OFF; + LED_GREEN_OFF; +} + +void loop_delay(void) { + volatile uint16_t i, j; + for (i = 1; i < 30; i++) { + for (j = 1; j != 0; j++) { + asm volatile (" nop "); + } + } +} + +void bl_blink(void) { + LED_RED_ON; + LED_GREEN_ON; + + loop_delay(); + + LED_RED_OFF; + LED_GREEN_OFF; +} + diff --git a/msba2/drivers/Jamfile b/msba2/drivers/Jamfile new file mode 100644 index 0000000000..79705aca0a --- /dev/null +++ b/msba2/drivers/Jamfile @@ -0,0 +1,6 @@ +SubDir TOP board msba2 drivers ; + +Module board_cc1100 : msba2-cc1100.c ; +Module board_hal : msba2-hal.c ; +Module board_ltc4150 : msba2-ltc4150.c : gpioint ; +Module board_common : msba2-uart0.c ; diff --git a/msba2/drivers/include/hal-board.h b/msba2/drivers/include/hal-board.h new file mode 100644 index 0000000000..a4dfc293ab --- /dev/null +++ b/msba2/drivers/include/hal-board.h @@ -0,0 +1,68 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef HALPLATFORM_H_ +#define HALPLATFORM_H_ + +/** + * @ingroup msba2 + * @{ + */ + +/** + * @file + * @brief + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author baar + * @version $Revision$ + * + * @note $Id$ + */ + +#include "vdevice.h" +#include "device-gpio.h" +#include "device-rs232.h" +#include "device-serial.h" + +VDEVICE_NAME(vdevice_gpio, gpio_led_green); +VDEVICE_NAME(vdevice_gpio, gpio_led_red); +VDEVICE_NAME(vdevice_gpio, gpio_led_usb); + +/** + * @var tty0 + * @brief RS232 TTY0 device on UART0 + */ +VDEVICE_NAME(vdevice_rs232, tty0); + +/** + * @var console0 + * @brief console device on tty0 + */ +VDEVICE_NAME(vdevice_serial, console0); + +/** @} */ +#endif /* HALPLATFORM_H_ */ diff --git a/msba2/drivers/include/sht11-board.h b/msba2/drivers/include/sht11-board.h new file mode 100644 index 0000000000..fc0313906a --- /dev/null +++ b/msba2/drivers/include/sht11-board.h @@ -0,0 +1,63 @@ +/****************************************************************************** +Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef SHT11BOARD_H_ +#define SHT11BOARD_H_ + +/** + * @ingroup lpc2387 + * @{ + */ + +/** + * @file + * @brief LPC2387 SHT11 Device Driver + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @version $Revision$ + * + * @note $Id$ + */ + +#include +#include + +#define SHT11_SCK_LOW FIO1CLR = BIT25; // serial clock line low +#define SHT11_SCK_HIGH FIO1SET = BIT25; // serial clock line high +#define SHT11_DATA ((FIO1PIN & BIT26) != 0) // read serial I/O +#define SHT11_DATA_LOW (FIO1CLR = BIT26); // serial I/O line low +#define SHT11_DATA_HIGH (FIO1SET = BIT26); // serial I/O line high +#define SHT11_DATA_IN (FIO1DIR &= ~BIT26) // serial I/O as input +#define SHT11_DATA_OUT (FIO1DIR |= BIT26) // serial I/O as output +#define SHT11_INIT FIO1DIR |= BIT25; PINSEL3 &= ~(BIT14|BIT15 | BIT16|BIT17); + +/* time to wait after toggling the data line */ +#define SHT11_DATA_WAIT (50) +/* time to wait after toggling the clock line */ +#define SHT11_CLK_WAIT (10) + +/** @} */ +#endif /* SHT11BOARD_H_ */ diff --git a/msba2/drivers/msba2-cc1100.c b/msba2/drivers/msba2-cc1100.c new file mode 100644 index 0000000000..726d585506 --- /dev/null +++ b/msba2/drivers/msba2-cc1100.c @@ -0,0 +1,243 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/** + * @file + * @ingroup LPC2387 + * @brief CC1100 LPC2387 dependend functions + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Thomas Hillebrandt + * @version $Revision: 1781 $ + * + * @note $Id: msba2-cc1100.c 1781 2010-01-26 13:39:36Z hillebra $ + */ + +#include +#include +// core +#include +#include +// sys +#include "cc1100.h" +#include "arch_cc1100.h" +#include "cc1100_spi.h" +#include "gpioint.h" + +#define CC1100_GDO0 (FIO0PIN & BIT27) // read serial I/O (GDO0) +#define CC1100_GDO1 (FIO1PIN & BIT23) // read serial I/O (GDO1) +#define CC1100_GDO2 (FIO0PIN & BIT28) // read serial I/O (GDO2) + +#define SPI_TX_EMPTY (SSP0SR & SSPSR_TFE) +#define SPI_BUSY (SSP0SR & SSPSR_BSY) +#define SPI_RX_AVAIL (SSP0SR & SSPSR_RNE) + +#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 + +//#define DEBUG +#ifdef DEBUG + +#include "stdio.h" + +static unsigned long time_value; + +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; +} +#endif + +int cc1100_get_gdo0(void) { + return CC1100_GDO0; +} + +int cc1100_get_gdo1(void) { + return CC1100_GDO1; +} + +int cc1100_get_gdo2(void) { + return CC1100_GDO2; +} + +void cc1100_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 + } +} + +uint8_t +cc1100_txrx(uint8_t c) { + uint8_t result; + SSP0DR = c; +#ifdef DEBUG + set_time(); +#endif + while (!SPI_TX_EMPTY) { +#ifdef DEBUG + test_time(0); +#endif + } +#ifdef DEBUG + set_time(); +#endif + while (SPI_BUSY) { +#ifdef DEBUG + test_time(1); +#endif + } +#ifdef DEBUG + set_time(); +#endif + while (!SPI_RX_AVAIL) { +#ifdef DEBUG + test_time(2); +#endif + } + result = (uint8_t)SSP0DR; + return result; +} + +void cc1100_spi_cs(void) +{ + FIO1CLR = BIT21; +} + +void +cc1100_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 +} + +void +cc1100_spi_unselect(void) +{ + FIO1SET = BIT21; +} + +void cc1100_before_send(void) +{ + // Disable GDO2 interrupt before sending packet + cc1100_gdo2_disable(); +} + +void cc1100_after_send(void) +{ + // Enable GDO2 interrupt after sending packet + cc1100_gdo2_enable(); +} + +void cc1100_gdo0_enable(void) { + gpioint_set(0, BIT27, GPIOINT_RISING_EDGE, &cc1100_gdo0_irq); +} + +void cc1100_gdo0_disable(void) { + gpioint_set(0, BIT27, GPIOINT_DISABLE, NULL); +} + +void cc1100_gdo2_disable(void) { + gpioint_set(0, BIT28, GPIOINT_DISABLE, NULL); +} + +void cc1100_gdo2_enable(void) { + gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc1100_gdo2_irq); +} + +void cc1100_init_interrupts(void) +{ + // Enable external interrupt on low edge (for GDO2) + FIO0DIR &= ~BIT28; + cc1100_gdo2_enable(); + // Enable external interrupt on low edge (for GDO0) + FIO0DIR &= ~BIT27; +} diff --git a/msba2/drivers/msba2-ltc4150.c b/msba2/drivers/msba2-ltc4150.c new file mode 100644 index 0000000000..c590dee8db --- /dev/null +++ b/msba2/drivers/msba2-ltc4150.c @@ -0,0 +1,65 @@ +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/** + * @ingroup msba2 + * @ingroup ltc4150 + * @{ + */ + +/** + * @file + * @brief LTC4150 MSB-A2 specific implemetation + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Michael Baar + * @author Kaspar Schleiser + */ + +#include +#include "lpc2387.h" +#include "ltc4150_arch.h" +#include "gpioint.h" + +void ltc4150_disable_int(void) { + gpioint_set(0, BIT4, GPIOINT_DISABLE, NULL); +} + +void ltc4150_enable_int(void) { + gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, <c4150_interrupt); +} + +void ltc4150_sync_blocking(void) { + while(!(FIO0PIN & BIT4)) {}; +} + +void ltc4150_arch_init() { + FIO0DIR |= BIT5; + FIO0SET = BIT5; +} + +/** @} */ diff --git a/msba2/drivers/msba2-uart0.c b/msba2/drivers/msba2-uart0.c new file mode 100644 index 0000000000..01aaf609dc --- /dev/null +++ b/msba2/drivers/msba2-uart0.c @@ -0,0 +1,205 @@ +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/* + * debug_uart.c: provides initial serial debug output + * + * Copyright (C) 2008, 2009 Kaspar Schleiser + * Heiko Will + */ +#include +#include +#include +#include "lpc23xx.h" +#include "VIC.h" + +/** + * @file + * @ingroup lpc2387 + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @version $Revision$ + * + * @note $Id$ + */ + +typedef struct toprint { + unsigned int len; + char content[]; +}toprint; + +#define QUEUESIZE 255 +static volatile toprint* queue[QUEUESIZE]; +static volatile unsigned char queue_head = 0; +static volatile unsigned char queue_tail = 0; +static volatile unsigned char queue_items = 0; + +static volatile unsigned int actual_pos = 0; +static volatile unsigned int running = 0; +static volatile unsigned int fifo = 0; + +static volatile toprint* actual = NULL; +void (*uart0_callback)(int); + +static inline void enqueue(void) { + queue_items++; + queue_tail++; +} + +static inline void dequeue(void) { + actual = (queue[queue_head]); + queue_items--; + queue_head++; +} + +static void push_queue(void) { + running = 1; +start: + if (!actual) { + if (queue_items) { + dequeue(); + } else { + running = 0; + if (!fifo) + while(!(U0LSR & BIT6)){}; + return; + } + } + while ((actual_pos < actual->len) && (fifo++ < 16)){ + U0THR = actual->content[actual_pos++]; + } + if (actual_pos == actual->len) { + free((void*)actual); + actual = NULL; + actual_pos = 0; + goto start; + } +} + +int uart_active(void){ + return (running || fifo); +} + +static inline void receive(int c) +{ + if (uart0_callback != NULL) uart0_callback(c); +} + +void stdio_flush(void) +{ + 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 +} + +void UART0_IRQHandler(void) __attribute__((interrupt("IRQ"))); +void UART0_IRQHandler(void) +{ + int iir; + iir = U0IIR; + + switch(iir & UIIR_ID_MASK) { + case UIIR_THRE_INT: // Transmit Holding Register Empty + fifo=0; + push_queue(); + break; + + case UIIR_CTI_INT: // Character Timeout Indicator + case UIIR_RDA_INT: // Receive Data Available + do { + int c = U0RBR; + receive(c); + } while (U0LSR & ULSR_RDR); + break; + + default: + U0LSR; + U0RBR; + break; + } // switch + VICVectAddr = 0; // Acknowledge Interrupt +} + +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 + + /* alternative without queue: + int i; + for (i=0;iconfig->speed + /* + * Baudrate calculation + * BR = PCLK (9 MHz) / (16 x 256 x DLM + DLL) x (1/(DIVADDVAL/MULVAL)) + */ + U0FDR = 0x92; // DIVADDVAL = 0010 = 2, MULVAL = 1001 = 9 + U0DLM = 0x00; + U0DLL = 0x04; + + U0LCR = 0x03; // DLAB = 0 + U0FCR = 0x07; // Enable and reset TX and RX FIFO + + /* irq */ + install_irq(UART0_INT, UART0_IRQHandler, 6); + U0IER |= BIT0 | BIT1; // enable RX+TX irq + return 1; +} + diff --git a/msba2/include/board-conf.h b/msba2/include/board-conf.h new file mode 100644 index 0000000000..2c8824f1fc --- /dev/null +++ b/msba2/include/board-conf.h @@ -0,0 +1,68 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef BOARDCONF_H_ +#define BOARDCONF_H_ + +/** + * @ingroup conf + * @ingroup msba2 + * + * @{ + */ + +/** + * @file + * @brief MSB-A2 board configuration + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author baar + * @version $Revision$ + * + * @note $Id$ + */ + +#define FEUERWARE_CONF_BOARD_NAME "FU Berlin MSB-A2" + +#ifdef MODULE_CC110X +#define FEUERWARE_CONF_NUM_RADIOS 1 +#else +#define FEUERWARE_CONF_NUM_RADIOS 0 +#endif + +// if FAT is enabled this board supports files +#define FEUERWARE_CONF_CORE_SUPPORTS_FILES defined(MODULE_FAT) + +#ifdef MODULE_FAT +#define CFG_CONF_MEM_SIZE 0x7FFFFFFF +#define SYSLOG_CONF_NUM_INTERFACES 2 +#else +#define SYSLOG_CONF_NUM_INTERFACES 1 +#endif + + +/** @} */ +#endif /* BOARDCONF_H_ */ diff --git a/msba2/include/board.h b/msba2/include/board.h new file mode 100644 index 0000000000..4356e4423f --- /dev/null +++ b/msba2/include/board.h @@ -0,0 +1,62 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef __BOARD_H +#define __BOARD_H + +/** + * @ingroup msb_a2 + * @{ + */ + +/** + * @file + * @brief MSB-A2 Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Kaspar Schleiser + * @version $Revision$ + * + * @note $Id$ + */ + +#include + +#define VICIntEnClear VICIntEnClr + +#define LED_RED_PIN (BIT25) +#define LED_GREEN_PIN (BIT26) + +#define LED_GREEN_OFF (FIO3SET = LED_GREEN_PIN) +#define LED_GREEN_ON (FIO3CLR = LED_GREEN_PIN) +#define LED_GREEN_TOGGLE (FIO3PIN ^= LED_GREEN_PIN) + +#define LED_RED_OFF (FIO3SET = LED_RED_PIN) +#define LED_RED_ON (FIO3CLR = LED_RED_PIN) +#define LED_RED_TOGGLE (FIO3PIN ^= LED_RED_PIN) + +/** @} */ +#endif // __BOARD_H diff --git a/msba2/lpc2387-timer3.c b/msba2/lpc2387-timer3.c new file mode 100644 index 0000000000..8978390e9a --- /dev/null +++ b/msba2/lpc2387-timer3.c @@ -0,0 +1,37 @@ +/* + * lpc2387_timer0.c + * + * Created on: 13.01.2009 + * Author: heiko + */ + +#include +#include +#include "lpc2387.h" +#include "benchmark.h" + +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 +} + +void benchmark_reset_start(void) +{ + T3TCR = 0; // disable timer + T3TC = 0; // reset counter + T3TCR = BIT0; +} + +unsigned int benchmark_read_stop(void) +{ + T3TCR = 0; // disable timer + return T3TC; +} + diff --git a/msba2/tools/CHANGES b/msba2/tools/CHANGES new file mode 100644 index 0000000000..dd9e6ec1ea --- /dev/null +++ b/msba2/tools/CHANGES @@ -0,0 +1,23 @@ +(heavily hacked by Heiko Will & Kaspar Schleiser since then) + +1.05 (9-Apr-2007) +----------------- +Added boot jump code specific to 2378 (and similar chips) to +disable the PLL before jumping to the user's code. + +1.04 (19-Dec-2006) +------------------ +Added 2364, 2366, 2368, 2378 & 2468 to list. Untested. + +1.03 (2-Jun-2006) +----------------- +Added 2103 chip to chip list. ID numbers for 2101 and 2102 unknown + +1.02 (31-Jul-2005) +------------------ +Added support for other chips +Added soft boot code +Added user configurable crystal value (for baud sync protocol) + + + diff --git a/msba2/tools/COPYING b/msba2/tools/COPYING new file mode 100644 index 0000000000..a43ea2126f --- /dev/null +++ b/msba2/tools/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/msba2/tools/Makefile b/msba2/tools/Makefile new file mode 100644 index 0000000000..91d44fdf78 --- /dev/null +++ b/msba2/tools/Makefile @@ -0,0 +1,43 @@ +CFLAGS = -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" +CC = gcc + +all: lpc2k_pgm pseudoterm + +SRC = lpc2k_pgm.c download.c uuencode.c ihex.c serial.c chipinfo.c boot_2xxx.c boot_23xx.c control_2xxx.c +OBJS = ${addprefix obj/,${patsubst %.c,%.o,$(SRC)}} + +PSEUDOTERM_SRC = pseudoterm.c serial.c control_2xxx.c +PSEUDOTERM_OBJS = ${addprefix obj/,${patsubst %.c,%.o,$(PSEUDOTERM_SRC)}} + +TARGETDIR = bin + +lpc2k_pgm: $(OBJS) + $(CC) -o $(TARGETDIR)/lpc2k_pgm $(OBJS) + +pseudoterm: $(PSEUDOTERM_OBJS) + $(CC) -lpthread -o $(TARGETDIR)/pseudoterm $(PSEUDOTERM_OBJS) + +chipinfo.o: boot_2xxx.h boot_23xx.h + +static: $(OBJS) mkstaticlist + $(CC) -o $(TARGETDIR)/lpc2k_pgm $(OBJS) `./mkstaticlist` + +obj/%.o : src/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +cksum_test: cksum_test.c uuencode.o cksum_test.o + $(CC) $(CFLAGS) -o $(TARGETDIR)/cksum_test obj/cksum_test.o obj/uuencode.o + +boot_2xxx.c boot_2xxx.h: boot_2xxx.armasm mkbootc + arm-elf-as -o boot_2xxx.armobj boot_2xxx.armasm + arm-elf-objdump -d boot_2xxx.armobj | ./mkbootc boot_2xxx + +boot_23xx.c boot_23xx.h: src/boot_23xx.armasm mkbootc + arm-elf-as -o obj/boot_23xx.armobj src/boot_23xx.armasm + arm-elf-objdump -d obj/boot_23xx.armobj | ./mkbootc boot_23xx + +clean: + rm -f bin/lpc2k_pgm cksum_test obj/*.o core core.* obj/*.armobj bin/pseudoterm + +obj/gui.o: src/gui.c + $(CC) $(CFLAGS) `gtk-config --cflags` -c src/gui.c -o obj/gui.o diff --git a/msba2/tools/README.txt b/msba2/tools/README.txt new file mode 100644 index 0000000000..8fd6adb012 --- /dev/null +++ b/msba2/tools/README.txt @@ -0,0 +1,144 @@ +This utility downloads code to Philip LPC 2000 series chips, using the +bootloader communication protocol documented in the LPC2106/2105/2104 +User Manual, Sept 2003 revision, pages 177 to 192. This code has also +been tested with LPC2131 and LPC2138 chips (thanks to New Micros for +providing eval boards). It may work with other Philips ARM LPC parts. + + + +Usage: +----- + +When you start the program, it's small control window appears, and a +xterm terminal window is launched. The Xterm window allows you to +simply leave lpc2k_pgm running and interface with the LPC uart using +that window. Most people configure "printf" on in their code to print +to UART0, which will appear in this window. + +This program has 4 settings: + +Firmware: The intel-hex file with your LPC firmware to program. +Port: Which serial device to use. +Baud: The baud rate to communicate. +Crystal: The speed of the crystal on your LPC board. + +Once you have set up these values, simply press the "Program Now" +button to write your firmware to the LPC flash memory, and automatically +run it. If your firmware communicates on UART0, its messages will appear +in the xterm window, and anything you type in that window will be +transmitted to your board. + +The "Reboot" button may be used to reboot your code (assuming you have +connected DTR appropriately). The "Bootloader" button may be used to +stop your code by rebooting into the bootloader, rather than your program. + + + +Hardware Requirements: +--------------------- + +You must have a compatible Philips LPC chip with its UART0 interfaced +to a serial port on your PC. + +You must be able to reset the chip and cause it to enter bootloader mode. +Normally, this is done by connecting the (TTL level translated) DTR signal +to the LPC reset, so that when DTR is high (the TTL version is low), the +Philips chip is in reset mode. Alternately, a pushbutton may be used, +but you will need to manually press the button every time you want to get +back into bootloader mode (while this program attempts to sync baud rates), +rather than letting DTR do it automatically. A few minutes spent wiring +up your circuit so DTR can reset the board will save you much trouble as +you develop code. + +P0.14 must be connected low shortly after reset. Normally, this pin +is just shorted to ground using a jumper. Starting with version 1.02, +you can simply leave this shorted to ground. If your design needs to +use this pin, you may also build a simple circuit that forces this pin +to ground when RTS is high. + + + +Software Requirements: +--------------------- + +You must have a Linux-based system running X Windows. This code has +been tested with Linux kernel 2.4.20 and 2.6.8, and should work with +almost any linux system. + +You must have the "xterm" program installed. Nearly all linux +distrubtions provide this, and it is often installed by default. If +you do not have it, simply install from your linux distribution. + +Your serial port device file (usually /dev/ttyS0 or /dev/ttyS1) must +allow permission for you to use the serial port. + +GTK 1.2 is used for the GUI. Many newer systems only have GTK version +2 (or higher). If you have one of these systems, perhaps you can +install GTK 1.2 (including the development libraries) to allow you to +compile this code. Alternately, you may be able to use the semi-static +build, which includes a copy of this code built into the program. + + + +Building and Installation: +------------------------- + +This software is only provided semi-static binary and source code form. + +To use the semi-static binary, simply copy it to a location where you +can run it, and change the permissions if necessary: + + cp lpc2k_pgm /usr/local/bin + chmod 755 /usr/local/bin/lpc2k_pgm + +The semi-static binary has all of the GTK and X11 libraries statically +linked into it, for maximum compatibility with all linux distributions. +The only disadvantage is, of course, that this uses an extra 1.4 megs +of RAM, with (might) otherwise be shared with other programs. If you +simply want to run this program with minimal work, using the semi-static +binary may be the easiest way. + +If you compile from the source code, the result should be a small +binary that is optimal for your system. + +To build from source, you must have GTK+ 1.2 development libraries +and GCC properly installed. Nearly all linux distributions provide +these as packages, but you may need to install them before you can +compile the code. + +TODO: specific instructions for Debian stable +TODO: specific instructions for Debian testing/unstable +TODO: specific instructions for Fedora +TODO: specific instructions for Suse + +Simply type "make" to build the code. The resulting "lpc2k_pgm" +program can be run from any location. Simply copy to /usr/local/bin, +or where ever you like. + + + +Contact Info: +------------ + +Paul Stoffregen +paul@pjrc.com +http://www.pjrc.com/arm/lpc2k_pgm + +If you discover a bug, you want to request a new feature, or you have +a new Philips LPC chip which is not recognized, please attempt to +provide COMPLETE information in your message. + +If you have problems building from source, please contact me with ALL +of the following: + +1: Complete copy of all messages during the build. +2: Output of "gtk-config --version" +3: Output of "gtk-config --libs" +4: Output of "gtk-config --cflags" +5: Output of "uname -a" +6: Other info... which linux distribution, version, other software + +If you get "Command not found" when trying to run "gtk-config", this +is a sure sign that you do not have GTK+ 1.2 installed. + + diff --git a/msba2/tools/armtools.txt b/msba2/tools/armtools.txt new file mode 100644 index 0000000000..c91a4853f7 --- /dev/null +++ b/msba2/tools/armtools.txt @@ -0,0 +1,15 @@ +This directory contains flash & terminal-utilities for use with +the msb_av2 platform used by the FeuerWhere-Project. + +Usage: +Running "./pseudoterm /dev/ttyUSB1" will start the terminal-emulator, +open the specified port and reset the connected msb_av2-board. +If it receives a SIGUSR2, the terminal closes the port an waits. +On reception of a SIGUSR1, it reopens the port and resets the ARM. + +"./lpc2k_pgm /dev/ttyUSB1 /path/to/firmware.ihex" will do what you +expect, but it will additionally run "killall -SIGUSR2 pseudoterm" before +anѕ "killall -SIGUSR1 pseudoterm" after flashing. + +Together, the tools enable you to have a terminal connected to the board +at all times, but let you flash whenever you feel like. diff --git a/msba2/tools/flash.cmd b/msba2/tools/flash.cmd new file mode 100755 index 0000000000..e957ca2b65 --- /dev/null +++ b/msba2/tools/flash.cmd @@ -0,0 +1,2 @@ +fm.exe "COM(%1, 230400) DEVICE(LPC2387, 16.000000) HARDWARE(BOOTEXEC, 50, 100) HIGHSPEED(0, 230400) ERASEUSED(%2, PROTECTISP) HEXFILE(%2, NOCHECKSUMS, NOFILL, PROTECTISP) RESET" +sleep 2 diff --git a/msba2/tools/flashutil.sh b/msba2/tools/flashutil.sh new file mode 100755 index 0000000000..c97d7c9a63 --- /dev/null +++ b/msba2/tools/flashutil.sh @@ -0,0 +1,113 @@ +#/bin/bash + +linux_checkid() { + udevinfo -a -n ${1} | grep -q "ATTRS{product}==\"${2}\"" +} + +windows_flash_fm() { + echo "Checking FTDI device on COM${1}" + PORTINFO=`${BASEDIR}/../../../tools/windows/ftdiinfo/bin/Debug/ftdiinfo.exe /l COM${1}` + PORTCHECK=`echo ${PORTINFO} | awk '{ print $1 }'` + BOARDCHECK=`echo ${PORTINFO} | awk '{ print $3 }'` + SERIAL=`echo ${PORTINFO} | awk '{ print $2 }'` + if [ "${PORTCHECK}" != "COM${1}" ]; then + echo " port mismatch / ftdiinfo failed" + exit 1 + fi + if [ "${BOARDCHECK}" != "\"${FTDI_ID}\"" ]; then + echo " target mismatch: target board is \"${FTDI_ID}\", connected is ${BOARDCHECK}" + exit 1 + fi + + echo "Flashing ${HEXFILE} to COM${1} (${BOARDCHECK} serial ${SERIAL})" + # Using FlashMagic on Windows (in separate window) + cmd /C start "FlashMagic ${HEXFILE} to ${BOARDCHECK} on COM${1}" fm.exe "COM(${1}, 230400) DEVICE(LPC2387, 16.000000) HARDWARE(BOOTEXEC, 50, 100) HIGHSPEED(0, 230400) ERASEUSED(${HEXFILE}, PROTECTISP) HEXFILE(${HEXFILE}, NOCHECKSUMS, NOFILL, PROTECTISP) RESET" +} + +windows_flash_openocd() { + echo "Flashing ${HEXFILE} through JTAG" + # Using OpenOcd on Windows + #cmd /C start "OpenOCD ${HEXFILE} to ${BOARDCHECK}" + bash -x ${OPENOCD} ${OPENOCD_IF} "mt_flash ${HEXFILE}; reset run; shutdown" +} + +TEMP=`getopt -a -o b:i:p:f:: --long basedir:,id:,ports:,file:,openocd:,openocd-if:,xxx:: \ + -n 'flashutil.sh' -- "$@"` + +if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi + +# Note the quotes around `$TEMP': they are essential! +eval set -- "$TEMP" + +while true ; do + echo $1: $2 + case "$1" in + -b|--basedir) BASEDIR=$2 ; shift 2 ;; + -i|--id) FTDI_ID=$2; shift 2 ;; + -p|--ports) PORTS=`echo $2 | sed -e 's:,: :g'`; shift 2 ;; + --openocd) OPENOCD=$2; shift 2 ;; + --openocd-if) OPENOCD_IF=$2; shift 2 ;; + + --) HEXFILE=$2 ; shift ; break ;; + *) echo "Internal error!" ; exit 1 ;; + esac +done + +if [ "${OS}" = "Windows_NT" ]; then + WINDOWS=1 +fi + +FLASHUTIL_SHELL=${FLASHUTIL_SHELL:-"xterm -e"} + +if [ "x${WINDOWS}x" = "xx" ]; then + echo Pausing terminal + ${BASEDIR}/termctrl.sh pause +else + HEXFILE=`echo ${HEXFILE} | sed -e 's:/:\\\\:g'` + BASEDIRWIN=`echo ${BASEDIR} | sed -e 's:/:\\\\:g'` +fi + +pids="" + +# +# for OpenOCD let the user verify, that the correct board is connected +# +if [ ${PORTS} = "openocd" ]; then + [ "$OPENOCD" != "" ] || exit 1 + [ "$OPENOCD_IF" != "" ] || exit 1 +# echo -n "Is the board connected to the JTAG a '${FTDI_ID}' (y/n)? " +# read REPLY +# [ "$REPLY" = "y" ] || exit 1 +fi +# +# start a flasher for each port +# +for PORT in $PORTS; do + if [ "x${WINDOWS}x" != "xx" ]; then + if [ "${PORT}" = "openocd" ]; then + windows_flash_openocd + else + windows_flash_fm ${PORT} + fi + else + if [ "${PORT}" = "openocd" ]; then + ${OPENOCD} ${OPENOCD_IF} "mt_flash ${HEXFILE}; reset run; shutdown" + else + echo Flashing ${HEXFILE} to ${PORT} + # using homemade lpc2k_pgm else + ${FLASHUTIL_SHELL} "${BASEDIR}/bin/lpc2k_pgm ${PORT} ${HEXFILE}; sleep 2" & + pids="${pids} $!" + fi + fi +done + +### wait for all flasher processes to finish +echo Waiting until all devices have been programmed... +for pid in "${pids}"; do + wait ${pid} +done + +if [ "x${WINDOWS}x" = "xx" ]; then + echo Resuming terminal + ${BASEDIR}/termctrl.sh continue +fi diff --git a/msba2/tools/mkbootc b/msba2/tools/mkbootc new file mode 100644 index 0000000000..4c0d9554dc --- /dev/null +++ b/msba2/tools/mkbootc @@ -0,0 +1,28 @@ +#! /usr/bin/perl + +$h = '[0-9A-Fa-f]'; +$n = 1; +while () { + next unless /^\s*$h+:\s+($h{8})/; + $data[$n++] = "0x$1"; +} +$data[0] = $n; +#$size = $ARGV[0]; +#$size =~ tr/a-z/A-Z/; +#$size .= '_SIZE'; + +open H, ">$ARGV[0].h" or die "unable to write boot.h\n"; +print H "/* automatically generated from $ARGV[0].armasm */\n"; +#print H "#define $size $n\n"; +print H "extern const unsigned int ${ARGV[0]}[];\n"; +close H; + +open C, ">$ARGV[0].c" or die "unable to write boot.c\n"; +print C "/* automatically generated from $ARGV[0].armasm */\n"; +print C "#include \"$ARGV[0].h\"\n"; +print C "const unsigned int ${ARGV[0]}[] = {\n"; +print C "\t", join(', ', @data), "\n"; +print C "};\n"; +close C; + + diff --git a/msba2/tools/mkstaticlist b/msba2/tools/mkstaticlist new file mode 100644 index 0000000000..4ad31030ca --- /dev/null +++ b/msba2/tools/mkstaticlist @@ -0,0 +1,47 @@ +#! /usr/bin/perl + +@arg = split(/\s+/, `gtk-config --libs`); + +%liblist = ( + 'libgtk.a', '/usr/lib/libgtk.a', + 'libgdk.a', '/usr/lib/libgdk.a', + 'libgmodule.a', '/usr/lib/libgmodule.a', + 'libglib.a', '/usr/lib/libglib.a', + 'libXi.a', '/usr/X11R6/lib/libXi.a', + 'libXext.a', '/usr/X11R6/lib/libXext.a', + 'libX11.a', '/usr/X11R6/lib/libX11.a' +); + + +for ($i=0; $i<@arg; $i++) { + $a = $arg[$i]; + next if $a eq '-rdynamic'; # always delete -rdynamic + if (($a eq '-lm') || ($a eq '-ldl') || ($a =~ /^-L/)) { + # a few things we never change + print "$a "; + next; + } + if ($a =~ /^-l/) { + $lib = $'; + $lib = 'lib' . $lib . '.a'; + # first check if it's in the known location + if (-f $liblist{$lib}) { + print $liblist{$lib}, " "; + next; + } + # resort to trying whereis to find it + @source = split(/\s+/, `whereis $lib`); + undef($static); + for ($j=0; $j<@source; $j++) { + $static = $source[$j] if $source[$j] =~ /$lib$/; + } + # if we found a static lib, use it. + if ($static) { + print $static, " "; + } else { + print $a, " "; + } + } +} +print "\n"; + diff --git a/msba2/tools/obj/boot_23xx.d b/msba2/tools/obj/boot_23xx.d new file mode 100644 index 0000000000..874c0d70ef --- /dev/null +++ b/msba2/tools/obj/boot_23xx.d @@ -0,0 +1,3 @@ +obj/boot_23xx.d obj/boot_23xx.o: src/boot_23xx.c src/boot_23xx.h + +src/boot_23xx.h: diff --git a/msba2/tools/obj/boot_2xxx.d b/msba2/tools/obj/boot_2xxx.d new file mode 100644 index 0000000000..b33d065787 --- /dev/null +++ b/msba2/tools/obj/boot_2xxx.d @@ -0,0 +1,3 @@ +obj/boot_2xxx.d obj/boot_2xxx.o: src/boot_2xxx.c src/boot_2xxx.h + +src/boot_2xxx.h: diff --git a/msba2/tools/obj/chipinfo.d b/msba2/tools/obj/chipinfo.d new file mode 100644 index 0000000000..b6840f4c8d --- /dev/null +++ b/msba2/tools/obj/chipinfo.d @@ -0,0 +1,8 @@ +obj/chipinfo.d obj/chipinfo.o: src/chipinfo.c src/chipinfo.h \ + src/boot_2xxx.h src/boot_23xx.h + +src/chipinfo.h: + +src/boot_2xxx.h: + +src/boot_23xx.h: diff --git a/msba2/tools/obj/control_2xxx.d b/msba2/tools/obj/control_2xxx.d new file mode 100644 index 0000000000..d91c1b90fe --- /dev/null +++ b/msba2/tools/obj/control_2xxx.d @@ -0,0 +1,6 @@ +obj/control_2xxx.d obj/control_2xxx.o: src/control_2xxx.c \ + src/control_2xxx.h src/serial.h + +src/control_2xxx.h: + +src/serial.h: diff --git a/msba2/tools/obj/download.d b/msba2/tools/obj/download.d new file mode 100644 index 0000000000..1bdc25ec41 --- /dev/null +++ b/msba2/tools/obj/download.d @@ -0,0 +1,19 @@ +obj/download.d obj/download.o: src/download.c src/lpc2k_pgm.h \ + src/download.h src/serial.h src/ihex.h src/uuencode.h src/chipinfo.h \ + src/boot.h src/control_2xxx.h + +src/lpc2k_pgm.h: + +src/download.h: + +src/serial.h: + +src/ihex.h: + +src/uuencode.h: + +src/chipinfo.h: + +src/boot.h: + +src/control_2xxx.h: diff --git a/msba2/tools/obj/ihex.d b/msba2/tools/obj/ihex.d new file mode 100644 index 0000000000..e2430e90ca --- /dev/null +++ b/msba2/tools/obj/ihex.d @@ -0,0 +1,3 @@ +obj/ihex.d obj/ihex.o: src/ihex.c src/ihex.h + +src/ihex.h: diff --git a/msba2/tools/obj/lpc2k_pgm.d b/msba2/tools/obj/lpc2k_pgm.d new file mode 100644 index 0000000000..50838bbfcf --- /dev/null +++ b/msba2/tools/obj/lpc2k_pgm.d @@ -0,0 +1,8 @@ +obj/lpc2k_pgm.d obj/lpc2k_pgm.o: src/lpc2k_pgm.c src/lpc2k_pgm.h \ + src/serial.h src/download.h + +src/lpc2k_pgm.h: + +src/serial.h: + +src/download.h: diff --git a/msba2/tools/obj/pseudoterm.d b/msba2/tools/obj/pseudoterm.d new file mode 100644 index 0000000000..3524292e42 --- /dev/null +++ b/msba2/tools/obj/pseudoterm.d @@ -0,0 +1,6 @@ +obj/pseudoterm.d obj/pseudoterm.o: src/pseudoterm.c src/serial.h \ + src/download.h + +src/serial.h: + +src/download.h: diff --git a/msba2/tools/obj/serial.d b/msba2/tools/obj/serial.d new file mode 100644 index 0000000000..70d6d9d7dc --- /dev/null +++ b/msba2/tools/obj/serial.d @@ -0,0 +1,3 @@ +obj/serial.d obj/serial.o: src/serial.c src/serial.h + +src/serial.h: diff --git a/msba2/tools/obj/uuencode.d b/msba2/tools/obj/uuencode.d new file mode 100644 index 0000000000..fa6d25aca3 --- /dev/null +++ b/msba2/tools/obj/uuencode.d @@ -0,0 +1,3 @@ +obj/uuencode.d obj/uuencode.o: src/uuencode.c src/uuencode.h + +src/uuencode.h: diff --git a/msba2/tools/src/Jamfile b/msba2/tools/src/Jamfile new file mode 100644 index 0000000000..43ead81f93 --- /dev/null +++ b/msba2/tools/src/Jamfile @@ -0,0 +1,9 @@ +Library liblpc2k : download.c uuencode.c ihex.c serial.c chipinfo.c boot_2xxx.c boot_23xx.c control_2xxx.c ; + +LinkLibraries lpc2k_pgm : liblpc2k ; + +LinkLibraries pseudoterm : liblpc2k ; +LINKFLAGS on pseudoterm = -lrt ; + +Main lpc2k_pgm : lpc2k_pgm.c ; +Main pseudoterm : pseudoterm.c ; diff --git a/msba2/tools/src/boot.h b/msba2/tools/src/boot.h new file mode 100644 index 0000000000..1560f10380 --- /dev/null +++ b/msba2/tools/src/boot.h @@ -0,0 +1,9 @@ + +typedef struct { + int size; + const int *prog; +} boot_t; + + + + diff --git a/msba2/tools/src/boot_23xx.armasm b/msba2/tools/src/boot_23xx.armasm new file mode 100644 index 0000000000..50e29957ff --- /dev/null +++ b/msba2/tools/src/boot_23xx.armasm @@ -0,0 +1,32 @@ + /* ARM code to run user code */ + /* on the LPC23xx chips, the bootloader defaults to using the RC */ + /* osciallator and it activates the PLL to create 14.78 MHz, even */ + /* if there is no crystal. However, when we use try to jump to */ + /* the user's code, their startup routine may (incorrectly) assume */ + /* the PLL is not enabled and crash if it is. So in addition to */ + /* remapping the reset vector to flash, we have to shut off the */ + /* PLL so the user's startup code sees the same conditions as it */ + /* would following a hard reset */ +begin: + adr r0, const + ldr r1, [r0] /* r1 points to MEMMAP register */ + ldr r2, [r0,#4] /* r2 points to PLLCON */ + ldr r3, [r0,#8] /* r3 points to PLLFEED */ + mov r0, #1 + str r0, [r1] /* remap interrupt vectors to flash */ + mov r4, #0xAA + mov r5, #0x55 + str r0, [r2] /* disconnect the PLL, PLLCON = 1 */ + str r4, [r3] + str r5, [r3] + mov r0, #0 + str r0, [r2] /* disable the PLL, PLLCON = 0 */ + str r4, [r3] + str r5, [r3] + mov pc, #0 /* and then jump to the user's code */ +const: + .int 0xE01FC040 /* MEMMAP register */ + .int 0xE01FC080 /* PLLCON */ + .int 0xE01FC08C /* PLLFEED */ + + diff --git a/msba2/tools/src/boot_23xx.c b/msba2/tools/src/boot_23xx.c new file mode 100644 index 0000000000..9901171cc0 --- /dev/null +++ b/msba2/tools/src/boot_23xx.c @@ -0,0 +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 +}; diff --git a/msba2/tools/src/boot_23xx.h b/msba2/tools/src/boot_23xx.h new file mode 100644 index 0000000000..0696a29312 --- /dev/null +++ b/msba2/tools/src/boot_23xx.h @@ -0,0 +1,2 @@ +/* automatically generated from boot_23xx.armasm */ +extern const unsigned int boot_23xx[]; diff --git a/msba2/tools/src/boot_2xxx.armasm b/msba2/tools/src/boot_2xxx.armasm new file mode 100644 index 0000000000..38e171520a --- /dev/null +++ b/msba2/tools/src/boot_2xxx.armasm @@ -0,0 +1,15 @@ + /* ARM code to run user code */ + /* This allows us to jump to the user's code in flash. We have */ + /* to remap the flash before jumping. */ +begin: + adr r0, const + ldr r1, [r0] /* r1 points to MEMMAP register */ + mov r0, #1 + str r0, [r1] /* remap interrupt vectors to flash */ + mov pc, #0 /* and then jump to the user's code */ +const: + .int 0xE01FC040 /* MEMMAP register */ + + + + diff --git a/msba2/tools/src/boot_2xxx.c b/msba2/tools/src/boot_2xxx.c new file mode 100644 index 0000000000..4d9b367ebe --- /dev/null +++ b/msba2/tools/src/boot_2xxx.c @@ -0,0 +1,5 @@ +/* automatically generated from boot_2xxx.armasm */ +#include "boot_2xxx.h" +const unsigned int boot_2xxx[] = { + 7, 0xe28f000c, 0xe5901000, 0xe3a00001, 0xe5810000, 0xe3a0f000, 0xe01fc040 +}; diff --git a/msba2/tools/src/boot_2xxx.h b/msba2/tools/src/boot_2xxx.h new file mode 100644 index 0000000000..333188def2 --- /dev/null +++ b/msba2/tools/src/boot_2xxx.h @@ -0,0 +1,2 @@ +/* automatically generated from boot_2xxx.armasm */ +extern const unsigned int boot_2xxx[]; diff --git a/msba2/tools/src/chipinfo.c b/msba2/tools/src/chipinfo.c new file mode 100644 index 0000000000..4f3f1a9d7e --- /dev/null +++ b/msba2/tools/src/chipinfo.c @@ -0,0 +1,159 @@ +/* + * LPC 2000 Loader, http://www.pjrc.com/arm/lpc2k_pgm + * Copyright (c) 2004, PJRC.COM, LLC, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include +#include "chipinfo.h" +#include "boot_2xxx.h" +#include "boot_23xx.h" + + +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} +}; + +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} +}; + +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} +}; + + + +// 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. + + +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} +}; + + + +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" +}; + diff --git a/msba2/tools/src/chipinfo.h b/msba2/tools/src/chipinfo.h new file mode 100644 index 0000000000..1b12bb3666 --- /dev/null +++ b/msba2/tools/src/chipinfo.h @@ -0,0 +1,20 @@ +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 +}; + +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) +}; + +extern struct chip_info_struct chip_info[]; + + diff --git a/msba2/tools/src/cksum_test.c b/msba2/tools/src/cksum_test.c new file mode 100644 index 0000000000..8cff9b55e2 --- /dev/null +++ b/msba2/tools/src/cksum_test.c @@ -0,0 +1,76 @@ +/* + * LPC 2000 Loader, http://www.pjrc.com/arm/lpc2k_pgm + * Copyright (c) 2004, PJRC.COM, LLC, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* 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" + * 4: Output of "gtk-config --cflags" + * 5: Output of "uname -a" + * 6: Version of GTK installed... eg, type: ls -l /lib/libgtk* + * 7: Other info... which linux distribution, version, other software + */ + + +#include +#include +#include + +#include "uuencode.h" + + +unsigned int sum=0; + + + +void cksum(const char *str) +{ + int num, i; + unsigned char data[256]; + + if (str == NULL) return; + num = uudecode(str, data, sizeof(data)); + for (i=0; i +#include +#include + +#include "serial.h" + +void hard_reset_to_bootloader(void) +{ + printf("Reset CPU (into bootloader)\r\n"); + set_rts(1); // 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 + 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); +} diff --git a/msba2/tools/src/control_2xxx.h b/msba2/tools/src/control_2xxx.h new file mode 100644 index 0000000000..e37e2e29d5 --- /dev/null +++ b/msba2/tools/src/control_2xxx.h @@ -0,0 +1,8 @@ +#ifndef CONTROL_2XXXX_H +#define CONTROL_2XXXX_H + +void hard_reset_to_bootloader(void); +void hard_reset_to_user_code(void); + +#endif // ..._H + diff --git a/msba2/tools/src/download.c b/msba2/tools/src/download.c new file mode 100644 index 0000000000..5494661dfd --- /dev/null +++ b/msba2/tools/src/download.c @@ -0,0 +1,972 @@ +/* + * LPC 2000 Loader, http://www.pjrc.com/arm/lpc2k_pgm + * Copyright (c) 2004, PJRC.COM, LLC, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* 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" + * 4: Output of "gtk-config --cflags" + * 5: Output of "uname -a" + * 6: Version of GTK installed... eg, type: ls -l /lib/libgtk* + * 7: Other info... which linux distribution, version, other software + */ + +#include +#include +#include +#include +#include +#include + +#include "lpc2k_pgm.h" +#include "download.h" +#include "serial.h" +#include "ihex.h" +#include "uuencode.h" +//#include "gui.h" +#include "chipinfo.h" +#include "boot.h" +#include "control_2xxx.h" + + +// This will cause all bytes send and received to be printed as hex. +// It's a LOT of extra output, but useful for difficult debugging +// of what's _really_ being sent and received. +//#define PRINT_TX_RX_BYTES + + +static void download_main(int event); +static void xmit_cmd(const char *cmd, int max_time); +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 char expected_echo_buf[4096]; +static char *expected_echo_ptr=NULL; +static char parsed_response_buf[4096]; +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"; + +/****************************************************************/ +/* */ +/* Main Download Section */ +/* */ +/****************************************************************/ + +// possible states +#define SYNC_1 1 +#define SYNC_2 2 +#define SYNC_3 3 +#define CHIP_ID 4 +#define UNLOCK 5 +#define BLANK_CHECK_SECTOR 6 +#define ERASE_PREPARE 7 +#define ERASE_SECTOR 8 +#define DOWNLOAD_CODE 9 +#define XMIT_DATA 10 +#define XMIT_CKSUM 11 +#define WRITE_PREPARE 12 +#define WRITE_SECTOR 13 +#define BOOT_HARD 14 +#define BOOT_SOFT 15 +#define BOOT_XMIT_DATA 16 +#define BOOT_XMIT_CKSUM 17 +#define BOOT_RUN_CODE 18 + + +// possible input values for "event" +#define BEGIN 1 +#define RESPONSE 2 +#define TIMEOUT 3 +#define RETRY 4 + + + + +int download_begin(char* file) +{ + 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) { + /* abort on ioerror */ + return 0; + } + 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); +} + +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); +} + + +static unsigned int sum(unsigned char *data, int num) +{ + unsigned int sum=0; + + while (num > 0) { + sum += *data++; + num--; + } + 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; +} + +void trim_crlf(char *str) +{ + 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); + } +} + + +#define NO_SYNC_ERR "\r\n\ +ERROR: Unable to sync to baud rate.\r\n\ +This probably means the LPC2xxx chip is not connected\r\n\ +or it is not being reset, or P0.14 is not low after\r\n\ +reset to cause it to enter the bootloader mode.\r\n\r\n\ +Please check the serial port connection, make sure\r\n\ +pin P0.14 is low (or tied to RTS via RS-232 level\r\n\ +translator), and the chip has been reset (or reset\r\n\ +is tied to DTR via RS-232 level translator).\r\n" + +#define UNKNOWN_CHIP_ERROR "\r\n\ +Unknown chip ID: \"%s\".\r\n\r\n\ +Perhaps you have a new Philips LPC chip which does not\r\n\ +have its ID string and sector map defined in this program?\r\n\ +Please contact paul@pjrc.com. Please include an exact copy\r\n\ +of this message and any info about the chip and other\r\n\ +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; + + + 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; + } + } +} + + +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); +} + + +/****************************************************************/ +/* */ +/* Transmit Commands to Bootloader */ +/* */ +/****************************************************************/ + + + +static void xmit_cmd(const char *cmd, int max_time) +{ + int len; + + if (cmd == NULL || *cmd == '\0') return; + len = strlen(cmd); + +#ifdef PRINT_TX_RX_BYTES + printf("tx %d bytes: %s\n", len, cmd); +#endif + + input_flush_serial_port(); + + write_serial_port(cmd, len); + + 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; + + response_timer = max_time; +} + + + +/****************************************************************/ +/* */ +/* Handlers that respond to input */ +/* */ +/****************************************************************/ + + +/* +Whenever the main gtk event loop detects more input has arrived from the +serial port, and we're in the process of a download, it calls here to +hand off the data. We're supposed to match it up to the echo buffer, +and then store it into the parsed response buffer and if it looks like +this might be a complete response, call download_main with a response +event. +*/ +void download_rx_port(const unsigned char *buf, int num) +{ + int i=0; + + if (num <= 0) return; + + // echo the data + //write(term_fd, buf, num); + +#ifdef PRINT_TX_RX_BYTES + printf("rx %d bytes:", num); + for (i=0; i "); +#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); + } +} + + + +/* +During a download, this is supposed to get called at 100 Hz. Whenever +something is transmitted and we expect a response, the response_timer +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); + } + } +} + +/* +During a download, all input the user types into the terminal is sent +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?? +} + + diff --git a/msba2/tools/src/download.h b/msba2/tools/src/download.h new file mode 100644 index 0000000000..4d57bfa5d0 --- /dev/null +++ b/msba2/tools/src/download.h @@ -0,0 +1,8 @@ +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); +extern void download_cancel(const char *mesg); +extern void download_rx_term(const unsigned char *buf, int num); +extern void download_rx_port(const unsigned char *buf, int num); +extern void download_timer(void); diff --git a/msba2/tools/src/gui.c b/msba2/tools/src/gui.c new file mode 100644 index 0000000000..ce6d13c96e --- /dev/null +++ b/msba2/tools/src/gui.c @@ -0,0 +1,387 @@ +/* + * LPC 2000 Loader, http://www.pjrc.com/arm/lpc2k_pgm + * Copyright (c) 2004, PJRC.COM, LLC, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* 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" + * 4: Output of "gtk-config --cflags" + * 5: Output of "uname -a" + * 6: Version of GTK installed... eg, type: ls -l /lib/libgtk* + * 7: Other info... which linux distribution, version, other software + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gui.h" +#include "settings.h" +#include "serial.h" +#include "lpc2k_pgm.h" +#include "download.h" + + +static GtkWidget *firmware_label, *firmware_entry, *program_button; +static GtkWidget *port_label, *port_entry, *baud_label, *baud_combo; +static GtkWidget *crystal_label, *crystal_entry, *mhz_label; +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; + +gint do_quit(GtkWidget *widget, gpointer *data) +{ + 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; +} + +int file_exists(const char *filename) +{ + struct stat file_stats; + int r; + + r = stat(filename, &file_stats); + if (r != 0) return 0; + 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); +} + +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 0 + 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; +} + +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; +} + +gint do_new_port(GtkWidget *widget, gpointer *data) +{ + port_timeout = 12; + return FALSE; +} + +gint do_new_baud(GtkWidget *widget, gpointer *data) +{ + 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; +} + +gint do_new_crystal(GtkWidget *widget, gpointer *data) +{ + const char *xtal; + + 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; +} + +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); + } + } +} + +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); + } + } +} + + +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(); +} + + +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); +} diff --git a/msba2/tools/src/gui.h b/msba2/tools/src/gui.h new file mode 100644 index 0000000000..fadde6db6d --- /dev/null +++ b/msba2/tools/src/gui.h @@ -0,0 +1,3 @@ +extern void create_window(int *argc, char ***argv); +extern void run_gui(void); +extern void done_program(int still_in_bootloader); diff --git a/msba2/tools/src/ihex.c b/msba2/tools/src/ihex.c new file mode 100644 index 0000000000..cda37af66c --- /dev/null +++ b/msba2/tools/src/ihex.c @@ -0,0 +1,229 @@ +/* + * LPC 2000 Loader, http://www.pjrc.com/arm/lpc2k_pgm + * Copyright (c) 2004, PJRC.COM, LLC, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* 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" + * 4: Output of "gtk-config --cflags" + * 5: Output of "uname -a" + * 6: Version of GTK installed... eg, type: ls -l /lib/libgtk* + * 7: Other info... which linux distribution, version, other software + */ + +#include +#include + + +// the maximum flash image size we can support +// chips with larger memory may be used, but only this +// much intel-hex data can be loaded into memory! +#define MAX_MEMORY_SIZE 0x80000 + + +#include "ihex.h" + + +static unsigned char firmware_image[MAX_MEMORY_SIZE]; +static unsigned char firmware_mask[MAX_MEMORY_SIZE]; +static int end_record_seen=0; +static int byte_count; +static unsigned int extended_addr = 0; + + +static int parse_hex_line(char *line); + + +/****************************************************************/ +/* */ +/* Read Intel Hex File */ +/* */ +/****************************************************************/ + + + +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) 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 += 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; +} + + +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; +} + +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= MAX_MEMORY_SIZE) { + return; + } + for (i=0; i + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* 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" + * 4: Output of "gtk-config --cflags" + * 5: Output of "uname -a" + * 6: Version of GTK installed... eg, type: ls -l /lib/libgtk* + * 7: Other info... which linux distribution, version, other software + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "lpc2k_pgm.h" +#include "serial.h" +#include "download.h" + +int programming_done = 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; + + num = read_serial_port(buf, sizeof(buf)); + if (num > 0) { + download_rx_port(buf, num); + } +} + +void usage() { + printf("usage: lpc2k_pgm \n"); +} + +int main(int argc, char **argv) +{ + if (argc < 3 ) { + usage(); + exit(1); + } + + char* port_name = argv[1]; + char* file_name = argv[2]; + + sleep(1); + + if (open_serial_port(port_name) < 0) { + return(1); + } + + if (!download_begin(file_name)) { + return 1; + } + while (!programming_done) { + handle_port_input(); + } + + close_serial_port(); + + return 0; +} + diff --git a/msba2/tools/src/lpc2k_pgm.h b/msba2/tools/src/lpc2k_pgm.h new file mode 100644 index 0000000000..0a5f5a7eeb --- /dev/null +++ b/msba2/tools/src/lpc2k_pgm.h @@ -0,0 +1,12 @@ +#ifndef LPC2K_PGM +#define LPC2K_PGM + +/* gets a name like "115200", sets baudrate accordingly. */ +void change_baud(const char *baud_name); + +/* called before/after using serial device, used to have terminal + * close the device. +*/ +void signal_terminal(); + +#endif // LPC2K_PGM diff --git a/msba2/tools/src/pseudoterm.c b/msba2/tools/src/pseudoterm.c new file mode 100644 index 0000000000..ce8a446b32 --- /dev/null +++ b/msba2/tools/src/pseudoterm.c @@ -0,0 +1,135 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "serial.h" +#include "pthread.h" +#include "download.h" + +int tty_fd; +int stopped = 0; +char* port_name = "/dev/ttyUSB1"; +pthread_t serial_reader; + +void* serial_reader_func(void* arg) { + unsigned char buf[255]; + while(1) { + int n = read_serial_port(buf, sizeof(buf)); + if (n > 0) { + write(tty_fd, buf, n); + } + } +} + +int init() { + int result = open_serial_port(port_name); + pthread_create(&serial_reader, NULL, serial_reader_func, NULL); + hard_reset_to_user_code(); + return result; +} + +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"); + exit(1); + } + } + } else if (signal == SIGUSR2) { + if (!stopped) { + stopped = 1; + printf("\nSignal received, closing port. \r\n"); + pthread_cancel(serial_reader); + close_serial_port(); + } + } +} + +int open_tty(void) +{ + 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; + term_setting.c_oflag |= ( ONLRET ); + term_setting.c_iflag |= (IGNBRK | IGNPAR); + term_setting.c_iflag &= ~(ISTRIP | BRKINT); + term_setting.c_lflag &= ~(ICANON | ISIG | ECHO); + 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() { + struct sigaction action; + sigemptyset (&action.sa_mask); + sigaddset( &action.sa_mask, SIGUSR1 ); + sigaddset( &action.sa_mask, SIGUSR2 ); + action.sa_flags = 0; + action.sa_handler = sig_handler; + sigaction(SIGUSR1, &action, NULL); + sigaction(SIGUSR2, &action, NULL); +} + +int main(int argc, char** argv) { + if (argc == 2) { + port_name = argv[1]; + } + + printf("Using %s as serial device.\n", port_name); + + char ttybuf[255]; + tty_fd = open_tty(); + if (tty_fd < 0) { + printf("Error opening terminal.\n"); + return(1); + } + + install_sighandler(); + + if (init() < 0) { + printf("Cannot open port.\r\n"); + exit(1); + } + + while (1) { + int n = read(tty_fd, ttybuf, sizeof(ttybuf)); + int i; + + /* check for 0x3 (ctrl-c), clean exit */ + for (i = 0; i < n; i++) { + if (ttybuf[i] == 0x3) { + if (i > 0) { + write_serial_port(ttybuf, i); + } + close_serial_port(); + system("tset -c"); + return 0; + } + + } + write_serial_port(ttybuf,n); + } + + close_serial_port(); + return 0; +} + + diff --git a/msba2/tools/src/serial.c b/msba2/tools/src/serial.c new file mode 100644 index 0000000000..cd51e1cc5c --- /dev/null +++ b/msba2/tools/src/serial.c @@ -0,0 +1,350 @@ +/* + * LPC 2000 Loader, http://www.pjrc.com/arm/lpc2k_pgm + * Copyright (c) 2004, PJRC.COM, LLC, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* 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" + * 4: Output of "gtk-config --cflags" + * 5: Output of "uname -a" + * 6: Version of GTK installed... eg, type: ls -l /lib/libgtk* + * 7: Other info... which linux distribution, version, other software + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef LINUX +#include +#endif + +#include "serial.h" + +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"; + +int open_serial_port(const char *port_name) +{ + int r; + + 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; + } + 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; +} + + +/* if the port can't be opened, try to print as much info as + * possible, so the problem can be resolved (usually permissions) + */ +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"); +} + + + +int write_serial_port(const void *buf, int num) +{ + return(write(port_fd, buf, num)); +} + + +void input_flush_serial_port(void) +{ + tcflush(port_fd, TCIFLUSH); +} + + +int read_serial_port_nb(unsigned char *buf, int bufsize) +{ + 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; +} + +int read_serial_port(unsigned char *buf, int bufsize) +{ + int num; + + num = read(port_fd, buf, bufsize); + + return num; +} + + +void send_break_signal(void) +{ + tcsendbreak(port_fd, 0); +} + + +void close_serial_port(void) +{ + 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; +} + + +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; + //port_setting.c_iflag = IGNBRK | IGNPAR | IXANY | IXON; + port_setting.c_iflag = IGNBRK | IGNPAR; + port_setting.c_cflag = baud | CS8 | CREAD | HUPCL | CLOCAL; + port_setting.c_oflag = 0; + port_setting.c_lflag = 0; + r = tcsetattr(port_fd, TCSAFLUSH, &port_setting); + if (r != 0) return -4; + return 0; +} + + +// Normally this should never be used... except to pass the port +// file descriptor to the GTK event monitoring loop. All other +// use of the serial port is supposed to happen in the file. +int serial_port_fd(void) +{ + 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); +} + + + + + + + +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); +} + + + + + + diff --git a/msba2/tools/src/serial.h b/msba2/tools/src/serial.h new file mode 100644 index 0000000000..4ef9a82e5b --- /dev/null +++ b/msba2/tools/src/serial.h @@ -0,0 +1,19 @@ +#ifndef SERIAL_H +#define SERIAL_H + +extern char* baud_rate; + +int open_serial_port(const char *port_name); +int write_serial_port(const void *buf, int num); +void input_flush_serial_port(void); +int read_serial_port_nb(unsigned char *buf, int bufsize); +int read_serial_port(unsigned char *buf, int bufsize); +void close_serial_port(void); +void send_break_signal(void); +int set_baud(const char *baud_name); +int serial_port_fd(void); +void set_rts(int val); +void set_dtr(int val); +void change_baud(const char *baud_name); + +#endif // SERIAL_H diff --git a/msba2/tools/src/settings.c b/msba2/tools/src/settings.c new file mode 100644 index 0000000000..d52e24a03f --- /dev/null +++ b/msba2/tools/src/settings.c @@ -0,0 +1,172 @@ +/* + * LPC 2000 Loader, http://www.pjrc.com/arm/lpc2k_pgm + * Copyright (c) 2004, PJRC.COM, LLC, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* 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" + * 4: Output of "gtk-config --cflags" + * 5: Output of "uname -a" + * 6: Version of GTK installed... eg, type: ls -l /lib/libgtk* + * 7: Other info... which linux distribution, version, other software + */ + + +#include +#include +#include +#include + +#include "settings.h" + +#define DEFAULT_FILE "" +#define DEFAULT_PORT "/dev/ttyS0" +#define DEFAULT_BAUD "115200" +#define DEFAULT_CRYSTAL "16" + +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 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); + } +} + +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); +} + +const char * file_setting(void) +{ + return file; +} + +const char * port_setting(void) +{ + return port; +} + +const char * baud_setting(void) +{ + return baud; +} + +const char * crystal_setting(void) +{ + 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(); + } +} + +void new_port_setting(const char *new_port) +{ + 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(); + } +} + +void new_crystal_setting(const char *new_xtal) +{ + if (strcmp(crystal, new_xtal)) { + snprintf(crystal, sizeof(crystal), "%s", new_xtal); + write_settings_file(); + } +} + + + + + + diff --git a/msba2/tools/src/settings.h b/msba2/tools/src/settings.h new file mode 100644 index 0000000000..20686821a4 --- /dev/null +++ b/msba2/tools/src/settings.h @@ -0,0 +1,12 @@ + +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 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); +extern void new_crystal_setting(const char *new_xtal); + +extern char *baud_list[]; diff --git a/msba2/tools/src/uuencode.c b/msba2/tools/src/uuencode.c new file mode 100644 index 0000000000..5cc76e796c --- /dev/null +++ b/msba2/tools/src/uuencode.c @@ -0,0 +1,98 @@ +/* + * LPC 2000 Loader, http://www.pjrc.com/arm/lpc2k_pgm + * Copyright (c) 2004, PJRC.COM, LLC, + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +/* 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" + * 4: Output of "gtk-config --cflags" + * 5: Output of "uname -a" + * 6: Version of GTK installed... eg, type: ls -l /lib/libgtk* + * 7: Other info... which linux distribution, version, other software + */ + +#include "uuencode.h" + +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> 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 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; +} + + + diff --git a/msba2/tools/src/uuencode.h b/msba2/tools/src/uuencode.h new file mode 100644 index 0000000000..92fecb7d33 --- /dev/null +++ b/msba2/tools/src/uuencode.h @@ -0,0 +1,3 @@ +extern void uuencode(char *str, const unsigned char *data, int num); +extern int uudecode(const char *str, unsigned char *data, int max); + diff --git a/msba2/tools/termctrl.sh b/msba2/tools/termctrl.sh new file mode 100755 index 0000000000..75e87ab21e --- /dev/null +++ b/msba2/tools/termctrl.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +pid=`pgrep pseudoterm` + +if test "$pid" = "" ; then + + echo " Pseudoterm not running." + +else + + if test "$1" = "continue" ; then + kill -s USR1 $pid; + elif test "$1" = "pause" ; then + kill -s USR2 $pid ; + elif test "$1" = "stop" ; then + kill $pid ; + else + echo "Usage:"; + echo "termctrl.sh continue/pause/stop"; + fi + +fi diff --git a/olimex_lpc2148/Jamfile b/olimex_lpc2148/Jamfile new file mode 100644 index 0000000000..43ad7d1baf --- /dev/null +++ b/olimex_lpc2148/Jamfile @@ -0,0 +1,10 @@ +SubDir TOP board olimex_lpc2148 ; + +CPU = lpc214x ; + +HDRS += $(TOP)/board/olimex_lpc2148/include ; + +Module board : board_init.c debug_uart.c rs232.c ; +UseModule board ; + +SubInclude TOP cpu lpc214x ; diff --git a/olimex_lpc2148/Jamfile.olimex_lpc2148 b/olimex_lpc2148/Jamfile.olimex_lpc2148 new file mode 100644 index 0000000000..057aa7b322 --- /dev/null +++ b/olimex_lpc2148/Jamfile.olimex_lpc2148 @@ -0,0 +1,4 @@ +################## + +include $(TOP)/Jamfile.arm_common ; + diff --git a/olimex_lpc2148/Jamrules.olimex_lpc2148 b/olimex_lpc2148/Jamrules.olimex_lpc2148 new file mode 100644 index 0000000000..7a7086d5bc --- /dev/null +++ b/olimex_lpc2148/Jamrules.olimex_lpc2148 @@ -0,0 +1,9 @@ +############################ + +BOARD = olimex_lpc2148 ; +CPU = lpc214x ; + +GDB = arm-elf-gdb ; +GDBFLAGS = -x board/olimex_lpc2148/tools/lpc2148_flash.gdb ; + +include $(TOP)/Jamrules.arm_common ; diff --git a/olimex_lpc2148/board_init.c b/olimex_lpc2148/board_init.c new file mode 100644 index 0000000000..874feb8812 --- /dev/null +++ b/olimex_lpc2148/board_init.c @@ -0,0 +1,88 @@ +/* + * bl_board_init.c + * + * Created on: 19.08.2008 + * Author: heiko, kaspar + */ + +#include "cpu.h" +#include "bits.h" +#include "VIC.h" + +#define PLOCK 0x400 + +static void feed(void) +{ + 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; +} + + + + +void bl_init_ports(void) +{ + +} + diff --git a/olimex_lpc2148/debug_uart.c b/olimex_lpc2148/debug_uart.c new file mode 100644 index 0000000000..90f5144dfe --- /dev/null +++ b/olimex_lpc2148/debug_uart.c @@ -0,0 +1,14 @@ +#include "lpc214x.h" +#include "bits.h" + +#include "rs232.h" + +void debug_putchar(int character) +{ + UART1WriteChar(character); +} + +void bl_uart_init(void) +{ + UART1Initialize(115200U); +} diff --git a/olimex_lpc2148/include/board.h b/olimex_lpc2148/include/board.h new file mode 100644 index 0000000000..eaf536b005 --- /dev/null +++ b/olimex_lpc2148/include/board.h @@ -0,0 +1 @@ +#include diff --git a/olimex_lpc2148/include/rs232.h b/olimex_lpc2148/include/rs232.h new file mode 100644 index 0000000000..9fe0bf2c87 --- /dev/null +++ b/olimex_lpc2148/include/rs232.h @@ -0,0 +1,40 @@ +//rs232.h +//#include + +#include "lpc214x.h" + +//#define OSCILLATOR_CLOCK_FREQUENCY 14745600 //in MHz +#define OSCILLATOR_CLOCK_FREQUENCY 12000000 //in MHz + +//get real processor clock frequency +unsigned int processorClockFrequency(void); +//get peripheral clock frequency +unsigned int peripheralClockFrequency(void); + +/**** UART0 ****/ +//initialize UART0 interface +void UART0Initialize(unsigned int baud); +//write char to UART0 (RS232); +void UART0WriteChar(int ch0); +//read char from RS232 +unsigned char UART0ReadChar(void); + +//this function read/write char from RS232, +//but they not wait to read/write +unsigned char UART0ReadChar_nostop(void); +void UART0WriteChar_nostop(unsigned char ch0); + + +/**** UART1 ****/ +//initialize UART0 interface +void UART1Initialize(unsigned int baud); +//write char to UART0 (RS232); +void UART1WriteChar(int ch0); +//read char from RS232 +unsigned char UART0ReadChar(void); + +//this function read/write char from RS232, +//but they not wait to read/write +unsigned char UART1ReadChar_nostop(void); +void UART1WriteChar_nostop(unsigned char ch0); + diff --git a/olimex_lpc2148/rs232.c b/olimex_lpc2148/rs232.c new file mode 100644 index 0000000000..43e70a00f2 --- /dev/null +++ b/olimex_lpc2148/rs232.c @@ -0,0 +1,65 @@ +//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 new file mode 100644 index 0000000000..08b3dcb0bb --- /dev/null +++ b/olimex_lpc2148/tick.c @@ -0,0 +1,63 @@ +/* Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will + +This file is part of the Micro-mesh SensorWeb Firmware. + +Micro-Mesh is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +Micro-Mesh is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Micro-Mesh; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "lpc214x.h" +#include "bits.h" +//#include "tick.h" +#include "minimal_dbg_console.h" +#include "VIC.h" + +void Timer0_IRQHandler (void) __attribute__((interrupt("IRQ"))); + +extern void eINT(); +extern void dINT(); + + +void driver_timer_load(void) +{ + T0TCR = 0; // Disable timer 0. + 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; + T0TCR = BIT0; // Enable timer 0. + + dINT(); // Disable all interrupts + VICIntEnable = BIT4; // Enable Interrupthandling for Timer0 + VICVectCntl3 = 4 + BIT5; // Assign Timer0 to IRQ Slot 3 + VICVectAddr3 = (unsigned int)Timer0_IRQHandler; // Assign Isr Address + eINT(); +} + +int counter = 0; + +void Timer0_IRQHandler (void) +{ + extern unsigned int fk_context_switch_request; + counter++; + T0IR |= 0xff; // reset timer1 interrupt flag + sl_printf("#"); + + fk_context_switch_request = 1; + + VICVectAddr = 0; // acknowledge interrupt (if using VIC IRQ) +} + diff --git a/olimex_lpc2148/tools/lpc2148_flash.gdb b/olimex_lpc2148/tools/lpc2148_flash.gdb new file mode 100644 index 0000000000..cb308752ae --- /dev/null +++ b/olimex_lpc2148/tools/lpc2148_flash.gdb @@ -0,0 +1,22 @@ +#winheight regs 11 +set history save on +set history size 1000 +target remote localhost:3333 +monitor reset +monitor sleep 100 +monitor halt +monitor poll +#monitor arm7_9 sw_bkpts disable +#monitor arm7_9 force_hw_bkpts enable +monitor mww 0xE01FC040 0x0001 +monitor mdw 0xE01FC040 +monitor flash erase_sector 0 0 14 +#monitor flash auto_erase on +monitor flash erase_check 0 +#monitor flash write_image /home/kaspar/FeuerWhere/src/x/bin/arm.elf +set remote hardware-watchpoint-limit 2 +load +break bootloader +mon soft_reset_halt +continue +d b 1 diff --git a/pttu/Jamfile b/pttu/Jamfile new file mode 100644 index 0000000000..a7b4d6df11 --- /dev/null +++ b/pttu/Jamfile @@ -0,0 +1,35 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id: Jamfile 922 2009-03-26 12:52:27Z baar $ + +SubDir TOP board pttu ; + +Module board : board_init.c ; +UseModule board ; +UseModule board_common ; + +SubInclude TOP board $(BOARD) drivers ; +SubInclude TOP cpu $(CPU) ; diff --git a/pttu/Jamfile.pttu b/pttu/Jamfile.pttu new file mode 100644 index 0000000000..1bce8934fe --- /dev/null +++ b/pttu/Jamfile.pttu @@ -0,0 +1,28 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id: Jamfile.msba2 832 2009-03-13 16:45:41Z kaspar $ + +include [ FPath $(TOP) cpu arm_common Jamfile.arm_common ] ; diff --git a/pttu/Jamrules.pttu b/pttu/Jamrules.pttu new file mode 100644 index 0000000000..7eff15f0bb --- /dev/null +++ b/pttu/Jamrules.pttu @@ -0,0 +1,37 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id: Jamrules.msba2 881 2009-03-20 12:24:58Z kaspar $ + +CPU = lpc2387 ; + +HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; + +FLASHER = $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; +FLASHFLAGS = --basedir $(TOP)/board/msba2/tools --id PTTU --ports "$(PORT)" --openocd $(TOP)/board/pttu/tools/openocd-pttu.sh --openocd-if $(OPENOCD_IF) ; + +GDB = arm-elf-gdb ; +GDBFLAGS = -x board/pttu/tools/pttu_debug.gdb ; + diff --git a/pttu/board_init.c b/pttu/board_init.c new file mode 100644 index 0000000000..3070bdfce7 --- /dev/null +++ b/pttu/board_init.c @@ -0,0 +1,239 @@ +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/** + * @ingroup pttu + * @{ + */ + +/** + * @file + * @brief PTTU board initialization + * + * @author Freie Universit�t Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Kaspar Schleise + * @author Michael Baar + * + * @note $Id: cmdengine-out.c 971 2009-04-07 13:41:36Z baar $ + */ +#include "lpc23xx.h" +#include "VIC.h" +#include "cpu.h" + +#define PCRTC BIT9 +#define CL_CPU_DIV 4 + +/*---------------------------------------------------------------------------*/ +/** + * @brief Enabling MAM and setting number of clocks used for Flash memory fetch + * @internal + */ +void +init_mam(void) +{ + MAMCR = 0x0000; + MAMTIM = 0x0003; + MAMCR = 0x0002; +} +/*---------------------------------------------------------------------------*/ +static inline void +pllfeed(void) +{ + PLLFEED = 0xAA; + PLLFEED = 0x55; +} +/*---------------------------------------------------------------------------*/ +void init_clks1(void) +{ + // Disconnect PLL + PLLCON &= ~0x0002; + pllfeed(); + + // Disable PLL + PLLCON &= ~0x0001; + pllfeed(); + + SCS |= 0x20; // Enable main OSC + while( !(SCS & 0x40) ); // Wait until main OSC is usable + + /* select main OSC, 16MHz, as the PLL clock source */ + CLKSRCSEL = 0x0001; + + // Setting Multiplier and Divider values + PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz + pllfeed(); + + // Enabling the PLL */ + PLLCON = 0x0001; + pllfeed(); + + /* Set clock divider to 4 (value+1) */ + CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz + +#if USE_USB + USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ +#endif +} + +void init_clks2(void){ + // Wait for the PLL to lock to set frequency + while(!(PLLSTAT & BIT26)); + + // Connect the PLL as the clock source + PLLCON = 0x0003; + pllfeed(); + + /* Check connect bit status */ + while (!(PLLSTAT & BIT25)); +} + +void bl_init_clks(void) +{ + PCONP = PCRTC; // switch off everything except RTC + init_clks1(); + init_clks2(); + init_mam(); +} + + +// Michael, Do not change anything here! even not the redundant parts! +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; +} + +/** @} */ diff --git a/pttu/drivers/Jamfile b/pttu/drivers/Jamfile new file mode 100644 index 0000000000..26a8b7c2af --- /dev/null +++ b/pttu/drivers/Jamfile @@ -0,0 +1,4 @@ +SubDir TOP board pttu drivers ; + +Module board_common : pttu-uart0.c ; + diff --git a/pttu/drivers/pttu-uart0.c b/pttu/drivers/pttu-uart0.c new file mode 100644 index 0000000000..d542f22602 --- /dev/null +++ b/pttu/drivers/pttu-uart0.c @@ -0,0 +1,204 @@ +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/* + * debug_uart.c: provides initial serial debug output + * + * Copyright (C) 2008, 2009 Kaspar Schleiser + * Heiko Will + */ +#include +#include +#include +#include "lpc23xx.h" +#include "VIC.h" + +/** + * @file + * @ingroup lpc2387 + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @version $Revision$ + * + * @note $Id$ + */ + +typedef struct toprint { + unsigned int len; + char content[]; +}toprint; + +#define QUEUESIZE 255 +static volatile toprint* queue[QUEUESIZE]; +static volatile unsigned char queue_head = 0; +static volatile unsigned char queue_tail = 0; +static volatile unsigned char queue_items = 0; + +static volatile unsigned int actual_pos = 0; +static volatile unsigned int running = 0; +static volatile unsigned int fifo = 0; + +static volatile toprint* actual = NULL; +void (*uart0_callback)(int); + +static inline void enqueue(void) { + queue_items++; + queue_tail++; +} + +static inline void dequeue(void) { + actual = (queue[queue_head]); + queue_items--; + queue_head++; +} + +static void push_queue(void) { + running = 1; +start: + if (!actual) { + if (queue_items) { + dequeue(); + } else { + running = 0; + if (!fifo) + while(!(U0LSR & BIT6)){}; + return; + } + } + while ((actual_pos < actual->len) && (fifo++ < 16)){ + U0THR = actual->content[actual_pos++]; + } + if (actual_pos == actual->len) { + free((void*)actual); + actual = NULL; + actual_pos = 0; + goto start; + } +} + +int uart_active(void){ + return (running || fifo); +} + +static inline void receive(int c) +{ + if (uart0_callback != NULL) uart0_callback(c); +} + +void stdio_flush(void) +{ + 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 +} + +void UART0_IRQHandler(void) __attribute__((interrupt("IRQ"))); +void UART0_IRQHandler(void) +{ + int iir; + iir = U0IIR; + + switch(iir & UIIR_ID_MASK) { + case UIIR_THRE_INT: // Transmit Holding Register Empty + fifo=0; + push_queue(); + break; + + case UIIR_CTI_INT: // Character Timeout Indicator + case UIIR_RDA_INT: // Receive Data Available + do { + int c = U0RBR; + receive(c); + } while (U0LSR & ULSR_RDR); + break; + + default: + U0LSR; + U0RBR; + break; + } // switch + VICVectAddr = 0; // Acknowledge Interrupt +} + +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 + + // alternative without queue: +// int i; +// for (i=0;iconfig->speed + /* + * Baudrate calculation + * BR = PCLK (9 MHz) / (16 x 256 x DLM + DLL) x (1/(DIVADDVAL/MULVAL)) + */ + U0FDR = 0x92; // DIVADDVAL = 0010 = 2, MULVAL = 1001 = 9 + U0DLM = 0x00; + U0DLL = 0x04; + + U0LCR = 0x03; // DLAB = 0 + U0FCR = 0x07; // Enable and reset TX and RX FIFO + + /* irq */ + install_irq(UART0_INT, UART0_IRQHandler, 6); + U0IER |= BIT0 | BIT1; // enable RX+TX irq + return 1; +} + diff --git a/pttu/include/board.h b/pttu/include/board.h new file mode 100644 index 0000000000..850f8d1d17 --- /dev/null +++ b/pttu/include/board.h @@ -0,0 +1,56 @@ +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef __BOARD_H +#define __BOARD_H + +/** + * @ingroup pttu + * @{ + */ + +/** + * @file + * @brief PTTU Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Kaspar Schleiser + * @version $Revision$ + * + * @note $Id: board.h 664 2009-02-19 10:54:44Z baar $ + */ + +#include +#include + +#define VICIntEnClear VICIntEnClr + +void init_clks1(void); +void init_clks2(void); +void bl_init_clks(void); + +/** @} */ +#endif // __BOARD_H diff --git a/pttu/tools/jtag.txt b/pttu/tools/jtag.txt new file mode 100644 index 0000000000..586eea6745 --- /dev/null +++ b/pttu/tools/jtag.txt @@ -0,0 +1,14 @@ +compile openocd release v0.1: +[extract to somewhere] +./configure --prefix=CHANGEMEtowhatever --enable-ft2232_libftdi +make +make install + +to flash run from within board/pttu/tools: +./openocd-pttu.sh olimex-usb-jtag-tiny-a "mt_flash CHANGEME/absolute/path/to/hexfile/pttu.hex;shutdown" + + +to debug, first start the following from within board/pttu/tools: +./openocd-pttu.sh olimex-usb-jtag-tiny-a + +then just run "jam debug". this will flash bin/pttu.hex, run it and stop at the bootloader. diff --git a/pttu/tools/olimex-arm-usb-ocd.cfg b/pttu/tools/olimex-arm-usb-ocd.cfg new file mode 100644 index 0000000000..0aaba1d2bb --- /dev/null +++ b/pttu/tools/olimex-arm-usb-ocd.cfg @@ -0,0 +1,9 @@ +# +set CPUTAPID 0x4f1f0f0f + +jtag_speed 100 + +source [find interface/olimex-arm-usb-ocd.cfg] +#source [find target/lpc2148.cfg] +source lpc2378.cfg + diff --git a/pttu/tools/openocd-pttu.cfg b/pttu/tools/openocd-pttu.cfg new file mode 100644 index 0000000000..b58392f1ee --- /dev/null +++ b/pttu/tools/openocd-pttu.cfg @@ -0,0 +1,75 @@ +###### +# parts taken from Martin Thomas +# http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/openocd_intro/index.html +# + +set CPUTAPID 0x4f1f0f0f +jtag_speed 100 + +source [find cpu/lpc2387/tools/openocd-lpc2387.cfg] + +fast disable + +# +# scipts/macros/user commands - this is TCL (variant JIM): +# +proc mt_internal_rc {} { + jtag_khz 100 + reset run + sleep 100 + reset + halt + wait_halt 2 + # PLL disconnect PLLCON + mww 0xE01FC080 0x01 + mww 0xE01FC08C 0xAA + mww 0xE01FC08C 0x55 + # PLL disable PLLCON + mww 0xE01FC080 0x00 + mww 0xE01FC08C 0xAA + mww 0xE01FC08C 0x55 + # no prescaler CCLKCFG + mww 0xE01FC104 0x00 + # internal RC CLKSRCSEL + mww 0xE01FC10C 0x00 + #### main oscil. CLKSRCSEL + #### mww 0xE01FC10C 0x01 + # remap to internal flash + mww 0xE01FC040 0x01 + sleep 100 + jtag_khz 500 + flash probe 0 +} + +proc mt_flash_bin {IMGFILE OFFSET} { + mt_internal_rc + flash write_image erase $IMGFILE $OFFSET + sleep 100 + verify_image $IMGFILE $OFFSET + sleep 100 +} + +proc mt_flash_v {IMGFILE} { + mt_internal_rc + flash write_image erase $IMGFILE + sleep 100 + verify_image $IMGFILE + sleep 100 +} + +proc mt_flash {IMGFILE} { + mt_internal_rc + flash write_image erase $IMGFILE +} + +flash bank lpc2000 0x0 0x7d000 0 0 0 lpc2000_v2 4000 calc_checksum + +arm7_9 dcc_downloads enable + +gdb_flash_program enable + +init + +fast enable +jtag_khz 500 +debug_level 1 diff --git a/pttu/tools/openocd-pttu.sh b/pttu/tools/openocd-pttu.sh new file mode 100755 index 0000000000..95f11fa148 --- /dev/null +++ b/pttu/tools/openocd-pttu.sh @@ -0,0 +1,30 @@ +#/bin/bash + +if [ $# -le 0 ]; then + echo "usage: $0 [openocd interface name] [openocd args]" >&2 + echo " common interfaces: olimex-arm-usb-ocd olimex-jtag-tiny olimex-jtag-tiny-a" + echo "" + echo "using default olimex-jtag-tiny-a" + INTERFACE=olimex-jtag-tiny-a +else + INTERFACE=$1 + shift +fi + +if [ $# -ge 1 ]; then + COMMAND=$@ +else + COMMAND="debug_level 1" +fi + +if [ "${OS}" = "Windows_NT" ]; then + WINDOWS=1 +fi + +if [ "x${WINDOWS}x" = "xx" ]; then + xterm -e "openocd -s ../../.. -f interface/${INTERFACE}.cfg -f board/pttu/tools/openocd-pttu.cfg -c \"${COMMAND}\"|| read" & +else + echo ${COMMAND} + #cmd /C start "OpenOCD PTTU using ${INTERFACE}" + openocd-ftd2xx.exe -s ../../.. -f interface/${INTERFACE}.cfg -f board/pttu/tools/openocd-pttu.cfg -c "${COMMAND}" +fi diff --git a/pttu/tools/pttu_debug.gdb b/pttu/tools/pttu_debug.gdb new file mode 100644 index 0000000000..2c8ec0df14 --- /dev/null +++ b/pttu/tools/pttu_debug.gdb @@ -0,0 +1,15 @@ +#winheight regs 11 +set history save on +set history size 1000 +target remote localhost:3333 +monitor mt_internal_rc +load +compare-sections +monitor soft_reset_halt +set mem inaccessible-by-default off +monitor debug_level 0 + +break bootloader +continue +d b 1 + From e9d283d090e5178d3444c1ff07718f15fa31a375 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 24 Sep 2010 14:42:50 +0200 Subject: [PATCH 002/188] * line ending change --- msba2/drivers/msba2-uart0.c | 421 ++++++++++++++++++------------------ 1 file changed, 216 insertions(+), 205 deletions(-) diff --git a/msba2/drivers/msba2-uart0.c b/msba2/drivers/msba2-uart0.c index 01aaf609dc..71c35854af 100644 --- a/msba2/drivers/msba2-uart0.c +++ b/msba2/drivers/msba2-uart0.c @@ -1,205 +1,216 @@ -/****************************************************************************** -Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. - -These sources were developed at the Freie Universitaet Berlin, Computer Systems -and Telematics group (http://cst.mi.fu-berlin.de). -------------------------------------------------------------------------------- -This file is part of FeuerWare. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -FeuerWare is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see http://www.gnu.org/licenses/ . --------------------------------------------------------------------------------- -For further information and questions please use the web site - http://scatterweb.mi.fu-berlin.de -and the mailinglist (subscription via web site) - scatterweb@lists.spline.inf.fu-berlin.de -*******************************************************************************/ - -/* - * debug_uart.c: provides initial serial debug output - * - * Copyright (C) 2008, 2009 Kaspar Schleiser - * Heiko Will - */ -#include -#include -#include -#include "lpc23xx.h" -#include "VIC.h" - -/** - * @file - * @ingroup lpc2387 - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @version $Revision$ - * - * @note $Id$ - */ - -typedef struct toprint { - unsigned int len; - char content[]; -}toprint; - -#define QUEUESIZE 255 -static volatile toprint* queue[QUEUESIZE]; -static volatile unsigned char queue_head = 0; -static volatile unsigned char queue_tail = 0; -static volatile unsigned char queue_items = 0; - -static volatile unsigned int actual_pos = 0; -static volatile unsigned int running = 0; -static volatile unsigned int fifo = 0; - -static volatile toprint* actual = NULL; -void (*uart0_callback)(int); - -static inline void enqueue(void) { - queue_items++; - queue_tail++; -} - -static inline void dequeue(void) { - actual = (queue[queue_head]); - queue_items--; - queue_head++; -} - -static void push_queue(void) { - running = 1; -start: - if (!actual) { - if (queue_items) { - dequeue(); - } else { - running = 0; - if (!fifo) - while(!(U0LSR & BIT6)){}; - return; - } - } - while ((actual_pos < actual->len) && (fifo++ < 16)){ - U0THR = actual->content[actual_pos++]; - } - if (actual_pos == actual->len) { - free((void*)actual); - actual = NULL; - actual_pos = 0; - goto start; - } -} - -int uart_active(void){ - return (running || fifo); -} - -static inline void receive(int c) -{ - if (uart0_callback != NULL) uart0_callback(c); -} - -void stdio_flush(void) -{ - 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 -} - -void UART0_IRQHandler(void) __attribute__((interrupt("IRQ"))); -void UART0_IRQHandler(void) -{ - int iir; - iir = U0IIR; - - switch(iir & UIIR_ID_MASK) { - case UIIR_THRE_INT: // Transmit Holding Register Empty - fifo=0; - push_queue(); - break; - - case UIIR_CTI_INT: // Character Timeout Indicator - case UIIR_RDA_INT: // Receive Data Available - do { - int c = U0RBR; - receive(c); - } while (U0LSR & ULSR_RDR); - break; - - default: - U0LSR; - U0RBR; - break; - } // switch - VICVectAddr = 0; // Acknowledge Interrupt -} - -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 - - /* alternative without queue: - int i; - for (i=0;iconfig->speed - /* - * Baudrate calculation - * BR = PCLK (9 MHz) / (16 x 256 x DLM + DLL) x (1/(DIVADDVAL/MULVAL)) - */ - U0FDR = 0x92; // DIVADDVAL = 0010 = 2, MULVAL = 1001 = 9 - U0DLM = 0x00; - U0DLL = 0x04; - - U0LCR = 0x03; // DLAB = 0 - U0FCR = 0x07; // Enable and reset TX and RX FIFO - - /* irq */ - install_irq(UART0_INT, UART0_IRQHandler, 6); - U0IER |= BIT0 | BIT1; // enable RX+TX irq - return 1; -} - +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/* + * debug_uart.c: provides initial serial debug output + * + * Copyright (C) 2008, 2009 Kaspar Schleiser + * Heiko Will + */ +#include +#include +#include +#include "lpc23xx.h" +#include "VIC.h" + +#include +#include +#include "uart0.h" + +/** + * @file + * @ingroup lpc2387 + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @version $Revision$ + * + * @note $Id$ + */ + +typedef struct toprint { + unsigned int len; + char content[]; +}toprint; + +#define QUEUESIZE 255 +static volatile toprint* queue[QUEUESIZE]; +static volatile unsigned char queue_head = 0; +static volatile unsigned char queue_tail = 0; +static volatile unsigned char queue_items = 0; + +static volatile unsigned int actual_pos = 0; +static volatile unsigned int running = 0; +static volatile unsigned int fifo = 0; + +static volatile toprint* actual = NULL; + +int uart0_handler_pid = 0; +extern ringbuffer uart0_ringbuffer; + +static inline void enqueue(void) { + queue_items++; + queue_tail++; +} + +static inline void dequeue(void) { + actual = (queue[queue_head]); + queue_items--; + queue_head++; +} + +static void push_queue(void) { + running = 1; +start: + if (!actual) { + if (queue_items) { + dequeue(); + } else { + running = 0; + if (!fifo) + while(!(U0LSR & BIT6)){}; + return; + } + } + while ((actual_pos < actual->len) && (fifo++ < 16)){ + U0THR = actual->content[actual_pos++]; + } + if (actual_pos == actual->len) { + free((void*)actual); + actual = NULL; + actual_pos = 0; + goto start; + } +} + +int uart_active(void){ + return (running || fifo); +} + +static void notify_handler() { + if (uart0_handler_pid) { + msg m; + m.type = 0; + msg_send_int(&m, uart0_handler_pid); + } +} + +void stdio_flush(void) +{ + 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 +} + +void UART0_IRQHandler(void) __attribute__((interrupt("IRQ"))); +void UART0_IRQHandler(void) +{ + int iir; + iir = U0IIR; + + switch(iir & UIIR_ID_MASK) { + case UIIR_THRE_INT: // Transmit Holding Register Empty + fifo=0; + push_queue(); + break; + + case UIIR_CTI_INT: // Character Timeout Indicator + case UIIR_RDA_INT: // Receive Data Available + do { + int c = U0RBR; + rb_add_element(&uart0_ringbuffer, c); + } while (U0LSR & ULSR_RDR); + + notify_handler(); + break; + + default: + U0LSR; + U0RBR; + break; + } // switch + VICVectAddr = 0; // Acknowledge Interrupt +} + +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 + + /* alternative without queue: + int i; + for (i=0;iconfig->speed + /* + * Baudrate calculation + * BR = PCLK (9 MHz) / (16 x 256 x DLM + DLL) x (1/(DIVADDVAL/MULVAL)) + */ + U0FDR = 0x92; // DIVADDVAL = 0010 = 2, MULVAL = 1001 = 9 + U0DLM = 0x00; + U0DLL = 0x04; + + U0LCR = 0x03; // DLAB = 0 + U0FCR = 0x07; // Enable and reset TX and RX FIFO + + /* irq */ + install_irq(UART0_INT, UART0_IRQHandler, 6); + U0IER |= BIT0 | BIT1; // enable RX+TX irq + return 1; +} + From 19f5c85eea3ef811d0e37f3c7e6b4ba909a22329 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 24 Sep 2010 16:28:34 +0200 Subject: [PATCH 003/188] * initial posix_io support --- msba2/drivers/Jamfile | 2 +- msba2/drivers/include/uart0.h | 8 +++ msba2/drivers/msba2-uart0_thread.c | 101 +++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 msba2/drivers/include/uart0.h create mode 100644 msba2/drivers/msba2-uart0_thread.c diff --git a/msba2/drivers/Jamfile b/msba2/drivers/Jamfile index 79705aca0a..f7b223ce01 100644 --- a/msba2/drivers/Jamfile +++ b/msba2/drivers/Jamfile @@ -3,4 +3,4 @@ SubDir TOP board msba2 drivers ; Module board_cc1100 : msba2-cc1100.c ; Module board_hal : msba2-hal.c ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; -Module board_common : msba2-uart0.c ; +Module board_common : msba2-uart0.c msba2-uart0_thread.c : ringbuffer ; diff --git a/msba2/drivers/include/uart0.h b/msba2/drivers/include/uart0.h new file mode 100644 index 0000000000..0c580becc2 --- /dev/null +++ b/msba2/drivers/include/uart0.h @@ -0,0 +1,8 @@ +#ifndef __UART0_H +#define __UART0_H + +#define UART0_BUFSIZE 32 + +extern int uart0_handler_pid; + +#endif /* __UART0_H */ diff --git a/msba2/drivers/msba2-uart0_thread.c b/msba2/drivers/msba2-uart0_thread.c new file mode 100644 index 0000000000..c9c34c23d7 --- /dev/null +++ b/msba2/drivers/msba2-uart0_thread.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include "uart0.h" + +//#define ENABLE_DEBUG +#include + +static char buffer[UART0_BUFSIZE]; +ringbuffer uart0_ringbuffer; + +static void uart0_loop(); + +void uart0_init() { + ringbuffer_init(&uart0_ringbuffer, buffer, UART0_BUFSIZE); + int pid = thread_create(KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); + uart0_handler_pid = pid; + puts("uart0_init() [OK]"); +} + +static int min(int a, int b) { + if (b>a) return a; + else return b; +} + +static void uart0_loop() { + msg m; + + int pid = thread_getpid(); + + int reader_pid = -1; + struct posix_iop *r = NULL; + + puts("UART0 thread started."); + + while (1) { + msg_receive(&m); + + if (m.sender_pid == pid) { + } else { + switch (m.type) { + case OPEN: + if (reader_pid == -1) { + reader_pid = m.sender_pid; + m.content.value = 0; // no error + } else { + m.content.value = -EBUSY; + } + msg_reply(&m,&m); + break; + case READ: + if (m.sender_pid != reader_pid) { + m.content.value = -EINVAL; + msg_reply(&m, &m); + } else { + r = (struct posix_iop *)m.content.ptr; + } + break; + case CLOSE: + if (m.sender_pid == reader_pid) { + DEBUG("uart0_thread: closing file from %i\n", reader_pid); + reader_pid = -1; + r = NULL; + m.content.value = 0; + } else { + m.content.value = -EINVAL; + } + msg_reply(&m,&m); + break; + default: + m.content.value = -EINVAL; + msg_reply(&m, &m); + } + } + + if (uart0_ringbuffer.avail && (r != NULL)) { + int state = disableIRQ(); + int nbytes = min(r->nbytes, uart0_ringbuffer.avail); + DEBUG("uart0_thread: sending %i bytes to pid %i\n", nbytes, reader_pid); + rb_get_elements(&uart0_ringbuffer, r->buffer, nbytes); + r->nbytes = nbytes; + + m.sender_pid = reader_pid; + m.type = OPEN; + m.content.ptr = (char*)r; + + msg_reply(&m, &m); + // DEBUG("uart0_thread: sending res=%i\n", res); + + r = NULL; + restoreIRQ(state); + } + } +} From 8fb55fc0f7840d2cc5435b3480299d71907a0f1a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 28 Sep 2010 17:18:57 +0200 Subject: [PATCH 004/188] * make flasher options optional for msba2 --- msba2/Jamrules.msba2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msba2/Jamrules.msba2 b/msba2/Jamrules.msba2 index fdcf4b6f65..5111de74d3 100644 --- a/msba2/Jamrules.msba2 +++ b/msba2/Jamrules.msba2 @@ -29,5 +29,5 @@ CPU = lpc2387 ; HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; -FLASHER = $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; -FLASHFLAGS = --basedir $(TOP)/board/msba2/tools --id "MSB-A2" --ports "$(PORT)" ; +FLASHER ?= $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; +FLASHFLAGS ?= --basedir $(TOP)/board/msba2/tools --id "MSB-A2" --ports "$(PORT)" ; From 4941f01946cfd2c9cebe77563414c5f9e226bf53 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 28 Sep 2010 17:46:55 +0200 Subject: [PATCH 005/188] * minor doc change --- msba2/board_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msba2/board_init.c b/msba2/board_init.c index d12cc4058e..44c6cc33a3 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -25,7 +25,7 @@ and the mailinglist (subscription via web site) *******************************************************************************/ /** - * @ingroup pttu + * @ingroup msba2 * @{ */ From d3f396219085f2318ffff1187023786bc9fef977 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 30 Sep 2010 15:10:39 +0200 Subject: [PATCH 006/188] * refactored uart / chardev handling --- msba2/drivers/Jamfile | 3 +- msba2/drivers/msba2-uart0.c | 23 ++++--- msba2/drivers/msba2-uart0_thread.c | 100 ++++------------------------- 3 files changed, 25 insertions(+), 101 deletions(-) diff --git a/msba2/drivers/Jamfile b/msba2/drivers/Jamfile index f7b223ce01..4961670ed8 100644 --- a/msba2/drivers/Jamfile +++ b/msba2/drivers/Jamfile @@ -3,4 +3,5 @@ SubDir TOP board msba2 drivers ; Module board_cc1100 : msba2-cc1100.c ; Module board_hal : msba2-hal.c ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; -Module board_common : msba2-uart0.c msba2-uart0_thread.c : ringbuffer ; +Module board_common : msba2-uart0.c : ringbuffer ; +Module board_uart : msba2-uart0_thread.c : chardev_thread ; diff --git a/msba2/drivers/msba2-uart0.c b/msba2/drivers/msba2-uart0.c index 71c35854af..fcd21fcd82 100644 --- a/msba2/drivers/msba2-uart0.c +++ b/msba2/drivers/msba2-uart0.c @@ -110,11 +110,9 @@ int uart_active(void){ } static void notify_handler() { - if (uart0_handler_pid) { - msg m; - m.type = 0; - msg_send_int(&m, uart0_handler_pid); - } + msg m; + m.type = 0; + msg_send_int(&m, uart0_handler_pid); } void stdio_flush(void) @@ -142,14 +140,15 @@ void UART0_IRQHandler(void) case UIIR_CTI_INT: // Character Timeout Indicator case UIIR_RDA_INT: // Receive Data Available - do { - int c = U0RBR; - rb_add_element(&uart0_ringbuffer, c); - } while (U0LSR & ULSR_RDR); - - notify_handler(); - break; + if (uart0_handler_pid) { + do { + int c = U0RBR; + rb_add_element(&uart0_ringbuffer, c); + } while (U0LSR & ULSR_RDR); + notify_handler(); + break; + } default: U0LSR; U0RBR; diff --git a/msba2/drivers/msba2-uart0_thread.c b/msba2/drivers/msba2-uart0_thread.c index c9c34c23d7..f343e32401 100644 --- a/msba2/drivers/msba2-uart0_thread.c +++ b/msba2/drivers/msba2-uart0_thread.c @@ -1,101 +1,25 @@ -#include -#include -#include -#include +#include #include - #include -#include -#include -#include -#include "uart0.h" +#include -//#define ENABLE_DEBUG -#include +#include + +#define UART0_BUFSIZE 32 + +extern ringbuffer uart0_ringbuffer; +extern int uart0_handler_pid; static char buffer[UART0_BUFSIZE]; -ringbuffer uart0_ringbuffer; -static void uart0_loop(); +static void uart0_loop() { + chardev_loop(&uart0_ringbuffer); +} -void uart0_init() { +void board_uart0_init() { ringbuffer_init(&uart0_ringbuffer, buffer, UART0_BUFSIZE); int pid = thread_create(KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); uart0_handler_pid = pid; puts("uart0_init() [OK]"); } -static int min(int a, int b) { - if (b>a) return a; - else return b; -} - -static void uart0_loop() { - msg m; - - int pid = thread_getpid(); - - int reader_pid = -1; - struct posix_iop *r = NULL; - - puts("UART0 thread started."); - - while (1) { - msg_receive(&m); - - if (m.sender_pid == pid) { - } else { - switch (m.type) { - case OPEN: - if (reader_pid == -1) { - reader_pid = m.sender_pid; - m.content.value = 0; // no error - } else { - m.content.value = -EBUSY; - } - msg_reply(&m,&m); - break; - case READ: - if (m.sender_pid != reader_pid) { - m.content.value = -EINVAL; - msg_reply(&m, &m); - } else { - r = (struct posix_iop *)m.content.ptr; - } - break; - case CLOSE: - if (m.sender_pid == reader_pid) { - DEBUG("uart0_thread: closing file from %i\n", reader_pid); - reader_pid = -1; - r = NULL; - m.content.value = 0; - } else { - m.content.value = -EINVAL; - } - msg_reply(&m,&m); - break; - default: - m.content.value = -EINVAL; - msg_reply(&m, &m); - } - } - - if (uart0_ringbuffer.avail && (r != NULL)) { - int state = disableIRQ(); - int nbytes = min(r->nbytes, uart0_ringbuffer.avail); - DEBUG("uart0_thread: sending %i bytes to pid %i\n", nbytes, reader_pid); - rb_get_elements(&uart0_ringbuffer, r->buffer, nbytes); - r->nbytes = nbytes; - - m.sender_pid = reader_pid; - m.type = OPEN; - m.content.ptr = (char*)r; - - msg_reply(&m, &m); - // DEBUG("uart0_thread: sending res=%i\n", res); - - r = NULL; - restoreIRQ(state); - } - } -} From fa207088b2f6355d3b81611775ba9a74b26445aa Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 30 Sep 2010 15:12:51 +0200 Subject: [PATCH 007/188] * fix module dependency --- msba2/drivers/Jamfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msba2/drivers/Jamfile b/msba2/drivers/Jamfile index 4961670ed8..0b750d9474 100644 --- a/msba2/drivers/Jamfile +++ b/msba2/drivers/Jamfile @@ -4,4 +4,4 @@ Module board_cc1100 : msba2-cc1100.c ; Module board_hal : msba2-hal.c ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; Module board_common : msba2-uart0.c : ringbuffer ; -Module board_uart : msba2-uart0_thread.c : chardev_thread ; +Module board_uart : msba2-uart0_thread.c : chardev_thread ringbuffer ; From 74014d04089ecd793f79e8f9adda0437c94f0a63 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 30 Sep 2010 16:07:31 +0200 Subject: [PATCH 008/188] * build fixes --- msba2/drivers/msba2-uart0.c | 22 ++++++---------------- msba2/drivers/msba2-uart0_thread.c | 25 ------------------------- 2 files changed, 6 insertions(+), 41 deletions(-) delete mode 100644 msba2/drivers/msba2-uart0_thread.c diff --git a/msba2/drivers/msba2-uart0.c b/msba2/drivers/msba2-uart0.c index fcd21fcd82..9198f50bb2 100644 --- a/msba2/drivers/msba2-uart0.c +++ b/msba2/drivers/msba2-uart0.c @@ -36,9 +36,7 @@ and the mailinglist (subscription via web site) #include "lpc23xx.h" #include "VIC.h" -#include -#include -#include "uart0.h" +#include /** * @file @@ -67,9 +65,6 @@ static volatile unsigned int fifo = 0; static volatile toprint* actual = NULL; -int uart0_handler_pid = 0; -extern ringbuffer uart0_ringbuffer; - static inline void enqueue(void) { queue_items++; queue_tail++; @@ -109,12 +104,6 @@ int uart_active(void){ return (running || fifo); } -static void notify_handler() { - msg m; - m.type = 0; - msg_send_int(&m, uart0_handler_pid); -} - void stdio_flush(void) { U0IER &= ~BIT1; // disable THRE interrupt @@ -140,15 +129,16 @@ void UART0_IRQHandler(void) case UIIR_CTI_INT: // Character Timeout Indicator case UIIR_RDA_INT: // Receive Data Available +#ifdef MODULE_UART0 if (uart0_handler_pid) { do { int c = U0RBR; - rb_add_element(&uart0_ringbuffer, c); + uart0_handle_incoming(c); } while (U0LSR & ULSR_RDR); - - notify_handler(); - break; + uart0_notify_thread(); } +#endif + break; default: U0LSR; U0RBR; diff --git a/msba2/drivers/msba2-uart0_thread.c b/msba2/drivers/msba2-uart0_thread.c deleted file mode 100644 index f343e32401..0000000000 --- a/msba2/drivers/msba2-uart0_thread.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -#include - -#include - -#define UART0_BUFSIZE 32 - -extern ringbuffer uart0_ringbuffer; -extern int uart0_handler_pid; - -static char buffer[UART0_BUFSIZE]; - -static void uart0_loop() { - chardev_loop(&uart0_ringbuffer); -} - -void board_uart0_init() { - ringbuffer_init(&uart0_ringbuffer, buffer, UART0_BUFSIZE); - int pid = thread_create(KERNEL_CONF_STACKSIZE_MAIN, PRIORITY_MAIN-1, CREATE_STACKTEST, uart0_loop, "uart0"); - uart0_handler_pid = pid; - puts("uart0_init() [OK]"); -} - From 44393dc3c5ddc043706fa7ad9b9e13d536cc1133 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 11 Oct 2010 17:05:40 +0200 Subject: [PATCH 009/188] * added msb-430 support, split msb-430 and 430h common stuff out --- msb-430-common/Jamfile | 33 +++++++++++ msb-430-common/Jamrules.msb-430-common | 36 ++++++++++++ {msb-430h => msb-430-common}/board_init.c | 0 {msb-430h => msb-430-common}/debug_uart.c | 0 msb-430/Jamfile | 32 +++++++++++ msb-430/Jamrules.msb-430 | 3 + msb-430/include/board.h | 69 +++++++++++++++++++++++ msb-430h/Jamfile | 5 +- msb-430h/Jamrules.msb-430h | 36 +----------- 9 files changed, 176 insertions(+), 38 deletions(-) create mode 100644 msb-430-common/Jamfile create mode 100644 msb-430-common/Jamrules.msb-430-common rename {msb-430h => msb-430-common}/board_init.c (100%) rename {msb-430h => msb-430-common}/debug_uart.c (100%) create mode 100644 msb-430/Jamfile create mode 100644 msb-430/Jamrules.msb-430 create mode 100644 msb-430/include/board.h diff --git a/msb-430-common/Jamfile b/msb-430-common/Jamfile new file mode 100644 index 0000000000..97c2be0f30 --- /dev/null +++ b/msb-430-common/Jamfile @@ -0,0 +1,33 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +SubDir TOP board msb-430-common ; + +Module board : board_init.c debug_uart.c ; +UseModule board ; + +SubInclude TOP cpu $(CPU) ; diff --git a/msb-430-common/Jamrules.msb-430-common b/msb-430-common/Jamrules.msb-430-common new file mode 100644 index 0000000000..db12fc6763 --- /dev/null +++ b/msb-430-common/Jamrules.msb-430-common @@ -0,0 +1,36 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +CPU = msp430 ; +MCU = msp430x1612 ; + +FLASH_PORT ?= /dev/ttyUSB0 ; +FLASHER ?= mspdebug ; +FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; + +RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; + diff --git a/msb-430h/board_init.c b/msb-430-common/board_init.c similarity index 100% rename from msb-430h/board_init.c rename to msb-430-common/board_init.c diff --git a/msb-430h/debug_uart.c b/msb-430-common/debug_uart.c similarity index 100% rename from msb-430h/debug_uart.c rename to msb-430-common/debug_uart.c diff --git a/msb-430/Jamfile b/msb-430/Jamfile new file mode 100644 index 0000000000..f2592c24cf --- /dev/null +++ b/msb-430/Jamfile @@ -0,0 +1,32 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +SubDir TOP board msb-430 ; + +SubInclude TOP board msb-430-common ; +SubInclude TOP cpu $(CPU) ; + diff --git a/msb-430/Jamrules.msb-430 b/msb-430/Jamrules.msb-430 new file mode 100644 index 0000000000..ae1d28b444 --- /dev/null +++ b/msb-430/Jamrules.msb-430 @@ -0,0 +1,3 @@ +BOARD = msb-430 ; + +include $(TOP)/board/msb-430-common/Jamrules.msb-430-common ; diff --git a/msb-430/include/board.h b/msb-430/include/board.h new file mode 100644 index 0000000000..6ca75c9c45 --- /dev/null +++ b/msb-430/include/board.h @@ -0,0 +1,69 @@ +/****************************************************************************** +Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef _MSB_BOARD_H +#define _MSB_BOARD_H + +/** + * @defgroup msb_430h ScatterWeb MSB-430H + * @ingroup msp430 + * +

Compontents

+\li MSP430 +\li CC1100 + +* @{ +*/ + +/** + * @file + * @brief MSB-430H Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @version $Revision$ + * + * @note $Id$ + */ + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 7372800uL +#define MSP430_HAS_DCOR 1 +#define MSP430_HAS_EXTERNAL_CRYSTAL 0 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x80 +#define LEDS_CONF_GREEN 0x00 +#define LEDS_CONF_YELLOW 0x00 + +#define RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define RED_OFF LEDS_PxOUT |= LEDS_CONF_RED + +#include + +/** @} */ +#endif // _MSB_BOARD_H diff --git a/msb-430h/Jamfile b/msb-430h/Jamfile index b1181a57db..79e6f920c0 100644 --- a/msb-430h/Jamfile +++ b/msb-430h/Jamfile @@ -27,9 +27,8 @@ SubDir TOP board msb-430h ; -Module board : board_init.c debug_uart.c ; -UseModule board ; - Module board_cc1100 : driver_cc1100.c ; +SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; + diff --git a/msb-430h/Jamrules.msb-430h b/msb-430h/Jamrules.msb-430h index 41bf0779d9..d1913ed542 100644 --- a/msb-430h/Jamrules.msb-430h +++ b/msb-430h/Jamrules.msb-430h @@ -1,37 +1,3 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - BOARD = msb-430h ; -CPU = msp430 ; -MCU = msp430x1612 ; - -FLASH_PORT ?= /dev/ttyUSB0 ; -FLASHER ?= mspdebug ; -FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; - -RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; +include $(TOP)/board/msb-430-common/Jamrules.msb-430-common ; From acc118337b8300785cb3cadd962e2328264352d1 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 25 Oct 2010 15:39:26 +0200 Subject: [PATCH 010/188] * fix msba2 flash command to use lpc2k_pgm from path, without flashutil --- msba2/Jamrules.msba2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/msba2/Jamrules.msba2 b/msba2/Jamrules.msba2 index 5111de74d3..b0ad55f759 100644 --- a/msba2/Jamrules.msba2 +++ b/msba2/Jamrules.msba2 @@ -29,5 +29,5 @@ CPU = lpc2387 ; HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; -FLASHER ?= $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; -FLASHFLAGS ?= --basedir $(TOP)/board/msba2/tools --id "MSB-A2" --ports "$(PORT)" ; +FLASHER ?= $(POSIXSHELL) lpc2k_pgm ; +FLASHFLAGS ?= "$(PORT)" ; From 468431a6dd281fa83f67027d57ca1674992c16c8 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 28 Oct 2010 11:22:57 +0200 Subject: [PATCH 011/188] * massive name changes --- olimex_lpc2148/tick.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/olimex_lpc2148/tick.c b/olimex_lpc2148/tick.c index 08b3dcb0bb..4b8912607b 100644 --- a/olimex_lpc2148/tick.c +++ b/olimex_lpc2148/tick.c @@ -51,12 +51,12 @@ int counter = 0; void Timer0_IRQHandler (void) { - extern unsigned int fk_context_switch_request; + extern unsigned int sched_context_switch_request; counter++; T0IR |= 0xff; // reset timer1 interrupt flag sl_printf("#"); - fk_context_switch_request = 1; + sched_context_switch_request = 1; VICVectAddr = 0; // acknowledge interrupt (if using VIC IRQ) } From d6245a50ee2acc95affaee2a17ddb174eb3fc3b1 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 28 Oct 2010 11:22:57 +0200 Subject: [PATCH 012/188] * massive name changes --- olimex_lpc2148/tick.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/olimex_lpc2148/tick.c b/olimex_lpc2148/tick.c index 08b3dcb0bb..4b8912607b 100644 --- a/olimex_lpc2148/tick.c +++ b/olimex_lpc2148/tick.c @@ -51,12 +51,12 @@ int counter = 0; void Timer0_IRQHandler (void) { - extern unsigned int fk_context_switch_request; + extern unsigned int sched_context_switch_request; counter++; T0IR |= 0xff; // reset timer1 interrupt flag sl_printf("#"); - fk_context_switch_request = 1; + sched_context_switch_request = 1; VICVectAddr = 0; // acknowledge interrupt (if using VIC IRQ) } From 97e876c6a7c5811ed8d91f5e81ddc06d87b6c561 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 28 Oct 2010 16:54:49 +0200 Subject: [PATCH 013/188] * msba2_tools: create bin dir if needed --- msba2/tools/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msba2/tools/Makefile b/msba2/tools/Makefile index 91d44fdf78..e98492a309 100644 --- a/msba2/tools/Makefile +++ b/msba2/tools/Makefile @@ -12,9 +12,11 @@ PSEUDOTERM_OBJS = ${addprefix obj/,${patsubst %.c,%.o,$(PSEUDOTERM_SRC)}} TARGETDIR = bin lpc2k_pgm: $(OBJS) + mkdir -p $(TARGETDIR) $(CC) -o $(TARGETDIR)/lpc2k_pgm $(OBJS) pseudoterm: $(PSEUDOTERM_OBJS) + mkdir -p $(TARGETDIR) $(CC) -lpthread -o $(TARGETDIR)/pseudoterm $(PSEUDOTERM_OBJS) chipinfo.o: boot_2xxx.h boot_23xx.h From 70cbff9255ab2f8e07148fee747c5b428640fe0f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 29 Oct 2010 17:32:03 +0200 Subject: [PATCH 014/188] * added support for sht11 for msb-430-common * fixed some jamfile isssues for msb-430 * fixed arch32 detection for scheduler * changed sht11 driver to be platform independent --- msb-430-common/Jamrules.msb-430-common | 1 + msb-430-common/board_init.c | 2 +- msb-430-common/drivers/include/sht11-board.h | 61 ++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 msb-430-common/drivers/include/sht11-board.h diff --git a/msb-430-common/Jamrules.msb-430-common b/msb-430-common/Jamrules.msb-430-common index db12fc6763..bfe5a1a6f8 100644 --- a/msb-430-common/Jamrules.msb-430-common +++ b/msb-430-common/Jamrules.msb-430-common @@ -34,3 +34,4 @@ FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; +HDRS += [ FPath $(TOP) board msb-430-common drivers include ] ; diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index 7dee70e3b1..4673600445 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -201,7 +201,7 @@ void board_init() { msp430_cpu_init(); msb_ports_init(); - RED_ON; + LED_RED_ON; msp430_set_cpu_speed(7372800uL); } diff --git a/msb-430-common/drivers/include/sht11-board.h b/msb-430-common/drivers/include/sht11-board.h new file mode 100644 index 0000000000..a4debd4473 --- /dev/null +++ b/msb-430-common/drivers/include/sht11-board.h @@ -0,0 +1,61 @@ +/****************************************************************************** +Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef SHT11BOARD_H_ +#define SHT11BOARD_H_ + +/** + * @ingroup msb_430h + * @{ + */ + +/** + * @file + * @brief SHT11 Device Driver Configuration For MSB-430 Platform + * + * @author Freie Universität Berlin, Computer Systems & Telematics, µkleos + * @version $Revision$ + * + * @note $Id$ + */ +#include +#include + +/* SCK = P3B5 + * DATA = P3B4 + */ + +#define SHT11_SCK_LOW P3OUT &= ~(BIT5); /**< serial clock line low */ +#define SHT11_SCK_HIGH P3OUT |= BIT5; /**< serial clock line high */ +#define SHT11_DATA (P3IN & BIT5) /**< read serial I/O */ +#define SHT11_DATA_LOW P3OUT &= ~(BIT5); /**< serial I/O line low */ +#define SHT11_DATA_HIGH P3OUT |= BIT5; /**< serial I/O line high */ +#define SHT11_DATA_IN P3DIR &= ~(BIT5); /**< serial I/O as input */ +#define SHT11_DATA_OUT P3DIR |= BIT5; /**< serial I/O as output */ +#define SHT11_INIT P3DIR |= BIT5; /* FIO1DIR |= BIT25; PINSEL3 &= ~(BIT14|BIT15 | BIT16|BIT17); */ + +/** @} */ +#endif /* SHT11BOARD_H_ */ From 098e0ff8e87c5e6680823e69756b07d871f23092 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 29 Oct 2010 17:34:13 +0200 Subject: [PATCH 015/188] * missing parts of last commit --- msb-430/include/board.h | 5 +++-- msb-430h/include/board.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/msb-430/include/board.h b/msb-430/include/board.h index 6ca75c9c45..18d4a04721 100644 --- a/msb-430/include/board.h +++ b/msb-430/include/board.h @@ -60,8 +60,9 @@ and the mailinglist (subscription via web site) #define LEDS_CONF_GREEN 0x00 #define LEDS_CONF_YELLOW 0x00 -#define RED_ON LEDS_PxOUT &=~LEDS_CONF_RED -#define RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED #include diff --git a/msb-430h/include/board.h b/msb-430h/include/board.h index ef2bbb6585..d9634d6b4d 100644 --- a/msb-430h/include/board.h +++ b/msb-430h/include/board.h @@ -60,8 +60,9 @@ and the mailinglist (subscription via web site) #define LEDS_CONF_GREEN 0x00 #define LEDS_CONF_YELLOW 0x00 -#define RED_ON LEDS_PxOUT &=~LEDS_CONF_RED -#define RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED #include From ff2e8c5c115afb6faecb635b7c2a3944fcdf8a14 Mon Sep 17 00:00:00 2001 From: oleg Date: Fri, 29 Oct 2010 19:16:02 +0200 Subject: [PATCH 016/188] * removed SHT11 timings from msba2 header --- msba2/drivers/include/sht11-board.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/msba2/drivers/include/sht11-board.h b/msba2/drivers/include/sht11-board.h index fc0313906a..c35fb00788 100644 --- a/msba2/drivers/include/sht11-board.h +++ b/msba2/drivers/include/sht11-board.h @@ -54,10 +54,5 @@ and the mailinglist (subscription via web site) #define SHT11_DATA_OUT (FIO1DIR |= BIT26) // serial I/O as output #define SHT11_INIT FIO1DIR |= BIT25; PINSEL3 &= ~(BIT14|BIT15 | BIT16|BIT17); -/* time to wait after toggling the data line */ -#define SHT11_DATA_WAIT (50) -/* time to wait after toggling the clock line */ -#define SHT11_CLK_WAIT (10) - /** @} */ #endif /* SHT11BOARD_H_ */ From a208ef488ef06c44d5a8ab59a3e30b4338050ae2 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 1 Nov 2010 17:31:23 +0100 Subject: [PATCH 017/188] * switch to direct serial output (w/o interrupts --- msba2/drivers/msba2-uart0.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/msba2/drivers/msba2-uart0.c b/msba2/drivers/msba2-uart0.c index 9198f50bb2..dceba9aed7 100644 --- a/msba2/drivers/msba2-uart0.c +++ b/msba2/drivers/msba2-uart0.c @@ -149,7 +149,7 @@ void UART0_IRQHandler(void) static inline int uart0_puts(char *astring,int length) { - while (queue_items == (QUEUESIZE-1)) {} ; +/* while (queue_items == (QUEUESIZE-1)) {} ; U0IER = 0; queue[queue_tail] = malloc(length+sizeof(unsigned int)); queue[queue_tail]->len = length; @@ -158,14 +158,14 @@ static inline int uart0_puts(char *astring,int length) if (!running) push_queue(); U0IER |= BIT0 | BIT1; // enable RX irq - - /* alternative without queue: +*/ + /* alternative without queue:*/ int i; for (i=0;i Date: Tue, 2 Nov 2010 11:39:11 +0100 Subject: [PATCH 018/188] * msba2_uart0: disable TX interrupt --- msba2/drivers/msba2-uart0.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/msba2/drivers/msba2-uart0.c b/msba2/drivers/msba2-uart0.c index dceba9aed7..8ff7e11e37 100644 --- a/msba2/drivers/msba2-uart0.c +++ b/msba2/drivers/msba2-uart0.c @@ -199,7 +199,8 @@ bl_uart_init(void) /* irq */ install_irq(UART0_INT, UART0_IRQHandler, 6); - U0IER |= BIT0 | BIT1; // enable RX+TX irq +// U0IER |= BIT0 | BIT1; // enable RX+TX irq + U0IER |= BIT0; // enable only RX irq return 1; } From 65e9364d2f45399c5bd327674b606234efcfd17f Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 3 Nov 2010 12:03:37 +0100 Subject: [PATCH 019/188] * disable irq-based uart output --- msba2/drivers/msba2-uart0.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/msba2/drivers/msba2-uart0.c b/msba2/drivers/msba2-uart0.c index 9198f50bb2..8ff7e11e37 100644 --- a/msba2/drivers/msba2-uart0.c +++ b/msba2/drivers/msba2-uart0.c @@ -149,7 +149,7 @@ void UART0_IRQHandler(void) static inline int uart0_puts(char *astring,int length) { - while (queue_items == (QUEUESIZE-1)) {} ; +/* while (queue_items == (QUEUESIZE-1)) {} ; U0IER = 0; queue[queue_tail] = malloc(length+sizeof(unsigned int)); queue[queue_tail]->len = length; @@ -158,14 +158,14 @@ static inline int uart0_puts(char *astring,int length) if (!running) push_queue(); U0IER |= BIT0 | BIT1; // enable RX irq - - /* alternative without queue: +*/ + /* alternative without queue:*/ int i; for (i=0;i Date: Mon, 8 Nov 2010 21:39:30 +0100 Subject: [PATCH 020/188] * some cosmetics and lpm flags for UART --- msba2/drivers/msba2-uart0.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/msba2/drivers/msba2-uart0.c b/msba2/drivers/msba2-uart0.c index 8ff7e11e37..3107e8d40c 100644 --- a/msba2/drivers/msba2-uart0.c +++ b/msba2/drivers/msba2-uart0.c @@ -35,6 +35,7 @@ and the mailinglist (subscription via web site) #include #include "lpc23xx.h" #include "VIC.h" +#include #include @@ -78,12 +79,14 @@ static inline void dequeue(void) { static void push_queue(void) { running = 1; + lpm_prevent_sleep |= LPM_PREVENT_SLEEP_UART; start: if (!actual) { if (queue_items) { dequeue(); } else { running = 0; + lpm_prevent_sleep &= ~LPM_PREVENT_SLEEP_UART; if (!fifo) while(!(U0LSR & BIT6)){}; return; From 071aa972544e7d6a49016eab76ac0e884c41e444 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 18 Nov 2010 16:16:57 +0100 Subject: [PATCH 021/188] * removed unnecessary sleep --- msba2/tools/src/lpc2k_pgm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/msba2/tools/src/lpc2k_pgm.c b/msba2/tools/src/lpc2k_pgm.c index 153fa9b425..4891c55946 100644 --- a/msba2/tools/src/lpc2k_pgm.c +++ b/msba2/tools/src/lpc2k_pgm.c @@ -78,8 +78,6 @@ int main(int argc, char **argv) char* port_name = argv[1]; char* file_name = argv[2]; - sleep(1); - if (open_serial_port(port_name) < 0) { return(1); } From 9b059f217c63c68d29384f909a5a193e927792b8 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 29 Nov 2010 16:17:44 +0100 Subject: [PATCH 022/188] * make pseudoterm reset terminal on sigint, make it honour ctrl-c --- msba2/tools/src/pseudoterm.c | 291 +++++++++++++++++++---------------- 1 file changed, 156 insertions(+), 135 deletions(-) diff --git a/msba2/tools/src/pseudoterm.c b/msba2/tools/src/pseudoterm.c index ce8a446b32..cf17d99703 100644 --- a/msba2/tools/src/pseudoterm.c +++ b/msba2/tools/src/pseudoterm.c @@ -1,135 +1,156 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "serial.h" -#include "pthread.h" -#include "download.h" - -int tty_fd; -int stopped = 0; -char* port_name = "/dev/ttyUSB1"; -pthread_t serial_reader; - -void* serial_reader_func(void* arg) { - unsigned char buf[255]; - while(1) { - int n = read_serial_port(buf, sizeof(buf)); - if (n > 0) { - write(tty_fd, buf, n); - } - } -} - -int init() { - int result = open_serial_port(port_name); - pthread_create(&serial_reader, NULL, serial_reader_func, NULL); - hard_reset_to_user_code(); - return result; -} - -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"); - exit(1); - } - } - } else if (signal == SIGUSR2) { - if (!stopped) { - stopped = 1; - printf("\nSignal received, closing port. \r\n"); - pthread_cancel(serial_reader); - close_serial_port(); - } - } -} - -int open_tty(void) -{ - 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; - term_setting.c_oflag |= ( ONLRET ); - term_setting.c_iflag |= (IGNBRK | IGNPAR); - term_setting.c_iflag &= ~(ISTRIP | BRKINT); - term_setting.c_lflag &= ~(ICANON | ISIG | ECHO); - 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() { - struct sigaction action; - sigemptyset (&action.sa_mask); - sigaddset( &action.sa_mask, SIGUSR1 ); - sigaddset( &action.sa_mask, SIGUSR2 ); - action.sa_flags = 0; - action.sa_handler = sig_handler; - sigaction(SIGUSR1, &action, NULL); - sigaction(SIGUSR2, &action, NULL); -} - -int main(int argc, char** argv) { - if (argc == 2) { - port_name = argv[1]; - } - - printf("Using %s as serial device.\n", port_name); - - char ttybuf[255]; - tty_fd = open_tty(); - if (tty_fd < 0) { - printf("Error opening terminal.\n"); - return(1); - } - - install_sighandler(); - - if (init() < 0) { - printf("Cannot open port.\r\n"); - exit(1); - } - - while (1) { - int n = read(tty_fd, ttybuf, sizeof(ttybuf)); - int i; - - /* check for 0x3 (ctrl-c), clean exit */ - for (i = 0; i < n; i++) { - if (ttybuf[i] == 0x3) { - if (i > 0) { - write_serial_port(ttybuf, i); - } - close_serial_port(); - system("tset -c"); - return 0; - } - - } - write_serial_port(ttybuf,n); - } - - close_serial_port(); - return 0; -} - - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "serial.h" +#include "pthread.h" +#include "download.h" + +int tty_fd; +int stopped = 0; +char* port_name = "/dev/ttyUSB1"; +pthread_t serial_reader; + +void* serial_reader_func(void* arg) { + unsigned char buf[255]; + while(1) { + int n = read_serial_port(buf, sizeof(buf)); + if (n > 0) { + write(tty_fd, buf, n); + } + } +} + +int init() { + int result = open_serial_port(port_name); + pthread_create(&serial_reader, NULL, serial_reader_func, NULL); + hard_reset_to_user_code(); + return result; +} + +struct termios old_term_setting; + +void close_tty() { + tcsetattr(tty_fd, TCSANOW, &old_term_setting); +} + +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) { + if (!stopped) { + stopped = 1; + printf("\nSignal received, closing port. \r\n"); + pthread_cancel(serial_reader); + close_serial_port(); + } + } else if (signal == SIGINT) { + printf("SIGINT received, exiting...\n"); + pthread_cancel(serial_reader); + close_serial_port(); + close_tty(); + exit(0); + } +} + +int open_tty(void) +{ + 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; + + 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; +} + +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 ); + action.sa_flags = 0; + action.sa_handler = sig_handler; + sigaction(SIGINT, &action, NULL); + sigaction(SIGUSR1, &action, NULL); + sigaction(SIGUSR2, &action, NULL); +} + +int main(int argc, char** argv) { + if (argc == 2) { + port_name = argv[1]; + } + + printf("Using %s as serial device.\n", port_name); + + char ttybuf[255]; + tty_fd = open_tty(); + if (tty_fd < 0) { + printf("Error opening terminal.\n"); + return(1); + } + + install_sighandler(); + + if (init() < 0) { + printf("Cannot open port.\r\n"); + exit(1); + } + + while (1) { + int n = read(tty_fd, ttybuf, sizeof(ttybuf)); + int i; + + /* check for 0x3 (ctrl-c), clean exit */ + for (i = 0; i < n; i++) { + if (ttybuf[i] == 0x3) { + if (i > 0) { + write_serial_port(ttybuf, i); + } + close_serial_port(); + close_tty(); + system("tset -c"); + return 0; + } + + } + write_serial_port(ttybuf,n); + } + + close_tty(); + close_serial_port(); + return 0; +} + + From 77a02220bd5dfa63ad89e2fb124f243167134780 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 29 Nov 2010 16:17:44 +0100 Subject: [PATCH 023/188] * make pseudoterm reset terminal on sigint, make it honour ctrl-c --- msba2/tools/src/pseudoterm.c | 291 +++++++++++++++++++---------------- 1 file changed, 156 insertions(+), 135 deletions(-) diff --git a/msba2/tools/src/pseudoterm.c b/msba2/tools/src/pseudoterm.c index ce8a446b32..cf17d99703 100644 --- a/msba2/tools/src/pseudoterm.c +++ b/msba2/tools/src/pseudoterm.c @@ -1,135 +1,156 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "serial.h" -#include "pthread.h" -#include "download.h" - -int tty_fd; -int stopped = 0; -char* port_name = "/dev/ttyUSB1"; -pthread_t serial_reader; - -void* serial_reader_func(void* arg) { - unsigned char buf[255]; - while(1) { - int n = read_serial_port(buf, sizeof(buf)); - if (n > 0) { - write(tty_fd, buf, n); - } - } -} - -int init() { - int result = open_serial_port(port_name); - pthread_create(&serial_reader, NULL, serial_reader_func, NULL); - hard_reset_to_user_code(); - return result; -} - -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"); - exit(1); - } - } - } else if (signal == SIGUSR2) { - if (!stopped) { - stopped = 1; - printf("\nSignal received, closing port. \r\n"); - pthread_cancel(serial_reader); - close_serial_port(); - } - } -} - -int open_tty(void) -{ - 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; - term_setting.c_oflag |= ( ONLRET ); - term_setting.c_iflag |= (IGNBRK | IGNPAR); - term_setting.c_iflag &= ~(ISTRIP | BRKINT); - term_setting.c_lflag &= ~(ICANON | ISIG | ECHO); - 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() { - struct sigaction action; - sigemptyset (&action.sa_mask); - sigaddset( &action.sa_mask, SIGUSR1 ); - sigaddset( &action.sa_mask, SIGUSR2 ); - action.sa_flags = 0; - action.sa_handler = sig_handler; - sigaction(SIGUSR1, &action, NULL); - sigaction(SIGUSR2, &action, NULL); -} - -int main(int argc, char** argv) { - if (argc == 2) { - port_name = argv[1]; - } - - printf("Using %s as serial device.\n", port_name); - - char ttybuf[255]; - tty_fd = open_tty(); - if (tty_fd < 0) { - printf("Error opening terminal.\n"); - return(1); - } - - install_sighandler(); - - if (init() < 0) { - printf("Cannot open port.\r\n"); - exit(1); - } - - while (1) { - int n = read(tty_fd, ttybuf, sizeof(ttybuf)); - int i; - - /* check for 0x3 (ctrl-c), clean exit */ - for (i = 0; i < n; i++) { - if (ttybuf[i] == 0x3) { - if (i > 0) { - write_serial_port(ttybuf, i); - } - close_serial_port(); - system("tset -c"); - return 0; - } - - } - write_serial_port(ttybuf,n); - } - - close_serial_port(); - return 0; -} - - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "serial.h" +#include "pthread.h" +#include "download.h" + +int tty_fd; +int stopped = 0; +char* port_name = "/dev/ttyUSB1"; +pthread_t serial_reader; + +void* serial_reader_func(void* arg) { + unsigned char buf[255]; + while(1) { + int n = read_serial_port(buf, sizeof(buf)); + if (n > 0) { + write(tty_fd, buf, n); + } + } +} + +int init() { + int result = open_serial_port(port_name); + pthread_create(&serial_reader, NULL, serial_reader_func, NULL); + hard_reset_to_user_code(); + return result; +} + +struct termios old_term_setting; + +void close_tty() { + tcsetattr(tty_fd, TCSANOW, &old_term_setting); +} + +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) { + if (!stopped) { + stopped = 1; + printf("\nSignal received, closing port. \r\n"); + pthread_cancel(serial_reader); + close_serial_port(); + } + } else if (signal == SIGINT) { + printf("SIGINT received, exiting...\n"); + pthread_cancel(serial_reader); + close_serial_port(); + close_tty(); + exit(0); + } +} + +int open_tty(void) +{ + 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; + + 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; +} + +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 ); + action.sa_flags = 0; + action.sa_handler = sig_handler; + sigaction(SIGINT, &action, NULL); + sigaction(SIGUSR1, &action, NULL); + sigaction(SIGUSR2, &action, NULL); +} + +int main(int argc, char** argv) { + if (argc == 2) { + port_name = argv[1]; + } + + printf("Using %s as serial device.\n", port_name); + + char ttybuf[255]; + tty_fd = open_tty(); + if (tty_fd < 0) { + printf("Error opening terminal.\n"); + return(1); + } + + install_sighandler(); + + if (init() < 0) { + printf("Cannot open port.\r\n"); + exit(1); + } + + while (1) { + int n = read(tty_fd, ttybuf, sizeof(ttybuf)); + int i; + + /* check for 0x3 (ctrl-c), clean exit */ + for (i = 0; i < n; i++) { + if (ttybuf[i] == 0x3) { + if (i > 0) { + write_serial_port(ttybuf, i); + } + close_serial_port(); + close_tty(); + system("tset -c"); + return 0; + } + + } + write_serial_port(ttybuf,n); + } + + close_tty(); + close_serial_port(); + return 0; +} + + From c0047711ce3efd70ae9217ac4b1698455c3f8474 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 1 Dec 2010 16:26:48 +0100 Subject: [PATCH 024/188] * introduced identifiers (include shell commands to get and set) * introduced a system wide configuration --- msba2/Jamfile | 2 +- msba2/board_init.c | 23 +++++++++++++++++++++-- msba2/config.c | 8 ++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 msba2/config.c diff --git a/msba2/Jamfile b/msba2/Jamfile index 88106e45cb..4bef1bd295 100644 --- a/msba2/Jamfile +++ b/msba2/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msba2 ; -Module board : board_init.c ; +Module board : board_init.c config.c ; UseModule board ; UseModule board_common ; diff --git a/msba2/board_init.c b/msba2/board_init.c index 44c6cc33a3..4996b07785 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -42,12 +42,21 @@ and the mailinglist (subscription via web site) */ #include #include -#include "VIC.h" -#include "cpu.h" +#include +#include +#include +#include +#include #define PCRTC BIT9 #define CL_CPU_DIV 4 +config_t sysconfig = { + 0, ///< default ID + 0, ///< default radio address + 0, ///< default radio channel +}; + /*---------------------------------------------------------------------------*/ /** * @brief Enabling MAM and setting number of clocks used for Flash memory fetch @@ -154,3 +163,13 @@ void bl_blink(void) { LED_GREEN_OFF; } +void bl_config_init(void) { + extern char configmem[]; + if (*((uint16_t*) configmem) == CONFIG_KEY) { + memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); + LED_GREEN_TOGGLE; + } + else { + config_save(); + } +} diff --git a/msba2/config.c b/msba2/config.c new file mode 100644 index 0000000000..9d149eb86f --- /dev/null +++ b/msba2/config.c @@ -0,0 +1,8 @@ +#include +#include +#include + +uint8_t config_save(void) { + configmem_t mem = { CONFIG_KEY, sysconfig }; + return (flashrom_erase((uint32_t) configmem) && flashrom_write((uint32_t) configmem, (char*) &mem, sizeof(mem))); +} From f62fa6611b8f6854a1518b993f03b8f5d0a3be1f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 2 Dec 2010 15:38:28 +0100 Subject: [PATCH 025/188] [drivers/cc110x_ng sys/transceiver] * updated interface to switch transceiver off and back to rx mode * removed some debugging stuff --- msba2/board_init.c | 1 - 1 file changed, 1 deletion(-) diff --git a/msba2/board_init.c b/msba2/board_init.c index 4996b07785..aea2c5093d 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -167,7 +167,6 @@ void bl_config_init(void) { extern char configmem[]; if (*((uint16_t*) configmem) == CONFIG_KEY) { memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); - LED_GREEN_TOGGLE; } else { config_save(); From 5f84689c0bf772a2d7e2a173fa76f74e506fca7b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 3 Dec 2010 18:42:03 +0100 Subject: [PATCH 026/188] [board/msp-430-common board/msba2 core/] * introduced dummy function for msp-430 config-save * moved sysconfig from board to core [sys/transceiver cpu/] * moved some buffer size defines to cpu dependent parts * some cleanups --- msb-430-common/Jamfile | 2 +- msb-430-common/Jamrules.msb-430-common | 2 +- msb-430-common/config.c | 6 ++++++ msba2/board_init.c | 6 ------ 4 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 msb-430-common/config.c diff --git a/msb-430-common/Jamfile b/msb-430-common/Jamfile index 97c2be0f30..6cc5f8f1e3 100644 --- a/msb-430-common/Jamfile +++ b/msb-430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430-common ; -Module board : board_init.c debug_uart.c ; +Module board : board_init.c debug_uart.c config.c ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/msb-430-common/Jamrules.msb-430-common b/msb-430-common/Jamrules.msb-430-common index bfe5a1a6f8..af4e671c17 100644 --- a/msb-430-common/Jamrules.msb-430-common +++ b/msb-430-common/Jamrules.msb-430-common @@ -28,7 +28,7 @@ CPU = msp430 ; MCU = msp430x1612 ; -FLASH_PORT ?= /dev/ttyUSB0 ; +FLASH_PORT ?= "$(PORT)" ; FLASHER ?= mspdebug ; FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; diff --git a/msb-430-common/config.c b/msb-430-common/config.c new file mode 100644 index 0000000000..f8d169e2a2 --- /dev/null +++ b/msb-430-common/config.c @@ -0,0 +1,6 @@ +#include +#include + +uint8_t config_save(void) { + return 1; +} diff --git a/msba2/board_init.c b/msba2/board_init.c index aea2c5093d..de730c33b6 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -51,12 +51,6 @@ and the mailinglist (subscription via web site) #define PCRTC BIT9 #define CL_CPU_DIV 4 -config_t sysconfig = { - 0, ///< default ID - 0, ///< default radio address - 0, ///< default radio channel -}; - /*---------------------------------------------------------------------------*/ /** * @brief Enabling MAM and setting number of clocks used for Flash memory fetch From d00b12ef753ea9e9fbc2bd446e08153a7aafe895 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 3 Dec 2010 22:22:58 +0100 Subject: [PATCH 027/188] * introduced flashrom driver for msb430 * restructured some files concerning flashrom access * added some ifdefs to shell commands --- msb-430-common/Jamrules.msb-430-common | 1 + msb-430-common/config.c | 5 ++++- msb-430-common/include/board-conf.h | 6 ++++++ msba2/config.c | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 msb-430-common/include/board-conf.h diff --git a/msb-430-common/Jamrules.msb-430-common b/msb-430-common/Jamrules.msb-430-common index af4e671c17..9c51cd21db 100644 --- a/msb-430-common/Jamrules.msb-430-common +++ b/msb-430-common/Jamrules.msb-430-common @@ -34,4 +34,5 @@ FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; +HDRS += [ FPath $(TOP) board msb-430-common include ] ; HDRS += [ FPath $(TOP) board msb-430-common drivers include ] ; diff --git a/msb-430-common/config.c b/msb-430-common/config.c index f8d169e2a2..3e752592c9 100644 --- a/msb-430-common/config.c +++ b/msb-430-common/config.c @@ -1,6 +1,9 @@ #include +#include #include +#include uint8_t config_save(void) { - return 1; + configmem_t mem = { CONFIG_KEY, sysconfig }; + return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem))); } diff --git a/msb-430-common/include/board-conf.h b/msb-430-common/include/board-conf.h new file mode 100644 index 0000000000..e85c3128f2 --- /dev/null +++ b/msb-430-common/include/board-conf.h @@ -0,0 +1,6 @@ +#ifndef BOARD_CONF_H +#define BOARD_CONF_H + +#define INFOMEM (0x1000) + +#endif /* BOARD-CONF_H */ diff --git a/msba2/config.c b/msba2/config.c index 9d149eb86f..0ca7176651 100644 --- a/msba2/config.c +++ b/msba2/config.c @@ -4,5 +4,5 @@ uint8_t config_save(void) { configmem_t mem = { CONFIG_KEY, sysconfig }; - return (flashrom_erase((uint32_t) configmem) && flashrom_write((uint32_t) configmem, (char*) &mem, sizeof(mem))); + return (flashrom_erase((uint8_t*) &configmem) && flashrom_write((uint8_t*) &configmem, (char*) &mem, sizeof(mem))); } From ee0e37f8eacc6ed22493352aa872a7a0652cb491 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 6 Dec 2010 12:05:03 +0100 Subject: [PATCH 028/188] [board/eZ430-Chronos board/msba2 drivers/cc110x_ng] * restructured interface functions for cc1100 access --- eZ430-Chronos/drivers/Jamfile | 5 +-- eZ430-Chronos/drivers/cc430-cc1100.c | 66 ++++++++++++++++++++++++++++ msba2/drivers/Jamfile | 2 +- 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 eZ430-Chronos/drivers/cc430-cc1100.c diff --git a/eZ430-Chronos/drivers/Jamfile b/eZ430-Chronos/drivers/Jamfile index b2fb968fae..2ccbb030ec 100644 --- a/eZ430-Chronos/drivers/Jamfile +++ b/eZ430-Chronos/drivers/Jamfile @@ -1,5 +1,4 @@ SubDir TOP board eZ430-Chronos drivers ; -UseModule board_common ; - -Module board_common : display.c display1.c ; +Module board_display : display.c display1.c ; +Module board_cc1100 : cc430-cc1100.c : cc110x_cc430 ; diff --git a/eZ430-Chronos/drivers/cc430-cc1100.c b/eZ430-Chronos/drivers/cc430-cc1100.c new file mode 100644 index 0000000000..9ca6890364 --- /dev/null +++ b/eZ430-Chronos/drivers/cc430-cc1100.c @@ -0,0 +1,66 @@ +#include + +#include +#include +#include + +#warning CC430_CC1100 NOT WORKING +/* TODO: defines... */ +#define CC1100_GDO0 (0) +#define CC1100_GDO1 (1) +#define CC1100_GDO2 (2) + +int cc1100_get_gdo0(void) { + return CC1100_GDO0; +} + +int cc1100_get_gdo1(void) { + return CC1100_GDO1; +} + +int cc1100_get_gdo2(void) { + return CC1100_GDO2; +} + +void cc1100_before_send(void) +{ + // Disable GDO2 interrupt before sending packet + cc1100_gdo2_disable(); +} + +void cc1100_after_send(void) +{ + // Enable GDO2 interrupt after sending packet + cc1100_gdo2_enable(); +} + +void cc1100_gdo0_enable(void) { +} + +void cc1100_gdo0_disable(void) { +} + +void cc1100_gdo2_disable(void) { +} + +void cc1100_gdo2_enable(void) { +} + +void cc1100_init_interrupts(void) { + uint8_t state = disableIRQ(); /* Disable all interrupts */ + restoreIRQ(state); /* Enable all interrupts */ +} + +interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ + __enter_isr(); + /* Check IFG */ + if (1 == 1) { + cc1100_gdo2_irq(); + } + else if (2 == 2) { + cc1100_gdo0_irq(); + } else { + puts("cc1100_isr(): unexpected IFG!"); + } + __exit_isr(); +} diff --git a/msba2/drivers/Jamfile b/msba2/drivers/Jamfile index 0b750d9474..50f2ddbf01 100644 --- a/msba2/drivers/Jamfile +++ b/msba2/drivers/Jamfile @@ -1,6 +1,6 @@ SubDir TOP board msba2 drivers ; -Module board_cc1100 : msba2-cc1100.c ; +Module board_cc1100 : msba2-cc1100.c : gpioint cc110x_spi ; Module board_hal : msba2-hal.c ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; Module board_common : msba2-uart0.c : ringbuffer ; From 23c7710d7e828c28a21c399e4a736f721e267b8c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 6 Dec 2010 13:19:31 +0100 Subject: [PATCH 029/188] [board config] * made config optional --- msb-430-common/Jamfile | 3 ++- msba2/Jamfile | 3 ++- msba2/board_init.c | 13 ------------- msba2/config.c | 10 ++++++++++ 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/msb-430-common/Jamfile b/msb-430-common/Jamfile index 6cc5f8f1e3..29cd73df0c 100644 --- a/msb-430-common/Jamfile +++ b/msb-430-common/Jamfile @@ -27,7 +27,8 @@ SubDir TOP board msb-430-common ; -Module board : board_init.c debug_uart.c config.c ; +Module board : board_init.c debug_uart.c ; +Module config : config.c ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/msba2/Jamfile b/msba2/Jamfile index 4bef1bd295..468b453066 100644 --- a/msba2/Jamfile +++ b/msba2/Jamfile @@ -27,7 +27,8 @@ SubDir TOP board msba2 ; -Module board : board_init.c config.c ; +Module board : board_init.c ; +Module config : config.c ; UseModule board ; UseModule board_common ; diff --git a/msba2/board_init.c b/msba2/board_init.c index de730c33b6..469c8fe7cd 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -44,9 +44,6 @@ and the mailinglist (subscription via web site) #include #include #include -#include -#include -#include #define PCRTC BIT9 #define CL_CPU_DIV 4 @@ -156,13 +153,3 @@ void bl_blink(void) { LED_RED_OFF; LED_GREEN_OFF; } - -void bl_config_init(void) { - extern char configmem[]; - if (*((uint16_t*) configmem) == CONFIG_KEY) { - memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); - } - else { - config_save(); - } -} diff --git a/msba2/config.c b/msba2/config.c index 0ca7176651..1910f0b7ff 100644 --- a/msba2/config.c +++ b/msba2/config.c @@ -2,6 +2,16 @@ #include #include +void config_load(void) { + extern char configmem[]; + if (*((uint16_t*) configmem) == CONFIG_KEY) { + memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); + } + else { + config_save(); + } +} + 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))); From 684d9af65ee39e970d384a9cd9ab185452f60184 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 16:06:14 +0100 Subject: [PATCH 030/188] * msba2: updated pttu port, refactored common code into msba2-common --- msba2-common/Jamfile | 6 + {msba2 => msba2-common}/Jamfile.msba2 | 3 +- msba2-common/Jamrules.msba2 | 34 +++ msba2-common/board_common_init.c | 160 ++++++++++++++ {msba2 => msba2-common}/config.c | 0 msba2-common/drivers/Jamfile | 5 + .../drivers/include/sht11-board.h | 0 .../drivers/include/uart0.h | 0 .../drivers/msba2-cc1100.c | 0 .../drivers/msba2-ltc4150.c | 0 {msba2 => msba2-common}/drivers/msba2-uart0.c | 0 .../include/msba2_common.h | 33 +-- {msba2 => msba2-common}/lpc2387-timer3.c | 0 {msba2 => msba2-common}/tools/CHANGES | 0 {msba2 => msba2-common}/tools/COPYING | 0 {msba2 => msba2-common}/tools/Makefile | 0 {msba2 => msba2-common}/tools/README.txt | 0 {msba2 => msba2-common}/tools/armtools.txt | 0 {msba2 => msba2-common}/tools/flash.cmd | 0 {msba2 => msba2-common}/tools/flashutil.sh | 0 {msba2 => msba2-common}/tools/mkbootc | 0 {msba2 => msba2-common}/tools/mkstaticlist | 0 {msba2 => msba2-common}/tools/obj/boot_23xx.d | 0 {msba2 => msba2-common}/tools/obj/boot_2xxx.d | 0 {msba2 => msba2-common}/tools/obj/chipinfo.d | 0 .../tools/obj/control_2xxx.d | 0 {msba2 => msba2-common}/tools/obj/download.d | 0 {msba2 => msba2-common}/tools/obj/ihex.d | 0 {msba2 => msba2-common}/tools/obj/lpc2k_pgm.d | 0 .../tools/obj/pseudoterm.d | 0 {msba2 => msba2-common}/tools/obj/serial.d | 0 {msba2 => msba2-common}/tools/obj/uuencode.d | 0 {msba2 => msba2-common}/tools/src/Jamfile | 0 {msba2 => msba2-common}/tools/src/boot.h | 0 .../tools/src/boot_23xx.armasm | 0 {msba2 => msba2-common}/tools/src/boot_23xx.c | 0 {msba2 => msba2-common}/tools/src/boot_23xx.h | 0 .../tools/src/boot_2xxx.armasm | 0 {msba2 => msba2-common}/tools/src/boot_2xxx.c | 0 {msba2 => msba2-common}/tools/src/boot_2xxx.h | 0 {msba2 => msba2-common}/tools/src/chipinfo.c | 0 {msba2 => msba2-common}/tools/src/chipinfo.h | 0 .../tools/src/cksum_test.c | 0 .../tools/src/control_2xxx.c | 0 .../tools/src/control_2xxx.h | 0 {msba2 => msba2-common}/tools/src/download.c | 0 {msba2 => msba2-common}/tools/src/download.h | 0 {msba2 => msba2-common}/tools/src/gui.c | 0 {msba2 => msba2-common}/tools/src/gui.h | 0 {msba2 => msba2-common}/tools/src/ihex.c | 0 {msba2 => msba2-common}/tools/src/ihex.h | 0 {msba2 => msba2-common}/tools/src/lpc2k_pgm.c | 0 {msba2 => msba2-common}/tools/src/lpc2k_pgm.h | 0 .../tools/src/pseudoterm.c | 0 {msba2 => msba2-common}/tools/src/serial.c | 0 {msba2 => msba2-common}/tools/src/serial.h | 0 {msba2 => msba2-common}/tools/src/settings.c | 0 {msba2 => msba2-common}/tools/src/settings.h | 0 {msba2 => msba2-common}/tools/src/uuencode.c | 0 {msba2 => msba2-common}/tools/src/uuencode.h | 0 {msba2 => msba2-common}/tools/termctrl.sh | 0 msba2/Jamfile | 10 +- msba2/Jamrules.msba2 | 34 +-- msba2/board_init.c | 153 ++----------- msba2/drivers/Jamfile | 7 - msba2/include/board-conf.h | 68 ------ msba2/include/board.h | 51 +---- pttu/Jamfile | 9 +- pttu/Jamrules.pttu | 5 +- pttu/board_init.c | 86 +------- pttu/drivers/Jamfile | 2 - pttu/drivers/pttu-uart0.c | 204 ------------------ 72 files changed, 252 insertions(+), 618 deletions(-) create mode 100644 msba2-common/Jamfile rename {msba2 => msba2-common}/Jamfile.msba2 (90%) create mode 100644 msba2-common/Jamrules.msba2 create mode 100644 msba2-common/board_common_init.c rename {msba2 => msba2-common}/config.c (100%) create mode 100644 msba2-common/drivers/Jamfile rename {msba2 => msba2-common}/drivers/include/sht11-board.h (100%) rename {msba2 => msba2-common}/drivers/include/uart0.h (100%) rename {msba2 => msba2-common}/drivers/msba2-cc1100.c (100%) rename {msba2 => msba2-common}/drivers/msba2-ltc4150.c (100%) rename {msba2 => msba2-common}/drivers/msba2-uart0.c (100%) rename msba2/drivers/include/hal-board.h => msba2-common/include/msba2_common.h (74%) rename {msba2 => msba2-common}/lpc2387-timer3.c (100%) rename {msba2 => msba2-common}/tools/CHANGES (100%) rename {msba2 => msba2-common}/tools/COPYING (100%) rename {msba2 => msba2-common}/tools/Makefile (100%) rename {msba2 => msba2-common}/tools/README.txt (100%) rename {msba2 => msba2-common}/tools/armtools.txt (100%) rename {msba2 => msba2-common}/tools/flash.cmd (100%) rename {msba2 => msba2-common}/tools/flashutil.sh (100%) rename {msba2 => msba2-common}/tools/mkbootc (100%) rename {msba2 => msba2-common}/tools/mkstaticlist (100%) rename {msba2 => msba2-common}/tools/obj/boot_23xx.d (100%) rename {msba2 => msba2-common}/tools/obj/boot_2xxx.d (100%) rename {msba2 => msba2-common}/tools/obj/chipinfo.d (100%) rename {msba2 => msba2-common}/tools/obj/control_2xxx.d (100%) rename {msba2 => msba2-common}/tools/obj/download.d (100%) rename {msba2 => msba2-common}/tools/obj/ihex.d (100%) rename {msba2 => msba2-common}/tools/obj/lpc2k_pgm.d (100%) rename {msba2 => msba2-common}/tools/obj/pseudoterm.d (100%) rename {msba2 => msba2-common}/tools/obj/serial.d (100%) rename {msba2 => msba2-common}/tools/obj/uuencode.d (100%) rename {msba2 => msba2-common}/tools/src/Jamfile (100%) rename {msba2 => msba2-common}/tools/src/boot.h (100%) rename {msba2 => msba2-common}/tools/src/boot_23xx.armasm (100%) rename {msba2 => msba2-common}/tools/src/boot_23xx.c (100%) rename {msba2 => msba2-common}/tools/src/boot_23xx.h (100%) rename {msba2 => msba2-common}/tools/src/boot_2xxx.armasm (100%) rename {msba2 => msba2-common}/tools/src/boot_2xxx.c (100%) rename {msba2 => msba2-common}/tools/src/boot_2xxx.h (100%) rename {msba2 => msba2-common}/tools/src/chipinfo.c (100%) rename {msba2 => msba2-common}/tools/src/chipinfo.h (100%) rename {msba2 => msba2-common}/tools/src/cksum_test.c (100%) rename {msba2 => msba2-common}/tools/src/control_2xxx.c (100%) rename {msba2 => msba2-common}/tools/src/control_2xxx.h (100%) rename {msba2 => msba2-common}/tools/src/download.c (100%) rename {msba2 => msba2-common}/tools/src/download.h (100%) rename {msba2 => msba2-common}/tools/src/gui.c (100%) rename {msba2 => msba2-common}/tools/src/gui.h (100%) rename {msba2 => msba2-common}/tools/src/ihex.c (100%) rename {msba2 => msba2-common}/tools/src/ihex.h (100%) rename {msba2 => msba2-common}/tools/src/lpc2k_pgm.c (100%) rename {msba2 => msba2-common}/tools/src/lpc2k_pgm.h (100%) rename {msba2 => msba2-common}/tools/src/pseudoterm.c (100%) rename {msba2 => msba2-common}/tools/src/serial.c (100%) rename {msba2 => msba2-common}/tools/src/serial.h (100%) rename {msba2 => msba2-common}/tools/src/settings.c (100%) rename {msba2 => msba2-common}/tools/src/settings.h (100%) rename {msba2 => msba2-common}/tools/src/uuencode.c (100%) rename {msba2 => msba2-common}/tools/src/uuencode.h (100%) rename {msba2 => msba2-common}/tools/termctrl.sh (100%) delete mode 100644 msba2/drivers/Jamfile delete mode 100644 msba2/include/board-conf.h delete mode 100644 pttu/drivers/pttu-uart0.c diff --git a/msba2-common/Jamfile b/msba2-common/Jamfile new file mode 100644 index 0000000000..8b3d8febcc --- /dev/null +++ b/msba2-common/Jamfile @@ -0,0 +1,6 @@ +SubDir TOP board msba2-common ; + +Module board_common : board_common_init.c ; + +SubInclude TOP board msba2-common drivers ; + diff --git a/msba2/Jamfile.msba2 b/msba2-common/Jamfile.msba2 similarity index 90% rename from msba2/Jamfile.msba2 rename to msba2-common/Jamfile.msba2 index 44014a6c96..e9e291c906 100644 --- a/msba2/Jamfile.msba2 +++ b/msba2-common/Jamfile.msba2 @@ -25,7 +25,6 @@ # ****************************************************************************** # $Id$ -#LinkLibraries $(BOARD).elf : sys-drivers.a net_mm.a sys-lib.a fat-lib.a -# cpu_drivers.a board_drivers.a cc110x.a hal.a hal_drivers.a lpc2387_hal.a ; +Module msba2_common : board_init.c ; include [ FPath $(TOP) cpu arm_common Jamfile.arm_common ] ; diff --git a/msba2-common/Jamrules.msba2 b/msba2-common/Jamrules.msba2 new file mode 100644 index 0000000000..1bce8075c4 --- /dev/null +++ b/msba2-common/Jamrules.msba2 @@ -0,0 +1,34 @@ +# ****************************************************************************** +# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +# +# These sources were developed at the Freie Universitaet Berlin, Computer +# Systems and Telematics group (http://cst.mi.fu-berlin.de). +# ------------------------------------------------------------------------------ +# This file is part of FeuerWare. +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# FeuerWare is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see http://www.gnu.org/licenses/ . +# ------------------------------------------------------------------------------ +# For further information and questions please use the web site +# http://scatterweb.mi.fu-berlin.de +# and the mailinglist (subscription via web site) +# scatterweb@lists.spline.inf.fu-berlin.de +# ****************************************************************************** +# $Id$ + +CPU = lpc2387 ; + +HDRS += [ FPath $(TOP) board msba2-common include ] ; +HDRS += [ FPath $(TOP) board msba2-common drivers include ] ; + +FLASHER ?= $(POSIXSHELL) lpc2k_pgm ; +FLASHFLAGS ?= "$(PORT)" ; diff --git a/msba2-common/board_common_init.c b/msba2-common/board_common_init.c new file mode 100644 index 0000000000..0823a71bc9 --- /dev/null +++ b/msba2-common/board_common_init.c @@ -0,0 +1,160 @@ +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/** + * @ingroup msba2 + * @{ + */ + +/** + * @file + * @brief MSB-A2 board initialization + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Kaspar Schleiser + * @author Michael Baar + * + * @note $Id$ + */ +#include +#include +#include +#include +#include +#include +#include + +#define PCRTC BIT9 +#define CL_CPU_DIV 4 + +config_t sysconfig = { + 0, ///< default ID + 0, ///< default radio address + 0, ///< default radio channel +}; + +/*---------------------------------------------------------------------------*/ +/** + * @brief Enabling MAM and setting number of clocks used for Flash memory fetch + * @internal + */ +static void +init_mam(void) +{ + MAMCR = 0x0000; + MAMTIM = 0x0003; + MAMCR = 0x0002; +} +/*---------------------------------------------------------------------------*/ +static inline void +pllfeed(void) +{ + PLLFEED = 0xAA; + PLLFEED = 0x55; +} +/*---------------------------------------------------------------------------*/ +void init_clks1(void) +{ + // Disconnect PLL + PLLCON &= ~0x0002; + pllfeed(); + + // Disable PLL + PLLCON &= ~0x0001; + pllfeed(); + + SCS |= 0x20; // Enable main OSC + while( !(SCS & 0x40) ); // Wait until main OSC is usable + + /* select main OSC, 16MHz, as the PLL clock source */ + CLKSRCSEL = 0x0001; + + // Setting Multiplier and Divider values + PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz + pllfeed(); + + // Enabling the PLL */ + PLLCON = 0x0001; + pllfeed(); + + /* Set clock divider to 4 (value+1) */ + CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz + +#if USE_USB + USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ +#endif +} + +void init_clks2(void){ + // Wait for the PLL to lock to set frequency + while(!(PLLSTAT & BIT26)); + + // Connect the PLL as the clock source + PLLCON = 0x0003; + pllfeed(); + + /* Check connect bit status */ + while (!(PLLSTAT & BIT25)); +} + +void bl_init_clks(void) +{ + PCONP = PCRTC; // switch off everything except RTC + init_clks1(); + init_clks2(); + init_mam(); +} + +void loop_delay(void) { + volatile uint16_t i, j; + for (i = 1; i < 30; i++) { + for (j = 1; j != 0; j++) { + asm volatile (" nop "); + } + } +} + +/*void bl_blink(void) { + LED_RED_ON; + LED_GREEN_ON; + + loop_delay(); + + LED_RED_OFF; + LED_GREEN_OFF; +}*/ + +// void bl_config_init(void) { +// extern char configmem[]; +// if (*((uint16_t*) configmem) == CONFIG_KEY) { +// memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); +// LED_GREEN_TOGGLE; +// } +// else { +// config_save(); +// } +// } diff --git a/msba2/config.c b/msba2-common/config.c similarity index 100% rename from msba2/config.c rename to msba2-common/config.c diff --git a/msba2-common/drivers/Jamfile b/msba2-common/drivers/Jamfile new file mode 100644 index 0000000000..9637982162 --- /dev/null +++ b/msba2-common/drivers/Jamfile @@ -0,0 +1,5 @@ +SubDir TOP board msba2-common drivers ; + +Module board_cc1100 : msba2-cc1100.c ; +Module board_ltc4150 : msba2-ltc4150.c : gpioint ; +Module board_uart : msba2-uart0.c : chardev_thread ringbuffer ; diff --git a/msba2/drivers/include/sht11-board.h b/msba2-common/drivers/include/sht11-board.h similarity index 100% rename from msba2/drivers/include/sht11-board.h rename to msba2-common/drivers/include/sht11-board.h diff --git a/msba2/drivers/include/uart0.h b/msba2-common/drivers/include/uart0.h similarity index 100% rename from msba2/drivers/include/uart0.h rename to msba2-common/drivers/include/uart0.h diff --git a/msba2/drivers/msba2-cc1100.c b/msba2-common/drivers/msba2-cc1100.c similarity index 100% rename from msba2/drivers/msba2-cc1100.c rename to msba2-common/drivers/msba2-cc1100.c diff --git a/msba2/drivers/msba2-ltc4150.c b/msba2-common/drivers/msba2-ltc4150.c similarity index 100% rename from msba2/drivers/msba2-ltc4150.c rename to msba2-common/drivers/msba2-ltc4150.c diff --git a/msba2/drivers/msba2-uart0.c b/msba2-common/drivers/msba2-uart0.c similarity index 100% rename from msba2/drivers/msba2-uart0.c rename to msba2-common/drivers/msba2-uart0.c diff --git a/msba2/drivers/include/hal-board.h b/msba2-common/include/msba2_common.h similarity index 74% rename from msba2/drivers/include/hal-board.h rename to msba2-common/include/msba2_common.h index a4dfc293ab..a9d9d3e72c 100644 --- a/msba2/drivers/include/hal-board.h +++ b/msba2-common/include/msba2_common.h @@ -24,45 +24,28 @@ and the mailinglist (subscription via web site) scatterweb@lists.spline.inf.fu-berlin.de *******************************************************************************/ -#ifndef HALPLATFORM_H_ -#define HALPLATFORM_H_ +#ifndef __BOARD_H +#define __BOARD_H /** - * @ingroup msba2 + * @ingroup msb_a2 * @{ */ /** * @file - * @brief + * @brief MSB-A2 Common Board Definitions * * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author baar + * @author Kaspar Schleiser * @version $Revision$ * * @note $Id$ */ -#include "vdevice.h" -#include "device-gpio.h" -#include "device-rs232.h" -#include "device-serial.h" +#include -VDEVICE_NAME(vdevice_gpio, gpio_led_green); -VDEVICE_NAME(vdevice_gpio, gpio_led_red); -VDEVICE_NAME(vdevice_gpio, gpio_led_usb); - -/** - * @var tty0 - * @brief RS232 TTY0 device on UART0 - */ -VDEVICE_NAME(vdevice_rs232, tty0); - -/** - * @var console0 - * @brief console device on tty0 - */ -VDEVICE_NAME(vdevice_serial, console0); +#define VICIntEnClear VICIntEnClr /** @} */ -#endif /* HALPLATFORM_H_ */ +#endif // __BOARD_H diff --git a/msba2/lpc2387-timer3.c b/msba2-common/lpc2387-timer3.c similarity index 100% rename from msba2/lpc2387-timer3.c rename to msba2-common/lpc2387-timer3.c diff --git a/msba2/tools/CHANGES b/msba2-common/tools/CHANGES similarity index 100% rename from msba2/tools/CHANGES rename to msba2-common/tools/CHANGES diff --git a/msba2/tools/COPYING b/msba2-common/tools/COPYING similarity index 100% rename from msba2/tools/COPYING rename to msba2-common/tools/COPYING diff --git a/msba2/tools/Makefile b/msba2-common/tools/Makefile similarity index 100% rename from msba2/tools/Makefile rename to msba2-common/tools/Makefile diff --git a/msba2/tools/README.txt b/msba2-common/tools/README.txt similarity index 100% rename from msba2/tools/README.txt rename to msba2-common/tools/README.txt diff --git a/msba2/tools/armtools.txt b/msba2-common/tools/armtools.txt similarity index 100% rename from msba2/tools/armtools.txt rename to msba2-common/tools/armtools.txt diff --git a/msba2/tools/flash.cmd b/msba2-common/tools/flash.cmd similarity index 100% rename from msba2/tools/flash.cmd rename to msba2-common/tools/flash.cmd diff --git a/msba2/tools/flashutil.sh b/msba2-common/tools/flashutil.sh similarity index 100% rename from msba2/tools/flashutil.sh rename to msba2-common/tools/flashutil.sh diff --git a/msba2/tools/mkbootc b/msba2-common/tools/mkbootc similarity index 100% rename from msba2/tools/mkbootc rename to msba2-common/tools/mkbootc diff --git a/msba2/tools/mkstaticlist b/msba2-common/tools/mkstaticlist similarity index 100% rename from msba2/tools/mkstaticlist rename to msba2-common/tools/mkstaticlist diff --git a/msba2/tools/obj/boot_23xx.d b/msba2-common/tools/obj/boot_23xx.d similarity index 100% rename from msba2/tools/obj/boot_23xx.d rename to msba2-common/tools/obj/boot_23xx.d diff --git a/msba2/tools/obj/boot_2xxx.d b/msba2-common/tools/obj/boot_2xxx.d similarity index 100% rename from msba2/tools/obj/boot_2xxx.d rename to msba2-common/tools/obj/boot_2xxx.d diff --git a/msba2/tools/obj/chipinfo.d b/msba2-common/tools/obj/chipinfo.d similarity index 100% rename from msba2/tools/obj/chipinfo.d rename to msba2-common/tools/obj/chipinfo.d diff --git a/msba2/tools/obj/control_2xxx.d b/msba2-common/tools/obj/control_2xxx.d similarity index 100% rename from msba2/tools/obj/control_2xxx.d rename to msba2-common/tools/obj/control_2xxx.d diff --git a/msba2/tools/obj/download.d b/msba2-common/tools/obj/download.d similarity index 100% rename from msba2/tools/obj/download.d rename to msba2-common/tools/obj/download.d diff --git a/msba2/tools/obj/ihex.d b/msba2-common/tools/obj/ihex.d similarity index 100% rename from msba2/tools/obj/ihex.d rename to msba2-common/tools/obj/ihex.d diff --git a/msba2/tools/obj/lpc2k_pgm.d b/msba2-common/tools/obj/lpc2k_pgm.d similarity index 100% rename from msba2/tools/obj/lpc2k_pgm.d rename to msba2-common/tools/obj/lpc2k_pgm.d diff --git a/msba2/tools/obj/pseudoterm.d b/msba2-common/tools/obj/pseudoterm.d similarity index 100% rename from msba2/tools/obj/pseudoterm.d rename to msba2-common/tools/obj/pseudoterm.d diff --git a/msba2/tools/obj/serial.d b/msba2-common/tools/obj/serial.d similarity index 100% rename from msba2/tools/obj/serial.d rename to msba2-common/tools/obj/serial.d diff --git a/msba2/tools/obj/uuencode.d b/msba2-common/tools/obj/uuencode.d similarity index 100% rename from msba2/tools/obj/uuencode.d rename to msba2-common/tools/obj/uuencode.d diff --git a/msba2/tools/src/Jamfile b/msba2-common/tools/src/Jamfile similarity index 100% rename from msba2/tools/src/Jamfile rename to msba2-common/tools/src/Jamfile diff --git a/msba2/tools/src/boot.h b/msba2-common/tools/src/boot.h similarity index 100% rename from msba2/tools/src/boot.h rename to msba2-common/tools/src/boot.h diff --git a/msba2/tools/src/boot_23xx.armasm b/msba2-common/tools/src/boot_23xx.armasm similarity index 100% rename from msba2/tools/src/boot_23xx.armasm rename to msba2-common/tools/src/boot_23xx.armasm diff --git a/msba2/tools/src/boot_23xx.c b/msba2-common/tools/src/boot_23xx.c similarity index 100% rename from msba2/tools/src/boot_23xx.c rename to msba2-common/tools/src/boot_23xx.c diff --git a/msba2/tools/src/boot_23xx.h b/msba2-common/tools/src/boot_23xx.h similarity index 100% rename from msba2/tools/src/boot_23xx.h rename to msba2-common/tools/src/boot_23xx.h diff --git a/msba2/tools/src/boot_2xxx.armasm b/msba2-common/tools/src/boot_2xxx.armasm similarity index 100% rename from msba2/tools/src/boot_2xxx.armasm rename to msba2-common/tools/src/boot_2xxx.armasm diff --git a/msba2/tools/src/boot_2xxx.c b/msba2-common/tools/src/boot_2xxx.c similarity index 100% rename from msba2/tools/src/boot_2xxx.c rename to msba2-common/tools/src/boot_2xxx.c diff --git a/msba2/tools/src/boot_2xxx.h b/msba2-common/tools/src/boot_2xxx.h similarity index 100% rename from msba2/tools/src/boot_2xxx.h rename to msba2-common/tools/src/boot_2xxx.h diff --git a/msba2/tools/src/chipinfo.c b/msba2-common/tools/src/chipinfo.c similarity index 100% rename from msba2/tools/src/chipinfo.c rename to msba2-common/tools/src/chipinfo.c diff --git a/msba2/tools/src/chipinfo.h b/msba2-common/tools/src/chipinfo.h similarity index 100% rename from msba2/tools/src/chipinfo.h rename to msba2-common/tools/src/chipinfo.h diff --git a/msba2/tools/src/cksum_test.c b/msba2-common/tools/src/cksum_test.c similarity index 100% rename from msba2/tools/src/cksum_test.c rename to msba2-common/tools/src/cksum_test.c diff --git a/msba2/tools/src/control_2xxx.c b/msba2-common/tools/src/control_2xxx.c similarity index 100% rename from msba2/tools/src/control_2xxx.c rename to msba2-common/tools/src/control_2xxx.c diff --git a/msba2/tools/src/control_2xxx.h b/msba2-common/tools/src/control_2xxx.h similarity index 100% rename from msba2/tools/src/control_2xxx.h rename to msba2-common/tools/src/control_2xxx.h diff --git a/msba2/tools/src/download.c b/msba2-common/tools/src/download.c similarity index 100% rename from msba2/tools/src/download.c rename to msba2-common/tools/src/download.c diff --git a/msba2/tools/src/download.h b/msba2-common/tools/src/download.h similarity index 100% rename from msba2/tools/src/download.h rename to msba2-common/tools/src/download.h diff --git a/msba2/tools/src/gui.c b/msba2-common/tools/src/gui.c similarity index 100% rename from msba2/tools/src/gui.c rename to msba2-common/tools/src/gui.c diff --git a/msba2/tools/src/gui.h b/msba2-common/tools/src/gui.h similarity index 100% rename from msba2/tools/src/gui.h rename to msba2-common/tools/src/gui.h diff --git a/msba2/tools/src/ihex.c b/msba2-common/tools/src/ihex.c similarity index 100% rename from msba2/tools/src/ihex.c rename to msba2-common/tools/src/ihex.c diff --git a/msba2/tools/src/ihex.h b/msba2-common/tools/src/ihex.h similarity index 100% rename from msba2/tools/src/ihex.h rename to msba2-common/tools/src/ihex.h diff --git a/msba2/tools/src/lpc2k_pgm.c b/msba2-common/tools/src/lpc2k_pgm.c similarity index 100% rename from msba2/tools/src/lpc2k_pgm.c rename to msba2-common/tools/src/lpc2k_pgm.c diff --git a/msba2/tools/src/lpc2k_pgm.h b/msba2-common/tools/src/lpc2k_pgm.h similarity index 100% rename from msba2/tools/src/lpc2k_pgm.h rename to msba2-common/tools/src/lpc2k_pgm.h diff --git a/msba2/tools/src/pseudoterm.c b/msba2-common/tools/src/pseudoterm.c similarity index 100% rename from msba2/tools/src/pseudoterm.c rename to msba2-common/tools/src/pseudoterm.c diff --git a/msba2/tools/src/serial.c b/msba2-common/tools/src/serial.c similarity index 100% rename from msba2/tools/src/serial.c rename to msba2-common/tools/src/serial.c diff --git a/msba2/tools/src/serial.h b/msba2-common/tools/src/serial.h similarity index 100% rename from msba2/tools/src/serial.h rename to msba2-common/tools/src/serial.h diff --git a/msba2/tools/src/settings.c b/msba2-common/tools/src/settings.c similarity index 100% rename from msba2/tools/src/settings.c rename to msba2-common/tools/src/settings.c diff --git a/msba2/tools/src/settings.h b/msba2-common/tools/src/settings.h similarity index 100% rename from msba2/tools/src/settings.h rename to msba2-common/tools/src/settings.h diff --git a/msba2/tools/src/uuencode.c b/msba2-common/tools/src/uuencode.c similarity index 100% rename from msba2/tools/src/uuencode.c rename to msba2-common/tools/src/uuencode.c diff --git a/msba2/tools/src/uuencode.h b/msba2-common/tools/src/uuencode.h similarity index 100% rename from msba2/tools/src/uuencode.h rename to msba2-common/tools/src/uuencode.h diff --git a/msba2/tools/termctrl.sh b/msba2-common/tools/termctrl.sh similarity index 100% rename from msba2/tools/termctrl.sh rename to msba2-common/tools/termctrl.sh diff --git a/msba2/Jamfile b/msba2/Jamfile index 468b453066..553522ba68 100644 --- a/msba2/Jamfile +++ b/msba2/Jamfile @@ -25,12 +25,12 @@ # ****************************************************************************** # $Id$ -SubDir TOP board msba2 ; +SubDir TOP board $(BOARD) ; -Module board : board_init.c ; -Module config : config.c ; +Module board : board_init.c : board_common board_uart ; UseModule board ; -UseModule board_common ; -SubInclude TOP board $(BOARD) drivers ; +Module config : config.c ; + +SubInclude TOP board $(BOARD)-common ; SubInclude TOP cpu $(CPU) ; diff --git a/msba2/Jamrules.msba2 b/msba2/Jamrules.msba2 index b0ad55f759..22c8a88060 100644 --- a/msba2/Jamrules.msba2 +++ b/msba2/Jamrules.msba2 @@ -1,33 +1 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -CPU = lpc2387 ; - -HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; - -FLASHER ?= $(POSIXSHELL) lpc2k_pgm ; -FLASHFLAGS ?= "$(PORT)" ; +include board/msba2-common/Jamrules.msba2 ; diff --git a/msba2/board_init.c b/msba2/board_init.c index 469c8fe7cd..f250109c08 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -1,140 +1,6 @@ -/****************************************************************************** -Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. - -These sources were developed at the Freie Universitaet Berlin, Computer Systems -and Telematics group (http://cst.mi.fu-berlin.de). -------------------------------------------------------------------------------- -This file is part of FeuerWare. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -FeuerWare is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see http://www.gnu.org/licenses/ . --------------------------------------------------------------------------------- -For further information and questions please use the web site - http://scatterweb.mi.fu-berlin.de -and the mailinglist (subscription via web site) - scatterweb@lists.spline.inf.fu-berlin.de -*******************************************************************************/ - -/** - * @ingroup msba2 - * @{ - */ - -/** - * @file - * @brief MSB-A2 board initialization - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author Heiko Will - * @author Kaspar Schleiser - * @author Michael Baar - * - * @note $Id$ - */ #include -#include -#include #include -#define PCRTC BIT9 -#define CL_CPU_DIV 4 - -/*---------------------------------------------------------------------------*/ -/** - * @brief Enabling MAM and setting number of clocks used for Flash memory fetch - * @internal - */ -static void -init_mam(void) -{ - MAMCR = 0x0000; - MAMTIM = 0x0003; - MAMCR = 0x0002; -} -/*---------------------------------------------------------------------------*/ -static inline void -pllfeed(void) -{ - PLLFEED = 0xAA; - PLLFEED = 0x55; -} -/*---------------------------------------------------------------------------*/ -void init_clks1(void) -{ - // Disconnect PLL - PLLCON &= ~0x0002; - pllfeed(); - - // Disable PLL - PLLCON &= ~0x0001; - pllfeed(); - - SCS |= 0x20; // Enable main OSC - while( !(SCS & 0x40) ); // Wait until main OSC is usable - - /* select main OSC, 16MHz, as the PLL clock source */ - CLKSRCSEL = 0x0001; - - // Setting Multiplier and Divider values - PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz - pllfeed(); - - // Enabling the PLL */ - PLLCON = 0x0001; - pllfeed(); - - /* Set clock divider to 4 (value+1) */ - CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz - -#if USE_USB - USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ -#endif -} - -void init_clks2(void){ - // Wait for the PLL to lock to set frequency - while(!(PLLSTAT & BIT26)); - - // Connect the PLL as the clock source - PLLCON = 0x0003; - pllfeed(); - - /* Check connect bit status */ - while (!(PLLSTAT & BIT25)); -} - -void bl_init_clks(void) -{ - PCONP = PCRTC; // switch off everything except RTC - init_clks1(); - init_clks2(); - init_mam(); -} - -void bl_init_ports(void) -{ - SCS |= BIT0; // Set IO Ports to fast switching mode - - /* UART0 */ - PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 - PINSEL0 &= ~(BIT5 + BIT7); - - /* LEDS */ - FIO3DIR |= LED_RED_PIN; - FIO3DIR |= LED_GREEN_PIN; - LED_RED_OFF; - LED_GREEN_OFF; -} - void loop_delay(void) { volatile uint16_t i, j; for (i = 1; i < 30; i++) { @@ -153,3 +19,22 @@ void bl_blink(void) { LED_RED_OFF; LED_GREEN_OFF; } + +void bl_init_ports(void) +{ + SCS |= BIT0; // Set IO Ports to fast switching mode + + /* UART0 */ + PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 + PINSEL0 &= ~(BIT5 + BIT7); + + /* LEDS */ + FIO3DIR |= LED_RED_PIN; + 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/drivers/Jamfile b/msba2/drivers/Jamfile deleted file mode 100644 index 50f2ddbf01..0000000000 --- a/msba2/drivers/Jamfile +++ /dev/null @@ -1,7 +0,0 @@ -SubDir TOP board msba2 drivers ; - -Module board_cc1100 : msba2-cc1100.c : gpioint cc110x_spi ; -Module board_hal : msba2-hal.c ; -Module board_ltc4150 : msba2-ltc4150.c : gpioint ; -Module board_common : msba2-uart0.c : ringbuffer ; -Module board_uart : msba2-uart0_thread.c : chardev_thread ringbuffer ; diff --git a/msba2/include/board-conf.h b/msba2/include/board-conf.h deleted file mode 100644 index 2c8824f1fc..0000000000 --- a/msba2/include/board-conf.h +++ /dev/null @@ -1,68 +0,0 @@ -/****************************************************************************** -Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - -These sources were developed at the Freie Universitaet Berlin, Computer Systems -and Telematics group (http://cst.mi.fu-berlin.de). -------------------------------------------------------------------------------- -This file is part of FeuerWare. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -FeuerWare is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see http://www.gnu.org/licenses/ . --------------------------------------------------------------------------------- -For further information and questions please use the web site - http://scatterweb.mi.fu-berlin.de -and the mailinglist (subscription via web site) - scatterweb@lists.spline.inf.fu-berlin.de -*******************************************************************************/ - -#ifndef BOARDCONF_H_ -#define BOARDCONF_H_ - -/** - * @ingroup conf - * @ingroup msba2 - * - * @{ - */ - -/** - * @file - * @brief MSB-A2 board configuration - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author baar - * @version $Revision$ - * - * @note $Id$ - */ - -#define FEUERWARE_CONF_BOARD_NAME "FU Berlin MSB-A2" - -#ifdef MODULE_CC110X -#define FEUERWARE_CONF_NUM_RADIOS 1 -#else -#define FEUERWARE_CONF_NUM_RADIOS 0 -#endif - -// if FAT is enabled this board supports files -#define FEUERWARE_CONF_CORE_SUPPORTS_FILES defined(MODULE_FAT) - -#ifdef MODULE_FAT -#define CFG_CONF_MEM_SIZE 0x7FFFFFFF -#define SYSLOG_CONF_NUM_INTERFACES 2 -#else -#define SYSLOG_CONF_NUM_INTERFACES 1 -#endif - - -/** @} */ -#endif /* BOARDCONF_H_ */ diff --git a/msba2/include/board.h b/msba2/include/board.h index 4356e4423f..bf596f0ee1 100644 --- a/msba2/include/board.h +++ b/msba2/include/board.h @@ -1,51 +1,7 @@ -/****************************************************************************** -Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - -These sources were developed at the Freie Universitaet Berlin, Computer Systems -and Telematics group (http://cst.mi.fu-berlin.de). -------------------------------------------------------------------------------- -This file is part of FeuerWare. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -FeuerWare is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see http://www.gnu.org/licenses/ . --------------------------------------------------------------------------------- -For further information and questions please use the web site - http://scatterweb.mi.fu-berlin.de -and the mailinglist (subscription via web site) - scatterweb@lists.spline.inf.fu-berlin.de -*******************************************************************************/ - #ifndef __BOARD_H -#define __BOARD_H +#define __BOARD_H -/** - * @ingroup msb_a2 - * @{ - */ - -/** - * @file - * @brief MSB-A2 Board - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author Kaspar Schleiser - * @version $Revision$ - * - * @note $Id$ - */ - -#include - -#define VICIntEnClear VICIntEnClr +#include #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) @@ -58,5 +14,4 @@ and the mailinglist (subscription via web site) #define LED_RED_ON (FIO3CLR = LED_RED_PIN) #define LED_RED_TOGGLE (FIO3PIN ^= LED_RED_PIN) -/** @} */ -#endif // __BOARD_H +#endif /* __BOARD_H */ diff --git a/pttu/Jamfile b/pttu/Jamfile index a7b4d6df11..11b4a77e7e 100644 --- a/pttu/Jamfile +++ b/pttu/Jamfile @@ -23,13 +23,12 @@ # and the mailinglist (subscription via web site) # scatterweb@lists.spline.inf.fu-berlin.de # ****************************************************************************** -# $Id: Jamfile 922 2009-03-26 12:52:27Z baar $ +# $Id$ -SubDir TOP board pttu ; +SubDir TOP board $(BOARD) ; -Module board : board_init.c ; +Module board : board_init.c : board_common board_uart ; UseModule board ; -UseModule board_common ; -SubInclude TOP board $(BOARD) drivers ; +SubInclude TOP board msba2-common ; SubInclude TOP cpu $(CPU) ; diff --git a/pttu/Jamrules.pttu b/pttu/Jamrules.pttu index 7eff15f0bb..53e71c71f1 100644 --- a/pttu/Jamrules.pttu +++ b/pttu/Jamrules.pttu @@ -25,13 +25,10 @@ # ****************************************************************************** # $Id: Jamrules.msba2 881 2009-03-20 12:24:58Z kaspar $ -CPU = lpc2387 ; +include board/msba2-common/Jamrules.msba2 ; HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; -FLASHER = $(POSIXSHELL) $(TOP)/board/msba2/tools/flashutil.sh ; -FLASHFLAGS = --basedir $(TOP)/board/msba2/tools --id PTTU --ports "$(PORT)" --openocd $(TOP)/board/pttu/tools/openocd-pttu.sh --openocd-if $(OPENOCD_IF) ; - GDB = arm-elf-gdb ; GDBFLAGS = -x board/pttu/tools/pttu_debug.gdb ; diff --git a/pttu/board_init.c b/pttu/board_init.c index 3070bdfce7..b5b78bde25 100644 --- a/pttu/board_init.c +++ b/pttu/board_init.c @@ -33,94 +33,18 @@ and the mailinglist (subscription via web site) * @file * @brief PTTU board initialization * - * @author Freie Universit�t Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project * @author Heiko Will - * @author Kaspar Schleise - * @author Michael Baar + * @author Kaspar Schleiser * - * @note $Id: cmdengine-out.c 971 2009-04-07 13:41:36Z baar $ */ -#include "lpc23xx.h" -#include "VIC.h" -#include "cpu.h" +#include +#include +#include #define PCRTC BIT9 #define CL_CPU_DIV 4 -/*---------------------------------------------------------------------------*/ -/** - * @brief Enabling MAM and setting number of clocks used for Flash memory fetch - * @internal - */ -void -init_mam(void) -{ - MAMCR = 0x0000; - MAMTIM = 0x0003; - MAMCR = 0x0002; -} -/*---------------------------------------------------------------------------*/ -static inline void -pllfeed(void) -{ - PLLFEED = 0xAA; - PLLFEED = 0x55; -} -/*---------------------------------------------------------------------------*/ -void init_clks1(void) -{ - // Disconnect PLL - PLLCON &= ~0x0002; - pllfeed(); - - // Disable PLL - PLLCON &= ~0x0001; - pllfeed(); - - SCS |= 0x20; // Enable main OSC - while( !(SCS & 0x40) ); // Wait until main OSC is usable - - /* select main OSC, 16MHz, as the PLL clock source */ - CLKSRCSEL = 0x0001; - - // Setting Multiplier and Divider values - PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz - pllfeed(); - - // Enabling the PLL */ - PLLCON = 0x0001; - pllfeed(); - - /* Set clock divider to 4 (value+1) */ - CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz - -#if USE_USB - USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ -#endif -} - -void init_clks2(void){ - // Wait for the PLL to lock to set frequency - while(!(PLLSTAT & BIT26)); - - // Connect the PLL as the clock source - PLLCON = 0x0003; - pllfeed(); - - /* Check connect bit status */ - while (!(PLLSTAT & BIT25)); -} - -void bl_init_clks(void) -{ - PCONP = PCRTC; // switch off everything except RTC - init_clks1(); - init_clks2(); - init_mam(); -} - - -// Michael, Do not change anything here! even not the redundant parts! void bl_init_ports(void) { SCS |= BIT0; // Set IO Ports to fast switching mode diff --git a/pttu/drivers/Jamfile b/pttu/drivers/Jamfile index 26a8b7c2af..31d6db1d6d 100644 --- a/pttu/drivers/Jamfile +++ b/pttu/drivers/Jamfile @@ -1,4 +1,2 @@ SubDir TOP board pttu drivers ; -Module board_common : pttu-uart0.c ; - diff --git a/pttu/drivers/pttu-uart0.c b/pttu/drivers/pttu-uart0.c deleted file mode 100644 index d542f22602..0000000000 --- a/pttu/drivers/pttu-uart0.c +++ /dev/null @@ -1,204 +0,0 @@ -/****************************************************************************** -Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. - -These sources were developed at the Freie Universitaet Berlin, Computer Systems -and Telematics group (http://cst.mi.fu-berlin.de). -------------------------------------------------------------------------------- -This file is part of FeuerWare. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -FeuerWare is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see http://www.gnu.org/licenses/ . --------------------------------------------------------------------------------- -For further information and questions please use the web site - http://scatterweb.mi.fu-berlin.de -and the mailinglist (subscription via web site) - scatterweb@lists.spline.inf.fu-berlin.de -*******************************************************************************/ - -/* - * debug_uart.c: provides initial serial debug output - * - * Copyright (C) 2008, 2009 Kaspar Schleiser - * Heiko Will - */ -#include -#include -#include -#include "lpc23xx.h" -#include "VIC.h" - -/** - * @file - * @ingroup lpc2387 - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @version $Revision$ - * - * @note $Id$ - */ - -typedef struct toprint { - unsigned int len; - char content[]; -}toprint; - -#define QUEUESIZE 255 -static volatile toprint* queue[QUEUESIZE]; -static volatile unsigned char queue_head = 0; -static volatile unsigned char queue_tail = 0; -static volatile unsigned char queue_items = 0; - -static volatile unsigned int actual_pos = 0; -static volatile unsigned int running = 0; -static volatile unsigned int fifo = 0; - -static volatile toprint* actual = NULL; -void (*uart0_callback)(int); - -static inline void enqueue(void) { - queue_items++; - queue_tail++; -} - -static inline void dequeue(void) { - actual = (queue[queue_head]); - queue_items--; - queue_head++; -} - -static void push_queue(void) { - running = 1; -start: - if (!actual) { - if (queue_items) { - dequeue(); - } else { - running = 0; - if (!fifo) - while(!(U0LSR & BIT6)){}; - return; - } - } - while ((actual_pos < actual->len) && (fifo++ < 16)){ - U0THR = actual->content[actual_pos++]; - } - if (actual_pos == actual->len) { - free((void*)actual); - actual = NULL; - actual_pos = 0; - goto start; - } -} - -int uart_active(void){ - return (running || fifo); -} - -static inline void receive(int c) -{ - if (uart0_callback != NULL) uart0_callback(c); -} - -void stdio_flush(void) -{ - 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 -} - -void UART0_IRQHandler(void) __attribute__((interrupt("IRQ"))); -void UART0_IRQHandler(void) -{ - int iir; - iir = U0IIR; - - switch(iir & UIIR_ID_MASK) { - case UIIR_THRE_INT: // Transmit Holding Register Empty - fifo=0; - push_queue(); - break; - - case UIIR_CTI_INT: // Character Timeout Indicator - case UIIR_RDA_INT: // Receive Data Available - do { - int c = U0RBR; - receive(c); - } while (U0LSR & ULSR_RDR); - break; - - default: - U0LSR; - U0RBR; - break; - } // switch - VICVectAddr = 0; // Acknowledge Interrupt -} - -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 - - // alternative without queue: -// int i; -// for (i=0;iconfig->speed - /* - * Baudrate calculation - * BR = PCLK (9 MHz) / (16 x 256 x DLM + DLL) x (1/(DIVADDVAL/MULVAL)) - */ - U0FDR = 0x92; // DIVADDVAL = 0010 = 2, MULVAL = 1001 = 9 - U0DLM = 0x00; - U0DLL = 0x04; - - U0LCR = 0x03; // DLAB = 0 - U0FCR = 0x07; // Enable and reset TX and RX FIFO - - /* irq */ - install_irq(UART0_INT, UART0_IRQHandler, 6); - U0IER |= BIT0 | BIT1; // enable RX+TX irq - return 1; -} - From 77146f63b27a4d7ccfc3cf948b457a67ee736d81 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 17:15:00 +0100 Subject: [PATCH 031/188] * misc merge fixes --- msba2-common/Jamfile | 1 + msba2-common/board_common_init.c | 35 -------------------------------- msba2-common/drivers/Jamfile | 3 ++- msba2/Jamfile | 2 -- 4 files changed, 3 insertions(+), 38 deletions(-) diff --git a/msba2-common/Jamfile b/msba2-common/Jamfile index 8b3d8febcc..ed2adc5647 100644 --- a/msba2-common/Jamfile +++ b/msba2-common/Jamfile @@ -1,6 +1,7 @@ SubDir TOP board msba2-common ; Module board_common : board_common_init.c ; +Module config : config.c ; SubInclude TOP board msba2-common drivers ; diff --git a/msba2-common/board_common_init.c b/msba2-common/board_common_init.c index 0823a71bc9..8d7c359625 100644 --- a/msba2-common/board_common_init.c +++ b/msba2-common/board_common_init.c @@ -51,12 +51,6 @@ and the mailinglist (subscription via web site) #define PCRTC BIT9 #define CL_CPU_DIV 4 -config_t sysconfig = { - 0, ///< default ID - 0, ///< default radio address - 0, ///< default radio channel -}; - /*---------------------------------------------------------------------------*/ /** * @brief Enabling MAM and setting number of clocks used for Flash memory fetch @@ -129,32 +123,3 @@ void bl_init_clks(void) init_mam(); } -void loop_delay(void) { - volatile uint16_t i, j; - for (i = 1; i < 30; i++) { - for (j = 1; j != 0; j++) { - asm volatile (" nop "); - } - } -} - -/*void bl_blink(void) { - LED_RED_ON; - LED_GREEN_ON; - - loop_delay(); - - LED_RED_OFF; - LED_GREEN_OFF; -}*/ - -// void bl_config_init(void) { -// extern char configmem[]; -// if (*((uint16_t*) configmem) == CONFIG_KEY) { -// memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); -// LED_GREEN_TOGGLE; -// } -// else { -// config_save(); -// } -// } diff --git a/msba2-common/drivers/Jamfile b/msba2-common/drivers/Jamfile index 9637982162..c0f4138ab9 100644 --- a/msba2-common/drivers/Jamfile +++ b/msba2-common/drivers/Jamfile @@ -1,5 +1,6 @@ SubDir TOP board msba2-common drivers ; -Module board_cc1100 : msba2-cc1100.c ; +Module board_cc1100 : msba2-cc1100.c : cc110x_spi gpioint ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; Module board_uart : msba2-uart0.c : chardev_thread ringbuffer ; + diff --git a/msba2/Jamfile b/msba2/Jamfile index 553522ba68..6e74471b63 100644 --- a/msba2/Jamfile +++ b/msba2/Jamfile @@ -30,7 +30,5 @@ SubDir TOP board $(BOARD) ; Module board : board_init.c : board_common board_uart ; UseModule board ; -Module config : config.c ; - SubInclude TOP board $(BOARD)-common ; SubInclude TOP cpu $(CPU) ; From 7d7c956c26e20a55281f3182c222b091aa4441f1 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 6 Dec 2010 17:17:19 +0100 Subject: [PATCH 032/188] [board/msba2-common] * added string.h include --- msba2-common/config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/msba2-common/config.c b/msba2-common/config.c index 1910f0b7ff..8eff7e9db8 100644 --- a/msba2-common/config.c +++ b/msba2-common/config.c @@ -1,4 +1,5 @@ #include +#include #include #include From a5918f3086a237aef55ed80af38d2aad3dd2dcdc Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 6 Dec 2010 17:32:27 +0100 Subject: [PATCH 033/188] * moved config to sys, split away board specifics --- msba2-common/Jamfile | 2 +- msba2-common/{config.c => board_config.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename msba2-common/{config.c => board_config.c} (100%) diff --git a/msba2-common/Jamfile b/msba2-common/Jamfile index ed2adc5647..ff9a8ccd4c 100644 --- a/msba2-common/Jamfile +++ b/msba2-common/Jamfile @@ -1,7 +1,7 @@ SubDir TOP board msba2-common ; Module board_common : board_common_init.c ; -Module config : config.c ; +Module board_config : board_config.c ; SubInclude TOP board msba2-common drivers ; diff --git a/msba2-common/config.c b/msba2-common/board_config.c similarity index 100% rename from msba2-common/config.c rename to msba2-common/board_config.c From 04f2003a510bf553b80e3690021f70a3af0b1d0c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 8 Dec 2010 12:16:49 +0100 Subject: [PATCH 034/188] [board/msb-430-common board/eZ430-Chronos cpu/msp430*] * reorganized msp430 based cpu folders --- eZ430-Chronos/Jamrules.eZ430-Chronos | 2 +- eZ430-Chronos/board_init.c | 74 +++++++++++++++++++++++++- msb-430-common/Jamrules.msb-430-common | 2 +- msb-430h/Jamfile | 1 - 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/eZ430-Chronos/Jamrules.eZ430-Chronos b/eZ430-Chronos/Jamrules.eZ430-Chronos index eef3a03017..74e57f0929 100644 --- a/eZ430-Chronos/Jamrules.eZ430-Chronos +++ b/eZ430-Chronos/Jamrules.eZ430-Chronos @@ -4,7 +4,7 @@ # $Id$ BOARD = eZ430-Chronos ; -CPU = msp430 ; +CPU = cc430 ; MCU = cc430x6137 ; FLASHER ?= mspdebug ; diff --git a/eZ430-Chronos/board_init.c b/eZ430-Chronos/board_init.c index aa52e65af9..74799abace 100644 --- a/eZ430-Chronos/board_init.c +++ b/eZ430-Chronos/board_init.c @@ -1,2 +1,74 @@ -void board_init() { +#include +#include +#include +#include + +void cc430_cpu_init(void) { + volatile uint16_t i; + volatile unsigned char *ptr; + + /* disable watchdog */ + WDTCTL = WDTPW + WDTHOLD; + + // --------------------------------------------------------------------- + // 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 + + UCSCTL3 = SELA__XT1CLK; // Select XT1 as FLL reference + UCSCTL4 = SELA__XT1CLK | SELS__DCOCLKDIV | SELM__DCOCLKDIV; + + // --------------------------------------------------------------------- + // Configure CPU clock for 12MHz + _BIS_SR(SCG0); // Disable the FLL control loop + UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx + UCSCTL1 = DCORSEL_5; // Select suitable range + UCSCTL2 = FLLD_1 + 0x16E; // Set DCO Multiplier + _BIC_SR(SCG0); // Enable the FLL control loop + + // Worst-case settling time for the DCO when the DCO range bits have been + // 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 + + // Loop until XT1 & DCO stabilizes, use do-while to insure that + // body is executed at least once + do + { + UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG); + SFRIFG1 &= ~OFIFG; // Clear fault flags + } while ((SFRIFG1 & OFIFG)); + + // Disable all interrupts + __disable_interrupt(); + // Get write-access to port mapping registers: + PMAPPWD = 0x02D52; + // Allow reconfiguration during runtime: + PMAPCTL = PMAPRECFG; + + // P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output) + ptr = &P2MAP0; + *(ptr+7) = PM_TA1CCR0A; + P2OUT &= ~BIT7; + P2DIR |= BIT7; + + // P1.5 = SPI MISO input + ptr = &P1MAP0; + *(ptr+5) = PM_UCA0SOMI; + // P1.6 = SPI MOSI output + *(ptr+6) = PM_UCA0SIMO; + // P1.7 = SPI CLK output + *(ptr+7) = PM_UCA0CLK; + + // Disable write-access to port mapping registers: + PMAPPWD = 0; + // Re-enable all interrupts + enableIRQ(); + +} + +void board_init() { + cc430_cpu_init(); } diff --git a/msb-430-common/Jamrules.msb-430-common b/msb-430-common/Jamrules.msb-430-common index 9c51cd21db..7eee8b088f 100644 --- a/msb-430-common/Jamrules.msb-430-common +++ b/msb-430-common/Jamrules.msb-430-common @@ -25,7 +25,7 @@ # ****************************************************************************** # $Id$ -CPU = msp430 ; +CPU = msp430x16x ; MCU = msp430x1612 ; FLASH_PORT ?= "$(PORT)" ; diff --git a/msb-430h/Jamfile b/msb-430h/Jamfile index 79e6f920c0..15f7ba97f9 100644 --- a/msb-430h/Jamfile +++ b/msb-430h/Jamfile @@ -31,4 +31,3 @@ Module board_cc1100 : driver_cc1100.c ; SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; - From a356dc2494570a35f0b87d13bc88f767601c354d Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 8 Dec 2010 12:58:02 +0100 Subject: [PATCH 035/188] * renamed eZ430-Chronos board to 'chronos' --- {eZ430-Chronos => chronos}/Jamfile | 2 +- .../Jamrules.eZ430-Chronos => chronos/Jamrules.chronos | 2 +- {eZ430-Chronos => chronos}/board_init.c | 0 {eZ430-Chronos => chronos}/debug_uart.c | 0 {eZ430-Chronos => chronos}/drivers/Jamfile | 2 +- {eZ430-Chronos => chronos}/drivers/cc430-cc1100.c | 0 {eZ430-Chronos => chronos}/drivers/display.c | 0 {eZ430-Chronos => chronos}/drivers/display.h | 0 {eZ430-Chronos => chronos}/drivers/display1.c | 0 {eZ430-Chronos => chronos}/include/board.h | 0 10 files changed, 3 insertions(+), 3 deletions(-) rename {eZ430-Chronos => chronos}/Jamfile (83%) rename eZ430-Chronos/Jamrules.eZ430-Chronos => chronos/Jamrules.chronos (93%) rename {eZ430-Chronos => chronos}/board_init.c (100%) rename {eZ430-Chronos => chronos}/debug_uart.c (100%) rename {eZ430-Chronos => chronos}/drivers/Jamfile (71%) rename {eZ430-Chronos => chronos}/drivers/cc430-cc1100.c (100%) rename {eZ430-Chronos => chronos}/drivers/display.c (100%) rename {eZ430-Chronos => chronos}/drivers/display.h (100%) rename {eZ430-Chronos => chronos}/drivers/display1.c (100%) rename {eZ430-Chronos => chronos}/include/board.h (100%) diff --git a/eZ430-Chronos/Jamfile b/chronos/Jamfile similarity index 83% rename from eZ430-Chronos/Jamfile rename to chronos/Jamfile index ea723c95a9..bf3341d785 100644 --- a/eZ430-Chronos/Jamfile +++ b/chronos/Jamfile @@ -1,4 +1,4 @@ -SubDir TOP board eZ430-Chronos ; +SubDir TOP board chronos ; HDRS += $(TOP)/board/$(CPU)/include ; diff --git a/eZ430-Chronos/Jamrules.eZ430-Chronos b/chronos/Jamrules.chronos similarity index 93% rename from eZ430-Chronos/Jamrules.eZ430-Chronos rename to chronos/Jamrules.chronos index 74e57f0929..4c975ae1f9 100644 --- a/eZ430-Chronos/Jamrules.eZ430-Chronos +++ b/chronos/Jamrules.chronos @@ -3,7 +3,7 @@ # ****************************************************************************** # $Id$ -BOARD = eZ430-Chronos ; +BOARD = chronos ; CPU = cc430 ; MCU = cc430x6137 ; diff --git a/eZ430-Chronos/board_init.c b/chronos/board_init.c similarity index 100% rename from eZ430-Chronos/board_init.c rename to chronos/board_init.c diff --git a/eZ430-Chronos/debug_uart.c b/chronos/debug_uart.c similarity index 100% rename from eZ430-Chronos/debug_uart.c rename to chronos/debug_uart.c diff --git a/eZ430-Chronos/drivers/Jamfile b/chronos/drivers/Jamfile similarity index 71% rename from eZ430-Chronos/drivers/Jamfile rename to chronos/drivers/Jamfile index 2ccbb030ec..221ba2ffbc 100644 --- a/eZ430-Chronos/drivers/Jamfile +++ b/chronos/drivers/Jamfile @@ -1,4 +1,4 @@ -SubDir TOP board eZ430-Chronos drivers ; +SubDir TOP board chronos drivers ; Module board_display : display.c display1.c ; Module board_cc1100 : cc430-cc1100.c : cc110x_cc430 ; diff --git a/eZ430-Chronos/drivers/cc430-cc1100.c b/chronos/drivers/cc430-cc1100.c similarity index 100% rename from eZ430-Chronos/drivers/cc430-cc1100.c rename to chronos/drivers/cc430-cc1100.c diff --git a/eZ430-Chronos/drivers/display.c b/chronos/drivers/display.c similarity index 100% rename from eZ430-Chronos/drivers/display.c rename to chronos/drivers/display.c diff --git a/eZ430-Chronos/drivers/display.h b/chronos/drivers/display.h similarity index 100% rename from eZ430-Chronos/drivers/display.h rename to chronos/drivers/display.h diff --git a/eZ430-Chronos/drivers/display1.c b/chronos/drivers/display1.c similarity index 100% rename from eZ430-Chronos/drivers/display1.c rename to chronos/drivers/display1.c diff --git a/eZ430-Chronos/include/board.h b/chronos/include/board.h similarity index 100% rename from eZ430-Chronos/include/board.h rename to chronos/include/board.h From cf3b704bc5e4b5213572fb8335890d7cf9f22f04 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 9 Dec 2010 13:24:24 +0100 Subject: [PATCH 036/188] [Chronos] * changed display driver interface from uint8_t* to char* * fixed hardware timer interrupt * ported cc1100 driver * added simple test application for radio [msb430] * fixex config and flashrom [cc110x_ng] * removed dependency from sysconfig --- chronos/drivers/cc430-cc1100.c | 31 ++++++++++++++------- chronos/drivers/display.c | 18 +++++------- chronos/drivers/display.h | 4 +-- msb-430-common/Jamfile | 2 +- msb-430-common/{config.c => board_config.c} | 10 +++++++ msb-430h/Jamfile | 2 +- msb-430h/driver_cc1100.c | 3 +- 7 files changed, 43 insertions(+), 27 deletions(-) rename msb-430-common/{config.c => board_config.c} (55%) diff --git a/chronos/drivers/cc430-cc1100.c b/chronos/drivers/cc430-cc1100.c index 9ca6890364..6c36e7e6df 100644 --- a/chronos/drivers/cc430-cc1100.c +++ b/chronos/drivers/cc430-cc1100.c @@ -2,13 +2,15 @@ #include #include +#include #include -#warning CC430_CC1100 NOT WORKING -/* TODO: defines... */ -#define CC1100_GDO0 (0) -#define CC1100_GDO1 (1) -#define CC1100_GDO2 (2) +#include +#include + +#define CC1100_GDO0 IOCFG0 +#define CC1100_GDO1 IOCFG1 +#define CC1100_GDO2 IOCFG2 int cc1100_get_gdo0(void) { return CC1100_GDO0; @@ -35,15 +37,23 @@ void cc1100_after_send(void) } void cc1100_gdo0_enable(void) { + RF1AIFG &= ~RF1AIV_RFIFG0; + RF1AIE |= RF1AIV_RFIFG0; } void cc1100_gdo0_disable(void) { + RF1AIE &= ~RF1AIV_RFIFG0; + RF1AIFG &= ~RF1AIV_RFIFG0; } void cc1100_gdo2_disable(void) { + RF1AIFG &= ~RF1AIV_RFIFG2; + RF1AIE &= ~RF1AIV_RFIFG2; } void cc1100_gdo2_enable(void) { + RF1AIE &= ~RF1AIV_RFIFG2; + RF1AIFG |= RF1AIV_RFIFG2; } void cc1100_init_interrupts(void) { @@ -51,16 +61,17 @@ void cc1100_init_interrupts(void) { restoreIRQ(state); /* Enable all interrupts */ } -interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ +interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ __enter_isr(); /* Check IFG */ - if (1 == 1) { + if (RF1AIFG & RF1AIV_RFIFG2) { + RF1AIFG &= ~RF1AIV_RFIFG2; cc1100_gdo2_irq(); } - else if (2 == 2) { + if (RF1AIFG & RF1AIV_RFIFG0) { + RF1AIFG &= ~RF1AIV_RFIFG0; + RF1AIE &= ~RF1AIV_RFIFG0; cc1100_gdo0_irq(); - } else { - puts("cc1100_isr(): unexpected IFG!"); } __exit_isr(); } diff --git a/chronos/drivers/display.c b/chronos/drivers/display.c index c0418f544e..1473703e4b 100644 --- a/chronos/drivers/display.c +++ b/chronos/drivers/display.c @@ -43,18 +43,15 @@ #include // driver -#include "cc430x613x.h" -#include "display.h" +#include +#include // ************************************************************************************************* // Prototypes section -void write_lcd_mem(uint8_t * lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); +void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); void clear_line(uint8_t line); void display_symbol(uint8_t symbol, uint8_t mode); -void display_char(uint8_t segment, uint8_t chr, uint8_t mode); -void display_chars(uint8_t segments, uint8_t * str, uint8_t mode); - // ************************************************************************************************* // Defines section @@ -285,12 +282,12 @@ uint8_t * itoa(uint32_t n, uint8_t digits, uint8_t blanks) // ************************************************************************************************* void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) { - uint8_t * str; + uint8_t* str; str = itoa(value, digits, blanks); // Display string in blink mode - display_chars(segments, str, disp_mode); + display_chars(segments, (char*) str, disp_mode); } @@ -332,7 +329,7 @@ void display_symbol(uint8_t symbol, uint8_t mode) // uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK // @return none // ************************************************************************************************* -void display_char(uint8_t segment, uint8_t chr, uint8_t 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 @@ -393,8 +390,7 @@ void display_char(uint8_t segment, uint8_t chr, uint8_t mode) // uint8_t mode SEG_ON, SEG_OFF, SEG_BLINK // @return none // ************************************************************************************************* -void display_chars(uint8_t segments, uint8_t * str, uint8_t 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 diff --git a/chronos/drivers/display.h b/chronos/drivers/display.h index 993814ce7b..a4fbde92b1 100644 --- a/chronos/drivers/display.h +++ b/chronos/drivers/display.h @@ -337,8 +337,8 @@ void clear_blink_mem(void); void set_blink_rate(uint8_t bits); // Character / symbol draw functions -void display_char(uint8_t segment, uint8_t chr, uint8_t mode); -void display_chars(uint8_t segments, uint8_t * str, uint8_t mode); +void display_char(uint8_t segment, char chr, uint8_t mode); +void display_chars(uint8_t segments, char* str, uint8_t mode); void display_symbol(uint8_t symbol, uint8_t mode); // Time display function diff --git a/msb-430-common/Jamfile b/msb-430-common/Jamfile index 29cd73df0c..17bf86c9bb 100644 --- a/msb-430-common/Jamfile +++ b/msb-430-common/Jamfile @@ -28,7 +28,7 @@ SubDir TOP board msb-430-common ; Module board : board_init.c debug_uart.c ; -Module config : config.c ; +Module board_config : board_config.c ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/msb-430-common/config.c b/msb-430-common/board_config.c similarity index 55% rename from msb-430-common/config.c rename to msb-430-common/board_config.c index 3e752592c9..f22e513b20 100644 --- a/msb-430-common/config.c +++ b/msb-430-common/board_config.c @@ -1,8 +1,18 @@ #include +#include #include #include #include +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) { configmem_t mem = { CONFIG_KEY, sysconfig }; return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem))); diff --git a/msb-430h/Jamfile b/msb-430h/Jamfile index 15f7ba97f9..588fede19d 100644 --- a/msb-430h/Jamfile +++ b/msb-430h/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430h ; -Module board_cc1100 : driver_cc1100.c ; +Module board_cc1100 : driver_cc1100.c : cc110x_spi ; SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; diff --git a/msb-430h/driver_cc1100.c b/msb-430h/driver_cc1100.c index 9575bee6a5..1e5af6e9fd 100644 --- a/msb-430h/driver_cc1100.c +++ b/msb-430h/driver_cc1100.c @@ -23,7 +23,7 @@ Boston, MA 02111-1307, USA. */ #include #include -#include +#include #include #define CC1100_GDO0 (P2IN & 0x02) // read serial I/O (GDO0) @@ -340,4 +340,3 @@ puts("cc1100_isr()"); // if (system_state.POWERDOWN != 0) END_LPM3; __exit_isr(); } - From 31f6c1760685fca14eaae997d70adccec712759f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 10 Dec 2010 18:00:31 +0100 Subject: [PATCH 037/188] [cc110x_ng] * fuxed transceiver driver for chronos * some more stuff --- chronos/drivers/cc430-cc1100.c | 35 ++++++++++++++++------------- msba2-common/drivers/msba2-cc1100.c | 3 +-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/chronos/drivers/cc430-cc1100.c b/chronos/drivers/cc430-cc1100.c index 6c36e7e6df..513cef3e5d 100644 --- a/chronos/drivers/cc430-cc1100.c +++ b/chronos/drivers/cc430-cc1100.c @@ -8,9 +8,9 @@ #include #include -#define CC1100_GDO0 IOCFG0 -#define CC1100_GDO1 IOCFG1 -#define CC1100_GDO2 IOCFG2 +#define CC1100_GDO0 (RF1AIN & BIT0) +#define CC1100_GDO1 (RF1AIN & BIT1) +#define CC1100_GDO2 (RF1AIN & BIT2) int cc1100_get_gdo0(void) { return CC1100_GDO0; @@ -37,41 +37,44 @@ void cc1100_after_send(void) } void cc1100_gdo0_enable(void) { - RF1AIFG &= ~RF1AIV_RFIFG0; - RF1AIE |= RF1AIV_RFIFG0; + RF1AIFG &= ~BIT0; + RF1AIE |= BIT0; } void cc1100_gdo0_disable(void) { - RF1AIE &= ~RF1AIV_RFIFG0; - RF1AIFG &= ~RF1AIV_RFIFG0; + RF1AIE &= ~BIT0; + RF1AIFG &= ~BIT0; } void cc1100_gdo2_disable(void) { - RF1AIFG &= ~RF1AIV_RFIFG2; - RF1AIE &= ~RF1AIV_RFIFG2; + RF1AIFG &= ~BIT2; // Clear a pending interrupt + RF1AIE &= ~BIT2; // Disable the interrupt } void cc1100_gdo2_enable(void) { - RF1AIE &= ~RF1AIV_RFIFG2; - RF1AIFG |= RF1AIV_RFIFG2; + RF1AIFG &= ~BIT2; // Clear a pending interrupt + RF1AIE |= BIT2; // Enable the interrupt } void cc1100_init_interrupts(void) { uint8_t state = disableIRQ(); /* Disable all interrupts */ + cc1100_gdo2_enable(); + cc1100_gdo0_disable(); restoreIRQ(state); /* Enable all interrupts */ } interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ __enter_isr(); /* Check IFG */ - if (RF1AIFG & RF1AIV_RFIFG2) { - RF1AIFG &= ~RF1AIV_RFIFG2; + if (RF1AIV == RF1AIV_RFIFG2) { + while (RF1AIN & BIT2); + /* discard all further interrupts */ + RF1AIV = 0; cc1100_gdo2_irq(); } - if (RF1AIFG & RF1AIV_RFIFG0) { - RF1AIFG &= ~RF1AIV_RFIFG0; - RF1AIE &= ~RF1AIV_RFIFG0; + if (RF1AIV == RF1AIV_RFIFG0) { cc1100_gdo0_irq(); + RF1AIE &= ~BIT0; } __exit_isr(); } diff --git a/msba2-common/drivers/msba2-cc1100.c b/msba2-common/drivers/msba2-cc1100.c index 726d585506..327720c1f3 100644 --- a/msba2-common/drivers/msba2-cc1100.c +++ b/msba2-common/drivers/msba2-cc1100.c @@ -128,8 +128,7 @@ void cc1100_spi_init(void) } } -uint8_t -cc1100_txrx(uint8_t c) { +uint8_t cc1100_txrx(uint8_t c) { uint8_t result; SSP0DR = c; #ifdef DEBUG From b01b1e8e2f02271eb299665cf08da9b7604798fc Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 11 Dec 2010 12:09:20 +0100 Subject: [PATCH 038/188] [board/chronos board/msb-430h board/msba2-common drivers/cc110x_ng sys/shell sys/transceiver] * renamed all occurrences of cc1100 to cc110x as in fact all driver parts should work for cc1100 and cc110x as well [driver/cc110x_ng] * added some documentation * introduced a new register function to access rxfifo (fixing the of-by-one problem on chronos platform --- chronos/drivers/Jamfile | 2 +- .../{cc430-cc1100.c => cc430-cc110x.c} | 43 +++++----- msb-430h/Jamfile | 2 +- msb-430h/{driver_cc1100.c => driver_cc110x.c} | 78 +++++++++---------- msba2-common/drivers/Jamfile | 2 +- .../{msba2-cc1100.c => msba2-cc110x.c} | 50 ++++++------ 6 files changed, 89 insertions(+), 88 deletions(-) rename chronos/drivers/{cc430-cc1100.c => cc430-cc110x.c} (63%) rename msb-430h/{driver_cc1100.c => driver_cc110x.c} (84%) rename msba2-common/drivers/{msba2-cc1100.c => msba2-cc110x.c} (86%) diff --git a/chronos/drivers/Jamfile b/chronos/drivers/Jamfile index 221ba2ffbc..4b2a0d0a85 100644 --- a/chronos/drivers/Jamfile +++ b/chronos/drivers/Jamfile @@ -1,4 +1,4 @@ SubDir TOP board chronos drivers ; Module board_display : display.c display1.c ; -Module board_cc1100 : cc430-cc1100.c : cc110x_cc430 ; +Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; diff --git a/chronos/drivers/cc430-cc1100.c b/chronos/drivers/cc430-cc110x.c similarity index 63% rename from chronos/drivers/cc430-cc1100.c rename to chronos/drivers/cc430-cc110x.c index 513cef3e5d..78380c4ca4 100644 --- a/chronos/drivers/cc430-cc1100.c +++ b/chronos/drivers/cc430-cc110x.c @@ -2,78 +2,79 @@ #include #include -#include -#include +#include +#include -#include -#include +//#include +#include +//#include #define CC1100_GDO0 (RF1AIN & BIT0) #define CC1100_GDO1 (RF1AIN & BIT1) #define CC1100_GDO2 (RF1AIN & BIT2) -int cc1100_get_gdo0(void) { +int cc110x_get_gdo0(void) { return CC1100_GDO0; } -int cc1100_get_gdo1(void) { +int cc110x_get_gdo1(void) { return CC1100_GDO1; } -int cc1100_get_gdo2(void) { +int cc110x_get_gdo2(void) { return CC1100_GDO2; } -void cc1100_before_send(void) +void cc110x_before_send(void) { // Disable GDO2 interrupt before sending packet - cc1100_gdo2_disable(); + cc110x_gdo2_disable(); } -void cc1100_after_send(void) +void cc110x_after_send(void) { // Enable GDO2 interrupt after sending packet - cc1100_gdo2_enable(); + cc110x_gdo2_enable(); } -void cc1100_gdo0_enable(void) { +void cc110x_gdo0_enable(void) { RF1AIFG &= ~BIT0; RF1AIE |= BIT0; } -void cc1100_gdo0_disable(void) { +void cc110x_gdo0_disable(void) { RF1AIE &= ~BIT0; RF1AIFG &= ~BIT0; } -void cc1100_gdo2_disable(void) { +void cc110x_gdo2_disable(void) { RF1AIFG &= ~BIT2; // Clear a pending interrupt RF1AIE &= ~BIT2; // Disable the interrupt } -void cc1100_gdo2_enable(void) { +void cc110x_gdo2_enable(void) { RF1AIFG &= ~BIT2; // Clear a pending interrupt RF1AIE |= BIT2; // Enable the interrupt } -void cc1100_init_interrupts(void) { +void cc110x_init_interrupts(void) { uint8_t state = disableIRQ(); /* Disable all interrupts */ - cc1100_gdo2_enable(); - cc1100_gdo0_disable(); + cc110x_gdo2_enable(); + cc110x_gdo0_disable(); restoreIRQ(state); /* Enable all interrupts */ } -interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ +interrupt (CC1101_VECTOR) __attribute__ ((naked)) cc110x_isr(void){ __enter_isr(); /* Check IFG */ if (RF1AIV == RF1AIV_RFIFG2) { while (RF1AIN & BIT2); /* discard all further interrupts */ RF1AIV = 0; - cc1100_gdo2_irq(); + cc110x_gdo2_irq(); } if (RF1AIV == RF1AIV_RFIFG0) { - cc1100_gdo0_irq(); + cc110x_gdo0_irq(); RF1AIE &= ~BIT0; } __exit_isr(); diff --git a/msb-430h/Jamfile b/msb-430h/Jamfile index 588fede19d..9f9ee47bf3 100644 --- a/msb-430h/Jamfile +++ b/msb-430h/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430h ; -Module board_cc1100 : driver_cc1100.c : cc110x_spi ; +Module board_cc110x : driver_cc110x.c : cc110x_spi ; SubInclude TOP board msb-430-common ; SubInclude TOP cpu $(CPU) ; diff --git a/msb-430h/driver_cc1100.c b/msb-430h/driver_cc110x.c similarity index 84% rename from msb-430h/driver_cc1100.c rename to msb-430h/driver_cc110x.c index 1e5af6e9fd..a0967b272f 100644 --- a/msb-430h/driver_cc1100.c +++ b/msb-430h/driver_cc110x.c @@ -23,8 +23,8 @@ Boston, MA 02111-1307, USA. */ #include #include -#include -#include +#include +#include #define CC1100_GDO0 (P2IN & 0x02) // read serial I/O (GDO0) #define CC1100_GDO1 (P3IN & 0x04) // read serial I/O (GDO1) @@ -39,61 +39,61 @@ Boston, MA 02111-1307, USA. */ volatile int abort_count; volatile int retry_count = 0; -void cc1100_gdo0_enable(void) +void cc110x_gdo0_enable(void) { P2IFG &= ~0x02; /* Clear IFG for GDO0 */ P2IE |= 0x02; /* Enable interrupt for GDO0 */ } -void cc1100_gdo0_disable(void) +void cc110x_gdo0_disable(void) { P2IE &= ~0x02; /* Disable interrupt for GDO0 */ P2IFG &= ~0x02; /* Clear IFG for GDO0 */ } -void cc1100_gdo2_enable(void) +void cc110x_gdo2_enable(void) { P2IFG &= ~0x01; /* Clear IFG for GDO2 */ P2IE |= 0x01; /* Enable interrupt for GDO2 */ } -void cc1100_gdo2_disable(void) +void cc110x_gdo2_disable(void) { P2IE &= ~0x01; /* Disable interrupt for GDO2 */ P2IFG &= ~0x01; /* Clear IFG for GDO2 */ } -void cc1100_before_send(void) +void cc110x_before_send(void) { // Disable GDO2 interrupt before sending packet - cc1100_gdo2_disable(); + cc110x_gdo2_disable(); } -void cc1100_after_send(void) +void cc110x_after_send(void) { // Enable GDO2 interrupt after sending packet - cc1100_gdo2_enable(); + cc110x_gdo2_enable(); } -int cc1100_get_gdo0(void) { +int cc110x_get_gdo0(void) { return CC1100_GDO0; } -int cc1100_get_gdo1(void) { +int cc110x_get_gdo1(void) { return CC1100_GDO1; } -int cc1100_get_gdo2(void) { +int cc110x_get_gdo2(void) { return CC1100_GDO2; } -void cc1100_spi_cs(void) +void cc110x_spi_cs(void) { CC1100_CS_LOW; } -uint8_t cc1100_txrx(uint8_t data) +uint8_t cc110x_txrx(uint8_t data) { /* Ensure TX Buf is empty */ long c = 0; @@ -103,20 +103,20 @@ uint8_t cc1100_txrx(uint8_t data) while(!(IFG1 & UTXIFG0)) { if (c++ == 1000000) - puts("cc1100_txrx alarm()"); + puts("cc110x_txrx alarm()"); } /* Wait for Byte received */ c = 0; while(!(IFG1 & URXIFG0)) { if (c++ == 1000000) - puts("cc1100_txrx alarm()"); + puts("cc110x_txrx alarm()"); } return RXBUF0; } -void cc1100_spi_select(void) +void cc110x_spi_select(void) { // Switch to GDO mode P3SEL &= ~0x04; @@ -147,11 +147,11 @@ void cc1100_spi_select(void) P3SEL |= 0x04; } -void cc1100_spi_unselect(void) { +void cc110x_spi_unselect(void) { CC1100_CS_HIGH; } -void cc1100_init_interrupts(void) +void cc110x_init_interrupts(void) { unsigned int state = disableIRQ(); /* Disable all interrupts */ P2SEL = 0x00; /* must be <> 1 to use interrupts */ @@ -163,7 +163,7 @@ void cc1100_init_interrupts(void) restoreIRQ(state); /* Enable all interrupts */ } -void cc1100_spi_init(uint8_t clockrate) +void cc110x_spi_init(uint8_t clockrate) { // Switch off async UART while(!(UTCTL0 & TXEPT)); // Wait for empty UxTXBUF register @@ -197,8 +197,8 @@ void cc1100_spi_init(uint8_t clockrate) // #include // #include // #include "type.h" -// #include "cc1100_defines.h" -// #include "driver_cc1100.h" +// #include "cc110x_defines.h" +// #include "driver_cc110x.h" // #include "driver_system.h" // #include "spi0.h" // @@ -213,17 +213,17 @@ void cc1100_spi_init(uint8_t clockrate) // // void spiInitTrx(void) // // // // DESCRIPTION: -// // This function puts the cc1100 into spi mode. You have to call this bevore every spi transaction. +// // This function puts the cc110x into spi mode. You have to call this bevore every spi transaction. // // // //------------------------------------------------------------------------------------------------------- // // -// void drivercc1100_spiwriteburstreg(uint8_t addr, unsigned char *buffer, uint8_t count) +// void drivercc110x_spiwriteburstreg(uint8_t addr, unsigned char *buffer, uint8_t count) // { // uint8_t i; // long c; -// drivercc1100_spiinittrx(); -// drivercc1100_trxspi(addr | CC1100_WRITE_BURST); +// drivercc110x_spiinittrx(); +// drivercc110x_trxspi(addr | CC1100_WRITE_BURST); // for (i = 0; i < count; i++) // { // c = 0; @@ -247,11 +247,11 @@ void cc1100_spi_init(uint8_t clockrate) // CC1100_CS_HIGH; // } // -// void drivercc1100_spireadburstreg(uint8_t addr, char *buffer, uint8_t count) +// void drivercc110x_spireadburstreg(uint8_t addr, char *buffer, uint8_t count) // { // uint8_t i; -// drivercc1100_spiinittrx(); -// drivercc1100_trxspi(addr | CC1100_READ_BURST); +// drivercc110x_spiinittrx(); +// drivercc110x_trxspi(addr | CC1100_READ_BURST); // for (i = 0; i < count; i++) // { // long c = 0; @@ -275,21 +275,21 @@ void cc1100_spi_init(uint8_t clockrate) // CC1100_CS_HIGH; // } // -// void drivercc1100_load(callback_t cs_cb,callback_t paket_cb) +// void drivercc110x_load(callback_t cs_cb,callback_t paket_cb) // { // _paket_cb = paket_cb; // _cs_cb = cs_cb; // spi0_init(0); // } // -// void drivercc1100_aftersend(void) +// void drivercc110x_aftersend(void) // { // CLEAR(P2IFG, 0x01); // SET(P2IE, 0x01); /* Enable interrupts on port 2 pin 0 */ // CLEAR(P4OUT, 0x08); /* Turn off Sending Led*/ // } // -// void drivercc1100_initinterrupts(void) +// void drivercc110x_initinterrupts(void) // { // _DINT(); /* Disable all interrupts */ // P2SEL = 0x00; /* must be <> 1 to use interrupts */ @@ -301,7 +301,7 @@ void cc1100_spi_init(uint8_t clockrate) // _EINT(); /* Enable all interrupts */ // } // -// void drivercc1100_beforesend(void) +// void drivercc110x_beforesend(void) // { // /* Turn on Led while sending paket for debug reasons */ // SET(P4OUT, 0x08); @@ -319,21 +319,21 @@ void cc1100_spi_init(uint8_t clockrate) /* * CC1100 receive interrupt */ -interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc1100_isr(void){ +interrupt (PORT2_VECTOR) __attribute__ ((naked)) cc110x_isr(void){ __enter_isr(); -puts("cc1100_isr()"); +puts("cc110x_isr()"); // if (system_state.POWERDOWN) SPI_INIT; /* Initialize SPI after wakeup */ /* Check IFG */ if ((P2IFG & 0x01) != 0) { P2IFG &= ~0x01; - cc1100_gdo2_irq(); + cc110x_gdo2_irq(); } else if ((P2IFG & 0x02) != 0) { - cc1100_gdo0_irq(); + cc110x_gdo0_irq(); P2IE &= ~0x02; // Disable interrupt for GDO0 P2IFG &= ~0x02; // Clear IFG for GDO0 } else { - puts("cc1100_isr(): unexpected IFG!"); + puts("cc110x_isr(): unexpected IFG!"); /* Should not occur - only Port 2 Pin 0 interrupts are enabled */ // CLEAR(P2IFG, 0xFF); /* Clear all flags */ } diff --git a/msba2-common/drivers/Jamfile b/msba2-common/drivers/Jamfile index c0f4138ab9..ed8e73498a 100644 --- a/msba2-common/drivers/Jamfile +++ b/msba2-common/drivers/Jamfile @@ -1,6 +1,6 @@ SubDir TOP board msba2-common drivers ; -Module board_cc1100 : msba2-cc1100.c : cc110x_spi gpioint ; +Module board_cc110x : msba2-cc110x.c : cc110x_spi gpioint ; Module board_ltc4150 : msba2-ltc4150.c : gpioint ; Module board_uart : msba2-uart0.c : chardev_thread ringbuffer ; diff --git a/msba2-common/drivers/msba2-cc1100.c b/msba2-common/drivers/msba2-cc110x.c similarity index 86% rename from msba2-common/drivers/msba2-cc1100.c rename to msba2-common/drivers/msba2-cc110x.c index 327720c1f3..7d5a6b2196 100644 --- a/msba2-common/drivers/msba2-cc1100.c +++ b/msba2-common/drivers/msba2-cc110x.c @@ -34,7 +34,7 @@ and the mailinglist (subscription via web site) * @author Thomas Hillebrandt * @version $Revision: 1781 $ * - * @note $Id: msba2-cc1100.c 1781 2010-01-26 13:39:36Z hillebra $ + * @note $Id: msba2-cc110x.c 1781 2010-01-26 13:39:36Z hillebra $ */ #include @@ -43,10 +43,10 @@ and the mailinglist (subscription via web site) #include #include // sys -#include "cc1100.h" -#include "arch_cc1100.h" -#include "cc1100_spi.h" -#include "gpioint.h" +#include +#include +#include +#include #define CC1100_GDO0 (FIO0PIN & BIT27) // read serial I/O (GDO0) #define CC1100_GDO1 (FIO1PIN & BIT23) // read serial I/O (GDO1) @@ -82,19 +82,19 @@ static int test_time(int code) { } #endif -int cc1100_get_gdo0(void) { +int cc110x_get_gdo0(void) { return CC1100_GDO0; } -int cc1100_get_gdo1(void) { +int cc110x_get_gdo1(void) { return CC1100_GDO1; } -int cc1100_get_gdo2(void) { +int cc110x_get_gdo2(void) { return CC1100_GDO2; } -void cc1100_spi_init(void) +void cc110x_spi_init(void) { // configure chip-select FIO1DIR |= BIT21; @@ -128,7 +128,7 @@ void cc1100_spi_init(void) } } -uint8_t cc1100_txrx(uint8_t c) { +uint8_t cc110x_txrx(uint8_t c) { uint8_t result; SSP0DR = c; #ifdef DEBUG @@ -159,13 +159,13 @@ uint8_t cc1100_txrx(uint8_t c) { return result; } -void cc1100_spi_cs(void) +void cc110x_spi_cs(void) { FIO1CLR = BIT21; } void -cc1100_spi_select(void) +cc110x_spi_select(void) { volatile int retry_count = 0; volatile int abort_count; @@ -199,44 +199,44 @@ cc1100_spi_select(void) } void -cc1100_spi_unselect(void) +cc110x_spi_unselect(void) { FIO1SET = BIT21; } -void cc1100_before_send(void) +void cc110x_before_send(void) { // Disable GDO2 interrupt before sending packet - cc1100_gdo2_disable(); + cc110x_gdo2_disable(); } -void cc1100_after_send(void) +void cc110x_after_send(void) { // Enable GDO2 interrupt after sending packet - cc1100_gdo2_enable(); + cc110x_gdo2_enable(); } -void cc1100_gdo0_enable(void) { - gpioint_set(0, BIT27, GPIOINT_RISING_EDGE, &cc1100_gdo0_irq); +void cc110x_gdo0_enable(void) { + gpioint_set(0, BIT27, GPIOINT_RISING_EDGE, &cc110x_gdo0_irq); } -void cc1100_gdo0_disable(void) { +void cc110x_gdo0_disable(void) { gpioint_set(0, BIT27, GPIOINT_DISABLE, NULL); } -void cc1100_gdo2_disable(void) { +void cc110x_gdo2_disable(void) { gpioint_set(0, BIT28, GPIOINT_DISABLE, NULL); } -void cc1100_gdo2_enable(void) { - gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc1100_gdo2_irq); +void cc110x_gdo2_enable(void) { + gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc110x_gdo2_irq); } -void cc1100_init_interrupts(void) +void cc110x_init_interrupts(void) { // Enable external interrupt on low edge (for GDO2) FIO0DIR &= ~BIT28; - cc1100_gdo2_enable(); + cc110x_gdo2_enable(); // Enable external interrupt on low edge (for GDO0) FIO0DIR &= ~BIT27; } From 8e74db43472219d6fcec1e7b225b9bef554f6c88 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 11 Dec 2010 13:38:04 +0100 Subject: [PATCH 039/188] [board/chronos/drivers/display] * cleaned up code and documentation [drivers/cc110x_ng] * fixed include pathes --- chronos/drivers/display.c | 550 ++++++++++++++----------------------- chronos/drivers/display.h | 310 ++++++++++++++------- chronos/drivers/display1.c | 219 +++++++-------- 3 files changed, 513 insertions(+), 566 deletions(-) diff --git a/chronos/drivers/display.c b/chronos/drivers/display.c index 1473703e4b..39774279b3 100644 --- a/chronos/drivers/display.c +++ b/chronos/drivers/display.c @@ -1,514 +1,382 @@ -// ************************************************************************************************* -// -// 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. -// -// ************************************************************************************************* -// Display functions. -// ************************************************************************************************* +/* ************************************************************************************************* + * + * 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. + * ************************************************************************************************/ +/* ************************************************************************************************* + * Include section + */ -// ************************************************************************************************* -// Include section - -// system +/* system */ #include -// driver +/* driver */ #include #include -// ************************************************************************************************* -// Prototypes section +/************************************************************************************************** + * Prototypes section */ void write_lcd_mem(uint8_t *lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state); void clear_line(uint8_t line); void display_symbol(uint8_t symbol, uint8_t mode); -// ************************************************************************************************* -// Defines section +/* ************************************************************************************************* + * Global Variable section */ - - -// ************************************************************************************************* -// Global Variable section - -// Display flags +/* Display flags */ volatile s_display_flags display; -// Global return string for itoa function -uint8_t itoa_str[8]; +/* Global return string for itoa function */ +char itoa_str[8]; - - -// ************************************************************************************************* -// @fn lcd_init -// @brief Erase LCD memory. Init LCD peripheral. -// @param none -// @return none -// ************************************************************************************************* -void lcd_init(void) -{ - // Clear entire display memory +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 + /* 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 + /* LCB_BLK_FREQ = ACLK/8/4096 = 1Hz */ LCDBBLKCTL = LCDBLKPRE0 | LCDBLKPRE1 | LCDBLKDIV0 | LCDBLKDIV1 | LCDBLKDIV2 | LCDBLKMOD0; - // I/O to COM outputs + /* 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 + /* 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 + /* Charge pump voltage generated internally, internal bias (V2-V4) generation */ LCDBVCTL = LCDCPEN | VLCD_2_72; #endif } - -// ************************************************************************************************* -// @fn clear_display_all -// @brief Erase LINE1 and LINE2 segments. Clear also function-specific content. -// @param none -// @return none -// ************************************************************************************************* -void clear_display_all(void) -{ +void clear_display_all(void) { // Clear generic content clear_line(LINE1); clear_line(LINE2); - - } - -// ************************************************************************************************* -// @fn clear_display -// @brief Erase LINE1 and LINE2 segments. Keep icons. -// @param none -// @return none -// ************************************************************************************************* -void clear_display(void) -{ +void clear_display(void) { clear_line(LINE1); clear_line(LINE2); } - -// ************************************************************************************************* -// @fn clear_line -// @brief Erase segments of a given line. -// @param uint8_t line LINE1, LINE2 -// @return none -// ************************************************************************************************* -void clear_line(uint8_t line) -{ +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) - { + 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); } - else // line == LINE2 - { + /* 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); } } - -// ************************************************************************************************* -// @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 -// ************************************************************************************************* -void write_lcd_mem(uint8_t * lcdmem, uint8_t bits, uint8_t bitmask, uint8_t state) -{ - if (state == SEG_ON) - { - // Clear segments before writing +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 + /* Set visible segments */ *lcdmem = (uint8_t)(*lcdmem | bits); } - else if (state == SEG_OFF) - { - // Clear segments + 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 + 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 + /* 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 + else if (state == SEG_ON_BLINK_OFF) { + /* Clear visible segments before writing */ *lcdmem = (uint8_t)(*lcdmem & ~bitmask); - // Set visible segments + /* Set visible segments */ *lcdmem = (uint8_t)(*lcdmem | bits); - // Clear blink segments + /* Clear blink segments */ *(lcdmem+0x20) = (uint8_t)(*(lcdmem+0x20) & ~bitmask); } - else if (state == SEG_OFF_BLINK_OFF) - { - // Clear segments + else if (state == SEG_OFF_BLINK_OFF) { + /* Clear segments */ *lcdmem = (uint8_t)(*lcdmem & ~bitmask); - // Clear blink segments + /* Clear blink segments */ *(lcdmem+0x20) = (uint8_t)(*(lcdmem+0x20) & ~bitmask); } } - -// ************************************************************************************************* -// @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 -// ************************************************************************************************* -uint8_t * itoa(uint32_t n, uint8_t digits, uint8_t blanks) -{ +char *itoa(uint32_t n, uint8_t digits, uint8_t blanks) { uint8_t i; uint8_t digits1 = digits; - // Preset result string + /* 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); + /* 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) - { + /* 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); } - else // digits == 1 || 2 - { + /* digits == 1 || 2 */ + else { memcpy(itoa_str, itoa_conversion_table[n]+(3-digits), digits); } } - else // For n > 180 need to calculate string content - { - // Calculate digits from least to most significant number - do - { + /* 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 + /* 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' + 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); } - -// ************************************************************************************************* -// @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 -// @return none -// ************************************************************************************************* -void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) -{ - uint8_t* 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, (char*) str, disp_mode); + /* Display string in blink mode */ + display_chars(segments, str, disp_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 -// @return none -// ************************************************************************************************* -void display_symbol(uint8_t symbol, uint8_t mode) -{ - uint8_t * lcdmem; +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]; + 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 + /* Get bits for symbol from table */ bits = segments_bitmask[symbol]; - // Bitmask for symbols equals bits + /* Bitmask for symbols equals bits */ bitmask = bits; - // Write LCD memory + /* Write LCD memory */ write_lcd_mem(lcdmem, bits, bitmask, mode); } } - -// ************************************************************************************************* -// @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 -// @return none -// ************************************************************************************************* -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 +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]; + /* 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 + /* Get bitmask for character from table */ bitmask = segments_bitmask[segment]; - // Get bits from font set - if ((chr >= 0x30) && (chr <= 0x5A)) - { - // Use font set + /* 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 + else if (chr == 0x2D) { + /* '-' not in font set */ bits = BIT1; } - else - { - // Other characters map to ' ' (blank) + 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) - { + /* 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) - { + /* 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 + /* Physically write to LCD memory */ write_lcd_mem(lcdmem, bits, bitmask, 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 -// @return none -// ************************************************************************************************* 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 + 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; break; - 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; break; - case LCD_SEG_L1_3_2: length=2; char_start=LCD_SEG_L1_3; break; + 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; + break; + 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; + break; + 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; break; - 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; break; - 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; break; - 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; break; - 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; break; + /* 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; + break; + 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; + break; + 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; + break; + 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; + break; + case LCD_SEG_L2_4_2: + length=3; + char_start=LCD_SEG_L2_4; + break; } - // Write to consecutive digits - for(i=0; i +#include +/* ************************************************************************************************* */ +/* Global Variable section */ -// driver -#include "display.h" - - -// ************************************************************************************************* -// Prototypes section - - -// ************************************************************************************************* -// Defines section - - - -// ************************************************************************************************* -// Global Variable section - -// Table with memory bit assignment for digits "0" to "9" and characters "A" to "Z" -// A -// F B -// G -// 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 +/* Table with memory bit assignment for digits "0" to "9" and characters "A" to "Z" */ +/* A */ +/* F B */ +/* G */ +/* 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 */ }; - -// Table with memory address for each display element -const uint8_t * segments_lcdmem[] = -{ +/* 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, @@ -158,10 +142,8 @@ const uint8_t * segments_lcdmem[] = LCD_SEG_L2_DP_MEM, }; - -// Table with bit mask for each display element -const uint8_t segments_bitmask[] = -{ +/* 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, @@ -206,10 +188,10 @@ const uint8_t segments_bitmask[] = LCD_SEG_L2_DP_MASK, }; - -// Quick integer to array conversion table for most common integer values -const uint8_t itoa_conversion_table[][3] = -{ +/* 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", @@ -223,4 +205,3 @@ const uint8_t itoa_conversion_table[][3] = "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", }; - From 5185fcf7f0fc28f0ea98096de59419dceb9d499f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 13 Dec 2010 01:30:46 +0100 Subject: [PATCH 040/188] [board/msb-430h] * fixed include --- msb-430h/driver_cc110x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msb-430h/driver_cc110x.c b/msb-430h/driver_cc110x.c index a0967b272f..9316e8bf56 100644 --- a/msb-430h/driver_cc110x.c +++ b/msb-430h/driver_cc110x.c @@ -24,7 +24,7 @@ Boston, MA 02111-1307, USA. */ #include #include -#include +#include #define CC1100_GDO0 (P2IN & 0x02) // read serial I/O (GDO0) #define CC1100_GDO1 (P3IN & 0x04) // read serial I/O (GDO1) From 7b5f3900adeee7a161259f0ae7cb14ab4ed6a69f Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 13 Dec 2010 21:19:58 +0100 Subject: [PATCH 041/188] [board/chronos/drivers] * simple buzzer driver --- chronos/Jamrules.chronos | 2 ++ chronos/drivers/Jamfile | 3 +++ chronos/drivers/buzzer.c | 27 +++++++++++++++++++++++++ chronos/drivers/include/buzzer.h | 6 ++++++ chronos/drivers/{ => include}/display.h | 0 5 files changed, 38 insertions(+) create mode 100644 chronos/drivers/buzzer.c create mode 100644 chronos/drivers/include/buzzer.h rename chronos/drivers/{ => include}/display.h (100%) diff --git a/chronos/Jamrules.chronos b/chronos/Jamrules.chronos index 4c975ae1f9..4c17a9a9ae 100644 --- a/chronos/Jamrules.chronos +++ b/chronos/Jamrules.chronos @@ -7,6 +7,8 @@ BOARD = chronos ; CPU = cc430 ; MCU = cc430x6137 ; +HDRS += [ FPath $(TOP) board chronos drivers include ] ; + FLASHER ?= mspdebug ; FLASHFLAGS ?= rf2500 ; diff --git a/chronos/drivers/Jamfile b/chronos/drivers/Jamfile index 4b2a0d0a85..d89390029d 100644 --- a/chronos/drivers/Jamfile +++ b/chronos/drivers/Jamfile @@ -1,4 +1,7 @@ SubDir TOP board chronos drivers ; +HDRS += $(TOP)/board/$(CPU)/drivers/include ; + Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; +Module board_buzzer : buzzer.c : hwtimer ; diff --git a/chronos/drivers/buzzer.c b/chronos/drivers/buzzer.c new file mode 100644 index 0000000000..79002f992c --- /dev/null +++ b/chronos/drivers/buzzer.c @@ -0,0 +1,27 @@ +#include +#include +#include + +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 + TA1CCR0 = pitch; + + // Enable IRQ, set output mode "toggle" + TA1CCTL0 = OUTMOD_4; + + // Allow buzzer PWM output on P2.7 + P2SEL |= BIT7; + + hwtimer_wait(duration); + + // Stop PWM timer + TA1CTL &= ~(BIT4 | BIT5); + + // Reset and disable buzzer PWM output + P2OUT &= ~BIT7; + P2SEL &= ~BIT7; + TA1CCTL0 &= ~CCIE; +} diff --git a/chronos/drivers/include/buzzer.h b/chronos/drivers/include/buzzer.h new file mode 100644 index 0000000000..1786b0c513 --- /dev/null +++ b/chronos/drivers/include/buzzer.h @@ -0,0 +1,6 @@ +#ifndef BUZZER_H +#define BUZZER_H + +void buzzer_beep(uint8_t pitch, uint16_t duration); + +#endif /* BUZZER_H */ diff --git a/chronos/drivers/display.h b/chronos/drivers/include/display.h similarity index 100% rename from chronos/drivers/display.h rename to chronos/drivers/include/display.h From d2e45cdf5942870739e13651c5edd24f5276550c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 14 Dec 2010 00:24:42 +0100 Subject: [PATCH 042/188] [cpu/cc430/gpioint] * introduced gpioint to make buttons usable --- chronos/drivers/buzzer.c | 1 + chronos/include/buttons.h | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 chronos/include/buttons.h diff --git a/chronos/drivers/buzzer.c b/chronos/drivers/buzzer.c index 79002f992c..5e0bc2ca34 100644 --- a/chronos/drivers/buzzer.c +++ b/chronos/drivers/buzzer.c @@ -1,5 +1,6 @@ #include #include +#include #include void buzzer_beep(uint8_t pitch, uint16_t duration) { diff --git a/chronos/include/buttons.h b/chronos/include/buttons.h new file mode 100644 index 0000000000..4e7ab28dca --- /dev/null +++ b/chronos/include/buttons.h @@ -0,0 +1,11 @@ +#ifndef BUTTONS_H +#define BUTTONS_H + +// Button ports +#define BUTTON_STAR_PIN (BIT2) +#define BUTTON_NUM_PIN (BIT1) +#define BUTTON_UP_PIN (BIT4) +#define BUTTON_DOWN_PIN (BIT0) +#define BUTTON_BACKLIGHT_PIN (BIT3) + +#endif From 6ff96f0ab104064b55851e32e2ffb625a3e370c8 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 11:39:52 +0100 Subject: [PATCH 043/188] * minor file rename --- msb-430-common/Jamfile | 2 +- msb-430-common/{debug_uart.c => uart1.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename msb-430-common/{debug_uart.c => uart1.c} (100%) diff --git a/msb-430-common/Jamfile b/msb-430-common/Jamfile index 17bf86c9bb..b59f8c4748 100644 --- a/msb-430-common/Jamfile +++ b/msb-430-common/Jamfile @@ -27,7 +27,7 @@ SubDir TOP board msb-430-common ; -Module board : board_init.c debug_uart.c ; +Module board : board_init.c uart1.c ; Module board_config : board_config.c ; UseModule board ; diff --git a/msb-430-common/debug_uart.c b/msb-430-common/uart1.c similarity index 100% rename from msb-430-common/debug_uart.c rename to msb-430-common/uart1.c From b473e44b561a74dd60616b2c0f95eab6d0749991 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 16:40:47 +0100 Subject: [PATCH 044/188] * chronos display putchar included --- chronos/Jamfile | 2 +- chronos/drivers/Jamfile | 2 ++ chronos/drivers/display_putchar.c | 42 +++++++++++++++++++++++ chronos/drivers/include/display_putchar.h | 6 ++++ chronos/putchar.c | 11 ++++++ msb-430-common/putchar.c | 7 ++++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 chronos/drivers/display_putchar.c create mode 100644 chronos/drivers/include/display_putchar.h create mode 100644 chronos/putchar.c create mode 100644 msb-430-common/putchar.c diff --git a/chronos/Jamfile b/chronos/Jamfile index bf3341d785..0899e4631b 100644 --- a/chronos/Jamfile +++ b/chronos/Jamfile @@ -2,7 +2,7 @@ SubDir TOP board chronos ; HDRS += $(TOP)/board/$(CPU)/include ; -Module board : debug_uart.c board_init.c ; +Module board : putchar.c board_init.c ; UseModule board ; SubInclude TOP board $(BOARD) drivers ; diff --git a/chronos/drivers/Jamfile b/chronos/drivers/Jamfile index d89390029d..54d2fb4e7b 100644 --- a/chronos/drivers/Jamfile +++ b/chronos/drivers/Jamfile @@ -5,3 +5,5 @@ HDRS += $(TOP)/board/$(CPU)/drivers/include ; Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; + +Module display_putchar : display_putchar.c : board_display ; diff --git a/chronos/drivers/display_putchar.c b/chronos/drivers/display_putchar.c new file mode 100644 index 0000000000..2f1d9468af --- /dev/null +++ b/chronos/drivers/display_putchar.c @@ -0,0 +1,42 @@ +#include +#include +#include + +extern int toupper(int c); +extern void (*_putchar)(int c); + +static char display_buf[11]; + +void putchar_to_display(); + +void init_display_putchar() { + memset(display_buf, '\0', 11); + _putchar = putchar_to_display; +} + +void putchar_to_display(int c) { + if (c == '\n') { + display_buf[4] = 1; + return; + } + + if (display_buf[4]) { + memset(display_buf, '\0', 11); + } else { + display_buf[0] = display_buf[1]; + display_buf[1] = display_buf[2]; + display_buf[2] = display_buf[3]; + display_buf[3] = display_buf[5]; + display_buf[5] = display_buf[6]; + display_buf[6] = display_buf[7]; + display_buf[7] = display_buf[8]; + display_buf[8] = display_buf[9]; + } + + display_buf[9] = toupper(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); +} diff --git a/chronos/drivers/include/display_putchar.h b/chronos/drivers/include/display_putchar.h new file mode 100644 index 0000000000..6adbb9c9c0 --- /dev/null +++ b/chronos/drivers/include/display_putchar.h @@ -0,0 +1,6 @@ +#ifndef __DISPLAY_PUTCHAR_H +#define __DISPLAY_PUTCHAR_H + +void init_display_putchar(); + +#endif /* __DISPLAY_PUTCHAR_H */ diff --git a/chronos/putchar.c b/chronos/putchar.c new file mode 100644 index 0000000000..436d350f51 --- /dev/null +++ b/chronos/putchar.c @@ -0,0 +1,11 @@ +static void _dummy(int c) { +} + +void (*_putchar)(int c) = _dummy; + +int putchar(int c) +{ + _putchar(c); + return c; +} + diff --git a/msb-430-common/putchar.c b/msb-430-common/putchar.c new file mode 100644 index 0000000000..4193c0db42 --- /dev/null +++ b/msb-430-common/putchar.c @@ -0,0 +1,7 @@ +#include + +void (_putchar(int)) = uart1_putchar; + +void putchar(int c) { + _putchar(c); +} From 7d1da05452bcb50ccf438ba7534e83585c1b351e Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 14 Dec 2010 16:41:06 +0100 Subject: [PATCH 045/188] file obsoleted --- chronos/debug_uart.c | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 chronos/debug_uart.c diff --git a/chronos/debug_uart.c b/chronos/debug_uart.c deleted file mode 100644 index d80c9c6e83..0000000000 --- a/chronos/debug_uart.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include "board.h" - -#define UART1_TX TXBUF1 -#define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); } - - -int putchar(int c) -{ -// UART1_TX = c; -// UART1_WAIT_TXDONE(); -// -// if (c == 10) { -// UART1_TX = 13; -// UART1_WAIT_TXDONE(); -// } - - return c; -} - - From fd8224303767ef225dbbc0eddf41754a66da0775 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 14 Dec 2010 16:44:32 +0100 Subject: [PATCH 046/188] * moved flashrom from msp430-common to msb430x16x --- msb-430-common/Jamfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msb-430-common/Jamfile b/msb-430-common/Jamfile index 17bf86c9bb..147e49ea23 100644 --- a/msb-430-common/Jamfile +++ b/msb-430-common/Jamfile @@ -28,7 +28,7 @@ SubDir TOP board msb-430-common ; Module board : board_init.c debug_uart.c ; -Module board_config : board_config.c ; +Module board_config : board_config.c : flashrom ; UseModule board ; SubInclude TOP cpu $(CPU) ; From 27afca63aacd80388643364dbfb1b5070b1c0e5e Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 17 Dec 2010 13:38:03 +0100 Subject: [PATCH 047/188] [board/chronos] * introduced battery driver --- chronos/drivers/Jamfile | 1 + chronos/drivers/battery.c | 13 +++++++++++++ chronos/drivers/include/battery.h | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 chronos/drivers/battery.c create mode 100644 chronos/drivers/include/battery.h diff --git a/chronos/drivers/Jamfile b/chronos/drivers/Jamfile index 54d2fb4e7b..286616c5d9 100644 --- a/chronos/drivers/Jamfile +++ b/chronos/drivers/Jamfile @@ -5,5 +5,6 @@ HDRS += $(TOP)/board/$(CPU)/drivers/include ; Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; +Module battery : battery.c : adc hwtimer ; Module display_putchar : display_putchar.c : board_display ; diff --git a/chronos/drivers/battery.c b/chronos/drivers/battery.c new file mode 100644 index 0000000000..69553fc451 --- /dev/null +++ b/chronos/drivers/battery.c @@ -0,0 +1,13 @@ +#include +#include +#include + +uint16_t battery_get_voltate(void) { + uint16_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; + return voltage; +} diff --git a/chronos/drivers/include/battery.h b/chronos/drivers/include/battery.h new file mode 100644 index 0000000000..6b206c6eca --- /dev/null +++ b/chronos/drivers/include/battery.h @@ -0,0 +1,6 @@ +#ifndef BATTERY_H +#define BATTERY_H + +uint16_t battery_get_voltate(void); + +#endif /* BATTERY_H */ From 1933006138e282f932afd9a91fec8b727284a06b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 31 Jan 2011 18:25:20 +0100 Subject: [PATCH 048/188] * introduced energy profiling (yet in a very early state) --- msba2-common/drivers/msba2-ltc4150.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/msba2-common/drivers/msba2-ltc4150.c b/msba2-common/drivers/msba2-ltc4150.c index c590dee8db..4e6534c022 100644 --- a/msba2-common/drivers/msba2-ltc4150.c +++ b/msba2-common/drivers/msba2-ltc4150.c @@ -45,19 +45,19 @@ and the mailinglist (subscription via web site) #include "ltc4150_arch.h" #include "gpioint.h" -void ltc4150_disable_int(void) { +void __attribute__((__no_instrument_function__)) ltc4150_disable_int(void) { gpioint_set(0, BIT4, GPIOINT_DISABLE, NULL); } -void ltc4150_enable_int(void) { +void __attribute__((__no_instrument_function__)) ltc4150_enable_int(void) { gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, <c4150_interrupt); } -void ltc4150_sync_blocking(void) { +void __attribute__((__no_instrument_function__)) ltc4150_sync_blocking(void) { while(!(FIO0PIN & BIT4)) {}; } -void ltc4150_arch_init() { +void __attribute__((__no_instrument_function__)) ltc4150_arch_init() { FIO0DIR |= BIT5; FIO0SET = BIT5; } From 0a05f0901e2d815bf2cda77d017cc327dbcfb18c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 4 Mar 2011 16:46:20 +0100 Subject: [PATCH 049/188] [board msba2] * fixed header guards [drivers ltc4150] * added joule conversion --- msba2-common/include/msba2_common.h | 6 +++--- msba2/include/board.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/msba2-common/include/msba2_common.h b/msba2-common/include/msba2_common.h index a9d9d3e72c..fff12f965d 100644 --- a/msba2-common/include/msba2_common.h +++ b/msba2-common/include/msba2_common.h @@ -24,8 +24,8 @@ and the mailinglist (subscription via web site) scatterweb@lists.spline.inf.fu-berlin.de *******************************************************************************/ -#ifndef __BOARD_H -#define __BOARD_H +#ifndef __MSBA2_COMMON_H +#define __MSBA2_COMMON_H /** * @ingroup msb_a2 @@ -48,4 +48,4 @@ and the mailinglist (subscription via web site) #define VICIntEnClear VICIntEnClr /** @} */ -#endif // __BOARD_H +#endif // __MSBA2_COMMON_H diff --git a/msba2/include/board.h b/msba2/include/board.h index bf596f0ee1..2b1f28fd2a 100644 --- a/msba2/include/board.h +++ b/msba2/include/board.h @@ -2,6 +2,7 @@ #define __BOARD_H #include +#include #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) From cdab9a9a885a4d630610c3dbf2e22c510dc3eabe Mon Sep 17 00:00:00 2001 From: Stephan Zeisberg Date: Tue, 8 Mar 2011 11:43:21 +0100 Subject: [PATCH 050/188] changed types irq_callback, hashtable, posix_io, s_display_flags, seq_buffer_entry, tcb, toprint to type_t" --- chronos/drivers/display.c | 2 +- chronos/drivers/include/display.h | 4 ++-- msba2-common/drivers/msba2-uart0.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/chronos/drivers/display.c b/chronos/drivers/display.c index 39774279b3..063ade5855 100644 --- a/chronos/drivers/display.c +++ b/chronos/drivers/display.c @@ -57,7 +57,7 @@ void display_symbol(uint8_t symbol, uint8_t mode); * Global Variable section */ /* Display flags */ -volatile s_display_flags display; +volatile s_display_flags_t display; /* Global return string for itoa function */ char itoa_str[8]; diff --git a/chronos/drivers/include/display.h b/chronos/drivers/include/display.h index 805d801d2e..3b7c2e131f 100644 --- a/chronos/drivers/include/display.h +++ b/chronos/drivers/include/display.h @@ -67,9 +67,9 @@ typedef union { 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; +} s_display_flags_t; -extern volatile s_display_flags display; +extern volatile s_display_flags_t display; // Constants defined in library extern const uint8_t lcd_font[]; diff --git a/msba2-common/drivers/msba2-uart0.c b/msba2-common/drivers/msba2-uart0.c index 3107e8d40c..31a9870aaf 100644 --- a/msba2-common/drivers/msba2-uart0.c +++ b/msba2-common/drivers/msba2-uart0.c @@ -49,13 +49,13 @@ and the mailinglist (subscription via web site) * @note $Id$ */ -typedef struct toprint { +typedef struct toprint_t { unsigned int len; char content[]; -}toprint; +}toprint_t; #define QUEUESIZE 255 -static volatile toprint* 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,7 +64,7 @@ static volatile unsigned int actual_pos = 0; static volatile unsigned int running = 0; static volatile unsigned int fifo = 0; -static volatile toprint* actual = NULL; +static volatile toprint_t* actual = NULL; static inline void enqueue(void) { queue_items++; From 34ad51eca5f25e2f7b3797140e422286ff400246 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Fri, 18 Mar 2011 15:59:50 +0100 Subject: [PATCH 051/188] * some changes to chronos (not yet finished) --- chronos/drivers/Jamfile | 1 + chronos/drivers/battery.c | 4 ++-- chronos/drivers/include/battery.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/chronos/drivers/Jamfile b/chronos/drivers/Jamfile index 286616c5d9..71ee1c982c 100644 --- a/chronos/drivers/Jamfile +++ b/chronos/drivers/Jamfile @@ -6,5 +6,6 @@ Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; Module board_buzzer : buzzer.c : hwtimer ; Module battery : battery.c : adc hwtimer ; +Module vti_ps_twi : vti_ps_twi.c : hwtimer ; Module display_putchar : display_putchar.c : board_display ; diff --git a/chronos/drivers/battery.c b/chronos/drivers/battery.c index 69553fc451..bae37d3295 100644 --- a/chronos/drivers/battery.c +++ b/chronos/drivers/battery.c @@ -2,8 +2,8 @@ #include #include -uint16_t battery_get_voltate(void) { - uint16_t voltage; +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 diff --git a/chronos/drivers/include/battery.h b/chronos/drivers/include/battery.h index 6b206c6eca..c6381b721b 100644 --- a/chronos/drivers/include/battery.h +++ b/chronos/drivers/include/battery.h @@ -1,6 +1,6 @@ #ifndef BATTERY_H #define BATTERY_H -uint16_t battery_get_voltate(void); +uint32_t battery_get_voltage(void); #endif /* BATTERY_H */ From 04bcd7718a958c79909cab250d8e2cee6148fbe8 Mon Sep 17 00:00:00 2001 From: mlenders Date: Sun, 10 Jul 2011 22:49:41 +0200 Subject: [PATCH 052/188] merged --- chronos/Jamfile | 2 +- chronos/Jamrules.chronos | 2 ++ chronos/debug_uart.c | 21 ------------ chronos/drivers/Jamfile | 7 ++++ chronos/drivers/battery.c | 13 +++++++ chronos/drivers/buzzer.c | 28 +++++++++++++++ chronos/drivers/display.c | 2 +- chronos/drivers/display_putchar.c | 42 +++++++++++++++++++++++ chronos/drivers/include/battery.h | 6 ++++ chronos/drivers/include/buzzer.h | 6 ++++ chronos/drivers/{ => include}/display.h | 4 +-- chronos/drivers/include/display_putchar.h | 6 ++++ chronos/include/buttons.h | 11 ++++++ chronos/putchar.c | 11 ++++++ msb-430-common/Jamfile | 4 +-- msb-430-common/putchar.c | 7 ++++ msb-430-common/{debug_uart.c => uart1.c} | 0 msba2-common/drivers/msba2-ltc4150.c | 8 ++--- msba2-common/drivers/msba2-uart0.c | 8 ++--- msba2-common/include/msba2_common.h | 6 ++-- msba2/include/board.h | 1 + 21 files changed, 157 insertions(+), 38 deletions(-) delete mode 100644 chronos/debug_uart.c create mode 100644 chronos/drivers/battery.c create mode 100644 chronos/drivers/buzzer.c create mode 100644 chronos/drivers/display_putchar.c create mode 100644 chronos/drivers/include/battery.h create mode 100644 chronos/drivers/include/buzzer.h rename chronos/drivers/{ => include}/display.h (99%) create mode 100644 chronos/drivers/include/display_putchar.h create mode 100644 chronos/include/buttons.h create mode 100644 chronos/putchar.c create mode 100644 msb-430-common/putchar.c rename msb-430-common/{debug_uart.c => uart1.c} (100%) diff --git a/chronos/Jamfile b/chronos/Jamfile index bf3341d785..0899e4631b 100644 --- a/chronos/Jamfile +++ b/chronos/Jamfile @@ -2,7 +2,7 @@ SubDir TOP board chronos ; HDRS += $(TOP)/board/$(CPU)/include ; -Module board : debug_uart.c board_init.c ; +Module board : putchar.c board_init.c ; UseModule board ; SubInclude TOP board $(BOARD) drivers ; diff --git a/chronos/Jamrules.chronos b/chronos/Jamrules.chronos index 4c975ae1f9..4c17a9a9ae 100644 --- a/chronos/Jamrules.chronos +++ b/chronos/Jamrules.chronos @@ -7,6 +7,8 @@ BOARD = chronos ; CPU = cc430 ; MCU = cc430x6137 ; +HDRS += [ FPath $(TOP) board chronos drivers include ] ; + FLASHER ?= mspdebug ; FLASHFLAGS ?= rf2500 ; diff --git a/chronos/debug_uart.c b/chronos/debug_uart.c deleted file mode 100644 index d80c9c6e83..0000000000 --- a/chronos/debug_uart.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include "board.h" - -#define UART1_TX TXBUF1 -#define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); } - - -int putchar(int c) -{ -// UART1_TX = c; -// UART1_WAIT_TXDONE(); -// -// if (c == 10) { -// UART1_TX = 13; -// UART1_WAIT_TXDONE(); -// } - - return c; -} - - diff --git a/chronos/drivers/Jamfile b/chronos/drivers/Jamfile index 4b2a0d0a85..71ee1c982c 100644 --- a/chronos/drivers/Jamfile +++ b/chronos/drivers/Jamfile @@ -1,4 +1,11 @@ SubDir TOP board chronos drivers ; +HDRS += $(TOP)/board/$(CPU)/drivers/include ; + Module board_display : display.c display1.c ; Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; +Module board_buzzer : buzzer.c : hwtimer ; +Module battery : battery.c : adc hwtimer ; +Module vti_ps_twi : vti_ps_twi.c : hwtimer ; + +Module display_putchar : display_putchar.c : board_display ; diff --git a/chronos/drivers/battery.c b/chronos/drivers/battery.c new file mode 100644 index 0000000000..bae37d3295 --- /dev/null +++ b/chronos/drivers/battery.c @@ -0,0 +1,13 @@ +#include +#include +#include + +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; + return voltage; +} diff --git a/chronos/drivers/buzzer.c b/chronos/drivers/buzzer.c new file mode 100644 index 0000000000..5e0bc2ca34 --- /dev/null +++ b/chronos/drivers/buzzer.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +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 + TA1CCR0 = pitch; + + // Enable IRQ, set output mode "toggle" + TA1CCTL0 = OUTMOD_4; + + // Allow buzzer PWM output on P2.7 + P2SEL |= BIT7; + + hwtimer_wait(duration); + + // Stop PWM timer + TA1CTL &= ~(BIT4 | BIT5); + + // Reset and disable buzzer PWM output + P2OUT &= ~BIT7; + P2SEL &= ~BIT7; + TA1CCTL0 &= ~CCIE; +} diff --git a/chronos/drivers/display.c b/chronos/drivers/display.c index 39774279b3..063ade5855 100644 --- a/chronos/drivers/display.c +++ b/chronos/drivers/display.c @@ -57,7 +57,7 @@ void display_symbol(uint8_t symbol, uint8_t mode); * Global Variable section */ /* Display flags */ -volatile s_display_flags display; +volatile s_display_flags_t display; /* Global return string for itoa function */ char itoa_str[8]; diff --git a/chronos/drivers/display_putchar.c b/chronos/drivers/display_putchar.c new file mode 100644 index 0000000000..2f1d9468af --- /dev/null +++ b/chronos/drivers/display_putchar.c @@ -0,0 +1,42 @@ +#include +#include +#include + +extern int toupper(int c); +extern void (*_putchar)(int c); + +static char display_buf[11]; + +void putchar_to_display(); + +void init_display_putchar() { + memset(display_buf, '\0', 11); + _putchar = putchar_to_display; +} + +void putchar_to_display(int c) { + if (c == '\n') { + display_buf[4] = 1; + return; + } + + if (display_buf[4]) { + memset(display_buf, '\0', 11); + } else { + display_buf[0] = display_buf[1]; + display_buf[1] = display_buf[2]; + display_buf[2] = display_buf[3]; + display_buf[3] = display_buf[5]; + display_buf[5] = display_buf[6]; + display_buf[6] = display_buf[7]; + display_buf[7] = display_buf[8]; + display_buf[8] = display_buf[9]; + } + + display_buf[9] = toupper(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); +} diff --git a/chronos/drivers/include/battery.h b/chronos/drivers/include/battery.h new file mode 100644 index 0000000000..c6381b721b --- /dev/null +++ b/chronos/drivers/include/battery.h @@ -0,0 +1,6 @@ +#ifndef BATTERY_H +#define BATTERY_H + +uint32_t battery_get_voltage(void); + +#endif /* BATTERY_H */ diff --git a/chronos/drivers/include/buzzer.h b/chronos/drivers/include/buzzer.h new file mode 100644 index 0000000000..1786b0c513 --- /dev/null +++ b/chronos/drivers/include/buzzer.h @@ -0,0 +1,6 @@ +#ifndef BUZZER_H +#define BUZZER_H + +void buzzer_beep(uint8_t pitch, uint16_t duration); + +#endif /* BUZZER_H */ diff --git a/chronos/drivers/display.h b/chronos/drivers/include/display.h similarity index 99% rename from chronos/drivers/display.h rename to chronos/drivers/include/display.h index 805d801d2e..3b7c2e131f 100644 --- a/chronos/drivers/display.h +++ b/chronos/drivers/include/display.h @@ -67,9 +67,9 @@ typedef union { 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; +} s_display_flags_t; -extern volatile s_display_flags display; +extern volatile s_display_flags_t display; // Constants defined in library extern const uint8_t lcd_font[]; diff --git a/chronos/drivers/include/display_putchar.h b/chronos/drivers/include/display_putchar.h new file mode 100644 index 0000000000..6adbb9c9c0 --- /dev/null +++ b/chronos/drivers/include/display_putchar.h @@ -0,0 +1,6 @@ +#ifndef __DISPLAY_PUTCHAR_H +#define __DISPLAY_PUTCHAR_H + +void init_display_putchar(); + +#endif /* __DISPLAY_PUTCHAR_H */ diff --git a/chronos/include/buttons.h b/chronos/include/buttons.h new file mode 100644 index 0000000000..4e7ab28dca --- /dev/null +++ b/chronos/include/buttons.h @@ -0,0 +1,11 @@ +#ifndef BUTTONS_H +#define BUTTONS_H + +// Button ports +#define BUTTON_STAR_PIN (BIT2) +#define BUTTON_NUM_PIN (BIT1) +#define BUTTON_UP_PIN (BIT4) +#define BUTTON_DOWN_PIN (BIT0) +#define BUTTON_BACKLIGHT_PIN (BIT3) + +#endif diff --git a/chronos/putchar.c b/chronos/putchar.c new file mode 100644 index 0000000000..436d350f51 --- /dev/null +++ b/chronos/putchar.c @@ -0,0 +1,11 @@ +static void _dummy(int c) { +} + +void (*_putchar)(int c) = _dummy; + +int putchar(int c) +{ + _putchar(c); + return c; +} + diff --git a/msb-430-common/Jamfile b/msb-430-common/Jamfile index 17bf86c9bb..78807c1441 100644 --- a/msb-430-common/Jamfile +++ b/msb-430-common/Jamfile @@ -27,8 +27,8 @@ SubDir TOP board msb-430-common ; -Module board : board_init.c debug_uart.c ; -Module board_config : board_config.c ; +Module board : board_init.c uart1.c ; +Module board_config : board_config.c : flashrom ; UseModule board ; SubInclude TOP cpu $(CPU) ; diff --git a/msb-430-common/putchar.c b/msb-430-common/putchar.c new file mode 100644 index 0000000000..4193c0db42 --- /dev/null +++ b/msb-430-common/putchar.c @@ -0,0 +1,7 @@ +#include + +void (_putchar(int)) = uart1_putchar; + +void putchar(int c) { + _putchar(c); +} diff --git a/msb-430-common/debug_uart.c b/msb-430-common/uart1.c similarity index 100% rename from msb-430-common/debug_uart.c rename to msb-430-common/uart1.c diff --git a/msba2-common/drivers/msba2-ltc4150.c b/msba2-common/drivers/msba2-ltc4150.c index c590dee8db..4e6534c022 100644 --- a/msba2-common/drivers/msba2-ltc4150.c +++ b/msba2-common/drivers/msba2-ltc4150.c @@ -45,19 +45,19 @@ and the mailinglist (subscription via web site) #include "ltc4150_arch.h" #include "gpioint.h" -void ltc4150_disable_int(void) { +void __attribute__((__no_instrument_function__)) ltc4150_disable_int(void) { gpioint_set(0, BIT4, GPIOINT_DISABLE, NULL); } -void ltc4150_enable_int(void) { +void __attribute__((__no_instrument_function__)) ltc4150_enable_int(void) { gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, <c4150_interrupt); } -void ltc4150_sync_blocking(void) { +void __attribute__((__no_instrument_function__)) ltc4150_sync_blocking(void) { while(!(FIO0PIN & BIT4)) {}; } -void ltc4150_arch_init() { +void __attribute__((__no_instrument_function__)) ltc4150_arch_init() { FIO0DIR |= BIT5; FIO0SET = BIT5; } diff --git a/msba2-common/drivers/msba2-uart0.c b/msba2-common/drivers/msba2-uart0.c index 3107e8d40c..31a9870aaf 100644 --- a/msba2-common/drivers/msba2-uart0.c +++ b/msba2-common/drivers/msba2-uart0.c @@ -49,13 +49,13 @@ and the mailinglist (subscription via web site) * @note $Id$ */ -typedef struct toprint { +typedef struct toprint_t { unsigned int len; char content[]; -}toprint; +}toprint_t; #define QUEUESIZE 255 -static volatile toprint* 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,7 +64,7 @@ static volatile unsigned int actual_pos = 0; static volatile unsigned int running = 0; static volatile unsigned int fifo = 0; -static volatile toprint* actual = NULL; +static volatile toprint_t* actual = NULL; static inline void enqueue(void) { queue_items++; diff --git a/msba2-common/include/msba2_common.h b/msba2-common/include/msba2_common.h index a9d9d3e72c..fff12f965d 100644 --- a/msba2-common/include/msba2_common.h +++ b/msba2-common/include/msba2_common.h @@ -24,8 +24,8 @@ and the mailinglist (subscription via web site) scatterweb@lists.spline.inf.fu-berlin.de *******************************************************************************/ -#ifndef __BOARD_H -#define __BOARD_H +#ifndef __MSBA2_COMMON_H +#define __MSBA2_COMMON_H /** * @ingroup msb_a2 @@ -48,4 +48,4 @@ and the mailinglist (subscription via web site) #define VICIntEnClear VICIntEnClr /** @} */ -#endif // __BOARD_H +#endif // __MSBA2_COMMON_H diff --git a/msba2/include/board.h b/msba2/include/board.h index bf596f0ee1..2b1f28fd2a 100644 --- a/msba2/include/board.h +++ b/msba2/include/board.h @@ -2,6 +2,7 @@ #define __BOARD_H #include +#include #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) From 531601e7bc67842ab33659bfe2a11b14dca360b7 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 5 Jan 2012 17:42:44 +0100 Subject: [PATCH 053/188] [board msba2-common board-config] * fixed casting to satisfy strict-aliasing rules --- msba2-common/board_config.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/msba2-common/board_config.c b/msba2-common/board_config.c index 8eff7e9db8..496a077961 100644 --- a/msba2-common/board_config.c +++ b/msba2-common/board_config.c @@ -5,12 +5,14 @@ void config_load(void) { extern char configmem[]; - if (*((uint16_t*) configmem) == CONFIG_KEY) { - memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); - } - else { - config_save(); - } + /* cast it here for strict-aliasing */ + uint16_t* tmp = (uint16_t*) configmem; + if (*tmp == CONFIG_KEY) { + memcpy(&sysconfig, (configmem + sizeof(CONFIG_KEY)), sizeof(sysconfig)); + } + else { + config_save(); + } } uint8_t config_save(void) { From b2e1098aad88ef3fa814ad10d0aa234f335ed679 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 16 Feb 2012 21:33:41 +0100 Subject: [PATCH 054/188] [board msba2-common] [sys chardev_thread] [sys shell] [driver cc110x_ng] [core msg] * some cosmetics and cleanups --- msba2-common/drivers/msba2-uart0.c | 1 - 1 file changed, 1 deletion(-) diff --git a/msba2-common/drivers/msba2-uart0.c b/msba2-common/drivers/msba2-uart0.c index 31a9870aaf..ccfc6d8e04 100644 --- a/msba2-common/drivers/msba2-uart0.c +++ b/msba2-common/drivers/msba2-uart0.c @@ -202,7 +202,6 @@ bl_uart_init(void) /* irq */ install_irq(UART0_INT, UART0_IRQHandler, 6); -// U0IER |= BIT0 | BIT1; // enable RX+TX irq U0IER |= BIT0; // enable only RX irq return 1; } From 66cabcf6251c4f23072bc1c3d5e4d1bdf8c93232 Mon Sep 17 00:00:00 2001 From: Stephan Arndt Date: Sat, 12 May 2012 15:50:52 +0200 Subject: [PATCH 055/188] Changed makefiles board/msba2-common/tools/Makefile and tools/toolchains/build_gnuarm.sh to be compatible with gcc version 4.6.1 --- msba2-common/tools/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msba2-common/tools/Makefile b/msba2-common/tools/Makefile index e98492a309..5d4d6b9222 100644 --- a/msba2-common/tools/Makefile +++ b/msba2-common/tools/Makefile @@ -17,7 +17,7 @@ lpc2k_pgm: $(OBJS) pseudoterm: $(PSEUDOTERM_OBJS) mkdir -p $(TARGETDIR) - $(CC) -lpthread -o $(TARGETDIR)/pseudoterm $(PSEUDOTERM_OBJS) + $(CC) -o $(TARGETDIR)/pseudoterm $(PSEUDOTERM_OBJS) -lpthread chipinfo.o: boot_2xxx.h boot_23xx.h From c0aae0af5952b034a2453c7e036d41349ca86b74 Mon Sep 17 00:00:00 2001 From: julsch Date: Wed, 20 Jun 2012 17:17:24 +0200 Subject: [PATCH 056/188] + jam tutorial \n --- msba2-common/tools/Makefile | 2 +- msba2-common/tools/obj/boot_23xx.d | 2 +- msba2-common/tools/obj/boot_2xxx.d | 2 +- msba2-common/tools/obj/chipinfo.d | 4 ++-- msba2-common/tools/obj/control_2xxx.d | 3 +-- msba2-common/tools/obj/download.d | 6 +++--- msba2-common/tools/obj/ihex.d | 2 +- msba2-common/tools/obj/lpc2k_pgm.d | 4 ++-- msba2-common/tools/obj/pseudoterm.d | 3 +-- msba2-common/tools/obj/serial.d | 2 +- msba2-common/tools/obj/uuencode.d | 2 +- 11 files changed, 15 insertions(+), 17 deletions(-) diff --git a/msba2-common/tools/Makefile b/msba2-common/tools/Makefile index e98492a309..5d4d6b9222 100644 --- a/msba2-common/tools/Makefile +++ b/msba2-common/tools/Makefile @@ -17,7 +17,7 @@ lpc2k_pgm: $(OBJS) pseudoterm: $(PSEUDOTERM_OBJS) mkdir -p $(TARGETDIR) - $(CC) -lpthread -o $(TARGETDIR)/pseudoterm $(PSEUDOTERM_OBJS) + $(CC) -o $(TARGETDIR)/pseudoterm $(PSEUDOTERM_OBJS) -lpthread chipinfo.o: boot_2xxx.h boot_23xx.h diff --git a/msba2-common/tools/obj/boot_23xx.d b/msba2-common/tools/obj/boot_23xx.d index 874c0d70ef..e45338d651 100644 --- a/msba2-common/tools/obj/boot_23xx.d +++ b/msba2-common/tools/obj/boot_23xx.d @@ -1,3 +1,3 @@ -obj/boot_23xx.d obj/boot_23xx.o: src/boot_23xx.c src/boot_23xx.h +obj/boot_23xx.d: src/boot_23xx.c src/boot_23xx.h src/boot_23xx.h: diff --git a/msba2-common/tools/obj/boot_2xxx.d b/msba2-common/tools/obj/boot_2xxx.d index b33d065787..e0e9fb40da 100644 --- a/msba2-common/tools/obj/boot_2xxx.d +++ b/msba2-common/tools/obj/boot_2xxx.d @@ -1,3 +1,3 @@ -obj/boot_2xxx.d obj/boot_2xxx.o: src/boot_2xxx.c src/boot_2xxx.h +obj/boot_2xxx.d: src/boot_2xxx.c src/boot_2xxx.h src/boot_2xxx.h: diff --git a/msba2-common/tools/obj/chipinfo.d b/msba2-common/tools/obj/chipinfo.d index b6840f4c8d..b695e68c42 100644 --- a/msba2-common/tools/obj/chipinfo.d +++ b/msba2-common/tools/obj/chipinfo.d @@ -1,5 +1,5 @@ -obj/chipinfo.d obj/chipinfo.o: src/chipinfo.c src/chipinfo.h \ - src/boot_2xxx.h src/boot_23xx.h +obj/chipinfo.d: src/chipinfo.c src/chipinfo.h src/boot_2xxx.h \ + src/boot_23xx.h src/chipinfo.h: diff --git a/msba2-common/tools/obj/control_2xxx.d b/msba2-common/tools/obj/control_2xxx.d index d91c1b90fe..e9ed3f7b1b 100644 --- a/msba2-common/tools/obj/control_2xxx.d +++ b/msba2-common/tools/obj/control_2xxx.d @@ -1,5 +1,4 @@ -obj/control_2xxx.d obj/control_2xxx.o: src/control_2xxx.c \ - src/control_2xxx.h src/serial.h +obj/control_2xxx.d: src/control_2xxx.c src/control_2xxx.h src/serial.h src/control_2xxx.h: diff --git a/msba2-common/tools/obj/download.d b/msba2-common/tools/obj/download.d index 1bdc25ec41..94c10a80c5 100644 --- a/msba2-common/tools/obj/download.d +++ b/msba2-common/tools/obj/download.d @@ -1,6 +1,6 @@ -obj/download.d obj/download.o: src/download.c src/lpc2k_pgm.h \ - src/download.h src/serial.h src/ihex.h src/uuencode.h src/chipinfo.h \ - src/boot.h src/control_2xxx.h +obj/download.d: src/download.c src/lpc2k_pgm.h src/download.h \ + src/serial.h src/ihex.h src/uuencode.h src/chipinfo.h src/boot.h \ + src/control_2xxx.h src/lpc2k_pgm.h: diff --git a/msba2-common/tools/obj/ihex.d b/msba2-common/tools/obj/ihex.d index e2430e90ca..89b506056a 100644 --- a/msba2-common/tools/obj/ihex.d +++ b/msba2-common/tools/obj/ihex.d @@ -1,3 +1,3 @@ -obj/ihex.d obj/ihex.o: src/ihex.c src/ihex.h +obj/ihex.d: src/ihex.c src/ihex.h src/ihex.h: diff --git a/msba2-common/tools/obj/lpc2k_pgm.d b/msba2-common/tools/obj/lpc2k_pgm.d index 50838bbfcf..98c82eb328 100644 --- a/msba2-common/tools/obj/lpc2k_pgm.d +++ b/msba2-common/tools/obj/lpc2k_pgm.d @@ -1,5 +1,5 @@ -obj/lpc2k_pgm.d obj/lpc2k_pgm.o: src/lpc2k_pgm.c src/lpc2k_pgm.h \ - src/serial.h src/download.h +obj/lpc2k_pgm.d: src/lpc2k_pgm.c src/lpc2k_pgm.h src/serial.h \ + src/download.h src/lpc2k_pgm.h: diff --git a/msba2-common/tools/obj/pseudoterm.d b/msba2-common/tools/obj/pseudoterm.d index 3524292e42..858fa2cba7 100644 --- a/msba2-common/tools/obj/pseudoterm.d +++ b/msba2-common/tools/obj/pseudoterm.d @@ -1,5 +1,4 @@ -obj/pseudoterm.d obj/pseudoterm.o: src/pseudoterm.c src/serial.h \ - src/download.h +obj/pseudoterm.d: src/pseudoterm.c src/serial.h src/download.h src/serial.h: diff --git a/msba2-common/tools/obj/serial.d b/msba2-common/tools/obj/serial.d index 70d6d9d7dc..ebabf01ecf 100644 --- a/msba2-common/tools/obj/serial.d +++ b/msba2-common/tools/obj/serial.d @@ -1,3 +1,3 @@ -obj/serial.d obj/serial.o: src/serial.c src/serial.h +obj/serial.d: src/serial.c src/serial.h src/serial.h: diff --git a/msba2-common/tools/obj/uuencode.d b/msba2-common/tools/obj/uuencode.d index fa6d25aca3..548a00f642 100644 --- a/msba2-common/tools/obj/uuencode.d +++ b/msba2-common/tools/obj/uuencode.d @@ -1,3 +1,3 @@ -obj/uuencode.d obj/uuencode.o: src/uuencode.c src/uuencode.h +obj/uuencode.d: src/uuencode.c src/uuencode.h src/uuencode.h: From 22c5bd3215357266f5b3c9142d618eba0906d3d5 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 1 Aug 2012 17:00:48 +0200 Subject: [PATCH 057/188] [board msba2-common tools pseudoterm] * comments for preparing pseudoterm to use with node without DTR line [drivers cc110x] * changed default behavior to WOR mode * fixed a bug that let CC1100 never return to WOR mode, when receiving a packet during sending --- msba2-common/tools/src/control_2xxx.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/msba2-common/tools/src/control_2xxx.c b/msba2-common/tools/src/control_2xxx.c index ae2806c2b7..10d924e39e 100644 --- a/msba2-common/tools/src/control_2xxx.c +++ b/msba2-common/tools/src/control_2xxx.c @@ -8,12 +8,19 @@ void hard_reset_to_bootloader(void) { - printf("Reset CPU (into bootloader)\r\n"); +/* 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 + /* 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(0); // allow the CPU to run + 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); From 693afbbdd0841c60152ffbd4854a644b60cb9cb6 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 18 Oct 2012 18:08:40 +0200 Subject: [PATCH 058/188] [core thread] * added thread_getlastpid --- msba2-common/drivers/msba2-cc110x.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msba2-common/drivers/msba2-cc110x.c b/msba2-common/drivers/msba2-cc110x.c index 7d5a6b2196..b0a5854446 100644 --- a/msba2-common/drivers/msba2-cc110x.c +++ b/msba2-common/drivers/msba2-cc110x.c @@ -126,6 +126,8 @@ void cc110x_spi_init(void) 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) { From 19ff8ad137230b59ed1eb4e90410e67d4cceef2d Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 5 Nov 2012 18:55:05 -0500 Subject: [PATCH 059/188] * cosmetics --- msb-430-common/board_init.c | 1 + msb-430/include/board.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index 4673600445..c9037cb521 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -3,6 +3,7 @@ #include "kernel_intern.h" #include "msp430.h" #include "debug.h" +#include volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; diff --git a/msb-430/include/board.h b/msb-430/include/board.h index 18d4a04721..56c24a5461 100644 --- a/msb-430/include/board.h +++ b/msb-430/include/board.h @@ -49,7 +49,7 @@ and the mailinglist (subscription via web site) */ //MSB430 core -#define MSP430_INITIAL_CPU_SPEED 7372800uL +#define MSP430_INITIAL_CPU_SPEED 2457600uL #define MSP430_HAS_DCOR 1 #define MSP430_HAS_EXTERNAL_CRYSTAL 0 From d9017085432f2aa677ba8d6eb4de45e1d1c7982d Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 20 Nov 2012 21:30:03 +0100 Subject: [PATCH 060/188] [board msba2-common tools] * fixed lpc2k_pgm --- msba2-common/tools/src/control_2xxx.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/msba2-common/tools/src/control_2xxx.c b/msba2-common/tools/src/control_2xxx.c index 10d924e39e..ac0c8ca975 100644 --- a/msba2-common/tools/src/control_2xxx.c +++ b/msba2-common/tools/src/control_2xxx.c @@ -8,28 +8,30 @@ void hard_reset_to_bootloader(void) { -/* Use this lines for flashing a node with interrupted DTR line - * printf("Press Reset - confirm with anykey\n"); +/* 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(0); // 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); - printf("Release Reset - confirm with anykey\n"); + /* 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) + set_rts(0); // 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_rts(1); // 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); From 182151f46326e9eb6c0c48bd2ac6438c66302a13 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Fri, 1 Feb 2013 16:55:19 +0100 Subject: [PATCH 061/188] * added makefiles for chronos and msba2 --- chronos/makefile | 35 +++++++++++++++++++++++++++++++++++ makefile | 5 +++++ msba2/makefile | 27 +++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 chronos/makefile create mode 100644 makefile create mode 100644 msba2/makefile diff --git a/chronos/makefile b/chronos/makefile new file mode 100644 index 0000000000..aae0e9956c --- /dev/null +++ b/chronos/makefile @@ -0,0 +1,35 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES = -Iinclude -I../../feuerware-base/sys/lib -I../../feuerware-base/sys/drivers/include +INCLUDES += -I../../feuerware-base/sys/drivers/cc110x_ng/include +INCLUDES += -I../../feuerware-base/core/include +INCLUDES += -I../../feuerware-base/cpu/msp430/include/ +INCLUDES += -I../../feuerware-base/cpu/cc430/include/ +INCLUDES += -I/usr/msp430/include/ + +all: $(BINDIR)chronos_base.a + $(MAKE) -C drivers + +$(BINDIR)chronos_base.a: $(OBJ) + $(AR) rcs $(BINDIR)chronos_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/fw_out && mv /tmp/fw_out $(BINDIR)$*.d + +# remove compilation products +clean: + rm -f $(BINDIR)chronos_base.a $(OBJ) $(DEP) + $(MAKE) -C drivers clean + + + diff --git a/makefile b/makefile new file mode 100644 index 0000000000..e0f39c5c4d --- /dev/null +++ b/makefile @@ -0,0 +1,5 @@ +all: + $(MAKE) -C $(BOARD) + +clean: + $(MAKE) -C $(BOARD) clean diff --git a/msba2/makefile b/msba2/makefile new file mode 100644 index 0000000000..19b83b10ce --- /dev/null +++ b/msba2/makefile @@ -0,0 +1,27 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/lpc2387/include/ + +all: $(BINDIR)msba2_base.a + +$(BINDIR)msba2_base.a: $(OBJ) + $(AR) rcs $(BINDIR)msba2_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + rm -f $(BINDIR)riot_base.a $(OBJ) $(DEP) + From 39e96d46905f868684dc1b38f171f93202267e2a Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 6 Feb 2013 12:19:39 +0100 Subject: [PATCH 062/188] [msba2] * updated makefiles --- msba2-common/drivers/makefile | 24 ++++++++++++++++++++++++ msba2-common/lpc2387-timer3.c | 1 - msba2-common/makefile | 31 +++++++++++++++++++++++++++++++ msba2/board_init.o | Bin 0 -> 3140 bytes msba2/makefile | 5 ++++- 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 msba2-common/drivers/makefile create mode 100644 msba2-common/makefile create mode 100644 msba2/board_init.o diff --git a/msba2-common/drivers/makefile b/msba2-common/drivers/makefile new file mode 100644 index 0000000000..7eb5f229fe --- /dev/null +++ b/msba2-common/drivers/makefile @@ -0,0 +1,24 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o) +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ + +$(BINDIR)msba2_common_drivers.a: $(OBJ) + $(AR) rcs $(BINDIR)msba2_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)" | cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products + +clean: + rm -f $(OBJ) $(DEP) + diff --git a/msba2-common/lpc2387-timer3.c b/msba2-common/lpc2387-timer3.c index 8978390e9a..3b404edd94 100644 --- a/msba2-common/lpc2387-timer3.c +++ b/msba2-common/lpc2387-timer3.c @@ -8,7 +8,6 @@ #include #include #include "lpc2387.h" -#include "benchmark.h" void benchmark_init(void) { diff --git a/msba2-common/makefile b/msba2-common/makefile new file mode 100644 index 0000000000..61afe95c5f --- /dev/null +++ b/msba2-common/makefile @@ -0,0 +1,31 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/msba2-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/lpc2387/include/ +INCLUDES += -I$(RIOTBASE)/drivers/include/ + +all: $(BINDIR)msba2_common_base.a + $(MAKE) -C drivers + +$(BINDIR)msba2_common_base.a: $(OBJ) + $(AR) rcs $(BINDIR)msba2_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + make -C drivers clean + rm -f $(OBJ) $(DEP) + diff --git a/msba2/board_init.o b/msba2/board_init.o new file mode 100644 index 0000000000000000000000000000000000000000..8f4042b27d671ce30748e4a8fdb0d5814bd3e0ee GIT binary patch literal 3140 zcma)8U5Hd=7=FJqvp=>!?vIwG<`Gv~$(=LFwunZqnVI;DS`Zc6nVoTVYIbIsnKcDP zakPa(H(w8$NgH^#>Rq9lwlmoAXw^{%-vGh4}~T-rUsa z&@Zb-XKPM6SWt(9g=#TgtB%EMf7R>1&Oo1mK6U1coAvMN+m0k>Yr)z}HRYaN2-a3> zt2ghM7xz-_Ah@{I8uh^aO6wcpJL~n=oPo0ovtCT=YF(&11Hr-!Y-(MInCq5YUGp>N z_z~yf=rf6{w}I+;bQ`omByLX7QLSIX%ples}qgP#uK>^ws zv?XdKdUc-)0L)z6_wPSZbLW~`E z-I7q-I>V8NIvF?Gs^HN&EV1^`-9e(ZM}=|i3Hhfp7V|G7>PJf)y(6cD$mK()s-+Ws z51J!yRfsN{lEVi9N6=_~0mv|z(Q8?S-bKUkG2$>9h93hkGUCa=<7k|p7=${f(!xxp z42-35`!wk5l~?Jd{_O4&JZd;+%pl5}C{AX)Vm_1gvW02CH0kAYDK9%d?m-{Q`3`Uc_>#H&rhc_BB`QZN{{6Vxk_T3bCxS)j z7oV$mhjt%0;^}pGljW4ZNpz0p_~>b8%{d=C7uWF|4$#t666F(<6+Z>6ltP@a zS}BuHR5Hgal1Td%UlOTuSrRm+GpXq;j{Rs6Lt6J!sZ!>cW%=TG)X^{bg>0rN7Dtt_ z-k44jg+9j7&`s`%P)Mq85s)m{bUKy=1W44uCKF0 zpPr;TKRbV#i(tw>pQmVM8tzBX;aL@aX#P zVtw}fXt(Q|f^K7&Vhs5{p<=|2<-w!*I#KjIPwp3~7xSHj&KRB#1*I=HLsj=2W1BH( z{qDf8PkV%&^?MT(OX4!M@PpT536Or2574Ymz5;#+sTkpYDFIq^AIq?hBy8LV^U{y| z>P54)0#zoE?^7y9>|Dg~r5+BXk^ChXmw_@T^D!^yjOP0q^*jQb6`Rj;i&1-AZr81y z7;D-wd2|NyxbUAqLzLdvdy598$AbvxzVAl(q6#IZE4yKdNn3;Hah_a5VofK_cveb7 zV$!A8!}AHHp^?X$ZkoJ#H!)eN&zZh_&-URw_ Date: Wed, 6 Feb 2013 12:20:34 +0100 Subject: [PATCH 063/188] [msba2] * removed accidentally committed object file --- msba2/board_init.o | Bin 3140 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 msba2/board_init.o diff --git a/msba2/board_init.o b/msba2/board_init.o deleted file mode 100644 index 8f4042b27d671ce30748e4a8fdb0d5814bd3e0ee..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3140 zcma)8U5Hd=7=FJqvp=>!?vIwG<`Gv~$(=LFwunZqnVI;DS`Zc6nVoTVYIbIsnKcDP zakPa(H(w8$NgH^#>Rq9lwlmoAXw^{%-vGh4}~T-rUsa z&@Zb-XKPM6SWt(9g=#TgtB%EMf7R>1&Oo1mK6U1coAvMN+m0k>Yr)z}HRYaN2-a3> zt2ghM7xz-_Ah@{I8uh^aO6wcpJL~n=oPo0ovtCT=YF(&11Hr-!Y-(MInCq5YUGp>N z_z~yf=rf6{w}I+;bQ`omByLX7QLSIX%ples}qgP#uK>^ws zv?XdKdUc-)0L)z6_wPSZbLW~`E z-I7q-I>V8NIvF?Gs^HN&EV1^`-9e(ZM}=|i3Hhfp7V|G7>PJf)y(6cD$mK()s-+Ws z51J!yRfsN{lEVi9N6=_~0mv|z(Q8?S-bKUkG2$>9h93hkGUCa=<7k|p7=${f(!xxp z42-35`!wk5l~?Jd{_O4&JZd;+%pl5}C{AX)Vm_1gvW02CH0kAYDK9%d?m-{Q`3`Uc_>#H&rhc_BB`QZN{{6Vxk_T3bCxS)j z7oV$mhjt%0;^}pGljW4ZNpz0p_~>b8%{d=C7uWF|4$#t666F(<6+Z>6ltP@a zS}BuHR5Hgal1Td%UlOTuSrRm+GpXq;j{Rs6Lt6J!sZ!>cW%=TG)X^{bg>0rN7Dtt_ z-k44jg+9j7&`s`%P)Mq85s)m{bUKy=1W44uCKF0 zpPr;TKRbV#i(tw>pQmVM8tzBX;aL@aX#P zVtw}fXt(Q|f^K7&Vhs5{p<=|2<-w!*I#KjIPwp3~7xSHj&KRB#1*I=HLsj=2W1BH( z{qDf8PkV%&^?MT(OX4!M@PpT536Or2574Ymz5;#+sTkpYDFIq^AIq?hBy8LV^U{y| z>P54)0#zoE?^7y9>|Dg~r5+BXk^ChXmw_@T^D!^yjOP0q^*jQb6`Rj;i&1-AZr81y z7;D-wd2|NyxbUAqLzLdvdy598$AbvxzVAl(q6#IZE4yKdNn3;Hah_a5VofK_cveb7 zV$!A8!}AHHp^?X$ZkoJ#H!)eN&zZh_&-URw_ Date: Wed, 6 Feb 2013 13:56:06 +0100 Subject: [PATCH 064/188] * created (and remove) bin-directory in makefile --- msba2/makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msba2/makefile b/msba2/makefile index 2c6ed76af7..fd3478df5d 100644 --- a/msba2/makefile +++ b/msba2/makefile @@ -19,6 +19,7 @@ $(BINDIR)msba2_base.a: $(OBJ) # compile and generate dependency info $(BINDIR)%.o: %.c + mkdir $(BINDIR) $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d @@ -27,4 +28,5 @@ $(BINDIR)%.o: %.c clean: $(MAKE) -C ../msba2-common clean rm -f $(BINDIR)msba2_base.a $(OBJ) $(DEP) + rmdir $(BINDIR) From 402bc0e1b920b54e1a87329d0b496fedfeafd811 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Fri, 8 Feb 2013 17:31:33 +0100 Subject: [PATCH 065/188] * check for existence of BINDIR when cleaning --- msba2/makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/msba2/makefile b/msba2/makefile index fd3478df5d..06f501ed5c 100644 --- a/msba2/makefile +++ b/msba2/makefile @@ -28,5 +28,8 @@ $(BINDIR)%.o: %.c clean: $(MAKE) -C ../msba2-common clean rm -f $(BINDIR)msba2_base.a $(OBJ) $(DEP) - rmdir $(BINDIR) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi + From d3b68f6bc65d6a131e848915437bd5bd237d4059 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 8 Feb 2013 08:45:26 -0800 Subject: [PATCH 066/188] Create README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000000..cda1a563ea --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +Platform configurations for RIOT-OS +==================================== +This repository contains existing configuration and initialization files for platforms supported by RIOT-OS. + +RIOT's kernel, system libraries, and drivers can be found here: +https://github.com/RIOT-OS/RIOT From 49871ac41b27225415dab2b35cfc05ada2d32bcd Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 20 Feb 2013 17:28:59 +0100 Subject: [PATCH 067/188] * added makefiles for msb-430h (NOT YET WORKING!) --- msb-430-common/drivers/makefile | 24 ++++++++++++++++++++++ msb-430-common/makefile | 30 +++++++++++++++++++++++++++ msb-430h/makefile | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 msb-430-common/drivers/makefile create mode 100644 msb-430-common/makefile create mode 100644 msb-430h/makefile diff --git a/msb-430-common/drivers/makefile b/msb-430-common/drivers/makefile new file mode 100644 index 0000000000..5ede0ecace --- /dev/null +++ b/msb-430-common/drivers/makefile @@ -0,0 +1,24 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o) +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ + +$(BINDIR)msb-430_common_drivers.a: $(OBJ) + $(AR) rcs $(BINDIR)msb-430_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)" | cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products + +clean: + rm -f $(OBJ) $(DEP) + diff --git a/msb-430-common/makefile b/msb-430-common/makefile new file mode 100644 index 0000000000..2fe5acee43 --- /dev/null +++ b/msb-430-common/makefile @@ -0,0 +1,30 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/mspx16x/include/ + +all: $(BINDIR)msb-430_common_base.a + $(MAKE) -C drivers + +$(BINDIR)msb-430_common_base.a: $(OBJ) + $(AR) rcs $(BINDIR)msb-430_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + $(MAKE) -C drivers clean + rm -f $(OBJ) $(DEP) + diff --git a/msb-430h/makefile b/msb-430h/makefile new file mode 100644 index 0000000000..dd4d0f213f --- /dev/null +++ b/msb-430h/makefile @@ -0,0 +1,36 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430x16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/include + +all: $(BINDIR)msb-430_base.a + $(MAKE) -C ../msb-430-common + +$(BINDIR)msb-430_base.a: $(OBJ) + $(AR) rcs $(BINDIR)msb-430_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + mkdir -p $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + $(MAKE) -C ../msb-430-common clean + rm -f $(BINDIR)msb-430_base.a $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi + + From ba837126110875d8832730532d725c4d93e49e45 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 21 Feb 2013 17:10:36 +0100 Subject: [PATCH 068/188] * fixed makefiles for msb-430h --- msb-430-common/board_init.c | 2 +- msb-430-common/drivers/makefile | 2 +- msb-430-common/makefile | 9 +++++---- msb-430-common/putchar.c | 7 ------- msb-430h/makefile | 7 ++++--- 5 files changed, 11 insertions(+), 16 deletions(-) delete mode 100644 msb-430-common/putchar.c diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index c9037cb521..b34642861e 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -3,7 +3,7 @@ #include "kernel_intern.h" #include "msp430.h" #include "debug.h" -#include +#include "msb430-uart1.h" volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; diff --git a/msb-430-common/drivers/makefile b/msb-430-common/drivers/makefile index 5ede0ecace..d4b65dc031 100644 --- a/msb-430-common/drivers/makefile +++ b/msb-430-common/drivers/makefile @@ -6,7 +6,7 @@ DEP = $(SRC:%.c=$(BINDIR)%.d) INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ $(BINDIR)msb-430_common_drivers.a: $(OBJ) - $(AR) rcs $(BINDIR)msb-430_base.a $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) # pull in dependency info for *existing* .o files -include $(OBJ:.o=.d) diff --git a/msb-430-common/makefile b/msb-430-common/makefile index 2fe5acee43..021a4f163f 100644 --- a/msb-430-common/makefile +++ b/msb-430-common/makefile @@ -7,12 +7,13 @@ DEP = $(SRC:%.c=$(BINDIR)%.d) INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/mspx16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/include/ -all: $(BINDIR)msb-430_common_base.a +all: $(BINDIR)$(ARCH) $(MAKE) -C drivers -$(BINDIR)msb-430_common_base.a: $(OBJ) - $(AR) rcs $(BINDIR)msb-430_base.a $(OBJ) +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) # pull in dependency info for *existing* .o files -include $(OBJ:.o=.d) @@ -27,4 +28,4 @@ $(BINDIR)%.o: %.c clean: $(MAKE) -C drivers clean rm -f $(OBJ) $(DEP) - + rm -f $(BINDIR)$(ARCH) diff --git a/msb-430-common/putchar.c b/msb-430-common/putchar.c deleted file mode 100644 index 4193c0db42..0000000000 --- a/msb-430-common/putchar.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -void (_putchar(int)) = uart1_putchar; - -void putchar(int c) { - _putchar(c); -} diff --git a/msb-430h/makefile b/msb-430h/makefile index dd4d0f213f..327f5d6825 100644 --- a/msb-430h/makefile +++ b/msb-430h/makefile @@ -1,6 +1,7 @@ SRC = $(wildcard *.c) BINDIR = bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = msb-430h_base.a DEP = $(SRC:%.c=$(BINDIR)%.d) @@ -9,11 +10,11 @@ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/msp430x16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/include -all: $(BINDIR)msb-430_base.a +all: $(BINDIR)$(ARCH) $(MAKE) -C ../msb-430-common -$(BINDIR)msb-430_base.a: $(OBJ) - $(AR) rcs $(BINDIR)msb-430_base.a $(OBJ) +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) # pull in dependency info for *existing* .o files -include $(OBJ:.o=.d) From d46f042530ea7633e9c4b699c13ae502a27fe82c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 21 Feb 2013 17:23:55 +0100 Subject: [PATCH 069/188] * removed missing header from msb-430-common board_init * fixed msba2 related makefiles --- msb-430-common/board_init.c | 1 - msb-430h/makefile | 2 +- msba2-common/makefile | 2 +- msba2/makefile | 9 +++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index b34642861e..4673600445 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -3,7 +3,6 @@ #include "kernel_intern.h" #include "msp430.h" #include "debug.h" -#include "msb430-uart1.h" volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; diff --git a/msb-430h/makefile b/msb-430h/makefile index 327f5d6825..91c5da5880 100644 --- a/msb-430h/makefile +++ b/msb-430h/makefile @@ -29,7 +29,7 @@ $(BINDIR)%.o: %.c # remove compilation products clean: $(MAKE) -C ../msb-430-common clean - rm -f $(BINDIR)msb-430_base.a $(OBJ) $(DEP) + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) @if [ -d $(BINDIR) ] ; \ then rmdir $(BINDIR) ; \ fi diff --git a/msba2-common/makefile b/msba2-common/makefile index 61afe95c5f..73ea5843d4 100644 --- a/msba2-common/makefile +++ b/msba2-common/makefile @@ -13,7 +13,7 @@ all: $(BINDIR)msba2_common_base.a $(MAKE) -C drivers $(BINDIR)msba2_common_base.a: $(OBJ) - $(AR) rcs $(BINDIR)msba2_base.a $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) # pull in dependency info for *existing* .o files -include $(OBJ:.o=.d) diff --git a/msba2/makefile b/msba2/makefile index 06f501ed5c..dab7d39a76 100644 --- a/msba2/makefile +++ b/msba2/makefile @@ -1,6 +1,7 @@ SRC = $(wildcard *.c) BINDIR = bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = msba2_base.a DEP = $(SRC:%.c=$(BINDIR)%.d) @@ -8,11 +9,11 @@ INCLUDES += -I$(RIOTBOARD)/msba2-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include/ INCLUDES += -I$(RIOTBASE)/cpu/lpc2387/include/ -all: $(BINDIR)msba2_base.a +all: $(BINDIR)$(ARCH) $(MAKE) -C ../msba2-common -$(BINDIR)msba2_base.a: $(OBJ) - $(AR) rcs $(BINDIR)msba2_base.a $(OBJ) +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) # pull in dependency info for *existing* .o files -include $(OBJ:.o=.d) @@ -27,7 +28,7 @@ $(BINDIR)%.o: %.c # remove compilation products clean: $(MAKE) -C ../msba2-common clean - rm -f $(BINDIR)msba2_base.a $(OBJ) $(DEP) + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) @if [ -d $(BINDIR) ] ; \ then rmdir $(BINDIR) ; \ fi From 9a21ba09c3a85490a1b0b56208d6d0996c9f2b4d Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 6 Mar 2013 01:10:50 +0100 Subject: [PATCH 070/188] initial native board inport --- native/board_config.c | 16 +++++++++++ native/board_init.c | 4 +++ native/makefile | 27 ++++++++++++++++++ native/native-ltc4150.c | 61 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 native/board_config.c create mode 100644 native/board_init.c create mode 100644 native/makefile create mode 100644 native/native-ltc4150.c diff --git a/native/board_config.c b/native/board_config.c new file mode 100644 index 0000000000..8f343f349e --- /dev/null +++ b/native/board_config.c @@ -0,0 +1,16 @@ +#include +#include + +#include + +void config_load(void) +{ + printf("XXX: config_load(): not implemented\n"); + return; +} + +uint8_t config_save(void) +{ + printf("XXX: config_save(): not implemented - your config will vanish on process termination\n"); + return 1; +} diff --git a/native/board_init.c b/native/board_init.c new file mode 100644 index 0000000000..ab08803451 --- /dev/null +++ b/native/board_init.c @@ -0,0 +1,4 @@ +void board_init() +{ + puts("RIOT native board initialized."); +} diff --git a/native/makefile b/native/makefile new file mode 100644 index 0000000000..bd68eb4cd0 --- /dev/null +++ b/native/makefile @@ -0,0 +1,27 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBASE)/cpu/native/include/ + +all: $(BINDIR)native_base.a + +$(BINDIR)native_base.a: $(OBJ) + $(AR) rcs $(BINDIR)native_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + -mkdir $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + rm -f $(BINDIR)native_base.a $(OBJ) $(DEP) + -rmdir $(BINDIR) + diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c new file mode 100644 index 0000000000..42711b7538 --- /dev/null +++ b/native/native-ltc4150.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include + +#include "ltc4150_arch.h" +#include "debug.h" + +#include "cpu.h" +#include "cpu-conf.h" + +#define native_ltc4150_startup_delay 10 + +static timer_t native_ltc4150_timer; +static struct itimerspec native_ltc4150_timer_time; + +void ltc4150_disable_int(void) +{ + DEBUG("ltc4150_disable_int()\n"); + unregister_interrupt(_SIG_LTC4150); +} + +void ltc4150_enable_int(void) +{ + DEBUG("ltc4150_enable_int()\n"); + register_interrupt(_SIG_LTC4150, ltc4150_interrupt); +} + +void ltc4150_sync_blocking(void) +{ + DEBUG("ltc4150_sync_blocking()\n"); + for(int i = native_ltc4150_startup_delay; i>0; i--); +} + +void ltc4150_arch_init(void) +{ + struct sigevent sev; + + ltc4150_disable_int(); + + /* create timer */ + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = _SIG_LTC4150; + sev.sigev_value.sival_ptr = &native_ltc4150_timer; + + if (timer_create(CLOCK_MONOTONIC, &sev, &native_ltc4150_timer) == -1) { + err(1, "ltc4150_arch_init(): timer_create"); + } + + /* set timer */ + native_ltc4150_timer_time.it_value.tv_sec = 0; + native_ltc4150_timer_time.it_value.tv_nsec = 100000000; + native_ltc4150_timer_time.it_interval.tv_sec = 0; + native_ltc4150_timer_time.it_interval.tv_nsec = 100000000; + + if (timer_settime(native_ltc4150_timer, 0, &native_ltc4150_timer_time, NULL) == -1) { + err(1, "ltc4150_arch_init: timer_settime"); + } + + puts("Native LTC4150 initialized."); +} From fbb33c3b8d1a25bb4d4afc62942e5880bf917588 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 6 Mar 2013 10:48:14 +0100 Subject: [PATCH 071/188] copyright header --- native/board_config.c | 15 +++++++++++++++ native/board_init.c | 15 +++++++++++++++ native/native-ltc4150.c | 15 +++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/native/board_config.c b/native/board_config.c index 8f343f349e..317cdbb79e 100644 --- a/native/board_config.c +++ b/native/board_config.c @@ -1,3 +1,18 @@ +/** + * Native Board config.h implementation + * + * Copyright (C) 2013 Ludwig Ortmann + * + * This file subject to the terms and conditions of the GNU General Public + * License. See the file LICENSE in the top level directory for more details. + * + * @ingroup native + * @{ + * @file + * @author Ludwig Ortmann + * @} + */ + #include #include diff --git a/native/board_init.c b/native/board_init.c index ab08803451..cfc072d4ac 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -1,3 +1,18 @@ +/** + * Native Board board_init implementation + * + * Copyright (C) 2013 Ludwig Ortmann + * + * This file subject to the terms and conditions of the GNU General Public + * License. See the file LICENSE in the top level directory for more details. + * + * @ingroup native + * @{ + * @file + * @author Ludwig Ortmann + * @} + */ + void board_init() { puts("RIOT native board initialized."); diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c index 42711b7538..e18dee912d 100644 --- a/native/native-ltc4150.c +++ b/native/native-ltc4150.c @@ -1,3 +1,18 @@ +/** + * Native Board ltc4150_arch.h implementation + * + * Copyright (C) 2013 Ludwig Ortmann + * + * This file subject to the terms and conditions of the GNU General Public + * License. See the file LICENSE in the top level directory for more details. + * + * @ingroup native + * @{ + * @file + * @author Ludwig Ortmann + * @} + */ + #include #include #include From 81f2a5bc1223172911ebe179527b7b4336a4dbe3 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 6 Mar 2013 12:19:15 +0100 Subject: [PATCH 072/188] native board interface and dummy LED implementation --- native/board.h | 22 ++++++++++++++++++++ native/native-led.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 native/board.h create mode 100644 native/native-led.c diff --git a/native/board.h b/native/board.h new file mode 100644 index 0000000000..71afb726ce --- /dev/null +++ b/native/board.h @@ -0,0 +1,22 @@ +/** + * Native Board interface + * + * Copyright (C) 2013 Ludwig Ortmann + * + * This file subject to the terms and conditions of the GNU General Public + * License. See the file LICENSE in the top level directory for more details. + * + * @ingroup native + * @{ + * @file + * @author Ludwig Ortmann + * @} + */ + +void LED_GREEN_OFF(void); +void LED_GREEN_ON(void); +void LED_GREEN_TOGGLE(void); +void LED_RED_OFF(void); +void LED_RED_ON(void); +void LED_RED_TOGGLE(void); + diff --git a/native/native-led.c b/native/native-led.c new file mode 100644 index 0000000000..2ee9d4979b --- /dev/null +++ b/native/native-led.c @@ -0,0 +1,49 @@ +/** + * Native Board LED implementation + * + * Copyright (C) 2013 Ludwig Ortmann + * + * This file subject to the terms and conditions of the GNU General Public + * License. See the file LICENSE in the top level directory for more details. + * + * @ingroup native + * @{ + * @file + * @author Ludwig Ortmann + * @} + */ + +#include + +#include "board.h" + +void LED_GREEN_OFF(void) +{ + printf("LED_GREEN_OFF\n"); +} + +void LED_GREEN_ON(void) +{ + printf("LED_GREEN_ON\n"); +} + +void LED_GREEN_TOGGLE(void) +{ + printf("LED_GREEN_TOGGLE\n"); +} + +void LED_RED_OFF(void) +{ + printf("LED_RED_OFF\n"); +} + +void LED_RED_ON(void) +{ + printf("LED_RED_ON\n"); +} + +void LED_RED_TOGGLE(void) +{ + printf("LED_RED_TOGGLE\n"); +} + From 23688ecef3be2a56e05b21bfed63f6972642e3ab Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 6 Mar 2013 12:27:25 +0100 Subject: [PATCH 073/188] initialize LEDs --- native/board_init.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/native/board_init.c b/native/board_init.c index cfc072d4ac..9a3266703e 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -13,7 +13,11 @@ * @} */ +#include "board.h" + void board_init() { + LED_GREEN_OFF(); + LED_RED_ON(); puts("RIOT native board initialized."); } From 782eb207b2a2907260f1091871c27a4de5d0b278 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 6 Mar 2013 15:58:21 +0100 Subject: [PATCH 074/188] fix board.h path and set it in makefile --- native/{ => include}/board.h | 0 native/makefile | 1 + 2 files changed, 1 insertion(+) rename native/{ => include}/board.h (100%) diff --git a/native/board.h b/native/include/board.h similarity index 100% rename from native/board.h rename to native/include/board.h diff --git a/native/makefile b/native/makefile index bd68eb4cd0..da7907f159 100644 --- a/native/makefile +++ b/native/makefile @@ -4,6 +4,7 @@ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines DEP = $(SRC:%.c=$(BINDIR)%.d) INCLUDES += -I$(RIOTBASE)/cpu/native/include/ +INCLUDES += -I$(RIOTBOARD)/native/include/ all: $(BINDIR)native_base.a From 40ebf3aac11a7150c6f6ddf4a441d3f7a1cef0d4 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Thu, 7 Mar 2013 19:25:48 +0100 Subject: [PATCH 075/188] * introduced PHONY targets for -common makefiles --- msb-430-common/makefile | 4 +++- msba2-common/makefile | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/msb-430-common/makefile b/msb-430-common/makefile index 021a4f163f..7f3a80971e 100644 --- a/msb-430-common/makefile +++ b/msb-430-common/makefile @@ -1,7 +1,6 @@ SRC = $(wildcard *.c) BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines - DEP = $(SRC:%.c=$(BINDIR)%.d) INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ @@ -9,10 +8,13 @@ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/mspx16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/include/ +.PHONY: $(BINDIR)$(ARCH) + all: $(BINDIR)$(ARCH) $(MAKE) -C drivers $(BINDIR)$(ARCH): $(OBJ) + echo $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) # pull in dependency info for *existing* .o files diff --git a/msba2-common/makefile b/msba2-common/makefile index 73ea5843d4..1ac90178e1 100644 --- a/msba2-common/makefile +++ b/msba2-common/makefile @@ -1,7 +1,6 @@ SRC = $(wildcard *.c) BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines - DEP = $(SRC:%.c=$(BINDIR)%.d) INCLUDES += -I$(RIOTBOARD)/msba2-common/include/ @@ -9,6 +8,8 @@ INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include/ INCLUDES += -I$(RIOTBASE)/cpu/lpc2387/include/ INCLUDES += -I$(RIOTBASE)/drivers/include/ +.PHONY: $(BINDIR)msba2_common_base.a + all: $(BINDIR)msba2_common_base.a $(MAKE) -C drivers @@ -26,6 +27,6 @@ $(BINDIR)%.o: %.c # remove compilation products clean: - make -C drivers clean + ${MAKE} -C drivers clean rm -f $(OBJ) $(DEP) From 8b563bb2714f55e8c00fae060fb42aa5a98cfee7 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Thu, 7 Mar 2013 22:42:48 +0100 Subject: [PATCH 076/188] =?UTF-8?q?*=20replaced=20outdated=20=C2=B5kleos?= =?UTF-8?q?=20reference?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- msb-430-common/drivers/include/sht11-board.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/msb-430-common/drivers/include/sht11-board.h b/msb-430-common/drivers/include/sht11-board.h index a4debd4473..13aeb89968 100644 --- a/msb-430-common/drivers/include/sht11-board.h +++ b/msb-430-common/drivers/include/sht11-board.h @@ -1,5 +1,5 @@ /****************************************************************************** -Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +Copyright 2013, Freie Universitaet Berlin (FUB). All rights reserved. These sources were developed at the Freie Universitaet Berlin, Computer Systems and Telematics group (http://cst.mi.fu-berlin.de). @@ -36,10 +36,8 @@ and the mailinglist (subscription via web site) * @file * @brief SHT11 Device Driver Configuration For MSB-430 Platform * - * @author Freie Universität Berlin, Computer Systems & Telematics, µkleos - * @version $Revision$ + * @author Freie Universität Berlin, Computer Systems & Telematics, RIOT * - * @note $Id$ */ #include #include From 8df4d77996d033404d0fb49084e5fba9106bda73 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sun, 10 Mar 2013 16:50:50 +0100 Subject: [PATCH 077/188] * renamed makefiles to Makefile * included a more convenient approach to organize Makefiles --- makefile => Makefile | 0 chronos/{makefile => Makefile} | 0 msb-430-common/{makefile => Makefile} | 0 msb-430-common/Makefile.include | 21 +++++++++++ msb-430-common/drivers/{makefile => Makefile} | 0 msb-430/Makefile | 37 +++++++++++++++++++ msb-430/Makefile.include | 1 + msb-430h/{makefile => Makefile} | 0 msba2-common/{makefile => Makefile} | 0 msba2-common/drivers/{makefile => Makefile} | 0 msba2/{makefile => Makefile} | 0 11 files changed, 59 insertions(+) rename makefile => Makefile (100%) rename chronos/{makefile => Makefile} (100%) rename msb-430-common/{makefile => Makefile} (100%) create mode 100644 msb-430-common/Makefile.include rename msb-430-common/drivers/{makefile => Makefile} (100%) create mode 100644 msb-430/Makefile create mode 100644 msb-430/Makefile.include rename msb-430h/{makefile => Makefile} (100%) rename msba2-common/{makefile => Makefile} (100%) rename msba2-common/drivers/{makefile => Makefile} (100%) rename msba2/{makefile => Makefile} (100%) diff --git a/makefile b/Makefile similarity index 100% rename from makefile rename to Makefile diff --git a/chronos/makefile b/chronos/Makefile similarity index 100% rename from chronos/makefile rename to chronos/Makefile diff --git a/msb-430-common/makefile b/msb-430-common/Makefile similarity index 100% rename from msb-430-common/makefile rename to msb-430-common/Makefile diff --git a/msb-430-common/Makefile.include b/msb-430-common/Makefile.include new file mode 100644 index 0000000000..d3d4dfd3ba --- /dev/null +++ b/msb-430-common/Makefile.include @@ -0,0 +1,21 @@ +## the cpu to build for +export CPU = msp430x16x +export MCU = msp430x1612 + +# toolchain config +export PREFIX = @msp430- +export CC = @$(PREFIX)gcc +export AR = @$(PREFIX)ar +export CFLAGS += -std=gnu99 -Wstrict-prototypes -gdwarf-2 -Os -Wall -mmcu=$(MCU) +export ASFLAGS += -mmcu=$(MCU) --defsym $(MCU)=1 --gdwarf-2 +export AS = $(PREFIX)as +export LINK = $(PREFIX)gcc +export SIZE = $(PREFIX)size +export OBJCOPY = $(PREFIX)objcopy +export LINKFLAGS = -mmcu=$(MCU) -lgcc $(RIOTBASE)/bin/startup.o +export FLASHER = mspdebug +ifeq ($(strip $(PORT)),) + export PORT = /dev/ttyUSB0 +endif +export HEXFILE = bin/$(PROJECT).hex +export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" diff --git a/msb-430-common/drivers/makefile b/msb-430-common/drivers/Makefile similarity index 100% rename from msb-430-common/drivers/makefile rename to msb-430-common/drivers/Makefile diff --git a/msb-430/Makefile b/msb-430/Makefile new file mode 100644 index 0000000000..66dcd277d1 --- /dev/null +++ b/msb-430/Makefile @@ -0,0 +1,37 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = msb-430_base.a + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430x16x/include/ + +all: $(BINDIR)$(ARCH) + $(MAKE) -C ../msb-430-common + +$(BINDIR)$(ARCH): $(OBJ) + mkdir -p $(BINDIR) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + $(MAKE) -C ../msb-430-common clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi + + + diff --git a/msb-430/Makefile.include b/msb-430/Makefile.include new file mode 100644 index 0000000000..c42b46b063 --- /dev/null +++ b/msb-430/Makefile.include @@ -0,0 +1 @@ +include $(RIOTBOARD)/msb-430-common/Makefile.include diff --git a/msb-430h/makefile b/msb-430h/Makefile similarity index 100% rename from msb-430h/makefile rename to msb-430h/Makefile diff --git a/msba2-common/makefile b/msba2-common/Makefile similarity index 100% rename from msba2-common/makefile rename to msba2-common/Makefile diff --git a/msba2-common/drivers/makefile b/msba2-common/drivers/Makefile similarity index 100% rename from msba2-common/drivers/makefile rename to msba2-common/drivers/Makefile diff --git a/msba2/makefile b/msba2/Makefile similarity index 100% rename from msba2/makefile rename to msba2/Makefile From 9f9308b4d1e4deb59c10523bde5cda03f2cd7cff Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Tue, 12 Mar 2013 15:51:09 +0100 Subject: [PATCH 078/188] renamed makefile --- native/{makefile => Makefile} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename native/{makefile => Makefile} (100%) diff --git a/native/makefile b/native/Makefile similarity index 100% rename from native/makefile rename to native/Makefile From 679aca926ac868c2c27c12f028df1b7dce5f9122 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 13 Mar 2013 16:52:00 +0100 Subject: [PATCH 079/188] * added Makefile.include to msba2(-common) --- msba2-common/Makefile.include | 22 ++++++++++++++++++++++ msba2/Makefile.include | 1 + 2 files changed, 23 insertions(+) create mode 100644 msba2-common/Makefile.include create mode 100644 msba2/Makefile.include diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include new file mode 100644 index 0000000000..e0c7efc57c --- /dev/null +++ b/msba2-common/Makefile.include @@ -0,0 +1,22 @@ +## the cpu to build for +export CPU = lpc2387 + +# toolchain config +export PREFIX = @arm-elf- +export CC = @$(PREFIX)gcc +export AR = @$(PREFIX)ar +export CFLAGS = -std=gnu99 -O2 -Wall -Wstrict-prototypes -mcpu=arm7tdmi-s -gdwarf-2 +export ASFLAGS = -gdwarf-2 -mcpu=arm7tdmi-s +export AS = $(PREFIX)as +export LINK = $(PREFIX)gcc +export SIZE = $(PREFIX)size +export OBJCOPY = $(PREFIX)objcopy +FLASHER = lpc2k_pgm +TERM = pyterm.py +LINKFLAGS = -gdwarf-2 -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T$(RIOTBASE)/cpu/$(CPU)/linkerscript.x + +ifeq ($(strip $(PORT)),) + export PORT = /dev/ttyUSB0 +endif +export HEXFILE = bin/$(PROJECT).hex +export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" diff --git a/msba2/Makefile.include b/msba2/Makefile.include new file mode 100644 index 0000000000..814b729673 --- /dev/null +++ b/msba2/Makefile.include @@ -0,0 +1 @@ +include $(RIOTBOARD)/msba2-common/Makefile.include From fa62cfe68869ff22b21a51fff54de10639222cdc Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 13 Mar 2013 17:46:48 +0100 Subject: [PATCH 080/188] * deleted Jam files --- Jamfile | 3 -- chronos/Jamfile | 10 ------- chronos/Jamrules.chronos | 14 ---------- chronos/drivers/Jamfile | 11 -------- msb-430-common/Jamfile | 34 ----------------------- msb-430-common/Jamrules.msb-430-common | 38 -------------------------- msb-430/Jamfile | 32 ---------------------- msb-430/Jamrules.msb-430 | 3 -- msb-430h/Jamfile | 33 ---------------------- msb-430h/Jamrules.msb-430h | 3 -- msba2-common/Jamfile | 7 ----- msba2-common/Jamfile.msba2 | 30 -------------------- msba2-common/Jamrules.msba2 | 34 ----------------------- msba2-common/drivers/Jamfile | 6 ---- msba2-common/tools/src/Jamfile | 9 ------ msba2/Jamfile | 34 ----------------------- msba2/Jamrules.msba2 | 1 - olimex_lpc2148/Jamfile | 10 ------- olimex_lpc2148/Jamfile.olimex_lpc2148 | 4 --- olimex_lpc2148/Jamrules.olimex_lpc2148 | 9 ------ pttu/Jamfile | 34 ----------------------- pttu/Jamfile.pttu | 28 ------------------- pttu/Jamrules.pttu | 34 ----------------------- pttu/drivers/Jamfile | 2 -- 24 files changed, 423 deletions(-) delete mode 100644 Jamfile delete mode 100644 chronos/Jamfile delete mode 100644 chronos/Jamrules.chronos delete mode 100644 chronos/drivers/Jamfile delete mode 100644 msb-430-common/Jamfile delete mode 100644 msb-430-common/Jamrules.msb-430-common delete mode 100644 msb-430/Jamfile delete mode 100644 msb-430/Jamrules.msb-430 delete mode 100644 msb-430h/Jamfile delete mode 100644 msb-430h/Jamrules.msb-430h delete mode 100644 msba2-common/Jamfile delete mode 100644 msba2-common/Jamfile.msba2 delete mode 100644 msba2-common/Jamrules.msba2 delete mode 100644 msba2-common/drivers/Jamfile delete mode 100644 msba2-common/tools/src/Jamfile delete mode 100644 msba2/Jamfile delete mode 100644 msba2/Jamrules.msba2 delete mode 100644 olimex_lpc2148/Jamfile delete mode 100644 olimex_lpc2148/Jamfile.olimex_lpc2148 delete mode 100644 olimex_lpc2148/Jamrules.olimex_lpc2148 delete mode 100644 pttu/Jamfile delete mode 100644 pttu/Jamfile.pttu delete mode 100644 pttu/Jamrules.pttu delete mode 100644 pttu/drivers/Jamfile diff --git a/Jamfile b/Jamfile deleted file mode 100644 index ad37fbe5b6..0000000000 --- a/Jamfile +++ /dev/null @@ -1,3 +0,0 @@ -SubDir TOP board ; - -SubInclude TOP board $(BOARD) ; diff --git a/chronos/Jamfile b/chronos/Jamfile deleted file mode 100644 index 0899e4631b..0000000000 --- a/chronos/Jamfile +++ /dev/null @@ -1,10 +0,0 @@ -SubDir TOP board chronos ; - -HDRS += $(TOP)/board/$(CPU)/include ; - -Module board : putchar.c board_init.c ; -UseModule board ; - -SubInclude TOP board $(BOARD) drivers ; -SubInclude TOP cpu $(CPU) ; - diff --git a/chronos/Jamrules.chronos b/chronos/Jamrules.chronos deleted file mode 100644 index 4c17a9a9ae..0000000000 --- a/chronos/Jamrules.chronos +++ /dev/null @@ -1,14 +0,0 @@ -# ****************************************************************************** -# Copyright 2010, Freie Universitaet Berlin (FUB). All rights reserved. -# ****************************************************************************** -# $Id$ - -BOARD = chronos ; -CPU = cc430 ; -MCU = cc430x6137 ; - -HDRS += [ FPath $(TOP) board chronos drivers include ] ; - -FLASHER ?= mspdebug ; -FLASHFLAGS ?= rf2500 ; - diff --git a/chronos/drivers/Jamfile b/chronos/drivers/Jamfile deleted file mode 100644 index 71ee1c982c..0000000000 --- a/chronos/drivers/Jamfile +++ /dev/null @@ -1,11 +0,0 @@ -SubDir TOP board chronos drivers ; - -HDRS += $(TOP)/board/$(CPU)/drivers/include ; - -Module board_display : display.c display1.c ; -Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ; -Module board_buzzer : buzzer.c : hwtimer ; -Module battery : battery.c : adc hwtimer ; -Module vti_ps_twi : vti_ps_twi.c : hwtimer ; - -Module display_putchar : display_putchar.c : board_display ; diff --git a/msb-430-common/Jamfile b/msb-430-common/Jamfile deleted file mode 100644 index 78807c1441..0000000000 --- a/msb-430-common/Jamfile +++ /dev/null @@ -1,34 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -SubDir TOP board msb-430-common ; - -Module board : board_init.c uart1.c ; -Module board_config : board_config.c : flashrom ; -UseModule board ; - -SubInclude TOP cpu $(CPU) ; diff --git a/msb-430-common/Jamrules.msb-430-common b/msb-430-common/Jamrules.msb-430-common deleted file mode 100644 index 7eee8b088f..0000000000 --- a/msb-430-common/Jamrules.msb-430-common +++ /dev/null @@ -1,38 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -CPU = msp430x16x ; -MCU = msp430x1612 ; - -FLASH_PORT ?= "$(PORT)" ; -FLASHER ?= mspdebug ; -FLASHFLAGS ?= -d $(FLASH_PORT) -j uif ; - -RESET ?= $(FLASHER) $(FLASHFLAGS) reset ; - -HDRS += [ FPath $(TOP) board msb-430-common include ] ; -HDRS += [ FPath $(TOP) board msb-430-common drivers include ] ; diff --git a/msb-430/Jamfile b/msb-430/Jamfile deleted file mode 100644 index f2592c24cf..0000000000 --- a/msb-430/Jamfile +++ /dev/null @@ -1,32 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -SubDir TOP board msb-430 ; - -SubInclude TOP board msb-430-common ; -SubInclude TOP cpu $(CPU) ; - diff --git a/msb-430/Jamrules.msb-430 b/msb-430/Jamrules.msb-430 deleted file mode 100644 index ae1d28b444..0000000000 --- a/msb-430/Jamrules.msb-430 +++ /dev/null @@ -1,3 +0,0 @@ -BOARD = msb-430 ; - -include $(TOP)/board/msb-430-common/Jamrules.msb-430-common ; diff --git a/msb-430h/Jamfile b/msb-430h/Jamfile deleted file mode 100644 index 9f9ee47bf3..0000000000 --- a/msb-430h/Jamfile +++ /dev/null @@ -1,33 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -SubDir TOP board msb-430h ; - -Module board_cc110x : driver_cc110x.c : cc110x_spi ; - -SubInclude TOP board msb-430-common ; -SubInclude TOP cpu $(CPU) ; diff --git a/msb-430h/Jamrules.msb-430h b/msb-430h/Jamrules.msb-430h deleted file mode 100644 index d1913ed542..0000000000 --- a/msb-430h/Jamrules.msb-430h +++ /dev/null @@ -1,3 +0,0 @@ -BOARD = msb-430h ; - -include $(TOP)/board/msb-430-common/Jamrules.msb-430-common ; diff --git a/msba2-common/Jamfile b/msba2-common/Jamfile deleted file mode 100644 index ff9a8ccd4c..0000000000 --- a/msba2-common/Jamfile +++ /dev/null @@ -1,7 +0,0 @@ -SubDir TOP board msba2-common ; - -Module board_common : board_common_init.c ; -Module board_config : board_config.c ; - -SubInclude TOP board msba2-common drivers ; - diff --git a/msba2-common/Jamfile.msba2 b/msba2-common/Jamfile.msba2 deleted file mode 100644 index e9e291c906..0000000000 --- a/msba2-common/Jamfile.msba2 +++ /dev/null @@ -1,30 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -Module msba2_common : board_init.c ; - -include [ FPath $(TOP) cpu arm_common Jamfile.arm_common ] ; diff --git a/msba2-common/Jamrules.msba2 b/msba2-common/Jamrules.msba2 deleted file mode 100644 index 1bce8075c4..0000000000 --- a/msba2-common/Jamrules.msba2 +++ /dev/null @@ -1,34 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -CPU = lpc2387 ; - -HDRS += [ FPath $(TOP) board msba2-common include ] ; -HDRS += [ FPath $(TOP) board msba2-common drivers include ] ; - -FLASHER ?= $(POSIXSHELL) lpc2k_pgm ; -FLASHFLAGS ?= "$(PORT)" ; diff --git a/msba2-common/drivers/Jamfile b/msba2-common/drivers/Jamfile deleted file mode 100644 index ed8e73498a..0000000000 --- a/msba2-common/drivers/Jamfile +++ /dev/null @@ -1,6 +0,0 @@ -SubDir TOP board msba2-common drivers ; - -Module board_cc110x : msba2-cc110x.c : cc110x_spi gpioint ; -Module board_ltc4150 : msba2-ltc4150.c : gpioint ; -Module board_uart : msba2-uart0.c : chardev_thread ringbuffer ; - diff --git a/msba2-common/tools/src/Jamfile b/msba2-common/tools/src/Jamfile deleted file mode 100644 index 43ead81f93..0000000000 --- a/msba2-common/tools/src/Jamfile +++ /dev/null @@ -1,9 +0,0 @@ -Library liblpc2k : download.c uuencode.c ihex.c serial.c chipinfo.c boot_2xxx.c boot_23xx.c control_2xxx.c ; - -LinkLibraries lpc2k_pgm : liblpc2k ; - -LinkLibraries pseudoterm : liblpc2k ; -LINKFLAGS on pseudoterm = -lrt ; - -Main lpc2k_pgm : lpc2k_pgm.c ; -Main pseudoterm : pseudoterm.c ; diff --git a/msba2/Jamfile b/msba2/Jamfile deleted file mode 100644 index 6e74471b63..0000000000 --- a/msba2/Jamfile +++ /dev/null @@ -1,34 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -SubDir TOP board $(BOARD) ; - -Module board : board_init.c : board_common board_uart ; -UseModule board ; - -SubInclude TOP board $(BOARD)-common ; -SubInclude TOP cpu $(CPU) ; diff --git a/msba2/Jamrules.msba2 b/msba2/Jamrules.msba2 deleted file mode 100644 index 22c8a88060..0000000000 --- a/msba2/Jamrules.msba2 +++ /dev/null @@ -1 +0,0 @@ -include board/msba2-common/Jamrules.msba2 ; diff --git a/olimex_lpc2148/Jamfile b/olimex_lpc2148/Jamfile deleted file mode 100644 index 43ad7d1baf..0000000000 --- a/olimex_lpc2148/Jamfile +++ /dev/null @@ -1,10 +0,0 @@ -SubDir TOP board olimex_lpc2148 ; - -CPU = lpc214x ; - -HDRS += $(TOP)/board/olimex_lpc2148/include ; - -Module board : board_init.c debug_uart.c rs232.c ; -UseModule board ; - -SubInclude TOP cpu lpc214x ; diff --git a/olimex_lpc2148/Jamfile.olimex_lpc2148 b/olimex_lpc2148/Jamfile.olimex_lpc2148 deleted file mode 100644 index 057aa7b322..0000000000 --- a/olimex_lpc2148/Jamfile.olimex_lpc2148 +++ /dev/null @@ -1,4 +0,0 @@ -################## - -include $(TOP)/Jamfile.arm_common ; - diff --git a/olimex_lpc2148/Jamrules.olimex_lpc2148 b/olimex_lpc2148/Jamrules.olimex_lpc2148 deleted file mode 100644 index 7a7086d5bc..0000000000 --- a/olimex_lpc2148/Jamrules.olimex_lpc2148 +++ /dev/null @@ -1,9 +0,0 @@ -############################ - -BOARD = olimex_lpc2148 ; -CPU = lpc214x ; - -GDB = arm-elf-gdb ; -GDBFLAGS = -x board/olimex_lpc2148/tools/lpc2148_flash.gdb ; - -include $(TOP)/Jamrules.arm_common ; diff --git a/pttu/Jamfile b/pttu/Jamfile deleted file mode 100644 index 11b4a77e7e..0000000000 --- a/pttu/Jamfile +++ /dev/null @@ -1,34 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id$ - -SubDir TOP board $(BOARD) ; - -Module board : board_init.c : board_common board_uart ; -UseModule board ; - -SubInclude TOP board msba2-common ; -SubInclude TOP cpu $(CPU) ; diff --git a/pttu/Jamfile.pttu b/pttu/Jamfile.pttu deleted file mode 100644 index 1bce8934fe..0000000000 --- a/pttu/Jamfile.pttu +++ /dev/null @@ -1,28 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id: Jamfile.msba2 832 2009-03-13 16:45:41Z kaspar $ - -include [ FPath $(TOP) cpu arm_common Jamfile.arm_common ] ; diff --git a/pttu/Jamrules.pttu b/pttu/Jamrules.pttu deleted file mode 100644 index 53e71c71f1..0000000000 --- a/pttu/Jamrules.pttu +++ /dev/null @@ -1,34 +0,0 @@ -# ****************************************************************************** -# Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. -# -# These sources were developed at the Freie Universitaet Berlin, Computer -# Systems and Telematics group (http://cst.mi.fu-berlin.de). -# ------------------------------------------------------------------------------ -# This file is part of FeuerWare. -# -# This program is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# FeuerWare is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program. If not, see http://www.gnu.org/licenses/ . -# ------------------------------------------------------------------------------ -# For further information and questions please use the web site -# http://scatterweb.mi.fu-berlin.de -# and the mailinglist (subscription via web site) -# scatterweb@lists.spline.inf.fu-berlin.de -# ****************************************************************************** -# $Id: Jamrules.msba2 881 2009-03-20 12:24:58Z kaspar $ - -include board/msba2-common/Jamrules.msba2 ; - -HDRS += [ FPath $(TOP) board $(BOARD) drivers include ] ; - -GDB = arm-elf-gdb ; -GDBFLAGS = -x board/pttu/tools/pttu_debug.gdb ; - diff --git a/pttu/drivers/Jamfile b/pttu/drivers/Jamfile deleted file mode 100644 index 31d6db1d6d..0000000000 --- a/pttu/drivers/Jamfile +++ /dev/null @@ -1,2 +0,0 @@ -SubDir TOP board pttu drivers ; - From 6bdc2573691bf2894ef2cf9a8e52f9fc3ec214ea Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 13 Mar 2013 21:45:28 +0100 Subject: [PATCH 081/188] add doxygen documentation --- native/board_config.c | 10 +++++++++- native/board_init.c | 6 +++++- native/include/board.h | 4 +++- native/native-led.c | 4 +++- native/native-ltc4150.c | 20 ++++++++++++++++++-- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/native/board_config.c b/native/board_config.c index 317cdbb79e..dafdf747aa 100644 --- a/native/board_config.c +++ b/native/board_config.c @@ -1,12 +1,14 @@ /** * Native Board config.h implementation * + * No functionality implemented at the moment. + * * Copyright (C) 2013 Ludwig Ortmann * * This file subject to the terms and conditions of the GNU General Public * License. See the file LICENSE in the top level directory for more details. * - * @ingroup native + * @ingroup native_board * @{ * @file * @author Ludwig Ortmann @@ -18,12 +20,18 @@ #include +/** + * XXX: loading not implemented + */ void config_load(void) { printf("XXX: config_load(): not implemented\n"); return; } +/** + * XXX: storing not implemented + */ uint8_t config_save(void) { printf("XXX: config_save(): not implemented - your config will vanish on process termination\n"); diff --git a/native/board_init.c b/native/board_init.c index 9a3266703e..d6f4c4ba31 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -6,7 +6,7 @@ * This file subject to the terms and conditions of the GNU General Public * License. See the file LICENSE in the top level directory for more details. * - * @ingroup native + * @ingroup native_board * @{ * @file * @author Ludwig Ortmann @@ -15,6 +15,10 @@ #include "board.h" +/** + * Nothing to initialize at the moment. + * Turns the red LED on and the green LED off. + */ void board_init() { LED_GREEN_OFF(); diff --git a/native/include/board.h b/native/include/board.h index 71afb726ce..457289a566 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -1,12 +1,14 @@ /** * Native Board interface * + * The native board uses call level hardware simulation. + * * Copyright (C) 2013 Ludwig Ortmann * * This file subject to the terms and conditions of the GNU General Public * License. See the file LICENSE in the top level directory for more details. * - * @ingroup native + * @defgroup native_board * @{ * @file * @author Ludwig Ortmann diff --git a/native/native-led.c b/native/native-led.c index 2ee9d4979b..f2091c9a37 100644 --- a/native/native-led.c +++ b/native/native-led.c @@ -1,12 +1,14 @@ /** * Native Board LED implementation * + * Only prints function calls at the moment. + * * Copyright (C) 2013 Ludwig Ortmann * * This file subject to the terms and conditions of the GNU General Public * License. See the file LICENSE in the top level directory for more details. * - * @ingroup native + * @ingroup native_board * @{ * @file * @author Ludwig Ortmann diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c index e18dee912d..99b4d0a3e5 100644 --- a/native/native-ltc4150.c +++ b/native/native-ltc4150.c @@ -1,16 +1,19 @@ /** * Native Board ltc4150_arch.h implementation * + * Only measures time at the moment. Uses POSIX real-time extension + * timer to generate periodic signal/interrupt. + * * Copyright (C) 2013 Ludwig Ortmann * * This file subject to the terms and conditions of the GNU General Public * License. See the file LICENSE in the top level directory for more details. * - * @ingroup native + * @ingroup native_board + * @ingroup ltc4150 * @{ * @file * @author Ludwig Ortmann - * @} */ #include @@ -29,24 +32,36 @@ static timer_t native_ltc4150_timer; static struct itimerspec native_ltc4150_timer_time; +/** + * unregister signal handler + */ void ltc4150_disable_int(void) { DEBUG("ltc4150_disable_int()\n"); unregister_interrupt(_SIG_LTC4150); } +/** + * register signal handler + */ void ltc4150_enable_int(void) { DEBUG("ltc4150_enable_int()\n"); register_interrupt(_SIG_LTC4150, ltc4150_interrupt); } +/** + * elaborate nop + */ void ltc4150_sync_blocking(void) { DEBUG("ltc4150_sync_blocking()\n"); for(int i = native_ltc4150_startup_delay; i>0; i--); } +/** + * set up posix real-time timer to simulate coloumb counter ticks + */ void ltc4150_arch_init(void) { struct sigevent sev; @@ -74,3 +89,4 @@ void ltc4150_arch_init(void) puts("Native LTC4150 initialized."); } +/** @} */ From defd7cef13987a19bd2db1e3fbe56138beadcdd8 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 18 Mar 2013 19:35:39 +0100 Subject: [PATCH 082/188] * fixed lpc2k_pgm (was broken in d9017085432f2aa677ba8d6eb4de45e1d1c7982d) --- msba2-common/tools/src/control_2xxx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/msba2-common/tools/src/control_2xxx.c b/msba2-common/tools/src/control_2xxx.c index ac0c8ca975..64f7046e9b 100644 --- a/msba2-common/tools/src/control_2xxx.c +++ b/msba2-common/tools/src/control_2xxx.c @@ -13,7 +13,7 @@ void hard_reset_to_bootloader(void) getchar(); */ printf("Reset CPU (into bootloader)\r\n"); - set_rts(0); // 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 @@ -24,14 +24,14 @@ void hard_reset_to_bootloader(void) */ set_dtr(0); // allow the CPU to run: set_baud(baud_rate); - set_rts(0); // set RTS again (as it has been reset by set_baudrate) + 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(1); // RTS (ttl level) connects to P0.14 + et_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); From 1604de8c55c4f8b3c307371178217b3d3b1b4b4e Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 19 Mar 2013 17:57:43 +0100 Subject: [PATCH 083/188] * added msba2-common/include to INCLUDE path for msba2 --- msba2/Makefile.include | 2 ++ 1 file changed, 2 insertions(+) diff --git a/msba2/Makefile.include b/msba2/Makefile.include index 814b729673..741b952a92 100644 --- a/msba2/Makefile.include +++ b/msba2/Makefile.include @@ -1 +1,3 @@ +export INCLUDES += -I$(RIOTBOARD)/msba2-common/include + include $(RIOTBOARD)/msba2-common/Makefile.include From 3b8adabdbd06f77d44571f05f530d3d46c2c2395 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Tue, 19 Mar 2013 22:02:22 +0100 Subject: [PATCH 084/188] migrate to current Makefile structure --- native/Makefile.include | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 native/Makefile.include diff --git a/native/Makefile.include b/native/Makefile.include new file mode 100644 index 0000000000..a14da50af5 --- /dev/null +++ b/native/Makefile.include @@ -0,0 +1,21 @@ +export INCLUDES += -I$(RIOTBOARD)/native/include +export CPU = native + +# toolchain config +export PREFIX = +#export CC = @$(PREFIX)gcc +export AR = @$(PREFIX)ar +export CFLAGS = -std=gnu99 -Wall -m32 +export ASFLAGS = +export AS = $(PREFIX)as +export LINK = $(PREFIX)gcc +export SIZE = $(PREFIX)size +export OBJCOPY = $(PREFIX)objcopy +FLASHER = lpc2k_pgm +TERM = pyterm.py + +LINKFLAGS = -lrt -m32 + +ifeq ($(strip $(PORT)),) + export PORT = /dev/ttyUSB0 +endif From 1b2d1925568c6efbe66a138eb9c4754a38b0745d Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Thu, 21 Mar 2013 17:49:59 +0100 Subject: [PATCH 085/188] * fixed bindir creation in msba2 Makefile --- msba2/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msba2/Makefile b/msba2/Makefile index dab7d39a76..a539327476 100644 --- a/msba2/Makefile +++ b/msba2/Makefile @@ -20,7 +20,7 @@ $(BINDIR)$(ARCH): $(OBJ) # compile and generate dependency info $(BINDIR)%.o: %.c - mkdir $(BINDIR) + mkdir -p $(BINDIR) $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d From 0de960b03803702447cc8609847cb1e16d156fad Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Sat, 23 Mar 2013 18:42:11 +0100 Subject: [PATCH 086/188] * adapted Makefiles to core restructuring --- Makefile.base | 18 ++++++++++++++++++ msb-430h/Makefile.dep | 6 ++++++ msb-430h/Makefile.include | 3 +++ msba2-common/Makefile.dep | 8 ++++++++ msba2-common/Makefile.include | 2 ++ 5 files changed, 37 insertions(+) create mode 100644 Makefile.base create mode 100644 msb-430h/Makefile.dep create mode 100644 msb-430h/Makefile.include create mode 100644 msba2-common/Makefile.dep diff --git a/Makefile.base b/Makefile.base new file mode 100644 index 0000000000..1b1177f894 --- /dev/null +++ b/Makefile.base @@ -0,0 +1,18 @@ +ifeq ($(BOARD),msba2) + INCLUDES += -I$(RIOTBOARD)/msba2/include/ + INCLUDES += -I$(RIOTBOARD)/msba2-common/include/ + INCLUDES += -I$(RIOTBOARD)/msba2-common/drivers/include/ +endif +ifeq ($(BOARD),msb-430) + INCLUDES += -I$(RIOTBOARD)/msb-430/include/ + INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ + INCLUDES += -I$(RIOTBOARD)/msb-430-common/drivers/include/ +endif +ifeq ($(BOARD),msb-430h) + INCLUDES += -I$(RIOTBOARD)/msb-430h/include/ + INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ + INCLUDES += -I$(RIOTBOARD)/msb-430-common/drivers/include/ +endif +ifeq ($(BOARD),native) + INCLUDES += -I$(RIOTBOARD)/native/include/ +endif diff --git a/msb-430h/Makefile.dep b/msb-430h/Makefile.dep new file mode 100644 index 0000000000..de1d7e692c --- /dev/null +++ b/msb-430h/Makefile.dep @@ -0,0 +1,6 @@ +ifneq (,$(findstring cc110x_ng,$(USEMODULE))) + ifeq (,$(findstring cc110x_spi,$(USEMODULE))) + USEMODULE += cc110x_spi + endif +endif + diff --git a/msb-430h/Makefile.include b/msb-430h/Makefile.include new file mode 100644 index 0000000000..c5716486eb --- /dev/null +++ b/msb-430h/Makefile.include @@ -0,0 +1,3 @@ +include $(RIOTBOARD)/$(BOARD)/Makefile.dep + +include $(RIOTBOARD)/msb-430-common/Makefile.include diff --git a/msba2-common/Makefile.dep b/msba2-common/Makefile.dep new file mode 100644 index 0000000000..5182f34f4b --- /dev/null +++ b/msba2-common/Makefile.dep @@ -0,0 +1,8 @@ +ifneq (,$(findstring cc110x_ng,$(USEMODULE))) + ifeq (,$(findstring cc110x_spi,$(USEMODULE))) + USEMODULE += cc110x_spi + endif + ifeq (,$(findstring gpioint,$(USEMODULE))) + USEMODULE += gpioint + endif +endif diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index e0c7efc57c..fa6cb01c37 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -20,3 +20,5 @@ ifeq ($(strip $(PORT)),) endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" + +include $(RIOTBOARD)/msba2-common/Makefile.dep From 212d840a1fee00571249bb7e55e524aa3db97815 Mon Sep 17 00:00:00 2001 From: mikoff Date: Sat, 30 Mar 2013 21:37:56 +0100 Subject: [PATCH 087/188] modified and cleaned some files to build RIOT for chronos --- Makefile.base | 4 ++++ chronos/Makefile | 12 ++++++------ chronos/Makefile.include | 21 ++++++++++++++++++++ chronos/board_init.c | 2 +- chronos/drivers/Makefile | 24 +++++++++++++++++++++++ chronos/drivers/battery.c | 2 +- chronos/drivers/buzzer.c | 2 +- chronos/drivers/cc430-cc110x.c | 2 +- chronos/drivers/display.c | 2 +- chronos/drivers/display1.c | 3 ++- chronos/drivers/display_putchar.c | 4 ++-- chronos/drivers/include/display_putchar.h | 2 +- chronos/include/board.h | 2 +- 13 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 chronos/Makefile.include create mode 100644 chronos/drivers/Makefile diff --git a/Makefile.base b/Makefile.base index 1b1177f894..a9a5375397 100644 --- a/Makefile.base +++ b/Makefile.base @@ -13,6 +13,10 @@ ifeq ($(BOARD),msb-430h) INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ INCLUDES += -I$(RIOTBOARD)/msb-430-common/drivers/include/ endif +ifeq ($(BOARD),chronos) + INCLUDES += -I$(RIOTBOARD)/chronos/include/ + INCLUDES += -I$(RIOTBOARD)/chronos/drivers/include/ +endif ifeq ($(BOARD),native) INCLUDES += -I$(RIOTBOARD)/native/include/ endif diff --git a/chronos/Makefile b/chronos/Makefile index aae0e9956c..1b8144cb49 100644 --- a/chronos/Makefile +++ b/chronos/Makefile @@ -4,12 +4,12 @@ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines DEP = $(SRC:%.c=$(BINDIR)%.d) -INCLUDES = -Iinclude -I../../feuerware-base/sys/lib -I../../feuerware-base/sys/drivers/include -INCLUDES += -I../../feuerware-base/sys/drivers/cc110x_ng/include -INCLUDES += -I../../feuerware-base/core/include -INCLUDES += -I../../feuerware-base/cpu/msp430/include/ -INCLUDES += -I../../feuerware-base/cpu/cc430/include/ -INCLUDES += -I/usr/msp430/include/ +INCLUDES += -Iinclude -I$(RIOTBASE)/sys/lib -I$(RIOTBASE)/sys/drivers/include +INCLUDES += -I$(RIOTBASE)/sys/drivers/cc110x_ng/include +INCLUDES += -I$(RIOTBASE)/core/include +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/cc430/include/ +#INCLUDES += -I/usr/msp430/include/ all: $(BINDIR)chronos_base.a $(MAKE) -C drivers diff --git a/chronos/Makefile.include b/chronos/Makefile.include new file mode 100644 index 0000000000..47ba1a079f --- /dev/null +++ b/chronos/Makefile.include @@ -0,0 +1,21 @@ +## the cpu to build for +export CPU = cc430 +export MCU = cc430f6137 + +# toolchain config +export PREFIX = @msp430- +export CC = @$(PREFIX)gcc +export AR = @$(PREFIX)ar +export CFLAGS += -std=gnu99 -Wstrict-prototypes -gdwarf-2 -Os -Wall -mmcu=$(MCU) -D CC430 +export ASFLAGS += -mmcu=$(MCU) --defsym $(MCU)=1 --gdwarf-2 +export AS = $(PREFIX)as +export LINK = $(PREFIX)gcc +export SIZE = $(PREFIX)size +export OBJCOPY = $(PREFIX)objcopy +export LINKFLAGS = -mmcu=$(MCU) -lgcc $(RIOTBASE)/bin/startup.o +export FLASHER = mspdebug +ifeq ($(strip $(PORT)),) + export PORT = /dev/ttyUSB0 +endif +export HEXFILE = bin/$(PROJECT).hex +export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" diff --git a/chronos/board_init.c b/chronos/board_init.c index 74799abace..95e5dfd3a7 100644 --- a/chronos/board_init.c +++ b/chronos/board_init.c @@ -69,6 +69,6 @@ void cc430_cpu_init(void) { } -void board_init() { +void board_init(void) { cc430_cpu_init(); } diff --git a/chronos/drivers/Makefile b/chronos/drivers/Makefile new file mode 100644 index 0000000000..bf355bf8e2 --- /dev/null +++ b/chronos/drivers/Makefile @@ -0,0 +1,24 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o) +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ + +$(BINDIR)chronos_drivers.a: $(OBJ) + $(AR) rcs $(BINDIR)chronos_base.a $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)" | cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products + +clean: + rm -f $(OBJ) $(DEP) + diff --git a/chronos/drivers/battery.c b/chronos/drivers/battery.c index bae37d3295..6ca24a3b67 100644 --- a/chronos/drivers/battery.c +++ b/chronos/drivers/battery.c @@ -1,5 +1,5 @@ #include -#include +#include #include uint32_t battery_get_voltage(void) { diff --git a/chronos/drivers/buzzer.c b/chronos/drivers/buzzer.c index 5e0bc2ca34..b8f5327450 100644 --- a/chronos/drivers/buzzer.c +++ b/chronos/drivers/buzzer.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include void buzzer_beep(uint8_t pitch, uint16_t duration) { // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK diff --git a/chronos/drivers/cc430-cc110x.c b/chronos/drivers/cc430-cc110x.c index 78380c4ca4..0a38b68b7b 100644 --- a/chronos/drivers/cc430-cc110x.c +++ b/chronos/drivers/cc430-cc110x.c @@ -6,7 +6,7 @@ #include //#include -#include +#include //#include #define CC1100_GDO0 (RF1AIN & BIT0) diff --git a/chronos/drivers/display.c b/chronos/drivers/display.c index 063ade5855..f33cd6eaf1 100644 --- a/chronos/drivers/display.c +++ b/chronos/drivers/display.c @@ -43,7 +43,7 @@ #include /* driver */ -#include +#include #include diff --git a/chronos/drivers/display1.c b/chronos/drivers/display1.c index 40795d54bb..a45c74625e 100644 --- a/chronos/drivers/display1.c +++ b/chronos/drivers/display1.c @@ -38,7 +38,8 @@ /* ************************************************************************************************* */ /* Include section */ -#include +#include +#include #include /* ************************************************************************************************* */ diff --git a/chronos/drivers/display_putchar.c b/chronos/drivers/display_putchar.c index 2f1d9468af..ca0e9b396b 100644 --- a/chronos/drivers/display_putchar.c +++ b/chronos/drivers/display_putchar.c @@ -7,9 +7,9 @@ extern void (*_putchar)(int c); static char display_buf[11]; -void putchar_to_display(); +void putchar_to_display(int c); -void init_display_putchar() { +void init_display_putchar(void) { memset(display_buf, '\0', 11); _putchar = putchar_to_display; } diff --git a/chronos/drivers/include/display_putchar.h b/chronos/drivers/include/display_putchar.h index 6adbb9c9c0..504ece6ebd 100644 --- a/chronos/drivers/include/display_putchar.h +++ b/chronos/drivers/include/display_putchar.h @@ -1,6 +1,6 @@ #ifndef __DISPLAY_PUTCHAR_H #define __DISPLAY_PUTCHAR_H -void init_display_putchar(); +void init_display_putchar(void); #endif /* __DISPLAY_PUTCHAR_H */ diff --git a/chronos/include/board.h b/chronos/include/board.h index af0a99b5da..3186b63316 100644 --- a/chronos/include/board.h +++ b/chronos/include/board.h @@ -1,7 +1,7 @@ #ifndef _MSB_BOARD_H #define _MSB_BOARD_H -#include +#include #define MSP430_INITIAL_CPU_SPEED 7372800uL #define MSP430_HAS_DCOR 1 From 519144f40ace32782d40a5e17de8fe51fb8f4f34 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 1 Apr 2013 00:00:42 +0200 Subject: [PATCH 088/188] * changed MCU name to adapt to current msp430-gcc version --- msb-430-common/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msb-430-common/Makefile.include b/msb-430-common/Makefile.include index d3d4dfd3ba..0f578d2ce7 100644 --- a/msb-430-common/Makefile.include +++ b/msb-430-common/Makefile.include @@ -1,6 +1,6 @@ ## the cpu to build for export CPU = msp430x16x -export MCU = msp430x1612 +export MCU = msp430f1612 # toolchain config export PREFIX = @msp430- From b0d9e4f86f4cbc0310098a788849bc5df9ba562d Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 1 Apr 2013 00:09:56 +0200 Subject: [PATCH 089/188] * removed unnecessary line from msba2 Makefile --- msba2-common/Makefile.include | 1 - 1 file changed, 1 deletion(-) diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index fa6cb01c37..218370b258 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -19,6 +19,5 @@ ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 endif export HEXFILE = bin/$(PROJECT).hex -export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" include $(RIOTBOARD)/msba2-common/Makefile.dep From a9caa848263de7fb39cf70204346c25013de4332 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 2 Apr 2013 10:06:17 +0200 Subject: [PATCH 090/188] * initial commit for yet not working redbee support --- redbee-econotag/Makefile | 26 ++++++++++++++++ redbee-econotag/Makefile.dep | 0 redbee-econotag/Makefile.include | 27 ++++++++++++++++ redbee-econotag/board_init.c | 11 +++++++ redbee-econotag/drivers/Makefile | 26 ++++++++++++++++ redbee-econotag/drivers/redbee_uart1.c | 43 ++++++++++++++++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 redbee-econotag/Makefile create mode 100644 redbee-econotag/Makefile.dep create mode 100644 redbee-econotag/Makefile.include create mode 100644 redbee-econotag/board_init.c create mode 100644 redbee-econotag/drivers/Makefile create mode 100644 redbee-econotag/drivers/redbee_uart1.c diff --git a/redbee-econotag/Makefile b/redbee-econotag/Makefile new file mode 100644 index 0000000000..391c9bd42f --- /dev/null +++ b/redbee-econotag/Makefile @@ -0,0 +1,26 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +DEP = $(SRC:%.c=$(BINDIR)%.d) +export ARCH = redbee-econotag_base.a + +all: $(BINDIR)$(ARCH) + $(MAKE) -C drivers + +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + ${MAKE} -C drivers clean + rm -f $(OBJ) $(DEP) + diff --git a/redbee-econotag/Makefile.dep b/redbee-econotag/Makefile.dep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/redbee-econotag/Makefile.include b/redbee-econotag/Makefile.include new file mode 100644 index 0000000000..ee087fb781 --- /dev/null +++ b/redbee-econotag/Makefile.include @@ -0,0 +1,27 @@ +## the cpu to build for +export CPU = mc1322x + +# toolchain config +export PREFIX = @arm-none-eabi- +export CC = @$(PREFIX)gcc +export AR = @$(PREFIX)ar +export CFLAGS = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ + -msoft-float -mthumb-interwork -fno-strict-aliasing -fno-common \ + -ffixed-r8 -ffunction-sections -ffreestanding -fno-builtin \ + -nodefaultlibs -Wcast-align -Wall -Wstrict-prototypes -Wextra \ + -Os -pipe +$(warning TODO add -mthumb) +export AFLAGS = -Wa,-gstabs $(CFLAGS) +export AS = $(PREFIX)as +export LINK = $(PREFIX)gcc +export SIZE = $(PREFIX)size +export OBJCOPY = $(PREFIX)objcopy +FLASHER = lpc2k_pgm +TERM = pyterm.py +LINKFLAGS = -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T$(RIOTBASE)/cpu/$(CPU)/mc1322x.lds + +ifeq ($(strip $(PORT)),) + export PORT = /dev/ttyUSB0 +endif +export HEXFILE = bin/$(PROJECT).hex +export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" diff --git a/redbee-econotag/board_init.c b/redbee-econotag/board_init.c new file mode 100644 index 0000000000..5a0b03177c --- /dev/null +++ b/redbee-econotag/board_init.c @@ -0,0 +1,11 @@ +/* + * board_init.c - redbee-econotag initialization code + * Copyright (C) 2013 Oliver Hahm + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +void board_init(void) { + asm("nop"); +} diff --git a/redbee-econotag/drivers/Makefile b/redbee-econotag/drivers/Makefile new file mode 100644 index 0000000000..8b8b6094b9 --- /dev/null +++ b/redbee-econotag/drivers/Makefile @@ -0,0 +1,26 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o) +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ + +.PHONY: redbee-econotag_drivers.a + +$(BINDIR)redbee-econotag_common_drivers.a: $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)" | cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products + +clean: + rm -f $(OBJ) $(DEP) + diff --git a/redbee-econotag/drivers/redbee_uart1.c b/redbee-econotag/drivers/redbee_uart1.c new file mode 100644 index 0000000000..046ed26ab1 --- /dev/null +++ b/redbee-econotag/drivers/redbee_uart1.c @@ -0,0 +1,43 @@ +/* + * redbee_uart1.c - UART1 driver for redbee + * Copyright (C) 2013 Oliver Hahm + * + * 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" + +static volatile unsigned int running = 0; +static volatile unsigned int fifo = 0; + +static inline int uart0_puts(char *astring, int length) +{ + int i; + for (i=0;iTXCON != 0); + UART1->DATA = astring[i]; + } + return length; +} + +int fw_puts(char *astring, int length) +{ + return uart0_puts(astring, length); +} + +void stdio_flush(void) +{ + /* disable TX interrupt */ + UART1->CONbits.MTXR = 1; + while(running) { + while(UART1->TXCON != 0); + fifo=0; + push_queue(); // dequeue to fifo + } + /* enable TX interrupt */ + UART1->CONbits.MTXR = 0; +} From a623d1428612a1d92e73c75398ed348fa84966a5 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 9 Apr 2013 11:25:04 +0200 Subject: [PATCH 091/188] * fixed flasher flags for MSB-A2 * added required include for msb-430-common --- msb-430-common/Makefile.include | 2 ++ msba2-common/Makefile.include | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/msb-430-common/Makefile.include b/msb-430-common/Makefile.include index 0f578d2ce7..8fc09d2874 100644 --- a/msb-430-common/Makefile.include +++ b/msb-430-common/Makefile.include @@ -19,3 +19,5 @@ ifeq ($(strip $(PORT)),) endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" + +export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index 218370b258..83337fd035 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -19,5 +19,5 @@ ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 endif export HEXFILE = bin/$(PROJECT).hex - +export FFLAGS = $(PORT) $(PROJBINDIR)/$(PROJECT).hex include $(RIOTBOARD)/msba2-common/Makefile.dep From 34b2dc31e5bcd294672cfe4f6adfa00ea682c073 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 10 Apr 2013 12:52:19 +0200 Subject: [PATCH 092/188] adapted native Makefiles to core restructuring --- native/Makefile.dep | 6 ++++++ native/Makefile.include | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 native/Makefile.dep diff --git a/native/Makefile.dep b/native/Makefile.dep new file mode 100644 index 0000000000..de1d7e692c --- /dev/null +++ b/native/Makefile.dep @@ -0,0 +1,6 @@ +ifneq (,$(findstring cc110x_ng,$(USEMODULE))) + ifeq (,$(findstring cc110x_spi,$(USEMODULE))) + USEMODULE += cc110x_spi + endif +endif + diff --git a/native/Makefile.include b/native/Makefile.include index a14da50af5..e7bf1c65bd 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -19,3 +19,5 @@ LINKFLAGS = -lrt -m32 ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 endif + +include $(RIOTBOARD)/$(BOARD)/Makefile.dep From 9f27cf54bc7e53e0849ac25c74420b24063903a6 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 10 Apr 2013 16:07:40 +0200 Subject: [PATCH 093/188] * fixed the broken bugfix from defd7cef13987a19bd2db1e3fbe56138beadcdd8 --- msba2-common/tools/src/control_2xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msba2-common/tools/src/control_2xxx.c b/msba2-common/tools/src/control_2xxx.c index 64f7046e9b..6843fec204 100644 --- a/msba2-common/tools/src/control_2xxx.c +++ b/msba2-common/tools/src/control_2xxx.c @@ -31,7 +31,7 @@ void hard_reset_to_bootloader(void) void hard_reset_to_user_code(void) { printf("Reset CPU (into user code)\r\n"); - et_rts(0); // RTS (ttl level) connects to P0.14 + 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); From 3c481c754893df9532515906eae88a750a61b804 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 10 Apr 2013 16:21:17 +0200 Subject: [PATCH 094/188] * changed arm-prefix from arm-elf to arm-none-eabi --- msba2-common/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index 83337fd035..767e75716a 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -2,7 +2,7 @@ export CPU = lpc2387 # toolchain config -export PREFIX = @arm-elf- +export PREFIX = @arm-none-eabi- export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar export CFLAGS = -std=gnu99 -O2 -Wall -Wstrict-prototypes -mcpu=arm7tdmi-s -gdwarf-2 From b3b7ea928de752dcc294ba2b0ed72002717d1d01 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 10 Apr 2013 16:21:44 +0200 Subject: [PATCH 095/188] * added an install target --- msba2-common/tools/Makefile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/msba2-common/tools/Makefile b/msba2-common/tools/Makefile index 5d4d6b9222..8dbdcc242a 100644 --- a/msba2-common/tools/Makefile +++ b/msba2-common/tools/Makefile @@ -1,5 +1,6 @@ CFLAGS = -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" CC = gcc +prefix=/usr/local all: lpc2k_pgm pseudoterm @@ -31,15 +32,20 @@ cksum_test: cksum_test.c uuencode.o cksum_test.o $(CC) $(CFLAGS) -o $(TARGETDIR)/cksum_test obj/cksum_test.o obj/uuencode.o boot_2xxx.c boot_2xxx.h: boot_2xxx.armasm mkbootc - arm-elf-as -o boot_2xxx.armobj boot_2xxx.armasm - arm-elf-objdump -d boot_2xxx.armobj | ./mkbootc boot_2xxx + arm-none-eabi-as -o boot_2xxx.armobj boot_2xxx.armasm + arm-none-eabi-objdump -d boot_2xxx.armobj | ./mkbootc boot_2xxx boot_23xx.c boot_23xx.h: src/boot_23xx.armasm mkbootc - arm-elf-as -o obj/boot_23xx.armobj src/boot_23xx.armasm - arm-elf-objdump -d obj/boot_23xx.armobj | ./mkbootc boot_23xx + arm-none-eabi-as -o obj/boot_23xx.armobj src/boot_23xx.armasm + arm-none-eabi-objdump -d obj/boot_23xx.armobj | ./mkbootc boot_23xx clean: rm -f bin/lpc2k_pgm cksum_test obj/*.o core core.* obj/*.armobj bin/pseudoterm +install: + install -m 0755 bin/lpc2k_pgm $(prefix)/bin + +.PHONY: install + obj/gui.o: src/gui.c $(CC) $(CFLAGS) `gtk-config --cflags` -c src/gui.c -o obj/gui.o From af36e54b499599d42fe9d231f9d93865ed1532de Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Thu, 11 Apr 2013 13:23:40 +0200 Subject: [PATCH 096/188] * merged fix for lpc2k_pgm for MacOS from feuerware --- msba2-common/tools/src/serial.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/msba2-common/tools/src/serial.c b/msba2-common/tools/src/serial.c index cd51e1cc5c..203af564da 100644 --- a/msba2-common/tools/src/serial.c +++ b/msba2-common/tools/src/serial.c @@ -60,6 +60,7 @@ 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); @@ -69,6 +70,14 @@ int open_serial_port(const char *port_name) 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", @@ -272,9 +281,15 @@ int set_baud(const char *baud_name) if (baud == B0) return -2; r = tcgetattr(port_fd, &port_setting); if (r != 0) return -3; - //port_setting.c_iflag = IGNBRK | IGNPAR | IXANY | IXON; +#ifdef __APPLE__ + 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; +#endif + port_setting.c_oflag = 0; port_setting.c_lflag = 0; r = tcsetattr(port_fd, TCSAFLUSH, &port_setting); From 364dbaa40654aac7e23af130ad124d5b6cd520f4 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Thu, 11 Apr 2013 13:29:34 +0200 Subject: [PATCH 097/188] * made path to pyterm absolute in Makefile for MSB-A2 --- msba2-common/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index 767e75716a..7ba1eae0e0 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -12,7 +12,7 @@ export LINK = $(PREFIX)gcc export SIZE = $(PREFIX)size export OBJCOPY = $(PREFIX)objcopy FLASHER = lpc2k_pgm -TERM = pyterm.py +TERM = $(RIOTBASE)/dist/tools/pyterm/pyterm.py LINKFLAGS = -gdwarf-2 -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T$(RIOTBASE)/cpu/$(CPU)/linkerscript.x ifeq ($(strip $(PORT)),) From cbe8feb3ddd64b9d496ae05db4d43fca114ed8e4 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 15 Apr 2013 20:11:15 +0200 Subject: [PATCH 098/188] make native ltc4150 posix rt independent --- native/native-ltc4150.c | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c index 99b4d0a3e5..e84501ef2c 100644 --- a/native/native-ltc4150.c +++ b/native/native-ltc4150.c @@ -26,11 +26,25 @@ #include "cpu.h" #include "cpu-conf.h" +#include "hwtimer.h" #define native_ltc4150_startup_delay 10 -static timer_t native_ltc4150_timer; -static struct itimerspec native_ltc4150_timer_time; +static int _int_enabled; + +/** + * native ltc4150 hwtimer - interrupt handler proxy + */ +static void _int_handler() +{ + DEBUG("ltc4150 _int_handler()\n"); + ltc4150_interrupt(); + if (_int_enabled == 1) { + if (hwtimer_set(100000, _int_handler, NULL) == -1) { + errx(1, "_int_handler: hwtimer_set"); + }; + } +} /** * unregister signal handler @@ -38,7 +52,7 @@ static struct itimerspec native_ltc4150_timer_time; void ltc4150_disable_int(void) { DEBUG("ltc4150_disable_int()\n"); - unregister_interrupt(_SIG_LTC4150); + _int_enabled = 0; } /** @@ -47,7 +61,10 @@ void ltc4150_disable_int(void) void ltc4150_enable_int(void) { DEBUG("ltc4150_enable_int()\n"); - register_interrupt(_SIG_LTC4150, ltc4150_interrupt); + _int_enabled = 1; + if (hwtimer_set(100000, _int_handler, NULL) == -1) { + errx(1, "ltc4150_enable_int: hwtimer_set"); + }; } /** @@ -68,25 +85,6 @@ void ltc4150_arch_init(void) ltc4150_disable_int(); - /* create timer */ - sev.sigev_notify = SIGEV_SIGNAL; - sev.sigev_signo = _SIG_LTC4150; - sev.sigev_value.sival_ptr = &native_ltc4150_timer; - - if (timer_create(CLOCK_MONOTONIC, &sev, &native_ltc4150_timer) == -1) { - err(1, "ltc4150_arch_init(): timer_create"); - } - - /* set timer */ - native_ltc4150_timer_time.it_value.tv_sec = 0; - native_ltc4150_timer_time.it_value.tv_nsec = 100000000; - native_ltc4150_timer_time.it_interval.tv_sec = 0; - native_ltc4150_timer_time.it_interval.tv_nsec = 100000000; - - if (timer_settime(native_ltc4150_timer, 0, &native_ltc4150_timer_time, NULL) == -1) { - err(1, "ltc4150_arch_init: timer_settime"); - } - puts("Native LTC4150 initialized."); } /** @} */ From d4fc6e1b7629fe3d0c095959d5fb9441694ad83b Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 17 Apr 2013 18:03:32 +0200 Subject: [PATCH 099/188] * replaced string by variable for archive name --- msba2-common/drivers/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msba2-common/drivers/Makefile b/msba2-common/drivers/Makefile index 7eb5f229fe..c2ec597162 100644 --- a/msba2-common/drivers/Makefile +++ b/msba2-common/drivers/Makefile @@ -6,7 +6,7 @@ DEP = $(SRC:%.c=$(BINDIR)%.d) INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ $(BINDIR)msba2_common_drivers.a: $(OBJ) - $(AR) rcs $(BINDIR)msba2_base.a $(OBJ) + $(AR) rcs $(BINDIR)${ARCH} $(OBJ) # pull in dependency info for *existing* .o files -include $(OBJ:.o=.d) From 0fe0018da7643970af4bdf6a0335c40fb2deb4b3 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 18 Apr 2013 02:31:02 +0200 Subject: [PATCH 100/188] * added missing include paths to msb-430 Makefiles --- msb-430-common/Makefile | 2 +- msb-430h/Makefile | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/msb-430-common/Makefile b/msb-430-common/Makefile index 7f3a80971e..4ca6a9248b 100644 --- a/msb-430-common/Makefile +++ b/msb-430-common/Makefile @@ -3,7 +3,7 @@ BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines DEP = $(SRC:%.c=$(BINDIR)%.d) -INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ +INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ -I${RIOTBOARD}/${BOARD}/include/ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/mspx16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/include/ diff --git a/msb-430h/Makefile b/msb-430h/Makefile index 91c5da5880..2bd0f63c26 100644 --- a/msb-430h/Makefile +++ b/msb-430h/Makefile @@ -5,9 +5,9 @@ export ARCH = msb-430h_base.a DEP = $(SRC:%.c=$(BINDIR)%.d) -INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ -INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -INCLUDES += -I$(RIOTBASE)/cpu/msp430x16x/include/ +INCLUDES += -I${RIOTBASE}/core/include/ +INCLUDES += -Iinclude/ -I$(RIOTBOARD)/msb-430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/include all: $(BINDIR)$(ARCH) From d70982d5ba1c545239f7440d236fad9d6fe6cfb5 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Mon, 6 May 2013 17:04:51 +0200 Subject: [PATCH 101/188] implemented UART functions --- redbee-econotag/drivers/gpio.c | 74 +++++++++++ redbee-econotag/drivers/include/gpio.h | 157 +++++++++++++++++++++++ redbee-econotag/drivers/include/uart.h | 139 ++++++++++++++++++++ redbee-econotag/drivers/redbee_uart.c | 171 +++++++++++++++++++++++++ redbee-econotag/drivers/redbee_uart1.c | 157 +++++++++++++++++++---- redbee-econotag/drivers/redbee_uart2.c | 121 +++++++++++++++++ 6 files changed, 796 insertions(+), 23 deletions(-) create mode 100644 redbee-econotag/drivers/gpio.c create mode 100644 redbee-econotag/drivers/include/gpio.h create mode 100644 redbee-econotag/drivers/include/uart.h create mode 100644 redbee-econotag/drivers/redbee_uart.c create mode 100644 redbee-econotag/drivers/redbee_uart2.c diff --git a/redbee-econotag/drivers/gpio.c b/redbee-econotag/drivers/gpio.c new file mode 100644 index 0000000000..c9b867277a --- /dev/null +++ b/redbee-econotag/drivers/gpio.c @@ -0,0 +1,74 @@ +/* + * gpio.c - GPIO driver for redbee + * Copyright (C) 2013 Thomas Eichinger + * + * 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 0000000000..6a727b9da8 --- /dev/null +++ b/redbee-econotag/drivers/include/gpio.h @@ -0,0 +1,157 @@ +/* + * gpio.h - GPIO driver for redbee + * Copyright (C) 2013 Thomas Eichinger + * + * 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 + +/* 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 0000000000..44359b8f60 --- /dev/null +++ b/redbee-econotag/drivers/include/uart.h @@ -0,0 +1,139 @@ +/* + * uart.h - UART driver for redbee + * Copyright (C) 2013 Thomas Eichinger + * + * 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(char 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(char 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 0000000000..52d2cb5f42 --- /dev/null +++ b/redbee-econotag/drivers/redbee_uart.c @@ -0,0 +1,171 @@ +/* + * redbee_uart.c - UART driver for redbee + * Copyright (C) 2013 Thomas Eichinger + * + * 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) */ + +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; + } + } +} + +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); + } + 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); + } + + uart_set_baudrate( uart, baudrate ); +} + +int fw_puts(char *astring,int length) +{ + int i = 0; + for (; i + * 2013 Thomas Eichinger * * This source code is licensed under the GNU General Public License, * Version 3. See the file LICENSE for more details. @@ -9,35 +10,145 @@ */ #include "mc1322x.h" +#include "uart.h" -static volatile unsigned int running = 0; -static volatile unsigned int fifo = 0; +volatile uint8_t u1_tx_buf[UART1_TX_BUFFERSIZE]; +volatile uint32_t u1_tx_head, u1_tx_tail; -static inline int uart0_puts(char *astring, int length) -{ - int i; - for (i=0;iTXCON != 0); - UART1->DATA = astring[i]; +#if UART1_RX_BUFFERSIZE > 32 +volatile uint8_t u1_rx_buf[UART1_RX_BUFFERSIZE]; +volatile uint32_t u1_rx_head, u1_rx_tail; +#endif + +void uart1_isr ( void ) { +#if UART1_RX_BUFFERSIZE > 32 + /* receive interrupt */ + if ( UART1->USTATbits.RXRDY == 1) { + /* copy fifo into SW buffer */ + while (UART1->RXCON != 0) { + uint32_t u1_rx_tail_next; + u1_rx_tail_next = u1_rx_tail + 1; + if ( u1_rx_tail_next >= sizeof(u1_rx_buf) ) { + u1_rx_tail_next = 0; + } + if ( u1_rx_head != u1_rx_tail_next ) { + u1_rx_buf[u1_rx_tail] = UART1->DATA; + u1_rx_tail = u1_rx_tail_next; + } + /* buffer full, flush fifo */ + else { + while ( UART1->RXCON != 0 ) { + UART1->DATA; + } + } + } + return; + } +#endif + while ( UART1->TXCON != 0 ) { + if ( u1_tx_head == u1_tx_tail ) { +#if UART1_RX_BUFFERSIZE > 32 + UART1->CONbits.MTXR = 1; +#else + disable_irq(UART1); +#endif + return; + } + + UART1->DATA = u1_tx_buf[u1_tx_tail++]; + if ( u1_tx_tail >= sizeof(u1_tx_buf) ) { + u1_tx_tail = 0; + } } - return length; } -int fw_puts(char *astring, int length) -{ - return uart0_puts(astring, length); -} - -void stdio_flush(void) -{ - /* disable TX interrupt */ +void uart1_putc ( uint8_t c ) { + /* disable UART1_IRQ since it modifies u1_tx_(head|tail) */ +#if UART1_RX_BUFFERSIZE > 32 UART1->CONbits.MTXR = 1; - while(running) { - while(UART1->TXCON != 0); - fifo=0; - push_queue(); // dequeue to fifo +#else + disable_irq(UART1); +#endif + if ( (u1_tx_head == u1_tx_tail) && (UART1->TXCON != 0) ) { + UART1->DATA = c; } - /* enable TX interrupt */ + else { + u1_tx_buf[u1_tx_head++] = c; + if ( u1_tx_head >= sizeof(u1_tx_buf) ) { + u1_tx_head = 0; + } + if ( u1_tx_head == u1_tx_tail ) { + uint32_t u1_tx_tail_save = u1_tx_tail; + /* back up head to show buffer not empty and enable tx interrupt */ + u1_tx_head--; +#if UART1_RX_BUFFERSIZE > 32 + UART1->CONbits.MTXR = 0; +#else + enable_irq(UART1); +#endif + /* tail will change after one char goes out */ + while ( u1_tx_tail_save == u1_tx_tail ) { + /* wait */ + } + /* restor head */ + u1_tx_head++; + return; + } + } +#if UART1_RX_BUFFERSIZE > 32 UART1->CONbits.MTXR = 0; +#else + enable_irq(UART1); +#endif } + +uint8_t uart1_getc ( void ) { +#if UART1_RX_BUFFERSIZE > 32 + /* pull from ram buffer */ + uint8_t c = 0; + if ( u1_rx_head != u1_rx_tail ) { + c = u1_rx_buf[u1_rx_head++]; + if ( u1_rx_head >= sizeof(u1_rx_buf) ) { + u1_rx_head = 0; + } + return c; + } +#endif + /* pull from hw fifo */ + while ( uart1_can_get() == 0 ) { + /* wait */ + } + return UART1->DATA; +} + +// static volatile unsigned int running = 0; +// static volatile unsigned int fifo = 0; +// +// static inline int uart0_puts(char *astring, int length) +// { +// int i; +// for (i=0;iTXCON != 0); +// UART1->DATA = astring[i]; +// } +// return length; +// } +// +// int fw_puts(char *astring, int length) +// { +// return uart0_puts(astring, length); +// } +// +// void stdio_flush(void) +// { +// /* disable TX interrupt */ +// UART1->CONbits.MTXR = 1; +// while(running) { +// while(UART1->TXCON != 0); +// fifo=0; +// push_queue(); // dequeue to fifo +// } +// /* enable TX interrupt */ +// UART1->CONbits.MTXR = 0; +// } diff --git a/redbee-econotag/drivers/redbee_uart2.c b/redbee-econotag/drivers/redbee_uart2.c new file mode 100644 index 0000000000..14af686c6c --- /dev/null +++ b/redbee-econotag/drivers/redbee_uart2.c @@ -0,0 +1,121 @@ +/* + * redbee_uart2.c - UART2 driver for redbee + * Copyright (C) 2013 Thomas Eichinger + * + * 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" + +volatile uint8_t u2_tx_buf[UART2_TX_BUFFERSIZE]; +volatile uint32_t u2_tx_head, u2_tx_tail; + +#if UART2_RX_BUFFERSIZE > 32 +volatile uint8_t u2_rx_buf[UART2_RX_BUFFERSIZE]; +volatile uint32_t u2_rx_head, u2_rx_tail; +#endif + +void uart2_isr ( void ) { +#if UART2_RX_BUFFERSIZE > 32 + /* receive interrupt */ + if ( UART2->USTATbits.RXRDY == 1) { + /* copy fifo into SW buffer */ + while (UART2->RXCON != 0) { + uint32_t u2_rx_tail_next; + u2_rx_tail_next = u2_rx_tail + 1; + if ( u2_rx_tail_next >= sizeof(u2_rx_buf) ) { + u2_rx_tail_next = 0; + } + if ( u2_rx_head != u2_rx_tail_next ) { + u2_rx_buf[u2_rx_tail] = UART2->DATA; + u2_rx_tail = u2_rx_tail_next; + } + /* buffer full, flush fifo */ + else { + while ( UART2->RXCON != 0 ) { + UART2->DATA; + } + } + } + return; + } +#endif + while ( UART2->TXCON != 0 ) { + if ( u2_tx_head == u2_tx_tail ) { +#if UART2_RX_BUFFERSIZE > 32 + UART2->CONbits.MTXR = 1; +#else + disable_irq(UART2); +#endif + return; + } + + UART2->DATA = u2_tx_buf[u2_tx_tail++]; + if ( u2_tx_tail >= sizeof(u2_tx_buf) ) { + u2_tx_tail = 0; + } + } +} + +void uart2_putc ( uint8_t c ) { + /* disable UART2_IRQ since it modifies u2_tx_(head|tail) */ +#if UART2_RX_BUFFERSIZE > 32 + UART2->CONbits.MTXR = 1; +#else + disable_irq(UART2); +#endif + if ( (u2_tx_head == u2_tx_tail) && (UART2->TXCON != 0) ) { + UART2->DATA = c; + } + else { + u2_tx_buf[u2_tx_head++] = c; + if ( u2_tx_head >= sizeof(u2_tx_buf) ) { + u2_tx_head = 0; + } + if ( u2_tx_head == u2_tx_tail ) { + uint32_t u2_tx_tail_save = u2_tx_tail; + /* back up head to show buffer not empty and enable tx interrupt */ + u2_tx_head--; +#if UART2_RX_BUFFERSIZE > 32 + UART2->CONbits.MTXR = 0; +#else + enable_irq(UART2); +#endif + /* tail will change after one char goes out */ + while ( u2_tx_tail_save == u2_tx_tail ) { + /* wait */ + } + /* restor head */ + u2_tx_head++; + return; + } + } +#if UART2_RX_BUFFERSIZE > 32 + UART2->CONbits.MTXR = 0; +#else + enable_irq(UART2); +#endif +} + +uint8_t uart2_getc ( void ) { +#if UART2_RX_BUFFERSIZE > 32 + /* pull from ram buffer */ + uint8_t c = 0; + if ( u2_rx_head != u2_rx_tail ) { + c = u2_rx_buf[u2_rx_head++]; + if ( u2_rx_head >= sizeof(u2_rx_buf) ) { + u2_rx_head = 0; + } + return c; + } +#endif + /* pull from hw fifo */ + while ( uart2_can_get() == 0 ) { + /* wait */ + } + return UART2->DATA; +} \ No newline at end of file From 15ec5c2f17dcd0d6a96f6b4e9e8b59a48eb1dd35 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Wed, 8 May 2013 11:40:17 +0200 Subject: [PATCH 102/188] new implementation of UART functions, respecting RIOT more now --- redbee-econotag/drivers/redbee_uart.c | 4 + redbee-econotag/drivers/redbee_uart1.c | 145 ++++--------------------- redbee-econotag/drivers/redbee_uart2.c | 113 ++++--------------- 3 files changed, 44 insertions(+), 218 deletions(-) diff --git a/redbee-econotag/drivers/redbee_uart.c b/redbee-econotag/drivers/redbee_uart.c index 52d2cb5f42..1015bb7759 100644 --- a/redbee-econotag/drivers/redbee_uart.c +++ b/redbee-econotag/drivers/redbee_uart.c @@ -162,6 +162,10 @@ void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { int fw_puts(char *astring,int length) { + return uart0_puts ( astring, length ); +} + +static inline uint32_t uart0_puts ( uint8_t *astring, uint32_t length ) { int i = 0; for (; i * 2013 Thomas Eichinger * @@ -10,145 +10,40 @@ */ #include "mc1322x.h" +#include "board_uart0.h" #include "uart.h" -volatile uint8_t u1_tx_buf[UART1_TX_BUFFERSIZE]; -volatile uint32_t u1_tx_head, u1_tx_tail; - -#if UART1_RX_BUFFERSIZE > 32 -volatile uint8_t u1_rx_buf[UART1_RX_BUFFERSIZE]; -volatile uint32_t u1_rx_head, u1_rx_tail; -#endif - void uart1_isr ( void ) { -#if UART1_RX_BUFFERSIZE > 32 - /* receive interrupt */ - if ( UART1->USTATbits.RXRDY == 1) { - /* copy fifo into SW buffer */ - while (UART1->RXCON != 0) { - uint32_t u1_rx_tail_next; - u1_rx_tail_next = u1_rx_tail + 1; - if ( u1_rx_tail_next >= sizeof(u1_rx_buf) ) { - u1_rx_tail_next = 0; - } - if ( u1_rx_head != u1_rx_tail_next ) { - u1_rx_buf[u1_rx_tail] = UART1->DATA; - u1_rx_tail = u1_rx_tail_next; - } - /* buffer full, flush fifo */ - else { - while ( UART1->RXCON != 0 ) { - UART1->DATA; + int i = 0; + 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(); } - return; - } #endif - while ( UART1->TXCON != 0 ) { - if ( u1_tx_head == u1_tx_tail ) { -#if UART1_RX_BUFFERSIZE > 32 - UART1->CONbits.MTXR = 1; -#else - disable_irq(UART1); -#endif - return; - } - - UART1->DATA = u1_tx_buf[u1_tx_tail++]; - if ( u1_tx_tail >= sizeof(u1_tx_buf) ) { - u1_tx_tail = 0; - } } } void uart1_putc ( uint8_t c ) { - /* disable UART1_IRQ since it modifies u1_tx_(head|tail) */ -#if UART1_RX_BUFFERSIZE > 32 - UART1->CONbits.MTXR = 1; -#else - disable_irq(UART1); -#endif - if ( (u1_tx_head == u1_tx_tail) && (UART1->TXCON != 0) ) { - UART1->DATA = c; + /* while uart fifo is full */ + while ( UART1->TXCON == 0 ) { + /* wait */ } - else { - u1_tx_buf[u1_tx_head++] = c; - if ( u1_tx_head >= sizeof(u1_tx_buf) ) { - u1_tx_head = 0; - } - if ( u1_tx_head == u1_tx_tail ) { - uint32_t u1_tx_tail_save = u1_tx_tail; - /* back up head to show buffer not empty and enable tx interrupt */ - u1_tx_head--; -#if UART1_RX_BUFFERSIZE > 32 - UART1->CONbits.MTXR = 0; -#else - enable_irq(UART1); -#endif - /* tail will change after one char goes out */ - while ( u1_tx_tail_save == u1_tx_tail ) { - /* wait */ - } - /* restor head */ - u1_tx_head++; - return; - } - } -#if UART1_RX_BUFFERSIZE > 32 - UART1->CONbits.MTXR = 0; -#else - enable_irq(UART1); -#endif + UART1->DATA = c; } uint8_t uart1_getc ( void ) { -#if UART1_RX_BUFFERSIZE > 32 - /* pull from ram buffer */ - uint8_t c = 0; - if ( u1_rx_head != u1_rx_tail ) { - c = u1_rx_buf[u1_rx_head++]; - if ( u1_rx_head >= sizeof(u1_rx_buf) ) { - u1_rx_head = 0; - } - return c; - } -#endif - /* pull from hw fifo */ - while ( uart1_can_get() == 0 ) { + /* while uart fifo is empty */ + while ( UART1->RXCON == 0 ) { /* wait */ } + return UART1->DATA; -} - -// static volatile unsigned int running = 0; -// static volatile unsigned int fifo = 0; -// -// static inline int uart0_puts(char *astring, int length) -// { -// int i; -// for (i=0;iTXCON != 0); -// UART1->DATA = astring[i]; -// } -// return length; -// } -// -// int fw_puts(char *astring, int length) -// { -// return uart0_puts(astring, length); -// } -// -// void stdio_flush(void) -// { -// /* disable TX interrupt */ -// UART1->CONbits.MTXR = 1; -// while(running) { -// while(UART1->TXCON != 0); -// fifo=0; -// push_queue(); // dequeue to fifo -// } -// /* enable TX interrupt */ -// UART1->CONbits.MTXR = 0; -// } +} \ No newline at end of file diff --git a/redbee-econotag/drivers/redbee_uart2.c b/redbee-econotag/drivers/redbee_uart2.c index 14af686c6c..a1b2e6bab9 100644 --- a/redbee-econotag/drivers/redbee_uart2.c +++ b/redbee-econotag/drivers/redbee_uart2.c @@ -1,6 +1,7 @@ /* - * redbee_uart2.c - UART2 driver for redbee - * Copyright (C) 2013 Thomas Eichinger + * uart1.c - UART1 driver for redbee + * Copyright (C) 2013 Oliver Hahm + * 2013 Thomas Eichinger * * This source code is licensed under the GNU General Public License, * Version 3. See the file LICENSE for more details. @@ -9,112 +10,38 @@ */ #include "mc1322x.h" +#include "board_uart0.h" #include "uart.h" -volatile uint8_t u2_tx_buf[UART2_TX_BUFFERSIZE]; -volatile uint32_t u2_tx_head, u2_tx_tail; - -#if UART2_RX_BUFFERSIZE > 32 -volatile uint8_t u2_rx_buf[UART2_RX_BUFFERSIZE]; -volatile uint32_t u2_rx_head, u2_rx_tail; -#endif - void uart2_isr ( void ) { -#if UART2_RX_BUFFERSIZE > 32 - /* receive interrupt */ - if ( UART2->USTATbits.RXRDY == 1) { - /* copy fifo into SW buffer */ - while (UART2->RXCON != 0) { - uint32_t u2_rx_tail_next; - u2_rx_tail_next = u2_rx_tail + 1; - if ( u2_rx_tail_next >= sizeof(u2_rx_buf) ) { - u2_rx_tail_next = 0; - } - if ( u2_rx_head != u2_rx_tail_next ) { - u2_rx_buf[u2_rx_tail] = UART2->DATA; - u2_rx_tail = u2_rx_tail_next; - } - /* buffer full, flush fifo */ - else { - while ( UART2->RXCON != 0 ) { - UART2->DATA; + 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(); } - return; - } #endif - while ( UART2->TXCON != 0 ) { - if ( u2_tx_head == u2_tx_tail ) { -#if UART2_RX_BUFFERSIZE > 32 - UART2->CONbits.MTXR = 1; -#else - disable_irq(UART2); -#endif - return; - } - - UART2->DATA = u2_tx_buf[u2_tx_tail++]; - if ( u2_tx_tail >= sizeof(u2_tx_buf) ) { - u2_tx_tail = 0; - } } } void uart2_putc ( uint8_t c ) { - /* disable UART2_IRQ since it modifies u2_tx_(head|tail) */ -#if UART2_RX_BUFFERSIZE > 32 - UART2->CONbits.MTXR = 1; -#else - disable_irq(UART2); -#endif - if ( (u2_tx_head == u2_tx_tail) && (UART2->TXCON != 0) ) { - UART2->DATA = c; + /* while uart fifo is full */ + while ( UART2->TXCON == 0 ) { + /* wait */ } - else { - u2_tx_buf[u2_tx_head++] = c; - if ( u2_tx_head >= sizeof(u2_tx_buf) ) { - u2_tx_head = 0; - } - if ( u2_tx_head == u2_tx_tail ) { - uint32_t u2_tx_tail_save = u2_tx_tail; - /* back up head to show buffer not empty and enable tx interrupt */ - u2_tx_head--; -#if UART2_RX_BUFFERSIZE > 32 - UART2->CONbits.MTXR = 0; -#else - enable_irq(UART2); -#endif - /* tail will change after one char goes out */ - while ( u2_tx_tail_save == u2_tx_tail ) { - /* wait */ - } - /* restor head */ - u2_tx_head++; - return; - } - } -#if UART2_RX_BUFFERSIZE > 32 - UART2->CONbits.MTXR = 0; -#else - enable_irq(UART2); -#endif + UART2->DATA = c; } uint8_t uart2_getc ( void ) { -#if UART2_RX_BUFFERSIZE > 32 - /* pull from ram buffer */ - uint8_t c = 0; - if ( u2_rx_head != u2_rx_tail ) { - c = u2_rx_buf[u2_rx_head++]; - if ( u2_rx_head >= sizeof(u2_rx_buf) ) { - u2_rx_head = 0; - } - return c; - } -#endif - /* pull from hw fifo */ - while ( uart2_can_get() == 0 ) { + /* while uart fifo is empty */ + while ( UART2->RXCON == 0 ) { /* wait */ } return UART2->DATA; From 0e424b9007da014b5560387d5e4a28c4d9ad5d44 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 14 May 2013 15:06:51 +0200 Subject: [PATCH 103/188] * changes to be compliant to RIOT UART infrastructure * added flashing tool * made bugfixes to compile --- redbee-econotag/Makefile | 6 + redbee-econotag/board_init.c | 8 + redbee-econotag/drivers/include/gpio.h | 4 +- redbee-econotag/drivers/include/uart.h | 4 +- redbee-econotag/drivers/redbee_uart.c | 61 +++-- redbee-econotag/drivers/redbee_uart1.c | 1 - redbee-econotag/tools/mc1322x-load.c | 325 +++++++++++++++++++++++++ redbee-econotag/tools/mc1322x-load.pl | 171 +++++++++++++ 8 files changed, 560 insertions(+), 20 deletions(-) create mode 100644 redbee-econotag/tools/mc1322x-load.c create mode 100755 redbee-econotag/tools/mc1322x-load.pl diff --git a/redbee-econotag/Makefile b/redbee-econotag/Makefile index 391c9bd42f..ae4ccfd0a7 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/board_init.c b/redbee-econotag/board_init.c index 5a0b03177c..7c157b1038 100644 --- a/redbee-econotag/board_init.c +++ b/redbee-econotag/board_init.c @@ -9,3 +9,11 @@ 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/include/gpio.h b/redbee-econotag/drivers/include/gpio.h index 6a727b9da8..b46051a1a7 100644 --- a/redbee-econotag/drivers/include/gpio.h +++ b/redbee-econotag/drivers/include/gpio.h @@ -11,6 +11,9 @@ #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: @@ -94,7 +97,6 @@ #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) \ diff --git a/redbee-econotag/drivers/include/uart.h b/redbee-econotag/drivers/include/uart.h index 44359b8f60..928a2157a9 100644 --- a/redbee-econotag/drivers/include/uart.h +++ b/redbee-econotag/drivers/include/uart.h @@ -104,7 +104,7 @@ void uart_flow_ctl(volatile struct UART_struct * uart, uint8_t on); */ #define UART1_TX_BUFFERSIZE 1024 extern volatile uint32_t u1_tx_head, u1_tx_tail; -void uart1_putc(char c); +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. @@ -125,7 +125,7 @@ uint8_t uart1_getc(void); #define UART2_TX_BUFFERSIZE 1024 extern volatile uint32_t u2_tx_head, u2_tx_tail; -void uart2_putc(char c); +void uart2_putc(uint8_t c); #define UART2_RX_BUFFERSIZE 128 #if UART2_RX_BUFFERSIZE > 32 diff --git a/redbee-econotag/drivers/redbee_uart.c b/redbee-econotag/drivers/redbee_uart.c index 1015bb7759..621d94e060 100644 --- a/redbee-econotag/drivers/redbee_uart.c +++ b/redbee-econotag/drivers/redbee_uart.c @@ -16,6 +16,8 @@ #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; @@ -86,6 +88,7 @@ void uart_flow_ctl ( volatile struct UART_struct* uart, uint8_t on ) { } } +// 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 */ @@ -108,8 +111,8 @@ void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { 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; + //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 */ @@ -120,10 +123,11 @@ void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { UART1->CONbits.MRXR = 1; /*< disable rx interrupt */ #endif - u1_tx_head = 0; - u1_tx_tail = 0; + //u1_tx_head = 0; + //u1_tx_tail = 0; - enable_irq(UART1); + //enable_irq(UART1); + ITC->INTENABLEbits.UART1 = 1; } else { /* UART2 */ @@ -139,8 +143,8 @@ void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { 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; + //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 */ @@ -151,25 +155,50 @@ void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { UART2->CONbits.MRXR = 1; /*< disable rx interrupt */ #endif - u2_tx_head = 0; - u2_tx_tail = 0; + // u2_tx_head = 0; + //u2_tx_tail = 0; - enable_irq(UART2); + //enable_irq(UART2); + ITC->INTENABLEbits.UART2 = 1; } uart_set_baudrate( uart, baudrate ); } -int fw_puts(char *astring,int length) -{ - return uart0_puts ( astring, length ); -} - static inline uint32_t uart0_puts ( uint8_t *astring, uint32_t length ) { - int i = 0; + uint32_t i = 0; for (; iINTENABLEbits.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 ffe386791e..a4a53afc40 100644 --- a/redbee-econotag/drivers/redbee_uart1.c +++ b/redbee-econotag/drivers/redbee_uart1.c @@ -14,7 +14,6 @@ #include "uart.h" void uart1_isr ( void ) { - int i = 0; if ( UART1->USTATbits.RXRDY == 1 ) { #ifdef MODULE_UART0 if ( uart0_handler_pid ) { diff --git a/redbee-econotag/tools/mc1322x-load.c b/redbee-econotag/tools/mc1322x-load.c new file mode 100644 index 0000000000..d63df23802 --- /dev/null +++ b/redbee-econotag/tools/mc1322x-load.c @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2012, Maxim Osipov + * Copyright (c) 2010, Mariano Alvira 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 +#include +#include +#include +#include +#include +#include +#include +#include + + +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 0000000000..bfc1d1ffcd --- /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; + From a860087f502958589a8fec8f12d9f6fca80ef1fd Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Tue, 14 May 2013 17:42:08 +0200 Subject: [PATCH 104/188] native board uart0 import --- native/board_init.c | 3 +++ native/include/board.h | 5 +++++ native/native-uart0.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 native/native-uart0.c diff --git a/native/board_init.c b/native/board_init.c index d6f4c4ba31..52e63878fc 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -21,6 +21,9 @@ */ void board_init() { +#ifdef MODULE_UART0 + _native_init_uart0(); +#endif LED_GREEN_OFF(); LED_RED_ON(); puts("RIOT native board initialized."); diff --git a/native/include/board.h b/native/include/board.h index 457289a566..69e40eb383 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -22,3 +22,8 @@ void LED_RED_OFF(void); void LED_RED_ON(void); void LED_RED_TOGGLE(void); +#ifdef MODULE_UART0 +#include +extern fd_set _native_uart_rfds; +extern void _native_handle_uart0_input(void); +#endif diff --git a/native/native-uart0.c b/native/native-uart0.c new file mode 100644 index 0000000000..c73b5ee6ea --- /dev/null +++ b/native/native-uart0.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include "cpu.h" +#include "debug.h" +#include "board_uart0.h" + +fd_set _native_uart_rfds; + +static inline int uart0_puts(char *astring, int length) +{ + return puts(astring); +} + +void _native_handle_uart0_input() +{ + char buf[42]; + int nread; + + _native_in_syscall = 0; + _native_in_isr = 1; + + nread = read(0, buf, sizeof(buf)); + if (nread == -1) { + err(1, "_native_handle_uart0_input(): read()"); + } + for(int pos = 0; pos < nread; pos++) { + uart0_handle_incoming(buf[pos]); + } + uart0_notify_thread(); + + _native_in_isr = 0; + cpu_switch_context_exit(); +} + +void _native_init_uart0() +{ + /* Watch stdin (fd 0) to see when it has input. */ + FD_ZERO(&_native_uart_rfds); + FD_SET(0, &_native_uart_rfds); + puts("RIOT native uart0 initialized."); +} From 63971962d1ecae0d00f4b33428935975638050ea Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 15 May 2013 10:44:57 +0200 Subject: [PATCH 105/188] lose superflouse -lrt CFLAG --- native/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/Makefile.include b/native/Makefile.include index e7bf1c65bd..d360b2248f 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -14,7 +14,7 @@ export OBJCOPY = $(PREFIX)objcopy FLASHER = lpc2k_pgm TERM = pyterm.py -LINKFLAGS = -lrt -m32 +LINKFLAGS = -m32 ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 From c660c56bbdda016a74bb66b35228b1501c0e6a60 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 15 May 2013 16:04:48 +0200 Subject: [PATCH 106/188] native board putchar implementation --- native/native-uart0.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/native/native-uart0.c b/native/native-uart0.c index c73b5ee6ea..e13447bb0e 100644 --- a/native/native-uart0.c +++ b/native/native-uart0.c @@ -1,3 +1,8 @@ +/* + * TODO: + * make stdin/stdout customizable. + */ + #include #include #include @@ -42,3 +47,8 @@ void _native_init_uart0() FD_SET(0, &_native_uart_rfds); puts("RIOT native uart0 initialized."); } + +int putchar(int c) { + write(1, &c, 1); + return 0; +} From feb6e807934a6f4e81e84c207fff0621cf6118b4 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Wed, 22 May 2013 13:21:02 +0200 Subject: [PATCH 107/188] added README with flashing instructions and the bbmc tool for reset/erase the econotag --- redbee-econotag/README | 11 + redbee-econotag/tools/ftditools/Makefile | 17 + redbee-econotag/tools/ftditools/bbmc.c | 531 +++++++++++++++++++++++ 3 files changed, 559 insertions(+) create mode 100644 redbee-econotag/README create mode 100644 redbee-econotag/tools/ftditools/Makefile create mode 100644 redbee-econotag/tools/ftditools/bbmc.c diff --git a/redbee-econotag/README b/redbee-econotag/README new file mode 100644 index 0000000000..7cce0fdd05 --- /dev/null +++ b/redbee-econotag/README @@ -0,0 +1,11 @@ +Flashing: +tools/mc1322x-load.pl -f -t /dev/ + +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/tools/ftditools/Makefile b/redbee-econotag/tools/ftditools/Makefile new file mode 100644 index 0000000000..521d7d14ff --- /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 0000000000..7e2b654412 --- /dev/null +++ b/redbee-econotag/tools/ftditools/bbmc.c @@ -0,0 +1,531 @@ +/* + * Copyright (c) 2010, Mariano Alvira 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 +#include +#include +#include +#include + +#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; + +} From 1cea4fa074458c9fe99266e973c62d6b9e23df1d Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Sun, 2 Jun 2013 12:41:27 +0200 Subject: [PATCH 108/188] minor: fix warning from mkdir --- native/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/Makefile b/native/Makefile index da7907f159..86ddb4a6ff 100644 --- a/native/Makefile +++ b/native/Makefile @@ -16,7 +16,7 @@ $(BINDIR)native_base.a: $(OBJ) # compile and generate dependency info $(BINDIR)%.o: %.c - -mkdir $(BINDIR) + -mkdir -p $(BINDIR) $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d @@ -24,5 +24,5 @@ $(BINDIR)%.o: %.c # remove compilation products clean: rm -f $(BINDIR)native_base.a $(OBJ) $(DEP) - -rmdir $(BINDIR) + -rmdir -p $(BINDIR) From a6b41814b9d17d9d517b16a9314a43a20a224835 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Sun, 2 Jun 2013 12:42:10 +0200 Subject: [PATCH 109/188] add missing include --- native/board_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/board_init.c b/native/board_init.c index 52e63878fc..d32c653dc9 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -12,7 +12,7 @@ * @author Ludwig Ortmann * @} */ - +#include #include "board.h" /** From b159234fee9f01cd6fc0994aa8da032aef51cc6f Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Sun, 2 Jun 2013 12:42:49 +0200 Subject: [PATCH 110/188] remove unused struct --- native/native-ltc4150.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c index e84501ef2c..2f2d414cf8 100644 --- a/native/native-ltc4150.c +++ b/native/native-ltc4150.c @@ -81,8 +81,6 @@ void ltc4150_sync_blocking(void) */ void ltc4150_arch_init(void) { - struct sigevent sev; - ltc4150_disable_int(); puts("Native LTC4150 initialized."); From 70a9c5f2d133bc2cc353a8a3a1fe001a7e89d852 Mon Sep 17 00:00:00 2001 From: Milan Babel Date: Sat, 25 May 2013 12:34:18 +0200 Subject: [PATCH 111/188] added support for board wsn430-v1_3b --- Makefile.base | 4 + wsn430-common/Makefile | 33 +++++ wsn430-common/Makefile.include | 23 ++++ wsn430-common/board_config.c | 19 +++ wsn430-common/board_init.c | 150 +++++++++++++++++++++ wsn430-common/drivers/Makefile | 0 wsn430-common/include/board-conf.h | 6 + wsn430-common/uart0.c | 63 +++++++++ wsn430-v1_3b/Makefile | 36 +++++ wsn430-v1_3b/Makefile.dep | 7 + wsn430-v1_3b/Makefile.include | 3 + wsn430-v1_3b/driver_cc110x.c | 206 +++++++++++++++++++++++++++++ wsn430-v1_3b/include/board.h | 31 +++++ 13 files changed, 581 insertions(+) create mode 100644 wsn430-common/Makefile create mode 100644 wsn430-common/Makefile.include create mode 100644 wsn430-common/board_config.c create mode 100644 wsn430-common/board_init.c create mode 100644 wsn430-common/drivers/Makefile create mode 100644 wsn430-common/include/board-conf.h create mode 100644 wsn430-common/uart0.c create mode 100644 wsn430-v1_3b/Makefile create mode 100644 wsn430-v1_3b/Makefile.dep create mode 100644 wsn430-v1_3b/Makefile.include create mode 100644 wsn430-v1_3b/driver_cc110x.c create mode 100644 wsn430-v1_3b/include/board.h diff --git a/Makefile.base b/Makefile.base index a9a5375397..641eaf56cd 100644 --- a/Makefile.base +++ b/Makefile.base @@ -13,6 +13,10 @@ ifeq ($(BOARD),msb-430h) INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ INCLUDES += -I$(RIOTBOARD)/msb-430-common/drivers/include/ endif +ifeq ($(BOARD),wsn430-v1_3b) + INCLUDES += -I$(RIOTBOARD)/wsn430-v1_3b/include/ + INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ +endif ifeq ($(BOARD),chronos) INCLUDES += -I$(RIOTBOARD)/chronos/include/ INCLUDES += -I$(RIOTBOARD)/chronos/drivers/include/ diff --git a/wsn430-common/Makefile b/wsn430-common/Makefile new file mode 100644 index 0000000000..8f8f23add9 --- /dev/null +++ b/wsn430-common/Makefile @@ -0,0 +1,33 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ -I${RIOTBOARD}/${BOARD}/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/mspx16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/include/ + +.PHONY: $(BINDIR)$(ARCH) + +all: $(BINDIR)$(ARCH) + #$(MAKE) -C drivers + +$(BINDIR)$(ARCH): $(OBJ) + echo $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + #$(MAKE) -C drivers clean + rm -f $(OBJ) $(DEP) + rm -f $(BINDIR)$(ARCH) diff --git a/wsn430-common/Makefile.include b/wsn430-common/Makefile.include new file mode 100644 index 0000000000..63cee9a3af --- /dev/null +++ b/wsn430-common/Makefile.include @@ -0,0 +1,23 @@ +## the cpu to build for +export CPU = msp430x16x +export MCU = msp430f1611 + +# toolchain config +export PREFIX = @msp430- +export CC = @$(PREFIX)gcc +export AR = @$(PREFIX)ar +export CFLAGS += -std=gnu99 -Wstrict-prototypes -gdwarf-2 -Os -Wall -mmcu=$(MCU) +export ASFLAGS += -mmcu=$(MCU) --defsym $(MCU)=1 --gdwarf-2 +export AS = $(PREFIX)as +export LINK = $(PREFIX)gcc +export SIZE = $(PREFIX)size +export OBJCOPY = $(PREFIX)objcopy +export LINKFLAGS = -mmcu=$(MCU) -lgcc $(RIOTBASE)/bin/startup.o +export FLASHER = mspdebug +ifeq ($(strip $(PORT)),) + export PORT = /dev/ttyUSB0 +endif +export HEXFILE = bin/$(PROJECT).hex +export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" + +export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ \ No newline at end of file diff --git a/wsn430-common/board_config.c b/wsn430-common/board_config.c new file mode 100644 index 0000000000..f22e513b20 --- /dev/null +++ b/wsn430-common/board_config.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include + +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) { + configmem_t mem = { CONFIG_KEY, sysconfig }; + return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem))); +} diff --git a/wsn430-common/board_init.c b/wsn430-common/board_init.c new file mode 100644 index 0000000000..b7b523cf76 --- /dev/null +++ b/wsn430-common/board_init.c @@ -0,0 +1,150 @@ + /* + * board_init.c - Implementation of functions to init board. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +#include "cpu.h" +#include "board.h" +#include "kernel_intern.h" +#include "msp430.h" +#include "debug.h" + +volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; + +typedef enum { + MCLK_2MHZ_SCLK_1MHZ = 1000002uL, + MCLK_4MHZ_SCLK_1MHZ = 1000004uL, + MCLK_8MHZ_SCLK_1MHZ = 1000008uL, + MCLK_8MHZ_SCLK_8MHZ = 8000000uL +}speed_t; + +/*---------------------------------------------------------------------------*/ +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: GDO, Flash, BSL TX + P1SEL = 0x02; // Port1 Select: 00000010 = 0x02 + P1OUT = 0x00; // Port1 Output: 00000000 = 0x00 + P1DIR = 0xE7; // Port1 Direction: 11100111 = 0xE7 + + // Port 2: GPIO, BSL RX, 1wire + P2SEL = 0x04; // Port2 Select: 00000100 = 0x04 + P2OUT = 0x00; // Port2 Output: 00000000 = 0x00 + P2DIR = 0xFF; // Port2 Direction: 11111111 = 0xFF + + + // Port 3: UART + P3SEL = 0xFE; // Port3 Select: 11111110 = 0xFE + P3OUT = 0x00; // Port3 Output: 00000000 = 0x00 + P3DIR = 0xFF; // Port3 Direction: 11111111 = 0xFF + + + // Port 4: CS + P4SEL = 0x00; // Port4 Select: 00000000 = 0x00 + P4OUT = 0x14; // Port4 Output: 00010100 = 0x14 + P4DIR = 0xFF; // Port4 Direction: 11111111 = 0xFF + + // Port 5: SPI, LED + P5SEL = 0x0E; // Port5 Select: 00001110 = 0x0E + P5OUT = 0x70; // Port5 Output: 01110000 = 0x70 + P5DIR = 0x70; // Port5 Direction: 01110000 = 0x70 + + + P6SEL = 0xFF; // Port6 Select: 11111111 = 0xFF + P6OUT = 0x00; // Port6 Output: 00000000 = 0x00 + P6DIR = 0xFF; // Port6 Direction: 11111000 = 0xF8 + +} + +void msp430_set_cpu_speed(uint32_t speed) +{ + + dint(); + __msp430_cpu_speed = speed; + msp430_init_dco(); + uint16_t br; + + U0CTL = SWRST; + U0CTL = SWRST | CHAR; // 8-bit character + U0TCTL = SSEL1 | TXEPT; // UCLK = SCLK + U0RCTL = 0; + // activate + ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD + br = (uint16_t)((__msp430_cpu_speed & 0xFFFFF0) / 115200uL); + UBR00 = br; // set baudrate + UBR10 = br>>8; + UMCTL0 = calc_umctl(br); // set modulation + + U0CTL &= ~SWRST; + + //URCTL0 |= URXEIE; // allow chars to interrupt + IE1 |= URXIE0; // enable rx interrupt + IFG1 &= ~UTXIFG0; + eint(); +} + +/*---------------------------------------------------------------------------*/ +void msp430_init_dco(void) +{ + /*----------------------- use external oszillator -------------------------*/ + uint16_t i; + + // Stop watchdog + WDTCTL = WDTPW + WDTHOLD; + + 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? + switch (__msp430_cpu_speed) { + case MCLK_2MHZ_SCLK_1MHZ: + BCSCTL2 = (SELM_2 | DIVM_2) | (SELS | DIVS_3); + break; + case MCLK_4MHZ_SCLK_1MHZ: + BCSCTL2 = (SELM_2 | DIVM_1) | (SELS | DIVS_3); + break; + case MCLK_8MHZ_SCLK_1MHZ: + BCSCTL2 = SELM_2 | (SELS | DIVS_3); + break; + default: + BCSCTL2 = SELM_2 + SELS; // MCLK and SMCLK = XT2 (safe) + break; + } +} + +void board_init() { + msp430_cpu_init(); + msb_ports_init(); + + LED_RED_ON; + + msp430_set_cpu_speed(MCLK_8MHZ_SCLK_8MHZ); +} diff --git a/wsn430-common/drivers/Makefile b/wsn430-common/drivers/Makefile new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wsn430-common/include/board-conf.h b/wsn430-common/include/board-conf.h new file mode 100644 index 0000000000..e85c3128f2 --- /dev/null +++ b/wsn430-common/include/board-conf.h @@ -0,0 +1,6 @@ +#ifndef BOARD_CONF_H +#define BOARD_CONF_H + +#define INFOMEM (0x1000) + +#endif /* BOARD-CONF_H */ diff --git a/wsn430-common/uart0.c b/wsn430-common/uart0.c new file mode 100644 index 0000000000..f743335ec4 --- /dev/null +++ b/wsn430-common/uart0.c @@ -0,0 +1,63 @@ + /* + * uart0.c - Implementation of the uart. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +#include "board.h" + +#define UART0_TX U0TXBUF +#define UART0_WAIT_TXDONE() while( (U0TCTL & TXEPT) == 0 ) { _NOP(); } + +#include +#include + +#include + +int putchar(int c) +{ + UART0_TX = c; + UART0_WAIT_TXDONE(); + + if (c == 10) { + UART0_TX = 13; + UART0_WAIT_TXDONE(); + } + + return c; +} + +void usart0irq(void); +/** + * \brief the interrupt function + */ +interrupt(USART0RX_VECTOR) usart0irq(void) { + int dummy = 0; + /* Check status register for receive errors. */ + if(U0RCTL & RXERR) { + if (U0RCTL & FE) { + puts("rx framing error"); + } + if (U0RCTL & OE) { + puts("rx overrun error"); + } + if (U0RCTL & PE) { + puts("rx parity error"); + } + if (U0RCTL & BRK) { + puts("rx break error"); + } + /* Clear error flags by forcing a dummy read. */ + dummy = U0RXBUF; + } +#ifdef MODULE_UART0 + else if (uart0_handler_pid) { + dummy = U0RXBUF; + uart0_handle_incoming(dummy); + uart0_notify_thread(); + } +#endif +} + diff --git a/wsn430-v1_3b/Makefile b/wsn430-v1_3b/Makefile new file mode 100644 index 0000000000..e19884c6b1 --- /dev/null +++ b/wsn430-v1_3b/Makefile @@ -0,0 +1,36 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = wsn430-v1_3b_base.a + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I${RIOTBASE}/core/include/ +INCLUDES += -Iinclude/ -I$(RIOTBOARD)/wsn430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/include +#INCLUDES += -I/usr/msp430/include/ + +all: $(BINDIR)$(ARCH) + $(MAKE) -C ../wsn430-common + +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + mkdir -p $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + $(MAKE) -C ../wsn430-common clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi \ No newline at end of file diff --git a/wsn430-v1_3b/Makefile.dep b/wsn430-v1_3b/Makefile.dep new file mode 100644 index 0000000000..5463317289 --- /dev/null +++ b/wsn430-v1_3b/Makefile.dep @@ -0,0 +1,7 @@ +ifneq (,$(findstring cc110x_ng,$(USEMODULE))) + ifeq (,$(findstring cc110x_spi,$(USEMODULE))) + USEMODULE += cc110x_spi + endif +endif + +USEMODULE += msp430_common \ No newline at end of file diff --git a/wsn430-v1_3b/Makefile.include b/wsn430-v1_3b/Makefile.include new file mode 100644 index 0000000000..366d6cbcc8 --- /dev/null +++ b/wsn430-v1_3b/Makefile.include @@ -0,0 +1,3 @@ +include $(RIOTBOARD)/$(BOARD)/Makefile.dep + +include $(RIOTBOARD)/wsn430-common/Makefile.include \ No newline at end of file diff --git a/wsn430-v1_3b/driver_cc110x.c b/wsn430-v1_3b/driver_cc110x.c new file mode 100644 index 0000000000..39ca90bb15 --- /dev/null +++ b/wsn430-v1_3b/driver_cc110x.c @@ -0,0 +1,206 @@ + /* + * driver_cc110x.c - Implementation of the board dependent cc1100 functions. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +#include + +#include +#include +#include + +#include +#include + +#define CC1100_GDO0 (P1IN & 0x08) // read serial I/O (GDO0) +#define CC1100_GDO1 (P5IN & 0x04) // read serial I/O (GDO1) +#define CC1100_GDO2 (P1IN & 0x10) // read serial I/O (GDO2) + +#define CC1100_CS_LOW (P4OUT &= ~0x04) +#define CC1100_CS_HIGH (P4OUT |= 0x04) + +#define CC1100_GDO1_LOW_COUNT (2700) // loop count (timeout ~ 500 us) to wait +#define CC1100_GDO1_LOW_RETRY (100) // max. retries for GDO1 to go low + +volatile int abort_count; +volatile int retry_count = 0; + +void cc110x_gdo0_enable(void) +{ + P1IFG &= ~0x08; /* Clear IFG for GDO0 */ + P1IE |= 0x08; /* Enable interrupt for GDO0 */ +} + +void cc110x_gdo0_disable(void) +{ + P1IE &= ~0x08; /* Disable interrupt for GDO0 */ + P1IFG &= ~0x08; /* Clear IFG for GDO0 */ +} + +void cc110x_gdo2_enable(void) +{ + P1IFG &= ~0x10; /* Clear IFG for GDO2 */ + P1IE |= 0x10; /* Enable interrupt for GDO2 */ +} + +void cc110x_gdo2_disable(void) +{ + P1IE &= ~0x10; /* Disable interrupt for GDO2 */ + P1IFG &= ~0x10; /* Clear IFG for GDO2 */ +} + +void cc110x_before_send(void) +{ + // Disable GDO2 interrupt before sending packet + cc110x_gdo2_disable(); +} + +void cc110x_after_send(void) +{ + // Enable GDO2 interrupt after sending packet + cc110x_gdo2_enable(); +} + + +int cc110x_get_gdo0(void) { + return CC1100_GDO0; +} + +int cc110x_get_gdo1(void) { + return CC1100_GDO1; +} + +int cc110x_get_gdo2(void) { + return CC1100_GDO2; +} + +void cc110x_spi_cs(void) +{ + CC1100_CS_LOW; +} + +uint8_t cc110x_txrx(uint8_t data) +{ + /* Ensure TX Buf is empty */ + long c = 0; + IFG2 &= ~UTXIFG1; + IFG2 &= ~URXIFG1; + U1TXBUF = data; + while(!(IFG2 & UTXIFG1)) { + if (c++ == 1000000) { + puts("cc110x_txrx alarm()"); + } + } + /* Wait for Byte received */ + c = 0; + while(!(IFG2 & URXIFG1)) { + if (c++ == 1000000) { + puts("cc110x_txrx alarm()"); + } + } + return U1RXBUF; +} + + +void cc110x_spi_select(void) +{ + // Switch to GDO mode + P5SEL &= ~0x04; + P5DIR &= ~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 */ + P5SEL |= 0x04; +} + +void cc110x_spi_unselect(void) { + CC1100_CS_HIGH; +} + +void cc110x_init_interrupts(void) +{ + unsigned int state = disableIRQ(); /* Disable all interrupts */ + P1SEL = 0x00; /* must be <> 1 to use interrupts */ + P1IES |= 0x10; /* Enables external interrupt on low edge (for GDO2) */ + P1IE |= 0x10; /* Enable interrupt */ + P1IFG &= ~0x10; /* Clears the interrupt flag */ + P1IE &= ~0x08; /* Disable interrupt for GDO0 */ + P1IFG &= ~0x08; /* Clear IFG for GDO0 */ + restoreIRQ(state); /* Enable all interrupts */ +} + +void cc110x_spi_init(uint8_t clockrate) +{ + // Switch off async UART + while(!(U1TCTL & TXEPT)); // Wait for empty UxTXBUF register + IE2 &= ~(URXIE1 + UTXIE1); // Disable USART1 receive&transmit interrupt + ME2 &= ~(UTXE1 + URXE1); + P5DIR |= 0x0A; // output for CLK and SIMO + P5DIR &= ~(0x04); // input for SOMI + P5SEL |= 0x0E; // Set pins as SPI + + // Keep peripheral in reset state + U1CTL = SWRST; + + // 8-bit SPI Master 3-pin mode, with SMCLK as clock source + // CKPL works also, but not CKPH+CKPL or none of them!! + U1CTL |= CHAR + SYNC + MM; + U1TCTL = CKPH + SSEL1 + SSEL0 + STC; + + // Ignore clockrate argument for now, just use clock source/2 + // SMCLK = 8 MHz + U1BR0 = 0x02; // Ensure baud rate >= 2 + U1BR1 = 0x00; + U1MCTL = 0x00; // No modulation + U1RCTL = 0x00; // Reset Receive Control Register + + // Enable SPI mode + ME2 |= USPIE1; + + // Release for operation + U1CTL &= ~SWRST; +} + +/* + * CC1100 receive interrupt + */ +interrupt (PORT1_VECTOR) __attribute__ ((naked)) cc110x_isr(void){ + __enter_isr(); + /* Check IFG */ + if ((P1IFG & 0x10) != 0) { + P1IFG &= ~0x10; + cc110x_gdo2_irq(); + } + else if ((P2IFG & 0x08) != 0) { + cc110x_gdo0_irq(); + P1IE &= ~0x08; // Disable interrupt for GDO0 + P1IFG &= ~0x08; // Clear IFG for GDO0 + } else { + puts("cc110x_isr(): unexpected IFG!"); + /* Should not occur - only GDO1 and GDO2 interrupts are enabled */ + } + __exit_isr(); +} diff --git a/wsn430-v1_3b/include/board.h b/wsn430-v1_3b/include/board.h new file mode 100644 index 0000000000..ad864e132e --- /dev/null +++ b/wsn430-v1_3b/include/board.h @@ -0,0 +1,31 @@ +#ifndef _MSB_BOARD_H +#define _MSB_BOARD_H + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 800000uL +#define MSP430_HAS_DCOR 0 +#define MSP430_HAS_EXTERNAL_CRYSTAL 1 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x04 +#define LEDS_CONF_GREEN 0x05 +#define LEDS_CONF_BLUE 0x06 + +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED + +#define LED_GREEN_ON LEDS_PxOUT &=~LEDS_CONF_GREEN +#define LED_GREEN_OFF LEDS_PxOUT |= LEDS_CONF_GREEN +#define LED_GREEN_TOGGLE LEDS_PxOUT ^= LEDS_CONF_GREEN + +#define LED_BLUE_ON LEDS_PxOUT &=~LEDS_CONF_BLUE +#define LED_BLUE_OFF LEDS_PxOUT |= LEDS_CONF_BLUE +#define LED_BLUE_TOGGLE LEDS_PxOUT ^= LEDS_CONF_BLUE + +#include + +/** @} */ +#endif // _MSB_BOARD_H From bdecdc5bf96c72e51a00bf55fb93ed33ab380d41 Mon Sep 17 00:00:00 2001 From: Milan Babel Date: Tue, 28 May 2013 10:10:45 +0200 Subject: [PATCH 112/188] added wsn430-v1.4 also made some minor changes to shared wsn430-common files --- Makefile.base | 4 + wsn430-common/board_config.c | 7 + wsn430-common/board_init.c | 6 +- wsn430-common/include/board-conf.h | 7 + wsn430-v1_3b/driver_cc110x.c | 5 +- wsn430-v1_3b/include/board.h | 36 ++++- wsn430-v1_4/Makefile | 36 +++++ wsn430-v1_4/Makefile.dep | 1 + wsn430-v1_4/Makefile.include | 3 + wsn430-v1_4/driver_cc2420.c | 213 +++++++++++++++++++++++++++++ wsn430-v1_4/include/board.h | 61 +++++++++ 11 files changed, 371 insertions(+), 8 deletions(-) create mode 100644 wsn430-v1_4/Makefile create mode 100644 wsn430-v1_4/Makefile.dep create mode 100644 wsn430-v1_4/Makefile.include create mode 100644 wsn430-v1_4/driver_cc2420.c create mode 100644 wsn430-v1_4/include/board.h diff --git a/Makefile.base b/Makefile.base index 641eaf56cd..0b860294f9 100644 --- a/Makefile.base +++ b/Makefile.base @@ -17,6 +17,10 @@ ifeq ($(BOARD),wsn430-v1_3b) INCLUDES += -I$(RIOTBOARD)/wsn430-v1_3b/include/ INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ endif +ifeq ($(BOARD),wsn430-v1_4) + INCLUDES += -I$(RIOTBOARD)/wsn430-v1_4/include/ + INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ +endif ifeq ($(BOARD),chronos) INCLUDES += -I$(RIOTBOARD)/chronos/include/ INCLUDES += -I$(RIOTBOARD)/chronos/drivers/include/ diff --git a/wsn430-common/board_config.c b/wsn430-common/board_config.c index f22e513b20..4e9bc0b69c 100644 --- a/wsn430-common/board_config.c +++ b/wsn430-common/board_config.c @@ -1,3 +1,10 @@ +/** + * board-config.c. + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + #include #include #include diff --git a/wsn430-common/board_init.c b/wsn430-common/board_init.c index b7b523cf76..d89657017b 100644 --- a/wsn430-common/board_init.c +++ b/wsn430-common/board_init.c @@ -2,8 +2,8 @@ * board_init.c - Implementation of functions to init board. * Copyright (C) 2013 Milan Babel * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. */ #include "cpu.h" @@ -49,7 +49,7 @@ static void msb_ports_init(void) // Port 1: GDO, Flash, BSL TX P1SEL = 0x02; // Port1 Select: 00000010 = 0x02 P1OUT = 0x00; // Port1 Output: 00000000 = 0x00 - P1DIR = 0xE7; // Port1 Direction: 11100111 = 0xE7 + P1DIR = 0x87; // Port1 Direction: 10000111 = 0x87 // Port 2: GPIO, BSL RX, 1wire P2SEL = 0x04; // Port2 Select: 00000100 = 0x04 diff --git a/wsn430-common/include/board-conf.h b/wsn430-common/include/board-conf.h index e85c3128f2..7ebf0e03e6 100644 --- a/wsn430-common/include/board-conf.h +++ b/wsn430-common/include/board-conf.h @@ -1,3 +1,10 @@ +/** + * board-conf.h. + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + #ifndef BOARD_CONF_H #define BOARD_CONF_H diff --git a/wsn430-v1_3b/driver_cc110x.c b/wsn430-v1_3b/driver_cc110x.c index 39ca90bb15..89669e64f7 100644 --- a/wsn430-v1_3b/driver_cc110x.c +++ b/wsn430-v1_3b/driver_cc110x.c @@ -1,9 +1,10 @@ /* * driver_cc110x.c - Implementation of the board dependent cc1100 functions. + * Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will * Copyright (C) 2013 Milan Babel * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. */ #include diff --git a/wsn430-v1_3b/include/board.h b/wsn430-v1_3b/include/board.h index ad864e132e..ee09d10169 100644 --- a/wsn430-v1_3b/include/board.h +++ b/wsn430-v1_3b/include/board.h @@ -1,5 +1,35 @@ -#ifndef _MSB_BOARD_H -#define _MSB_BOARD_H +/** + * board.h - wsn430-v1_3b Board. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef _WSN_BOARD_H +#define _WSN_BOARD_H + +/** + * @defgroup wsn430-v1_3b Senslab WSN430 v1.3b + * @ingroup wsn430 + * +

Compontents

+\li MSP430 +\li CC1100 + +* @{ +*/ + +/** + * @file + * @brief wsn430-v1_3b Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Milan Babel + * @version $Revision$ + * + * @note $Id$ + */ //MSB430 core #define MSP430_INITIAL_CPU_SPEED 800000uL @@ -28,4 +58,4 @@ #include /** @} */ -#endif // _MSB_BOARD_H +#endif // _WSN_BOARD_H diff --git a/wsn430-v1_4/Makefile b/wsn430-v1_4/Makefile new file mode 100644 index 0000000000..1bc4eca767 --- /dev/null +++ b/wsn430-v1_4/Makefile @@ -0,0 +1,36 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = wsn430-v1_4_base.a + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I${RIOTBASE}/core/include/ +INCLUDES += -Iinclude/ -I$(RIOTBOARD)/wsn430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include +#INCLUDES += -I/usr/msp430/include/ + +all: $(BINDIR)$(ARCH) + $(MAKE) -C ../wsn430-common + +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + mkdir -p $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + $(MAKE) -C ../wsn430-common clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi \ No newline at end of file diff --git a/wsn430-v1_4/Makefile.dep b/wsn430-v1_4/Makefile.dep new file mode 100644 index 0000000000..52516208bc --- /dev/null +++ b/wsn430-v1_4/Makefile.dep @@ -0,0 +1 @@ +USEMODULE += msp430_common \ No newline at end of file diff --git a/wsn430-v1_4/Makefile.include b/wsn430-v1_4/Makefile.include new file mode 100644 index 0000000000..366d6cbcc8 --- /dev/null +++ b/wsn430-v1_4/Makefile.include @@ -0,0 +1,3 @@ +include $(RIOTBOARD)/$(BOARD)/Makefile.dep + +include $(RIOTBOARD)/wsn430-common/Makefile.include \ No newline at end of file diff --git a/wsn430-v1_4/driver_cc2420.c b/wsn430-v1_4/driver_cc2420.c new file mode 100644 index 0000000000..c653c9ba3a --- /dev/null +++ b/wsn430-v1_4/driver_cc2420.c @@ -0,0 +1,213 @@ + /* + * driver_cc2420.c - Implementation of the board dependent cc2420 functions. + * Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#include + +#include +#include +#include +#include + +#include + +#define CC2420_RESETn_PIN 0x80 +#define CC2420_VREGEN_PIN 0x01 + +#define CC2420_GDO0_PIN 0x08 +#define CC2420_GDO2_PIN 0x10 +#define CC2420_SFD_PIN 0x20 +#define CC2420_CCA_PIN 0x40 + +#define CC2420_GDO0 (P1IN & CC2420_GDO0_PIN) // read serial I/O (GDO0) +#define CC2420_GDO2 (P1IN & CC2420_GDO2_PIN) // read serial I/O (GDO2) +#define CC2420_SFD (P1IN & CC2420_SFD_PIN) // read serial I/0 (SFD) +#define CC2420_CCA (P1IN & CC2420_CCA_PIN) // read serial I/O (CCA) + + +#define CC2420_CS_LOW (P4OUT &= ~0x04) +#define CC2420_CS_HIGH (P4OUT |= 0x04) + +#define CC2420_GDO1_LOW_COUNT (2700) // loop count (timeout ~ 500 us) to wait +#define CC2420_GDO1_LOW_RETRY (100) // max. retries for GDO1 to go low + +volatile int abort_count; +volatile int retry_count = 0; + +void cc2420_reset(void) +{ + P3OUT |= CC2420_VREGEN_PIN; + P1OUT &= ~CC2420_RESETn_PIN; + hwtimer_wait(500); + P1OUT |= CC2420_RESETn_PIN; +} + +void cc2420_gdo0_enable(void) +{ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ + P1IE |= CC2420_GDO0_PIN; /* Enable interrupt for GDO0 */ +} + +void cc2420_gdo0_disable(void) +{ + P1IE &= ~CC2420_GDO0_PIN; /* Disable interrupt for GDO0 */ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ +} + +void cc2420_gdo2_enable(void) +{ + P1IFG &= ~CC2420_GDO2_PIN; /* Clear IFG for GDO2 */ + P1IE |= CC2420_GDO2_PIN; /* Enable interrupt for GDO2 */ +} + +void cc2420_gdo2_disable(void) +{ + P1IE &= ~CC2420_GDO2_PIN; /* Disable interrupt for GDO2 */ + P1IFG &= ~CC2420_GDO2_PIN; /* Clear IFG for GDO2 */ +} + +void cc2420_before_send(void) +{ + // Disable SFD interrupt before sending packet + // However this is not used atm +} + +void cc2420_after_send(void) +{ + // Enable SFD interrupt after sending packet + // However this is not used atm +} + + +int cc2420_get_gdo0(void) +{ + return CC2420_GDO0; +} + +int cc2420_get_gdo2(void) +{ + return CC2420_GDO2; +} + +int cc2420_get_sfd(void) +{ + return CC2420_SFD; +} + +void cc2420_spi_cs(void) +{ + CC2420_CS_LOW; +} + +uint8_t cc2420_txrx(uint8_t data) +{ + /* Ensure TX Buf is empty */ + long c = 0; + IFG2 &= ~UTXIFG1; + IFG2 &= ~URXIFG1; + U1TXBUF = data; + while(!(IFG2 & UTXIFG1)) { + if (c++ == 1000000) { + puts("cc2420_txrx alarm()"); + } + } + /* Wait for Byte received */ + c = 0; + while(!(IFG2 & URXIFG1)) { + if (c++ == 1000000) { + puts("cc2420_txrx alarm()"); + } + } + return U1RXBUF; +} + + +void cc2420_spi_select(void) +{ + CC2420_CS_LOW; +} + +void cc2420_spi_unselect(void) { + CC2420_CS_HIGH; +} + +void cc2420_init_interrupts(void) +{ + unsigned int state = disableIRQ(); /* Disable all interrupts */ + P1SEL = 0x00; /* must be <> 1 to use interrupts */ + P1IES |= CC2420_GDO2_PIN; /* Enables external interrupt on falling edge (for GDO2) */ + P1IE |= CC2420_GDO2_PIN; /* Enable interrupt */ + P1IFG &= ~CC2420_GDO2_PIN; /* Clears the interrupt flag */ + P1IES |= CC2420_SFD_PIN; /* Enables external interrupt on falling edge (for GDO2) */ + P1IE |= CC2420_SFD_PIN; /* Enable interrupt */ + P1IFG &= ~CC2420_SFD_PIN; /* Clears the interrupt flag */ + P1IE &= ~CC2420_GDO0_PIN; /* Disable interrupt for GDO0 */ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ + restoreIRQ(state); /* Enable all interrupts */ +} + +void cc2420_spi_init(void) +{ + // Switch off async UART + while(!(U1TCTL & TXEPT)); // Wait for empty UxTXBUF register + IE2 &= ~(URXIE1 + UTXIE1); // Disable USART1 receive&transmit interrupt + ME2 &= ~(UTXE1 + URXE1); + P5DIR |= 0x0A; // output for CLK and SIMO + P5DIR &= ~(0x04); // input for SOMI + P5SEL |= 0x0E; // Set pins as SPI + + // Keep peripheral in reset state + U1CTL = SWRST; + + // 8-bit SPI Master 3-pin mode, with SMCLK as clock source + // CKPL works also, but not CKPH+CKPL or none of them!! + U1CTL |= CHAR + SYNC + MM; + U1TCTL = CKPH + SSEL1 + SSEL0 + STC; + + // Ignore clockrate argument for now, just use clock source/2 + // SMCLK = 8 MHz + U1BR0 = 0x02; // Ensure baud rate >= 2 + U1BR1 = 0x00; + U1MCTL = 0x00; // No modulation + U1RCTL = 0x00; // Reset Receive Control Register + + // Enable SPI mode + ME2 |= USPIE1; + + // Release for operation + U1CTL &= ~SWRST; +} + +/* + * CC1100 receive interrupt + */ +interrupt (PORT1_VECTOR) __attribute__ ((naked)) cc2420_isr(void){ + __enter_isr(); + /* Check IFG */ + if ((P1IFG & CC2420_GDO2_PIN) != 0) { + puts("rx interrupt"); + P1IFG &= ~CC2420_GDO2_PIN; + cc2420_rx_irq(); + } + else if ((P1IFG & CC2420_GDO0_PIN) != 0) { + cc2420_rxoverflow_irq(); + puts("[CC2420] rxfifo overflow"); + //P1IE &= ~CC2420_GDO0_PIN; // Disable interrupt for GDO0 + P1IFG &= ~CC2420_GDO0_PIN; // Clear IFG for GDO0 + } else if ((P1IFG & CC2420_SFD_PIN) != 0) { + puts("sfd interrupt"); + P1IFG &= ~CC2420_SFD_PIN; + cc2420_switch_to_rx(); + } + + else { + puts("cc2420_isr(): unexpected IFG!"); + /* Should not occur - only GDO1 and GDO2 interrupts are enabled */ + } + __exit_isr(); +} diff --git a/wsn430-v1_4/include/board.h b/wsn430-v1_4/include/board.h new file mode 100644 index 0000000000..3cb86d1366 --- /dev/null +++ b/wsn430-v1_4/include/board.h @@ -0,0 +1,61 @@ +/** + * board.h - wsn430-v1_4 Board. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef _WSN_BOARD_H +#define _WSN_BOARD_H + +/** + * @defgroup wsn430-v1_4 Senslab WSN430 v1.4 + * @ingroup wsn430 + * +

Compontents

+\li MSP430 +\li CC2420 + +* @{ +*/ + +/** + * @file + * @brief wsn430-v1_4 Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Milan Babel + * @version $Revision$ + * + * @note $Id$ + */ + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 800000uL +#define MSP430_HAS_DCOR 0 +#define MSP430_HAS_EXTERNAL_CRYSTAL 1 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x04 +#define LEDS_CONF_GREEN 0x05 +#define LEDS_CONF_BLUE 0x06 + +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED + +#define LED_GREEN_ON LEDS_PxOUT &=~LEDS_CONF_GREEN +#define LED_GREEN_OFF LEDS_PxOUT |= LEDS_CONF_GREEN +#define LED_GREEN_TOGGLE LEDS_PxOUT ^= LEDS_CONF_GREEN + +#define LED_BLUE_ON LEDS_PxOUT &=~LEDS_CONF_BLUE +#define LED_BLUE_OFF LEDS_PxOUT |= LEDS_CONF_BLUE +#define LED_BLUE_TOGGLE LEDS_PxOUT ^= LEDS_CONF_BLUE + +#include + +/** @} */ +#endif // _WSN_BOARD_H From a241da6bf7078ab570488ffacfc2c9fe3b7517b1 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 10 Jun 2013 16:15:38 +0200 Subject: [PATCH 113/188] * fixed includes for msb-a2 --- msba2-common/board_common_init.c | 1 - msba2/Makefile.include | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/msba2-common/board_common_init.c b/msba2-common/board_common_init.c index 8d7c359625..7e4eb2c126 100644 --- a/msba2-common/board_common_init.c +++ b/msba2-common/board_common_init.c @@ -40,7 +40,6 @@ and the mailinglist (subscription via web site) * * @note $Id$ */ -#include #include #include #include diff --git a/msba2/Makefile.include b/msba2/Makefile.include index 741b952a92..1258b6e330 100644 --- a/msba2/Makefile.include +++ b/msba2/Makefile.include @@ -1,3 +1,3 @@ -export INCLUDES += -I$(RIOTBOARD)/msba2-common/include +export INCLUDES += -Iinclude -I$(RIOTBOARD)/msba2-common/include include $(RIOTBOARD)/msba2-common/Makefile.include From 79b97c994693ebf0e4850564215c90f68a9d1e5c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 11 Jun 2013 11:37:29 +0200 Subject: [PATCH 114/188] * added missing msp430_common module to Makefile --- msb-430-common/Makefile.include | 1 + 1 file changed, 1 insertion(+) diff --git a/msb-430-common/Makefile.include b/msb-430-common/Makefile.include index 8fc09d2874..4adcbb6dd1 100644 --- a/msb-430-common/Makefile.include +++ b/msb-430-common/Makefile.include @@ -20,4 +20,5 @@ endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" +export USEMODULE += msp430_common export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ From 0ac14625f36af000a618ab86b691349911b7910c Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 3 Jun 2013 19:37:22 +0200 Subject: [PATCH 115/188] make stdin/stdout customizable stub --- native/native-uart0.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/native/native-uart0.c b/native/native-uart0.c index e13447bb0e..b43a7dcbe4 100644 --- a/native/native-uart0.c +++ b/native/native-uart0.c @@ -1,17 +1,20 @@ /* - * TODO: - * make stdin/stdout customizable. + * native uart0 implementation */ #include #include #include + #include #include "cpu.h" #include "debug.h" #include "board_uart0.h" +int _native_uart_in; +int _native_uart_out; + fd_set _native_uart_rfds; static inline int uart0_puts(char *astring, int length) @@ -24,10 +27,11 @@ void _native_handle_uart0_input() char buf[42]; int nread; + DEBUG("_native_handle_uart0_input\n"); _native_in_syscall = 0; _native_in_isr = 1; - nread = read(0, buf, sizeof(buf)); + nread = read(_native_uart_in, buf, sizeof(buf)); if (nread == -1) { err(1, "_native_handle_uart0_input(): read()"); } @@ -42,13 +46,17 @@ void _native_handle_uart0_input() void _native_init_uart0() { - /* Watch stdin (fd 0) to see when it has input. */ + _native_uart_out = STDOUT_FILENO; + _native_uart_in = STDIN_FILENO; + + /* set fds for select in lpm */ FD_ZERO(&_native_uart_rfds); - FD_SET(0, &_native_uart_rfds); + FD_SET(_native_uart_in, &_native_uart_rfds); + puts("RIOT native uart0 initialized."); } int putchar(int c) { - write(1, &c, 1); + write(_native_uart_out, &c, 1); return 0; } From c31648e2e42cbbae7cb406d1df6ec3db7b6d4d4a Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 12 Jun 2013 16:23:34 +0200 Subject: [PATCH 116/188] moved native board drivers into separate directory split up drivers to avoid building unnecessary files --- native/Makefile | 11 ++++++---- native/Makefile.include | 4 ++-- native/drivers/Makefile | 30 +++++++++++++++++++++++++++ native/{ => drivers}/native-led.c | 0 native/{ => drivers}/native-ltc4150.c | 0 native/{ => drivers}/native-uart0.c | 0 6 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 native/drivers/Makefile rename native/{ => drivers}/native-led.c (100%) rename native/{ => drivers}/native-ltc4150.c (100%) rename native/{ => drivers}/native-uart0.c (100%) diff --git a/native/Makefile b/native/Makefile index 86ddb4a6ff..ded96b6cf2 100644 --- a/native/Makefile +++ b/native/Makefile @@ -2,14 +2,16 @@ SRC = $(wildcard *.c) BINDIR = bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines DEP = $(SRC:%.c=$(BINDIR)%.d) +export ARCH = native_base.a INCLUDES += -I$(RIOTBASE)/cpu/native/include/ INCLUDES += -I$(RIOTBOARD)/native/include/ -all: $(BINDIR)native_base.a +all: $(BINDIR)$(ARCH) + $(MAKE) -C drivers -$(BINDIR)native_base.a: $(OBJ) - $(AR) rcs $(BINDIR)native_base.a $(OBJ) +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) # pull in dependency info for *existing* .o files -include $(OBJ:.o=.d) @@ -23,6 +25,7 @@ $(BINDIR)%.o: %.c # remove compilation products clean: - rm -f $(BINDIR)native_base.a $(OBJ) $(DEP) + ${MAKE} -C drivers clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) -rmdir -p $(BINDIR) diff --git a/native/Makefile.include b/native/Makefile.include index d360b2248f..e8e5d48e4d 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -5,7 +5,7 @@ export CPU = native export PREFIX = #export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar -export CFLAGS = -std=gnu99 -Wall -m32 +export CFLAGS += -std=gnu99 -Wall -m32 export ASFLAGS = export AS = $(PREFIX)as export LINK = $(PREFIX)gcc @@ -14,7 +14,7 @@ export OBJCOPY = $(PREFIX)objcopy FLASHER = lpc2k_pgm TERM = pyterm.py -LINKFLAGS = -m32 +LINKFLAGS = -m32 -gc ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 diff --git a/native/drivers/Makefile b/native/drivers/Makefile new file mode 100644 index 0000000000..f0516a8530 --- /dev/null +++ b/native/drivers/Makefile @@ -0,0 +1,30 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(BINDIR)native-led.o +ifneq (,$(findstring ltc4150,$(USEMODULE))) + OBJ += $(BINDIR)native-ltc4150.o +endif +ifneq (,$(findstring uart0,$(USEMODULE))) + OBJ += $(BINDIR)native-uart0.o +endif +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/native/include/ + +$(BINDIR)native_drivers.a: $(OBJ) + @$(AR) rcs $(BINDIR)${ARCH} $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + @$(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)" | cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products + +clean: + rm -f $(OBJ) $(DEP) + diff --git a/native/native-led.c b/native/drivers/native-led.c similarity index 100% rename from native/native-led.c rename to native/drivers/native-led.c diff --git a/native/native-ltc4150.c b/native/drivers/native-ltc4150.c similarity index 100% rename from native/native-ltc4150.c rename to native/drivers/native-ltc4150.c diff --git a/native/native-uart0.c b/native/drivers/native-uart0.c similarity index 100% rename from native/native-uart0.c rename to native/drivers/native-uart0.c From 0c9bc11a4a0fc0797646bf71876a55624a84b018 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 12 Jun 2013 16:27:17 +0200 Subject: [PATCH 117/188] * fixed includes for msba2 --- msba2-common/Makefile.include | 2 ++ msba2/Makefile.include | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index 7ba1eae0e0..b8626464fc 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -21,3 +21,5 @@ endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = $(PORT) $(PROJBINDIR)/$(PROJECT).hex include $(RIOTBOARD)/msba2-common/Makefile.dep + +export INCLUDES += -I$(RIOTCPU)/lpc2387/include diff --git a/msba2/Makefile.include b/msba2/Makefile.include index 1258b6e330..80751c020a 100644 --- a/msba2/Makefile.include +++ b/msba2/Makefile.include @@ -1,3 +1,3 @@ -export INCLUDES += -Iinclude -I$(RIOTBOARD)/msba2-common/include +export INCLUDES += -I$(RIOTBOARD)/msba2/include -I$(RIOTBOARD)/msba2-common/include include $(RIOTBOARD)/msba2-common/Makefile.include From 13738e7dd0ba59c83e54573a266ece57137d4891 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 25 Jun 2013 15:31:54 +0200 Subject: [PATCH 118/188] * fixed include path --- wsn430-v1_4/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wsn430-v1_4/Makefile b/wsn430-v1_4/Makefile index 1bc4eca767..d6b578d59f 100644 --- a/wsn430-v1_4/Makefile +++ b/wsn430-v1_4/Makefile @@ -9,7 +9,7 @@ INCLUDES += -I${RIOTBASE}/core/include/ INCLUDES += -Iinclude/ -I$(RIOTBOARD)/wsn430-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include -#INCLUDES += -I/usr/msp430/include/ +INCLUDES += -I$(RIOTBASE)/sys/net/ all: $(BINDIR)$(ARCH) $(MAKE) -C ../wsn430-common @@ -33,4 +33,4 @@ clean: rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) @if [ -d $(BINDIR) ] ; \ then rmdir $(BINDIR) ; \ - fi \ No newline at end of file + fi From c380603a5dad3d3c6b4d9e639f0085a4ab9d9fd5 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 15 Jul 2013 20:57:12 +0200 Subject: [PATCH 119/188] moved native internal functions declarations --- native/board_init.c | 2 ++ native/drivers/native-uart0.c | 2 +- native/include/board.h | 6 ------ native/include/board_internal.h | 6 ++++++ 4 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 native/include/board_internal.h diff --git a/native/board_init.c b/native/board_init.c index d32c653dc9..fa1a319afc 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -15,6 +15,8 @@ #include #include "board.h" +#include "board_internal.h" + /** * Nothing to initialize at the moment. * Turns the red LED on and the green LED off. diff --git a/native/drivers/native-uart0.c b/native/drivers/native-uart0.c index b43a7dcbe4..3af009eee4 100644 --- a/native/drivers/native-uart0.c +++ b/native/drivers/native-uart0.c @@ -17,7 +17,7 @@ int _native_uart_out; fd_set _native_uart_rfds; -static inline int uart0_puts(char *astring, int length) +inline int uart0_puts(char *astring, int length) { return puts(astring); } diff --git a/native/include/board.h b/native/include/board.h index 69e40eb383..18ee528271 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -21,9 +21,3 @@ void LED_GREEN_TOGGLE(void); void LED_RED_OFF(void); void LED_RED_ON(void); void LED_RED_TOGGLE(void); - -#ifdef MODULE_UART0 -#include -extern fd_set _native_uart_rfds; -extern void _native_handle_uart0_input(void); -#endif diff --git a/native/include/board_internal.h b/native/include/board_internal.h new file mode 100644 index 0000000000..752cbcdfb5 --- /dev/null +++ b/native/include/board_internal.h @@ -0,0 +1,6 @@ +#ifdef MODULE_UART0 +#include +extern fd_set _native_uart_rfds; +void _native_handle_uart0_input(void); +void _native_init_uart0(void); +#endif From 6ce0ad25a74ddcd1625119f7fda32fe6d8b5fe1c Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Thu, 18 Jul 2013 16:04:24 +0200 Subject: [PATCH 120/188] rename kernel_intern.h german "intern" to english "internal" --- msb-430-common/board_init.c | 2 +- wsn430-common/board_init.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index 4673600445..e32945a0cb 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -1,6 +1,6 @@ #include "cpu.h" #include "board.h" -#include "kernel_intern.h" +#include "kernel_internal.h" #include "msp430.h" #include "debug.h" diff --git a/wsn430-common/board_init.c b/wsn430-common/board_init.c index d89657017b..986a8ed10f 100644 --- a/wsn430-common/board_init.c +++ b/wsn430-common/board_init.c @@ -8,7 +8,7 @@ #include "cpu.h" #include "board.h" -#include "kernel_intern.h" +#include "kernel_internal.h" #include "msp430.h" #include "debug.h" From 4997e615662f90e078207cbf77c2d1ecdee3cbf1 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Thu, 18 Jul 2013 16:06:02 +0200 Subject: [PATCH 121/188] fixed old-style-declaration warning board_init.c:7:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration] --- msb-430-common/board_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index 4673600445..3ba37a3ec2 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -4,7 +4,7 @@ #include "msp430.h" #include "debug.h" -volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; +static volatile uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; /*---------------------------------------------------------------------------*/ static uint8_t calc_umctl(uint16_t br) { From e7965250c5b783b0617d332860f7ac3d809f43f6 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 23 Jul 2013 09:44:31 +0200 Subject: [PATCH 122/188] implementation of the radio driver for the mc1322x --- redbee-econotag/drivers/include/maca.h | 529 +++++++++ redbee-econotag/drivers/include/maca_packet.h | 44 + redbee-econotag/drivers/maca.c | 1041 +++++++++++++++++ 3 files changed, 1614 insertions(+) create mode 100644 redbee-econotag/drivers/include/maca.h create mode 100644 redbee-econotag/drivers/include/maca_packet.h create mode 100644 redbee-econotag/drivers/maca.c diff --git a/redbee-econotag/drivers/include/maca.h b/redbee-econotag/drivers/include/maca.h new file mode 100644 index 0000000000..3e8c26c15a --- /dev/null +++ b/redbee-econotag/drivers/include/maca.h @@ -0,0 +1,529 @@ +/* + * maca.h - The MACA driver for the Redbee EconoTag + * Copyright (C) 2013 Thomas Eichinger + * + * 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 MACA_H_ +#define MACA_H_ + +#include "maca_packet.h" +#include + +/*********************************************************/ +/* function definitions */ +/*********************************************************/ + +/* functions for the initialization and turning on and off of the MACA */ +void maca_init ( void ); +void maca_on ( void ); +void maca_off ( void ); + +/* function to check if MACA is running right */ +void maca_check ( void ); + +/* functions to configure MACA */ +void maca_set_power ( uint8_t power ); +void maca_set_channel ( uint8_t channel ); + +/* get Link Quality Indicator */ +//extern uint8_t (*get_lqi) ( void ); +uint8_t (*get_lqi)(void) = (void *) 0x0000e04d; + +/* interface to configure demodulator */ +#define MACA_DEMOD_DCD 1 /* -96dBm, 22.2mA */ +#define MACA_DEMOD_NCD 0 /* -100dBm, 24.2mA */ +void set_demodulator_type ( uint8_t type ); + +/* macro for setting checksum filtering */ +extern volatile uint8_t fcs_mode; +#define MACA_SET_FCS_MODE(x) fcs_mode = (x) + +/* MACA_SET_PRM_MODE(PROMISC) to disable address filtering */ +/* MACA_SET_PRM_MODE(AUTOACK) to enable address filtering AND autoack */ +extern volatile uint8_t prm_mode; +#define MACA_SET_PRM_MODE(x) prm_mode = (x) + +/* functions working on maca_packet_t */ +void maca_set_tx_packet ( volatile maca_packet_t *packet ); +volatile maca_packet_t* maca_get_rx_packet ( void ); +volatile maca_packet_t* maca_get_free_packet ( void ); +void maca_free_packet ( volatile maca_packet_t *packet ); +void maca_free_all_packets ( void ); + +extern volatile maca_packet_t *maca_rx_head, *maca_tx_head; +extern volatile uint32_t maca_entry; + +extern void maca_rx_callback ( volatile maca_packet_t *packet ) __attribute__((weak)); +extern void maca_tx_callback ( volatile maca_packet_t *packet ) __attribute__((weak)); + +/* internal lowlevel MACA functions */ +void _maca_reset ( void ); +void _maca_init_phy ( void ); +void _maca_flyback_init ( void ); +void _maca_resume_maca_sync ( void ); +void _maca_radio_init ( void ); +uint32_t _maca_init_from_flash ( uint32_t address ); + +#define MACA_MAX_PACKET_SIZE (MACA_MAX_PAYLOAD_SIZE + 2) /* +2 for checksum */ + +/*********************************************************/ +/* register definitions */ +/*********************************************************/ + +#define MACA_BASE_ADDRESS (0x80004000) + +struct MACA_struct { + union { + // Reset the MACA Module + uint32_t RESET; + struct MACA_RESET { + uint32_t RST:1; // MACA Reset + uint32_t CLK_ON:1; // MACA Clk on/off + uint32_t :30; + } RESETbits; + }; + union { + // Write: random generator seed + // Read: get random data + uint32_t RANDOM; + struct MACA_RANDOM { + uint32_t :32; + } RANDOMbits; + }; + union { + // Control register of the MACA + uint32_t CONTROL; + struct MACA_CONTROL { + uint32_t SEQUENCE :3; // set new mode of operation (see MACA_CONTROL_SEQUENCE_*) + uint32_t MODE :2; // transmission access mode (see MACA_CONTROL_MODE_*) + uint32_t TM :1; // test mode (see MACA_CONTROL_TM_*) + uint32_t :1; // LFSR reserved + uint32_t AUTO :1; // restart Rx automatically (see MACA_CONTROL_AUTO_*) + uint32_t BCN :1; // filter beacon only (see MACA_CONTROL_BCN_*) + uint32_t ASAP :1; // start action sequence ASAP (see MACA_CONTROL_ASAP_*) + uint32_t REL :1; // clk selector (see MACA_CONTROL_REL_*) + uint32_t PRM :1; // promiscuous mode (see MACA_CONTROL_PRM_*) + uint32_t NOFC :1; // no frame check (see MACA_CONTROL_NOFC_*) + uint32_t ROLE :1; // current role + uint32_t :1; // reserved + uint32_t RSTO :1; // reset slot offset (see MACA_CONTROL_RSTO_*) + uint32_t PRE_COUNT :4; // preamble repeat counter (btween 0-15) + uint32_t ISM :1; // ISM reserved + uint32_t :11; + } CONTROLbits; + }; + union { + uint32_t STATUS; + struct + { + uint32_t COMPLETE_CODE :4; // complete code (see MACA_STATUS_COMPLETECODE_*) + uint32_t :8; // reserved + uint32_t OVR :1; // Rx buffer overrun (see MACA_STATUS_OVR_*) + uint32_t BUSY :1; // channel busy detection (see MACA_STATUS_BUSY_*) + uint32_t CRC :1; // checksum failed (see MACA_STATUS_CRC_*) + uint32_t TO :1; // time-out (see MACA_STATUS_TO_*) + uint32_t :16; // reserved + } STATUSbits; + }; + union { + uint32_t FRMPND; + struct + { + uint32_t PND :1; // Ack Frame Pending Status (see MACA_FRMPND_PND_*) + uint32_t :31; // reserved + }FRMPNbits; + }; + union { + uint32_t MC1322x_ID; + struct + { + uint32_t MC1322x_ID :8; // the 9bit MC1322x ID (see MACA_MC1322x_ID_*) + uint32_t :24; // reserved + }MC1322x_IDbits; + }; + union { + uint32_t TMREN; + struct + { + uint32_t STRT :1; // enable start clk circuit (see MACA_TMREN_STRT_*) + uint32_t CPL :1; // enable complete clk circuit (see MACA_TMREN_CPL_*) + uint32_t SFT :1; // enable soft complete clk circ (see MACA_TMREN_SFT_*) + uint32_t :29; // reserved + }TMRENbits; + }; + union { + uint32_t TMRDIS; + struct + { + uint32_t STRT :1; // disable start clk circuit (see MACA_TMRDIS_STRT_*) + uint32_t CPL :1; // disable complete clk circuit (see MACA_TMRDIS_CPL_*) + uint32_t SFT :1; // disable soft complete clk circ (see MACA_TMRDIS_SFT_*) + uint32_t STRT_OFF :1; // abort start clk (see MACA_TMRDIS_STRTOFF_*) + uint32_t CPL_OFF :1; // abort complete clk (see MACA_TMRDIS_CPLOFF_*) + uint32_t SFT_OFF :1; // abort soft complete clk (see MACA_TMRDIS_SFT_OFF_*) + uint32_t :26; // reserved + }TMRDISbits; + }; + uint32_t CLK; // sets a new absolute clock value + // Ensure that the timers are not active + uint32_t STARTCLK; // see (9.7.10) + uint32_t CPLCLK; // see (9.7.11) + uint32_t SFTCLK; // see (9.7.12) + uint32_t CLKOFFSET; // see (9.7.13) + uint32_t RELCLK; // see (9.7.14) + uint32_t CPLTIM; // see (9.7.15) + union { + uint32_t SLOTOFFSET; // see (9.7.16) + struct + { + uint32_t TX_SLOT_OFFSET :12; + uint32_t :4; + uint32_t RX_SLOT_OFFSEt :12; + uint32_t :4; + }SLOTOFFSETbits; + }; + uint32_t TIMESTAMP; // see (9.7.17) + uint32_t DMARX; // see (9.7.18) + uint32_t DMATX; // see (9.7.19) + uint32_t DMAPOLL; // see (9.7.20) + union { + uint32_t TXLEN; // see (9.7.21) + struct + { + uint32_t TX_LEN :15; // Tx payload length + uint32_t :17; // reserved + }TXLENbits; + }; + union { + uint32_t TXSEQNR; // see (9.7.22) + struct + { + uint32_t TXSEQN :8; // Tx sequ. number + uint32_t :24; // reserved + }TXSEQNRbits; + }; + union { + uint32_t SETRXLVL; // see (9.7.23) + struct + { + uint32_t FIFO_LVL :16; // FIFO level + uint32_t :16; // reserved + }SETRXLVLbits; + }; + union { + uint32_t GETRXLVL; // see (9.7.24) + struct + { + uint32_t RECVBYTES :16; // received bytes + uint32_t :16; // reserved + }GETRXLVLbits; + }; + union { + uint32_t IRQ; // read only see (9.7.25) + struct + { + uint32_t ACPL :1; // Action Complete Interrupt + uint32_t POLL :1; // Poll Indication Interrupt + uint32_t DI :1; // Data Indication Interrupt + uint32_t :6; // reserved + uint32_t LVL :1; // FIFO Level Interrupt + uint32_t SFT :1; // Soft Complete Clk Interrupt + uint32_t FLT :1; // Filter Failed Interrupt + uint32_t CRC :1; // Checksum Failed Interrupt + uint32_t CM :1; // Complete Clock Interrupt + uint32_t SYNC :1; // Sync Detected Interrupt + uint32_t STRT :1; // Action Started Interrupt + uint32_t :16; // reserved + }IRQbits; + }; + union { + uint32_t CLRIRQ; // write only see (9.7.26) + // write 1 to clear + struct + { + uint32_t ACPL :1; // Clear Action Complete Interrupt + uint32_t POLL :1; // Clear Poll Indication Interrupt + uint32_t DI :1; // Clear Data Indication Interrupt + uint32_t :6; // reserved + uint32_t LVL :1; // Clear FIFO Level Interrupt + uint32_t SFT :1; // Clear Soft Complete Clk Interrupt + uint32_t FLT :1; // Clear Filter Failed Interrupt + uint32_t CRC :1; // Clear Checksum Failed Interrupt + uint32_t CM :1; // Clear Complete Clock Interrupt + uint32_t SYNC :1; // Clear Sync Detected Interrupt + uint32_t STRT :1; // Clear Action Started Interrupt + uint32_t :16; // reserved + }CLRIRQbits; + }; + union { + uint32_t SETIRQ; // write only see (9.7.27) + // write 1 to set IRQ + struct + { + uint32_t ACPL :1; // Trigger Action Complete Interrupt + uint32_t POLL :1; // Trigger Poll Indication Interrupt + uint32_t DI :1; // Trigger Data Indication Interrupt + uint32_t :6; // reserved + uint32_t LVL :1; // Trigger FIFO Level Interrupt + uint32_t SFT :1; // Trigger Soft Complete Clk Interrupt + uint32_t FLT :1; // Trigger Filter Failed Interrupt + uint32_t CRC :1; // Trigger Checksum Failed Interrupt + uint32_t CM :1; // Trigger Complete Clock Interrupt + uint32_t SYNC :1; // Trigger Sync Detected Interrupt + uint32_t STRT :1; // Trigger Action Started Interrupt + uint32_t :16; // reserved + }SETIRQbits; + }; + union { + uint32_t MASKIRQ; // write only see (9.7.28) + // write 1 to enable IRQ + struct + { + uint32_t ACPL :1; // Enable Action Complete Interrupt + uint32_t POLL :1; // Enable Poll Indication Interrupt + uint32_t DI :1; // Enable Data Indication Interrupt + uint32_t WU :1; // reserved but needed?? + uint32_t RST :1; // reserved but needed?? + uint32_t :4; // reserved + uint32_t LVL :1; // Enable FIFO Level Interrupt + uint32_t SFT :1; // Enable Soft Complete Clk Interrupt + uint32_t FLT :1; // Enable Filter Failed Interrupt + uint32_t CRC :1; // Enable Checksum Failed Interrupt + uint32_t CM :1; // Enable Complete Clock Interrupt + uint32_t SYNC :1; // Enable Sync Detected Interrupt + uint32_t STRT :1; // Enable Action Started Interrupt + uint32_t :16; // reserved + }MASKIRQbits; + }; + union { + uint32_t MACPANID; // see (9.7.29) + struct + { + uint32_t PANID :16; // MAC PAN ID for the 802.15.4 std network + } MACPANIDbits; + }; + union { + uint32_t MAC16ADDR; // see (9.7.30) + struct + { + uint32_t ADDR :16; // reflects the MAC short address + } MAC16ADDRbits; + }; + uint32_t MAC64HI; // see (9.7.31) + uint32_t MAC64LO; // see (9.7.32) + union { + uint32_t FLTREJ; // see (9.7.33) + struct + { + uint32_t BCN :1; // Reject Beacon packets + uint32_t DATA :1; // Reject Data packets + uint32_t ACK :1; // Reject ACK packets + uint32_t CMD :1; // Reject MAC CMD packets + uint32_t :4; // reserved + uint32_t POLL :1; // Accept POLL packets + uint32_t :7; // reserved + uint32_t FC_MASK :16; // Frame Control Mask + }FLTREJbits; + }; + union { + uint32_t CLKDIV; // see (9.7.34) + struct + { + uint32_t Divider :16; // prescale value for the MACA transmit clk + uint32_t :16; // reserved + }CLKDIVbits; + }; + union { + uint32_t WARMUP; // see (9.7.35) + struct + { + uint32_t Rx_WARMUP :12; // receiver warmup time + uint32_t :4; // reserved + uint32_t Tx_WARMUP :12; // transmitter warmuptime + uint32_t :4; // reserved + }WARMUPbits; + }; + uint32_t PREAMBLE; // see (9.7.36) + uint32_t FRAMESYNC0; // see (9.7.37) + uint32_t FRAMESYNC1; // see (9.7.38) + union { + uint32_t TXACKDELAY; // see (9.7.39) + struct + { + uint32_t TXACKDELAY :12; // Tx Acknowledgement Delay + uint32_t :4; // reserved + uint32_t TXPOLLDELAY :12; // Tx Poll Delay + uint32_t :4; // reserved + }TXACKDELAYbits; + }; + union { + uint32_t RXACKDELAY; // see (9.7.40) + struct + { + uint32_t RXACKDELAY :12; // Rx Acknowledgement Delay + uint32_t :4; // reserved + uint32_t RXAUTODELAY :12; // time to disable receiver before restarting + uint32_t :4; // reserved + }RXACKDELAYbits; + }; + union { + uint32_t EOFDELAY; // see (9.7.41) + struct + { + uint32_t EOFDELAY :12; // End Of Frame Delay + uint32_t :20; // reserved + }EOFDELAYbits; + }; + union { + uint32_t CCADELAY; // see (9.7.42) + struct + { + uint32_t CCADELAY :12; // CCA Delay + uint32_t :4; // reserved + uint32_t CCALENGTH :12; // Length of time to perform CCA + uint32_t :4; // reserved + }CCADELAYbits; + }; + union { + uint32_t RXEND; // see (9.7.43) + struct + { + uint32_t RXACK_END :12; // Rx Acknowledgement Window End in Normal Mode + uint32_t :4; // reserved + uint32_t RXSLOTTED_END :12; // Rx Acknowledgement Window End in slotted CSMA-CA mode + uint32_t :4; // reserved + }RXENDbits; + }; + union { + uint32_t TXCCADELAY; // see (9.7.44) + struct + { + uint32_t TXCCADELAY :12; // Delay from end of CCA to Tx start + uint32_t :20; // reserved + }RXENDbits; + }; + uint32_t KEY3; // see (9.7.45) + uint32_t KEY2; // see (9.7.45) + uint32_t KEY1; // see (9.7.45) + uint32_t KEY0; // see (9.7.45) + union { + uint32_t OPTIONS; // see (9.7.46) + struct + { + uint32_t POLL :1; // enables writing to DMAPOLL + uint32_t PLL_TX :1; // responde to PLL unlock only while transmition + uint32_t PLL_IGNORE :1; // ignore PLL unlock signal + uint32_t SEED_KEY :1; // generation can be seeded + uint32_t :28; // reserved + }OPTIONSbits; + }; + +}; + +static volatile struct MACA_struct * const MACA = (void *) (MACA_BASE_ADDRESS + 0x04); // +4 because base + 0x00 is reserved + +#define MACA_CONTROL_SEQUENCE_NOP 0 +#define MACA_CONTROL_SEQUENCE_ABORT 1 +#define MACA_CONTROL_SEQUENCE_WAIT 2 +#define MACA_CONTROL_SEQUENCE_TX 3 +#define MACA_CONTROL_SEQUENCE_RX 4 +#define MACA_CONTROL_SEQUENCE_TXPOLL 5 +#define MACA_CONTROL_SEQUENCE_CCA 6 +#define MACA_CONTROL_SEQUENCE_ED 7 + +#define MACA_CONTROL_MODE_NOCCA 0 +#define MACA_CONTROL_MODE_NONSLOTTED_CSMACA 1 +#define MACA_CONTROL_MODE_SLOTTED_CSMACA 2 +#define MACA_CONTROL_MODE_RESERVED 3 + +#define MACA_CONTROL_TM_NORMAL 0 +#define MACA_CONTROL_TM_TM 1 + +#define MACA_CONTROL_AUTO_OFF 0 +#define MACA_CONTROL_AUTO_ON 1 + +#define MACA_CONTROL_BCN_OFF 0 +#define MACA_CONTROL_BCN_ON 1 + +#define MACA_CONTROL_ASAP_OFF 0 +#define MACA_CONTROL_ASAP_ON 1 + +#define MACA_CONTROL_REL_ABSOLUTE 0 +#define MACA_CONTROL_REL_RELATIVE 1 + +#define MACA_CONTROL_PRM_OFF 0 +#define MACA_CONTROL_PRM_ON 1 + +#define MACA_CONTROL_NOFC_OFF 0 +#define MACA_CONTROL_USE_FCS 0 +#define MACA_CONTROL_NOFC_ON 1 +#define MACA_CONTROL_NO_FCS 1 + +#define MACA_CONTROL_ROLE_NOPAN 0 +#define MACA_CONTROL_ROLE_PAN 1 + +#define MACA_CONTROL_RSTO_DONOT_RST 0 +#define MACA_CONTROL_RSTO_DO_RST 1 + +#define MACA_STATUS_COMPLETECODE_SUCCESS 0 +#define MACA_STATUS_COMPLETECODE_TIMEOUT 1 +#define MACA_STATUS_COMPLETECODE_CHANBUSY 2 +#define MACA_STATUS_COMPLETECODE_CRC_FAIL 3 +#define MACA_STATUS_COMPLETECODE_ABORTED 4 +#define MACA_STATUS_COMPLETECODE_NOACK 5 +#define MACA_STATUS_COMPLETECODE_NODATA 6 +#define MACA_STATUS_COMPLETECODE_LATESTART 7 +#define MACA_STATUS_COMPLETECODE_EXTTIMEOUT 8 +#define MACA_STATUS_COMPLETECODE_EXTPNDTIMEOUT 9 +#define MACA_STATUS_COMPLETECODE_PLLUNLOCK 12 +#define MACA_STATUS_COMPLETECODE_EXTABORT 13 +#define MACA_STATUS_COMPLETECODE_NOTCOMPLETE 14 +#define MACA_STATUS_COMPLETECODE_DMABUSERROR 15 + +#define MACA_STATUS_OVR_FALSE 0 +#define MACA_STATUS_OVR_TRUE 1 + +#define MACA_STATUS_BUSY_FALSE 0 +#define MACA_STATUS_BUSY_TRUE 1 + +#define MACA_STATUS_CRC_OK 0 +#define MACA_STATUS_CRC_ERROR 1 + +#define MACA_STATUS_TO_FALSE 0 +#define MACA_STATUS_TO_TRUE 1 + +#define MACA_FRMPND_PND_NODATA 0 +#define MACA_FRMPND_PND_DATAAVAIL 1 + +#define MACA_MC1322x_ID_ENGINEERING 0 +#define MACA_MC1322x_ID_MC13224_1 1 +#define MACA_MC1322x_ID_MC13224_2 9 +#define MACA_MC1322x_ID_MC13226 17 + + +#define MACA_TMREN_STRT_ENABLE 1 + +#define MACA_TMREN_CPL_ENABLE 1 + +#define MACA_TMREN_SFT_ENABLE 1 + +#define MACA_TMRDIS_STRT_DISABLE 1 + +#define MACA_TMRDIS_CPL_DISABLE 1 + +#define MACA_TMRDIS_SFT_DISABLE 1 + +#define MACA_TMRDIS_STRTOFF_ABORT 1 + +#define MACA_TMRDIS_CPLOFF_ABORT 1 + +#define MACA_TMRDIS_SFTOFF_ABORT 1 + + + +#endif // MACA_H_ \ No newline at end of file diff --git a/redbee-econotag/drivers/include/maca_packet.h b/redbee-econotag/drivers/include/maca_packet.h new file mode 100644 index 0000000000..11c4c1b0f7 --- /dev/null +++ b/redbee-econotag/drivers/include/maca_packet.h @@ -0,0 +1,44 @@ +/* + * maca_packet.h - defines a rxtx packet for the MACA driver + * Copyright (C) 2013 Thomas Eichinger + * + * 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 PACKET_H +#define PACKET_H + +#include + +/* does not include 2 byte FCS checksum */ +#ifndef MACA_MAX_PAYLOAD_SIZE +#define MACA_MAX_PAYLOAD_SIZE 125 +#endif + +#define PACKET_STATS 0 + +struct packet { + uint8_t length; /*< does not include FCS checksum */ + volatile struct packet * left; + volatile struct packet * right; + /* offset into data for first byte of the packet payload */ + /* On TX this should be 0 */ + /* On RX this should be 1 since the maca puts the length as the first byte*/ + uint8_t offset; + uint8_t lqi; + uint8_t status; + uint32_t rx_time; + #if PACKET_STATS + uint8_t seen; + uint8_t post_tx; + uint8_t get_free; + uint8_t rxd; + #endif + uint8_t data[MACA_MAX_PAYLOAD_SIZE+2+1]; /* +2 for FCS; + 1 since maca returns the length as the first byte */ +}; +typedef struct packet maca_packet_t; + +#endif \ No newline at end of file diff --git a/redbee-econotag/drivers/maca.c b/redbee-econotag/drivers/maca.c new file mode 100644 index 0000000000..3283d37b2d --- /dev/null +++ b/redbee-econotag/drivers/maca.c @@ -0,0 +1,1041 @@ +/* + * maca.c - The MACA driver for the Redbee EconoTag + * Copyright (C) 2013 Thomas Eichinger + * + * 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 "maca.h" +#include "maca_packet.h" +#include "nvm.h" +#include "mc1322x.h" +#include + +// number of packets in the maca_packet_pool +#ifndef MACA_NUM_PACKETS +#define MACA_NUM_PACKETS 32 +#endif + +/* for 250kHz clock */ +#define MACA_CLOCK_DIV 95 +/* (32 chips/sym) * (sym/4bits) * (8bits/byte) = (64 chips/byte) */ +/* (8 chips/clk) * (byte/64 chips) = byte/8clks */ +#define CLK_PER_BYTE 8 + +#ifndef RECV_SOFTIMEOUT +#define RECV_SOFTIMEOUT (1024*128*CLK_PER_BYTE) +#endif + +#ifndef CPL_TIMEOUT +#define CPL_TIMEOUT (2*128*CLK_PER_BYTE) +#endif + + + +static volatile maca_packet_t maca_packet_pool[MACA_NUM_PACKETS]; + +static volatile maca_packet_t *maca_free_head; +static volatile maca_packet_t *maca_rx_end; +static volatile maca_packet_t *maca_tx_end; +static volatile maca_packet_t *maca_dma_tx; +static volatile maca_packet_t *maca_dma_rx; + +volatile maca_packet_t *maca_rx_head; +volatile maca_packet_t *maca_tx_head; + +static volatile maca_packet_t maca_dummy_ack; + +#define MACA_NO_POST 0 +#define MACA_TX_POST 1 +#define MACA_RX_POST 2 +#define MACA_MAX_POST 3 +static volatile uint8_t maca_last_post = MACA_NO_POST; + +void maca_init ( void ) { + _maca_reset(); + _maca_radio_init(); + _maca_flyback_init(); + _maca_init_phy(); + maca_set_channel ( 0 ); + maca_set_power ( 0 ); + + maca_free_head = 0; + maca_tx_head = 0; + maca_rx_head = 0; + maca_rx_end = 0; + maca_tx_end = 0; + maca_dma_rx = 0; + maca_dma_tx = 0; + + maca_free_all_packets(); + + // promiscuous, no CCA + MACA->CONTROLbits.PRM = MACA_CONTROL_PRM_ON; + MACA->CONTROLbits.MODE = MACA_CONTROL_MODE_NOCCA; + + enable_irq ( INT_NUM_MACA ); + ITC->INTFRCbits.MACA = 1; +} + +void _maca_reset ( void ) { + volatile uint32_t c; + + MACA->RESETbits.RST = 1; + + for ( c = 0; c < 100; c++ ) { + continue; + } + + MACA->RESETbits.CLK_ON = 1; + MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_NOP; + + for ( c = 0; c < 400000; c++ ) { + continue; + } + + // clear all interrupts + MACA->CLRIRQ = 0xffff; +} + +void maca_on ( void ) { + + // turn on the radio regulators + CRM->VREG_CNTLbits.BUCK_EN = 0x0; + CRM->VREG_CNTLbits.BUCK_SYNC_REC_EN = 0x0; + CRM->VREG_CNTLbits.BUCK_BYPASS_EN = 0x0; + CRM->VREG_CNTLbits.VREG_1P5V_EN = 0x3; + CRM->VREG_CNTLbits.VREG_1P5V_SEL = 0x3; + CRM->VREG_CNTLbits.VREG_1P8V_EN = 0x0; + CRM->VREG_CNTLbits.BUCK_CLKDIV = 0xf; + + // reinitialize phy + _maca_reset(); + _maca_init_phy(); + + enable_irq ( INT_NUM_MACA ); + ITC->INTFRCbits.MACA = 0x1; +} + +void maca_off ( void ) { + disable_irq ( INT_NUM_MACA ); + + // turn off radio regulators + CRM->VREG_CNTL = 0x00000f00; + + MACA->RESETbits.RST = 0x1; +} + +void maca_free_all_packets ( void ) { + volatile uint32_t i; + safe_irq_disable ( INT_NUM_MACA ); + + maca_free_head = 0; + + for ( i = 0; i < MACA_NUM_PACKETS; i++ ) { + maca_free_packet ( ( volatile maca_packet_t * ) & ( maca_packet_pool[i] ) ); + } + + maca_rx_head = 0; + maca_rx_end = 0; + maca_tx_head = 0; + maca_tx_end = 0; + + irq_restore(); + + // force MACA interrupt if there are pending irqs + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 0x1; + } +} + +void _maca_bound_check ( volatile maca_packet_t *packet ) { + volatile uint32_t i; + + if ( !packet || packet == &maca_dummy_ack ) { + return; + } + + for ( i = 0; i < MACA_NUM_PACKETS; i++ ) { + if ( packet == &maca_packet_pool[i] ) { + return; + } + } + + // bad packet bounds! next, nirvana... + printf ( "bad packet bounds! Halting... \n" ); + + while ( 1 ) { + continue; + } +} + +void maca_free_packet ( volatile maca_packet_t *packet ) { + safe_irq_disable ( INT_NUM_MACA ); + + // _maca_bound_check( packet ); + + if ( !packet || packet == &maca_dummy_ack ) { + return; + } + + // _maca_bound_check( maca_free_head ); + + packet->length = 0; + packet->offset = 0; + packet->left = maca_free_head; + packet->right = 0; + + maca_free_head = packet; + + // _maca_bound_check( maca_free_head ); + + irq_restore(); + + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 0x1; + } +} + +volatile maca_packet_t *maca_get_free_packet ( void ) { + volatile maca_packet_t *packet; + + safe_irq_disable ( INT_NUM_MACA ); + // _maca_bound_check( maca_free_head ); + + packet = maca_free_head; + + if ( packet ) { + maca_free_head = packet->left; + maca_free_head->right = 0; + } + + // _maca_bound_check( maca_free_head ); + + irq_restore(); + + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 0x1; + } + + return packet; +} + +volatile maca_packet_t *maca_get_rx_packet ( void ) { + volatile maca_packet_t *packet; + safe_irq_disable ( INT_NUM_MACA ); + + // maca_bound_check ( maca_rx_head ); + + packet = maca_rx_head; + + if ( packet ) { + maca_rx_head = packet->left; + maca_rx_head->right = 0; + } + + irq_restore (); + + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 0x1; + } + + return packet; +} + +void maca_set_tx_packet ( volatile maca_packet_t *packet ) { + safe_irq_disable ( INT_NUM_MACA ); + + // maca_bound_check ( packet ); + + if ( !packet ) { + return; + } + + if ( !maca_tx_head ) { + // start a new queue + maca_tx_end = packet; + maca_tx_end->left = 0; + maca_tx_end->right = 0; + maca_tx_head = maca_tx_end; + } + else { + // add packet to the end of the queue + maca_tx_end->left = packet; + packet->right = maca_tx_end; + // move the queue + maca_tx_end = packet; + maca_tx_end->left = 0; + } + + irq_restore (); + + if ( ITC->NIPENDbits.MACA || maca_last_post == MACA_NO_POST ) { + ITC->INTFRCbits.MACA = 0x1; + } + + if ( maca_last_post == MACA_RX_POST ) { + MACA->SFTCLK = MACA->CLK + CLK_PER_BYTE; + } + + return; +} + +void _maca_post_receive ( void ) { + maca_last_post = MACA_RX_POST; + + // from the libmc1322x implementation: + // "this sets the rxlen field + // this is undocumented but very important + // you will not receive anything without setting it" + MACA->TXLEN = ( MACA_MAX_PACKET_SIZE<<16 ); + + if ( !maca_dma_rx ) { + maca_dma_rx = maca_get_free_packet (); + + if ( !maca_dma_rx ) { + MACA->SFTCLK = MACA->CLK + RECV_SOFTIMEOUT; + MACA->TMRENbits.SFT = 0x1; + + // no free buffers, so don't start reception + enable_irq ( INT_NUM_MACA ); + return; + } + } + + // maca_bound_check ( maca_dma_rx ); + // maca_bound_check ( maca_dma_tx ); + + // load starting addess + MACA->DMARX = ( uint32_t ) & ( maca_dma_rx->data[0] ); + // wind up a timer for timeout + MACA->SFTCLK = MACA->CLK + RECV_SOFTIMEOUT; + // enable the soft complete clk circuit + MACA->TMRENbits.SFT = 0x1; + // start the receive sequence + MACA->CONTROLbits.ASAP = MACA_CONTROL_ASAP_ON; + MACA->CONTROLbits.PRE_COUNT = 0x4; + MACA->CONTROLbits.NOFC = MACA_CONTROL_NOFC_OFF; // aka use FCS + MACA->CONTROLbits.PRM = MACA_CONTROL_PRM_ON; + MACA->CONTROLbits.AUTO = MACA_CONTROL_AUTO_ON; + MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_RX; +} + +void _maca_post_transmit ( void ) { + safe_irq_disable ( INT_NUM_MACA ); + + maca_last_post = MACA_TX_POST; + maca_dma_tx = maca_tx_head; + + MACA->TXSEQNRbits.TXSEQN = maca_dma_tx->data[2]; + MACA->TXLENbits.TX_LEN = ( uint16_t ) ( ( maca_dma_tx->length ) + 2 ); + // set rx length to ACK length + MACA->TXLEN = ( uint32_t ) ( 3<<16 ); + // load data starting address + MACA->DMATX = ( uint32_t ) & ( maca_dma_tx->data[0 + maca_dma_tx->offset] ); + + if ( !maca_dma_rx ) { + maca_dma_rx = maca_get_free_packet(); + + if ( !maca_dma_rx ) { + printf ( "tried to fill MACA->DMARX in maca_post_tx but there are no packet buffers left" ); + maca_dma_rx = &maca_dummy_ack; + } + } + + // maca_bound_check ( maca_dma_rx ); + // maca_bound_check ( maca_dma_tx ); + + MACA->DMARX = ( uint32_t ) & ( maca_dma_rx->data[0] ); + + // disable soft timeout clk and start clk + MACA->TMRDISbits.SFT = MACA_TMRDIS_SFT_DISABLE; + MACA->TMRDISbits.CPL = MACA_TMRDIS_CPL_DISABLE; + + // set cpl clk to a long range and enable it + // for the case MACA locks + MACA->CPLCLK = MACA->CLK + CPL_TIMEOUT; + MACA->TMRENbits.CPL = 0x1; + + irq_restore (); + + MACA->CONTROLbits.ASAP = MACA_CONTROL_ASAP_ON; + MACA->CONTROLbits.PRE_COUNT = 0x4; + MACA->CONTROLbits.PRM = MACA_CONTROL_PRM_ON; + MACA->CONTROLbits.MODE = MACA_CONTROL_MODE_NOCCA; + MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_TX; + +} + +void _maca_free_tx_head ( void ) { + volatile maca_packet_t *packet; + safe_irq_disable ( INT_NUM_MACA ); + + packet = maca_tx_head; + maca_tx_head = maca_tx_head->left; + + if ( maca_tx_head == 0 ) { + maca_tx_end = 0; + } + + maca_free_packet ( packet ); + + irq_restore (); + + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 1; + } + + return; +} + +void _maca_add_to_rx ( volatile maca_packet_t *packet ) { + safe_irq_disable ( INT_NUM_MACA ); + + if ( !packet ) { + printf ( "packet null passed to _maca_add_to_rx\n" ); + return; + } + + packet->offset = 1; // first byte is the length + + if ( maca_rx_head == 0 ) { + // start a new queue + maca_rx_end = packet; + maca_rx_end->left = 0; + maca_rx_end->right = 0; + maca_rx_head = maca_rx_end; + } + else { + // enqueue packet + maca_rx_end->left = packet; + packet->right = maca_rx_end; + maca_rx_end = packet; + maca_rx_end->left = 0; + } + + irq_restore(); + + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 1; + } + + return; +} + +void _maca_decode_status ( void ) { + volatile uint32_t code; + + code = MACA->STATUSbits.COMPLETE_CODE; + + switch ( code ) { + case MACA_STATUS_COMPLETECODE_ABORTED: { + printf ( "maca: aborted\n" ); + _maca_resume_maca_sync (); + break; + } + + case MACA_STATUS_COMPLETECODE_NOTCOMPLETE: { + printf ( "maca: not completed\n" ); + _maca_resume_maca_sync (); + break; + } + + case MACA_STATUS_COMPLETECODE_TIMEOUT: { + printf ( "maca: timeout\n" ); + _maca_resume_maca_sync (); + break; + } + + case MACA_STATUS_COMPLETECODE_NOACK: { + printf ( "maca: no ack\n" ); + _maca_resume_maca_sync (); + break; + } + + case MACA_STATUS_COMPLETECODE_EXTTIMEOUT: { + printf ( "maca: ext timeout\n" ); + _maca_resume_maca_sync (); + break; + } + + case MACA_STATUS_COMPLETECODE_EXTPNDTIMEOUT: { + printf ( "maca: ext pnd timeout\n" ); + _maca_resume_maca_sync (); + break; + } + case MACA_STATUS_COMPLETECODE_SUCCESS: { + printf ( "maca: success\n" ); + _maca_resume_maca_sync (); + break; + } + + default: { + printf ( "maca status: %x", MACA->STATUSbits.COMPLETE_CODE ); + _maca_resume_maca_sync (); + } + } +} + +void maca_isr ( void ) { + maca_entry++; + + if ( MACA->STATUSbits.OVR ) { + printf ( "maca overrun\n" ); + } + + if ( MACA->STATUSbits.BUSY ) { + printf ( "maca busy\n" ); + } + + if ( MACA->STATUSbits.CRC ) { + printf ( "maca crc error\n" ); + } + + if ( MACA->STATUSbits.TO ) { + printf ( "maca timeout\n" ); + } + + if ( MACA->IRQbits.DI ) { + MACA->CLRIRQbits.DI = 0x1; + maca_dma_rx->length = MACA->GETRXLVLbits.RECVBYTES - 2; // packet length doesn't include length + maca_dma_rx->lqi = get_lqi(); + maca_dma_rx->rx_time = MACA->TIMESTAMP; + + // does the packet need an ACK? + if ( MACA->CONTROLbits.PRM == MACA_CONTROL_PRM_OFF && + ( maca_dma_rx->data[1] & 0x20 ) ) { + volatile uint32_t wait_clk; + wait_clk = MACA->CLK + 200; + + while ( MACA->CLK < wait_clk ) { + continue; + } + } + + if ( maca_rx_callback != 0 ) { + maca_rx_callback ( maca_dma_rx ); + } + + _maca_add_to_rx ( maca_dma_rx ); + maca_dma_rx = 0; + } + + // filter faild + if ( MACA->IRQbits.FLT ) { + printf ( "maca filter faild\n" ); + _maca_resume_maca_sync (); + MACA->CLRIRQbits.FLT = 0x1; + } + + // CRC checksum faild + if ( MACA->IRQbits.CRC ) { + printf ( "maca crc checksum faild\n" ); + _maca_resume_maca_sync (); + MACA->CLRIRQbits.CRC = 0x1; + } + + // softclock interrupt + if ( MACA->IRQbits.SFT ) { + MACA->CLRIRQbits.SFT = 0x1; + } + + // poll interrupt + if ( MACA->IRQbits.POLL ) { + MACA->CLRIRQbits.POLL = 0x1; + } + + // action complete interrupt + if ( MACA->IRQbits.ACPL ) { + if ( maca_last_post == MACA_TX_POST ) { + maca_tx_head->status == MACA->STATUSbits.COMPLETE_CODE; + + if ( maca_tx_callback != 0 ) { + maca_tx_callback ( maca_tx_head ); + } + + maca_dma_tx = 0x0; + _maca_free_tx_head (); + maca_last_post = MACA_NO_POST; + } + + _maca_resume_maca_sync (); + MACA->CLRIRQbits.ACPL = 0x1; + } + + _maca_decode_status (); + + // this should never happen ... + if ( MACA->IRQ != 0 ) { + printf ( "MACA->IRQ is %x", MACA->IRQ ); + } + + if ( maca_tx_head != 0 ) { + _maca_post_transmit (); + } + else { + _maca_post_receive (); + } +} + +void _maca_init_phy ( void ) { + MACA->CLKDIV = MACA_CLOCK_DIV; + MACA->WARMUP = 0x00180012; + MACA->EOFDELAY = 0x00000004; + MACA->CCADELAY = 0x001a0022; + MACA->TXCCADELAY = 0x00000025; + MACA->FRAMESYNC0 = 0x000000a7; + MACA->CLK = 0x00000008; + MACA->RXACKDELAY = 0x0000001e; + MACA->RXEND = 0x000000b4; + MACA->TXACKDELAY = 0x00000044; + MACA->MASKIRQbits.ACPL = 0x1; + MACA->MASKIRQbits.CM = 0x1; + MACA->MASKIRQbits.FLT = 0x1; + MACA->MASKIRQbits.CRC = 0x1; + MACA->MASKIRQbits.DI = 0x1; + MACA->MASKIRQbits.SFT = 0x1; + MACA->MASKIRQbits.RST = 0x1; + MACA->SLOTOFFSET = 0x00350000; +} + +#define MTOC_BASE 0x80009a00 //Modem Tracking Oscillator Controller +void _flyback_init ( void ) { + uint32_t val8, tmp; + + val8 = * ( volatile uint32_t * ) ( MTOC_BASE+8 ); + tmp = val8 | 0x0000f7df; + * ( volatile uint32_t * ) ( MTOC_BASE+8 ) = tmp; + * ( volatile uint32_t * ) ( MTOC_BASE+12 ) = 0x00ffffff; + * ( volatile uint32_t * ) ( MTOC_BASE+16 ) = ( ( ( uint32_t ) 0x00ffffff ) >>12 ); + * ( volatile uint32_t * ) ( MTOC_BASE ) = 16; +} + +#define MACA_MAX_SEQ_1 2 +const uint32_t maca_addr_seq_1[MACA_MAX_SEQ_1] = { + 0x80003048, + 0x8000304c, +}; + +const uint32_t maca_data_seq_1[MACA_MAX_SEQ_1] = { + 0x00000f78, + 0x00607707, +}; + + +#define MACA_MAX_SEQ_2 2 +const uint32_t maca_addr_seq_2[MACA_MAX_SEQ_2] = { + 0x8000a050, + 0x8000a054, +}; + +const uint32_t maca_data_seq_2[MACA_MAX_SEQ_2] = { + 0x0000047b, + 0x0000007b, +}; + +#define MACA_MAX_CAL3_SEQ_1 3 +const uint32_t maca_addr_cal3_seq_1[MACA_MAX_CAL3_SEQ_1] = { 0x80009400,0x80009a04,0x80009a00, }; +const uint32_t maca_data_cal3_seq_1[MACA_MAX_CAL3_SEQ_1] = {0x00020017,0x8185a0a4,0x8c900025, }; + +#define MACA_MAX_CAL3_SEQ_2 2 +const uint32_t maca_addr_cal3_seq_2[MACA_MAX_CAL3_SEQ_2] = { 0x80009a00,0x80009a00,}; +const uint32_t maca_data_cal3_seq_2[MACA_MAX_CAL3_SEQ_2] = { 0x8c900021,0x8c900027,}; + +#define MACA_MAX_CAL3_SEQ_3 1 +const uint32_t maca_addr_cal3_seq_3[MACA_MAX_CAL3_SEQ_3] = { 0x80009a00 }; +const uint32_t maca_data_cal3_seq_3[MACA_MAX_CAL3_SEQ_3] = { 0x8c900000 }; + +#define MACA_MAX_CAL5 4 +const uint32_t maca_addr_cal5[MACA_MAX_CAL5] = { + 0x80009400, + 0x8000a050, + 0x8000a054, + 0x80003048, +}; +const uint32_t maca_data_cal5[MACA_MAX_CAL5] = { + 0x00000017, + 0x00000000, + 0x00000000, + 0x00000f00, +}; + +#define MACA_MAX_DATA 43 +const uint32_t maca_addr_reg_rep[MACA_MAX_DATA] = { + 0x80004118,0x80009204,0x80009208,0x8000920c, + 0x80009210,0x80009300,0x80009304,0x80009308, + 0x8000930c,0x80009310,0x80009314,0x80009318, + 0x80009380,0x80009384,0x80009388,0x8000938c, + 0x80009390,0x80009394,0x8000a008,0x8000a018, + 0x8000a01c,0x80009424,0x80009434,0x80009438, + 0x8000943c,0x80009440,0x80009444,0x80009448, + 0x8000944c,0x80009450,0x80009460,0x80009464, + 0x8000947c,0x800094e0,0x800094e4,0x800094e8, + 0x800094ec,0x800094f0,0x800094f4,0x800094f8, + 0x80009470,0x8000981c,0x80009828 +}; + +const uint32_t maca_data_reg_rep[MACA_MAX_DATA] = { + 0x00180012,0x00000605,0x00000504,0x00001111, + 0x0fc40000,0x20046000,0x4005580c,0x40075801, + 0x4005d801,0x5a45d800,0x4a45d800,0x40044000, + 0x00106000,0x00083806,0x00093807,0x0009b804, + 0x000db800,0x00093802,0x00000015,0x00000002, + 0x0000000f,0x0000aaa0,0x01002020,0x016800fe, + 0x8e578248,0x000000dd,0x00000946,0x0000035a, + 0x00100010,0x00000515,0x00397feb,0x00180358, + 0x00000455,0x00000001,0x00020003,0x00040014, + 0x00240034,0x00440144,0x02440344,0x04440544, + 0x0ee7fc00,0x00000082,0x0000002a +}; + +uint8_t ctov[16] = { + 0x0b,0x0b,0x0b,0x0a, + 0x0d,0x0d,0x0c,0x0c, + 0x0f,0x0e,0x0e,0x0e, + 0x11,0x10,0x10,0x0f +}; + +#define _INIT_CTOV_WORD_1 0x00dfbe77 +#define _INIT_CTOV_WORD_2 0x023126e9 +uint8_t get_ctov ( uint32_t r0, uint32_t r1 ) { + r0 = r0 * _INIT_CTOV_WORD_1; + r0 += ( r1 << 22 ); + r0 += _INIT_CTOV_WORD_2; + + r0 = ( uint32_t ) ( ( ( int32_t ) r0 ) >>25 ); + return ( uint8_t ) r0; +} + +static uint8_t _ram_values[4]; + +void _maca_radio_init ( void ) { + volatile uint32_t c; + + // sequence 1 + for ( c = 0; c < MACA_MAX_SEQ_1; c++ ) { + if ( ( uint32_t ) maca_addr_seq_1[c] != CRM->VREG_CNTL ) { + * ( ( volatile uint32_t * ) ( maca_addr_seq_1[c] ) ) = maca_data_seq_1[c]; + } + } + + // sequence 1 delay + for ( c = 0; c < 0x161a8; c++ ) { + continue; + } + + // sequence 2 + for ( c = 0; c < MACA_MAX_SEQ_2; c++ ) { + * ( ( volatile uint32_t * ) ( maca_addr_seq_2[c] ) ) = maca_data_seq_2[c]; + } + + // modem value + * ( ( volatile uint32_t * ) 0x80009000 ) = 0x80050100; + + // cal 3 seq 1 + for ( c = 0; c < MACA_MAX_CAL3_SEQ_1; c++ ) { + * ( ( volatile uint32_t * ) ( maca_addr_cal3_seq_1[c] ) ) = maca_data_cal3_seq_1[c]; + } + + // cal 3 delay + for ( c = 0; c < 0x11194; c++ ) { + continue; + } + + // cal 3 seq 2 + for ( c = 0; c < MACA_MAX_CAL3_SEQ_2; c++ ) { + * ( ( volatile uint32_t * ) ( maca_addr_cal3_seq_2[c] ) ) = maca_data_cal3_seq_2[c]; + } + + // cal 3 delay + for ( c = 0; c < 0x11194; c++ ) { + continue; + } + + // cal 3 seq 3 + for ( c = 0; c < MACA_MAX_CAL3_SEQ_3; c++ ) { + * ( ( volatile uint32_t * ) ( maca_addr_cal3_seq_3[c] ) ) = maca_data_cal3_seq_3[c]; + } + + // cal 5 + for ( c = 0; c < MACA_MAX_CAL5; c++ ) { + if ( ( uint32_t ) maca_addr_cal5[c] != CRM->VREG_CNTL ) { + * ( ( volatile uint32_t * ) ( maca_addr_cal5[c] ) ) = maca_data_cal5[c]; + } + } + + /*reg replacment */ + for ( c = 0; c < MACA_MAX_DATA; c++ ) { + * ( ( volatile uint32_t * ) ( maca_addr_reg_rep[c] ) ) = maca_data_reg_rep[c]; + } + + _maca_init_from_flash ( 0x1f000 ); + + for ( c=0; c<4; c++ ) { + printf ( " 0x%02x\n\r", _ram_values[c] ); + } + + for ( c=0; c<16; c++ ) { + ctov[c] = get_ctov ( c, _ram_values[3] ); + } +} + +const uint32_t PSMVAL[19] = { + 0x0000080f, 0x0000080f, 0x0000080f, + 0x0000080f, 0x0000081f, 0x0000081f, + 0x0000081f, 0x0000080f, 0x0000080f, + 0x0000080f, 0x0000001f, 0x0000000f, + 0x0000000f, 0x00000816, 0x0000001b, + 0x0000000b, 0x00000802, 0x00000817, + 0x00000003, +}; + +const uint32_t PAVAL[19] = { + 0x000022c0, 0x000022c0, 0x000022c0, + 0x00002280, 0x00002303, 0x000023c0, + 0x00002880, 0x000029f0, 0x000029f0, + 0x000029f0, 0x000029c0, 0x00002bf0, + 0x000029f0, 0x000028a0, 0x00002800, + 0x00002ac0, 0x00002880, 0x00002a00, + 0x00002b00, +}; + +const uint32_t AIMVAL[19] = { + 0x000123a0, 0x000163a0, 0x0001a3a0, + 0x0001e3a0, 0x000223a0, 0x000263a0, + 0x0002a3a0, 0x0002e3a0, 0x000323a0, + 0x000363a0, 0x0003a3a0, 0x0003a3a0, + 0x0003e3a0, 0x000423a0, 0x000523a0, + 0x000423a0, 0x0004e3a0, 0x0004e3a0, + 0x0004e3a0, +}; + +// #define MRRF_BASE 0x80009400 // Modem Radio Receiver Functions +// void _set_demodulator_type ( uint8_t demod ) { +// uint32_t val = *(uint32_t*)(MRRF_BASE); +// if ( demod == MACA_DEMOD_NCD ) { +// val = (val & ~1); +// } else { +// val = (val | 1); +// } +// *(uint32_t*)(MRRF_BASE) = val; +// } + +#define ADDR_POW1 0x8000a014 +#define ADDR_POW2 (ADDR_POW1 + 12) +#define ADDR_POW3 (ADDR_POW1 + 64) + +void set_power ( uint8_t power ) { + safe_irq_disable ( INT_NUM_MACA ); + + * ( ( uint32_t * ) ( ADDR_POW1 ) ) = PSMVAL[power]; + +#ifdef USE_PA + * ( ( uint32_t * ) ( ADDR_POW2 ) ) = 0xffffdfff & PAVAL[power]; /* single port */ +#else + * ( ( uint32_t * ) ( ADDR_POW2 ) ) = 0x00002000 | PAVAL[power]; /* dual port */ +#endif + + * ( ( uint32_t * ) ( ADDR_POW3 ) ) = AIMVAL[power]; + irq_restore(); + + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 1; + } +} + +const uint8_t VCODivI[16] = { + 0x2f, 0x2f, 0x2f, 0x2f, + 0x2f, 0x2f, 0x2f, 0x2f, + 0x2f, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, +}; + +const uint32_t VCODivF[16] = { + 0x00355555, 0x006aaaaa, 0x00a00000, 0x00d55555, + 0x010aaaaa, 0x01400000, 0x01755555, 0x01aaaaaa, + 0x01e00000, 0x00155555, 0x004aaaaa, 0x00800000, + 0x00b55555, 0x00eaaaaa, 0x01200000, 0x01555555, +}; + +#define ADDR_CHAN1 0x80009800 +#define ADDR_CHAN2 (ADDR_CHAN1+12) +#define ADDR_CHAN3 (ADDR_CHAN1+16) +#define ADDR_CHAN4 (ADDR_CHAN1+48) + +void set_channel ( uint8_t chan ) { + volatile uint32_t tmp; + safe_irq_disable ( INT_NUM_MACA ); + + tmp = * ( uint32_t * ) ( ADDR_CHAN1 ); + tmp = tmp & 0xbfffffff; + * ( ( uint32_t * ) ( ADDR_CHAN1 ) ) = tmp; + + * ( ( uint32_t * ) ( ADDR_CHAN2 ) ) = VCODivI[chan]; + * ( ( uint32_t * ) ( ADDR_CHAN3 ) ) = VCODivF[chan]; + + tmp = * ( ( uint32_t * ) ( ADDR_CHAN4 ) ); + tmp = tmp | 2; + * ( ( uint32_t * ) ( ADDR_CHAN4 ) ) = tmp; + + tmp = * ( ( uint32_t * ) ( ADDR_CHAN4 ) ); + tmp = tmp | 4; + * ( ( uint32_t * ) ( ADDR_CHAN4 ) ) = tmp; + + tmp = tmp & 0xffffe0ff; + tmp = tmp | ( ( ( ctov[chan] ) <<8 ) &0x1f00 ); + * ( ( uint32_t * ) ( ADDR_CHAN4 ) ) = tmp; + + irq_restore(); + + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 1; + } +} + +#define MACA_ROM_END 0x0013ffff +#define MACA_ENTRY_EOF 0x00000e0f +uint32_t _exec_init_entry ( volatile uint32_t *entries, uint8_t *value_buffer ) { + volatile uint32_t i; + + if ( entries[0] <= MACA_ROM_END ) { + if ( entries[0] == 0 ) { + /* do delay */ + printf ( "init_entry: delay 0x%08x\n", entries[1] ); + + for ( i=0; i < entries[1]; i++ ) { + continue; + } + + return 2; + } + else if ( entries[0] == 1 ) { + /* do bit set/clear */ + printf ( "init_entry: bit set/clear 0x%08x 0x%08x 0x%08x\n", entries[1], entries[2], entries[3] ); + * ( uint32_t * ) ( entries[2] ) = ( * ( uint32_t * ) ( entries[2] ) & entries[1] ) | ( entries[3] & entries[1] ); + return 4; + } + else if ( entries[0] >= 16 && entries[0] < 0xfff1 ) { + /* store bytes in value_buffer */ + printf ( "init_entry: store in value_buffer 0x%02x position %d\n", entries[1], ( entries[0]>>4 ) - 1 ); + value_buffer[ ( entries[0]>>4 )-1] = entries[1]; + return 2; + } + else if ( entries[0] == MACA_ENTRY_EOF ) { + printf ( "init_entry: EOF \n" ); + return 0; + } + else { + /* invalid */ + printf ( "init_entry: invalid code 0x%08x\n", entries[0] ); + return 0; + } + } + else { + /* address not in ROM */ + /* store value in address command */ + printf ( "init_entry: address value pair - *0x%08x = 0x%08x\n", entries[0], entries[1] ); + + if ( entries[0] != CRM->VREG_CNTL ) { + * ( uint32_t * ) ( entries[0] ) = entries[1]; + } + else { + printf ( "skipping CRM->VREG_CNTL\n" ); + } + + return 2; + } +} + +#define MACA_FLASH_INIT_MAGIC 0x00000abc +uint32_t _maca_init_from_flash ( uint32_t addr ) { + nvm_type_t type = 0; + nvm_err_t err; + + volatile uint32_t buffer[8]; + volatile uint32_t length; + volatile uint32_t i = 0; + volatile uint32_t j = 0; + + err = nvm_detect ( g_nvm_internal_interface_c, &type ); + printf ( "nvm_detect returned type 0x%08x err 0x%02x\n", type, err ); + + nvm_setsvar ( 0 ); + err = nvm_read ( g_nvm_internal_interface_c, type, ( uint8_t * ) buffer, addr, 8 ); + i += 8; + printf ( "nvm_read returned: 0x%02x\n", err ); + + for ( j = 0; j < 4; j++ ) { + printf ( "0x%08x\n", buffer[j] ); + } + + if ( buffer[0] == MACA_FLASH_INIT_MAGIC ) { + length = buffer[1] & 0x0000ffff; + + while ( i < ( length-4 ) ) { + err = nvm_read ( g_nvm_internal_interface_c, type, ( uint8_t * ) buffer, addr+i, 32 ); + i += 4 * _exec_init_entry ( buffer, _ram_values ); + } + } + else { + i = 0; + } + + nvm_setsvar ( 1 ); + return i; +} + +void _maca_resume_maca_sync ( void ) { + volatile uint32_t clk; + volatile uint32_t tsm_rx_steps; + volatile uint32_t last_warmup_step; + volatile uint32_t last_warmup_data; + volatile uint32_t last_warmdown_step; + volatile uint32_t last_warmdown_data; + volatile uint32_t i; + + safe_irq_disable ( INT_NUM_MACA ); + + /* manual TSM modem shutdown */ + /* read TSM_RX_STEPS */ + tsm_rx_steps = * ( volatile uint32_t * ) ( 0x80009204 ); + /* isolate the RX_WU_STEPS */ + /* shift left to align with 32-bit addressing */ + last_warmup_step = ( tsm_rx_steps & 0x1f ) << 2; + /* Read "current" TSM step and save this value for later */ + last_warmup_data = ( * ( ( volatile uint32_t * ) ( 0x80009300 + last_warmup_step ) ) ); + + /* isolate the RX_WD_STEPS */ + /* right-shift bits down to bit 0 position */ + /* left-shift to align with 32-bit addressing */ + last_warmdown_step = ( ( tsm_rx_steps & 0x1f00 ) >> 8 ) << 2; + /* write "last warmdown data" to current TSM step to shutdown rx */ + last_warmdown_data = ( * ( ( volatile uint32_t * ) ( 0x80009300 + last_warmdown_step ) ) ); + ( * ( ( volatile uint32_t * ) ( 0x80009300 + last_warmup_step ) ) ) = last_warmdown_data; + + /* Abort */ + MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_ABORT; + + /* Wait ~8us */ + for ( clk = MACA->CLK, i = 0; MACA->CLK - clk < 3 && i < 300; i++ ) { + continue; + } + + /* NOP */ + MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_NOP; + + /* Wait ~8us */ + for ( clk = MACA->CLK, i = 0; MACA->CLK - clk < 3 && i < 300; i++ ) { + continue; + } + + /* restore original "last warmup step" data to TSM (VERY IMPORTANT!!!) */ + ( * ( ( volatile uint32_t * ) ( 0x80009300 + last_warmup_step ) ) ) = last_warmup_data; + + /* Clear all MACA interrupts - we should have gotten the ABORT IRQ */ + MACA->CLRIRQ = 0xffff; + + irq_restore(); +} From 8494d2827c1c49208650c5895eacb4e2083c5f6c Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 23 Jul 2013 09:45:40 +0200 Subject: [PATCH 123/188] implementation of the non volatile memory driver --- redbee-econotag/drivers/include/nvm.h | 58 +++++++++++++++++++++++++++ redbee-econotag/drivers/nvm.c | 22 ++++++++++ 2 files changed, 80 insertions(+) create mode 100644 redbee-econotag/drivers/include/nvm.h create mode 100644 redbee-econotag/drivers/nvm.c diff --git a/redbee-econotag/drivers/include/nvm.h b/redbee-econotag/drivers/include/nvm.h new file mode 100644 index 0000000000..2a8c72bfeb --- /dev/null +++ b/redbee-econotag/drivers/include/nvm.h @@ -0,0 +1,58 @@ +/* + * nvm.h - non-volatile memory specific definitions + * Copyright (C) 2013 Thomas Eichinger + * + * 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 NVM_H +#define NVM_H + +#include + +typedef enum +{ + g_nvm_type_no_nvm_c = 0, + g_nvm_type_SST_c, + g_nvm_type_ST_c, + g_nvm_type_ATM_c, + g_nvm_type_Max_c +} nvm_type_t; + + +typedef enum +{ + g_nvm_err_no_error_c = 0, + g_nvm_err_invalid_interface_c, + g_nvm_err_onvalid_nvm_type_c, + g_nvm_err_invalid_pointer_c, + g_nvm_err_write_protect_c, + g_nvm_err_verify_error_c, + g_nvm_err_address_space_overflow_c, + g_nvm_err_blank_check_error_c, + g_nvm_err_restricted_area_c, + g_nvm_err_max_error_c +} nvm_err_t; + +typedef enum +{ + g_nvm_internal_interface_c = 0, + g_nvm_external_interface_c, + g_nvm_interface_max_c +} nvm_interface_t; + +/* ROM code seems to be THUMB */ +/* need to be in a THUMB block before calling them */ +extern nvm_err_t (*nvm_detect)(nvm_interface_t nvm_interface,nvm_type_t* p_nvm_type); +extern nvm_err_t (*nvm_read)(nvm_interface_t nvm_interface , nvm_type_t nvm_type , void *p_dest, uint32_t address, uint32_t num_bytes); +extern nvm_err_t (*nvm_write)(nvm_interface_t nvm_interface, nvm_type_t nvm_type ,void *p_src, uint32_t address, uint32_t num_bytes); +/* sector bit field selects which sector to erase */ +/* SST flash has 32 sectors 4096 bytes each */ +/* bit 0 is the first sector, bit 31 is the last */ +extern nvm_err_t (*nvm_erase)(nvm_interface_t nvm_interface, nvm_type_t nvm_type ,uint32_t sector_bitfield); +extern void(*nvm_setsvar)(uint32_t zero_for_awesome); + +#endif //NVM_H diff --git a/redbee-econotag/drivers/nvm.c b/redbee-econotag/drivers/nvm.c new file mode 100644 index 0000000000..5d4538ef26 --- /dev/null +++ b/redbee-econotag/drivers/nvm.c @@ -0,0 +1,22 @@ +/* + * nvm.c - non-volatile memory implementations + * Copyright (C) 2013 Thomas Eichinger + * + * 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 "nvm.h" + +nvm_err_t (*nvm_detect) (nvm_interface_t nvm_interface, nvm_type_t* p_nvm_type) + = (void*) 0x00006cb9; +nvm_err_t (*nvm_read) (nvm_interface_t nvm_interface, nvm_type_t nvm_type, void *p_dest, uint32_t address, uint32_t num_bytes) + = (void*) 0x00006d69; +nvm_err_t (*nvm_write) (nvm_interface_t nvm_interface, nvm_type_t nvm_type, void *p_src, uint32_t address, uint32_t numb_bytes) + = (void*) 0x00006ec5; +nvm_err_t (*nvm_erase) (nvm_interface_t nvm_interface, nvm_type_t nvm_type, uint32_t sector_bitfield) + = (void*) 0x00006e05; +void (*nvm_sets_var) (uint32_t zero_is_for_winners) + = (void*) 0x00007085; \ No newline at end of file From ea6b16793820dcc677a24e377137bb10e13223b4 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 23 Jul 2013 10:39:57 +0200 Subject: [PATCH 124/188] * fixed some warnings in redbee_uart.c * fixed a missing variabl declaration in redbee_uart1.c --- redbee-econotag/drivers/include/uart.h | 2 ++ redbee-econotag/drivers/redbee_uart.c | 1 + redbee-econotag/drivers/redbee_uart1.c | 1 + 3 files changed, 4 insertions(+) diff --git a/redbee-econotag/drivers/include/uart.h b/redbee-econotag/drivers/include/uart.h index 928a2157a9..669ac135d0 100644 --- a/redbee-econotag/drivers/include/uart.h +++ b/redbee-econotag/drivers/include/uart.h @@ -97,6 +97,8 @@ void uart_set_baudrate(volatile struct UART_struct * uart, uint32_t baud); void uart_flow_ctl(volatile struct UART_struct * uart, uint8_t on); +#define UART0_BUFSIZE (32) + /* 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 diff --git a/redbee-econotag/drivers/redbee_uart.c b/redbee-econotag/drivers/redbee_uart.c index 621d94e060..9d02cc3b29 100644 --- a/redbee-econotag/drivers/redbee_uart.c +++ b/redbee-econotag/drivers/redbee_uart.c @@ -201,4 +201,5 @@ int fw_puts(char *astring,int length) int bl_uart_init(void) { uart_init( UART1, BAUTRATE_UART1 ); uart_init( UART2, BAUTRATE_UART2 ); + return 0; } \ No newline at end of file diff --git a/redbee-econotag/drivers/redbee_uart1.c b/redbee-econotag/drivers/redbee_uart1.c index a4a53afc40..10526d55d9 100644 --- a/redbee-econotag/drivers/redbee_uart1.c +++ b/redbee-econotag/drivers/redbee_uart1.c @@ -14,6 +14,7 @@ #include "uart.h" void uart1_isr ( void ) { + uint8_t i = 0; if ( UART1->USTATbits.RXRDY == 1 ) { #ifdef MODULE_UART0 if ( uart0_handler_pid ) { From 667cb2fd853d0577426a23eb6e94d9023c160cda Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 23 Jul 2013 16:03:52 +0200 Subject: [PATCH 125/188] small fixes --- redbee-econotag/drivers/Makefile | 2 +- redbee-econotag/drivers/include/maca.h | 2 ++ redbee-econotag/drivers/maca.c | 21 +++++++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/redbee-econotag/drivers/Makefile b/redbee-econotag/drivers/Makefile index 8b8b6094b9..0a40ae1d50 100644 --- a/redbee-econotag/drivers/Makefile +++ b/redbee-econotag/drivers/Makefile @@ -3,7 +3,7 @@ BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o) DEP = $(SRC:%.c=$(BINDIR)%.d) -INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ +INCLUDES += -I$(RIOTBASE)/sys/include/ .PHONY: redbee-econotag_drivers.a diff --git a/redbee-econotag/drivers/include/maca.h b/redbee-econotag/drivers/include/maca.h index 3e8c26c15a..79195fc7dd 100644 --- a/redbee-econotag/drivers/include/maca.h +++ b/redbee-econotag/drivers/include/maca.h @@ -29,6 +29,8 @@ void maca_check ( void ); /* functions to configure MACA */ void maca_set_power ( uint8_t power ); void maca_set_channel ( uint8_t channel ); +uint16_t maca_set_address ( uint16_t addr ); +uint16_t maca_get_address ( void ); /* get Link Quality Indicator */ //extern uint8_t (*get_lqi) ( void ); diff --git a/redbee-econotag/drivers/maca.c b/redbee-econotag/drivers/maca.c index 3283d37b2d..596002daeb 100644 --- a/redbee-econotag/drivers/maca.c +++ b/redbee-econotag/drivers/maca.c @@ -827,7 +827,7 @@ const uint32_t AIMVAL[19] = { #define ADDR_POW2 (ADDR_POW1 + 12) #define ADDR_POW3 (ADDR_POW1 + 64) -void set_power ( uint8_t power ) { +void maca_set_power ( uint8_t power ) { safe_irq_disable ( INT_NUM_MACA ); * ( ( uint32_t * ) ( ADDR_POW1 ) ) = PSMVAL[power]; @@ -865,7 +865,7 @@ const uint32_t VCODivF[16] = { #define ADDR_CHAN3 (ADDR_CHAN1+16) #define ADDR_CHAN4 (ADDR_CHAN1+48) -void set_channel ( uint8_t chan ) { +void maca_set_channel ( uint8_t chan ) { volatile uint32_t tmp; safe_irq_disable ( INT_NUM_MACA ); @@ -895,6 +895,23 @@ void set_channel ( uint8_t chan ) { } } +uint16_t maca_set_address ( uint16_t addr ) { + safe_irq_disable ( INT_NUM_MACA ); + + MACA->MAC16ADDR = addr; + + irq_restore(); + + if ( ITC->NIPENDbits.MACA ) { + ITC->INTFRCbits.MACA = 1; + } + return MACA->MAC16ADDR; +} + +uint16_t maca_get_address ( void ) { + return MACA->MAC16ADDR; +} + #define MACA_ROM_END 0x0013ffff #define MACA_ENTRY_EOF 0x00000e0f uint32_t _exec_init_entry ( volatile uint32_t *entries, uint8_t *value_buffer ) { From 9760b93d5cefd07124837667d683d6d53afa4cd0 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 24 Jul 2013 11:01:05 +0200 Subject: [PATCH 126/188] do not omit exported CFLAGS --- msba2-common/Makefile.include | 3 ++- redbee-econotag/Makefile.include | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index b8626464fc..082a2e57f1 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -3,9 +3,10 @@ export CPU = lpc2387 # toolchain config export PREFIX = @arm-none-eabi- +#export PREFIX = @arm-elf- export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar -export CFLAGS = -std=gnu99 -O2 -Wall -Wstrict-prototypes -mcpu=arm7tdmi-s -gdwarf-2 +export CFLAGS += -std=gnu99 -O2 -Wall -Wstrict-prototypes -mcpu=arm7tdmi-s -gdwarf-2 export ASFLAGS = -gdwarf-2 -mcpu=arm7tdmi-s export AS = $(PREFIX)as export LINK = $(PREFIX)gcc diff --git a/redbee-econotag/Makefile.include b/redbee-econotag/Makefile.include index ee087fb781..7275c2daf6 100644 --- a/redbee-econotag/Makefile.include +++ b/redbee-econotag/Makefile.include @@ -5,7 +5,7 @@ export CPU = mc1322x export PREFIX = @arm-none-eabi- export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar -export CFLAGS = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ +export CFLAGS += -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ -msoft-float -mthumb-interwork -fno-strict-aliasing -fno-common \ -ffixed-r8 -ffunction-sections -ffreestanding -fno-builtin \ -nodefaultlibs -Wcast-align -Wall -Wstrict-prototypes -Wextra \ From f839f18b111bb8ce926555af5aa057814302ef06 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Wed, 24 Jul 2013 15:51:07 +0200 Subject: [PATCH 127/188] bug fixes for mc1322x MACA --- redbee-econotag/drivers/include/maca.h | 4 ++-- redbee-econotag/drivers/maca.c | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/redbee-econotag/drivers/include/maca.h b/redbee-econotag/drivers/include/maca.h index 79195fc7dd..7c2bc8e071 100644 --- a/redbee-econotag/drivers/include/maca.h +++ b/redbee-econotag/drivers/include/maca.h @@ -33,8 +33,8 @@ uint16_t maca_set_address ( uint16_t addr ); uint16_t maca_get_address ( void ); /* get Link Quality Indicator */ -//extern uint8_t (*get_lqi) ( void ); -uint8_t (*get_lqi)(void) = (void *) 0x0000e04d; +extern uint8_t (*get_lqi) ( void ); + /* interface to configure demodulator */ #define MACA_DEMOD_DCD 1 /* -96dBm, 22.2mA */ diff --git a/redbee-econotag/drivers/maca.c b/redbee-econotag/drivers/maca.c index 596002daeb..befbc3c7fa 100644 --- a/redbee-econotag/drivers/maca.c +++ b/redbee-econotag/drivers/maca.c @@ -48,6 +48,8 @@ volatile maca_packet_t *maca_tx_head; static volatile maca_packet_t maca_dummy_ack; +uint8_t (*get_lqi)(void) = (void *) 0x0000e04d; + #define MACA_NO_POST 0 #define MACA_TX_POST 1 #define MACA_RX_POST 2 @@ -480,7 +482,7 @@ void _maca_decode_status ( void ) { } void maca_isr ( void ) { - maca_entry++; + //maca_entry++; if ( MACA->STATUSbits.OVR ) { printf ( "maca overrun\n" ); @@ -550,7 +552,7 @@ void maca_isr ( void ) { // action complete interrupt if ( MACA->IRQbits.ACPL ) { if ( maca_last_post == MACA_TX_POST ) { - maca_tx_head->status == MACA->STATUSbits.COMPLETE_CODE; + maca_tx_head->status = MACA->STATUSbits.COMPLETE_CODE; if ( maca_tx_callback != 0 ) { maca_tx_callback ( maca_tx_head ); @@ -569,7 +571,7 @@ void maca_isr ( void ) { // this should never happen ... if ( MACA->IRQ != 0 ) { - printf ( "MACA->IRQ is %x", MACA->IRQ ); + printf ( "MACA->IRQ is %x", (unsigned int) MACA->IRQ ); } if ( maca_tx_head != 0 ) { @@ -602,7 +604,7 @@ void _maca_init_phy ( void ) { } #define MTOC_BASE 0x80009a00 //Modem Tracking Oscillator Controller -void _flyback_init ( void ) { +void _maca_flyback_init ( void ) { uint32_t val8, tmp; val8 = * ( volatile uint32_t * ) ( MTOC_BASE+8 ); @@ -920,7 +922,7 @@ uint32_t _exec_init_entry ( volatile uint32_t *entries, uint8_t *value_buffer ) if ( entries[0] <= MACA_ROM_END ) { if ( entries[0] == 0 ) { /* do delay */ - printf ( "init_entry: delay 0x%08x\n", entries[1] ); + printf ( "init_entry: delay 0x%08x\n", (unsigned int) entries[1] ); for ( i=0; i < entries[1]; i++ ) { continue; @@ -930,13 +932,16 @@ uint32_t _exec_init_entry ( volatile uint32_t *entries, uint8_t *value_buffer ) } else if ( entries[0] == 1 ) { /* do bit set/clear */ - printf ( "init_entry: bit set/clear 0x%08x 0x%08x 0x%08x\n", entries[1], entries[2], entries[3] ); + printf ( "init_entry: bit set/clear 0x%08x 0x%08x 0x%08x\n", (unsigned int) entries[1], + (unsigned int) entries[2], + (unsigned int) entries[3] ); * ( uint32_t * ) ( entries[2] ) = ( * ( uint32_t * ) ( entries[2] ) & entries[1] ) | ( entries[3] & entries[1] ); return 4; } else if ( entries[0] >= 16 && entries[0] < 0xfff1 ) { /* store bytes in value_buffer */ - printf ( "init_entry: store in value_buffer 0x%02x position %d\n", entries[1], ( entries[0]>>4 ) - 1 ); + printf ( "init_entry: store in value_buffer 0x%02x position %d\n", (unsigned int) entries[1], + (unsigned int) ( entries[0]>>4 ) - 1 ); value_buffer[ ( entries[0]>>4 )-1] = entries[1]; return 2; } @@ -946,14 +951,15 @@ uint32_t _exec_init_entry ( volatile uint32_t *entries, uint8_t *value_buffer ) } else { /* invalid */ - printf ( "init_entry: invalid code 0x%08x\n", entries[0] ); + printf ( "init_entry: invalid code 0x%08x\n", (unsigned int) entries[0] ); return 0; } } else { /* address not in ROM */ /* store value in address command */ - printf ( "init_entry: address value pair - *0x%08x = 0x%08x\n", entries[0], entries[1] ); + printf ( "init_entry: address value pair - *0x%08x = 0x%08x\n", (unsigned int) entries[0], + (unsigned int) entries[1] ); if ( entries[0] != CRM->VREG_CNTL ) { * ( uint32_t * ) ( entries[0] ) = entries[1]; @@ -985,7 +991,7 @@ uint32_t _maca_init_from_flash ( uint32_t addr ) { printf ( "nvm_read returned: 0x%02x\n", err ); for ( j = 0; j < 4; j++ ) { - printf ( "0x%08x\n", buffer[j] ); + printf ( "0x%08x\n", (unsigned int) buffer[j] ); } if ( buffer[0] == MACA_FLASH_INIT_MAGIC ) { From cf2e1644b85ce581a165363b2e04dc171d4824ec Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 10 Apr 2013 12:52:19 +0200 Subject: [PATCH 128/188] adapted native Makefiles to core restructuring --- native/Makefile.dep | 6 ++++++ native/Makefile.include | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 native/Makefile.dep diff --git a/native/Makefile.dep b/native/Makefile.dep new file mode 100644 index 0000000000..de1d7e692c --- /dev/null +++ b/native/Makefile.dep @@ -0,0 +1,6 @@ +ifneq (,$(findstring cc110x_ng,$(USEMODULE))) + ifeq (,$(findstring cc110x_spi,$(USEMODULE))) + USEMODULE += cc110x_spi + endif +endif + diff --git a/native/Makefile.include b/native/Makefile.include index a14da50af5..e7bf1c65bd 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -19,3 +19,5 @@ LINKFLAGS = -lrt -m32 ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 endif + +include $(RIOTBOARD)/$(BOARD)/Makefile.dep From c5f8eee291cf20c1a13b7258a56d3ad49da809cd Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 15 Apr 2013 20:11:15 +0200 Subject: [PATCH 129/188] make native ltc4150 posix rt independent --- native/native-ltc4150.c | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c index 99b4d0a3e5..e84501ef2c 100644 --- a/native/native-ltc4150.c +++ b/native/native-ltc4150.c @@ -26,11 +26,25 @@ #include "cpu.h" #include "cpu-conf.h" +#include "hwtimer.h" #define native_ltc4150_startup_delay 10 -static timer_t native_ltc4150_timer; -static struct itimerspec native_ltc4150_timer_time; +static int _int_enabled; + +/** + * native ltc4150 hwtimer - interrupt handler proxy + */ +static void _int_handler() +{ + DEBUG("ltc4150 _int_handler()\n"); + ltc4150_interrupt(); + if (_int_enabled == 1) { + if (hwtimer_set(100000, _int_handler, NULL) == -1) { + errx(1, "_int_handler: hwtimer_set"); + }; + } +} /** * unregister signal handler @@ -38,7 +52,7 @@ static struct itimerspec native_ltc4150_timer_time; void ltc4150_disable_int(void) { DEBUG("ltc4150_disable_int()\n"); - unregister_interrupt(_SIG_LTC4150); + _int_enabled = 0; } /** @@ -47,7 +61,10 @@ void ltc4150_disable_int(void) void ltc4150_enable_int(void) { DEBUG("ltc4150_enable_int()\n"); - register_interrupt(_SIG_LTC4150, ltc4150_interrupt); + _int_enabled = 1; + if (hwtimer_set(100000, _int_handler, NULL) == -1) { + errx(1, "ltc4150_enable_int: hwtimer_set"); + }; } /** @@ -68,25 +85,6 @@ void ltc4150_arch_init(void) ltc4150_disable_int(); - /* create timer */ - sev.sigev_notify = SIGEV_SIGNAL; - sev.sigev_signo = _SIG_LTC4150; - sev.sigev_value.sival_ptr = &native_ltc4150_timer; - - if (timer_create(CLOCK_MONOTONIC, &sev, &native_ltc4150_timer) == -1) { - err(1, "ltc4150_arch_init(): timer_create"); - } - - /* set timer */ - native_ltc4150_timer_time.it_value.tv_sec = 0; - native_ltc4150_timer_time.it_value.tv_nsec = 100000000; - native_ltc4150_timer_time.it_interval.tv_sec = 0; - native_ltc4150_timer_time.it_interval.tv_nsec = 100000000; - - if (timer_settime(native_ltc4150_timer, 0, &native_ltc4150_timer_time, NULL) == -1) { - err(1, "ltc4150_arch_init: timer_settime"); - } - puts("Native LTC4150 initialized."); } /** @} */ From d3b806ea41139219db60412b0e02f990b97296fa Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Tue, 14 May 2013 17:42:08 +0200 Subject: [PATCH 130/188] native board uart0 import --- native/board_init.c | 3 +++ native/include/board.h | 5 +++++ native/native-uart0.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 native/native-uart0.c diff --git a/native/board_init.c b/native/board_init.c index d6f4c4ba31..52e63878fc 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -21,6 +21,9 @@ */ void board_init() { +#ifdef MODULE_UART0 + _native_init_uart0(); +#endif LED_GREEN_OFF(); LED_RED_ON(); puts("RIOT native board initialized."); diff --git a/native/include/board.h b/native/include/board.h index 457289a566..69e40eb383 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -22,3 +22,8 @@ void LED_RED_OFF(void); void LED_RED_ON(void); void LED_RED_TOGGLE(void); +#ifdef MODULE_UART0 +#include +extern fd_set _native_uart_rfds; +extern void _native_handle_uart0_input(void); +#endif diff --git a/native/native-uart0.c b/native/native-uart0.c new file mode 100644 index 0000000000..c73b5ee6ea --- /dev/null +++ b/native/native-uart0.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include "cpu.h" +#include "debug.h" +#include "board_uart0.h" + +fd_set _native_uart_rfds; + +static inline int uart0_puts(char *astring, int length) +{ + return puts(astring); +} + +void _native_handle_uart0_input() +{ + char buf[42]; + int nread; + + _native_in_syscall = 0; + _native_in_isr = 1; + + nread = read(0, buf, sizeof(buf)); + if (nread == -1) { + err(1, "_native_handle_uart0_input(): read()"); + } + for(int pos = 0; pos < nread; pos++) { + uart0_handle_incoming(buf[pos]); + } + uart0_notify_thread(); + + _native_in_isr = 0; + cpu_switch_context_exit(); +} + +void _native_init_uart0() +{ + /* Watch stdin (fd 0) to see when it has input. */ + FD_ZERO(&_native_uart_rfds); + FD_SET(0, &_native_uart_rfds); + puts("RIOT native uart0 initialized."); +} From 3d54e76b90440a732e229457147c99250cdcc75a Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 15 May 2013 10:44:57 +0200 Subject: [PATCH 131/188] lose superflouse -lrt CFLAG --- native/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/Makefile.include b/native/Makefile.include index e7bf1c65bd..d360b2248f 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -14,7 +14,7 @@ export OBJCOPY = $(PREFIX)objcopy FLASHER = lpc2k_pgm TERM = pyterm.py -LINKFLAGS = -lrt -m32 +LINKFLAGS = -m32 ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 From f0dbd8cf751ca393fca2116ced4b5fc590ea6880 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 15 May 2013 16:04:48 +0200 Subject: [PATCH 132/188] native board putchar implementation --- native/native-uart0.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/native/native-uart0.c b/native/native-uart0.c index c73b5ee6ea..e13447bb0e 100644 --- a/native/native-uart0.c +++ b/native/native-uart0.c @@ -1,3 +1,8 @@ +/* + * TODO: + * make stdin/stdout customizable. + */ + #include #include #include @@ -42,3 +47,8 @@ void _native_init_uart0() FD_SET(0, &_native_uart_rfds); puts("RIOT native uart0 initialized."); } + +int putchar(int c) { + write(1, &c, 1); + return 0; +} From 163c00ebd7385c5f02d41da1e691d85543bfe510 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Sun, 2 Jun 2013 12:41:27 +0200 Subject: [PATCH 133/188] minor: fix warning from mkdir --- native/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/Makefile b/native/Makefile index da7907f159..86ddb4a6ff 100644 --- a/native/Makefile +++ b/native/Makefile @@ -16,7 +16,7 @@ $(BINDIR)native_base.a: $(OBJ) # compile and generate dependency info $(BINDIR)%.o: %.c - -mkdir $(BINDIR) + -mkdir -p $(BINDIR) $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d @@ -24,5 +24,5 @@ $(BINDIR)%.o: %.c # remove compilation products clean: rm -f $(BINDIR)native_base.a $(OBJ) $(DEP) - -rmdir $(BINDIR) + -rmdir -p $(BINDIR) From 17048fd311903a740b0ec6c4ce5c7bb36fcc6f39 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Sun, 2 Jun 2013 12:42:10 +0200 Subject: [PATCH 134/188] add missing include --- native/board_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/board_init.c b/native/board_init.c index 52e63878fc..d32c653dc9 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -12,7 +12,7 @@ * @author Ludwig Ortmann * @} */ - +#include #include "board.h" /** From 4115c4421b27a0a9c33d6a6ed52cd5c7318d844c Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Sun, 2 Jun 2013 12:42:49 +0200 Subject: [PATCH 135/188] remove unused struct --- native/native-ltc4150.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c index e84501ef2c..2f2d414cf8 100644 --- a/native/native-ltc4150.c +++ b/native/native-ltc4150.c @@ -81,8 +81,6 @@ void ltc4150_sync_blocking(void) */ void ltc4150_arch_init(void) { - struct sigevent sev; - ltc4150_disable_int(); puts("Native LTC4150 initialized."); From bc27516d2f23e4ab3756d87ed69ed6dc628013c7 Mon Sep 17 00:00:00 2001 From: Milan Babel Date: Sat, 25 May 2013 12:34:18 +0200 Subject: [PATCH 136/188] added support for board wsn430-v1_3b --- Makefile.base | 4 + wsn430-common/Makefile | 33 +++++ wsn430-common/Makefile.include | 23 ++++ wsn430-common/board_config.c | 19 +++ wsn430-common/board_init.c | 150 +++++++++++++++++++++ wsn430-common/drivers/Makefile | 0 wsn430-common/include/board-conf.h | 6 + wsn430-common/uart0.c | 63 +++++++++ wsn430-v1_3b/Makefile | 36 +++++ wsn430-v1_3b/Makefile.dep | 7 + wsn430-v1_3b/Makefile.include | 3 + wsn430-v1_3b/driver_cc110x.c | 206 +++++++++++++++++++++++++++++ wsn430-v1_3b/include/board.h | 31 +++++ 13 files changed, 581 insertions(+) create mode 100644 wsn430-common/Makefile create mode 100644 wsn430-common/Makefile.include create mode 100644 wsn430-common/board_config.c create mode 100644 wsn430-common/board_init.c create mode 100644 wsn430-common/drivers/Makefile create mode 100644 wsn430-common/include/board-conf.h create mode 100644 wsn430-common/uart0.c create mode 100644 wsn430-v1_3b/Makefile create mode 100644 wsn430-v1_3b/Makefile.dep create mode 100644 wsn430-v1_3b/Makefile.include create mode 100644 wsn430-v1_3b/driver_cc110x.c create mode 100644 wsn430-v1_3b/include/board.h diff --git a/Makefile.base b/Makefile.base index a9a5375397..641eaf56cd 100644 --- a/Makefile.base +++ b/Makefile.base @@ -13,6 +13,10 @@ ifeq ($(BOARD),msb-430h) INCLUDES += -I$(RIOTBOARD)/msb-430-common/include/ INCLUDES += -I$(RIOTBOARD)/msb-430-common/drivers/include/ endif +ifeq ($(BOARD),wsn430-v1_3b) + INCLUDES += -I$(RIOTBOARD)/wsn430-v1_3b/include/ + INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ +endif ifeq ($(BOARD),chronos) INCLUDES += -I$(RIOTBOARD)/chronos/include/ INCLUDES += -I$(RIOTBOARD)/chronos/drivers/include/ diff --git a/wsn430-common/Makefile b/wsn430-common/Makefile new file mode 100644 index 0000000000..8f8f23add9 --- /dev/null +++ b/wsn430-common/Makefile @@ -0,0 +1,33 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ -I${RIOTBOARD}/${BOARD}/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/mspx16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/include/ + +.PHONY: $(BINDIR)$(ARCH) + +all: $(BINDIR)$(ARCH) + #$(MAKE) -C drivers + +$(BINDIR)$(ARCH): $(OBJ) + echo $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + #$(MAKE) -C drivers clean + rm -f $(OBJ) $(DEP) + rm -f $(BINDIR)$(ARCH) diff --git a/wsn430-common/Makefile.include b/wsn430-common/Makefile.include new file mode 100644 index 0000000000..63cee9a3af --- /dev/null +++ b/wsn430-common/Makefile.include @@ -0,0 +1,23 @@ +## the cpu to build for +export CPU = msp430x16x +export MCU = msp430f1611 + +# toolchain config +export PREFIX = @msp430- +export CC = @$(PREFIX)gcc +export AR = @$(PREFIX)ar +export CFLAGS += -std=gnu99 -Wstrict-prototypes -gdwarf-2 -Os -Wall -mmcu=$(MCU) +export ASFLAGS += -mmcu=$(MCU) --defsym $(MCU)=1 --gdwarf-2 +export AS = $(PREFIX)as +export LINK = $(PREFIX)gcc +export SIZE = $(PREFIX)size +export OBJCOPY = $(PREFIX)objcopy +export LINKFLAGS = -mmcu=$(MCU) -lgcc $(RIOTBASE)/bin/startup.o +export FLASHER = mspdebug +ifeq ($(strip $(PORT)),) + export PORT = /dev/ttyUSB0 +endif +export HEXFILE = bin/$(PROJECT).hex +export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" + +export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ \ No newline at end of file diff --git a/wsn430-common/board_config.c b/wsn430-common/board_config.c new file mode 100644 index 0000000000..f22e513b20 --- /dev/null +++ b/wsn430-common/board_config.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include + +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) { + configmem_t mem = { CONFIG_KEY, sysconfig }; + return (flashrom_erase((uint8_t*) INFOMEM) && flashrom_write((uint8_t*) INFOMEM, (char*) &mem, sizeof(mem))); +} diff --git a/wsn430-common/board_init.c b/wsn430-common/board_init.c new file mode 100644 index 0000000000..b7b523cf76 --- /dev/null +++ b/wsn430-common/board_init.c @@ -0,0 +1,150 @@ + /* + * board_init.c - Implementation of functions to init board. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +#include "cpu.h" +#include "board.h" +#include "kernel_intern.h" +#include "msp430.h" +#include "debug.h" + +volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; + +typedef enum { + MCLK_2MHZ_SCLK_1MHZ = 1000002uL, + MCLK_4MHZ_SCLK_1MHZ = 1000004uL, + MCLK_8MHZ_SCLK_1MHZ = 1000008uL, + MCLK_8MHZ_SCLK_8MHZ = 8000000uL +}speed_t; + +/*---------------------------------------------------------------------------*/ +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: GDO, Flash, BSL TX + P1SEL = 0x02; // Port1 Select: 00000010 = 0x02 + P1OUT = 0x00; // Port1 Output: 00000000 = 0x00 + P1DIR = 0xE7; // Port1 Direction: 11100111 = 0xE7 + + // Port 2: GPIO, BSL RX, 1wire + P2SEL = 0x04; // Port2 Select: 00000100 = 0x04 + P2OUT = 0x00; // Port2 Output: 00000000 = 0x00 + P2DIR = 0xFF; // Port2 Direction: 11111111 = 0xFF + + + // Port 3: UART + P3SEL = 0xFE; // Port3 Select: 11111110 = 0xFE + P3OUT = 0x00; // Port3 Output: 00000000 = 0x00 + P3DIR = 0xFF; // Port3 Direction: 11111111 = 0xFF + + + // Port 4: CS + P4SEL = 0x00; // Port4 Select: 00000000 = 0x00 + P4OUT = 0x14; // Port4 Output: 00010100 = 0x14 + P4DIR = 0xFF; // Port4 Direction: 11111111 = 0xFF + + // Port 5: SPI, LED + P5SEL = 0x0E; // Port5 Select: 00001110 = 0x0E + P5OUT = 0x70; // Port5 Output: 01110000 = 0x70 + P5DIR = 0x70; // Port5 Direction: 01110000 = 0x70 + + + P6SEL = 0xFF; // Port6 Select: 11111111 = 0xFF + P6OUT = 0x00; // Port6 Output: 00000000 = 0x00 + P6DIR = 0xFF; // Port6 Direction: 11111000 = 0xF8 + +} + +void msp430_set_cpu_speed(uint32_t speed) +{ + + dint(); + __msp430_cpu_speed = speed; + msp430_init_dco(); + uint16_t br; + + U0CTL = SWRST; + U0CTL = SWRST | CHAR; // 8-bit character + U0TCTL = SSEL1 | TXEPT; // UCLK = SCLK + U0RCTL = 0; + // activate + ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD + br = (uint16_t)((__msp430_cpu_speed & 0xFFFFF0) / 115200uL); + UBR00 = br; // set baudrate + UBR10 = br>>8; + UMCTL0 = calc_umctl(br); // set modulation + + U0CTL &= ~SWRST; + + //URCTL0 |= URXEIE; // allow chars to interrupt + IE1 |= URXIE0; // enable rx interrupt + IFG1 &= ~UTXIFG0; + eint(); +} + +/*---------------------------------------------------------------------------*/ +void msp430_init_dco(void) +{ + /*----------------------- use external oszillator -------------------------*/ + uint16_t i; + + // Stop watchdog + WDTCTL = WDTPW + WDTHOLD; + + 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? + switch (__msp430_cpu_speed) { + case MCLK_2MHZ_SCLK_1MHZ: + BCSCTL2 = (SELM_2 | DIVM_2) | (SELS | DIVS_3); + break; + case MCLK_4MHZ_SCLK_1MHZ: + BCSCTL2 = (SELM_2 | DIVM_1) | (SELS | DIVS_3); + break; + case MCLK_8MHZ_SCLK_1MHZ: + BCSCTL2 = SELM_2 | (SELS | DIVS_3); + break; + default: + BCSCTL2 = SELM_2 + SELS; // MCLK and SMCLK = XT2 (safe) + break; + } +} + +void board_init() { + msp430_cpu_init(); + msb_ports_init(); + + LED_RED_ON; + + msp430_set_cpu_speed(MCLK_8MHZ_SCLK_8MHZ); +} diff --git a/wsn430-common/drivers/Makefile b/wsn430-common/drivers/Makefile new file mode 100644 index 0000000000..e69de29bb2 diff --git a/wsn430-common/include/board-conf.h b/wsn430-common/include/board-conf.h new file mode 100644 index 0000000000..e85c3128f2 --- /dev/null +++ b/wsn430-common/include/board-conf.h @@ -0,0 +1,6 @@ +#ifndef BOARD_CONF_H +#define BOARD_CONF_H + +#define INFOMEM (0x1000) + +#endif /* BOARD-CONF_H */ diff --git a/wsn430-common/uart0.c b/wsn430-common/uart0.c new file mode 100644 index 0000000000..f743335ec4 --- /dev/null +++ b/wsn430-common/uart0.c @@ -0,0 +1,63 @@ + /* + * uart0.c - Implementation of the uart. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +#include "board.h" + +#define UART0_TX U0TXBUF +#define UART0_WAIT_TXDONE() while( (U0TCTL & TXEPT) == 0 ) { _NOP(); } + +#include +#include + +#include + +int putchar(int c) +{ + UART0_TX = c; + UART0_WAIT_TXDONE(); + + if (c == 10) { + UART0_TX = 13; + UART0_WAIT_TXDONE(); + } + + return c; +} + +void usart0irq(void); +/** + * \brief the interrupt function + */ +interrupt(USART0RX_VECTOR) usart0irq(void) { + int dummy = 0; + /* Check status register for receive errors. */ + if(U0RCTL & RXERR) { + if (U0RCTL & FE) { + puts("rx framing error"); + } + if (U0RCTL & OE) { + puts("rx overrun error"); + } + if (U0RCTL & PE) { + puts("rx parity error"); + } + if (U0RCTL & BRK) { + puts("rx break error"); + } + /* Clear error flags by forcing a dummy read. */ + dummy = U0RXBUF; + } +#ifdef MODULE_UART0 + else if (uart0_handler_pid) { + dummy = U0RXBUF; + uart0_handle_incoming(dummy); + uart0_notify_thread(); + } +#endif +} + diff --git a/wsn430-v1_3b/Makefile b/wsn430-v1_3b/Makefile new file mode 100644 index 0000000000..e19884c6b1 --- /dev/null +++ b/wsn430-v1_3b/Makefile @@ -0,0 +1,36 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = wsn430-v1_3b_base.a + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I${RIOTBASE}/core/include/ +INCLUDES += -Iinclude/ -I$(RIOTBOARD)/wsn430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBASE)/sys/include +#INCLUDES += -I/usr/msp430/include/ + +all: $(BINDIR)$(ARCH) + $(MAKE) -C ../wsn430-common + +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + mkdir -p $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + $(MAKE) -C ../wsn430-common clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi \ No newline at end of file diff --git a/wsn430-v1_3b/Makefile.dep b/wsn430-v1_3b/Makefile.dep new file mode 100644 index 0000000000..5463317289 --- /dev/null +++ b/wsn430-v1_3b/Makefile.dep @@ -0,0 +1,7 @@ +ifneq (,$(findstring cc110x_ng,$(USEMODULE))) + ifeq (,$(findstring cc110x_spi,$(USEMODULE))) + USEMODULE += cc110x_spi + endif +endif + +USEMODULE += msp430_common \ No newline at end of file diff --git a/wsn430-v1_3b/Makefile.include b/wsn430-v1_3b/Makefile.include new file mode 100644 index 0000000000..366d6cbcc8 --- /dev/null +++ b/wsn430-v1_3b/Makefile.include @@ -0,0 +1,3 @@ +include $(RIOTBOARD)/$(BOARD)/Makefile.dep + +include $(RIOTBOARD)/wsn430-common/Makefile.include \ No newline at end of file diff --git a/wsn430-v1_3b/driver_cc110x.c b/wsn430-v1_3b/driver_cc110x.c new file mode 100644 index 0000000000..39ca90bb15 --- /dev/null +++ b/wsn430-v1_3b/driver_cc110x.c @@ -0,0 +1,206 @@ + /* + * driver_cc110x.c - Implementation of the board dependent cc1100 functions. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +#include + +#include +#include +#include + +#include +#include + +#define CC1100_GDO0 (P1IN & 0x08) // read serial I/O (GDO0) +#define CC1100_GDO1 (P5IN & 0x04) // read serial I/O (GDO1) +#define CC1100_GDO2 (P1IN & 0x10) // read serial I/O (GDO2) + +#define CC1100_CS_LOW (P4OUT &= ~0x04) +#define CC1100_CS_HIGH (P4OUT |= 0x04) + +#define CC1100_GDO1_LOW_COUNT (2700) // loop count (timeout ~ 500 us) to wait +#define CC1100_GDO1_LOW_RETRY (100) // max. retries for GDO1 to go low + +volatile int abort_count; +volatile int retry_count = 0; + +void cc110x_gdo0_enable(void) +{ + P1IFG &= ~0x08; /* Clear IFG for GDO0 */ + P1IE |= 0x08; /* Enable interrupt for GDO0 */ +} + +void cc110x_gdo0_disable(void) +{ + P1IE &= ~0x08; /* Disable interrupt for GDO0 */ + P1IFG &= ~0x08; /* Clear IFG for GDO0 */ +} + +void cc110x_gdo2_enable(void) +{ + P1IFG &= ~0x10; /* Clear IFG for GDO2 */ + P1IE |= 0x10; /* Enable interrupt for GDO2 */ +} + +void cc110x_gdo2_disable(void) +{ + P1IE &= ~0x10; /* Disable interrupt for GDO2 */ + P1IFG &= ~0x10; /* Clear IFG for GDO2 */ +} + +void cc110x_before_send(void) +{ + // Disable GDO2 interrupt before sending packet + cc110x_gdo2_disable(); +} + +void cc110x_after_send(void) +{ + // Enable GDO2 interrupt after sending packet + cc110x_gdo2_enable(); +} + + +int cc110x_get_gdo0(void) { + return CC1100_GDO0; +} + +int cc110x_get_gdo1(void) { + return CC1100_GDO1; +} + +int cc110x_get_gdo2(void) { + return CC1100_GDO2; +} + +void cc110x_spi_cs(void) +{ + CC1100_CS_LOW; +} + +uint8_t cc110x_txrx(uint8_t data) +{ + /* Ensure TX Buf is empty */ + long c = 0; + IFG2 &= ~UTXIFG1; + IFG2 &= ~URXIFG1; + U1TXBUF = data; + while(!(IFG2 & UTXIFG1)) { + if (c++ == 1000000) { + puts("cc110x_txrx alarm()"); + } + } + /* Wait for Byte received */ + c = 0; + while(!(IFG2 & URXIFG1)) { + if (c++ == 1000000) { + puts("cc110x_txrx alarm()"); + } + } + return U1RXBUF; +} + + +void cc110x_spi_select(void) +{ + // Switch to GDO mode + P5SEL &= ~0x04; + P5DIR &= ~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 */ + P5SEL |= 0x04; +} + +void cc110x_spi_unselect(void) { + CC1100_CS_HIGH; +} + +void cc110x_init_interrupts(void) +{ + unsigned int state = disableIRQ(); /* Disable all interrupts */ + P1SEL = 0x00; /* must be <> 1 to use interrupts */ + P1IES |= 0x10; /* Enables external interrupt on low edge (for GDO2) */ + P1IE |= 0x10; /* Enable interrupt */ + P1IFG &= ~0x10; /* Clears the interrupt flag */ + P1IE &= ~0x08; /* Disable interrupt for GDO0 */ + P1IFG &= ~0x08; /* Clear IFG for GDO0 */ + restoreIRQ(state); /* Enable all interrupts */ +} + +void cc110x_spi_init(uint8_t clockrate) +{ + // Switch off async UART + while(!(U1TCTL & TXEPT)); // Wait for empty UxTXBUF register + IE2 &= ~(URXIE1 + UTXIE1); // Disable USART1 receive&transmit interrupt + ME2 &= ~(UTXE1 + URXE1); + P5DIR |= 0x0A; // output for CLK and SIMO + P5DIR &= ~(0x04); // input for SOMI + P5SEL |= 0x0E; // Set pins as SPI + + // Keep peripheral in reset state + U1CTL = SWRST; + + // 8-bit SPI Master 3-pin mode, with SMCLK as clock source + // CKPL works also, but not CKPH+CKPL or none of them!! + U1CTL |= CHAR + SYNC + MM; + U1TCTL = CKPH + SSEL1 + SSEL0 + STC; + + // Ignore clockrate argument for now, just use clock source/2 + // SMCLK = 8 MHz + U1BR0 = 0x02; // Ensure baud rate >= 2 + U1BR1 = 0x00; + U1MCTL = 0x00; // No modulation + U1RCTL = 0x00; // Reset Receive Control Register + + // Enable SPI mode + ME2 |= USPIE1; + + // Release for operation + U1CTL &= ~SWRST; +} + +/* + * CC1100 receive interrupt + */ +interrupt (PORT1_VECTOR) __attribute__ ((naked)) cc110x_isr(void){ + __enter_isr(); + /* Check IFG */ + if ((P1IFG & 0x10) != 0) { + P1IFG &= ~0x10; + cc110x_gdo2_irq(); + } + else if ((P2IFG & 0x08) != 0) { + cc110x_gdo0_irq(); + P1IE &= ~0x08; // Disable interrupt for GDO0 + P1IFG &= ~0x08; // Clear IFG for GDO0 + } else { + puts("cc110x_isr(): unexpected IFG!"); + /* Should not occur - only GDO1 and GDO2 interrupts are enabled */ + } + __exit_isr(); +} diff --git a/wsn430-v1_3b/include/board.h b/wsn430-v1_3b/include/board.h new file mode 100644 index 0000000000..ad864e132e --- /dev/null +++ b/wsn430-v1_3b/include/board.h @@ -0,0 +1,31 @@ +#ifndef _MSB_BOARD_H +#define _MSB_BOARD_H + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 800000uL +#define MSP430_HAS_DCOR 0 +#define MSP430_HAS_EXTERNAL_CRYSTAL 1 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x04 +#define LEDS_CONF_GREEN 0x05 +#define LEDS_CONF_BLUE 0x06 + +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED + +#define LED_GREEN_ON LEDS_PxOUT &=~LEDS_CONF_GREEN +#define LED_GREEN_OFF LEDS_PxOUT |= LEDS_CONF_GREEN +#define LED_GREEN_TOGGLE LEDS_PxOUT ^= LEDS_CONF_GREEN + +#define LED_BLUE_ON LEDS_PxOUT &=~LEDS_CONF_BLUE +#define LED_BLUE_OFF LEDS_PxOUT |= LEDS_CONF_BLUE +#define LED_BLUE_TOGGLE LEDS_PxOUT ^= LEDS_CONF_BLUE + +#include + +/** @} */ +#endif // _MSB_BOARD_H From 25b6ed699c19c7760575449c57ebd7706115029c Mon Sep 17 00:00:00 2001 From: Milan Babel Date: Tue, 28 May 2013 10:10:45 +0200 Subject: [PATCH 137/188] added wsn430-v1.4 also made some minor changes to shared wsn430-common files --- Makefile.base | 4 + wsn430-common/board_config.c | 7 + wsn430-common/board_init.c | 6 +- wsn430-common/include/board-conf.h | 7 + wsn430-v1_3b/driver_cc110x.c | 5 +- wsn430-v1_3b/include/board.h | 36 ++++- wsn430-v1_4/Makefile | 36 +++++ wsn430-v1_4/Makefile.dep | 1 + wsn430-v1_4/Makefile.include | 3 + wsn430-v1_4/driver_cc2420.c | 213 +++++++++++++++++++++++++++++ wsn430-v1_4/include/board.h | 61 +++++++++ 11 files changed, 371 insertions(+), 8 deletions(-) create mode 100644 wsn430-v1_4/Makefile create mode 100644 wsn430-v1_4/Makefile.dep create mode 100644 wsn430-v1_4/Makefile.include create mode 100644 wsn430-v1_4/driver_cc2420.c create mode 100644 wsn430-v1_4/include/board.h diff --git a/Makefile.base b/Makefile.base index 641eaf56cd..0b860294f9 100644 --- a/Makefile.base +++ b/Makefile.base @@ -17,6 +17,10 @@ ifeq ($(BOARD),wsn430-v1_3b) INCLUDES += -I$(RIOTBOARD)/wsn430-v1_3b/include/ INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ endif +ifeq ($(BOARD),wsn430-v1_4) + INCLUDES += -I$(RIOTBOARD)/wsn430-v1_4/include/ + INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ +endif ifeq ($(BOARD),chronos) INCLUDES += -I$(RIOTBOARD)/chronos/include/ INCLUDES += -I$(RIOTBOARD)/chronos/drivers/include/ diff --git a/wsn430-common/board_config.c b/wsn430-common/board_config.c index f22e513b20..4e9bc0b69c 100644 --- a/wsn430-common/board_config.c +++ b/wsn430-common/board_config.c @@ -1,3 +1,10 @@ +/** + * board-config.c. + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + #include #include #include diff --git a/wsn430-common/board_init.c b/wsn430-common/board_init.c index b7b523cf76..d89657017b 100644 --- a/wsn430-common/board_init.c +++ b/wsn430-common/board_init.c @@ -2,8 +2,8 @@ * board_init.c - Implementation of functions to init board. * Copyright (C) 2013 Milan Babel * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. */ #include "cpu.h" @@ -49,7 +49,7 @@ static void msb_ports_init(void) // Port 1: GDO, Flash, BSL TX P1SEL = 0x02; // Port1 Select: 00000010 = 0x02 P1OUT = 0x00; // Port1 Output: 00000000 = 0x00 - P1DIR = 0xE7; // Port1 Direction: 11100111 = 0xE7 + P1DIR = 0x87; // Port1 Direction: 10000111 = 0x87 // Port 2: GPIO, BSL RX, 1wire P2SEL = 0x04; // Port2 Select: 00000100 = 0x04 diff --git a/wsn430-common/include/board-conf.h b/wsn430-common/include/board-conf.h index e85c3128f2..7ebf0e03e6 100644 --- a/wsn430-common/include/board-conf.h +++ b/wsn430-common/include/board-conf.h @@ -1,3 +1,10 @@ +/** + * board-conf.h. + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + #ifndef BOARD_CONF_H #define BOARD_CONF_H diff --git a/wsn430-v1_3b/driver_cc110x.c b/wsn430-v1_3b/driver_cc110x.c index 39ca90bb15..89669e64f7 100644 --- a/wsn430-v1_3b/driver_cc110x.c +++ b/wsn430-v1_3b/driver_cc110x.c @@ -1,9 +1,10 @@ /* * driver_cc110x.c - Implementation of the board dependent cc1100 functions. + * Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will * Copyright (C) 2013 Milan Babel * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. */ #include diff --git a/wsn430-v1_3b/include/board.h b/wsn430-v1_3b/include/board.h index ad864e132e..ee09d10169 100644 --- a/wsn430-v1_3b/include/board.h +++ b/wsn430-v1_3b/include/board.h @@ -1,5 +1,35 @@ -#ifndef _MSB_BOARD_H -#define _MSB_BOARD_H +/** + * board.h - wsn430-v1_3b Board. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef _WSN_BOARD_H +#define _WSN_BOARD_H + +/** + * @defgroup wsn430-v1_3b Senslab WSN430 v1.3b + * @ingroup wsn430 + * +

Compontents

+\li MSP430 +\li CC1100 + +* @{ +*/ + +/** + * @file + * @brief wsn430-v1_3b Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Milan Babel + * @version $Revision$ + * + * @note $Id$ + */ //MSB430 core #define MSP430_INITIAL_CPU_SPEED 800000uL @@ -28,4 +58,4 @@ #include /** @} */ -#endif // _MSB_BOARD_H +#endif // _WSN_BOARD_H diff --git a/wsn430-v1_4/Makefile b/wsn430-v1_4/Makefile new file mode 100644 index 0000000000..1bc4eca767 --- /dev/null +++ b/wsn430-v1_4/Makefile @@ -0,0 +1,36 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = wsn430-v1_4_base.a + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I${RIOTBASE}/core/include/ +INCLUDES += -Iinclude/ -I$(RIOTBOARD)/wsn430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include +#INCLUDES += -I/usr/msp430/include/ + +all: $(BINDIR)$(ARCH) + $(MAKE) -C ../wsn430-common + +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + mkdir -p $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + $(MAKE) -C ../wsn430-common clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi \ No newline at end of file diff --git a/wsn430-v1_4/Makefile.dep b/wsn430-v1_4/Makefile.dep new file mode 100644 index 0000000000..52516208bc --- /dev/null +++ b/wsn430-v1_4/Makefile.dep @@ -0,0 +1 @@ +USEMODULE += msp430_common \ No newline at end of file diff --git a/wsn430-v1_4/Makefile.include b/wsn430-v1_4/Makefile.include new file mode 100644 index 0000000000..366d6cbcc8 --- /dev/null +++ b/wsn430-v1_4/Makefile.include @@ -0,0 +1,3 @@ +include $(RIOTBOARD)/$(BOARD)/Makefile.dep + +include $(RIOTBOARD)/wsn430-common/Makefile.include \ No newline at end of file diff --git a/wsn430-v1_4/driver_cc2420.c b/wsn430-v1_4/driver_cc2420.c new file mode 100644 index 0000000000..c653c9ba3a --- /dev/null +++ b/wsn430-v1_4/driver_cc2420.c @@ -0,0 +1,213 @@ + /* + * driver_cc2420.c - Implementation of the board dependent cc2420 functions. + * Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#include + +#include +#include +#include +#include + +#include + +#define CC2420_RESETn_PIN 0x80 +#define CC2420_VREGEN_PIN 0x01 + +#define CC2420_GDO0_PIN 0x08 +#define CC2420_GDO2_PIN 0x10 +#define CC2420_SFD_PIN 0x20 +#define CC2420_CCA_PIN 0x40 + +#define CC2420_GDO0 (P1IN & CC2420_GDO0_PIN) // read serial I/O (GDO0) +#define CC2420_GDO2 (P1IN & CC2420_GDO2_PIN) // read serial I/O (GDO2) +#define CC2420_SFD (P1IN & CC2420_SFD_PIN) // read serial I/0 (SFD) +#define CC2420_CCA (P1IN & CC2420_CCA_PIN) // read serial I/O (CCA) + + +#define CC2420_CS_LOW (P4OUT &= ~0x04) +#define CC2420_CS_HIGH (P4OUT |= 0x04) + +#define CC2420_GDO1_LOW_COUNT (2700) // loop count (timeout ~ 500 us) to wait +#define CC2420_GDO1_LOW_RETRY (100) // max. retries for GDO1 to go low + +volatile int abort_count; +volatile int retry_count = 0; + +void cc2420_reset(void) +{ + P3OUT |= CC2420_VREGEN_PIN; + P1OUT &= ~CC2420_RESETn_PIN; + hwtimer_wait(500); + P1OUT |= CC2420_RESETn_PIN; +} + +void cc2420_gdo0_enable(void) +{ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ + P1IE |= CC2420_GDO0_PIN; /* Enable interrupt for GDO0 */ +} + +void cc2420_gdo0_disable(void) +{ + P1IE &= ~CC2420_GDO0_PIN; /* Disable interrupt for GDO0 */ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ +} + +void cc2420_gdo2_enable(void) +{ + P1IFG &= ~CC2420_GDO2_PIN; /* Clear IFG for GDO2 */ + P1IE |= CC2420_GDO2_PIN; /* Enable interrupt for GDO2 */ +} + +void cc2420_gdo2_disable(void) +{ + P1IE &= ~CC2420_GDO2_PIN; /* Disable interrupt for GDO2 */ + P1IFG &= ~CC2420_GDO2_PIN; /* Clear IFG for GDO2 */ +} + +void cc2420_before_send(void) +{ + // Disable SFD interrupt before sending packet + // However this is not used atm +} + +void cc2420_after_send(void) +{ + // Enable SFD interrupt after sending packet + // However this is not used atm +} + + +int cc2420_get_gdo0(void) +{ + return CC2420_GDO0; +} + +int cc2420_get_gdo2(void) +{ + return CC2420_GDO2; +} + +int cc2420_get_sfd(void) +{ + return CC2420_SFD; +} + +void cc2420_spi_cs(void) +{ + CC2420_CS_LOW; +} + +uint8_t cc2420_txrx(uint8_t data) +{ + /* Ensure TX Buf is empty */ + long c = 0; + IFG2 &= ~UTXIFG1; + IFG2 &= ~URXIFG1; + U1TXBUF = data; + while(!(IFG2 & UTXIFG1)) { + if (c++ == 1000000) { + puts("cc2420_txrx alarm()"); + } + } + /* Wait for Byte received */ + c = 0; + while(!(IFG2 & URXIFG1)) { + if (c++ == 1000000) { + puts("cc2420_txrx alarm()"); + } + } + return U1RXBUF; +} + + +void cc2420_spi_select(void) +{ + CC2420_CS_LOW; +} + +void cc2420_spi_unselect(void) { + CC2420_CS_HIGH; +} + +void cc2420_init_interrupts(void) +{ + unsigned int state = disableIRQ(); /* Disable all interrupts */ + P1SEL = 0x00; /* must be <> 1 to use interrupts */ + P1IES |= CC2420_GDO2_PIN; /* Enables external interrupt on falling edge (for GDO2) */ + P1IE |= CC2420_GDO2_PIN; /* Enable interrupt */ + P1IFG &= ~CC2420_GDO2_PIN; /* Clears the interrupt flag */ + P1IES |= CC2420_SFD_PIN; /* Enables external interrupt on falling edge (for GDO2) */ + P1IE |= CC2420_SFD_PIN; /* Enable interrupt */ + P1IFG &= ~CC2420_SFD_PIN; /* Clears the interrupt flag */ + P1IE &= ~CC2420_GDO0_PIN; /* Disable interrupt for GDO0 */ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ + restoreIRQ(state); /* Enable all interrupts */ +} + +void cc2420_spi_init(void) +{ + // Switch off async UART + while(!(U1TCTL & TXEPT)); // Wait for empty UxTXBUF register + IE2 &= ~(URXIE1 + UTXIE1); // Disable USART1 receive&transmit interrupt + ME2 &= ~(UTXE1 + URXE1); + P5DIR |= 0x0A; // output for CLK and SIMO + P5DIR &= ~(0x04); // input for SOMI + P5SEL |= 0x0E; // Set pins as SPI + + // Keep peripheral in reset state + U1CTL = SWRST; + + // 8-bit SPI Master 3-pin mode, with SMCLK as clock source + // CKPL works also, but not CKPH+CKPL or none of them!! + U1CTL |= CHAR + SYNC + MM; + U1TCTL = CKPH + SSEL1 + SSEL0 + STC; + + // Ignore clockrate argument for now, just use clock source/2 + // SMCLK = 8 MHz + U1BR0 = 0x02; // Ensure baud rate >= 2 + U1BR1 = 0x00; + U1MCTL = 0x00; // No modulation + U1RCTL = 0x00; // Reset Receive Control Register + + // Enable SPI mode + ME2 |= USPIE1; + + // Release for operation + U1CTL &= ~SWRST; +} + +/* + * CC1100 receive interrupt + */ +interrupt (PORT1_VECTOR) __attribute__ ((naked)) cc2420_isr(void){ + __enter_isr(); + /* Check IFG */ + if ((P1IFG & CC2420_GDO2_PIN) != 0) { + puts("rx interrupt"); + P1IFG &= ~CC2420_GDO2_PIN; + cc2420_rx_irq(); + } + else if ((P1IFG & CC2420_GDO0_PIN) != 0) { + cc2420_rxoverflow_irq(); + puts("[CC2420] rxfifo overflow"); + //P1IE &= ~CC2420_GDO0_PIN; // Disable interrupt for GDO0 + P1IFG &= ~CC2420_GDO0_PIN; // Clear IFG for GDO0 + } else if ((P1IFG & CC2420_SFD_PIN) != 0) { + puts("sfd interrupt"); + P1IFG &= ~CC2420_SFD_PIN; + cc2420_switch_to_rx(); + } + + else { + puts("cc2420_isr(): unexpected IFG!"); + /* Should not occur - only GDO1 and GDO2 interrupts are enabled */ + } + __exit_isr(); +} diff --git a/wsn430-v1_4/include/board.h b/wsn430-v1_4/include/board.h new file mode 100644 index 0000000000..3cb86d1366 --- /dev/null +++ b/wsn430-v1_4/include/board.h @@ -0,0 +1,61 @@ +/** + * board.h - wsn430-v1_4 Board. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef _WSN_BOARD_H +#define _WSN_BOARD_H + +/** + * @defgroup wsn430-v1_4 Senslab WSN430 v1.4 + * @ingroup wsn430 + * +

Compontents

+\li MSP430 +\li CC2420 + +* @{ +*/ + +/** + * @file + * @brief wsn430-v1_4 Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Milan Babel + * @version $Revision$ + * + * @note $Id$ + */ + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 800000uL +#define MSP430_HAS_DCOR 0 +#define MSP430_HAS_EXTERNAL_CRYSTAL 1 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x04 +#define LEDS_CONF_GREEN 0x05 +#define LEDS_CONF_BLUE 0x06 + +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED + +#define LED_GREEN_ON LEDS_PxOUT &=~LEDS_CONF_GREEN +#define LED_GREEN_OFF LEDS_PxOUT |= LEDS_CONF_GREEN +#define LED_GREEN_TOGGLE LEDS_PxOUT ^= LEDS_CONF_GREEN + +#define LED_BLUE_ON LEDS_PxOUT &=~LEDS_CONF_BLUE +#define LED_BLUE_OFF LEDS_PxOUT |= LEDS_CONF_BLUE +#define LED_BLUE_TOGGLE LEDS_PxOUT ^= LEDS_CONF_BLUE + +#include + +/** @} */ +#endif // _WSN_BOARD_H From abb028767c89cde98e514e9a09bd6ab8e9a6ff84 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Mon, 10 Jun 2013 16:15:38 +0200 Subject: [PATCH 138/188] * fixed includes for msb-a2 --- msba2-common/board_common_init.c | 1 - msba2/Makefile.include | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/msba2-common/board_common_init.c b/msba2-common/board_common_init.c index 8d7c359625..7e4eb2c126 100644 --- a/msba2-common/board_common_init.c +++ b/msba2-common/board_common_init.c @@ -40,7 +40,6 @@ and the mailinglist (subscription via web site) * * @note $Id$ */ -#include #include #include #include diff --git a/msba2/Makefile.include b/msba2/Makefile.include index 741b952a92..1258b6e330 100644 --- a/msba2/Makefile.include +++ b/msba2/Makefile.include @@ -1,3 +1,3 @@ -export INCLUDES += -I$(RIOTBOARD)/msba2-common/include +export INCLUDES += -Iinclude -I$(RIOTBOARD)/msba2-common/include include $(RIOTBOARD)/msba2-common/Makefile.include From 95ba2fc3eac1e83ee9be7ec1e7fc4b4e8963636c Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 11 Jun 2013 11:37:29 +0200 Subject: [PATCH 139/188] * added missing msp430_common module to Makefile --- msb-430-common/Makefile.include | 1 + 1 file changed, 1 insertion(+) diff --git a/msb-430-common/Makefile.include b/msb-430-common/Makefile.include index 8fc09d2874..4adcbb6dd1 100644 --- a/msb-430-common/Makefile.include +++ b/msb-430-common/Makefile.include @@ -20,4 +20,5 @@ endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" +export USEMODULE += msp430_common export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ From eda5afc09dd75b9d65af7009776282fc081cbfef Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 3 Jun 2013 19:37:22 +0200 Subject: [PATCH 140/188] make stdin/stdout customizable stub --- native/native-uart0.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/native/native-uart0.c b/native/native-uart0.c index e13447bb0e..b43a7dcbe4 100644 --- a/native/native-uart0.c +++ b/native/native-uart0.c @@ -1,17 +1,20 @@ /* - * TODO: - * make stdin/stdout customizable. + * native uart0 implementation */ #include #include #include + #include #include "cpu.h" #include "debug.h" #include "board_uart0.h" +int _native_uart_in; +int _native_uart_out; + fd_set _native_uart_rfds; static inline int uart0_puts(char *astring, int length) @@ -24,10 +27,11 @@ void _native_handle_uart0_input() char buf[42]; int nread; + DEBUG("_native_handle_uart0_input\n"); _native_in_syscall = 0; _native_in_isr = 1; - nread = read(0, buf, sizeof(buf)); + nread = read(_native_uart_in, buf, sizeof(buf)); if (nread == -1) { err(1, "_native_handle_uart0_input(): read()"); } @@ -42,13 +46,17 @@ void _native_handle_uart0_input() void _native_init_uart0() { - /* Watch stdin (fd 0) to see when it has input. */ + _native_uart_out = STDOUT_FILENO; + _native_uart_in = STDIN_FILENO; + + /* set fds for select in lpm */ FD_ZERO(&_native_uart_rfds); - FD_SET(0, &_native_uart_rfds); + FD_SET(_native_uart_in, &_native_uart_rfds); + puts("RIOT native uart0 initialized."); } int putchar(int c) { - write(1, &c, 1); + write(_native_uart_out, &c, 1); return 0; } From c6061b8b40e084a6cc94ee078fb2a7d48c6f1b7e Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 12 Jun 2013 16:23:34 +0200 Subject: [PATCH 141/188] moved native board drivers into separate directory split up drivers to avoid building unnecessary files --- native/Makefile | 11 ++++++---- native/Makefile.include | 4 ++-- native/drivers/Makefile | 30 +++++++++++++++++++++++++++ native/{ => drivers}/native-led.c | 0 native/{ => drivers}/native-ltc4150.c | 0 native/{ => drivers}/native-uart0.c | 0 6 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 native/drivers/Makefile rename native/{ => drivers}/native-led.c (100%) rename native/{ => drivers}/native-ltc4150.c (100%) rename native/{ => drivers}/native-uart0.c (100%) diff --git a/native/Makefile b/native/Makefile index 86ddb4a6ff..ded96b6cf2 100644 --- a/native/Makefile +++ b/native/Makefile @@ -2,14 +2,16 @@ SRC = $(wildcard *.c) BINDIR = bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines DEP = $(SRC:%.c=$(BINDIR)%.d) +export ARCH = native_base.a INCLUDES += -I$(RIOTBASE)/cpu/native/include/ INCLUDES += -I$(RIOTBOARD)/native/include/ -all: $(BINDIR)native_base.a +all: $(BINDIR)$(ARCH) + $(MAKE) -C drivers -$(BINDIR)native_base.a: $(OBJ) - $(AR) rcs $(BINDIR)native_base.a $(OBJ) +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) # pull in dependency info for *existing* .o files -include $(OBJ:.o=.d) @@ -23,6 +25,7 @@ $(BINDIR)%.o: %.c # remove compilation products clean: - rm -f $(BINDIR)native_base.a $(OBJ) $(DEP) + ${MAKE} -C drivers clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) -rmdir -p $(BINDIR) diff --git a/native/Makefile.include b/native/Makefile.include index d360b2248f..e8e5d48e4d 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -5,7 +5,7 @@ export CPU = native export PREFIX = #export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar -export CFLAGS = -std=gnu99 -Wall -m32 +export CFLAGS += -std=gnu99 -Wall -m32 export ASFLAGS = export AS = $(PREFIX)as export LINK = $(PREFIX)gcc @@ -14,7 +14,7 @@ export OBJCOPY = $(PREFIX)objcopy FLASHER = lpc2k_pgm TERM = pyterm.py -LINKFLAGS = -m32 +LINKFLAGS = -m32 -gc ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 diff --git a/native/drivers/Makefile b/native/drivers/Makefile new file mode 100644 index 0000000000..f0516a8530 --- /dev/null +++ b/native/drivers/Makefile @@ -0,0 +1,30 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(BINDIR)native-led.o +ifneq (,$(findstring ltc4150,$(USEMODULE))) + OBJ += $(BINDIR)native-ltc4150.o +endif +ifneq (,$(findstring uart0,$(USEMODULE))) + OBJ += $(BINDIR)native-uart0.o +endif +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/native/include/ + +$(BINDIR)native_drivers.a: $(OBJ) + @$(AR) rcs $(BINDIR)${ARCH} $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + @$(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)" | cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products + +clean: + rm -f $(OBJ) $(DEP) + diff --git a/native/native-led.c b/native/drivers/native-led.c similarity index 100% rename from native/native-led.c rename to native/drivers/native-led.c diff --git a/native/native-ltc4150.c b/native/drivers/native-ltc4150.c similarity index 100% rename from native/native-ltc4150.c rename to native/drivers/native-ltc4150.c diff --git a/native/native-uart0.c b/native/drivers/native-uart0.c similarity index 100% rename from native/native-uart0.c rename to native/drivers/native-uart0.c From 4c60661434a1108787f6af3aa66a07b1c16ac466 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Wed, 12 Jun 2013 16:27:17 +0200 Subject: [PATCH 142/188] * fixed includes for msba2 --- msba2-common/Makefile.include | 2 ++ msba2/Makefile.include | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index 7ba1eae0e0..b8626464fc 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -21,3 +21,5 @@ endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = $(PORT) $(PROJBINDIR)/$(PROJECT).hex include $(RIOTBOARD)/msba2-common/Makefile.dep + +export INCLUDES += -I$(RIOTCPU)/lpc2387/include diff --git a/msba2/Makefile.include b/msba2/Makefile.include index 1258b6e330..80751c020a 100644 --- a/msba2/Makefile.include +++ b/msba2/Makefile.include @@ -1,3 +1,3 @@ -export INCLUDES += -Iinclude -I$(RIOTBOARD)/msba2-common/include +export INCLUDES += -I$(RIOTBOARD)/msba2/include -I$(RIOTBOARD)/msba2-common/include include $(RIOTBOARD)/msba2-common/Makefile.include From 5b696d038e52b9119613589852efed2721d17369 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Tue, 25 Jun 2013 15:31:54 +0200 Subject: [PATCH 143/188] * fixed include path --- wsn430-v1_4/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wsn430-v1_4/Makefile b/wsn430-v1_4/Makefile index 1bc4eca767..d6b578d59f 100644 --- a/wsn430-v1_4/Makefile +++ b/wsn430-v1_4/Makefile @@ -9,7 +9,7 @@ INCLUDES += -I${RIOTBASE}/core/include/ INCLUDES += -Iinclude/ -I$(RIOTBOARD)/wsn430-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include -#INCLUDES += -I/usr/msp430/include/ +INCLUDES += -I$(RIOTBASE)/sys/net/ all: $(BINDIR)$(ARCH) $(MAKE) -C ../wsn430-common @@ -33,4 +33,4 @@ clean: rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) @if [ -d $(BINDIR) ] ; \ then rmdir $(BINDIR) ; \ - fi \ No newline at end of file + fi From fdbf28fd44a3a7bb02fb11e359d3fd80f237aca6 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 15 Jul 2013 20:57:12 +0200 Subject: [PATCH 144/188] moved native internal functions declarations --- native/board_init.c | 2 ++ native/drivers/native-uart0.c | 2 +- native/include/board.h | 6 ------ native/include/board_internal.h | 6 ++++++ 4 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 native/include/board_internal.h diff --git a/native/board_init.c b/native/board_init.c index d32c653dc9..fa1a319afc 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -15,6 +15,8 @@ #include #include "board.h" +#include "board_internal.h" + /** * Nothing to initialize at the moment. * Turns the red LED on and the green LED off. diff --git a/native/drivers/native-uart0.c b/native/drivers/native-uart0.c index b43a7dcbe4..3af009eee4 100644 --- a/native/drivers/native-uart0.c +++ b/native/drivers/native-uart0.c @@ -17,7 +17,7 @@ int _native_uart_out; fd_set _native_uart_rfds; -static inline int uart0_puts(char *astring, int length) +inline int uart0_puts(char *astring, int length) { return puts(astring); } diff --git a/native/include/board.h b/native/include/board.h index 69e40eb383..18ee528271 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -21,9 +21,3 @@ void LED_GREEN_TOGGLE(void); void LED_RED_OFF(void); void LED_RED_ON(void); void LED_RED_TOGGLE(void); - -#ifdef MODULE_UART0 -#include -extern fd_set _native_uart_rfds; -extern void _native_handle_uart0_input(void); -#endif diff --git a/native/include/board_internal.h b/native/include/board_internal.h new file mode 100644 index 0000000000..752cbcdfb5 --- /dev/null +++ b/native/include/board_internal.h @@ -0,0 +1,6 @@ +#ifdef MODULE_UART0 +#include +extern fd_set _native_uart_rfds; +void _native_handle_uart0_input(void); +void _native_init_uart0(void); +#endif From 0c02095a42842cee2a69a6b329e2baa4313c6a39 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Thu, 18 Jul 2013 16:04:24 +0200 Subject: [PATCH 145/188] rename kernel_intern.h german "intern" to english "internal" --- msb-430-common/board_init.c | 2 +- wsn430-common/board_init.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index 4673600445..e32945a0cb 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -1,6 +1,6 @@ #include "cpu.h" #include "board.h" -#include "kernel_intern.h" +#include "kernel_internal.h" #include "msp430.h" #include "debug.h" diff --git a/wsn430-common/board_init.c b/wsn430-common/board_init.c index d89657017b..986a8ed10f 100644 --- a/wsn430-common/board_init.c +++ b/wsn430-common/board_init.c @@ -8,7 +8,7 @@ #include "cpu.h" #include "board.h" -#include "kernel_intern.h" +#include "kernel_internal.h" #include "msp430.h" #include "debug.h" From a256a7767aa26dfc046f91fa3fea2265e544e198 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Thu, 18 Jul 2013 16:06:02 +0200 Subject: [PATCH 146/188] fixed old-style-declaration warning board_init.c:7:1: warning: 'static' is not at beginning of declaration [-Wold-style-declaration] --- msb-430-common/board_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index e32945a0cb..56af75498d 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -4,7 +4,7 @@ #include "msp430.h" #include "debug.h" -volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; +static volatile uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; /*---------------------------------------------------------------------------*/ static uint8_t calc_umctl(uint16_t br) { From c99539c5cbcfab5029a3525c86c7e2162bab20a9 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 24 Jul 2013 11:01:05 +0200 Subject: [PATCH 147/188] do not omit exported CFLAGS --- msba2-common/Makefile.include | 3 ++- redbee-econotag/Makefile.include | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index b8626464fc..082a2e57f1 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -3,9 +3,10 @@ export CPU = lpc2387 # toolchain config export PREFIX = @arm-none-eabi- +#export PREFIX = @arm-elf- export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar -export CFLAGS = -std=gnu99 -O2 -Wall -Wstrict-prototypes -mcpu=arm7tdmi-s -gdwarf-2 +export CFLAGS += -std=gnu99 -O2 -Wall -Wstrict-prototypes -mcpu=arm7tdmi-s -gdwarf-2 export ASFLAGS = -gdwarf-2 -mcpu=arm7tdmi-s export AS = $(PREFIX)as export LINK = $(PREFIX)gcc diff --git a/redbee-econotag/Makefile.include b/redbee-econotag/Makefile.include index ee087fb781..7275c2daf6 100644 --- a/redbee-econotag/Makefile.include +++ b/redbee-econotag/Makefile.include @@ -5,7 +5,7 @@ export CPU = mc1322x export PREFIX = @arm-none-eabi- export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar -export CFLAGS = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ +export CFLAGS += -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ -msoft-float -mthumb-interwork -fno-strict-aliasing -fno-common \ -ffixed-r8 -ffunction-sections -ffreestanding -fno-builtin \ -nodefaultlibs -Wcast-align -Wall -Wstrict-prototypes -Wextra \ From b4ee555d17194f59efbadd9c33b8076aaf0c6af6 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 24 Jul 2013 22:01:33 +0200 Subject: [PATCH 148/188] coding convention fixes --- msba2-common/board_common_init.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/msba2-common/board_common_init.c b/msba2-common/board_common_init.c index 7e4eb2c126..a437cce2b7 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; From 4a48f10e2741ae53b6fc43c2f55d72d4bcfc0613 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 24 Jul 2013 22:12:12 +0200 Subject: [PATCH 149/188] split up CFLAGS for bootload and the rest --- redbee-econotag/Makefile.include | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/redbee-econotag/Makefile.include b/redbee-econotag/Makefile.include index 7275c2daf6..26738a93fc 100644 --- a/redbee-econotag/Makefile.include +++ b/redbee-econotag/Makefile.include @@ -5,11 +5,14 @@ export CPU = mc1322x export PREFIX = @arm-none-eabi- export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar -export CFLAGS += -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ +export CFLAGS = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ + +export CFLAGS_BASIC = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ -msoft-float -mthumb-interwork -fno-strict-aliasing -fno-common \ -ffixed-r8 -ffunction-sections -ffreestanding -fno-builtin \ -nodefaultlibs -Wcast-align -Wall -Wstrict-prototypes -Wextra \ -Os -pipe +export CFLAGS += $(CFLAGS_BASIC) -mthumb $(warning TODO add -mthumb) export AFLAGS = -Wa,-gstabs $(CFLAGS) export AS = $(PREFIX)as From 6d5601a70aae3c705de6a36b819318eaadd616a3 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 29 Jul 2013 16:00:52 +0200 Subject: [PATCH 150/188] added gpioint as dependency for original cc110x driver --- msba2-common/Makefile.dep | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/msba2-common/Makefile.dep b/msba2-common/Makefile.dep index 5182f34f4b..bffa6c72d7 100644 --- a/msba2-common/Makefile.dep +++ b/msba2-common/Makefile.dep @@ -1,3 +1,9 @@ +ifneq (,$(findstring cc110x,$(USEMODULE))) + ifeq (,$(findstring gpioint,$(USEMODULE))) + USEMODULE += gpioint + endif +endif + ifneq (,$(findstring cc110x_ng,$(USEMODULE))) ifeq (,$(findstring cc110x_spi,$(USEMODULE))) USEMODULE += cc110x_spi From dc0a5bf595760c1e16e5764f574ca0d913c88c12 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 29 Jul 2013 16:41:43 +0200 Subject: [PATCH 151/188] coding convention fixes (mostly due to astyle) --- chronos/board_init.c | 28 +- chronos/drivers/battery.c | 5 +- chronos/drivers/buzzer.c | 11 +- chronos/drivers/cc430-cc110x.c | 67 +- chronos/drivers/display.c | 609 ++++---- chronos/drivers/display1.c | 320 ++--- chronos/drivers/display_putchar.c | 15 +- chronos/drivers/include/battery.h | 2 +- chronos/drivers/include/buzzer.h | 2 +- chronos/drivers/include/display.h | 538 +++---- chronos/drivers/include/display_putchar.h | 2 +- chronos/putchar.c | 3 +- msb-430-common/board_config.c | 20 +- msb-430-common/board_init.c | 311 ++-- msb-430-common/include/board-conf.h | 2 +- msb-430-common/uart1.c | 2 +- msb-430h/driver_cc110x.c | 243 ++-- msba2-common/board_common_init.c | 8 +- msba2-common/board_config.c | 11 +- msba2-common/drivers/include/uart0.h | 2 +- msba2-common/drivers/msba2-cc110x.c | 236 +-- msba2-common/drivers/msba2-ltc4150.c | 20 +- msba2-common/drivers/msba2-uart0.c | 90 +- msba2-common/lpc2387-timer3.c | 26 +- msba2-common/tools/src/boot.h | 4 +- msba2-common/tools/src/boot_23xx.c | 2 +- msba2-common/tools/src/boot_2xxx.c | 2 +- msba2-common/tools/src/chipinfo.c | 219 ++- msba2-common/tools/src/chipinfo.h | 18 +- msba2-common/tools/src/cksum_test.c | 43 +- msba2-common/tools/src/control_2xxx.c | 32 +- msba2-common/tools/src/download.c | 1587 ++++++++++++--------- msba2-common/tools/src/download.h | 2 +- msba2-common/tools/src/gui.c | 499 ++++--- msba2-common/tools/src/ihex.c | 327 +++-- msba2-common/tools/src/lpc2k_pgm.c | 57 +- msba2-common/tools/src/pseudoterm.c | 91 +- msba2-common/tools/src/serial.c | 489 ++++--- msba2-common/tools/src/serial.h | 2 +- msba2-common/tools/src/settings.c | 209 +-- msba2-common/tools/src/settings.h | 8 +- msba2-common/tools/src/uuencode.c | 109 +- msba2/board_init.c | 13 +- msba2/include/board.h | 2 +- native/native-ltc4150.c | 3 +- olimex_lpc2148/board_init.c | 104 +- olimex_lpc2148/rs232.c | 140 +- olimex_lpc2148/tick.c | 16 +- pttu/board_init.c | 178 +-- redbee-econotag/board_init.c | 9 +- redbee-econotag/drivers/gpio.c | 65 +- redbee-econotag/drivers/include/gpio.h | 32 +- redbee-econotag/drivers/include/uart.h | 150 +- redbee-econotag/drivers/redbee_uart.c | 70 +- redbee-econotag/drivers/redbee_uart1.c | 30 +- redbee-econotag/drivers/redbee_uart2.c | 30 +- redbee-econotag/tools/ftditools/bbmc.c | 770 +++++----- redbee-econotag/tools/mc1322x-load.c | 534 ++++--- 58 files changed, 4619 insertions(+), 3800 deletions(-) diff --git a/chronos/board_init.c b/chronos/board_init.c index 95e5dfd3a7..db2326701f 100644 --- a/chronos/board_init.c +++ b/chronos/board_init.c @@ -3,7 +3,8 @@ #include #include -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 6ca24a3b67..13e50dc102 100644 --- a/chronos/drivers/battery.c +++ b/chronos/drivers/battery.c @@ -2,12 +2,13 @@ #include #include -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 b8f5327450..3d4d15061d 100644 --- a/chronos/drivers/buzzer.c +++ b/chronos/drivers/buzzer.c @@ -3,11 +3,12 @@ #include #include -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 0a38b68b7b..d606d5bfd5 100644 --- a/chronos/drivers/cc430-cc110x.c +++ b/chronos/drivers/cc430-cc110x.c @@ -9,73 +9,86 @@ #include //#include -#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 f33cd6eaf1..b93c820e1e 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); +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); - /* Clear blink segments */ - *(lcdmem+0x20) = (uint8_t)(*(lcdmem+0x20) & ~bitmask); - } - else if (state == SEG_OFF_BLINK_OFF) { - /* Clear segments */ - *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); - /* Clear blink segments */ - *(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); - } + 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); -} + /* Remove specified number of leading '0', always keep last one */ + i = 0; -void display_value1(uint8_t segments, uint32_t value, uint8_t digits, uint8_t blanks, uint8_t disp_mode) { - char *str; + while ((itoa_str[i] == '0') && (i < digits1 - 1)) { + if (blanks > 0) { + /* Convert only specified number of leading '0' */ + itoa_str[i] = ' '; + blanks--; + } - str = itoa(value, digits, blanks); + i++; + } - /* Display string in blink mode */ - display_chars(segments, str, disp_mode); + return (itoa_str); } -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_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_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]; +void display_symbol(uint8_t symbol, uint8_t mode) +{ + uint8_t *lcdmem; + uint8_t bits; + uint8_t bitmask; - /* 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; - } + if (symbol <= LCD_SEG_L2_DP) { + /* Get LCD memory address for symbol from table */ + lcdmem = (uint8_t *)segments_lcdmem[symbol]; - /* 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; + /* Get bits for symbol from table */ + bits = segments_bitmask[symbol]; - /* 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); - } -} + /* Bitmask for symbols equals bits */ + bitmask = bits; -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; - break; - 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; - break; - 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; - break; - 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; - break; - 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; - break; - 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; - break; - 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; - break; - } - - /* Write to consecutive digits */ - for(i=0; i= 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; + break; + + 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; + break; + + 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; + break; + + 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; + break; + + 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; + break; + + 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; + break; + + 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; + 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); + } +} + +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 a45c74625e..461c0c0097 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 ca0e9b396b..95498ea8e0 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 c6381b721b..e1f1569799 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 1786b0c513..47ccb81112 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 3b7c2e131f..533ce1e1db 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 + struct { + /* Line1 + Line2 + Icons*/ + uint16_t full_update : 1; /* 1 = Redraw all content */ + uint16_t partial_update : 1; /* 1 = Update changes */ - // 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) + /* 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 +/* ************************************************************************************************* */ +/* Defines section */ -// Display function modes -#define DISPLAY_LINE_UPDATE_FULL (BIT0) -#define DISPLAY_LINE_UPDATE_PARTIAL (BIT1) -#define DISPLAY_LINE_CLEAR (BIT2) +/* 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) +/* Definitions for line view style */ +#define DISPLAY_DEFAULT_VIEW (0u) +#define DISPLAY_ALTERNATIVE_VIEW (1u) +#define DISPLAY_ALTERNATIVE2_VIEW (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) +/* Definitions for line access */ +#define LINE1 (1u) +#define LINE2 (2u) -// 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 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 504ece6ebd..b903fc1db9 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 436d350f51..cefcb3281b 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 f22e513b20..14b8d00e31 100644 --- a/msb-430-common/board_config.c +++ b/msb-430-common/board_config.c @@ -4,16 +4,18 @@ #include #include -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 4673600445..0617d7bf53 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -7,201 +7,218 @@ volatile static 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 + 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 + 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 + // 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 + 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 + 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 + 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(); + UCTL1 &= ~SWRST; + //clock_init(); + eint(); } /*---------------------------------------------------------------------------*/ void msp430_init_dco() { - #if MSP430_HAS_EXTERNAL_CRYSTAL - /*------------------ use external oszillator -----------------------*/ - uint16_t i; +#if MSP430_HAS_EXTERNAL_CRYSTAL + /*------------------ use external oszillator -----------------------*/ + uint16_t i; - // Stop watchdog - WDTCTL = WDTPW + WDTHOLD; + // Stop watchdog + WDTCTL = WDTPW + WDTHOLD; - //Init crystal for mclk - //XT2 = HF XTAL - BCSCTL1 = RSEL2; + //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 + // Wait for xtal to stabilize + do { + IFG1 &= ~OFIFG; // Clear oscillator fault flag - unsigned int compare, oldcapture = 0; - unsigned int i; + 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 + 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 + // 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 */ + WDTCTL = WDTPW + WDTHOLD; /* Stop WDT */ + BCSCTL1 |= DIVA1 + DIVA0; /* ACLK = LFXT1CLK/8 */ - CCTL2 = CCIS0 + CM0 + CAP; // Define CCR2, CAP, ACLK - TACTL = TASSEL1 + TACLR + MC1; // SMCLK, continous mode + 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 (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 */ + while ((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occured! */ - 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 &= ~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 e85c3128f2..9db51d9454 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 7abad1d4e3..2b22b3171b 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 9316e8bf56..deb6835fd2 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 +// #include // #include // #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 8d7c359625..61020ac862 100644 --- a/msba2-common/board_common_init.c +++ b/msba2-common/board_common_init.c @@ -82,7 +82,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; @@ -103,9 +104,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 496a077961..a7207c895d 100644 --- a/msba2-common/board_config.c +++ b/msba2-common/board_config.c @@ -3,10 +3,12 @@ #include #include -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 0c580becc2..b0861b2b15 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 b0a5854446..b5bde7cbfc 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; + // configure chip-select + FIO1DIR |= BIT21; + FIO1SET = BIT21; - // Power - PCONP |= PCSSP0; // Enable power for SSP0 (default is on) + // 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 + // 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; + // 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; + // 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 + } - // 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 4e6534c022..aba9085189 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, <c4150_interrupt); +void __attribute__((__no_instrument_function__)) ltc4150_enable_int(void) +{ + gpioint_set(0, BIT4, GPIOINT_FALLING_EDGE, <c4150_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 ccfc6d8e04..5db2ca0da9 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> 0) & 255; - b[1] = (sum >> 8) & 255; - b[2] = (sum >> 16) & 255; - b[3] = (sum >> 24) & 255; - put_ihex_data(0x14, 4, b); + 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--; - } - return sum; + while (num > 0) { + sum += *data++; + num--; + } + + return sum; } static int num_lines(const char *buf) { - const char *p; - int count=0; + const char *p; + int count = 0; - p = buf; - while (p != NULL) { - p = strstr(p, "\r\n"); - if (p != NULL) { - count++; - p += 2; - } - } - return count; + 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]; + 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); - } + 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; + 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_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 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 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 UNLOCK: + switch (event) { + case BEGIN: + xmit_cmd("U 23130\r\n", 3); + return; - - 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 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_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 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 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_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 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_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 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_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_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_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_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; + 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; - } + 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; - len = strlen(cmd); + if (cmd == NULL || *cmd == '\0') { + return; + } + + 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); - 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; + snprintf(expected_echo_buf, sizeof(expected_echo_buf), "%s", cmd); - response_timer = max_time; + 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; + + 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 "); + printf(" "); #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]; - } + // ignore incorrect echo (will timeout) + expected_echo_ptr = NULL; + return; + } - // 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); - } + 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 4d57bfa5d0..b6b961049f 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 ce6d13c96e..0d4b18d8da 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; - if (!S_ISREG(file_stats.st_mode)) return 0; - return 1; + r = stat(filename, &file_stats); + + if (r != 0) { + return 0; + } + + if (!S_ISREG(file_stats.st_mode)) { + return 0; + } + + return 1; } void done_program(int still_in_bootloader) { - download_in_progress = 0; + 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); + 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); + 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_user_code(); + 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); - } + 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(); + 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 (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; + 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; + 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; + 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); - } - } + 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; + 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); - } - } + 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_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_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_main(); } void create_window(int *argc, char ***argv) { - GList *gtk_baud_list=NULL; - int i; + GList *gtk_baud_list = NULL; + int i; - gtk_init(argc, argv); + 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_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); + 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); + program_button = gtk_button_new_with_label("Program Now"); - 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); + 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_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); + 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); + baud_label = gtk_label_new("Baud:"); + gtk_label_set_justify(GTK_LABEL(baud_label), GTK_JUSTIFY_RIGHT); + gtk_widget_show(baud_label); - 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); + 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_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); + 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); + 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); + 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); + 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); + 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); + 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); + 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_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); + 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 cda37af66c..d5865a569a 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]; + FILE *fp; + int i, lineno = 0; + char buf[1024]; - byte_count = 0; - end_record_seen = 0; - for (i=0; i= 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 += i; - (num)++; - if (num >= 256) 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 (!sscanf(ptr, "%02x", &cksum)) return 0; - if (((sum & 255) + (cksum & 255)) & 255) return 0; /* checksum error */ - 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; + } + } + + 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; + 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; + 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; + int i; - if (addr < 0 || len < 0 || addr + len >= MAX_MEMORY_SIZE) { - for (i=0; i= 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; + int i; - if (addr < 0 || len < 0 || addr + len >= MAX_MEMORY_SIZE) { - return; - } - for (i=0; i= 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 4891c55946..8c74429887 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 \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 cf17d99703..24b2d33cb0 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 203af564da..9e7fee25f8 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; + 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; - } + if (port_fd >= 0) { + close(port_fd); + } - 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; + port_fd = open(port_name, O_RDWR); - 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 + 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; + 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(); + printf("\r\n"); + printf("Unable to open \"%s\"\r\n", filename); - 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); - } + if (err == EACCES) { + printf("You don't have permission to access %s\r\n", filename); + } - 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); - } + //printf("Attemping to find more information about %s....\r\n", filename); + r = stat(filename, &info); - 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); - } + 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); + } - 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); - } + return; + } - /* printf("%s is owned by: user %s, group %s\r\n", - filename, file_uname, file_gname); */ + my_uid = getuid(); + my_gid = getgid(); - perm = info.st_mode; + p = getpwuid(my_uid); - 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"); + 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; + 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; + } - 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; + int flags; + int result; - result = ioctl(port_fd, TIOCMGET, &flags); - if( result == -1 ) { - printf("Error %i while reading port io flags\n", errno); - return; - } + result = ioctl(port_fd, TIOCMGET, &flags); - if (val) { - flags |= TIOCM_RTS; - } else { - flags &= ~(TIOCM_RTS); - } + if (result == -1) { + printf("Error %i while reading port io flags\n", errno); + return; + } - result = ioctl(port_fd, TIOCMSET, &flags); - if( result == -1 ) - printf("Error %i while setting port io flags\n", errno); + 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; + int flags; + int result; - result = ioctl(port_fd, TIOCMGET, &flags); - if( result == -1 ) { - printf("Error %i while reading port io flags\n", errno); - return; - } + result = ioctl(port_fd, TIOCMGET, &flags); - if (val) { - flags |= TIOCM_DTR; - } else { - flags &= ~(TIOCM_DTR); - } + if (result == -1) { + printf("Error %i while reading port io flags\n", errno); + return; + } - result = ioctl(port_fd, TIOCMSET, &flags); - if( result == -1 ) - printf("Error %i while setting port io flags\n", errno); + 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 4ef9a82e5b..3887a18947 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 d52e24a03f..405d648e1a 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; + 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); - } + 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; + 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); + 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 20686821a4..47356be96c 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 5cc76e796c..7b6856ab64 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; + int i, n; + unsigned int val; - *str++ = uuchar(num); + *str++ = uuchar(num); - n = (num + 2) / 3; - for (i=0; i> 18); - *str++ = uuchar(val >> 12); - *str++ = uuchar(val >> 6); - *str++ = uuchar(val >> 0); - data += 3; - } - *str = '\0'; + 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; + int num = 0; + int i, n; + unsigned int val; - if (*str == '\0') return 0; + if (*str == '\0') { + return 0; + } - num = *str++ - 32; - if (num < 1 || num > 45) return 0; + num = *str++ - 32; - n = (num + 2) / 3; - for (i=0; i 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; + 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 f250109c08..729854e433 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -1,19 +1,22 @@ #include #include -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 2b1f28fd2a..398255ab4d 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 #include diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c index 99b4d0a3e5..72b3486405 100644 --- a/native/native-ltc4150.c +++ b/native/native-ltc4150.c @@ -56,7 +56,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 874feb8812..1d1746be4d 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 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(); + // Setting Multiplier and Divider values + PLL0CFG = 0x24; + feed(); - // Enabling the PLL */ - PLL0CON = 0x1; - feed(); + // Enabling the PLL */ + PLL0CON = 0x1; + feed(); - // Wait for the PLL to lock to set frequency - while(!(PLL0STAT & PLOCK)) ; + // Wait for the PLL to lock to set frequency + while (!(PLL0STAT & PLOCK)) ; - // Connect the PLL as the clock source - PLL0CON = 0x3; - feed(); + // 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; + // 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 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 43e70a00f2..ac885b877f 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 4b8912607b..0d62706943 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 b5b78bde25..18ba75d850 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 + SCS |= BIT0; // Set IO Ports to fast switching mode - /* UART0 */ - PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 - PINSEL0 &= ~(BIT5 + BIT7); + /* UART0 */ + PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 + PINSEL0 &= ~(BIT5 + BIT7); - /*Turn Board on*/ - PINMODE0 |= BIT1; - FIO0DIR |= BIT27; - FIO0CLR = BIT27; + /*Turn Board on*/ + PINMODE0 |= BIT1; + FIO0DIR |= BIT27; + FIO0CLR = BIT27; - /* 5V*/ - FIO1DIR |= BIT28; // Synch - FIO1SET = BIT28; // No Powersave + /* 5V*/ + FIO1DIR |= BIT28; // Synch + FIO1SET = BIT28; // No Powersave - FIO1DIR |= BIT27; // 5V off - FIO1CLR = BIT27; + FIO1DIR |= BIT27; // 5V off + FIO1CLR = BIT27; - /* Disable Resistors on Buttons */ - PINMODE4 |= BIT9 + BIT11; + /* 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; + /* 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; // ** + // 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 + // 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 + // 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 + 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 + 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; // + // RFID + FIO1DIR |= BIT1; // RFID Power + FIO1CLR = BIT1; // - FIO0DIR |= BIT1; // RFID Reset - FIO0SET = BIT1; // Hold in Reset + FIO0DIR |= BIT1; // RFID Reset + FIO0SET = BIT1; // Hold in Reset - FIO0DIR &= ~BIT10; // LED as INPUT - FIO0DIR &= ~BIT11; // DATA as INPUT - PINMODE0 |= BIT19 + BIT21; // No Pullups + FIO0DIR &= ~BIT10; // LED as INPUT + FIO0DIR &= ~BIT11; // DATA as INPUT + PINMODE0 |= BIT19 + BIT21; // No Pullups - // LTC4150 ARM - FIO0DIR |= BIT5; - FIO0CLR = BIT5; + // LTC4150 ARM + FIO0DIR |= BIT5; + FIO0CLR = BIT5; - // LTC4150 System - FIO0DIR |= BIT24; - FIO0CLR = BIT24; + // LTC4150 System + FIO0DIR |= BIT24; + FIO0CLR = BIT24; - // Battery Voltage (AD) - PINMODE1 |= BIT19; - PINSEL1 &= ~BIT19; - PINSEL1 |= BIT18; + // Battery Voltage (AD) + PINMODE1 |= BIT19; + PINSEL1 &= ~BIT19; + PINSEL1 |= BIT18; - //cc1100 - FIO0DIR |= BIT6 + BIT7 + BIT9; - FIO0SET = BIT6; - FIO0SET = BIT7 + BIT9; + //cc1100 + FIO0DIR |= BIT6 + BIT7 + BIT9; + FIO0SET = BIT6; + FIO0SET = BIT7 + BIT9; - //SD - FIO2DIR |= BIT12 + BIT13 + BIT11; - FIO0DIR |= BIT20 + BIT22 + BIT21; + //SD + FIO2DIR |= BIT12 + BIT13 + BIT11; + FIO0DIR |= BIT20 + BIT22 + BIT21; - //Tetra - FIO2DIR |= BIT0 + BIT7; + //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; + // 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/board_init.c b/redbee-econotag/board_init.c index 7c157b1038..7cafd1a0e2 100644 --- a/redbee-econotag/board_init.c +++ b/redbee-econotag/board_init.c @@ -6,14 +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 ) { +void bl_init_clks(void) +{ // dummy to compile } -void bl_init_ports( void ) { +void bl_init_ports(void) +{ // dummy to compile } diff --git a/redbee-econotag/drivers/gpio.c b/redbee-econotag/drivers/gpio.c index c9b867277a..cc34e15087 100644 --- a/redbee-econotag/drivers/gpio.c +++ b/redbee-econotag/drivers/gpio.c @@ -10,65 +10,66 @@ #include "gpio.h" -inline void gpio_pad_dir(volatile uint64_t data) +inline void gpio_pad_dir(volatile uint64_t data) { - GPIO->PAD_DIR0 = (data & 0xffffffff); - GPIO->PAD_DIR1 = (data >> 32); + GPIO->PAD_DIR0 = (data & 0xffffffff); + GPIO->PAD_DIR1 = (data >> 32); } -inline void gpio_data(volatile uint64_t data) +inline void gpio_data(volatile uint64_t data) { - GPIO->DATA0 = (data & 0xffffffff); - GPIO->DATA1 = (data >> 32); + GPIO->DATA0 = (data & 0xffffffff); + GPIO->DATA1 = (data >> 32); } -inline uint64_t gpio_data_get(volatile uint64_t bits) { - uint64_t rdata = 0; +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; + rdata = GPIO->DATA0 & (bits & 0xffffffff); + rdata |= (GPIO->DATA1 & (bits >> 32)) << 32; - return rdata; + return rdata; } -inline void gpio_pad_pu_en(volatile uint64_t data) +inline void gpio_pad_pu_en(volatile uint64_t data) { - GPIO->PAD_PU_EN0 = (data & 0xffffffff); - GPIO->PAD_PU_EN1 = (data >> 32); + GPIO->PAD_PU_EN0 = (data & 0xffffffff); + GPIO->PAD_PU_EN1 = (data >> 32); } -inline void gpio_data_sel(volatile uint64_t data) +inline void gpio_data_sel(volatile uint64_t data) { - GPIO->DATA_SEL0 = (data & 0xffffffff); - GPIO->DATA_SEL1 = (data >> 32); + GPIO->DATA_SEL0 = (data & 0xffffffff); + GPIO->DATA_SEL1 = (data >> 32); } -inline void gpio_pad_pu_sel(volatile uint64_t data) +inline void gpio_pad_pu_sel(volatile uint64_t data) { - GPIO->PAD_PU_SEL0 = (data & 0xffffffff); - GPIO->PAD_PU_SEL1 = (data >> 32); + GPIO->PAD_PU_SEL0 = (data & 0xffffffff); + GPIO->PAD_PU_SEL1 = (data >> 32); } -inline void gpio_data_set(volatile uint64_t data) +inline void gpio_data_set(volatile uint64_t data) { - GPIO->DATA_SET0 = (data & 0xffffffff); - GPIO->DATA_SET1 = (data >> 32); + GPIO->DATA_SET0 = (data & 0xffffffff); + GPIO->DATA_SET1 = (data >> 32); } -inline void gpio_data_reset(volatile uint64_t data) +inline void gpio_data_reset(volatile uint64_t data) { - GPIO->DATA_RESET0 = (data & 0xffffffff); - GPIO->DATA_RESET1 = (data >> 32); + GPIO->DATA_RESET0 = (data & 0xffffffff); + GPIO->DATA_RESET1 = (data >> 32); } -inline void gpio_pad_dir_set(volatile uint64_t data) +inline void gpio_pad_dir_set(volatile uint64_t data) { - GPIO->PAD_DIR_SET0 = (data & 0xffffffff); - GPIO->PAD_DIR_SET1 = (data >> 32); + GPIO->PAD_DIR_SET0 = (data & 0xffffffff); + GPIO->PAD_DIR_SET1 = (data >> 32); } -inline void gpio_pad_dir_reset(volatile uint64_t data) +inline void gpio_pad_dir_reset(volatile uint64_t data) { - GPIO->PAD_DIR_RESET0 = (data & 0xffffffff); - GPIO->PAD_DIR_RESET1 = (data >> 32); + 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 index b46051a1a7..595fa17c58 100644 --- a/redbee-econotag/drivers/include/gpio.h +++ b/redbee-econotag/drivers/include/gpio.h @@ -76,12 +76,12 @@ #define TXON GPIO_44 #define RXON GPIO_45 #define ANT1 GPIO_42 -#define ANT2 GPIO_43 +#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 MDO0 GPIO_51 #define MDO1 GPIO_52 #define MDO2 GPIO_53 #define MDO3 GPIO_54 @@ -118,18 +118,18 @@ struct GPIO_struct { 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); + _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 @@ -137,7 +137,7 @@ struct GPIO_struct { /* Build an enum lookup to map GPIO_08 -> 8 */ #undef _V #define _V(x,n,i) __NUM_GPIO_GPIO_##i, -enum { _REP(0,0) }; +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) @@ -154,6 +154,6 @@ enum { _REP(0,0) }; #undef _REP #undef _V -static volatile struct GPIO_struct * const GPIO = (void *) (0x80000000); +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 index 928a2157a9..760fc45d04 100644 --- a/redbee-econotag/drivers/include/uart.h +++ b/redbee-econotag/drivers/include/uart.h @@ -17,84 +17,84 @@ #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; - }; + 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); +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); +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. diff --git a/redbee-econotag/drivers/redbee_uart.c b/redbee-econotag/drivers/redbee_uart.c index 621d94e060..bf467a1376 100644 --- a/redbee-econotag/drivers/redbee_uart.c +++ b/redbee-econotag/drivers/redbee_uart.c @@ -16,26 +16,27 @@ #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_UART1 115200 #define BAUTRATE_UART2 115200 -void uart_set_baudrate ( volatile struct UART_struct* uart, uint32_t baudrate ) { +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; @@ -43,7 +44,8 @@ void uart_set_baudrate ( volatile struct UART_struct* uart, uint32_t baudrate ) uart->CONbits.RXE = 1; } -void uart_flow_ctl ( volatile struct UART_struct* uart, uint8_t on ) { +void uart_flow_ctl(volatile struct UART_struct *uart, uint8_t on) +{ if (on) { /* enable flow control */ if (uart == UART1) { @@ -63,12 +65,14 @@ void uart_flow_ctl ( volatile struct UART_struct* uart, uint8_t on ) { 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; @@ -89,24 +93,25 @@ void uart_flow_ctl ( volatile struct UART_struct* uart, uint8_t on ) { } // TODO: clean from u*_(rx|tx)_(head|tail) -void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { +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 @@ -122,10 +127,10 @@ void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { #else UART1->CONbits.MRXR = 1; /*< disable rx interrupt */ #endif - + //u1_tx_head = 0; //u1_tx_tail = 0; - + //enable_irq(UART1); ITC->INTENABLEbits.UART1 = 1; } @@ -134,11 +139,11 @@ void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { /* 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 @@ -154,23 +159,25 @@ void uart_init ( volatile struct UART_struct* uart, uint32_t baudrate ) { #else UART2->CONbits.MRXR = 1; /*< disable rx interrupt */ #endif - - // u2_tx_head = 0; + + // u2_tx_head = 0; //u2_tx_tail = 0; - + //enable_irq(UART2); ITC->INTENABLEbits.UART2 = 1; } - - uart_set_baudrate( uart, baudrate ); + + uart_set_baudrate(uart, baudrate); } -static inline uint32_t uart0_puts ( uint8_t *astring, uint32_t length ) { +static inline uint32_t uart0_puts(uint8_t *astring, uint32_t length) +{ uint32_t i = 0; - for (; iINTENABLEbits.UART1 = 0; ITC->INTENABLEbits.UART2 = 0; - + ITC->INTENABLEbits.UART1 = 1; ITC->INTENABLEbits.UART2 = 1; /** taken from msba2-uart0.c @@ -193,12 +200,13 @@ void stdio_flush(void) } -int fw_puts(char *astring,int length) +int fw_puts(char *astring, int length) { - return uart0_puts ( (uint8_t*) astring, (uint32_t) 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 ); +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 a4a53afc40..cf7f9d0152 100644 --- a/redbee-econotag/drivers/redbee_uart1.c +++ b/redbee-econotag/drivers/redbee_uart1.c @@ -13,36 +13,44 @@ #include "board_uart0.h" #include "uart.h" -void uart1_isr ( void ) { - if ( UART1->USTATbits.RXRDY == 1 ) { +void uart1_isr(void) +{ + 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 ) { + + 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 } } -void uart1_putc ( uint8_t c ) { +void uart1_putc(uint8_t c) +{ /* while uart fifo is full */ - while ( UART1->TXCON == 0 ) { + while (UART1->TXCON == 0) { /* wait */ } + UART1->DATA = c; } -uint8_t uart1_getc ( void ) { +uint8_t uart1_getc(void) +{ /* while uart fifo is empty */ - while ( UART1->RXCON == 0 ) { + while (UART1->RXCON == 0) { /* wait */ } - + 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 index a1b2e6bab9..a93c3f7137 100644 --- a/redbee-econotag/drivers/redbee_uart2.c +++ b/redbee-econotag/drivers/redbee_uart2.c @@ -13,36 +13,46 @@ #include "board_uart0.h" #include "uart.h" -void uart2_isr ( void ) { +void uart2_isr(void) +{ int i = 0; - if ( UART2->USTATbits.RXRDY == 1 ) { + + 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 ) { + + 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 ) { +void uart2_putc(uint8_t c) +{ /* while uart fifo is full */ - while ( UART2->TXCON == 0 ) { + while (UART2->TXCON == 0) { /* wait */ } + UART2->DATA = c; } -uint8_t uart2_getc ( void ) { +uint8_t uart2_getc(void) +{ /* while uart fifo is empty */ - while ( UART2->RXCON == 0 ) { + while (UART2->RXCON == 0) { /* wait */ } + return UART2->DATA; } \ No newline at end of file diff --git a/redbee-econotag/tools/ftditools/bbmc.c b/redbee-econotag/tools/ftditools/bbmc.c index 7e2b654412..f211f52eee 100644 --- a/redbee-econotag/tools/ftditools/bbmc.c +++ b/redbee-econotag/tools/ftditools/bbmc.c @@ -28,7 +28,7 @@ * SUCH DAMAGE. * * This file is part of libmc1322x: see http://mc1322x.devl.org - * for details. + * for details. * * */ @@ -48,7 +48,7 @@ #define REDBEE_ECONOTAG_RESET high(2) #define REDBEE_ECONOTAG_VREF2L high(7) -#define REDBEE_ECONOTAG_VREF2H high(6) +#define REDBEE_ECONOTAG_VREF2H high(6) #define REDBEE_ECONOTAG_INTERFACE INTERFACE_A #define REDBEE_USB_RESET high(2) @@ -79,20 +79,20 @@ #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; + 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); +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) \ @@ -101,431 +101,469 @@ void usage(void); .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 */ }, -}; + .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); + 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++; - } +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 */ }, +}; - return NULL; +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; +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"); + system("sudo kextload /System/Library/Extensions/FTDIUSBSerialDriver.kext"); } #endif -int main(int argc, char **argv) +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; + 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; + /* 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; + 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)); - } + 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; - } + override(interface); + override(dir); + override(reset_release); + override(reset_set); + override(vref2_normal); + override(vref2_erase); - 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; - } + 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; + } - 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 (ftdi_init(&ftdic) < 0) { + fprintf(stderr, "ftdi_init failed\n"); + return EXIT_FAILURE; + } - 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_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; + } - if( (ret = ftdi_usb_open_desc_index( - &ftdic, - vendid, - prodid, - NULL, - NULL, - dev_index)) < 0) { + 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) + + 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; - } - } + { + 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); + for (i = 0; commands[i].name != NULL; i++) { + if ((argv[optind] != NULL) && + (strcmp(commands[i].name, argv[optind]) == 0)) { + break; + } + } - return EXIT_FAILURE; - } + if (commands[i].name != NULL) { + commands[i].cmd(&ftdic, &layout); + } + else { + printf("invalid command\n"); - printf("done.\n"); - - ftdi_list_free(&devlist); - ftdi_deinit(&ftdic); - - return EXIT_SUCCESS; + 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) +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 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 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; + 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"); + 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; - } + i = 0; - printf("\nUse which device? "); + for (curdev = devlist; curdev != NULL; i++) { + printf(" [%d] ", i); - s = fgets(input, BUF_LEN, stdin); - if (s != NULL) { - size_t last = strlen (input) - 1; - if (input[last] == '\n') input[last] = '\0'; - } + 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; + } - sscanf(s, "%i",&sel); + printf("Manufacturer: %s, Description: %s, Serial %s\n", + manufacturer, description, serial); + curdev = curdev->next; + } - return sel; + 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) +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"); + /* 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_set | l->vref2_normal)); - bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal)); + printf("toggle reset\n"); - return; + 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) +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); + printf("setting VREF2 erase\n"); - 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)); + /* using MPSSE since it give access to high GPIO*/ + /* set as inputs for now */ + ftdi_set_bitmode(ftdic, 0 , BITMODE_MPSSE); - printf("waiting for erase\n"); + bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal)); + bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_erase)); - sleep(2); + printf("toggle reset\n"); - printf("setting VREF2 normal\n"); - - bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_normal)); + bb_mpsee(ftdic, l->dir, (l->reset_set | l->vref2_erase)); + bb_mpsee(ftdic, l->dir, (l->reset_release | l->vref2_erase)); - reset(ftdic, l); + printf("waiting for erase\n"); - return; + 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) +int bb_mpsee(struct ftdi_context *ftdic, uint16_t dir, uint16_t val) { - uint8_t buf[3]; - int ret; + uint8_t buf[3]; + int ret; - /* command "set data bits low byte" */ - buf[0] = 0x80; - buf[1] = (val & 0xff); - buf[2] = dir & 0xff; + /* 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]); + 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; - } + 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; + /* 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]); + 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; - } + 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; + return 0; } diff --git a/redbee-econotag/tools/mc1322x-load.c b/redbee-econotag/tools/mc1322x-load.c index d63df23802..82c59520b9 100644 --- a/redbee-econotag/tools/mc1322x-load.c +++ b/redbee-econotag/tools/mc1322x-load.c @@ -40,13 +40,13 @@ #include -char* filename; -char* second; -char* term = "/dev/ttyUSB0"; +char *filename; +char *second; +char *term = "/dev/ttyUSB0"; int baud = B115200; int verbose = 0; -char* rts = "rts"; -char* command; +char *rts = "rts"; +char *command; int first_delay = 50; int second_delay = 100; int do_exit = 0; @@ -64,262 +64,322 @@ void help(void); int main(int argc, char **argv) { - int c = 0; - int r = 0; - int i = 0; - uint32_t s = 0; - opterr = 0; + 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; + /* 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(); } - 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); + /* Get other arguments */ + if (optind < argc) { + args = argv[optind]; } - } - /* 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"); + /* 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); + } - /* Secondary loader wait loop */ - if (second || zerolen) { - /* Wait for ready */ - printf("Sending secondary file (waiting for ready)...\n"); + /* 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) { - 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; + /* 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; + } } - i += r; - if (i >= sizeof(buf)-1) { - i = 0; + else { + printf("."); + fflush(stdout); } - } else { - printf("."); fflush(stdout); - } } - /* Send secondary file */ - if (second) { - if (stat(second, &sbuf)) { - printf("Cannot open secondary file %s!\n", second); + /* Send primary file */ + if (!filename) { + printf("Please specify firmware file name (-f option)!\n"); return -1; - } - sfd = open(second, O_RDONLY); - if (sfd == -1) { - printf("Cannot open secondary file %s!\n", second); + } + + if (stat(filename, &sbuf)) { + printf("Cannot open firmware file %s!\n", filename); 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) { + } + + 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(second_delay); - c = write(pfd, (const void*)buf, r); - } while(c < r); + usleep(first_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); + printf("Written %i\r", i); + fflush(stdout); + r = read(ffd, buf, 1); } - } - /* 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); - } + printf("\n"); - /* 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); - } + /* 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"); + 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"); } From 9a7902740a9e0c70cbc968fa2fadac9701b60da8 Mon Sep 17 00:00:00 2001 From: Martin Lenders Date: Mon, 29 Jul 2013 17:51:19 +0200 Subject: [PATCH 152/188] Allow native port to link additional libs from app Might come handy for e.g. testing frameworks --- native/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/Makefile.include b/native/Makefile.include index e8e5d48e4d..1a5b2e4d2d 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -14,7 +14,7 @@ export OBJCOPY = $(PREFIX)objcopy FLASHER = lpc2k_pgm TERM = pyterm.py -LINKFLAGS = -m32 -gc +LINKFLAGS += -m32 -gc ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 From d89940624d6bdd3de0f46cbaa8fcdb46ab66f7f9 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Fri, 9 Aug 2013 15:43:40 +0200 Subject: [PATCH 153/188] added interrupt handler for UART1 (->uart0 & stdin) to MSB-430(h) --- msb-430-common/board_init.c | 7 +++++-- msb-430-common/uart1.c | 40 +++++++++++++++++++++++++++++++++++-- msb-430h/Makefile.include | 1 + msb-430h/driver_cc110x.c | 2 -- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index de2e5c01dc..4f0fec335d 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -55,8 +55,8 @@ static void msb_ports_init(void) // 0 - P2.7 [IN ] - SD-KARTE Detect P3SEL = 0xC0; // Port3 Zweitfunktion - P3OUT = 0x09; // Port3 Ausgangsregister: 00001001 = 0x09 - P3DIR = 0x2B; // Port3 Direction + P3OUT = 0x49; // Port3 Ausgangsregister: 00001001 = 0x09 + P3DIR = 0xAB; // Port3 Direction // 1 - P3.0 // 1 - P3.1 // 0 - P3.2 @@ -119,7 +119,10 @@ void msp430_set_cpu_speed(uint32_t speed) UBR11 = br >> 8; UMCTL1 = calc_umctl(br); // set modulation + ME2 |= (UTXE1 | URXE1); UCTL1 &= ~SWRST; + + IE2 |= URXIE1; //clock_init(); eint(); } diff --git a/msb-430-common/uart1.c b/msb-430-common/uart1.c index 2b22b3171b..025d09dc6e 100644 --- a/msb-430-common/uart1.c +++ b/msb-430-common/uart1.c @@ -1,9 +1,12 @@ #include "board.h" -#define UART1_TX TXBUF1 +#define UART1_TX TXBUF1 #define UART1_WAIT_TXDONE() while( (UTCTL1 & TXEPT) == 0 ) { _NOP(); } #include +#include + +#include int putchar(int c) { @@ -11,11 +14,44 @@ int putchar(int c) UART1_WAIT_TXDONE(); if (c == 10) { - UART1_TX = 13; UART1_WAIT_TXDONE(); } return c; } +void usart0irq(void); +/** + * \brief the interrupt function + */ +interrupt(USART1RX_VECTOR) usart0irq(void) +{ + U1TCTL &= ~URXSE; /* Clear the URXS signal */ + U1TCTL |= URXSE; /* Re-enable URXS - needed here?*/ + int c = 0; + /* Check status register for receive errors. */ + if(U1RCTL & RXERR) { + if (U1RCTL & FE) { + puts("rx framing error"); + } + if (U1RCTL & OE) { + puts("rx overrun error"); + } + if (U1RCTL & PE) { + puts("rx parity error"); + } + if (U1RCTL & BRK) { + puts("rx break error"); + } + /* Clear error flags by forcing a dummy read. */ + c = U1RXBUF; + } +#ifdef MODULE_UART0 + else if (uart0_handler_pid) { + c = U1RXBUF; + uart0_handle_incoming(c); + uart0_notify_thread(); + } +#endif +} diff --git a/msb-430h/Makefile.include b/msb-430h/Makefile.include index c5716486eb..166060e36f 100644 --- a/msb-430h/Makefile.include +++ b/msb-430h/Makefile.include @@ -1,3 +1,4 @@ +export INCLUDES += -I$(RIOTBOARD)/msb-430h/include -I$(RIOTBOARD)/msb-430-common/include include $(RIOTBOARD)/$(BOARD)/Makefile.dep include $(RIOTBOARD)/msb-430-common/Makefile.include diff --git a/msb-430h/driver_cc110x.c b/msb-430h/driver_cc110x.c index deb6835fd2..857bfcf1d4 100644 --- a/msb-430h/driver_cc110x.c +++ b/msb-430h/driver_cc110x.c @@ -337,8 +337,6 @@ void cc110x_spi_init(uint8_t clockrate) 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) { From 7a2cc4ae096a90308c026dd857e19b4489b162cf Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Fri, 9 Aug 2013 15:48:53 +0200 Subject: [PATCH 154/188] minor changes: * renamed terminal program variable * added terminal program for MSB-430 platforms * changed default JTAG for MSB-430 platforms from uif to olimex --- msb-430-common/Makefile.include | 4 +++- msba2-common/Makefile.include | 2 +- msba2/Makefile | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/msb-430-common/Makefile.include b/msb-430-common/Makefile.include index 4adcbb6dd1..33ce3d11eb 100644 --- a/msb-430-common/Makefile.include +++ b/msb-430-common/Makefile.include @@ -13,12 +13,14 @@ export LINK = $(PREFIX)gcc export SIZE = $(PREFIX)size export OBJCOPY = $(PREFIX)objcopy export LINKFLAGS = -mmcu=$(MCU) -lgcc $(RIOTBASE)/bin/startup.o +TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm.py export FLASHER = mspdebug ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 endif export HEXFILE = bin/$(PROJECT).hex -export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" +#export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" +export FFLAGS = -j olimex "prog $(HEXFILE)" export USEMODULE += msp430_common export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index 082a2e57f1..c2832ca47d 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -13,7 +13,7 @@ export LINK = $(PREFIX)gcc export SIZE = $(PREFIX)size export OBJCOPY = $(PREFIX)objcopy FLASHER = lpc2k_pgm -TERM = $(RIOTBASE)/dist/tools/pyterm/pyterm.py +TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm.py LINKFLAGS = -gdwarf-2 -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T$(RIOTBASE)/cpu/$(CPU)/linkerscript.x ifeq ($(strip $(PORT)),) diff --git a/msba2/Makefile b/msba2/Makefile index a539327476..0aff0df0b1 100644 --- a/msba2/Makefile +++ b/msba2/Makefile @@ -5,6 +5,7 @@ export ARCH = msba2_base.a DEP = $(SRC:%.c=$(BINDIR)%.d) +INCLUDES += -I$(RIOTBOARD)/msba2/include/ INCLUDES += -I$(RIOTBOARD)/msba2-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include/ INCLUDES += -I$(RIOTBASE)/cpu/lpc2387/include/ From 4eb96382be614e0aa98e840afb64f8b64c5a5c6c Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Mon, 12 Aug 2013 17:59:46 +0200 Subject: [PATCH 155/188] add .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..937bfe3459 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin/ +*.o From 8552c04c060602bb124ee3bb194c3b38362e93b2 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 13 Aug 2013 10:41:50 +0200 Subject: [PATCH 156/188] corrected and translated comments --- msb-430-common/board_init.c | 158 ++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index 4f0fec335d..4999b38d9c 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -9,7 +9,7 @@ static volatile uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; /*---------------------------------------------------------------------------*/ static uint8_t calc_umctl(uint16_t br) { - // from TI slaa049 + /* from TI slaa049 */ register uint8_t CMOD = 256 * br - 256 * (br + 1) / 2; register uint8_t c = 0; register int i = 0; @@ -17,12 +17,12 @@ static uint8_t calc_umctl(uint16_t br) a <<= 1; do { - if (a & 0x80) { // Overflow to integer? - a = a - 128 + CMOD; // Yes, subtract 1.000000 + if (a & 0x80) { /* Overflow to integer? */ + a = a - 128 + CMOD; /* Yes, subtract 1.000000 */ c |= 0x80; } else { - a += CMOD; // No, add fraction + a += CMOD; /* No, add fraction */ } if (i == 7) { @@ -37,71 +37,71 @@ static uint8_t calc_umctl(uint16_t br) static void msb_ports_init(void) { - // 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 + /* Port 1: Free port, for energy saving all outputs are set to zero. */ + P1SEL = 0x00; /* Port1 I/O Function */ + 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 + P2SEL = 0x20; /* Port2 I/O Function */ + P2OUT = 0x00; /* Port2 Output register: 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 ] - SDC Protect */ + /* 0 - P2.7 [IN ] - SDC Detect */ - P3SEL = 0xC0; // Port3 Zweitfunktion - P3OUT = 0x49; // Port3 Ausgangsregister: 00001001 = 0x09 - P3DIR = 0xAB; // 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 + P3SEL = 0xC0; /* Port3 Pins 6 & 7 for USART */ + P3OUT = 0x49; /* Port3 Output register: 01001001: 0x49 */ + P3DIR = 0xAB; /* Port3 Direction: 10101011: 0xAB */ + /* 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 */ + /* 1 - 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 + /* Port 4: Free port, for energy saving all outputs are set to zero. */ + P4SEL = 0x00; /* Port4 I/O Function */ + P4OUT = 0x00; /* Port4 Output register: 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 + P5SEL = 0x00; /* Port5 I/O Function: 00000000 = 0x00 */ + P5OUT = 0x80; /* Port5 Output register: 00001001 = 0x09 */ + P5DIR = 0xFF; /* Port5 Direction: 11111011 = 0xFB */ + /* 1 - P5.0 [OUT] - SDC /CS */ + /* 1 - P5.1 [OUT] - SDC DI */ + /* 0 - P5.2 [IN ] - SDC DO */ + /* 1 - P5.3 [OUT] - SDC DCLK */ + /* 1 - P5.4 [OUT] - MMA GS1 */ + /* 1 - P5.5 [OUT] - MMA GS2 */ + /* 1 - P5.6 [OUT] - MMA /SLEEP */ + /* 1 - P5.7 [OUT] - LED_RED 0-on, 1-off */ - 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 + P6SEL = 0x00; /* Port6 I/O Function = 0x07 */ + P6OUT = 0x00; /* Port6 Output register: 00000000 = 0x00 */ + P6DIR = 0xFF; /* Port6 Direction: 11111000 = 0xF8 */ + /* 0 - P6.0 [AD-IN] - MMA X-Axis */ + /* 0 - P6.1 [AD-IN] - MMA Y-Axis */ + /* 0 - P6.2 [AD-IN] - MMA Z-Axis */ + /* 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) @@ -110,14 +110,14 @@ void msp430_set_cpu_speed(uint32_t speed) __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 + 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 + UBR01 = br; /* set baudrate */ UBR11 = br >> 8; - UMCTL1 = calc_umctl(br); // set modulation + UMCTL1 = calc_umctl(br); /* set modulation */ ME2 |= (UTXE1 | URXE1); UCTL1 &= ~SWRST; @@ -135,22 +135,22 @@ msp430_init_dco() /*------------------ use external oszillator -----------------------*/ uint16_t i; - // Stop watchdog + /* Stop watchdog */ WDTCTL = WDTPW + WDTHOLD; //Init crystal for mclk //XT2 = HF XTAL BCSCTL1 = RSEL2; - // Wait for xtal to stabilize + /* Wait for xtal to stabilize */ do { - IFG1 &= ~OFIFG; // Clear oscillator fault flag + IFG1 &= ~OFIFG; /* Clear oscillator fault flag */ - for (i = 0xFF; i > 0; i--); // Time for flag to set + for (i = 0xFF; i > 0; i--); /* Time for flag to set */ } - while ((IFG1 & OFIFG) != 0); // Oscillator fault flag still set? + while ((IFG1 & OFIFG) != 0); /* Oscillator fault flag still set? */ - BCSCTL2 = SELM_2 + SELS; // MCLK und SMCLK = XT2 (safe) + 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; @@ -163,7 +163,7 @@ msp430_init_dco() 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 + /* Init FLL to desired frequency using the 32762Hz crystal */ #if MSP430_HAS_DCOR BCSCTL2 = 0x01; #else @@ -175,8 +175,8 @@ msp430_init_dco() 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 + CCTL2 = CCIS0 + CM0 + CAP; /* Define CCR2, CAP, ACLK */ + TACTL = TASSEL1 + TACLR + MC1; /* SMCLK, continous mode */ while (1) { From d7264418e829aa2f1653459cf86d21c2bf31ee19 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Tue, 16 Jul 2013 17:57:52 +0200 Subject: [PATCH 157/188] native cc110x_ng support --- native/drivers/native-uart0.c | 15 +++++++++++---- native/include/board_internal.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/native/drivers/native-uart0.c b/native/drivers/native-uart0.c index 3af009eee4..fc5eed29c3 100644 --- a/native/drivers/native-uart0.c +++ b/native/drivers/native-uart0.c @@ -27,6 +27,10 @@ void _native_handle_uart0_input() char buf[42]; int nread; + if (!FD_ISSET(_native_uart_in, &_native_rfds)) { + DEBUG("_native_handle_uart0_input - nothing to do\n"); + return; + } DEBUG("_native_handle_uart0_input\n"); _native_in_syscall = 0; _native_in_isr = 1; @@ -44,15 +48,18 @@ void _native_handle_uart0_input() cpu_switch_context_exit(); } +int _native_set_uart_fds(void) +{ + DEBUG("_native_set_uart_fds"); + FD_SET(_native_uart_in, &_native_rfds); + return _native_uart_in; +} + void _native_init_uart0() { _native_uart_out = STDOUT_FILENO; _native_uart_in = STDIN_FILENO; - /* set fds for select in lpm */ - FD_ZERO(&_native_uart_rfds); - FD_SET(_native_uart_in, &_native_uart_rfds); - puts("RIOT native uart0 initialized."); } diff --git a/native/include/board_internal.h b/native/include/board_internal.h index 752cbcdfb5..368d5287de 100644 --- a/native/include/board_internal.h +++ b/native/include/board_internal.h @@ -1,6 +1,6 @@ #ifdef MODULE_UART0 #include -extern fd_set _native_uart_rfds; void _native_handle_uart0_input(void); void _native_init_uart0(void); +int _native_set_uart_fds(void); #endif From 22f5bcdbc3f9eb534ffc3b3668ac141ab9d99b5d Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 14 Aug 2013 23:48:01 +0200 Subject: [PATCH 158/188] added prototype for msp430_init_dco() --- msb-430-common/board_init.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/msb-430-common/board_init.c b/msb-430-common/board_init.c index de2e5c01dc..8d45814222 100644 --- a/msb-430-common/board_init.c +++ b/msb-430-common/board_init.c @@ -6,6 +6,8 @@ static volatile uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; +void msp430_init_dco(void); + /*---------------------------------------------------------------------------*/ static uint8_t calc_umctl(uint16_t br) { @@ -125,8 +127,7 @@ void msp430_set_cpu_speed(uint32_t speed) } /*---------------------------------------------------------------------------*/ -void -msp430_init_dco() +void msp430_init_dco(void) { #if MSP430_HAS_EXTERNAL_CRYSTAL /*------------------ use external oszillator -----------------------*/ From ac222754ce584045b24fef94ed0fd6aff64c437a Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Thu, 15 Aug 2013 23:51:49 +0200 Subject: [PATCH 159/188] harmonize LED implementation fix https://github.com/RIOT-OS/RIOT/issues/145 --- native/board_init.c | 4 ++-- native/drivers/native-led.c | 12 ++++++------ native/include/board.h | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/native/board_init.c b/native/board_init.c index fa1a319afc..0abc01573c 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -26,7 +26,7 @@ void board_init() #ifdef MODULE_UART0 _native_init_uart0(); #endif - LED_GREEN_OFF(); - LED_RED_ON(); + LED_GREEN_OFF; + LED_RED_ON; puts("RIOT native board initialized."); } diff --git a/native/drivers/native-led.c b/native/drivers/native-led.c index f2091c9a37..7f9296d7c3 100644 --- a/native/drivers/native-led.c +++ b/native/drivers/native-led.c @@ -19,32 +19,32 @@ #include "board.h" -void LED_GREEN_OFF(void) +void _native_LED_GREEN_OFF(void) { printf("LED_GREEN_OFF\n"); } -void LED_GREEN_ON(void) +void _native_LED_GREEN_ON(void) { printf("LED_GREEN_ON\n"); } -void LED_GREEN_TOGGLE(void) +void _native_LED_GREEN_TOGGLE(void) { printf("LED_GREEN_TOGGLE\n"); } -void LED_RED_OFF(void) +void _native_LED_RED_OFF(void) { printf("LED_RED_OFF\n"); } -void LED_RED_ON(void) +void _native_LED_RED_ON(void) { printf("LED_RED_ON\n"); } -void LED_RED_TOGGLE(void) +void _native_LED_RED_TOGGLE(void) { printf("LED_RED_TOGGLE\n"); } diff --git a/native/include/board.h b/native/include/board.h index 18ee528271..f4797f2060 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -15,9 +15,15 @@ * @} */ -void LED_GREEN_OFF(void); -void LED_GREEN_ON(void); -void LED_GREEN_TOGGLE(void); -void LED_RED_OFF(void); -void LED_RED_ON(void); -void LED_RED_TOGGLE(void); +void _native_LED_GREEN_OFF(void); +#define LED_GREEN_OFF (_native_LED_GREEN_OFF()) +void _native_LED_GREEN_ON(void); +#define LED_GREEN_ON (_native_LED_GREEN_ON()) +void _native_LED_GREEN_TOGGLE(void); +#define LED_GREEN_TOGGLE (_native_LED_GREEN_TOGGLE()) +void _native_LED_RED_OFF(void); +#define LED_RED_OFF (_native_LED_RED_OFF()) +void _native_LED_RED_ON(void); +#define LED_RED_ON (_native_LED_RED_ON()) +void _native_LED_RED_TOGGLE(void); +#define LED_RED_TOGGLE (_native_LED_RED_TOGGLE()) From ca6f20f38453ffc8c396bbafadfae01e54916536 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Thu, 15 Aug 2013 22:58:26 +0200 Subject: [PATCH 160/188] implement uart0_puts properly --- native/drivers/native-uart0.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/native/drivers/native-uart0.c b/native/drivers/native-uart0.c index fc5eed29c3..419b043cc5 100644 --- a/native/drivers/native-uart0.c +++ b/native/drivers/native-uart0.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -19,7 +20,14 @@ fd_set _native_uart_rfds; inline int uart0_puts(char *astring, int length) { - return puts(astring); + _native_in_syscall = 1; + /* XXX: handle short writes: */ + if (write(_native_uart_out, astring, length) == -1) { + err(EXIT_FAILURE, "uart0_puts: write"); + return -1; + } + _native_in_syscall = 0; + return length; } void _native_handle_uart0_input() From 141bec642703d3f1f1d842398ee25ffe91f8b6e5 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Sun, 18 Aug 2013 11:21:38 +0200 Subject: [PATCH 161/188] improve uart0_puts --- native/drivers/native-uart0.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/native/drivers/native-uart0.c b/native/drivers/native-uart0.c index 419b043cc5..9f77a72d0c 100644 --- a/native/drivers/native-uart0.c +++ b/native/drivers/native-uart0.c @@ -20,13 +20,26 @@ fd_set _native_uart_rfds; inline int uart0_puts(char *astring, int length) { + int nwritten, offset; + + nwritten = 0; + offset = 0; + _native_in_syscall = 1; - /* XXX: handle short writes: */ - if (write(_native_uart_out, astring, length) == -1) { - err(EXIT_FAILURE, "uart0_puts: write"); - return -1; + + while ((length > 0) &&(nwritten = write(_native_uart_out, astring+offset, length-offset)) > 0) { + offset += nwritten; } + if (nwritten == -1) { + err(EXIT_FAILURE, "uart0_puts: write"); + } + else if ((length > 0) && (nwritten == 0)) { + /* XXX: handle properly */ + errx(EXIT_FAILURE, "uart0_puts: Could not write to stdout. I don't know what to do now."); + } + _native_in_syscall = 0; + return length; } From 7cde32f45276f3c9625e13b97344939ca3ca5983 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Fri, 23 Aug 2013 15:08:35 +0200 Subject: [PATCH 162/188] GPIO implementation was moved to RIOT/cpu/mc1322x since ADC module implementation depends on it --- redbee-econotag/drivers/gpio.c | 75 ------------ redbee-econotag/drivers/include/gpio.h | 159 ------------------------- 2 files changed, 234 deletions(-) delete mode 100644 redbee-econotag/drivers/gpio.c delete mode 100644 redbee-econotag/drivers/include/gpio.h diff --git a/redbee-econotag/drivers/gpio.c b/redbee-econotag/drivers/gpio.c deleted file mode 100644 index cc34e15087..0000000000 --- a/redbee-econotag/drivers/gpio.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * gpio.c - GPIO driver for redbee - * Copyright (C) 2013 Thomas Eichinger - * - * 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 deleted file mode 100644 index 595fa17c58..0000000000 --- a/redbee-econotag/drivers/include/gpio.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * gpio.h - GPIO driver for redbee - * Copyright (C) 2013 Thomas Eichinger - * - * 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 From f2413495380056b5b9340627d18b4af56912dee7 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 27 Aug 2013 18:12:57 +0200 Subject: [PATCH 163/188] added missing LICENSE file --- LICENSE | 454 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 454 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..f99be76ab3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,454 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS From 1ada39d7fdcd5a8cb4e1a47466891a790f5f032c Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 19 Aug 2013 18:58:45 +0200 Subject: [PATCH 164/188] initial commit for TelosB support --- telosb/Makefile | 33 ++++++++++ telosb/Makefile.dep | 2 + telosb/Makefile.include | 25 +++++++ telosb/board.c | 127 ++++++++++++++++++++++++++++++++++++ telosb/include/board-conf.h | 13 ++++ telosb/include/board.h | 58 ++++++++++++++++ telosb/uart.c | 45 +++++++++++++ 7 files changed, 303 insertions(+) create mode 100644 telosb/Makefile create mode 100644 telosb/Makefile.dep create mode 100644 telosb/Makefile.include create mode 100644 telosb/board.c create mode 100644 telosb/include/board-conf.h create mode 100644 telosb/include/board.h create mode 100644 telosb/uart.c diff --git a/telosb/Makefile b/telosb/Makefile new file mode 100644 index 0000000000..1f6fc07cb0 --- /dev/null +++ b/telosb/Makefile @@ -0,0 +1,33 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = telosb_base.a + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I${RIOTBASE}/core/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include +INCLUDES += -I$(RIOTBASE)/sys/net/ + +all: $(BINDIR)$(ARCH) + +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + mkdir -p $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi diff --git a/telosb/Makefile.dep b/telosb/Makefile.dep new file mode 100644 index 0000000000..4392a18adb --- /dev/null +++ b/telosb/Makefile.dep @@ -0,0 +1,2 @@ +USEMODULE += msp430_common + diff --git a/telosb/Makefile.include b/telosb/Makefile.include new file mode 100644 index 0000000000..e07ce0f5da --- /dev/null +++ b/telosb/Makefile.include @@ -0,0 +1,25 @@ +include $(RIOTBOARD)/$(BOARD)/Makefile.dep +## the cpu to build for +export CPU = msp430x16x +export MCU = msp430f1611 + +# toolchain config +export PREFIX = @msp430- +export CC = @$(PREFIX)gcc +export AR = @$(PREFIX)ar +export CFLAGS += -std=gnu99 -Wstrict-prototypes -gdwarf-2 -Os -Wall -mmcu=$(MCU) +export ASFLAGS += -mmcu=$(MCU) --defsym $(MCU)=1 --gdwarf-2 +export AS = $(PREFIX)as +export LINK = $(PREFIX)gcc +export SIZE = $(PREFIX)size +export OBJCOPY = $(PREFIX)objcopy +export LINKFLAGS = -mmcu=$(MCU) -lgcc $(RIOTBASE)/bin/startup.o +export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm.py +export FLASHER = goodfet.bsl +ifeq ($(strip $(PORT)),) + export PORT = /dev/ttyUSB0 +endif +export HEXFILE = bin/$(PROJECT).hex +export FFLAGS = --telosb -c $(PORT) -r -e -I -p $(HEXFILE) + +export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ diff --git a/telosb/board.c b/telosb/board.c new file mode 100644 index 0000000000..d461e3b4c1 --- /dev/null +++ b/telosb/board.c @@ -0,0 +1,127 @@ + /* + * board.c - Board initiazilation for the TelosB + * Copyright (C) 2013 Oliver Hahm + * + * This file subject to the terms and conditions of the GLGPLv2 License. See the file LICENSE in the + * top level directory for more details. + */ + +#include "cpu.h" +#include "board.h" + +void uart_init(void); + +static void telosb_ports_init(void) +{ + /* Port 1: GDO, Flash, BSL TX */ + P1SEL = 0x02; /* Port1 Select: 00000010 = 0x02 */ + P1OUT = 0x00; /* Port1 Output: 00000000 = 0x00 */ + P1DIR = 0x87; /* Port1 Direction: 10000111 = 0x87 */ + + /* Port 2: GPIO, BSL RX, 1wire */ + P2SEL = 0x04; /* Port2 Select: 00000100 = 0x04 */ + P2OUT = 0x00; /* Port2 Output: 00000000 = 0x00 */ + P2DIR = 0xFF; /* Port2 Direction: 11111111 = 0xFF */ + + /* Port 3: UART and SPI */ + P3SEL = 0xCE; /* Port3 Select: 11001110 = 0xCE */ + P3OUT = 0x00; /* Port3 Output: 00000000 = 0x00 */ + P3DIR = 0x4E; /* Port3 Direction: 01001110 = 0x4E */ + + /* Port 4: CS */ + P4SEL = 0x02; /* Port4 Select: 00000010 = 0x02 */ + P4OUT = 0x04; /* Port4 Output: 00000100 = 0x04 */ + P4DIR = 0x64; /* Port4 Direction: 01100100 = 0x64 */ + + /* Port 5: SPI, LED */ + P5SEL = 0x00; /* Port5 Select: 00000000 = 0x00 */ + P5OUT = 0x70; /* Port5 Output: 01110000 = 0x70 */ + P5DIR = 0x70; /* Port5 Direction: 01110000 = 0x70 */ + + + P6SEL = 0xFF; /* Port6 Select: 11111111 = 0xFF */ + P6OUT = 0x00; /* Port6 Output: 00000000 = 0x00 */ + P6DIR = 0xFF; /* Port6 Direction: 11111000 = 0xFF */ + +} + +/*---------------------------------------------------------------------------*/ +/* taken from Contiki code */ +void msp430_init_dco(void) +{ + /* This code taken from the FU Berlin sources and reformatted. */ +#define DELTA (F_CPU / (F_RC_OSCILLATOR / 8)) + + unsigned int compare, oldcapture = 0; + unsigned int i; + + /* 10100100 = XT2 is off, ACLK divided by 4, RSELx=4 */ + BCSCTL1 = XT2OFF | DIVA_2 | RSEL2; + + /* Init undivided DCO with internal resistor for MCLK and SMCLK + * DCO = 32762Hz -> FLL = 2,4576 MHz */ + BCSCTL2 = 0x00; + + BCSCTL1 |= DIVA1 + DIVA0; /* ACLK = LFXT1CLK/8 */ + + for (i = 0xFFFF; i > 0; i--) { /* Delay for XTAL to settle */ + asm("nop"); + } + + 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 */ + + BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ +} + + +//=========================== public ========================================== + +void board_init(void) +{ + msp430_cpu_init(); + /* disable watchdog timer */ + WDTCTL = WDTPW + WDTHOLD; + + telosb_ports_init(); + + msp430_init_dco(); + + /* initialize bsp modules */ + uart_init(); + + /* enable interrupts */ + __bis_SR_register(GIE); +} diff --git a/telosb/include/board-conf.h b/telosb/include/board-conf.h new file mode 100644 index 0000000000..f65074da9d --- /dev/null +++ b/telosb/include/board-conf.h @@ -0,0 +1,13 @@ +/** + * board-conf.h. + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef BOARD_CONF_H +#define BOARD_CONF_H + +#define INFOMEM (0x1000) + +#endif /* BOARD-CONF_H */ diff --git a/telosb/include/board.h b/telosb/include/board.h new file mode 100644 index 0000000000..d9ab4a6675 --- /dev/null +++ b/telosb/include/board.h @@ -0,0 +1,58 @@ +/** + * board.h - TelosB Board. + * Copyright (C) 2013 INRIA + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef _TELOSB_BOARD_H +#define _TELOSB_BOARD_H + +/** + * @defgroup TelosB + * @ingroup TelosB + * +

Compontents

+\li MSP430 +\li CC2420 + +* @{ +*/ + +/** + * @file + * @brief TelosB Board + * + * @author Oliver Hahm + * + */ + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 800000uL +#define MSP430_HAS_DCOR 0 +#define MSP430_HAS_EXTERNAL_CRYSTAL 1 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x10 +#define LEDS_CONF_GREEN 0x20 +#define LEDS_CONF_BLUE 0x40 + +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED + +#define LED_GREEN_ON LEDS_PxOUT &=~LEDS_CONF_GREEN +#define LED_GREEN_OFF LEDS_PxOUT |= LEDS_CONF_GREEN +#define LED_GREEN_TOGGLE LEDS_PxOUT ^= LEDS_CONF_GREEN + +#define LED_BLUE_ON LEDS_PxOUT &=~LEDS_CONF_BLUE +#define LED_BLUE_OFF LEDS_PxOUT |= LEDS_CONF_BLUE +#define LED_BLUE_TOGGLE LEDS_PxOUT ^= LEDS_CONF_BLUE + +#include + +/** @} */ +#endif // _TELOSB_BOARD_H diff --git a/telosb/uart.c b/telosb/uart.c new file mode 100644 index 0000000000..b8cdcdcd76 --- /dev/null +++ b/telosb/uart.c @@ -0,0 +1,45 @@ + /* + * uart.c - Implementation for the TelosB UART + * Copyright (C) 2013 Oliver Hahm + * + * This file subject to the terms and conditions of the GLGPLv2 License. See the file LICENSE in the + * top level directory for more details. + */ + +#include +#include +#include "cpu.h" +#include "board.h" +#include "kernel.h" + +#define UART1_TX U1TXBUF +#define UART1_WAIT_TXDONE() while ( (U1TCTL & TXEPT) == 0 ) { _NOP(); } + +#define BAUDRATE (115200ul) + +void uart_init(void) +{ + UCTL1 = SWRST; /* hold UART1 module in reset */ + UCTL1 |= CHAR; /* 8-bit character */ + + /* 115200 baud, clocked from 4.8MHz SMCLK */ + UTCTL1 |= SSEL1; /* UCLK = SCLK */ + UBR01 = F_CPU / BAUDRATE; + UBR11 = (F_CPU / BAUDRATE) >> 8; + UMCTL1 = 0x4A; /* modulation */ + + ME2 |= UTXE1 + URXE1; /* enable UART1 TX/RX */ + UCTL1 &= ~SWRST; /* clear UART1 reset bit */ +} + +int putchar(int c) +{ + UART1_TX = c; + UART1_WAIT_TXDONE(); + return c; +} + +uint8_t uart_readByte(void) +{ + return U1RXBUF; +} From 21dff812395488a6d0321f9cca9600d116efd654 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 19 Aug 2013 19:19:57 +0200 Subject: [PATCH 165/188] implemented stdin for TelosB --- telosb/Makefile | 1 + telosb/board.c | 4 +-- telosb/uart.c | 89 ++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 84 insertions(+), 10 deletions(-) diff --git a/telosb/Makefile b/telosb/Makefile index 1f6fc07cb0..4f9b220a4a 100644 --- a/telosb/Makefile +++ b/telosb/Makefile @@ -5,6 +5,7 @@ export ARCH = telosb_base.a DEP = $(SRC:%.c=$(BINDIR)%.d) +INCLUDES += -I${RIOTBOARD}/${BOARD}/include/ INCLUDES += -I${RIOTBASE}/core/include/ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include diff --git a/telosb/board.c b/telosb/board.c index d461e3b4c1..37b21b4caa 100644 --- a/telosb/board.c +++ b/telosb/board.c @@ -2,8 +2,8 @@ * board.c - Board initiazilation for the TelosB * Copyright (C) 2013 Oliver Hahm * - * This file subject to the terms and conditions of the GLGPLv2 License. See the file LICENSE in the - * top level directory for more details. + * This file subject to the terms and conditions of the LGPLv2. See the file + * LICENSE in the top level directory for more details. */ #include "cpu.h" diff --git a/telosb/uart.c b/telosb/uart.c index b8cdcdcd76..1e97bfb569 100644 --- a/telosb/uart.c +++ b/telosb/uart.c @@ -1,22 +1,51 @@ - /* - * uart.c - Implementation for the TelosB UART - * Copyright (C) 2013 Oliver Hahm - * - * This file subject to the terms and conditions of the GLGPLv2 License. See the file LICENSE in the - * top level directory for more details. - */ +/* + * uart.c - Implementation for the TelosB UART + * Copyright (C) 2013 Oliver Hahm + * + * This file subject to the terms and conditions of the LGPLv2. See the file + * LICENSE in the top level directory for more details. + */ #include #include #include "cpu.h" #include "board.h" #include "kernel.h" +#include "board_uart0.h" #define UART1_TX U1TXBUF #define UART1_WAIT_TXDONE() while ( (U1TCTL & TXEPT) == 0 ) { _NOP(); } #define BAUDRATE (115200ul) +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); +} + void uart_init(void) { UCTL1 = SWRST; /* hold UART1 module in reset */ @@ -26,10 +55,13 @@ void uart_init(void) UTCTL1 |= SSEL1; /* UCLK = SCLK */ UBR01 = F_CPU / BAUDRATE; UBR11 = (F_CPU / BAUDRATE) >> 8; - UMCTL1 = 0x4A; /* modulation */ + UMCTL1 = calc_umctl(F_CPU / BAUDRATE); /* set modulation */ ME2 |= UTXE1 + URXE1; /* enable UART1 TX/RX */ UCTL1 &= ~SWRST; /* clear UART1 reset bit */ + + IE2 |= URXIE1; /* enable rx interrupt */ + IFG1 &= ~UTXIFG1; } int putchar(int c) @@ -43,3 +75,44 @@ uint8_t uart_readByte(void) { return U1RXBUF; } + +void usart1irq(void); +/** + * \brief the interrupt function + */ +interrupt(USART1RX_VECTOR) usart1irq(void) +{ + int c = 0; + + /* Check status register for receive errors. */ + if (U1RCTL & RXERR) { + if (U1RCTL & FE) { + puts("rx framing error"); + } + + if (U1RCTL & OE) { + puts("rx overrun error"); + } + + if (U1RCTL & PE) { + puts("rx parity error"); + } + + if (U1RCTL & BRK) { + puts("rx break error"); + } + + /* Clear error flags by forcing a dummy read. */ + c = U1RXBUF; + } + +#ifdef MODULE_UART0 + else if (uart0_handler_pid) { + c = U1RXBUF; + uart0_handle_incoming(c); + uart0_notify_thread(); + } + +#endif +} + From df8c4a5ae6c8d7933dc17ca192f1697b646a13fb Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Thu, 22 Aug 2013 23:34:10 +0200 Subject: [PATCH 166/188] added board dependent part of the cc2420 for TelosB --- telosb/driver_cc2420.c | 247 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 telosb/driver_cc2420.c diff --git a/telosb/driver_cc2420.c b/telosb/driver_cc2420.c new file mode 100644 index 0000000000..67d926855f --- /dev/null +++ b/telosb/driver_cc2420.c @@ -0,0 +1,247 @@ + /* + * driver_cc2420.c - Implementation of the board dependent cc2420 functions. + * Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will + * Copyright (C) 2013 Oliver Hahm + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#include + +#include +#include +#include +#include + +#include + +#define ENABLE_DEBUG (1) +#include "debug.h" + +#define CC2420_RESETn_PIN 0x40 +#define CC2420_VREGEN_PIN 0x20 + +#define CC2420_FIFOP_PIN 0x01 +#define CC2420_GIO0_PIN 0x08 +#define CC2420_GIO1_PIN 0x10 +#define CC2420_CCA_PIN 0x40 +#define CC2420_SFD_PIN 0x02 + +#define CC2420_FIFOP (P1IN & CC2420_FIFOP_PIN) /* FIFOP <-> packet interrupt (P1.0) */ +#define CC2420_GIO0 (P1IN & CC2420_GIO0_PIN) /* FIFO <-> GIO0 - RX data available (P1.3) */ +#define CC2420_GIO1 (P1IN & CC2420_GIO1_PIN) /* CCA <-> GIO1 - clear channel (P1.4) */ +#define CC2420_SFD (P4IN & CC2420_SFD_PIN) /* SFD <-> TBL - start frame delimiter (P4.1) */ + +#define CC2420_CS_LOW (P4OUT &= ~0x04) /* P4.2 */ +#define CC2420_CS_HIGH (P4OUT |= 0x04) + +volatile int abort_count; +volatile int retry_count = 0; + +void cc2420_reset(void) +{ + P4OUT |= CC2420_VREGEN_PIN; + P4OUT &= ~CC2420_RESETn_PIN; + hwtimer_wait(500); + P4OUT |= CC2420_RESETn_PIN; +} + +void cc2420_gio0_enable(void) +{ + P1IFG &= ~CC2420_GIO0_PIN; /* Clear IFG for GIO0 */ + P1IE |= CC2420_GIO0_PIN; /* Enable interrupt for GIO0 */ +} + +void cc2420_gio0_disable(void) +{ + P1IE &= ~CC2420_GIO0_PIN; /* Disable interrupt for GIO0 */ + P1IFG &= ~CC2420_GIO0_PIN; /* Clear IFG for GIO0 */ +} + +void cc2420_gio1_enable(void) +{ + P1IFG &= ~CC2420_GIO1_PIN; /* Clear IFG for GIO1 */ + P1IE |= CC2420_GIO1_PIN; /* Enable interrupt for GIO1 */ +} + +void cc2420_gio1_disable(void) +{ + P1IE &= ~CC2420_GIO1_PIN; /* Disable interrupt for GIO1 */ + P1IFG &= ~CC2420_GIO1_PIN; /* Clear IFG for GIO1 */ +} + +void cc2420_before_send(void) +{ + /* Disable SFD interrupt before sending packet */ + /* However this is not used atm */ +} + +void cc2420_after_send(void) +{ + /* Enable SFD interrupt after sending packet */ + /* However this is not used atm */ +} + + +int cc2420_get_gio0(void) +{ + return CC2420_GIO0; +} + +int cc2420_get_gio1(void) +{ + return CC2420_GIO1; +} + +int cc2420_get_sfd(void) +{ + return CC2420_SFD; +} + +void cc2420_spi_cs(void) +{ + CC2420_CS_LOW; +} + +uint8_t cc2420_txrx(uint8_t data) +{ + /* Ensure TX Buf is empty */ + long c = 0; + IFG1 &= ~UTXIFG0; + IFG1 &= ~URXIFG0; + U0TXBUF = data; + while(!(IFG1 & UTXIFG0)) { + if (c++ == 1000000) { + puts("cc2420_txrx alarm()"); + } + } + /* Wait for Byte received */ + c = 0; + while(!(IFG1 & URXIFG0)) { + if (c++ == 1000000) { + puts("cc2420_txrx alarm()"); + } + } + return U0RXBUF; +} + + +void cc2420_spi_select(void) +{ + CC2420_CS_LOW; +} + +void cc2420_spi_unselect(void) { + CC2420_CS_HIGH; +} + +void cc2420_init_interrupts(void) +{ + unsigned int state = disableIRQ(); /* Disable all interrupts */ + P1SEL &= ~CC2420_FIFOP_PIN; /* must be <> 1 to use interrupts */ + + P1IE &= ~CC2420_FIFOP_PIN; /* Disable interrupt for GIO0 */ + P1IFG &= ~CC2420_FIFOP_PIN; /* Clear IFG for GIO0 */ + restoreIRQ(state); /* Enable all interrupts */ +} + +void cc2420_spi_init(void) +{ + /* Switch off async UART */ + while(!(U0TCTL & TXEPT)); /* Wait for empty UxTXBUF register */ + IE1 &= ~(URXIE0 + UTXIE0); /* Disable USART0 receive&transmit interrupt */ + ME1 &= ~(UTXE0 + URXE0); + + /* configure SPI-related pins */ + P3SEL |= 0x0E; /* P3.1 - SIMO mode, P3.2 - SOMI mode, P3.3 - SCL mode */ + P3DIR |= 0x0A; /* P3.1 and P3.3 as output */ + P3DIR &= ~(0x04); /* P3.2 as input for SOMI */ + P4OUT |= 0x04; /* P4.2 radio CS, hold high */ + P4DIR |= 0x04; /* P4.2 radio CS, output */ + + /* Keep peripheral in reset state */ + U0CTL = SWRST; + + /* 8-bit SPI Master 3-pin mode, with SMCLK as clock source */ + /* CKPL works also, but not CKPH+CKPL or none of them!! */ + U0CTL |= CHAR + SYNC + MM; + U0TCTL = CKPH + SSEL1 + SSEL0 + STC + TXEPT;; + + /* Ignore clockrate argument for now, just use clock source/2 */ + /* SMCLK = 8 MHz */ + U0BR0 = 0x02; /* Ensure baud rate >= 2 */ + U0BR1 = 0x00; + U0MCTL = 0x00; /* No modulation */ + U0RCTL = 0x00; /* Reset Receive Control Register */ + + /* Enable SPI mode */ + ME1 |= USPIE0; + + /* Release for operation */ + U0CTL &= ~SWRST; +} + +/* + * CC1100 receive interrupt + */ +interrupt (PORT1_VECTOR) __attribute__ ((naked)) cc2420_isr(void){ + __enter_isr(); + /* Check IFG */ + if ((P1IFG & CC2420_FIFOP_PIN) != 0) { + P1IFG &= ~CC2420_FIFOP_PIN; + if (cc2420_get_gio0()) { + cc2420_rx_irq(); + DEBUG("rx interrupt"); + } + else { + cc2420_rxoverflow_irq(); + DEBUG("[CC2420] rxfifo overflow"); + } + } + + else { + puts("cc2420_isr(): unexpected IFG!"); + /* Should not occur - only GDO1 and GIO1 interrupts are enabled */ + } + __exit_isr(); +} + +/** +\brief TimerB CCR1-6 interrupt service routine (taken from OpenWSN) +*/ +interrupt (TIMERB0_VECTOR) __attribute__ ((naked)) radiotimer_isr(void) { + uint16_t tbiv_local; + + /* reading TBIV returns the value of the highest pending interrupt flag */ + /* and automatically resets that flag. We therefore copy its value to the */ + /* tbiv_local local variable exactly once. If there is more than one */ + /* interrupt pending, we will reenter this function after having just left */ + /* it. */ + tbiv_local = TBIV; + + switch (tbiv_local) { + case 0x0002: /* CCR1 fires */ + if (TBCCTL1 & CCI) { + /* SFD pin is high */ + DEBUG("start of a frame\n"); + } + else { + /* SFD pin is low */ + DEBUG("end of a frame\n"); + } + break; + case 0x0004: /* CCR2 fires */ + break; + case 0x0006: /* CCR3 fires */ + break; + case 0x0008: /* CCR4 fires */ + break; + case 0x000a: /* CCR5 fires */ + break; + case 0x000c: /* CCR6 fires */ + break; + case 0x000e: /* timer overflow */ + break; + } +} From 5ae8378f29aedc627f3d69610b4f9fa299045868 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 27 Aug 2013 18:09:32 +0200 Subject: [PATCH 167/188] fixed interrupt implementation (#27) removed TIMERB0 interrupt (since we don't use SFD information for now) enable FIFOP interrupt in init_interrupts() --- telosb/driver_cc2420.c | 71 ++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/telosb/driver_cc2420.c b/telosb/driver_cc2420.c index 67d926855f..4ee7ce9d1d 100644 --- a/telosb/driver_cc2420.c +++ b/telosb/driver_cc2420.c @@ -94,6 +94,11 @@ int cc2420_get_gio1(void) return CC2420_GIO1; } +int cc2420_get_fifop(void) +{ + return CC2420_FIFOP; +} + int cc2420_get_sfd(void) { return CC2420_SFD; @@ -140,9 +145,16 @@ void cc2420_init_interrupts(void) { unsigned int state = disableIRQ(); /* Disable all interrupts */ P1SEL &= ~CC2420_FIFOP_PIN; /* must be <> 1 to use interrupts */ + P1SEL &= ~CC2420_GIO0_PIN; /* must be <> 1 to use interrupts */ - P1IE &= ~CC2420_FIFOP_PIN; /* Disable interrupt for GIO0 */ - P1IFG &= ~CC2420_FIFOP_PIN; /* Clear IFG for GIO0 */ + /* FIFO <-> GIO0 interrupt */ + P1IES |= CC2420_GIO0_PIN; /* Enables external interrupt on falling edge (for GIO0/FIFO) */ + P1IE |= CC2420_GIO0_PIN; /* Enable interrupt */ + P1IFG &= ~CC2420_GIO0_PIN; /* Clears the interrupt flag */ + + /* FIFOP <-> Packet interrupt */ + P1IE |= CC2420_FIFOP_PIN; /* Enable interrupt for FIFOP */ + P1IFG &= ~CC2420_FIFOP_PIN; /* Clear IFG for FIFOP */ restoreIRQ(state); /* Enable all interrupts */ } @@ -185,63 +197,26 @@ void cc2420_spi_init(void) /* * CC1100 receive interrupt */ -interrupt (PORT1_VECTOR) __attribute__ ((naked)) cc2420_isr(void){ +interrupt (PORT1_VECTOR) __attribute__ ((naked)) cc2420_isr(void) +{ __enter_isr(); /* Check IFG */ if ((P1IFG & CC2420_FIFOP_PIN) != 0) { P1IFG &= ~CC2420_FIFOP_PIN; - if (cc2420_get_gio0()) { - cc2420_rx_irq(); - DEBUG("rx interrupt"); - } - else { + cc2420_rx_irq(); + DEBUG("rx interrupt"); + } + /* GIO0 is falling => check if FIFOP is high, indicating an RXFIFO overflow */ + else if ((P1IFG & CC2420_GIO0) != 0) { + P1IFG &= ~CC2420_GIO0_PIN; + if (cc2420_get_fifop()) { cc2420_rxoverflow_irq(); DEBUG("[CC2420] rxfifo overflow"); } } - else { puts("cc2420_isr(): unexpected IFG!"); /* Should not occur - only GDO1 and GIO1 interrupts are enabled */ } __exit_isr(); } - -/** -\brief TimerB CCR1-6 interrupt service routine (taken from OpenWSN) -*/ -interrupt (TIMERB0_VECTOR) __attribute__ ((naked)) radiotimer_isr(void) { - uint16_t tbiv_local; - - /* reading TBIV returns the value of the highest pending interrupt flag */ - /* and automatically resets that flag. We therefore copy its value to the */ - /* tbiv_local local variable exactly once. If there is more than one */ - /* interrupt pending, we will reenter this function after having just left */ - /* it. */ - tbiv_local = TBIV; - - switch (tbiv_local) { - case 0x0002: /* CCR1 fires */ - if (TBCCTL1 & CCI) { - /* SFD pin is high */ - DEBUG("start of a frame\n"); - } - else { - /* SFD pin is low */ - DEBUG("end of a frame\n"); - } - break; - case 0x0004: /* CCR2 fires */ - break; - case 0x0006: /* CCR3 fires */ - break; - case 0x0008: /* CCR4 fires */ - break; - case 0x000a: /* CCR5 fires */ - break; - case 0x000c: /* CCR6 fires */ - break; - case 0x000e: /* timer overflow */ - break; - } -} From 1eb14f57c603561aff2464fe3f0195bb8f527258 Mon Sep 17 00:00:00 2001 From: Zakaria Kasmi Date: Wed, 7 Aug 2013 12:20:53 +0200 Subject: [PATCH 168/188] initial support for the avs-extrem-board --- avsextrem/Makefile | 38 + avsextrem/Makefile.include | 3 + avsextrem/avsextrem-cc1100.c | 250 ++++++ avsextrem/avsextrem-smb380.c | 1212 ++++++++++++++++++++++++++++++ avsextrem/avsextrem-ssp0.c | 344 +++++++++ avsextrem/board_init.c | 235 ++++++ avsextrem/include/board.h | 61 ++ avsextrem/include/configure.h | 95 +++ avsextrem/include/smb380-board.h | 234 ++++++ avsextrem/include/ssp0-board.h | 112 +++ avsextrem/include/type.h | 31 + 11 files changed, 2615 insertions(+) create mode 100644 avsextrem/Makefile create mode 100644 avsextrem/Makefile.include create mode 100644 avsextrem/avsextrem-cc1100.c create mode 100644 avsextrem/avsextrem-smb380.c create mode 100644 avsextrem/avsextrem-ssp0.c create mode 100644 avsextrem/board_init.c create mode 100644 avsextrem/include/board.h create mode 100644 avsextrem/include/configure.h create mode 100644 avsextrem/include/smb380-board.h create mode 100644 avsextrem/include/ssp0-board.h create mode 100644 avsextrem/include/type.h diff --git a/avsextrem/Makefile b/avsextrem/Makefile new file mode 100644 index 0000000000..3818708b88 --- /dev/null +++ b/avsextrem/Makefile @@ -0,0 +1,38 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = avsextrem_base.a + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBOARD)/msba2-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/lpc2387/include/ +INCLUDES += -I$(RIOTBASE)/drivers/cc110x + +all: $(BINDIR)$(ARCH) + "$(MAKE)" -C ../msba2-common + +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + mkdir -p $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + "$(MAKE)" -C ../msba2-common clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi + + + diff --git a/avsextrem/Makefile.include b/avsextrem/Makefile.include new file mode 100644 index 0000000000..741b952a92 --- /dev/null +++ b/avsextrem/Makefile.include @@ -0,0 +1,3 @@ +export INCLUDES += -I$(RIOTBOARD)/msba2-common/include + +include $(RIOTBOARD)/msba2-common/Makefile.include diff --git a/avsextrem/avsextrem-cc1100.c b/avsextrem/avsextrem-cc1100.c new file mode 100644 index 0000000000..3b8487bcb2 --- /dev/null +++ b/avsextrem/avsextrem-cc1100.c @@ -0,0 +1,250 @@ +/****************************************************************************** +Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/** + * @file + * @ingroup LPC2387 + * @brief CC1100 LPC2387 dependend functions + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Thomas Hillebrandt + * @version $Revision: 1781 $ + * + * @note $Id: avsextrem-cc1100.c 1781 2010-01-26 13:39:36Z hillebra $ + */ + +#include +#include +// cpu +#include "cpu.h" +// sys +#include "cc1100.h" +#include "arch_cc1100.h" +#include "cc1100_spi.h" +#include "gpioint.h" + +#define CC1100_GDO0 (FIO2PIN & BIT6) // read serial I/O (GDO0) +#define CC1100_GDO1 (FIO0PIN & BIT8) // read serial I/O (GDO1) +#define CC1100_GDO2 (FIO0PIN & BIT28) // read serial I/O (GDO2) + +#define SPI_TX_EMPTY (SSP1SR & SSPSR_TFE) +#define SPI_BUSY (SSP1SR & SSPSR_BSY) +#define SPI_RX_AVAIL (SSP1SR & SSPSR_RNE) + +#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 + +//#define DEBUG +#ifdef DEBUG + +#include "stdio.h" + +static unsigned long time_value; + +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; +} +#endif + +int cc1100_get_gdo0(void) { + return CC1100_GDO0; +} + +int cc1100_get_gdo1(void) { + return CC1100_GDO1; +} + +int cc1100_get_gdo2(void) { + return CC1100_GDO2; +} + +void cc1100_spi_init(void) +{ + // configure chip-select + FIO0DIR |= BIT6; + FIO0SET = BIT6; + + // Power + PCONP |= PCSSP1; // Enable power for SSP1 (default is on) + + // PIN Setup + PINSEL0 |= BIT15; // Set CLK function to SSP1 + PINSEL0 &= ~BIT14; + PINSEL0 |= BIT17 ; // Set MISO function to SSP1 + PINSEL0 &= ~BIT16; + PINSEL0 |= BIT19; // Set MOSI function to SSP1 + PINSEL0 &= ~BIT18; + // Interface Setup + SSP1CR0 = 7; + + // Clock Setup + uint32_t pclksel; + uint32_t cpsr; + lpc2387_pclk_scale(F_CPU/1000, 6000, &pclksel, &cpsr); + PCLKSEL0 &= ~(BIT21|BIT20); // CCLK to PCLK divider + PCLKSEL0 |= pclksel << 20; + SSP1CPSR = cpsr; + + // Enable + SSP1CR1 |= BIT1; // SSP-Enable + int dummy; + // Clear RxFIFO: + while( SPI_RX_AVAIL ) { // while RNE (Receive FIFO Not Empty)... + dummy = SSP1DR; // read data + } +} + +uint8_t +cc1100_txrx(uint8_t c) { + uint8_t result; + SSP1DR = c; +#ifdef DEBUG + set_time(); +#endif + while (!SPI_TX_EMPTY) { +#ifdef DEBUG + test_time(0); +#endif + } +#ifdef DEBUG + set_time(); +#endif + while (SPI_BUSY) { +#ifdef DEBUG + test_time(1); +#endif + } +#ifdef DEBUG + set_time(); +#endif + while (!SPI_RX_AVAIL) { +#ifdef DEBUG + test_time(2); +#endif + } + result = (uint8_t)SSP1DR; + return result; +} + +void cc1100_spi_cs(void) +{ + FIO0CLR = BIT6; +} + +void +cc1100_spi_select(void) +{ + volatile int retry_count = 0; + volatile int abort_count; + // Switch to GDO mode input + PINSEL0 &= ~(BIT17 + BIT16);// Set MISO function to GPIO + FIO0DIR &= ~BIT8; + cs_low: + // CS to low + abort_count = 0; + FIO0CLR = BIT6; + // 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; + } + FIO0SET = BIT6; // CS to high + goto cs_low; // try again + } + goto loop; + } + final: + // Switch to SPI mode + PINSEL0 |= BIT17; // Set MISO function to SSP1 + PINSEL0 &= ~BIT16; +} + +void +cc1100_spi_unselect(void) +{ + FIO0SET = BIT6; +} + +void cc1100_gdo2_disable(void) { + gpioint_set(0, BIT28, GPIOINT_DISABLE, NULL); +} + +void cc1100_gdo2_enable(void) { + gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc1100_gdo2_irq); +} + +void cc1100_before_send(void) +{ + // Disable GDO2 interrupt before sending packet + cc1100_gdo2_disable(); +} + +void cc1100_after_send(void) +{ + // Enable GDO2 interrupt after sending packet + cc1100_gdo2_enable(); +} + +void cc1100_gdo0_enable(void) { + gpioint_set(2, BIT6, GPIOINT_RISING_EDGE, &cc1100_gdo0_irq); +} + +void cc1100_gdo0_disable(void) { + gpioint_set(2, BIT6, GPIOINT_DISABLE, NULL); +} + + + + +void cc1100_init_interrupts(void) +{ + // Enable external interrupt on low edge (for GDO2) + FIO0DIR &= ~BIT28; + cc1100_gdo2_enable(); + // Enable external interrupt on low edge (for GDO0) + FIO2DIR &= ~BIT6; +} + + diff --git a/avsextrem/avsextrem-smb380.c b/avsextrem/avsextrem-smb380.c new file mode 100644 index 0000000000..b2dacc7d83 --- /dev/null +++ b/avsextrem/avsextrem-smb380.c @@ -0,0 +1,1212 @@ +/* + * msba2acc-smb380.c - implementation of the Driver for the SMB380 acceleration sensor. + * Copyright (C) 2013 Freie Universität Berlin + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +/** + * @file + * @internal + * @brief SMB380 acceleration sensor drivers for the LPC2387 + * + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi + * @version $Revision: 3854 $ + * + * @note $Id: msba2acc-smb380.c 3854 2010-01-18 15:27:01Z zkasmi $ + */ + + +#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ +#include "cpu.h" +#include "lpm.h" +//#include "PatrecInit.h" +#include "VIC.h" +#include "kernel.h" +#include "ssp0-board.h" +#include "smb380-board.h" +#include "hwtimer.h" +#include +#include +// for fk_thread: +#include "sched.h" +#include "msg.h" +#include "irq.h" + +//#include "hal-board.h" +#include "gpioint.h" +#include "stdlib.h" +#include "math.h" +#include "lpc2387.h" + +/* program example + * + * + * + * +SMB380_init(); //Initializes SPI and the SMB380 accelerator sensor +SMB380_setRange(SMB380_RANGE_8G); +//SMB380_setBandWidth(SMB380_BAND_WIDTH_100HZ); +SMB380_enableNewDataInt(); + +while( readRingBuff(accInt) ) { + printf("[%4i|%4i|%4i|%4i]\r\n", accInt[0], accInt[1], accInt[2], accInt[3]); + ktimer_wait(KTIMER_TICKS(1000000)); + //actualizeRingReadPointer(); //update read-pointer position to a current measurement (drop unread ones) +} +*/ + +uint8_t simple_pid; +int16_t simple_buffer[4]; + +volatile int16_t* ringBuff_X = NULL; +volatile int16_t* ringBuff_Y = NULL; +volatile int16_t* ringBuff_Z = NULL; +volatile int16_t* ringBuff_T = NULL; +uint16_t readPointerPos[SMB380_RING_BUFF_MAX_THREADS]; +u_char PointerList[SMB380_RING_BUFF_MAX_THREADS]; +static msg_t wakeupmessage; + +uint8_t (*smb380function)(int16_t*); //pointer to a user-defined function which is called during a writepointer action + +uint16_t sampleRateSMB380; + +bool dynRange = false; //condition if range-check should be done +uint8_t counter_Decreasing = 0; + +volatile uint16_t interruptTicksSMB380; + +typedef struct{ + u_int writePointerPos; //Writepointer position + uint8_t countRange; //check value for updated range settings (only needed for multiplication in Float-mode + uint8_t range; //current range +} settingsSMB380; + +settingsSMB380 settings; + +/* measuring temperature dependent internal sample rate of SMB380 */ +static volatile uint32_t tickStart = 0; +static volatile uint32_t tickLastSample = 0; +static volatile uint32_t tickCurrentSamples = 0; + +uint8_t initRingReadPointerforCurrentThread(void); +uint8_t getRingReadPointerforCurrentThread(void); +void wakeUpRegisteredProcesses(void); +uint8_t smb380emptyfunction(int16_t*); +static void SMB380_extIntHandler(void); + +extern unsigned long ktimer_now(void); + +float SMB380_getSampleRatio(void) +{ + return ((1.0 / ((float)(tickLastSample - tickStart) / tickCurrentSamples)) * 100000) /*/ (float)(SMB380_SAMPLE_RATE_MAX / sampleRateSMB380)*/; +} + +uint8_t smb380emptyfunction(int16_t* value) +{ + return 1; +} + +uint8_t SMB380_HystereseFunctionSample(int16_t* value) +{ + static int16_t x=0, y=0, z=0; + static uint8_t counter = 0; + int16_t delta = abs(value[0]-x) + abs(value[1]-y) + abs(value[2]-z); + if(delta <40) //TODO: delta and counter are constant values, change it! + counter++; + else counter = 0; + + x= value[0]; y= value[1]; z= value[2]; + + if(smb380_mode == SMB380_THRESHOLD){ + SMB380_disableAnyMotionLimit(); + SMB380_enableNewDataInt(); + smb380_mode = SMB380_CONTINOUS; + printf("Threshold: x=%i, y=%i, z=%i\n\r",value[0], value[1], value[2]); + } + + if((counter== 100) && (smb380_mode == SMB380_POLL)){ + //MZ SMB380_disableNewDataInt(); + //SMB380_setAnyMotionLimit(100,0); + SMB380_enableAnyMotionLimit(); + smb380_mode = SMB380_THRESHOLD; + counter = 0; //n�tig? + } + else if(counter== 100) + { + SMB380_disableNewDataInt(); + //SMB380_setAnyMotionLimit(100,0); + SMB380_enableAnyMotionLimit(); + smb380_mode = SMB380_FALSEALERT; + counter = 0; //n�tig? + return 0; + } + + + return 1; +} + +static void SMB380_simple_interrupthandler(void) +{ + lpm_awake(); + + SMB380_getAcceleration(SMB380_X_AXIS, NULL, &simple_buffer[0]); + SMB380_getAcceleration(SMB380_Y_AXIS, NULL, &simple_buffer[1]); + SMB380_getAcceleration(SMB380_Z_AXIS, NULL, &simple_buffer[2]); + simple_buffer[3] = SMB380_getTemperature(); + + if (interruptTicksSMB380 >= sampleRateSMB380 - 1) { + interruptTicksSMB380 = 0; + wakeupmessage.type = MSG_TYPE_SMB380_WAKEUP; + msg_send(&wakeupmessage, simple_pid, 0); + } else { + interruptTicksSMB380++; + } + return; +} + +// enables simple Interrupt driven Mode +uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t range) +{ + SSP0Init(); + interruptTicksSMB380 = 0; + simple_pid = active_thread->pid; + gpioint_set(0, BIT1, GPIOINT_RISING_EDGE, &SMB380_simple_interrupthandler); + SMB380_softReset(); + hwtimer_wait(HWTIMER_TICKS(100000)); + SMB380_disableUpperLimit(); + SMB380_disableLowerLimit(); + SMB380_setSampleRate(samplerate); + SMB380_setBandWidth(bandwidth); + SMB380_setRange(range); + + return 0; +} + +uint8_t SMB380_init(uint8_t (*func)(int16_t*)) +{ + SSP0Init(); + +#if SMB380_EXTINT_MODE + if(gpioint_set(0, BIT1, GPIOINT_RISING_EDGE, &SMB380_extIntHandler)); +#endif + + interruptTicksSMB380 = 0; + + if(func != NULL) + smb380function = func; + else + smb380function = smb380emptyfunction; + + //smb380function = SMB380_HystereseFunctionSample; //Platzhalter + + SMB380_softReset(); + hwtimer_wait(HWTIMER_TICKS(100000)); + SMB380_disableUpperLimit(); + SMB380_disableLowerLimit(); + + smb380_mode = SMB380_POLL; + SMB380_setSampleRate(SMB380_SAMPLE_RATE_MAX); //set output to 3000 Hz + + settings.writePointerPos = 0; + settings.range = 0; + settings.countRange = 0; + for(int i=0; i 0 && rate <= SMB380_SAMPLE_RATE_MAX ) { + sampleRateSMB380 = SMB380_SAMPLE_RATE_MAX / rate; + } else { + sampleRateSMB380 = 1; + } +} + +uint16_t SMB380_getSampleRate(void){ + return SMB380_SAMPLE_RATE_MAX / sampleRateSMB380; +} + +uint8_t SMB380_Prepare(void) +{ + return SSP0Prepare(SMB380_ACC,16,1,1,8000); +} + +uint8_t SMB380_Unprepare(void) +{ + return SSP0Unprepare(SMB380_ACC); +} + +/* return the pointerNo related with the current thread */ +uint8_t getRingReadPointerforCurrentThread(void) +{ + uint8_t pointerNo = 0; + while((PointerList[pointerNo]!=active_thread->pid)&&(pointerNo0)&&(pointerNopid; + readPointerPos[pointerNo] = settings.writePointerPos; + return 1; + } +} + +void freeRingReadPointer(void) +{//Should be Threadsafe + uint8_t pointerNo = getRingReadPointerforCurrentThread(); + if(pointerNo!=SMB380_RING_BUFF_MAX_THREADS){ + PointerList[pointerNo] = 0; + } +} + +void actualizeRingReadPointer(void) +{ + uint8_t pointerNo = getRingReadPointerforCurrentThread(); + if(pointerNo!=SMB380_RING_BUFF_MAX_THREADS){ + readPointerPos[pointerNo] = settings.writePointerPos; + } +} + +//TODO more read-pointer +uint8_t readRingBuff(int16_t* value){ + +// if( inISR() ) { +// if( readPointerPos[pointerNo] == settings.writePointerPos ) +// return 0; +// } else { +// while( readPointerPos[pointerNo] != settings.writePointerPos ) { +// uint8_t x = 254; +//// while( x ) +//// x--; +// } +// } + + // zugriff auf pid +// if(getRead fk_thread->pid kenn ich schon) +// { +// pointerno[pid]; +// } +// else +// { +// initRingReadPointerforCurrentThread(); +// } + uint8_t pointerNo = getRingReadPointerforCurrentThread(); + // If thread is not known to read on the ringbuffer, try adding him to the list of known threads, otherwise exit with error + if(pointerNo==SMB380_RING_BUFF_MAX_THREADS) { + if(!initRingReadPointerforCurrentThread()) { + //printf("%sNo Readpointer left, maximum of %u is reached!\n\r", SMB380_DEBUG_MESSAGE, SMB380_RING_BUFF_MAX_THREADS); + return 0; + } + else{ + pointerNo = getRingReadPointerforCurrentThread(); + } + } + + if(readPointerPos[pointerNo] == settings.writePointerPos) { + value[0] = 0; value[1] = 0; value[2] = 0; value[3] = 0; + return 0; + } + value[0] = ringBuff_X[readPointerPos[pointerNo]]; + value[1] = ringBuff_Y[readPointerPos[pointerNo]]; + value[2] = ringBuff_Z[readPointerPos[pointerNo]]; + value[3] = ringBuff_T[readPointerPos[pointerNo]]; + readPointerPos[pointerNo]+=1; + + if(readPointerPos[pointerNo]==SMB380_RING_BUFF_SIZE){ + readPointerPos[pointerNo] = 0; + } + return 1; +} + +//TODO more read-pointer +uint8_t writeRingBuff(int16_t* value){ + if(smb380_mode == SMB380_FALSEALERT) { + smb380_mode = SMB380_THRESHOLD; + return 0; + } + if( (interruptTicksSMB380 >= sampleRateSMB380 - 1) || (smb380_mode == SMB380_THRESHOLD) ) { + interruptTicksSMB380 = 0; + + /* measuring temperature dependent internal sample rate of SMB380 */ + if(smb380_mode == SMB380_CONTINOUS){ + tickLastSample = ktimer_now(); + tickCurrentSamples++; + } + + ringBuff_X[settings.writePointerPos] = value[0]; + ringBuff_Y[settings.writePointerPos] = value[1]; + ringBuff_Z[settings.writePointerPos] = value[2]; + ringBuff_T[settings.writePointerPos] = value[3]; + + /* check for increasing range if dynRange is true */ + if(dynRange) + smb380function = checkRange; + else + smb380function = smb380emptyfunction; + + smb380function(value); + + //printf("Werte: x=%i, y=%i, z=%i\n\r",value[0], value[1], value[2]); + //vgpio_toggle(&gpio_led_green); + + settings.writePointerPos += 1; + + if( settings.writePointerPos == SMB380_RING_BUFF_SIZE ) { + settings.writePointerPos = 0; + } + wakeUpRegisteredProcesses(); + return 1; + } + else { + interruptTicksSMB380++; + return 0; + } +} + +void SMB380_activateDynRangeSet(uint8_t activate) +{ + switch(activate){ + case 0: dynRange=false ; break; + case 1: dynRange=true ; break; + } +} + +/* + * checking for in-/decreasing range + */ +uint8_t checkRange(int16_t* value){ + bool increased = false; + + // printf("CurrentValues: %i %i %i \r\n", xyzTMP[0], xyzTMP[1], xyzTMP[2]); + + // determination of max and min value + int16_t maxValue = value[0]; // max(xValue, max(yValue, zValue)); + int16_t minValue = value[0]; // min(xValue, min(yValue, zValue)); + + for (int i=1; i<3; i++){ + if (value[i]>maxValue) + maxValue=value[i]; + if (value[i]1800)||(minValue<-1800)){ + SMB380_setRange(SMB380_RANGE_4G); + increased = true; + printf("=== Set range from 2 g to 4 g ===\r\n"); + } + break; + case 4: + if ((maxValue>3800)||(minValue<-3800)){ + SMB380_setRange(SMB380_RANGE_8G); + increased = true; + printf("=== Set range from 4 g to 8 g ===\r\n"); + } + break; + case 8: break; + } + + /* check for decreasing range */ + if (increased){ + counter_Decreasing = 0; + }else{ + //decrease range after 10 consecutive relevant values + switch(isRange){ + case 2: break; + case 4: + if ((maxValue < 2000)&&(minValue > -2000)){ + if (counter_Decreasing >= 9){ + SMB380_setRange(SMB380_RANGE_2G); + printf("=== Set range from 4 g to 2 g ===\r\n"); + counter_Decreasing = 0; + }else{ + counter_Decreasing++; + } + }else{ + counter_Decreasing = 0; + } + break; + case 8: + if ((maxValue < 4000)&&(minValue > -4000)){ + if (counter_Decreasing >= 9){ + SMB380_setRange(SMB380_RANGE_4G); + printf("=== Set range from 8 g to 4 g ===\r\n"); + counter_Decreasing = 0; + }else{ + counter_Decreasing++; + } + }else{ + counter_Decreasing = 0; + } + break; + } + } + return 0; +} + + +void wakeUpRegisteredProcesses(void) +{ + uint8_t pointerNo = 0; + //wake up waiting processes + wakeupmessage.type = MSG_TYPE_SMB380_WAKEUP; + while((PointerList[pointerNo]>0)&&(pointerNo>1) + SMB380_TEMP_OFFSET; + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return t; +} + +void SMB380_getAcceleration(unsigned char axis, int16_t *pAbs, int16_t *pMg) +{ + unsigned short ur; + + if(!settings.countRange && (pMg != NULL)){ + settings.countRange = 1; + settings.range = SMB380_getRange(); + } + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + switch( axis ) { + case SMB380_X_AXIS: + SMB380_ssp_write(SMB380_ACC_X_MSB, 0, SMB380_READ_REGISTER); + SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA, 0, SMB380_READ_REGISTER); + break; + case SMB380_Y_AXIS: + SMB380_ssp_write(SMB380_ACC_Y_MSB, 0, SMB380_READ_REGISTER); + SMB380_ssp_write(SMB380_ACC_Y_LSB_NEWDATA, 0, SMB380_READ_REGISTER); + break; + default: + SMB380_ssp_write(SMB380_ACC_Z_MSB, 0, SMB380_READ_REGISTER); + SMB380_ssp_write(SMB380_ACC_Z_LSB_NEWDATA, 0, SMB380_READ_REGISTER); + } + + ur = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + ur |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; + SMB380_Unprepare(); + restoreIRQ(cpsr); + + if( pAbs != NULL ) { + if( ur & BIT9 ) { //ur<0 + *pAbs = ur | 0xFC00; + } else { + *pAbs = ur & 0x03FF; + } + } + + if( pMg != NULL ) { + if( ur & BIT9 ) { //ur<0 + *pMg = -(((settings.range * (512 - (ur & 0x1FF)))* 2000) / 1024); + } else { + *pMg = ((settings.range * ur) * 2000) / 1024; + } + } + +} + +unsigned char SMB380_getChipID(void) +{ + unsigned char ur = 0; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CHIP_ID, 0, 0); + ur = (unsigned char)(SMB380_ssp_read() & SMB380_CHIP_ID_MASK); + restoreIRQ(cpsr); + return ur; +} + +void SMB380_setWakeUpPause(unsigned char duration) +{ + unsigned char utemp; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + utemp = SMB380_ssp_read(); + utemp &= ~SMB380_CONTROL4_WAKEUP_PAUSE_MASK; + utemp |= (duration & (0x3) << 1);//+1; + SMB380_ssp_write(SMB380_CONTROL4, utemp, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +unsigned char SMB380_getWakeUpPause(void) +{ + unsigned char up; + + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + up = (unsigned char)SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + up &= SMB380_CONTROL4_WAKEUP_PAUSE_MASK; + up = up >> 1; + + return up; +} + +void SMB380_setBandWidth(unsigned char bandWidth) +{ + unsigned char utemp; + + if( (bandWidth == SMB380_BAND_WIDTH_100HZ) | + (bandWidth == SMB380_BAND_WIDTH_1500HZ) | + (bandWidth == SMB380_BAND_WIDTH_190HZ) | + (bandWidth == SMB380_BAND_WIDTH_25HZ) | + (bandWidth == SMB380_BAND_WIDTH_375HZ) | + (bandWidth == SMB380_BAND_WIDTH_50HZ) | + (bandWidth == SMB380_BAND_WIDTH_750HZ) ) { + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); + utemp = SMB380_ssp_read(); + utemp &= ~SMB380_CONTROL3_BANDWITH_MASK; + utemp |= (bandWidth & 0x7); + SMB380_ssp_write(SMB380_CONTROL3, utemp, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + } +} + +void SMB380_setRange(unsigned char range) +{ + unsigned char utemp = 0; + + if( range != 0x3 ) { + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); + utemp = (unsigned char)SMB380_ssp_read(); + utemp &= ~SMB380_CONTROL3_RANGE_MASK; + utemp |= (range & 0x3) << 3; + SMB380_ssp_write(SMB380_CONTROL3, utemp, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + settings.countRange = 0; + } + +} + +unsigned char SMB380_getRange(void) +{ + unsigned char ur; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); + ur = (SMB380_ssp_read() & SMB380_CONTROL3_RANGE_MASK) >> 3; + SMB380_Unprepare(); + restoreIRQ(cpsr); + + switch(ur){ + case SMB380_RANGE_2G: return 2; + case SMB380_RANGE_4G: return 4; + case SMB380_RANGE_8G: return 8; + default: return 4; + } +} + +unsigned char SMB380_getBandWidth(void) +{ + unsigned char uBand; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); + uBand = SMB380_ssp_read() & SMB380_CONTROL3_BANDWITH_MASK; + SMB380_Unprepare(); + restoreIRQ(cpsr); + return uBand; +} + +int16_t SMB380_getBandWidthAbs(void) +{ + unsigned char uBand; + uBand = SMB380_getBandWidth(); + + switch(uBand){ + case SMB380_BAND_WIDTH_25HZ: return 25; + case SMB380_BAND_WIDTH_50HZ: return 50; + case SMB380_BAND_WIDTH_100HZ: return 100; + case SMB380_BAND_WIDTH_190HZ: return 190; + case SMB380_BAND_WIDTH_375HZ: return 375; + case SMB380_BAND_WIDTH_750HZ: return 750; + case SMB380_BAND_WIDTH_1500HZ: return 1500; + default: return uBand; + } +} + +void SMB380_softReset(void) +{ + unsigned char ur; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL1, SMB380_CONTROL1_SOFT_RESET_MASK, SMB380_WRITE_REGISTER); + ur = ((unsigned char)SMB380_ssp_read()) & SMB380_CONTROL1_SOFT_RESET_MASK; + SMB380_Unprepare(); + restoreIRQ(cpsr); + ur = ur >> 1; +} + +void SMB380_setCustomerReg(unsigned char data) +{ + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CUST1, data, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +unsigned char SMB380_getCustomerReg(void) +{ + unsigned uReg = 0; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CUST1, 0, SMB380_READ_REGISTER); + uReg = (unsigned char)SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + return uReg; +} + +/* Selftest + * + * */ +void SMB380_Selftest_1(void) +{ + unsigned char uReg = 0; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_LG_THRES, 6, SMB380_WRITE_REGISTER); + //SSP0Init(); + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_LG_DUR, 0, SMB380_WRITE_REGISTER); + //SSP0Init(); + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); + + uReg = (unsigned char)SMB380_ssp_read(); + uReg &= ~SMB380_CONTROL1_SELF_TEST_1_MASK; + uReg |= 0x01 << 3; + SMB380_ssp_write(SMB380_CONTROL1, uReg, SMB380_WRITE_REGISTER); +// SSP0Init(); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_ShowMemory(void) +{ + uint16_t uReg = 0; + uint8_t bitMask[16]; + printf("SMB380 Speicher\n\r"); + unsigned long cpsr; + for(unsigned char regAd=0x16;regAd>0;regAd--){ + cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(regAd-1, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + printf("Register: = %X: 0x%X = ", regAd-1, uReg); + for(int pos=0; pos<16; pos++) //uReg != 0) + { + bitMask[15-pos] = uReg %2; + + uReg = uReg /2; + } + for(int pos=8; pos<16; pos++) //uReg != 0) + { + printf ("%d",bitMask[pos]); + if((pos%4) == 0) printf(" "); + } + printf("\n"); + } +} + +void SMB380_setUpperLimit(void){ + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_HG_THRES, 128, SMB380_WRITE_REGISTER); //1g + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_HG_DUR, 0, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_enableUpperLimit(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_HG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_disableUpperLimit(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_HG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_enableLowerLimit(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_LG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_disableLowerLimit(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_LG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +/* @param gvaluefloat - value is in mg + * @param gvalueint - value in range of 0 to 512 + * Choose one of them, set the other to zero + */ +uint8_t SMB380_setAnyMotionLimit(uint16_t mg, uint16_t gvalueint){ + + uint8_t threshold = 0; + if(mg !=0){ + threshold = mg / (15.6 * (SMB380_getRange()/2)); + } + else if(gvalueint != 0){ + threshold = ceil(((gvalueint * 2000)/512.0) / 15.6); //Scaling for different gRanges is not needed + } + else return 0; + + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_ANY_MOTION_THRES, threshold, SMB380_WRITE_REGISTER); //0,3g = 300 / 15,6mg = 19 + SMB380_ssp_read(); + //Set duration at this point + SMB380_ssp_write(SMB380_ANY_MOTION_DUR_HYST, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); +// SMB380_ssp_write(SMB380_ANY_MOTION_DUR_HYST, (uReg & ~SMB380_ANY_MOTION_DUR_MASK) | 0x40, SMB380_WRITE_REGISTER); +// SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + return 1; +} + +void SMB380_enableAnyMotionLimit(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_ENABLE_ADV_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ANY_MOTION_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_disableAnyMotionLimit(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ANY_MOTION_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_ENABLE_ADV_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_enableNewDataInt(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + //prevent deep sleep, reason: 400�s wake-up time is to long for 3kHz interrupts + SETBIT(lpm_prevent_sleep, LPM_PREVENT_SLEEP_ACCSENSOR); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_NEW_DATA_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + /* measuring temperature dependent internal sample rate of SMB380 */ + tickStart = ktimer_now(); + tickCurrentSamples = 0; + restoreIRQ(cpsr); +} + +void SMB380_disableNewDataInt(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_NEW_DATA_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + //enable deep sleep, reason: 400�s wake-up time was to long for 3kHz interrupts + CLRBIT(lpm_prevent_sleep, LPM_PREVENT_SLEEP_ACCSENSOR); + restoreIRQ(cpsr); +} + +void SMB380_resetInterruptFlags(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_RESET_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_enableEEPROM(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_EE_W_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_disableEEPROM(void){ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL1, uReg & ~SMB380_CONTROL1_EE_W_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +//void SMB380_calibrate(void){ +// unsigned short uMSB, uLSB; +// //TODO 25Hz, 2G +// +// SMB380_ssp_write(SMB380_ACC_X_MSB, 0, SMB380_READ_REGISTER); +// SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA, 0, SMB380_READ_REGISTER); +// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; +// uLSB = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; +// +// SMB380_ssp_write(SMB380_ACC_X_MSB + SMB380_EEPROM_OFFSET, uMSB, SMB380_WRITE_REGISTER); +// SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA + SMB380_EEPROM_OFFSET, uLSB, SMB380_WRITE_REGISTER); +// +// +// SMB380_ssp_write(SMB380_ACC_Y_MSB, 0, SMB380_READ_REGISTER); +// SMB380_ssp_write(SMB380_ACC_Y_LSB_NEWDATA, 0, SMB380_READ_REGISTER); +// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; +// uLSB |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; +// +// SMB380_ssp_write(SMB380_ACC_Z_MSB, 0, SMB380_READ_REGISTER); +// SMB380_ssp_write(SMB380_ACC_Z_LSB_NEWDATA, 0, SMB380_READ_REGISTER); +// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; +// uLSB |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; +// +// +//} + +/* + * Return offsets from offset registers, + * remove xyz afterwards because it is useless + */ +unsigned char SMB380_readOffset(uint16_t *offset) +{ + if( sizeof(offset) < 3 ) + return false; + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); + uReg = ((SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6); + SMB380_ssp_write(SMB380_OFFSET_MSB_X, 0, SMB380_READ_REGISTER); + uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + + + offset[0] = uReg; + printf("Offset X: %u ", uReg); + + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); + uReg = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; + SMB380_ssp_write(SMB380_OFFSET_MSB_Y, 0, SMB380_READ_REGISTER); + uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + + offset[1] = uReg; + printf("Offset Y: %u ", uReg); + + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); + uReg = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; + SMB380_ssp_write(SMB380_OFFSET_MSB_Z, 0, SMB380_READ_REGISTER); + uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + + offset[2] = uReg; + printf("Offset Z: %u \r\n", uReg); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return true; +} + +unsigned char SMB380_readOffsetTemp(uint16_t *offset) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); + uReg = ((SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6); + SMB380_ssp_write(SMB380_OFFSET_MSB_T, 0, SMB380_READ_REGISTER); + uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + + + offset[0] = uReg; + printf("Offset T: %u ", uReg); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return true; +} + +/* EEPROM = 1 if data has to be written in EEPROM and not only in image + * + */ +void SMB380_writeOffset(uint16_t *offset, uint8_t EEPROM) +{ + printf("Writing Offset X: %u Y: %u Z: %u\r\n", offset[0], offset[1], offset[2]); + if( sizeof(offset) >= 3 ) + { + uint16_t eeoffset = 0; + if( EEPROM ) + eeoffset = SMB380_EEPROM_OFFSET; //create offset if saving to EEPROM is needed + + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + //x-Axis + uReg = (offset[0] & 0x03) << 6; //get both LSB Bits + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); //write them to image or eeprom + uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + uReg = (offset[0] & 0x3FC) >> 2; //get MSB Bits + SMB380_ssp_write(SMB380_OFFSET_MSB_X + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + //y-Axis + uReg = (offset[1] & 0x03) << 6; //get both LSB Bits + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); //write them to image or eeprom + uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + uReg = (offset[1] & 0x3FC) >> 2; //get MSB Bits + SMB380_ssp_write(SMB380_OFFSET_MSB_Y + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + //z-Axis + uReg = (offset[2] & 0x03) << 6; //get both LSB Bits + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); //write them to image or eeprom + uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + uReg = (offset[2] & 0x3FC) >> 2; //get MSB Bits + SMB380_ssp_write(SMB380_OFFSET_MSB_Z + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + } +} + +void SMB380_writeOffsetTemp(uint16_t *offset, uint8_t EEPROM) +{ + printf("Writing Offset Temp: %u\r\n", offset[0]); + if( sizeof(offset) >= 1 ) + { + uint16_t eeoffset = 0; + if( EEPROM ) + eeoffset = SMB380_EEPROM_OFFSET; //create offset if saving to EEPROM is needed + + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + //T-Axis + uReg = (offset[0] & 0x03) << 6; //get both LSB Bits + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); //write them to image or eeprom + uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + uReg = (offset[0] & 0x3FC) >> 2; //get MSB Bits + SMB380_ssp_write(SMB380_OFFSET_MSB_T + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + } +} + +unsigned char SMB380_readGain(uint16_t *gain) +{ + if( sizeof(gain) < 3 ) + return false; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + //x-gain + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); + gain[0] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); + //y-gain + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); + gain[1] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); + //z-gain + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); + gain[2] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return true; +} + +unsigned char SMB380_readGainTemp(uint16_t *gain) +{ + if( sizeof(gain) < 1 ) + return false; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + //T-gain + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); + gain[0] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return true; +} + + diff --git a/avsextrem/avsextrem-ssp0.c b/avsextrem/avsextrem-ssp0.c new file mode 100644 index 0000000000..3a9be8ed07 --- /dev/null +++ b/avsextrem/avsextrem-ssp0.c @@ -0,0 +1,344 @@ +/* + * avsextrem-ssp0.c - implementation of the SPI0 interface for the LPC2387. + * Copyright (C) 2013 Freie Universität Berlin + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +/** + * @file + * @internal + * @brief Implements the SPI0 interface for the LPC2387 + * + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi + * @version $Revision: 3854 $ + * + * @note $Id: avsextrem-ssp0.c 3854 2010-01-18 15:27:01Z zkasmi $ + */ + +#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ +#include "cpu.h" +#include "VIC.h" +#include "ssp0-board.h" +#include "smb380-board.h" +//#include "mma7455l-board.h" +#include "gpioint.h" +#include "hwtimer.h" +#include +#include "lpm.h" + +//uint16_t sampleRateMMA7455L; +//uint16_t interruptTicksMMA7455L; +// +//static void MMA7455L_extIntHandler(void); + +/***************************************************************************** + ** Function name: SSP0Init + ** + ** Descriptions: SSP0 port initialization routine + ** + ** parameters: None + ** Returned value: true or false, if the interrupt handler + ** can't be installed correctly, return false. + ** + *****************************************************************************/ +uint32_t SSP0Init(void) +{ + + /* enable clock to SSP0 for security reason. By default, it's enabled already */ + PCONP |= PCSSP0; + //TODO CLK, MISO, MOSI standardm��ig als GPIOs konfigurieren +#if USE_CS +// PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; //P1.20 1.21 1.23 1.24 +#else +// PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 SSEL0 nicht + +#endif + +#if SSP1_INTERRUPT_MODE + if ( install_irq( SSP1_INT, (void *)SSP0Handler, HIGHEST_PRIORITY ) == FALSE ) + { + return (FALSE); + } + + /* Set SSPINMS registers to enable interrupts */ + /* enable all error related interrupts */ + SSP1IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM; +#endif + + return (1); +} + +/* datasize (wordsize) in decimal (4-16), cpol&cpha =(0/1) and frequency divided by 1000 (e.g. 8 MHz = 8000) + * + */ +uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol,uint8_t cpha, uint16_t freq) +{ + switch(chip) + { + case BMA180_INTERN: + case SMB380_ACC:{ +#if USE_CS + PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; //P1.20 1.21 1.23 1.24 +#else + + PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 SSEL0 nicht +#endif + break; + } + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: + case ACAMDMS:{ +#if USE_CS + PINSEL0 |= BIT31; + PINSEL1 |= BIT1 | BIT3 | BIT5; //P0.15 0.16 0.17 0.18 +#else + //Turn on NanoPAN + PINSEL0 |= BIT31; + PINSEL1 |= BIT3 | BIT5; //0.15 0.17 0.18 SSEL0 nicht +#endif + break; + } + case NORDIC:{ + PINSEL0 |= BIT31; + PINSEL1 |= BIT3 | BIT5; //0.15 0.17 0.18 SSEL0 nicht + break; + } + default: { + printf("wrong CHIP selected\n"); + return 0; + } + } + uint32_t SSP0CR0tmp = 0; + + switch(datasize) + { + case 4: SSP0CR0tmp = BIT0 | BIT1; break; + case 5: SSP0CR0tmp = BIT2; break; + case 6: SSP0CR0tmp = BIT0 | BIT2; break; + case 7: SSP0CR0tmp = BIT1 | BIT2; break; + case 8: SSP0CR0tmp = BIT0 | BIT1 | BIT2; break; + case 9: SSP0CR0tmp = BIT3; break; + case 10: SSP0CR0tmp = BIT0 | BIT3; break; + case 11: SSP0CR0tmp = BIT1 | BIT3; break; + case 12: SSP0CR0tmp = BIT0 | BIT1 | BIT3; break; + case 13: SSP0CR0tmp = BIT2 | BIT3; break; + case 14: SSP0CR0tmp = BIT0 | BIT2 | BIT3; break; + case 15: SSP0CR0tmp = BIT1 | BIT2 | BIT3; break; + case 16: SSP0CR0tmp = BIT0 | BIT1 | BIT2 | BIT3; break; + default: return 0; + } + if(cpol) SSP0CR0tmp|= BIT6; + if(cpha) SSP0CR0tmp|= BIT7; + + SSP0CR1 = 0x00; //SSP0 disabled + + /* Setting xx-Bit Datasize, CPOL and CPHA*/ + SSP0CR0 = SSP0CR0tmp; + + // Clock Setup + uint32_t pclksel; + uint32_t cpsr; + lpc2387_pclk_scale(F_CPU / 1000, freq, &pclksel, &cpsr); + PCLKSEL1 &= ~(BIT10 | BIT11); // CCLK to PCLK divider ??? + PCLKSEL1 |= pclksel << 10; + SSP0CPSR = cpsr; + + // Enable + SSP0CR1 |= BIT1; //SSP0 enabled + + uint32_t Dummy; + for( uint32_t i = 0; i < FIFOSIZE; i++ ) { + Dummy = SSP0DR; // clear the RxFIFO + } + return 1; +} + +uint8_t SSP0Unprepare(uint8_t chip) +{ + switch(chip) + { + case BMA180_INTERN: + case SMB380_ACC:{ + //Turn off Acceleration Sensor + PINSEL3 &= ~(BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17); + FIO1DIR |= BIT20 | BIT21 | BIT24; + FIO1DIR &= ~BIT23; //MISO as Input + FIO1SET = BIT20 | BIT24; //CLK + SSEL + MOSI GPIO as Output //TODO depends on CPOL+CPHA Settings + FIO1CLR = BIT21; + break; + } + case BMA180_EXTERN: + case L3G_EXTERN: + case NORDIC: + case NANOPAN: + case ACAMDMS:{ + //Turn off Nanopan (Pins to GPIO) + PINSEL0 &= ~(BIT30 | BIT31); //CLK to GPIO + PINSEL1 &= ~(BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5); + FIO0DIR |= BIT15 | BIT16 | BIT18; //CLK + SSEL + MOSI GPIO as Output + FIO0DIR &= ~BIT17; //MISO as Input + FIO0SET = BIT15 | BIT16; //CLK + SSEL + MOSI GPIO as Output //TODO depends on CPOL+CPHA Settings + FIO0CLR = BIT18; + break; + } + default: { + printf("wrong CHIP selected\n"); + return 0; + } + } + return 1; +} + +unsigned char SMB380_ssp_write(const unsigned char regAddr, const unsigned char data, unsigned char flag) +{ + + uint16_t temp = 0; + if( flag ) { + temp = (unsigned int)(((regAddr & 0xFF7F) << 8) | data); + + } else { + temp = (((unsigned int)(regAddr | 0x80) << 8) | 0xFF); + } + + return SSP0_write(temp, SMB380_ACC); +} + +unsigned char SSP0_write(const uint16_t data, uint8_t device) +{ + unsigned char ret = 1; + + while( (SSP0SR & (SSPSR_TNF | SSPSR_BSY)) != SSPSR_TNF ) + ; + if( !USE_CS ) { + switch( device ) { + case BMA180_INTERN: + case SMB380_ACC: { + FIO1CLR = SSP0_SEL; + break; + } + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: + { + printf("[%s] line: %d\n", __FUNCTION__,__LINE__); + FIO0CLR = SSP0_SELN; + break; + } + case ACAMDMS: + case NORDIC: + //Chip Select is done in Nordic driver + break; + default: + ret = 0; + goto ret; + } + } + SSP0DR = data; + if( !USE_CS ) { + while( SSP0SR & SSPSR_BSY ) + ; + switch( device ) { + case BMA180_INTERN: + case SMB380_ACC: { + FIO1SET = SSP0_SEL; + break; + } + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: + { + FIO0SET = SSP0_SELN; + break; + } + case ACAMDMS: + case NORDIC: + //Chip Select is done in Nordic driver + break; + default: + ret = 0; + goto ret; + } + } + +ret: return ret; +} + +unsigned short SSP0_read(uint8_t device) +{ + uint16_t data; + + while( !(SSP0SR & SSPSR_RNE) ) + ; + + if( !USE_CS ) { + switch( device ) { + case BMA180_INTERN: + case SMB380_ACC: { + FIO1CLR = SSP0_SEL; + break; + } + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: + { + FIO0CLR = SSP0_SELN; + break; + } + case NORDIC: + case ACAMDMS: + //Chip Select is done in Nordic driver + break; + default: + data = 0xFFFF; + goto ret; + } + } + data = SSP0DR; + if( !USE_CS ) { + switch( device ) { + case BMA180_INTERN: + case SMB380_ACC: { + FIO1SET = SSP0_SEL; + break; + } + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: + { + FIO0SET = SSP0_SELN; + break; + } + case ACAMDMS: + case NORDIC: + //Chip Select is done in Nordic driver + break; + default: + data = 0xFFFF; + goto ret; + } + } + ret: return data; +} + +unsigned short SMB380_ssp_read(void) +{ + return SSP0_read(SMB380_ACC); +} + +unsigned short nrf24l01_ssp_read_write(const uint8_t data) +{ + SSP0_write(data, NORDIC); + return SSP0_read(NORDIC); +} + +unsigned short acam_trx(const uint8_t data) +{ + SSP0_write(data, ACAMDMS); + return SSP0_read(ACAMDMS); +} + diff --git a/avsextrem/board_init.c b/avsextrem/board_init.c new file mode 100644 index 0000000000..442e3660da --- /dev/null +++ b/avsextrem/board_init.c @@ -0,0 +1,235 @@ +/****************************************************************************** +Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +/** + * @ingroup avsextrem + * @{ + */ + +/** + * @file + * @brief avsextrem board initialization + * + * @author Freie Universit�t Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Kaspar Schleise + * @author Michael Baar + * @author Zakaria Kasmi + * @author Marco Ziegert + * @author Stefan Pfeiffer + * + * @note $Id: board_init.c 1071 2009-04-30 10:15:56Z hwill $ + */ +#include "lpc23xx.h" +#include "VIC.h" +#include "cpu.h" +#include "gpioint.h" + +#define PCRTC BIT9 +#define CL_CPU_DIV 4 + + +/*---------------------------------------------------------------------------*/ +static inline void +pllfeed(void) +{ + PLLFEED = 0xAA; + PLLFEED = 0x55; +} + +/*---------------------------------------------------------------------------*/ +void init_clks1(void) +{ + // Disconnect PLL + PLLCON &= ~0x0002; + pllfeed(); + while (PLLSTAT & BIT25); // wait until PLL is disconnected before disabling - deadlock otherwise + + // Disable PLL + PLLCON &= ~0x0001; + pllfeed(); + while (PLLSTAT & BIT24); // wait until PLL is disabled + + SCS |= 0x10; // main OSC between 15MHz and 24MHz (more stable in tests) + SCS |= 0x20; // Enable main OSC + while( !(SCS & 0x40) ); // Wait until main OSC is usable + + /* select main OSC, 16MHz, as the PLL clock source */ + CLKSRCSEL = 0x0001; + + // Setting Multiplier and Divider values + PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz + pllfeed(); + + // Enabling the PLL */ + PLLCON = 0x0001; + pllfeed(); + + /* Set clock divider to 4 (value+1) */ + CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz + +#if USE_USB + USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ +#endif +} + +/*---------------------------------------------------------------------------*/ +void bl_init_ports(void) +{ + SCS |= BIT0; // Set IO Ports to fast switching mode + + /* UART0 */ + PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 + PINSEL0 &= ~(BIT5 + BIT7); + + //PTTU: + + /*Turn Board on*/ +// PINMODE0 |= BIT1; +// FIO0DIR |= BIT27; +// FIO0CLR = BIT27; +// 0.27 + + /* 5V*/ +// FIO1DIR |= BIT28; // Synch +// FIO1SET = BIT28; // No Powersave +// 1.28 + +// FIO1DIR |= BIT27; // 5V off +// FIO1CLR = BIT27; +// 1.27 + + /* Disable Resistors on Buttons */ +// PINMODE4 |= BIT9 + BIT11; +// + + /* Disable Resistors on LED - and Ports to output*/ + PINMODE7 |= BIT19 + BIT21; //3.25 + 3.26 + PINMODE2 |= BIT1; //1.0 + FIO1DIR |= BIT0; + FIO3DIR |= BIT25 + BIT26; + FIO1SET = BIT0; //all off + 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; // ** +// 1.22 + 1.25 + 1.26 + + // 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 +// 1.1 + 0.1 + 0.10 + 0.11 + + // LTC4150 ARM + FIO0DIR |= BIT5; + FIO0CLR = BIT5; + + // LTC4150 System +// FIO0DIR |= BIT24; +// FIO0CLR = BIT24; +// 0.23 + 0.24 + + // Battery Voltage (AD) + PINMODE1 |= BIT19; //0.25 + PINSEL1 &= ~BIT19; + PINSEL1 |= BIT18; + + //cc1100 + FIO0DIR |= BIT6 + BIT7 + BIT9; + FIO0SET = BIT6; + FIO0SET = BIT7 + BIT9; + + //SMB380 + FIO1DIR |= BIT20 + BIT21 + BIT24; //SCK + CSB + SDI + FIO1SET = BIT21; + FIO1SET = BIT20 + 24; + + //SHT11 + FIO1DIR |= BIT25; //1.25 + PINSEL3 &= ~(BIT12|BIT13 | BIT18|BIT19); + + //SD + FIO0DIR &= ~( BIT19 | BIT20 | BIT21 | BIT22) ; //0.19 0.20 0.21 0.22 as input + PINMODE1 |= (BIT7) | (BIT9) | (BIT11) | (BIT13); // no resistors + FIO2DIR &= ~( BIT11 + BIT12 + BIT13 ); //2.11 2.12 2.13 as input + PINMODE4 |= (BIT23) | (BIT25) | (BIT27); // no resistors + + //Tetra +// FIO2DIR |= BIT0 + BIT7; +// 2.0 bis 2.7 + + // No Pullups on any port +// Does not work, needs more current than pull-ups +// 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/avsextrem/include/board.h b/avsextrem/include/board.h new file mode 100644 index 0000000000..11da670e0e --- /dev/null +++ b/avsextrem/include/board.h @@ -0,0 +1,61 @@ +/** + * @ingroup conf + * @ingroup avsextrem + * + * @{ + */ + +/** + * @file + * @brief avsextrem board configuration + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author baar + * @author Zakaria Kasmi + * @version $Revision: 1127 $ + * + * @note $Id: board-conf.h 1127 2009-05-13 08:48:29Z baar $ + */ + + +#ifndef BOARDCONF_H_ +#define BOARDCONF_H_ +#include + + +#define FEUERWARE_CONF_BOARD_NAME "FU Berlin AVSEXTREM BOARD" + +#define LED_RED_PIN (BIT25) +#define LED_GREEN_PIN (BIT26) + +#define LED_GREEN_OFF (FIO3SET = LED_GREEN_PIN) +#define LED_GREEN_ON (FIO3CLR = LED_GREEN_PIN) +#define LED_GREEN_TOGGLE (FIO3PIN ^= LED_GREEN_PIN) + +#define LED_RED_OFF (FIO3SET = LED_RED_PIN) +#define LED_RED_ON (FIO3CLR = LED_RED_PIN) +#define LED_RED_TOGGLE (FIO3PIN ^= LED_RED_PIN) + + + +#ifdef MODULE_CC110X +#define FEUERWARE_CONF_NUM_RADIOS 1 +#else +#define FEUERWARE_CONF_NUM_RADIOS 0 +#endif + +// if FAT is enabled this board supports files +#define FEUERWARE_CONF_CORE_SUPPORTS_FILES defined(MODULE_FAT) + +#ifdef MODULE_FAT +#define CFG_CONF_MEM_SIZE 0x7FFFFFFF +#define SYSLOG_CONF_NUM_INTERFACES 2 +#else +#define SYSLOG_CONF_NUM_INTERFACES 1 +#endif + +void init_clks1(void); + +/** @} */ +#endif /* BOARDCONF_H_ */ + diff --git a/avsextrem/include/configure.h b/avsextrem/include/configure.h new file mode 100644 index 0000000000..f12f3e1b89 --- /dev/null +++ b/avsextrem/include/configure.h @@ -0,0 +1,95 @@ +/****************************************************************************** +Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. + +These sources were developed at the Freie Universitaet Berlin, Computer Systems +and Telematics group (http://cst.mi.fu-berlin.de). +------------------------------------------------------------------------------- +This file is part of FeuerWare. + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +FeuerWare is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see http://www.gnu.org/licenses/ . +-------------------------------------------------------------------------------- +For further information and questions please use the web site + http://scatterweb.mi.fu-berlin.de +and the mailinglist (subscription via web site) + scatterweb@lists.spline.inf.fu-berlin.de +*******************************************************************************/ + +#ifndef CONFIGURE_H_ +#define CONFIGURE_H_ + +/** + * @defgroup conf Offline Configuration + * @ingroup feuerware + * + * The offline configuration file "configure.h" is automatically + * included in every file by the build system and allows to configure + * all neccessary defines on cpu, board and project level. + * + * The configuration is built of + * \li a project specific file (project-conf.h) + * \li a board specific file (board-conf.h) and + * \li a cpu specific file (cpu-conf.h). + * All of which are chosen by the build system depending on your arguments. + * + * @{ + */ + +/** + * @file + * @brief Central offline configuration + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author baar + * @version $Revision: 3854 $ + * + * @note $Id: configure.h 3854 2011-12-06 15:27:01Z hwill $ + */ + +//#include "project-conf.h" +//#include "board-conf.h" +#include "cpu-conf.h" + +#ifdef MODULE_SYSMON + #ifndef TRACELOG_CONF_NUM_ENTRIES + #define TRACELOG_CONF_NUM_ENTRIES 10 + #endif +#else + #undef TRACELOG_CONF_NUM_ENTRIES +#endif + + +/* ------------------------------------------------------------------------- */ +/* + * documentation of defines that do not belong to a specific module: + */ + +/** + * @def FEUERWARE_CONF_BOARD_NAME + * @brief Defines the name of the board as a string + */ + +/** + * @def FEUERWARE_CONF_CPU_NAME + * @brief Defines the name of the cpu as a string + */ + +/** + * @def FEUERWARE_CONF_SUPPORTS_FILES + * @brief Defines if standard library file functions are available + */ +#ifndef FEUERWARE_CONF_SUPPORTS_FILES +#define FEUERWARE_CONF_SUPPORTS_FILES 0 +#endif + +/** @} */ +#endif /* CONFIGURE_H_ */ diff --git a/avsextrem/include/smb380-board.h b/avsextrem/include/smb380-board.h new file mode 100644 index 0000000000..a45e38a893 --- /dev/null +++ b/avsextrem/include/smb380-board.h @@ -0,0 +1,234 @@ +/* + * msba2acc-smb380.h - header file of the Driver for the SMB380 acceleration sensor. + * Copyright (C) 2013 Freie Universität Berlin + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +/** + * @file + * @internal + * @brief SMB380 acceleration sensor definitions for the LPC2387 + * + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi + * @version $Revision: 3854 $ + * + * @note $Id: msba2acc-smb380.h 3854 2010-01-18 15:27:01Z zkasmi $ + * + */ + +#ifndef SMB380_H_ +#define SMB380_H_ +#include +#include + +#define SMB380_DEBUG_MESSAGE "SMB380 Driver Error: " + +#define MSG_TYPE_SMB380_WAKEUP 814 + +#define SMB380_X_AXIS 0 //X Axis-Name +#define SMB380_Y_AXIS 1 //Y Axis-Name +#define SMB380_Z_AXIS 2 //Z Axis-Name + +#define LPM_PREVENT_SLEEP_ACCSENSOR BIT2 + +enum SMB380_MODE{ + SMB380_POLL, + SMB380_POLL_AFTER_CONTINOUS, + SMB380_CONTINOUS, + SMB380_THRESHOLD, + SMB380_FALSEALERT +}; +//volatile enum SMB380_MODE +volatile enum SMB380_MODE smb380_mode;// = SMB380_POLL; + +/* Writeable values to EEPROM: from 0x0A (control1) to 0x1D (offset_T). + For writing enable ... flag and add eeprom_offset_address. + + Generally it is a good idea to read out shared register addresses before writing, + registers 0x14 and 34h are especially critical. +*/ + +#define SMB380_EEPROM_OFFSET 0x20 + +#define SMB380_CHIP_ID 0x00 //Chip-ID Bit0-2, default: 010b +#define SMB380_CHIP_ID_MASK 0x07 //Chip-ID mask + +#define SMB380_AL_ML_VERSION 0x01 //ml_version Bit0-3 ; al_version Bit4-7 +#define SMB380_AL_MASK 0xF0 //al_mask +#define SMB380_ML_MASK 0x0F //ml_mask + +#define SMB380_ACC_X_LSB_NEWDATA 0x02 //LSB_acc_x Bit6-7 ; new_data_x Bit0 +#define SMB380_ACC_X_MSB 0x03 //MSB_acc_x Bit0-7 +#define SMB380_ACC_Y_LSB_NEWDATA 0x04 //LSB_acc_y Bit6-7 ; new_data_y Bit0 +#define SMB380_ACC_Y_MSB 0x05 //MSB_acc_y Bit0-7 +#define SMB380_ACC_Z_LSB_NEWDATA 0x06 //LSB_acc_z Bit6-7 ; new_data_z Bit0 +#define SMB380_ACC_Z_MSB 0x07 //MSB_acc_z Bit0-7 +#define SMB380_ACC_LSB_MASK 0xC0 +#define SMB380_ACC_MSB_MASK 0xFF +#define SMB380_ACC_NEWDATA_MASK 0x01 + +#define SMB380_TEMP 0x08 //Temperature Bit0-7 + +#define SMB380_STATUS 0x09 //Status register, contains six flags +#define SMB380_STATUS_ST_RESULT_MASK 0x80 +#define SMB380_STATUS_ALERT_PHASE_MASK 0x10 +#define SMB380_STATUS_LG_LATCHED_MASK 0x08 +#define SMB380_STATUS_HG_LATCHED_MASK 0x04 +#define SMB380_STATUS_STATUS_LG_MASK 0x02 +#define SMB380_STATUS_STATUS_HG_MASK 0x01 + +#define SMB380_CONTROL1 0x0A //Control register - contains seven values, default: x000 0000b +#define SMB380_CONTROL1_RESET_INT_MASK 0x40 +#define SMB380_CONTROL1_UPDATE_MASK 0x20 +#define SMB380_CONTROL1_EE_W_MASK 0x10 +#define SMB380_CONTROL1_SELF_TEST_1_MASK 0x08 +#define SMB380_CONTROL1_SELF_TEST_0_MASK 0x04 +#define SMB380_CONTROL1_SOFT_RESET_MASK 0x02 +#define SMB380_CONTROL1_SLEEP_MASK 0x01 + +#define SMB380_CONTROL2 0x0B //Control register - contains six values, default: x000 0011b +#define SMB380_CONTROL2_ALERT_MASK 0x80 +#define SMB380_CONTROL2_ANY_MOTION_MASK 0x40 +#define SMB380_CONTROL2_COUNTER_HG_MASK 0x30 +#define SMB380_CONTROL2_COUNTER_LG_MASK 0x0C +#define SMB380_CONTROL2_ENABLE_HG_MASK 0x02 +#define SMB380_CONTROL2_ENABLE_LG_MASK 0x01 + +#define SMB380_LG_THRES 0x0C // , default: 20 +#define SMB380_LG_DUR 0x0D // , default: 150 +#define SMB380_HG_THRES 0x0E // , default: 160 +#define SMB380_HG_DUR 0x0F // , default: 150 +#define SMB380_ANY_MOTION_THRES 0x10 // , default: 0 +#define SMB380_ANY_MOTION_DUR_HYST 0x1 // , default: 0000 0000b +#define SMB380_ANY_MOTION_DUR_MASK 0xC0 +#define SMB380_ANY_MOTION_DUR_HG_HYST_MASK 0x38 +#define SMB380_ANY_MOTION_DUR_LG_HYST_MASK 0x07 + +#define SMB380_CUST1 0x12 // , default: 162 +#define SMB380_CUST2 0x13 // , default: 13 + +#define SMB380_CONTROL3 0x14 // , default: xxx0 1110b +#define SMB380_CONTROL3_RANGE_MASK 0x18 +#define SMB380_CONTROL3_BANDWITH_MASK 0x07 + +#define SMB380_CONTROL4 0x15 // , default: 1000 0000b +#define SMB380_CONTROL4_SPI4_MASK 0x80 +#define SMB380_CONTROL4_ENABLE_ADV_INT_MASK 0x40 +#define SMB380_CONTROL4_NEW_DATA_INT_MASK 0x20 +#define SMB380_CONTROL4_LATCH_INT_MASK 0x10 +#define SMB380_CONTROL4_SHADOW_DIS_MASK 0x08 +#define SMB380_CONTROL4_WAKEUP_PAUSE_MASK 0x06 +#define SMB380_CONTROL4_WAKEUP_MASK 0x01 + +#define SMB380_OFFSET_LSB_GAIN_X 0x16 +#define SMB380_OFFSET_LSB_GAIN_Y 0x17 +#define SMB380_OFFSET_LSB_GAIN_Z 0x18 +#define SMB380_OFFSET_LSB_GAIN_T 0x19 +#define SMB380_OFFSET_LSB_MASK 0xC0 +#define SMB380_OFFSET_GAIN_MASK 0x3F + +#define SMB380_OFFSET_MSB_X 0x1A +#define SMB380_OFFSET_MSB_Y 0x1B +#define SMB380_OFFSET_MSB_Z 0x1C +#define SMB380_OFFSET_MSB_T 0x1D + +#define SMB380_TEMP_OFFSET -30 +#define SMB380_DEFAULT_MAXG 4.0f +#define SMB380_READ_REGISTER 0x00 +#define SMB380_WRITE_REGISTER 0x01 +#define SMB380_WAKE_UP_PAUSE_20MS 0x00 +#define SMB380_WAKE_UP_PAUSE_80MS 0x01 +#define SMB380_WAKE_UP_PAUSE_320MS 0x02 +#define SMB380_WAKE_UP_PAUSE_2560MS 0x03 +#define SMB380_RANGE_2G 0x00 +#define SMB380_RANGE_4G 0x01 +#define SMB380_RANGE_8G 0x02 +#define SMB380_BAND_WIDTH_25HZ 0x00 +#define SMB380_BAND_WIDTH_50HZ 0x01 +#define SMB380_BAND_WIDTH_100HZ 0x02 +#define SMB380_BAND_WIDTH_190HZ 0x03 +#define SMB380_BAND_WIDTH_375HZ 0x04 +#define SMB380_BAND_WIDTH_750HZ 0x05 +#define SMB380_BAND_WIDTH_1500HZ 0x06 +#define SMB380_RING_BUFF_SIZE 256 //SMB380_RING_BUFF_SIZE * int16_t (2Byte) * 4 (x,y,z,Temp) = 512 Byte (for 64) +//TODO chsnge size to 2048 +#define SMB380_RING_BUFF_MAX_THREADS 10 +#define SMB380_SAMPLE_RATE_MAX 3000 + +/* change from Header (public) to internal use (private) (use it after every write to EEPROM) + * set update_image Bit in control1 to + * copie content from EEPROM (0x2B to 0x3D) to Image (0x0B to 0x1D) */ +void SMB380_update_image(void); + +/* change from Header (public) to internal use (private) + * set ee_w Bit in control1 to + * enable read to 0x16 to 0x22 and + * enable write to 0x16 to 0x3D */ +void SMB380_enable_eeprom_default(void); + +uint8_t SMB380_HystereseFunctionSample(int16_t* value); //Example Hysterese functon + +// simple api for single-sample, single thread interrupt mode +uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t range); + + + +uint8_t SMB380_init(uint8_t (*func)(int16_t*)); // enables Interrupts (normally only once called) +void SMB380_setSampleRate(uint16_t rate); +uint16_t SMB380_getSampleRate(void); +void freeRingReadPointer(void); +void actualizeRingReadPointer(void); +uint8_t readRingBuff(int16_t* value); +uint8_t writeRingBuff(int16_t* value); +void SMB380_activateDynRangeSet(uint8_t activate); +uint8_t checkRange(int16_t* value); + +void SMB380_enableEEPROM(void); +void SMB380_disableEEPROM(void); + +// getter +float SMB380_getSampleRatio(void); +void SMB380_getAcceleration(unsigned char axis, int16_t *pAbs, int16_t *pMg); +int16_t SMB380_getTemperature(void); +unsigned char SMB380_getChipID(void); +unsigned char SMB380_getWakeUpPause(void); +unsigned char SMB380_getBandWidth(void); +int16_t SMB380_getBandWidthAbs(void); +unsigned char SMB380_getRange(void); +unsigned char SMB380_getCustomerReg(void); +unsigned char SMB380_readOffset(uint16_t *offset); +unsigned char SMB380_readOffsetTemp(uint16_t *offset); +unsigned char SMB380_readGain(uint16_t *gain); +unsigned char SMB380_readGainTemp(uint16_t *gain); + +// setter +void SMB380_setTempOffset(uint16_t offset, uint8_t EEPROM); +void SMB380_setWakeUpPause(unsigned char duration); +void SMB380_setBandWidth(unsigned char bandWidth); +void SMB380_setRange(unsigned char range); +void SMB380_softReset(void); +void SMB380_setCustomerReg(unsigned char data); +void SMB380_setUpperLimit(void); +void SMB380_enableUpperLimit(void); +void SMB380_disableUpperLimit(void); +void SMB380_enableLowerLimit(void); +void SMB380_disableLowerLimit(void); +uint8_t SMB380_setAnyMotionLimit(uint16_t mg, uint16_t gvalueint); +void SMB380_enableAnyMotionLimit(void); +void SMB380_disableAnyMotionLimit(void); +void SMB380_enableNewDataInt(void); +void SMB380_disableNewDataInt(void); +void SMB380_resetInterruptFlags(void); +void SMB380_writeOffset(uint16_t *offset, uint8_t EEPROM); +void SMB380_writeOffsetTemp(uint16_t *offset, uint8_t EEPROM); + +// stats +void SMB380_ShowMemory(void); +void SMB380_Selftest_1(void); + + +#endif /* SMB380_H_ */ diff --git a/avsextrem/include/ssp0-board.h b/avsextrem/include/ssp0-board.h new file mode 100644 index 0000000000..4145a2f6e5 --- /dev/null +++ b/avsextrem/include/ssp0-board.h @@ -0,0 +1,112 @@ +/* + * ssp0-borad.h - header file of the SPI interface for the LPC2387. + * Copyright (C) 2013 Freie Universität Berlin + * + * This source code is licensed under the GNU General Public License, + * Version 3. See the file LICENSE for more details. + */ + +/** + * @file + * @internal + * @brief SPI interface definitions for the LPC2387 + * + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi + * @version $Revision: 3854 $ + * + * @note $Id: avsextrem-ssp0.c 3854 2010-01-18 15:27:01Z zkasmi $ + */ +#ifndef __SSP_H__ +#define __SSP_H__ + +#include "stdint.h" + +#define DMA_ENABLED 0 + +/* if USE_CS is zero, set SSEL as GPIO that you have total control of the sequence */ +#define USE_CS 0 + +/* if 1, use driver for onboard BMA180, otherwise for external BMA180 utilizing Nanopan Connector */ +#define BMA180_ONBOARD 1 + +#define SMB380_ACC 0 +#define NANOPAN 1 +#define NORDIC 2 +#define BMA180_EXTERN 3 +#define BMA180_INTERN 4 +#define L3G_EXTERN 5 +#define L3G_INTERN 6 +#define ACAMDMS 7 + +/* SPI read and write buffer size */ +#define BUFSIZE 256 +#define FIFOSIZE 8 + +/* SSP select pin */ +#define SSP0_SEL 1 << 21 //P1.21 SMB380 + +#define SSP0_SELN 1 << 16 //P0.16 Nanotron + +/* SSP1 external interrupt Pin (SMB380 specific) */ +#define SMB380_INT1 1 << 1 //P0.1 +#define BMA180_INT1 1 << 8 //P2.8 + + + +/* SSP1 CR0 register */ +#define SSPCR0_DSS 1 << 0 +#define SSPCR0_FRF 1 << 4 +#define SSPCR0_SPO 1 << 6 +#define SSPCR0_SPH 1 << 7 +#define SSPCR0_SCR 1 << 8 + +/* SSP1 CR1 register */ +#define SSPCR1_LBM 1 << 0 +#define SSPCR1_SSE 1 << 1 +#define SSPCR1_MS 1 << 2 +#define SSPCR1_SOD 1 << 3 + +/* SSP1 Interrupt Mask Set/Clear register */ +#define SSPIMSC_RORIM 1 << 0 +#define SSPIMSC_RTIM 1 << 1 +#define SSPIMSC_RXIM 1 << 2 +#define SSPIMSC_TXIM 1 << 3 + +/* SSP1 Interrupt Status register */ +#define SSPRIS_RORRIS 1 << 0 +#define SSPRIS_RTRIS 1 << 1 +#define SSPRIS_RXRIS 1 << 2 +#define SSPRIS_TXRIS 1 << 3 + +/* SSP1 Masked Interrupt register */ +#define SSPMIS_RORMIS 1 << 0 +#define SSPMIS_RTMIS 1 << 1 +#define SSPMIS_RXMIS 1 << 2 +#define SSPMIS_TXMIS 1 << 3 + +/* SSP1 Interrupt clear register */ +#define SSPICR_RORIC 1 << 0 +#define SSPICR_RTIC 1 << 1 + +#define SSP1_INTERRUPT_MODE 0 +#define SMB380_EXTINT_MODE 1 +#define BMA180_EXTINT_MODE 1 + +uint32_t SSP0Init( void ); +uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol,uint8_t cpha, uint16_t freq); +uint8_t SSP0Unprepare(uint8_t chip); +unsigned char SSP0_write(const uint16_t data, uint8_t device); +unsigned short SSP0_read(uint8_t device); +unsigned char SMB380_ssp_write(const unsigned char regAddr, const unsigned char data, unsigned char flag); +unsigned short SMB380_ssp_read(void); +unsigned short nrf24l01_ssp_read_write(const uint8_t data); +unsigned short acam_trx(const uint8_t data); +void SSP0Handler(void); + +#endif /* __SSP_H__ */ +/***************************************************************************** +** End Of File +******************************************************************************/ + diff --git a/avsextrem/include/type.h b/avsextrem/include/type.h new file mode 100644 index 0000000000..d2098f25ad --- /dev/null +++ b/avsextrem/include/type.h @@ -0,0 +1,31 @@ +/***************************************************************************** + * type.h: Type definition Header file for NXP LPC230x Family Microprocessors + * + * Copyright(C) 2006, NXP Semiconductor + * All rights reserved. + * + * History + * 2006.09.01 ver 1.00 Prelimnary version, first Release + * +******************************************************************************/ +#ifndef __TYPE_H__ +#define __TYPE_H__ + +#ifndef NULL +#define NULL ((void *)0) +#endif + +#ifndef FALSE +#define FALSE (0) +#endif + +#ifndef TRUE +#define TRUE (1) +#endif + +typedef unsigned char BYTE; +typedef unsigned short WORD; +typedef unsigned long DWORD; +typedef unsigned int BOOL; + +#endif /* __TYPE_H__ */ From f5e419b4cb4d4023533af8de77261afe8866bffb Mon Sep 17 00:00:00 2001 From: Zakaria Kasmi Date: Wed, 7 Aug 2013 12:25:03 +0200 Subject: [PATCH 169/188] updated board common initialization --- msba2-common/board_common_init.c | 41 +++----------------- msba2/board_init.c | 65 ++++++++++++++++++++++++++++++++ msba2/include/board.h | 2 + 3 files changed, 72 insertions(+), 36 deletions(-) diff --git a/msba2-common/board_common_init.c b/msba2-common/board_common_init.c index a437cce2b7..5db84af7ab 100644 --- a/msba2-common/board_common_init.c +++ b/msba2-common/board_common_init.c @@ -37,9 +37,10 @@ and the mailinglist (subscription via web site) * @author Heiko Will * @author Kaspar Schleiser * @author Michael Baar - * + * @author Zakaria Kasmi * @note $Id$ */ +#include #include #include #include @@ -69,44 +70,11 @@ pllfeed(void) PLLFEED = 0xAA; PLLFEED = 0x55; } -/*---------------------------------------------------------------------------*/ -void init_clks1(void) -{ - // Disconnect PLL - PLLCON &= ~0x0002; - pllfeed(); - // Disable PLL - PLLCON &= ~0x0001; - pllfeed(); - SCS |= 0x20; // Enable main OSC - - while (!(SCS & 0x40)); // Wait until main OSC is usable - - /* select main OSC, 16MHz, as the PLL clock source */ - CLKSRCSEL = 0x0001; - - // Setting Multiplier and Divider values - PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz - pllfeed(); - - // Enabling the PLL */ - PLLCON = 0x0001; - pllfeed(); - - /* Set clock divider to 4 (value+1) */ - CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz - -#if USE_USB - USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ -#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; @@ -124,3 +92,4 @@ void bl_init_clks(void) init_mam(); } +/*---------------------------------------------------------------------------*/ diff --git a/msba2/board_init.c b/msba2/board_init.c index 729854e433..a600de19d1 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -1,3 +1,30 @@ +/* + * main.c - Main function of the SRF02 ultrasonic sensor project. + * Copyright (C) 2013 Zakaria Kasmi + * + * The source code is licensed under the LGPLv2 license, + * See the file LICENSE for more details. + */ + +/** + * @ingroup msba2 + * @{ + */ + +/** + * @file + * @brief MSB-A2 board initialization + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Heiko Will + * @author Kaspar Schleiser + * @author Michael Baar + * @author Zakaria Kasmi + * + * @note $Id$ + */ + + #include #include @@ -41,3 +68,41 @@ void bl_init_ports(void) bl_blink(); } +static inline void +pllfeed(void) +{ + PLLFEED = 0xAA; + PLLFEED = 0x55; +} + +void init_clks1(void) +{ + // Disconnect PLL + PLLCON &= ~0x0002; + pllfeed(); + + // Disable PLL + PLLCON &= ~0x0001; + pllfeed(); + + SCS |= 0x20; // Enable main OSC + while( !(SCS & 0x40) ); // Wait until main OSC is usable + + /* select main OSC, 16MHz, as the PLL clock source */ + CLKSRCSEL = 0x0001; + + // Setting Multiplier and Divider values + PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz + pllfeed(); + + // Enabling the PLL */ + PLLCON = 0x0001; + pllfeed(); + + /* Set clock divider to 4 (value+1) */ + CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz + +#if USE_USB + USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ +#endif +} \ No newline at end of file diff --git a/msba2/include/board.h b/msba2/include/board.h index 398255ab4d..fb64f0095e 100644 --- a/msba2/include/board.h +++ b/msba2/include/board.h @@ -15,4 +15,6 @@ #define LED_RED_ON (FIO3CLR = LED_RED_PIN) #define LED_RED_TOGGLE (FIO3PIN ^= LED_RED_PIN) +void init_clks1(void); + #endif /* __BOARD_H */ From 24a35b573a3e677f11d320ad97a498083d29d356 Mon Sep 17 00:00:00 2001 From: Zakaria Kasmi Date: Wed, 7 Aug 2013 12:32:01 +0200 Subject: [PATCH 170/188] updated Makefiles for MSB-A2 and AVSEXTREM * updated Makefilde dep, add the gpioint dependency to use cc110x on MSBA2 board * updated CFLAGS Variable --- Makefile | 4 ++-- avsextrem/Makefile | 4 +++- avsextrem/drivers/Makefile | 24 ++++++++++++++++++++++++ msba2-common/Makefile | 7 ++++--- 4 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 avsextrem/drivers/Makefile diff --git a/Makefile b/Makefile index e0f39c5c4d..7a3c9d345b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - $(MAKE) -C $(BOARD) + "$(MAKE)" -C $(BOARD) clean: - $(MAKE) -C $(BOARD) clean + "$(MAKE)" -C $(BOARD) clean diff --git a/avsextrem/Makefile b/avsextrem/Makefile index 3818708b88..0340a2a81b 100644 --- a/avsextrem/Makefile +++ b/avsextrem/Makefile @@ -12,6 +12,7 @@ INCLUDES += -I$(RIOTBASE)/drivers/cc110x all: $(BINDIR)$(ARCH) "$(MAKE)" -C ../msba2-common + "$(MAKE)" -C drivers $(BINDIR)$(ARCH): $(OBJ) $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) @@ -29,10 +30,11 @@ $(BINDIR)%.o: %.c # remove compilation products clean: "$(MAKE)" -C ../msba2-common clean + "$(MAKE)" -C drivers clean rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) @if [ -d $(BINDIR) ] ; \ then rmdir $(BINDIR) ; \ fi - + diff --git a/avsextrem/drivers/Makefile b/avsextrem/drivers/Makefile new file mode 100644 index 0000000000..e3bb5c62ff --- /dev/null +++ b/avsextrem/drivers/Makefile @@ -0,0 +1,24 @@ +SRC = $(wildcard *.c) +BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o) +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ + +$(BINDIR)avsextrem_base.a: $(OBJ) + $(AR) rcs $(BINDIR)${ARCH} $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)" | cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products + +clean: + rm -f $(BINDIR)$(MODULE).a $(OBJ) $(DEP) $(ASMOBJ) + diff --git a/msba2-common/Makefile b/msba2-common/Makefile index 1ac90178e1..6e64f29bb8 100644 --- a/msba2-common/Makefile +++ b/msba2-common/Makefile @@ -1,4 +1,4 @@ -SRC = $(wildcard *.c) +SRC = $(wildcard *.c) BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines DEP = $(SRC:%.c=$(BINDIR)%.d) @@ -7,11 +7,12 @@ INCLUDES += -I$(RIOTBOARD)/msba2-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include/ INCLUDES += -I$(RIOTBASE)/cpu/lpc2387/include/ INCLUDES += -I$(RIOTBASE)/drivers/include/ +INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include .PHONY: $(BINDIR)msba2_common_base.a all: $(BINDIR)msba2_common_base.a - $(MAKE) -C drivers + "$(MAKE)" -C drivers $(BINDIR)msba2_common_base.a: $(OBJ) $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) @@ -27,6 +28,6 @@ $(BINDIR)%.o: %.c # remove compilation products clean: - ${MAKE} -C drivers clean + "$(MAKE)" -C drivers clean rm -f $(OBJ) $(DEP) From 9f962254003dcbf3d60e4d9d101cbcb34565c06e Mon Sep 17 00:00:00 2001 From: Zakaria Kasmi Date: Mon, 19 Aug 2013 16:17:58 +0200 Subject: [PATCH 171/188] drivers for the AVSEXTREM board. --- avsextrem/avsextrem-cc1100.c | 250 ----- avsextrem/avsextrem-smb380.c | 1212 ----------------------- avsextrem/avsextrem-ssp0.c | 344 ------- avsextrem/board_init.c | 321 +++--- avsextrem/drivers/Makefile | 2 +- avsextrem/drivers/avsextrem-cc1100.c | 260 +++++ avsextrem/drivers/avsextrem-smb380.c | 1347 ++++++++++++++++++++++++++ avsextrem/drivers/avsextrem-ssp0.c | 416 ++++++++ avsextrem/include/board.h | 29 +- avsextrem/include/configure.h | 51 +- avsextrem/include/smb380-board.h | 45 +- avsextrem/include/ssp0-board.h | 21 +- avsextrem/include/type.h | 31 - 13 files changed, 2251 insertions(+), 2078 deletions(-) delete mode 100644 avsextrem/avsextrem-cc1100.c delete mode 100644 avsextrem/avsextrem-smb380.c delete mode 100644 avsextrem/avsextrem-ssp0.c create mode 100644 avsextrem/drivers/avsextrem-cc1100.c create mode 100644 avsextrem/drivers/avsextrem-smb380.c create mode 100644 avsextrem/drivers/avsextrem-ssp0.c delete mode 100644 avsextrem/include/type.h diff --git a/avsextrem/avsextrem-cc1100.c b/avsextrem/avsextrem-cc1100.c deleted file mode 100644 index 3b8487bcb2..0000000000 --- a/avsextrem/avsextrem-cc1100.c +++ /dev/null @@ -1,250 +0,0 @@ -/****************************************************************************** -Copyright 2008, Freie Universitaet Berlin (FUB). All rights reserved. - -These sources were developed at the Freie Universitaet Berlin, Computer Systems -and Telematics group (http://cst.mi.fu-berlin.de). -------------------------------------------------------------------------------- -This file is part of FeuerWare. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -FeuerWare is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see http://www.gnu.org/licenses/ . --------------------------------------------------------------------------------- -For further information and questions please use the web site - http://scatterweb.mi.fu-berlin.de -and the mailinglist (subscription via web site) - scatterweb@lists.spline.inf.fu-berlin.de -*******************************************************************************/ - -/** - * @file - * @ingroup LPC2387 - * @brief CC1100 LPC2387 dependend functions - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author Heiko Will - * @author Thomas Hillebrandt - * @version $Revision: 1781 $ - * - * @note $Id: avsextrem-cc1100.c 1781 2010-01-26 13:39:36Z hillebra $ - */ - -#include -#include -// cpu -#include "cpu.h" -// sys -#include "cc1100.h" -#include "arch_cc1100.h" -#include "cc1100_spi.h" -#include "gpioint.h" - -#define CC1100_GDO0 (FIO2PIN & BIT6) // read serial I/O (GDO0) -#define CC1100_GDO1 (FIO0PIN & BIT8) // read serial I/O (GDO1) -#define CC1100_GDO2 (FIO0PIN & BIT28) // read serial I/O (GDO2) - -#define SPI_TX_EMPTY (SSP1SR & SSPSR_TFE) -#define SPI_BUSY (SSP1SR & SSPSR_BSY) -#define SPI_RX_AVAIL (SSP1SR & SSPSR_RNE) - -#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 - -//#define DEBUG -#ifdef DEBUG - -#include "stdio.h" - -static unsigned long time_value; - -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; -} -#endif - -int cc1100_get_gdo0(void) { - return CC1100_GDO0; -} - -int cc1100_get_gdo1(void) { - return CC1100_GDO1; -} - -int cc1100_get_gdo2(void) { - return CC1100_GDO2; -} - -void cc1100_spi_init(void) -{ - // configure chip-select - FIO0DIR |= BIT6; - FIO0SET = BIT6; - - // Power - PCONP |= PCSSP1; // Enable power for SSP1 (default is on) - - // PIN Setup - PINSEL0 |= BIT15; // Set CLK function to SSP1 - PINSEL0 &= ~BIT14; - PINSEL0 |= BIT17 ; // Set MISO function to SSP1 - PINSEL0 &= ~BIT16; - PINSEL0 |= BIT19; // Set MOSI function to SSP1 - PINSEL0 &= ~BIT18; - // Interface Setup - SSP1CR0 = 7; - - // Clock Setup - uint32_t pclksel; - uint32_t cpsr; - lpc2387_pclk_scale(F_CPU/1000, 6000, &pclksel, &cpsr); - PCLKSEL0 &= ~(BIT21|BIT20); // CCLK to PCLK divider - PCLKSEL0 |= pclksel << 20; - SSP1CPSR = cpsr; - - // Enable - SSP1CR1 |= BIT1; // SSP-Enable - int dummy; - // Clear RxFIFO: - while( SPI_RX_AVAIL ) { // while RNE (Receive FIFO Not Empty)... - dummy = SSP1DR; // read data - } -} - -uint8_t -cc1100_txrx(uint8_t c) { - uint8_t result; - SSP1DR = c; -#ifdef DEBUG - set_time(); -#endif - while (!SPI_TX_EMPTY) { -#ifdef DEBUG - test_time(0); -#endif - } -#ifdef DEBUG - set_time(); -#endif - while (SPI_BUSY) { -#ifdef DEBUG - test_time(1); -#endif - } -#ifdef DEBUG - set_time(); -#endif - while (!SPI_RX_AVAIL) { -#ifdef DEBUG - test_time(2); -#endif - } - result = (uint8_t)SSP1DR; - return result; -} - -void cc1100_spi_cs(void) -{ - FIO0CLR = BIT6; -} - -void -cc1100_spi_select(void) -{ - volatile int retry_count = 0; - volatile int abort_count; - // Switch to GDO mode input - PINSEL0 &= ~(BIT17 + BIT16);// Set MISO function to GPIO - FIO0DIR &= ~BIT8; - cs_low: - // CS to low - abort_count = 0; - FIO0CLR = BIT6; - // 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; - } - FIO0SET = BIT6; // CS to high - goto cs_low; // try again - } - goto loop; - } - final: - // Switch to SPI mode - PINSEL0 |= BIT17; // Set MISO function to SSP1 - PINSEL0 &= ~BIT16; -} - -void -cc1100_spi_unselect(void) -{ - FIO0SET = BIT6; -} - -void cc1100_gdo2_disable(void) { - gpioint_set(0, BIT28, GPIOINT_DISABLE, NULL); -} - -void cc1100_gdo2_enable(void) { - gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc1100_gdo2_irq); -} - -void cc1100_before_send(void) -{ - // Disable GDO2 interrupt before sending packet - cc1100_gdo2_disable(); -} - -void cc1100_after_send(void) -{ - // Enable GDO2 interrupt after sending packet - cc1100_gdo2_enable(); -} - -void cc1100_gdo0_enable(void) { - gpioint_set(2, BIT6, GPIOINT_RISING_EDGE, &cc1100_gdo0_irq); -} - -void cc1100_gdo0_disable(void) { - gpioint_set(2, BIT6, GPIOINT_DISABLE, NULL); -} - - - - -void cc1100_init_interrupts(void) -{ - // Enable external interrupt on low edge (for GDO2) - FIO0DIR &= ~BIT28; - cc1100_gdo2_enable(); - // Enable external interrupt on low edge (for GDO0) - FIO2DIR &= ~BIT6; -} - - diff --git a/avsextrem/avsextrem-smb380.c b/avsextrem/avsextrem-smb380.c deleted file mode 100644 index b2dacc7d83..0000000000 --- a/avsextrem/avsextrem-smb380.c +++ /dev/null @@ -1,1212 +0,0 @@ -/* - * msba2acc-smb380.c - implementation of the Driver for the SMB380 acceleration sensor. - * Copyright (C) 2013 Freie Universität Berlin - * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. - */ - -/** - * @file - * @internal - * @brief SMB380 acceleration sensor drivers for the LPC2387 - * - * @author Freie Universität Berlin, Computer Systems & Telematics - * @author Marco Ziegert - * @author Zakaria Kasmi - * @version $Revision: 3854 $ - * - * @note $Id: msba2acc-smb380.c 3854 2010-01-18 15:27:01Z zkasmi $ - */ - - -#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ -#include "cpu.h" -#include "lpm.h" -//#include "PatrecInit.h" -#include "VIC.h" -#include "kernel.h" -#include "ssp0-board.h" -#include "smb380-board.h" -#include "hwtimer.h" -#include -#include -// for fk_thread: -#include "sched.h" -#include "msg.h" -#include "irq.h" - -//#include "hal-board.h" -#include "gpioint.h" -#include "stdlib.h" -#include "math.h" -#include "lpc2387.h" - -/* program example - * - * - * - * -SMB380_init(); //Initializes SPI and the SMB380 accelerator sensor -SMB380_setRange(SMB380_RANGE_8G); -//SMB380_setBandWidth(SMB380_BAND_WIDTH_100HZ); -SMB380_enableNewDataInt(); - -while( readRingBuff(accInt) ) { - printf("[%4i|%4i|%4i|%4i]\r\n", accInt[0], accInt[1], accInt[2], accInt[3]); - ktimer_wait(KTIMER_TICKS(1000000)); - //actualizeRingReadPointer(); //update read-pointer position to a current measurement (drop unread ones) -} -*/ - -uint8_t simple_pid; -int16_t simple_buffer[4]; - -volatile int16_t* ringBuff_X = NULL; -volatile int16_t* ringBuff_Y = NULL; -volatile int16_t* ringBuff_Z = NULL; -volatile int16_t* ringBuff_T = NULL; -uint16_t readPointerPos[SMB380_RING_BUFF_MAX_THREADS]; -u_char PointerList[SMB380_RING_BUFF_MAX_THREADS]; -static msg_t wakeupmessage; - -uint8_t (*smb380function)(int16_t*); //pointer to a user-defined function which is called during a writepointer action - -uint16_t sampleRateSMB380; - -bool dynRange = false; //condition if range-check should be done -uint8_t counter_Decreasing = 0; - -volatile uint16_t interruptTicksSMB380; - -typedef struct{ - u_int writePointerPos; //Writepointer position - uint8_t countRange; //check value for updated range settings (only needed for multiplication in Float-mode - uint8_t range; //current range -} settingsSMB380; - -settingsSMB380 settings; - -/* measuring temperature dependent internal sample rate of SMB380 */ -static volatile uint32_t tickStart = 0; -static volatile uint32_t tickLastSample = 0; -static volatile uint32_t tickCurrentSamples = 0; - -uint8_t initRingReadPointerforCurrentThread(void); -uint8_t getRingReadPointerforCurrentThread(void); -void wakeUpRegisteredProcesses(void); -uint8_t smb380emptyfunction(int16_t*); -static void SMB380_extIntHandler(void); - -extern unsigned long ktimer_now(void); - -float SMB380_getSampleRatio(void) -{ - return ((1.0 / ((float)(tickLastSample - tickStart) / tickCurrentSamples)) * 100000) /*/ (float)(SMB380_SAMPLE_RATE_MAX / sampleRateSMB380)*/; -} - -uint8_t smb380emptyfunction(int16_t* value) -{ - return 1; -} - -uint8_t SMB380_HystereseFunctionSample(int16_t* value) -{ - static int16_t x=0, y=0, z=0; - static uint8_t counter = 0; - int16_t delta = abs(value[0]-x) + abs(value[1]-y) + abs(value[2]-z); - if(delta <40) //TODO: delta and counter are constant values, change it! - counter++; - else counter = 0; - - x= value[0]; y= value[1]; z= value[2]; - - if(smb380_mode == SMB380_THRESHOLD){ - SMB380_disableAnyMotionLimit(); - SMB380_enableNewDataInt(); - smb380_mode = SMB380_CONTINOUS; - printf("Threshold: x=%i, y=%i, z=%i\n\r",value[0], value[1], value[2]); - } - - if((counter== 100) && (smb380_mode == SMB380_POLL)){ - //MZ SMB380_disableNewDataInt(); - //SMB380_setAnyMotionLimit(100,0); - SMB380_enableAnyMotionLimit(); - smb380_mode = SMB380_THRESHOLD; - counter = 0; //n�tig? - } - else if(counter== 100) - { - SMB380_disableNewDataInt(); - //SMB380_setAnyMotionLimit(100,0); - SMB380_enableAnyMotionLimit(); - smb380_mode = SMB380_FALSEALERT; - counter = 0; //n�tig? - return 0; - } - - - return 1; -} - -static void SMB380_simple_interrupthandler(void) -{ - lpm_awake(); - - SMB380_getAcceleration(SMB380_X_AXIS, NULL, &simple_buffer[0]); - SMB380_getAcceleration(SMB380_Y_AXIS, NULL, &simple_buffer[1]); - SMB380_getAcceleration(SMB380_Z_AXIS, NULL, &simple_buffer[2]); - simple_buffer[3] = SMB380_getTemperature(); - - if (interruptTicksSMB380 >= sampleRateSMB380 - 1) { - interruptTicksSMB380 = 0; - wakeupmessage.type = MSG_TYPE_SMB380_WAKEUP; - msg_send(&wakeupmessage, simple_pid, 0); - } else { - interruptTicksSMB380++; - } - return; -} - -// enables simple Interrupt driven Mode -uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t range) -{ - SSP0Init(); - interruptTicksSMB380 = 0; - simple_pid = active_thread->pid; - gpioint_set(0, BIT1, GPIOINT_RISING_EDGE, &SMB380_simple_interrupthandler); - SMB380_softReset(); - hwtimer_wait(HWTIMER_TICKS(100000)); - SMB380_disableUpperLimit(); - SMB380_disableLowerLimit(); - SMB380_setSampleRate(samplerate); - SMB380_setBandWidth(bandwidth); - SMB380_setRange(range); - - return 0; -} - -uint8_t SMB380_init(uint8_t (*func)(int16_t*)) -{ - SSP0Init(); - -#if SMB380_EXTINT_MODE - if(gpioint_set(0, BIT1, GPIOINT_RISING_EDGE, &SMB380_extIntHandler)); -#endif - - interruptTicksSMB380 = 0; - - if(func != NULL) - smb380function = func; - else - smb380function = smb380emptyfunction; - - //smb380function = SMB380_HystereseFunctionSample; //Platzhalter - - SMB380_softReset(); - hwtimer_wait(HWTIMER_TICKS(100000)); - SMB380_disableUpperLimit(); - SMB380_disableLowerLimit(); - - smb380_mode = SMB380_POLL; - SMB380_setSampleRate(SMB380_SAMPLE_RATE_MAX); //set output to 3000 Hz - - settings.writePointerPos = 0; - settings.range = 0; - settings.countRange = 0; - for(int i=0; i 0 && rate <= SMB380_SAMPLE_RATE_MAX ) { - sampleRateSMB380 = SMB380_SAMPLE_RATE_MAX / rate; - } else { - sampleRateSMB380 = 1; - } -} - -uint16_t SMB380_getSampleRate(void){ - return SMB380_SAMPLE_RATE_MAX / sampleRateSMB380; -} - -uint8_t SMB380_Prepare(void) -{ - return SSP0Prepare(SMB380_ACC,16,1,1,8000); -} - -uint8_t SMB380_Unprepare(void) -{ - return SSP0Unprepare(SMB380_ACC); -} - -/* return the pointerNo related with the current thread */ -uint8_t getRingReadPointerforCurrentThread(void) -{ - uint8_t pointerNo = 0; - while((PointerList[pointerNo]!=active_thread->pid)&&(pointerNo0)&&(pointerNopid; - readPointerPos[pointerNo] = settings.writePointerPos; - return 1; - } -} - -void freeRingReadPointer(void) -{//Should be Threadsafe - uint8_t pointerNo = getRingReadPointerforCurrentThread(); - if(pointerNo!=SMB380_RING_BUFF_MAX_THREADS){ - PointerList[pointerNo] = 0; - } -} - -void actualizeRingReadPointer(void) -{ - uint8_t pointerNo = getRingReadPointerforCurrentThread(); - if(pointerNo!=SMB380_RING_BUFF_MAX_THREADS){ - readPointerPos[pointerNo] = settings.writePointerPos; - } -} - -//TODO more read-pointer -uint8_t readRingBuff(int16_t* value){ - -// if( inISR() ) { -// if( readPointerPos[pointerNo] == settings.writePointerPos ) -// return 0; -// } else { -// while( readPointerPos[pointerNo] != settings.writePointerPos ) { -// uint8_t x = 254; -//// while( x ) -//// x--; -// } -// } - - // zugriff auf pid -// if(getRead fk_thread->pid kenn ich schon) -// { -// pointerno[pid]; -// } -// else -// { -// initRingReadPointerforCurrentThread(); -// } - uint8_t pointerNo = getRingReadPointerforCurrentThread(); - // If thread is not known to read on the ringbuffer, try adding him to the list of known threads, otherwise exit with error - if(pointerNo==SMB380_RING_BUFF_MAX_THREADS) { - if(!initRingReadPointerforCurrentThread()) { - //printf("%sNo Readpointer left, maximum of %u is reached!\n\r", SMB380_DEBUG_MESSAGE, SMB380_RING_BUFF_MAX_THREADS); - return 0; - } - else{ - pointerNo = getRingReadPointerforCurrentThread(); - } - } - - if(readPointerPos[pointerNo] == settings.writePointerPos) { - value[0] = 0; value[1] = 0; value[2] = 0; value[3] = 0; - return 0; - } - value[0] = ringBuff_X[readPointerPos[pointerNo]]; - value[1] = ringBuff_Y[readPointerPos[pointerNo]]; - value[2] = ringBuff_Z[readPointerPos[pointerNo]]; - value[3] = ringBuff_T[readPointerPos[pointerNo]]; - readPointerPos[pointerNo]+=1; - - if(readPointerPos[pointerNo]==SMB380_RING_BUFF_SIZE){ - readPointerPos[pointerNo] = 0; - } - return 1; -} - -//TODO more read-pointer -uint8_t writeRingBuff(int16_t* value){ - if(smb380_mode == SMB380_FALSEALERT) { - smb380_mode = SMB380_THRESHOLD; - return 0; - } - if( (interruptTicksSMB380 >= sampleRateSMB380 - 1) || (smb380_mode == SMB380_THRESHOLD) ) { - interruptTicksSMB380 = 0; - - /* measuring temperature dependent internal sample rate of SMB380 */ - if(smb380_mode == SMB380_CONTINOUS){ - tickLastSample = ktimer_now(); - tickCurrentSamples++; - } - - ringBuff_X[settings.writePointerPos] = value[0]; - ringBuff_Y[settings.writePointerPos] = value[1]; - ringBuff_Z[settings.writePointerPos] = value[2]; - ringBuff_T[settings.writePointerPos] = value[3]; - - /* check for increasing range if dynRange is true */ - if(dynRange) - smb380function = checkRange; - else - smb380function = smb380emptyfunction; - - smb380function(value); - - //printf("Werte: x=%i, y=%i, z=%i\n\r",value[0], value[1], value[2]); - //vgpio_toggle(&gpio_led_green); - - settings.writePointerPos += 1; - - if( settings.writePointerPos == SMB380_RING_BUFF_SIZE ) { - settings.writePointerPos = 0; - } - wakeUpRegisteredProcesses(); - return 1; - } - else { - interruptTicksSMB380++; - return 0; - } -} - -void SMB380_activateDynRangeSet(uint8_t activate) -{ - switch(activate){ - case 0: dynRange=false ; break; - case 1: dynRange=true ; break; - } -} - -/* - * checking for in-/decreasing range - */ -uint8_t checkRange(int16_t* value){ - bool increased = false; - - // printf("CurrentValues: %i %i %i \r\n", xyzTMP[0], xyzTMP[1], xyzTMP[2]); - - // determination of max and min value - int16_t maxValue = value[0]; // max(xValue, max(yValue, zValue)); - int16_t minValue = value[0]; // min(xValue, min(yValue, zValue)); - - for (int i=1; i<3; i++){ - if (value[i]>maxValue) - maxValue=value[i]; - if (value[i]1800)||(minValue<-1800)){ - SMB380_setRange(SMB380_RANGE_4G); - increased = true; - printf("=== Set range from 2 g to 4 g ===\r\n"); - } - break; - case 4: - if ((maxValue>3800)||(minValue<-3800)){ - SMB380_setRange(SMB380_RANGE_8G); - increased = true; - printf("=== Set range from 4 g to 8 g ===\r\n"); - } - break; - case 8: break; - } - - /* check for decreasing range */ - if (increased){ - counter_Decreasing = 0; - }else{ - //decrease range after 10 consecutive relevant values - switch(isRange){ - case 2: break; - case 4: - if ((maxValue < 2000)&&(minValue > -2000)){ - if (counter_Decreasing >= 9){ - SMB380_setRange(SMB380_RANGE_2G); - printf("=== Set range from 4 g to 2 g ===\r\n"); - counter_Decreasing = 0; - }else{ - counter_Decreasing++; - } - }else{ - counter_Decreasing = 0; - } - break; - case 8: - if ((maxValue < 4000)&&(minValue > -4000)){ - if (counter_Decreasing >= 9){ - SMB380_setRange(SMB380_RANGE_4G); - printf("=== Set range from 8 g to 4 g ===\r\n"); - counter_Decreasing = 0; - }else{ - counter_Decreasing++; - } - }else{ - counter_Decreasing = 0; - } - break; - } - } - return 0; -} - - -void wakeUpRegisteredProcesses(void) -{ - uint8_t pointerNo = 0; - //wake up waiting processes - wakeupmessage.type = MSG_TYPE_SMB380_WAKEUP; - while((PointerList[pointerNo]>0)&&(pointerNo>1) + SMB380_TEMP_OFFSET; - SMB380_Unprepare(); - restoreIRQ(cpsr); - - return t; -} - -void SMB380_getAcceleration(unsigned char axis, int16_t *pAbs, int16_t *pMg) -{ - unsigned short ur; - - if(!settings.countRange && (pMg != NULL)){ - settings.countRange = 1; - settings.range = SMB380_getRange(); - } - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - switch( axis ) { - case SMB380_X_AXIS: - SMB380_ssp_write(SMB380_ACC_X_MSB, 0, SMB380_READ_REGISTER); - SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA, 0, SMB380_READ_REGISTER); - break; - case SMB380_Y_AXIS: - SMB380_ssp_write(SMB380_ACC_Y_MSB, 0, SMB380_READ_REGISTER); - SMB380_ssp_write(SMB380_ACC_Y_LSB_NEWDATA, 0, SMB380_READ_REGISTER); - break; - default: - SMB380_ssp_write(SMB380_ACC_Z_MSB, 0, SMB380_READ_REGISTER); - SMB380_ssp_write(SMB380_ACC_Z_LSB_NEWDATA, 0, SMB380_READ_REGISTER); - } - - ur = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; - ur |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; - SMB380_Unprepare(); - restoreIRQ(cpsr); - - if( pAbs != NULL ) { - if( ur & BIT9 ) { //ur<0 - *pAbs = ur | 0xFC00; - } else { - *pAbs = ur & 0x03FF; - } - } - - if( pMg != NULL ) { - if( ur & BIT9 ) { //ur<0 - *pMg = -(((settings.range * (512 - (ur & 0x1FF)))* 2000) / 1024); - } else { - *pMg = ((settings.range * ur) * 2000) / 1024; - } - } - -} - -unsigned char SMB380_getChipID(void) -{ - unsigned char ur = 0; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CHIP_ID, 0, 0); - ur = (unsigned char)(SMB380_ssp_read() & SMB380_CHIP_ID_MASK); - restoreIRQ(cpsr); - return ur; -} - -void SMB380_setWakeUpPause(unsigned char duration) -{ - unsigned char utemp; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); - utemp = SMB380_ssp_read(); - utemp &= ~SMB380_CONTROL4_WAKEUP_PAUSE_MASK; - utemp |= (duration & (0x3) << 1);//+1; - SMB380_ssp_write(SMB380_CONTROL4, utemp, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -unsigned char SMB380_getWakeUpPause(void) -{ - unsigned char up; - - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); - up = (unsigned char)SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); - up &= SMB380_CONTROL4_WAKEUP_PAUSE_MASK; - up = up >> 1; - - return up; -} - -void SMB380_setBandWidth(unsigned char bandWidth) -{ - unsigned char utemp; - - if( (bandWidth == SMB380_BAND_WIDTH_100HZ) | - (bandWidth == SMB380_BAND_WIDTH_1500HZ) | - (bandWidth == SMB380_BAND_WIDTH_190HZ) | - (bandWidth == SMB380_BAND_WIDTH_25HZ) | - (bandWidth == SMB380_BAND_WIDTH_375HZ) | - (bandWidth == SMB380_BAND_WIDTH_50HZ) | - (bandWidth == SMB380_BAND_WIDTH_750HZ) ) { - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); - utemp = SMB380_ssp_read(); - utemp &= ~SMB380_CONTROL3_BANDWITH_MASK; - utemp |= (bandWidth & 0x7); - SMB380_ssp_write(SMB380_CONTROL3, utemp, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); - } -} - -void SMB380_setRange(unsigned char range) -{ - unsigned char utemp = 0; - - if( range != 0x3 ) { - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); - utemp = (unsigned char)SMB380_ssp_read(); - utemp &= ~SMB380_CONTROL3_RANGE_MASK; - utemp |= (range & 0x3) << 3; - SMB380_ssp_write(SMB380_CONTROL3, utemp, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); - settings.countRange = 0; - } - -} - -unsigned char SMB380_getRange(void) -{ - unsigned char ur; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); - ur = (SMB380_ssp_read() & SMB380_CONTROL3_RANGE_MASK) >> 3; - SMB380_Unprepare(); - restoreIRQ(cpsr); - - switch(ur){ - case SMB380_RANGE_2G: return 2; - case SMB380_RANGE_4G: return 4; - case SMB380_RANGE_8G: return 8; - default: return 4; - } -} - -unsigned char SMB380_getBandWidth(void) -{ - unsigned char uBand; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); - uBand = SMB380_ssp_read() & SMB380_CONTROL3_BANDWITH_MASK; - SMB380_Unprepare(); - restoreIRQ(cpsr); - return uBand; -} - -int16_t SMB380_getBandWidthAbs(void) -{ - unsigned char uBand; - uBand = SMB380_getBandWidth(); - - switch(uBand){ - case SMB380_BAND_WIDTH_25HZ: return 25; - case SMB380_BAND_WIDTH_50HZ: return 50; - case SMB380_BAND_WIDTH_100HZ: return 100; - case SMB380_BAND_WIDTH_190HZ: return 190; - case SMB380_BAND_WIDTH_375HZ: return 375; - case SMB380_BAND_WIDTH_750HZ: return 750; - case SMB380_BAND_WIDTH_1500HZ: return 1500; - default: return uBand; - } -} - -void SMB380_softReset(void) -{ - unsigned char ur; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL1, SMB380_CONTROL1_SOFT_RESET_MASK, SMB380_WRITE_REGISTER); - ur = ((unsigned char)SMB380_ssp_read()) & SMB380_CONTROL1_SOFT_RESET_MASK; - SMB380_Unprepare(); - restoreIRQ(cpsr); - ur = ur >> 1; -} - -void SMB380_setCustomerReg(unsigned char data) -{ - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CUST1, data, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -unsigned char SMB380_getCustomerReg(void) -{ - unsigned uReg = 0; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CUST1, 0, SMB380_READ_REGISTER); - uReg = (unsigned char)SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); - return uReg; -} - -/* Selftest - * - * */ -void SMB380_Selftest_1(void) -{ - unsigned char uReg = 0; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_LG_THRES, 6, SMB380_WRITE_REGISTER); - //SSP0Init(); - SMB380_ssp_read(); - SMB380_ssp_write(SMB380_LG_DUR, 0, SMB380_WRITE_REGISTER); - //SSP0Init(); - SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); - - uReg = (unsigned char)SMB380_ssp_read(); - uReg &= ~SMB380_CONTROL1_SELF_TEST_1_MASK; - uReg |= 0x01 << 3; - SMB380_ssp_write(SMB380_CONTROL1, uReg, SMB380_WRITE_REGISTER); -// SSP0Init(); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_ShowMemory(void) -{ - uint16_t uReg = 0; - uint8_t bitMask[16]; - printf("SMB380 Speicher\n\r"); - unsigned long cpsr; - for(unsigned char regAd=0x16;regAd>0;regAd--){ - cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(regAd-1, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); - printf("Register: = %X: 0x%X = ", regAd-1, uReg); - for(int pos=0; pos<16; pos++) //uReg != 0) - { - bitMask[15-pos] = uReg %2; - - uReg = uReg /2; - } - for(int pos=8; pos<16; pos++) //uReg != 0) - { - printf ("%d",bitMask[pos]); - if((pos%4) == 0) printf(" "); - } - printf("\n"); - } -} - -void SMB380_setUpperLimit(void){ - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_HG_THRES, 128, SMB380_WRITE_REGISTER); //1g - SMB380_ssp_read(); - SMB380_ssp_write(SMB380_HG_DUR, 0, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_enableUpperLimit(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_HG_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_disableUpperLimit(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_HG_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_enableLowerLimit(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_LG_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_disableLowerLimit(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_LG_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -/* @param gvaluefloat - value is in mg - * @param gvalueint - value in range of 0 to 512 - * Choose one of them, set the other to zero - */ -uint8_t SMB380_setAnyMotionLimit(uint16_t mg, uint16_t gvalueint){ - - uint8_t threshold = 0; - if(mg !=0){ - threshold = mg / (15.6 * (SMB380_getRange()/2)); - } - else if(gvalueint != 0){ - threshold = ceil(((gvalueint * 2000)/512.0) / 15.6); //Scaling for different gRanges is not needed - } - else return 0; - - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_ANY_MOTION_THRES, threshold, SMB380_WRITE_REGISTER); //0,3g = 300 / 15,6mg = 19 - SMB380_ssp_read(); - //Set duration at this point - SMB380_ssp_write(SMB380_ANY_MOTION_DUR_HYST, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); -// SMB380_ssp_write(SMB380_ANY_MOTION_DUR_HYST, (uReg & ~SMB380_ANY_MOTION_DUR_MASK) | 0x40, SMB380_WRITE_REGISTER); -// SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); - return 1; -} - -void SMB380_enableAnyMotionLimit(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_ENABLE_ADV_INT_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ANY_MOTION_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_disableAnyMotionLimit(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ANY_MOTION_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_ENABLE_ADV_INT_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_enableNewDataInt(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - //prevent deep sleep, reason: 400�s wake-up time is to long for 3kHz interrupts - SETBIT(lpm_prevent_sleep, LPM_PREVENT_SLEEP_ACCSENSOR); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_NEW_DATA_INT_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - /* measuring temperature dependent internal sample rate of SMB380 */ - tickStart = ktimer_now(); - tickCurrentSamples = 0; - restoreIRQ(cpsr); -} - -void SMB380_disableNewDataInt(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_NEW_DATA_INT_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - //enable deep sleep, reason: 400�s wake-up time was to long for 3kHz interrupts - CLRBIT(lpm_prevent_sleep, LPM_PREVENT_SLEEP_ACCSENSOR); - restoreIRQ(cpsr); -} - -void SMB380_resetInterruptFlags(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_RESET_INT_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_enableEEPROM(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_EE_W_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -void SMB380_disableEEPROM(void){ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); - uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL1, uReg & ~SMB380_CONTROL1_EE_W_MASK, SMB380_WRITE_REGISTER); - SMB380_ssp_read(); - SMB380_Unprepare(); - restoreIRQ(cpsr); -} - -//void SMB380_calibrate(void){ -// unsigned short uMSB, uLSB; -// //TODO 25Hz, 2G -// -// SMB380_ssp_write(SMB380_ACC_X_MSB, 0, SMB380_READ_REGISTER); -// SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA, 0, SMB380_READ_REGISTER); -// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; -// uLSB = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; -// -// SMB380_ssp_write(SMB380_ACC_X_MSB + SMB380_EEPROM_OFFSET, uMSB, SMB380_WRITE_REGISTER); -// SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA + SMB380_EEPROM_OFFSET, uLSB, SMB380_WRITE_REGISTER); -// -// -// SMB380_ssp_write(SMB380_ACC_Y_MSB, 0, SMB380_READ_REGISTER); -// SMB380_ssp_write(SMB380_ACC_Y_LSB_NEWDATA, 0, SMB380_READ_REGISTER); -// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; -// uLSB |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; -// -// SMB380_ssp_write(SMB380_ACC_Z_MSB, 0, SMB380_READ_REGISTER); -// SMB380_ssp_write(SMB380_ACC_Z_LSB_NEWDATA, 0, SMB380_READ_REGISTER); -// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; -// uLSB |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; -// -// -//} - -/* - * Return offsets from offset registers, - * remove xyz afterwards because it is useless - */ -unsigned char SMB380_readOffset(uint16_t *offset) -{ - if( sizeof(offset) < 3 ) - return false; - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); - uReg = ((SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6); - SMB380_ssp_write(SMB380_OFFSET_MSB_X, 0, SMB380_READ_REGISTER); - uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; - - - offset[0] = uReg; - printf("Offset X: %u ", uReg); - - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); - uReg = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; - SMB380_ssp_write(SMB380_OFFSET_MSB_Y, 0, SMB380_READ_REGISTER); - uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; - - offset[1] = uReg; - printf("Offset Y: %u ", uReg); - - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); - uReg = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; - SMB380_ssp_write(SMB380_OFFSET_MSB_Z, 0, SMB380_READ_REGISTER); - uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; - - offset[2] = uReg; - printf("Offset Z: %u \r\n", uReg); - - SMB380_Unprepare(); - restoreIRQ(cpsr); - - return true; -} - -unsigned char SMB380_readOffsetTemp(uint16_t *offset) -{ - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); - uReg = ((SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6); - SMB380_ssp_write(SMB380_OFFSET_MSB_T, 0, SMB380_READ_REGISTER); - uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; - - - offset[0] = uReg; - printf("Offset T: %u ", uReg); - - SMB380_Unprepare(); - restoreIRQ(cpsr); - - return true; -} - -/* EEPROM = 1 if data has to be written in EEPROM and not only in image - * - */ -void SMB380_writeOffset(uint16_t *offset, uint8_t EEPROM) -{ - printf("Writing Offset X: %u Y: %u Z: %u\r\n", offset[0], offset[1], offset[2]); - if( sizeof(offset) >= 3 ) - { - uint16_t eeoffset = 0; - if( EEPROM ) - eeoffset = SMB380_EEPROM_OFFSET; //create offset if saving to EEPROM is needed - - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - - //x-Axis - uReg = (offset[0] & 0x03) << 6; //get both LSB Bits - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); //write them to image or eeprom - uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom - SMB380_ssp_read(); - hwtimer_wait(HWTIMER_TICKS(50000)); - - uReg = (offset[0] & 0x3FC) >> 2; //get MSB Bits - SMB380_ssp_write(SMB380_OFFSET_MSB_X + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom - SMB380_ssp_read(); - hwtimer_wait(HWTIMER_TICKS(50000)); - - //y-Axis - uReg = (offset[1] & 0x03) << 6; //get both LSB Bits - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); //write them to image or eeprom - uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom - SMB380_ssp_read(); - hwtimer_wait(HWTIMER_TICKS(50000)); - - uReg = (offset[1] & 0x3FC) >> 2; //get MSB Bits - SMB380_ssp_write(SMB380_OFFSET_MSB_Y + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom - SMB380_ssp_read(); - hwtimer_wait(HWTIMER_TICKS(50000)); - - //z-Axis - uReg = (offset[2] & 0x03) << 6; //get both LSB Bits - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); //write them to image or eeprom - uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom - SMB380_ssp_read(); - hwtimer_wait(HWTIMER_TICKS(50000)); - - uReg = (offset[2] & 0x3FC) >> 2; //get MSB Bits - SMB380_ssp_write(SMB380_OFFSET_MSB_Z + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom - SMB380_ssp_read(); - hwtimer_wait(HWTIMER_TICKS(50000)); - - SMB380_Unprepare(); - restoreIRQ(cpsr); - - } -} - -void SMB380_writeOffsetTemp(uint16_t *offset, uint8_t EEPROM) -{ - printf("Writing Offset Temp: %u\r\n", offset[0]); - if( sizeof(offset) >= 1 ) - { - uint16_t eeoffset = 0; - if( EEPROM ) - eeoffset = SMB380_EEPROM_OFFSET; //create offset if saving to EEPROM is needed - - unsigned short uReg; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - - //T-Axis - uReg = (offset[0] & 0x03) << 6; //get both LSB Bits - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); //write them to image or eeprom - uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom - SMB380_ssp_read(); - hwtimer_wait(HWTIMER_TICKS(50000)); - - uReg = (offset[0] & 0x3FC) >> 2; //get MSB Bits - SMB380_ssp_write(SMB380_OFFSET_MSB_T + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom - SMB380_ssp_read(); - hwtimer_wait(HWTIMER_TICKS(50000)); - - SMB380_Unprepare(); - restoreIRQ(cpsr); - } -} - -unsigned char SMB380_readGain(uint16_t *gain) -{ - if( sizeof(gain) < 3 ) - return false; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - - //x-gain - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); - gain[0] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); - //y-gain - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); - gain[1] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); - //z-gain - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); - gain[2] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); - - SMB380_Unprepare(); - restoreIRQ(cpsr); - - return true; -} - -unsigned char SMB380_readGainTemp(uint16_t *gain) -{ - if( sizeof(gain) < 1 ) - return false; - unsigned long cpsr = disableIRQ(); - SMB380_Prepare(); - - //T-gain - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); - gain[0] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); - - SMB380_Unprepare(); - restoreIRQ(cpsr); - - return true; -} - - diff --git a/avsextrem/avsextrem-ssp0.c b/avsextrem/avsextrem-ssp0.c deleted file mode 100644 index 3a9be8ed07..0000000000 --- a/avsextrem/avsextrem-ssp0.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - * avsextrem-ssp0.c - implementation of the SPI0 interface for the LPC2387. - * Copyright (C) 2013 Freie Universität Berlin - * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. - */ - -/** - * @file - * @internal - * @brief Implements the SPI0 interface for the LPC2387 - * - * @author Freie Universität Berlin, Computer Systems & Telematics - * @author Marco Ziegert - * @author Zakaria Kasmi - * @version $Revision: 3854 $ - * - * @note $Id: avsextrem-ssp0.c 3854 2010-01-18 15:27:01Z zkasmi $ - */ - -#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ -#include "cpu.h" -#include "VIC.h" -#include "ssp0-board.h" -#include "smb380-board.h" -//#include "mma7455l-board.h" -#include "gpioint.h" -#include "hwtimer.h" -#include -#include "lpm.h" - -//uint16_t sampleRateMMA7455L; -//uint16_t interruptTicksMMA7455L; -// -//static void MMA7455L_extIntHandler(void); - -/***************************************************************************** - ** Function name: SSP0Init - ** - ** Descriptions: SSP0 port initialization routine - ** - ** parameters: None - ** Returned value: true or false, if the interrupt handler - ** can't be installed correctly, return false. - ** - *****************************************************************************/ -uint32_t SSP0Init(void) -{ - - /* enable clock to SSP0 for security reason. By default, it's enabled already */ - PCONP |= PCSSP0; - //TODO CLK, MISO, MOSI standardm��ig als GPIOs konfigurieren -#if USE_CS -// PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; //P1.20 1.21 1.23 1.24 -#else -// PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 SSEL0 nicht - -#endif - -#if SSP1_INTERRUPT_MODE - if ( install_irq( SSP1_INT, (void *)SSP0Handler, HIGHEST_PRIORITY ) == FALSE ) - { - return (FALSE); - } - - /* Set SSPINMS registers to enable interrupts */ - /* enable all error related interrupts */ - SSP1IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM; -#endif - - return (1); -} - -/* datasize (wordsize) in decimal (4-16), cpol&cpha =(0/1) and frequency divided by 1000 (e.g. 8 MHz = 8000) - * - */ -uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol,uint8_t cpha, uint16_t freq) -{ - switch(chip) - { - case BMA180_INTERN: - case SMB380_ACC:{ -#if USE_CS - PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; //P1.20 1.21 1.23 1.24 -#else - - PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 SSEL0 nicht -#endif - break; - } - case BMA180_EXTERN: - case L3G_EXTERN: - case NANOPAN: - case ACAMDMS:{ -#if USE_CS - PINSEL0 |= BIT31; - PINSEL1 |= BIT1 | BIT3 | BIT5; //P0.15 0.16 0.17 0.18 -#else - //Turn on NanoPAN - PINSEL0 |= BIT31; - PINSEL1 |= BIT3 | BIT5; //0.15 0.17 0.18 SSEL0 nicht -#endif - break; - } - case NORDIC:{ - PINSEL0 |= BIT31; - PINSEL1 |= BIT3 | BIT5; //0.15 0.17 0.18 SSEL0 nicht - break; - } - default: { - printf("wrong CHIP selected\n"); - return 0; - } - } - uint32_t SSP0CR0tmp = 0; - - switch(datasize) - { - case 4: SSP0CR0tmp = BIT0 | BIT1; break; - case 5: SSP0CR0tmp = BIT2; break; - case 6: SSP0CR0tmp = BIT0 | BIT2; break; - case 7: SSP0CR0tmp = BIT1 | BIT2; break; - case 8: SSP0CR0tmp = BIT0 | BIT1 | BIT2; break; - case 9: SSP0CR0tmp = BIT3; break; - case 10: SSP0CR0tmp = BIT0 | BIT3; break; - case 11: SSP0CR0tmp = BIT1 | BIT3; break; - case 12: SSP0CR0tmp = BIT0 | BIT1 | BIT3; break; - case 13: SSP0CR0tmp = BIT2 | BIT3; break; - case 14: SSP0CR0tmp = BIT0 | BIT2 | BIT3; break; - case 15: SSP0CR0tmp = BIT1 | BIT2 | BIT3; break; - case 16: SSP0CR0tmp = BIT0 | BIT1 | BIT2 | BIT3; break; - default: return 0; - } - if(cpol) SSP0CR0tmp|= BIT6; - if(cpha) SSP0CR0tmp|= BIT7; - - SSP0CR1 = 0x00; //SSP0 disabled - - /* Setting xx-Bit Datasize, CPOL and CPHA*/ - SSP0CR0 = SSP0CR0tmp; - - // Clock Setup - uint32_t pclksel; - uint32_t cpsr; - lpc2387_pclk_scale(F_CPU / 1000, freq, &pclksel, &cpsr); - PCLKSEL1 &= ~(BIT10 | BIT11); // CCLK to PCLK divider ??? - PCLKSEL1 |= pclksel << 10; - SSP0CPSR = cpsr; - - // Enable - SSP0CR1 |= BIT1; //SSP0 enabled - - uint32_t Dummy; - for( uint32_t i = 0; i < FIFOSIZE; i++ ) { - Dummy = SSP0DR; // clear the RxFIFO - } - return 1; -} - -uint8_t SSP0Unprepare(uint8_t chip) -{ - switch(chip) - { - case BMA180_INTERN: - case SMB380_ACC:{ - //Turn off Acceleration Sensor - PINSEL3 &= ~(BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17); - FIO1DIR |= BIT20 | BIT21 | BIT24; - FIO1DIR &= ~BIT23; //MISO as Input - FIO1SET = BIT20 | BIT24; //CLK + SSEL + MOSI GPIO as Output //TODO depends on CPOL+CPHA Settings - FIO1CLR = BIT21; - break; - } - case BMA180_EXTERN: - case L3G_EXTERN: - case NORDIC: - case NANOPAN: - case ACAMDMS:{ - //Turn off Nanopan (Pins to GPIO) - PINSEL0 &= ~(BIT30 | BIT31); //CLK to GPIO - PINSEL1 &= ~(BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5); - FIO0DIR |= BIT15 | BIT16 | BIT18; //CLK + SSEL + MOSI GPIO as Output - FIO0DIR &= ~BIT17; //MISO as Input - FIO0SET = BIT15 | BIT16; //CLK + SSEL + MOSI GPIO as Output //TODO depends on CPOL+CPHA Settings - FIO0CLR = BIT18; - break; - } - default: { - printf("wrong CHIP selected\n"); - return 0; - } - } - return 1; -} - -unsigned char SMB380_ssp_write(const unsigned char regAddr, const unsigned char data, unsigned char flag) -{ - - uint16_t temp = 0; - if( flag ) { - temp = (unsigned int)(((regAddr & 0xFF7F) << 8) | data); - - } else { - temp = (((unsigned int)(regAddr | 0x80) << 8) | 0xFF); - } - - return SSP0_write(temp, SMB380_ACC); -} - -unsigned char SSP0_write(const uint16_t data, uint8_t device) -{ - unsigned char ret = 1; - - while( (SSP0SR & (SSPSR_TNF | SSPSR_BSY)) != SSPSR_TNF ) - ; - if( !USE_CS ) { - switch( device ) { - case BMA180_INTERN: - case SMB380_ACC: { - FIO1CLR = SSP0_SEL; - break; - } - case BMA180_EXTERN: - case L3G_EXTERN: - case NANOPAN: - { - printf("[%s] line: %d\n", __FUNCTION__,__LINE__); - FIO0CLR = SSP0_SELN; - break; - } - case ACAMDMS: - case NORDIC: - //Chip Select is done in Nordic driver - break; - default: - ret = 0; - goto ret; - } - } - SSP0DR = data; - if( !USE_CS ) { - while( SSP0SR & SSPSR_BSY ) - ; - switch( device ) { - case BMA180_INTERN: - case SMB380_ACC: { - FIO1SET = SSP0_SEL; - break; - } - case BMA180_EXTERN: - case L3G_EXTERN: - case NANOPAN: - { - FIO0SET = SSP0_SELN; - break; - } - case ACAMDMS: - case NORDIC: - //Chip Select is done in Nordic driver - break; - default: - ret = 0; - goto ret; - } - } - -ret: return ret; -} - -unsigned short SSP0_read(uint8_t device) -{ - uint16_t data; - - while( !(SSP0SR & SSPSR_RNE) ) - ; - - if( !USE_CS ) { - switch( device ) { - case BMA180_INTERN: - case SMB380_ACC: { - FIO1CLR = SSP0_SEL; - break; - } - case BMA180_EXTERN: - case L3G_EXTERN: - case NANOPAN: - { - FIO0CLR = SSP0_SELN; - break; - } - case NORDIC: - case ACAMDMS: - //Chip Select is done in Nordic driver - break; - default: - data = 0xFFFF; - goto ret; - } - } - data = SSP0DR; - if( !USE_CS ) { - switch( device ) { - case BMA180_INTERN: - case SMB380_ACC: { - FIO1SET = SSP0_SEL; - break; - } - case BMA180_EXTERN: - case L3G_EXTERN: - case NANOPAN: - { - FIO0SET = SSP0_SELN; - break; - } - case ACAMDMS: - case NORDIC: - //Chip Select is done in Nordic driver - break; - default: - data = 0xFFFF; - goto ret; - } - } - ret: return data; -} - -unsigned short SMB380_ssp_read(void) -{ - return SSP0_read(SMB380_ACC); -} - -unsigned short nrf24l01_ssp_read_write(const uint8_t data) -{ - SSP0_write(data, NORDIC); - return SSP0_read(NORDIC); -} - -unsigned short acam_trx(const uint8_t data) -{ - SSP0_write(data, ACAMDMS); - return SSP0_read(ACAMDMS); -} - diff --git a/avsextrem/board_init.c b/avsextrem/board_init.c index 442e3660da..ce1cc57933 100644 --- a/avsextrem/board_init.c +++ b/avsextrem/board_init.c @@ -1,28 +1,12 @@ -/****************************************************************************** -Copyright 2008-2009, Freie Universitaet Berlin (FUB). All rights reserved. +/* +* board_init.c - initialization of the AVSEXTREM-BOARD. +* Copyright (C) 2013 Heiko Will +* +* This source code is licensed under the LGPLv2 license, +* See the file LICENSE for more details. +* +*/ -These sources were developed at the Freie Universitaet Berlin, Computer Systems -and Telematics group (http://cst.mi.fu-berlin.de). -------------------------------------------------------------------------------- -This file is part of FeuerWare. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -FeuerWare is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see http://www.gnu.org/licenses/ . --------------------------------------------------------------------------------- -For further information and questions please use the web site - http://scatterweb.mi.fu-berlin.de -and the mailinglist (subscription via web site) - scatterweb@lists.spline.inf.fu-berlin.de -*******************************************************************************/ /** * @ingroup avsextrem @@ -31,17 +15,17 @@ and the mailinglist (subscription via web site) /** * @file - * @brief avsextrem board initialization + * @brief avsextrem board initialization * - * @author Freie Universit�t Berlin, Computer Systems & Telematics, FeuerWhere project - * @author Heiko Will - * @author Kaspar Schleise - * @author Michael Baar - * @author Zakaria Kasmi - * @author Marco Ziegert - * @author Stefan Pfeiffer + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Heiko Will + * @author Kaspar Schleise + * @author Michael Baar + * @author Zakaria Kasmi + * @author Marco Ziegert + * @author Stefan Pfeiffer * - * @note $Id: board_init.c 1071 2009-04-30 10:15:56Z hwill $ + * @note $Id: board_init.c 1071 2013-08-14 10:15:56Z hwill $ */ #include "lpc23xx.h" #include "VIC.h" @@ -56,180 +40,183 @@ and the mailinglist (subscription via web site) static inline void pllfeed(void) { - PLLFEED = 0xAA; - PLLFEED = 0x55; + PLLFEED = 0xAA; + PLLFEED = 0x55; } /*---------------------------------------------------------------------------*/ void init_clks1(void) { - // Disconnect PLL - PLLCON &= ~0x0002; - pllfeed(); - while (PLLSTAT & BIT25); // wait until PLL is disconnected before disabling - deadlock otherwise + // Disconnect PLL + PLLCON &= ~0x0002; + pllfeed(); - // Disable PLL - PLLCON &= ~0x0001; - pllfeed(); - while (PLLSTAT & BIT24); // wait until PLL is disabled + while (PLLSTAT & BIT25); // wait until PLL is disconnected before disabling - deadlock otherwise - SCS |= 0x10; // main OSC between 15MHz and 24MHz (more stable in tests) - SCS |= 0x20; // Enable main OSC - while( !(SCS & 0x40) ); // Wait until main OSC is usable + // Disable PLL + PLLCON &= ~0x0001; + pllfeed(); - /* select main OSC, 16MHz, as the PLL clock source */ - CLKSRCSEL = 0x0001; + while (PLLSTAT & BIT24); // wait until PLL is disabled - // Setting Multiplier and Divider values - PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz - pllfeed(); + SCS |= 0x10; // main OSC between 15MHz and 24MHz (more stable in tests) + SCS |= 0x20; // Enable main OSC - // Enabling the PLL */ - PLLCON = 0x0001; - pllfeed(); + while (!(SCS & 0x40)); // Wait until main OSC is usable - /* Set clock divider to 4 (value+1) */ - CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz + /* select main OSC, 16MHz, as the PLL clock source */ + CLKSRCSEL = 0x0001; + + // Setting Multiplier and Divider values + PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz + pllfeed(); + + // Enabling the PLL */ + PLLCON = 0x0001; + pllfeed(); + + /* Set clock divider to 4 (value+1) */ + CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz #if USE_USB - USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ + USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ #endif } /*---------------------------------------------------------------------------*/ void bl_init_ports(void) { - SCS |= BIT0; // Set IO Ports to fast switching mode + SCS |= BIT0; // Set IO Ports to fast switching mode - /* UART0 */ - PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 - PINSEL0 &= ~(BIT5 + BIT7); + /* UART0 */ + PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 + PINSEL0 &= ~(BIT5 + BIT7); - //PTTU: + //PTTU: - /*Turn Board on*/ -// PINMODE0 |= BIT1; -// FIO0DIR |= BIT27; -// FIO0CLR = BIT27; -// 0.27 + /*Turn Board on*/ + // PINMODE0 |= BIT1; + // FIO0DIR |= BIT27; + // FIO0CLR = BIT27; + // 0.27 - /* 5V*/ -// FIO1DIR |= BIT28; // Synch -// FIO1SET = BIT28; // No Powersave -// 1.28 + /* 5V*/ + // FIO1DIR |= BIT28; // Synch + // FIO1SET = BIT28; // No Powersave + // 1.28 -// FIO1DIR |= BIT27; // 5V off -// FIO1CLR = BIT27; -// 1.27 + // FIO1DIR |= BIT27; // 5V off + // FIO1CLR = BIT27; + // 1.27 - /* Disable Resistors on Buttons */ -// PINMODE4 |= BIT9 + BIT11; -// + /* Disable Resistors on Buttons */ + // PINMODE4 |= BIT9 + BIT11; + // - /* Disable Resistors on LED - and Ports to output*/ - PINMODE7 |= BIT19 + BIT21; //3.25 + 3.26 - PINMODE2 |= BIT1; //1.0 - FIO1DIR |= BIT0; - FIO3DIR |= BIT25 + BIT26; - FIO1SET = BIT0; //all off - FIO3SET = BIT25 + BIT26; + /* Disable Resistors on LED - and Ports to output*/ + PINMODE7 |= BIT19 + BIT21; //3.25 + 3.26 + PINMODE2 |= BIT1; //1.0 + FIO1DIR |= BIT0; + FIO3DIR |= BIT25 + BIT26; + FIO1SET = BIT0; //all off + 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; // ** -// 1.22 + 1.25 + 1.26 + // 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; // ** + // 1.22 + 1.25 + 1.26 - // 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 + // 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 + // 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 + 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 + 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 -// 1.1 + 0.1 + 0.10 + 0.11 + // 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 + // 1.1 + 0.1 + 0.10 + 0.11 - // LTC4150 ARM - FIO0DIR |= BIT5; - FIO0CLR = BIT5; + // LTC4150 ARM + FIO0DIR |= BIT5; + FIO0CLR = BIT5; - // LTC4150 System -// FIO0DIR |= BIT24; -// FIO0CLR = BIT24; -// 0.23 + 0.24 + // LTC4150 System + // FIO0DIR |= BIT24; + // FIO0CLR = BIT24; + // 0.23 + 0.24 - // Battery Voltage (AD) - PINMODE1 |= BIT19; //0.25 - PINSEL1 &= ~BIT19; - PINSEL1 |= BIT18; + // Battery Voltage (AD) + PINMODE1 |= BIT19; //0.25 + PINSEL1 &= ~BIT19; + PINSEL1 |= BIT18; - //cc1100 - FIO0DIR |= BIT6 + BIT7 + BIT9; - FIO0SET = BIT6; - FIO0SET = BIT7 + BIT9; + //cc1100 + FIO0DIR |= BIT6 + BIT7 + BIT9; + FIO0SET = BIT6; + FIO0SET = BIT7 + BIT9; - //SMB380 - FIO1DIR |= BIT20 + BIT21 + BIT24; //SCK + CSB + SDI - FIO1SET = BIT21; - FIO1SET = BIT20 + 24; + //SMB380 + FIO1DIR |= BIT20 + BIT21 + BIT24; //SCK + CSB + SDI + FIO1SET = BIT21; + FIO1SET = BIT20 + 24; - //SHT11 - FIO1DIR |= BIT25; //1.25 - PINSEL3 &= ~(BIT12|BIT13 | BIT18|BIT19); + //SHT11 + FIO1DIR |= BIT25; //1.25 + PINSEL3 &= ~(BIT12 | BIT13 | BIT18 | BIT19); - //SD - FIO0DIR &= ~( BIT19 | BIT20 | BIT21 | BIT22) ; //0.19 0.20 0.21 0.22 as input - PINMODE1 |= (BIT7) | (BIT9) | (BIT11) | (BIT13); // no resistors - FIO2DIR &= ~( BIT11 + BIT12 + BIT13 ); //2.11 2.12 2.13 as input - PINMODE4 |= (BIT23) | (BIT25) | (BIT27); // no resistors + //SD + FIO0DIR &= ~(BIT19 | BIT20 | BIT21 | BIT22) ; //0.19 0.20 0.21 0.22 as input + PINMODE1 |= (BIT7) | (BIT9) | (BIT11) | (BIT13); // no resistors + FIO2DIR &= ~(BIT11 + BIT12 + BIT13); //2.11 2.12 2.13 as input + PINMODE4 |= (BIT23) | (BIT25) | (BIT27); // no resistors - //Tetra -// FIO2DIR |= BIT0 + BIT7; -// 2.0 bis 2.7 + //Tetra + // FIO2DIR |= BIT0 + BIT7; + // 2.0 bis 2.7 - // No Pullups on any port -// Does not work, needs more current than pull-ups -// 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; + // No Pullups on any port + // Does not work, needs more current than pull-ups + // 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/avsextrem/drivers/Makefile b/avsextrem/drivers/Makefile index e3bb5c62ff..71736befcc 100644 --- a/avsextrem/drivers/Makefile +++ b/avsextrem/drivers/Makefile @@ -3,7 +3,7 @@ BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o) DEP = $(SRC:%.c=$(BINDIR)%.d) -INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ +INCLUDES += -I$(RIOTBASE)/sys/include/ -I$(RIOTBASE)/drivers/cc110x_ng/include/ -I$(RIOTBOARD)/$(BOARD)/include $(BINDIR)avsextrem_base.a: $(OBJ) $(AR) rcs $(BINDIR)${ARCH} $(OBJ) diff --git a/avsextrem/drivers/avsextrem-cc1100.c b/avsextrem/drivers/avsextrem-cc1100.c new file mode 100644 index 0000000000..da0da6aac8 --- /dev/null +++ b/avsextrem/drivers/avsextrem-cc1100.c @@ -0,0 +1,260 @@ +/* +* avsextrem-cc1100.c - CC100 Transceiver Driver for the AVSEXTREM-BOARD. +* Copyright (C) 2013 Heiko Will +* +* This source code is licensed under the LGPLv2 license, +* See the file LICENSE for more details. +* +*/ + + +/** + * @file + * @ingroup LPC2387 + * @brief CC1100 LPC2387 dependend functions + * + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Heiko Will + * @author Thomas Hillebrandt + * @author Zakaria Kasmi + * + * @version $Revision: 1781 $ + * + * @note $Id: avsextrem-cc1100.c 1781 2013-08-14 13:39:36Z kasmi $ + */ + +#include +#include +// cpu +#include "cpu.h" +// sys +#include "cc1100.h" +#include "arch_cc1100.h" +#include "cc1100_spi.h" +#include "gpioint.h" + +#define CC1100_GDO0 (FIO2PIN & BIT6) // read serial I/O (GDO0) +#define CC1100_GDO1 (FIO0PIN & BIT8) // read serial I/O (GDO1) +#define CC1100_GDO2 (FIO0PIN & BIT28) // read serial I/O (GDO2) + +#define SPI_TX_EMPTY (SSP1SR & SSPSR_TFE) +#define SPI_BUSY (SSP1SR & SSPSR_BSY) +#define SPI_RX_AVAIL (SSP1SR & SSPSR_RNE) + +#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 + +//#define DEBUG +#ifdef DEBUG + +#include "stdio.h" + +static unsigned long time_value; + +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; +} +#endif + +int cc1100_get_gdo0(void) +{ + return CC1100_GDO0; +} + +int cc1100_get_gdo1(void) +{ + return CC1100_GDO1; +} + +int cc1100_get_gdo2(void) +{ + return CC1100_GDO2; +} + +void cc1100_spi_init(void) +{ + // configure chip-select + FIO0DIR |= BIT6; + FIO0SET = BIT6; + + // Power + PCONP |= PCSSP1; // Enable power for SSP1 (default is on) + + // PIN Setup + PINSEL0 |= BIT15; // Set CLK function to SSP1 + PINSEL0 &= ~BIT14; + PINSEL0 |= BIT17 ; // Set MISO function to SSP1 + PINSEL0 &= ~BIT16; + PINSEL0 |= BIT19; // Set MOSI function to SSP1 + PINSEL0 &= ~BIT18; + // Interface Setup + SSP1CR0 = 7; + + // Clock Setup + uint32_t pclksel; + uint32_t cpsr; + lpc2387_pclk_scale(F_CPU / 1000, 6000, &pclksel, &cpsr); + PCLKSEL0 &= ~(BIT21 | BIT20); // CCLK to PCLK divider + PCLKSEL0 |= pclksel << 20; + SSP1CPSR = cpsr; + + // Enable + SSP1CR1 |= BIT1; // SSP-Enable + int dummy; + + // Clear RxFIFO: + while (SPI_RX_AVAIL) { // while RNE (Receive FIFO Not Empty)... + dummy = SSP1DR; // read data + } +} + +uint8_t +cc1100_txrx(uint8_t c) +{ + uint8_t result; + SSP1DR = c; +#ifdef DEBUG + set_time(); +#endif + + while (!SPI_TX_EMPTY) { +#ifdef DEBUG + test_time(0); +#endif + } + +#ifdef DEBUG + set_time(); +#endif + + while (SPI_BUSY) { +#ifdef DEBUG + test_time(1); +#endif + } + +#ifdef DEBUG + set_time(); +#endif + + while (!SPI_RX_AVAIL) { +#ifdef DEBUG + test_time(2); +#endif + } + + result = (uint8_t)SSP1DR; + return result; +} + +void cc1100_spi_cs(void) +{ + FIO0CLR = BIT6; +} + +void +cc1100_spi_select(void) +{ + volatile int retry_count = 0; + volatile int abort_count; + // Switch to GDO mode input + PINSEL0 &= ~(BIT17 + BIT16);// Set MISO function to GPIO + FIO0DIR &= ~BIT8; +cs_low: + // CS to low + abort_count = 0; + FIO0CLR = BIT6; + // 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; + } + + FIO0SET = BIT6; // CS to high + goto cs_low; // try again + } + + goto loop; + } + +final: + // Switch to SPI mode + PINSEL0 |= BIT17; // Set MISO function to SSP1 + PINSEL0 &= ~BIT16; +} + +void +cc1100_spi_unselect(void) +{ + FIO0SET = BIT6; +} + +void cc1100_gdo2_disable(void) +{ + gpioint_set(0, BIT28, GPIOINT_DISABLE, NULL); +} + +void cc1100_gdo2_enable(void) +{ + gpioint_set(0, BIT28, GPIOINT_FALLING_EDGE, &cc1100_gdo2_irq); +} + +void cc1100_before_send(void) +{ + // Disable GDO2 interrupt before sending packet + cc1100_gdo2_disable(); +} + +void cc1100_after_send(void) +{ + // Enable GDO2 interrupt after sending packet + cc1100_gdo2_enable(); +} + +void cc1100_gdo0_enable(void) +{ + gpioint_set(2, BIT6, GPIOINT_RISING_EDGE, &cc1100_gdo0_irq); +} + +void cc1100_gdo0_disable(void) +{ + gpioint_set(2, BIT6, GPIOINT_DISABLE, NULL); +} + + + + +void cc1100_init_interrupts(void) +{ + // Enable external interrupt on low edge (for GDO2) + FIO0DIR &= ~BIT28; + cc1100_gdo2_enable(); + // Enable external interrupt on low edge (for GDO0) + FIO2DIR &= ~BIT6; +} + diff --git a/avsextrem/drivers/avsextrem-smb380.c b/avsextrem/drivers/avsextrem-smb380.c new file mode 100644 index 0000000000..73d5a49be2 --- /dev/null +++ b/avsextrem/drivers/avsextrem-smb380.c @@ -0,0 +1,1347 @@ +/* + * msba2acc-smb380.c - implementation of the Driver for the SMB380 acceleration + * sensor on the AVSEXTREM board. + * Copyright (C) 2013 Freie Universität Berlin + * + * This source code is licensed under the LGPLv2 license, + * See the file LICENSE for more details. + * + */ + +/** + * @file + * @internal + * @brief SMB380 acceleration sensor driver for the LPC2387 on the + * AVSEXTREM board. + * + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi + * @version $Revision: 3854 $ + * + * @note $Id: msba2acc-smb380.c 3854 2010-01-18 15:27:01Z zkasmi $ + */ + + +#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ +#include "cpu.h" +#include "lpm.h" +//#include "PatrecInit.h" +#include "VIC.h" +#include "kernel.h" +#include "ssp0-board.h" +#include "smb380-board.h" +#include "hwtimer.h" +#include +#include +// for fk_thread: +#include "sched.h" +#include "msg.h" +#include "irq.h" + +//#include "hal-board.h" +#include "gpioint.h" +#include "stdlib.h" +#include "math.h" +#include "lpc2387.h" + +/* program example + * + * + * + * +SMB380_init(); //Initializes SPI and the SMB380 accelerator sensor +SMB380_setRange(SMB380_RANGE_8G); +//SMB380_setBandWidth(SMB380_BAND_WIDTH_100HZ); +SMB380_enableNewDataInt(); + +while ( readRingBuff(accInt) ) { + printf("[%4i|%4i|%4i|%4i]\r\n", accInt[0], accInt[1], accInt[2], accInt[3]); + ktimer_wait(KTIMER_TICKS(1000000)); + //actualizeRingReadPointer(); //update read-pointer position to a current measurement (drop unread ones) +} +*/ + +uint8_t simple_pid; +int16_t simple_buffer[4]; + +volatile int16_t *ringBuff_X = NULL; +volatile int16_t *ringBuff_Y = NULL; +volatile int16_t *ringBuff_Z = NULL; +volatile int16_t *ringBuff_T = NULL; +uint16_t readPointerPos[SMB380_RING_BUFF_MAX_THREADS]; +u_char PointerList[SMB380_RING_BUFF_MAX_THREADS]; +static msg_t wakeupmessage; + +uint8_t (*smb380function)(int16_t *); //pointer to a user-defined function which is called during a writepointer action + +uint16_t sampleRateSMB380; + +bool dynRange = false; //condition if range-check should be done +uint8_t counter_Decreasing = 0; + +volatile uint16_t interruptTicksSMB380; + +typedef struct { + u_int writePointerPos; //Writepointer position + uint8_t countRange; //check value for updated range settings (only needed for multiplication in Float-mode + uint8_t range; //current range +} settingsSMB380; + +settingsSMB380 settings; + +/* measuring temperature dependent internal sample rate of SMB380 */ +static volatile uint32_t tickStart = 0; +static volatile uint32_t tickLastSample = 0; +static volatile uint32_t tickCurrentSamples = 0; + +uint8_t initRingReadPointerforCurrentThread(void); +uint8_t getRingReadPointerforCurrentThread(void); +void wakeUpRegisteredProcesses(void); +uint8_t smb380emptyfunction(int16_t *); +static void SMB380_extIntHandler(void); + +extern unsigned long ktimer_now(void); + +float SMB380_getSampleRatio(void) +{ + return ((1.0 / ((float)(tickLastSample - tickStart) / tickCurrentSamples)) * 100000) /*/ (float)(SMB380_SAMPLE_RATE_MAX / sampleRateSMB380)*/; +} + +uint8_t smb380emptyfunction(int16_t *value) +{ + return 1; +} + +uint8_t SMB380_HystereseFunctionSample(int16_t *value) +{ + static int16_t x = 0, y = 0, z = 0; + static uint8_t counter = 0; + int16_t delta = abs(value[0] - x) + abs(value[1] - y) + abs(value[2] - z); + + if (delta < 40) { //TODO: delta and counter are constant values, change it! + counter++; + } + else { + counter = 0; + } + + x = value[0]; + y = value[1]; + z = value[2]; + + if (smb380_mode == SMB380_THRESHOLD) { + SMB380_disableAnyMotionLimit(); + SMB380_enableNewDataInt(); + smb380_mode = SMB380_CONTINOUS; + printf("Threshold: x=%i, y=%i, z=%i\n\r", value[0], value[1], value[2]); + } + + if ((counter == 100) && (smb380_mode == SMB380_POLL)) { + //MZ SMB380_disableNewDataInt(); + //SMB380_setAnyMotionLimit(100,0); + SMB380_enableAnyMotionLimit(); + smb380_mode = SMB380_THRESHOLD; + counter = 0; //n�tig? + } + else if (counter == 100) { + SMB380_disableNewDataInt(); + //SMB380_setAnyMotionLimit(100,0); + SMB380_enableAnyMotionLimit(); + smb380_mode = SMB380_FALSEALERT; + counter = 0; //n�tig? + return 0; + } + + + return 1; +} + +static void SMB380_simple_interrupthandler(void) +{ + lpm_awake(); + + SMB380_getAcceleration(SMB380_X_AXIS, NULL, &simple_buffer[0]); + SMB380_getAcceleration(SMB380_Y_AXIS, NULL, &simple_buffer[1]); + SMB380_getAcceleration(SMB380_Z_AXIS, NULL, &simple_buffer[2]); + simple_buffer[3] = SMB380_getTemperature(); + + if (interruptTicksSMB380 >= sampleRateSMB380 - 1) { + interruptTicksSMB380 = 0; + wakeupmessage.type = MSG_TYPE_SMB380_WAKEUP; + msg_send(&wakeupmessage, simple_pid, 0); + } + else { + interruptTicksSMB380++; + } + + return; +} + +// enables simple Interrupt driven Mode +uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t range) +{ + SSP0Init(); + interruptTicksSMB380 = 0; + simple_pid = active_thread->pid; + gpioint_set(0, BIT1, GPIOINT_RISING_EDGE, &SMB380_simple_interrupthandler); + SMB380_softReset(); + hwtimer_wait(HWTIMER_TICKS(100000)); + SMB380_disableUpperLimit(); + SMB380_disableLowerLimit(); + SMB380_setSampleRate(samplerate); + SMB380_setBandWidth(bandwidth); + SMB380_setRange(range); + + return 0; +} + +uint8_t SMB380_init(uint8_t (*func)(int16_t *)) +{ + SSP0Init(); + +#if SMB380_EXTINT_MODE + + if (gpioint_set(0, BIT1, GPIOINT_RISING_EDGE, &SMB380_extIntHandler)); + +#endif + + interruptTicksSMB380 = 0; + + if (func != NULL) { + smb380function = func; + } + else { + smb380function = smb380emptyfunction; + } + + //smb380function = SMB380_HystereseFunctionSample; //Platzhalter + + SMB380_softReset(); + hwtimer_wait(HWTIMER_TICKS(100000)); + SMB380_disableUpperLimit(); + SMB380_disableLowerLimit(); + + smb380_mode = SMB380_POLL; + SMB380_setSampleRate(SMB380_SAMPLE_RATE_MAX); //set output to 3000 Hz + + settings.writePointerPos = 0; + settings.range = 0; + settings.countRange = 0; + + for (int i = 0; i < SMB380_RING_BUFF_MAX_THREADS; i++) { + readPointerPos[i] = 0; + PointerList[i] = 0; + } + + ringBuff_X = (int16_t *)malloc(SMB380_RING_BUFF_SIZE * sizeof(int16_t)); + ringBuff_Y = (int16_t *)malloc(SMB380_RING_BUFF_SIZE * sizeof(int16_t)); + ringBuff_Z = (int16_t *)malloc(SMB380_RING_BUFF_SIZE * sizeof(int16_t)); + ringBuff_T = (int16_t *)malloc(SMB380_RING_BUFF_SIZE * sizeof(int16_t)); + + if ((ringBuff_X == NULL) | (ringBuff_Y == NULL) | (ringBuff_Z == NULL) | (ringBuff_T == NULL)) { + if (ringBuff_X != NULL) { + free((int16_t *)ringBuff_X); + } + + if (ringBuff_Y != NULL) { + free((int16_t *)ringBuff_Y); + } + + if (ringBuff_Z != NULL) { + free((int16_t *)ringBuff_Z); + } + + if (ringBuff_T != NULL) { + free((int16_t *)ringBuff_T); + } + + return 0; + } + + return 1; +} + +static void SMB380_extIntHandler(void) +{ + int16_t accInt[4]; + + lpm_awake(); //initializes clock + + SMB380_getAcceleration(SMB380_X_AXIS, NULL, &accInt[0]); + SMB380_getAcceleration(SMB380_Y_AXIS, NULL, &accInt[1]); + SMB380_getAcceleration(SMB380_Z_AXIS, NULL, &accInt[2]); + accInt[3] = SMB380_getTemperature(); + + + writeRingBuff(accInt); + + // printf("SMB380 acc x,y,z: [%i|%i|%i|%2.3f]\r\n", accInt[0], accInt[1], accInt[2], acc[3]); + // printf("SMB380 acc x,y,z: [%2.3f|%2.3f|%2.3f|%2.3f]\r\n\n\n", acc[0], acc[1], acc[2], acc[3]); + // printf("Nach Interrupt Reset:\n"); + // SMB380_ShowMemory(); +} + +void SMB380_setSampleRate(uint16_t rate) +{ + if (rate > 0 && rate <= SMB380_SAMPLE_RATE_MAX) { + sampleRateSMB380 = SMB380_SAMPLE_RATE_MAX / rate; + } + else { + sampleRateSMB380 = 1; + } +} + +uint16_t SMB380_getSampleRate(void) +{ + return SMB380_SAMPLE_RATE_MAX / sampleRateSMB380; +} + +uint8_t SMB380_Prepare(void) +{ + return SSP0Prepare(SMB380_ACC, 16, 1, 1, 8000); +} + +uint8_t SMB380_Unprepare(void) +{ + return SSP0Unprepare(SMB380_ACC); +} + +/* return the pointerNo related with the current thread */ +uint8_t getRingReadPointerforCurrentThread(void) +{ + uint8_t pointerNo = 0; + + while ((PointerList[pointerNo] != active_thread->pid) && (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { + pointerNo++; + } + + return pointerNo; +} + +uint8_t initRingReadPointerforCurrentThread(void) +{ + //TODO make it Threadsafe + uint8_t pointerNo = 0; + + while ((PointerList[pointerNo] > 0) && (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { + pointerNo++; + } + + if (pointerNo == SMB380_RING_BUFF_MAX_THREADS) { + return 0; + } + else { + PointerList[pointerNo] = active_thread->pid; + readPointerPos[pointerNo] = settings.writePointerPos; + return 1; + } +} + +void freeRingReadPointer(void) +{ + //Should be Threadsafe + uint8_t pointerNo = getRingReadPointerforCurrentThread(); + + if (pointerNo != SMB380_RING_BUFF_MAX_THREADS) { + PointerList[pointerNo] = 0; + } +} + +void actualizeRingReadPointer(void) +{ + uint8_t pointerNo = getRingReadPointerforCurrentThread(); + + if (pointerNo != SMB380_RING_BUFF_MAX_THREADS) { + readPointerPos[pointerNo] = settings.writePointerPos; + } +} + +//TODO more read-pointer +uint8_t readRingBuff(int16_t *value) +{ + + // if ( inISR() ) { + // if ( readPointerPos[pointerNo] == settings.writePointerPos ) + // return 0; + // } else { + // while ( readPointerPos[pointerNo] != settings.writePointerPos ) { + // uint8_t x = 254; + //// while ( x ) + //// x--; + // } + // } + + // zugriff auf pid + // if (getRead fk_thread->pid kenn ich schon) + // { + // pointerno[pid]; + // } + // else + // { + // initRingReadPointerforCurrentThread(); + // } + uint8_t pointerNo = getRingReadPointerforCurrentThread(); + + // If thread is not known to read on the ringbuffer, try adding him to the list of known threads, otherwise exit with error + if (pointerNo == SMB380_RING_BUFF_MAX_THREADS) { + if (!initRingReadPointerforCurrentThread()) { + //printf("%sNo Readpointer left, maximum of %u is reached!\n\r", SMB380_DEBUG_MESSAGE, SMB380_RING_BUFF_MAX_THREADS); + return 0; + } + else { + pointerNo = getRingReadPointerforCurrentThread(); + } + } + + if (readPointerPos[pointerNo] == settings.writePointerPos) { + value[0] = 0; + value[1] = 0; + value[2] = 0; + value[3] = 0; + return 0; + } + + value[0] = ringBuff_X[readPointerPos[pointerNo]]; + value[1] = ringBuff_Y[readPointerPos[pointerNo]]; + value[2] = ringBuff_Z[readPointerPos[pointerNo]]; + value[3] = ringBuff_T[readPointerPos[pointerNo]]; + readPointerPos[pointerNo] += 1; + + if (readPointerPos[pointerNo] == SMB380_RING_BUFF_SIZE) { + readPointerPos[pointerNo] = 0; + } + + return 1; +} + +//TODO more read-pointer +uint8_t writeRingBuff(int16_t *value) +{ + if (smb380_mode == SMB380_FALSEALERT) { + smb380_mode = SMB380_THRESHOLD; + return 0; + } + + if ((interruptTicksSMB380 >= sampleRateSMB380 - 1) || (smb380_mode == SMB380_THRESHOLD)) { + interruptTicksSMB380 = 0; + + /* measuring temperature dependent internal sample rate of SMB380 */ + if (smb380_mode == SMB380_CONTINOUS) { + tickLastSample = ktimer_now(); + tickCurrentSamples++; + } + + ringBuff_X[settings.writePointerPos] = value[0]; + ringBuff_Y[settings.writePointerPos] = value[1]; + ringBuff_Z[settings.writePointerPos] = value[2]; + ringBuff_T[settings.writePointerPos] = value[3]; + + /* check for increasing range if dynRange is true */ + if (dynRange) { + smb380function = checkRange; + } + else { + smb380function = smb380emptyfunction; + } + + smb380function(value); + + //printf("Werte: x=%i, y=%i, z=%i\n\r",value[0], value[1], value[2]); + //vgpio_toggle(&gpio_led_green); + + settings.writePointerPos += 1; + + if (settings.writePointerPos == SMB380_RING_BUFF_SIZE) { + settings.writePointerPos = 0; + } + + wakeUpRegisteredProcesses(); + return 1; + } + else { + interruptTicksSMB380++; + return 0; + } +} + +void SMB380_activateDynRangeSet(uint8_t activate) +{ + switch (activate) { + case 0: + dynRange = false ; + break; + + case 1: + dynRange = true ; + break; + } +} + +/* + * checking for in-/decreasing range + */ +uint8_t checkRange(int16_t *value) +{ + bool increased = false; + + // printf("CurrentValues: %i %i %i \r\n", xyzTMP[0], xyzTMP[1], xyzTMP[2]); + + // determination of max and min value + int16_t maxValue = value[0]; // max(xValue, max(yValue, zValue)); + int16_t minValue = value[0]; // min(xValue, min(yValue, zValue)); + + for (int i = 1; i < 3; i++) { + if (value[i] > maxValue) { + maxValue = value[i]; + } + + if (value[i] < minValue) { + minValue = value[i]; + } + } + + int8_t isRange = SMB380_getRange(); + + //increase range immediately + switch (isRange) { + case 2: + if ((maxValue > 1800) || (minValue < -1800)) { + SMB380_setRange(SMB380_RANGE_4G); + increased = true; + printf("=== Set range from 2 g to 4 g ===\r\n"); + } + + break; + + case 4: + if ((maxValue > 3800) || (minValue < -3800)) { + SMB380_setRange(SMB380_RANGE_8G); + increased = true; + printf("=== Set range from 4 g to 8 g ===\r\n"); + } + + break; + + case 8: + break; + } + + /* check for decreasing range */ + if (increased) { + counter_Decreasing = 0; + } + else { + //decrease range after 10 consecutive relevant values + switch (isRange) { + case 2: + break; + + case 4: + if ((maxValue < 2000) && (minValue > -2000)) { + if (counter_Decreasing >= 9) { + SMB380_setRange(SMB380_RANGE_2G); + printf("=== Set range from 4 g to 2 g ===\r\n"); + counter_Decreasing = 0; + } + else { + counter_Decreasing++; + } + } + else { + counter_Decreasing = 0; + } + + break; + + case 8: + if ((maxValue < 4000) && (minValue > -4000)) { + if (counter_Decreasing >= 9) { + SMB380_setRange(SMB380_RANGE_4G); + printf("=== Set range from 8 g to 4 g ===\r\n"); + counter_Decreasing = 0; + } + else { + counter_Decreasing++; + } + } + else { + counter_Decreasing = 0; + } + + break; + } + } + + return 0; +} + + +void wakeUpRegisteredProcesses(void) +{ + uint8_t pointerNo = 0; + //wake up waiting processes + wakeupmessage.type = MSG_TYPE_SMB380_WAKEUP; + + while ((PointerList[pointerNo] > 0) && (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { + msg_send(&wakeupmessage, PointerList[pointerNo], false); + pointerNo++; + } +} + +int16_t SMB380_getTemperature(void) +{ + int16_t t = 0; + + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_TEMP, 0, SMB380_READ_REGISTER); + + // t = (SMB380_ssp_read() & 0xFF) / 2.0 + SMB380_TEMP_OFFSET; + t = (SMB380_ssp_read() & 0xFF); + t = (t >> 1) + SMB380_TEMP_OFFSET; + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return t; +} + +void SMB380_getAcceleration(unsigned char axis, int16_t *pAbs, int16_t *pMg) +{ + unsigned short ur; + + if (!settings.countRange && (pMg != NULL)) { + settings.countRange = 1; + settings.range = SMB380_getRange(); + } + + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + switch (axis) { + case SMB380_X_AXIS: + SMB380_ssp_write(SMB380_ACC_X_MSB, 0, SMB380_READ_REGISTER); + SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA, 0, SMB380_READ_REGISTER); + break; + + case SMB380_Y_AXIS: + SMB380_ssp_write(SMB380_ACC_Y_MSB, 0, SMB380_READ_REGISTER); + SMB380_ssp_write(SMB380_ACC_Y_LSB_NEWDATA, 0, SMB380_READ_REGISTER); + break; + + default: + SMB380_ssp_write(SMB380_ACC_Z_MSB, 0, SMB380_READ_REGISTER); + SMB380_ssp_write(SMB380_ACC_Z_LSB_NEWDATA, 0, SMB380_READ_REGISTER); + } + + ur = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + ur |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; + SMB380_Unprepare(); + restoreIRQ(cpsr); + + if (pAbs != NULL) { + if (ur & BIT9) { //ur<0 + *pAbs = ur | 0xFC00; + } + else { + *pAbs = ur & 0x03FF; + } + } + + if (pMg != NULL) { + if (ur & BIT9) { //ur<0 + *pMg = -(((settings.range * (512 - (ur & 0x1FF))) * 2000) / 1024); + } + else { + *pMg = ((settings.range * ur) * 2000) / 1024; + } + } + +} + +unsigned char SMB380_getChipID(void) +{ + unsigned char ur = 0; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CHIP_ID, 0, 0); + ur = (unsigned char)(SMB380_ssp_read() & SMB380_CHIP_ID_MASK); + restoreIRQ(cpsr); + return ur; +} + +void SMB380_setWakeUpPause(unsigned char duration) +{ + unsigned char utemp; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + utemp = SMB380_ssp_read(); + utemp &= ~SMB380_CONTROL4_WAKEUP_PAUSE_MASK; + utemp |= (duration & (0x3) << 1);//+1; + SMB380_ssp_write(SMB380_CONTROL4, utemp, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +unsigned char SMB380_getWakeUpPause(void) +{ + unsigned char up; + + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + up = (unsigned char)SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + up &= SMB380_CONTROL4_WAKEUP_PAUSE_MASK; + up = up >> 1; + + return up; +} + +void SMB380_setBandWidth(unsigned char bandWidth) +{ + unsigned char utemp; + + if ((bandWidth == SMB380_BAND_WIDTH_100HZ) | + (bandWidth == SMB380_BAND_WIDTH_1500HZ) | + (bandWidth == SMB380_BAND_WIDTH_190HZ) | + (bandWidth == SMB380_BAND_WIDTH_25HZ) | + (bandWidth == SMB380_BAND_WIDTH_375HZ) | + (bandWidth == SMB380_BAND_WIDTH_50HZ) | + (bandWidth == SMB380_BAND_WIDTH_750HZ)) { + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); + utemp = SMB380_ssp_read(); + utemp &= ~SMB380_CONTROL3_BANDWITH_MASK; + utemp |= (bandWidth & 0x7); + SMB380_ssp_write(SMB380_CONTROL3, utemp, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + } +} + +void SMB380_setRange(unsigned char range) +{ + unsigned char utemp = 0; + + if (range != 0x3) { + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); + utemp = (unsigned char)SMB380_ssp_read(); + utemp &= ~SMB380_CONTROL3_RANGE_MASK; + utemp |= (range & 0x3) << 3; + SMB380_ssp_write(SMB380_CONTROL3, utemp, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + settings.countRange = 0; + } + +} + +unsigned char SMB380_getRange(void) +{ + unsigned char ur; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); + ur = (SMB380_ssp_read() & SMB380_CONTROL3_RANGE_MASK) >> 3; + SMB380_Unprepare(); + restoreIRQ(cpsr); + + switch (ur) { + case SMB380_RANGE_2G: + return 2; + + case SMB380_RANGE_4G: + return 4; + + case SMB380_RANGE_8G: + return 8; + + default: + return 4; + } +} + +unsigned char SMB380_getBandWidth(void) +{ + unsigned char uBand; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL3, 0, SMB380_READ_REGISTER); + uBand = SMB380_ssp_read() & SMB380_CONTROL3_BANDWITH_MASK; + SMB380_Unprepare(); + restoreIRQ(cpsr); + return uBand; +} + +int16_t SMB380_getBandWidthAbs(void) +{ + unsigned char uBand; + uBand = SMB380_getBandWidth(); + + switch (uBand) { + case SMB380_BAND_WIDTH_25HZ: + return 25; + + case SMB380_BAND_WIDTH_50HZ: + return 50; + + case SMB380_BAND_WIDTH_100HZ: + return 100; + + case SMB380_BAND_WIDTH_190HZ: + return 190; + + case SMB380_BAND_WIDTH_375HZ: + return 375; + + case SMB380_BAND_WIDTH_750HZ: + return 750; + + case SMB380_BAND_WIDTH_1500HZ: + return 1500; + + default: + return uBand; + } +} + +void SMB380_softReset(void) +{ + unsigned char ur; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL1, SMB380_CONTROL1_SOFT_RESET_MASK, SMB380_WRITE_REGISTER); + ur = ((unsigned char)SMB380_ssp_read()) & SMB380_CONTROL1_SOFT_RESET_MASK; + SMB380_Unprepare(); + restoreIRQ(cpsr); + ur = ur >> 1; +} + +void SMB380_setCustomerReg(unsigned char data) +{ + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CUST1, data, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +unsigned char SMB380_getCustomerReg(void) +{ + unsigned uReg = 0; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CUST1, 0, SMB380_READ_REGISTER); + uReg = (unsigned char)SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + return uReg; +} + +/* Selftest + * + * */ +void SMB380_Selftest_1(void) +{ + unsigned char uReg = 0; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_LG_THRES, 6, SMB380_WRITE_REGISTER); + //SSP0Init(); + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_LG_DUR, 0, SMB380_WRITE_REGISTER); + //SSP0Init(); + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); + + uReg = (unsigned char)SMB380_ssp_read(); + uReg &= ~SMB380_CONTROL1_SELF_TEST_1_MASK; + uReg |= 0x01 << 3; + SMB380_ssp_write(SMB380_CONTROL1, uReg, SMB380_WRITE_REGISTER); + // SSP0Init(); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_ShowMemory(void) +{ + uint16_t uReg = 0; + uint8_t bitMask[16]; + printf("SMB380 Speicher\n\r"); + unsigned long cpsr; + + for (unsigned char regAd = 0x16; regAd > 0; regAd--) { + cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(regAd - 1, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + printf("Register: = %X: 0x%X = ", regAd - 1, uReg); + + for (int pos = 0; pos < 16; pos++) { //uReg != 0) + bitMask[15 - pos] = uReg % 2; + + uReg = uReg / 2; + } + + for (int pos = 8; pos < 16; pos++) { //uReg != 0) + printf("%d", bitMask[pos]); + + if ((pos % 4) == 0) { + printf(" "); + } + } + + printf("\n"); + } +} + +void SMB380_setUpperLimit(void) +{ + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_HG_THRES, 128, SMB380_WRITE_REGISTER); //1g + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_HG_DUR, 0, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_enableUpperLimit(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_HG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_disableUpperLimit(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_HG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_enableLowerLimit(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_LG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_disableLowerLimit(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_LG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +/* @param gvaluefloat - value is in mg + * @param gvalueint - value in range of 0 to 512 + * Choose one of them, set the other to zero + */ +uint8_t SMB380_setAnyMotionLimit(uint16_t mg, uint16_t gvalueint) +{ + + uint8_t threshold = 0; + + if (mg != 0) { + threshold = mg / (15.6 * (SMB380_getRange() / 2)); + } + else if (gvalueint != 0) { + threshold = ceil(((gvalueint * 2000) / 512.0) / 15.6); //Scaling for different gRanges is not needed + } + else { + return 0; + } + + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_ANY_MOTION_THRES, threshold, SMB380_WRITE_REGISTER); //0,3g = 300 / 15,6mg = 19 + SMB380_ssp_read(); + //Set duration at this point + SMB380_ssp_write(SMB380_ANY_MOTION_DUR_HYST, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + // SMB380_ssp_write(SMB380_ANY_MOTION_DUR_HYST, (uReg & ~SMB380_ANY_MOTION_DUR_MASK) | 0x40, SMB380_WRITE_REGISTER); + // SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); + return 1; +} + +void SMB380_enableAnyMotionLimit(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_ENABLE_ADV_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ANY_MOTION_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_disableAnyMotionLimit(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ANY_MOTION_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_ENABLE_ADV_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_enableNewDataInt(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + //prevent deep sleep, reason: 400�s wake-up time is to long for 3kHz interrupts + SETBIT(lpm_prevent_sleep, LPM_PREVENT_SLEEP_ACCSENSOR); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_NEW_DATA_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + /* measuring temperature dependent internal sample rate of SMB380 */ + tickStart = ktimer_now(); + tickCurrentSamples = 0; + restoreIRQ(cpsr); +} + +void SMB380_disableNewDataInt(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_NEW_DATA_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + //enable deep sleep, reason: 400�s wake-up time was to long for 3kHz interrupts + CLRBIT(lpm_prevent_sleep, LPM_PREVENT_SLEEP_ACCSENSOR); + restoreIRQ(cpsr); +} + +void SMB380_resetInterruptFlags(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_RESET_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_enableEEPROM(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_EE_W_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +void SMB380_disableEEPROM(void) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); + uReg = SMB380_ssp_read(); + SMB380_ssp_write(SMB380_CONTROL1, uReg & ~SMB380_CONTROL1_EE_W_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_read(); + SMB380_Unprepare(); + restoreIRQ(cpsr); +} + +//void SMB380_calibrate(void){ +// unsigned short uMSB, uLSB; +// //TODO 25Hz, 2G +// +// SMB380_ssp_write(SMB380_ACC_X_MSB, 0, SMB380_READ_REGISTER); +// SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA, 0, SMB380_READ_REGISTER); +// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; +// uLSB = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; +// +// SMB380_ssp_write(SMB380_ACC_X_MSB + SMB380_EEPROM_OFFSET, uMSB, SMB380_WRITE_REGISTER); +// SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA + SMB380_EEPROM_OFFSET, uLSB, SMB380_WRITE_REGISTER); +// +// +// SMB380_ssp_write(SMB380_ACC_Y_MSB, 0, SMB380_READ_REGISTER); +// SMB380_ssp_write(SMB380_ACC_Y_LSB_NEWDATA, 0, SMB380_READ_REGISTER); +// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; +// uLSB |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; +// +// SMB380_ssp_write(SMB380_ACC_Z_MSB, 0, SMB380_READ_REGISTER); +// SMB380_ssp_write(SMB380_ACC_Z_LSB_NEWDATA, 0, SMB380_READ_REGISTER); +// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; +// uLSB |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; +// +// +//} + +/* + * Return offsets from offset registers, + * remove xyz afterwards because it is useless + */ +unsigned char SMB380_readOffset(uint16_t *offset) +{ + if (sizeof(offset) < 3) { + return false; + } + + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); + uReg = ((SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6); + SMB380_ssp_write(SMB380_OFFSET_MSB_X, 0, SMB380_READ_REGISTER); + uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + + + offset[0] = uReg; + printf("Offset X: %u ", uReg); + + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); + uReg = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; + SMB380_ssp_write(SMB380_OFFSET_MSB_Y, 0, SMB380_READ_REGISTER); + uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + + offset[1] = uReg; + printf("Offset Y: %u ", uReg); + + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); + uReg = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; + SMB380_ssp_write(SMB380_OFFSET_MSB_Z, 0, SMB380_READ_REGISTER); + uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + + offset[2] = uReg; + printf("Offset Z: %u \r\n", uReg); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return true; +} + +unsigned char SMB380_readOffsetTemp(uint16_t *offset) +{ + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); + uReg = ((SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6); + SMB380_ssp_write(SMB380_OFFSET_MSB_T, 0, SMB380_READ_REGISTER); + uReg |= (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; + + + offset[0] = uReg; + printf("Offset T: %u ", uReg); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return true; +} + +/* EEPROM = 1 if data has to be written in EEPROM and not only in image + * + */ +void SMB380_writeOffset(uint16_t *offset, uint8_t EEPROM) +{ + printf("Writing Offset X: %u Y: %u Z: %u\r\n", offset[0], offset[1], offset[2]); + + if (sizeof(offset) >= 3) { + uint16_t eeoffset = 0; + + if (EEPROM) { + eeoffset = SMB380_EEPROM_OFFSET; //create offset if saving to EEPROM is needed + } + + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + //x-Axis + uReg = (offset[0] & 0x03) << 6; //get both LSB Bits + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); //write them to image or eeprom + uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + uReg = (offset[0] & 0x3FC) >> 2; //get MSB Bits + SMB380_ssp_write(SMB380_OFFSET_MSB_X + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + //y-Axis + uReg = (offset[1] & 0x03) << 6; //get both LSB Bits + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); //write them to image or eeprom + uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + uReg = (offset[1] & 0x3FC) >> 2; //get MSB Bits + SMB380_ssp_write(SMB380_OFFSET_MSB_Y + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + //z-Axis + uReg = (offset[2] & 0x03) << 6; //get both LSB Bits + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); //write them to image or eeprom + uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + uReg = (offset[2] & 0x3FC) >> 2; //get MSB Bits + SMB380_ssp_write(SMB380_OFFSET_MSB_Z + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + } +} + +void SMB380_writeOffsetTemp(uint16_t *offset, uint8_t EEPROM) +{ + printf("Writing Offset Temp: %u\r\n", offset[0]); + + if (sizeof(offset) >= 1) { + uint16_t eeoffset = 0; + + if (EEPROM) { + eeoffset = SMB380_EEPROM_OFFSET; //create offset if saving to EEPROM is needed + } + + unsigned short uReg; + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + //T-Axis + uReg = (offset[0] & 0x03) << 6; //get both LSB Bits + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); //write them to image or eeprom + uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + uReg = (offset[0] & 0x3FC) >> 2; //get MSB Bits + SMB380_ssp_write(SMB380_OFFSET_MSB_T + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_read(); + hwtimer_wait(HWTIMER_TICKS(50000)); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + } +} + +unsigned char SMB380_readGain(uint16_t *gain) +{ + if (sizeof(gain) < 3) { + return false; + } + + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + //x-gain + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); + gain[0] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); + //y-gain + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); + gain[1] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); + //z-gain + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); + gain[2] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return true; +} + +unsigned char SMB380_readGainTemp(uint16_t *gain) +{ + if (sizeof(gain) < 1) { + return false; + } + + unsigned long cpsr = disableIRQ(); + SMB380_Prepare(); + + //T-gain + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); + gain[0] = (SMB380_ssp_read() & SMB380_OFFSET_GAIN_MASK); + + SMB380_Unprepare(); + restoreIRQ(cpsr); + + return true; +} + + diff --git a/avsextrem/drivers/avsextrem-ssp0.c b/avsextrem/drivers/avsextrem-ssp0.c new file mode 100644 index 0000000000..17dfa05133 --- /dev/null +++ b/avsextrem/drivers/avsextrem-ssp0.c @@ -0,0 +1,416 @@ +/* + * avsextrem-ssp0.c - implementation of the SPI0 interface for the LPC2387, + * and the AVSESTREM board. + * Copyright (C) 2013 Freie Universität Berlin + * + * This source code is licensed under the LGPLv2 license, + * See the file LICENSE for more details. + */ + +/** + * @file + * @internal + * @brief Implements the SPI0 interface for the LPC2387 + * + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi + * @version $Revision: 3854 $ + * + * @note $Id: avsextrem-ssp0.c 3854 2013-08-14 15:27:01Z zkasmi $ + */ + +#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ +#include "cpu.h" +#include "VIC.h" +#include "ssp0-board.h" +#include "smb380-board.h" +//#include "mma7455l-board.h" +#include "gpioint.h" +#include "hwtimer.h" +#include +#include "lpm.h" + +//uint16_t sampleRateMMA7455L; +//uint16_t interruptTicksMMA7455L; +// +//static void MMA7455L_extIntHandler(void); + +/***************************************************************************** + ** Function name: SSP0Init + ** + ** Descriptions: SSP0 port initialization routine + ** + ** parameters: None + ** Returned value: true or false, if the interrupt handler + ** can't be installed correctly, return false. + ** + *****************************************************************************/ +uint32_t SSP0Init(void) +{ + + /* enable clock to SSP0 for security reason. By default, it's enabled already */ + PCONP |= PCSSP0; + //TODO CLK, MISO, MOSI standardm��ig als GPIOs konfigurieren +#if USE_CS + // PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; //P1.20 1.21 1.23 1.24 +#else + // PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 SSEL0 nicht + +#endif + +#if SSP1_INTERRUPT_MODE + + if (install_irq(SSP1_INT, (void *)SSP0Handler, HIGHEST_PRIORITY) == FALSE) { + return (FALSE); + } + + /* Set SSPINMS registers to enable interrupts */ + /* enable all error related interrupts */ + SSP1IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM; +#endif + + return (1); +} + +/* datasize (wordsize) in decimal (4-16), cpol&cpha =(0/1) and frequency divided by 1000 (e.g. 8 MHz = 8000) + * + */ +uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, uint16_t freq) +{ + switch (chip) { + case BMA180_INTERN: + case SMB380_ACC: { +#if USE_CS + PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; //P1.20 1.21 1.23 1.24 +#else + + PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 SSEL0 nicht +#endif + break; + } + + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: + case ACAMDMS: { +#if USE_CS + PINSEL0 |= BIT31; + PINSEL1 |= BIT1 | BIT3 | BIT5; //P0.15 0.16 0.17 0.18 +#else + //Turn on NanoPAN + PINSEL0 |= BIT31; + PINSEL1 |= BIT3 | BIT5; //0.15 0.17 0.18 SSEL0 nicht +#endif + break; + } + + case NORDIC: { + PINSEL0 |= BIT31; + PINSEL1 |= BIT3 | BIT5; //0.15 0.17 0.18 SSEL0 nicht + break; + } + + default: { + printf("wrong CHIP selected\n"); + return 0; + } + } + + uint32_t SSP0CR0tmp = 0; + + switch (datasize) { + case 4: + SSP0CR0tmp = BIT0 | BIT1; + break; + + case 5: + SSP0CR0tmp = BIT2; + break; + + case 6: + SSP0CR0tmp = BIT0 | BIT2; + break; + + case 7: + SSP0CR0tmp = BIT1 | BIT2; + break; + + case 8: + SSP0CR0tmp = BIT0 | BIT1 | BIT2; + break; + + case 9: + SSP0CR0tmp = BIT3; + break; + + case 10: + SSP0CR0tmp = BIT0 | BIT3; + break; + + case 11: + SSP0CR0tmp = BIT1 | BIT3; + break; + + case 12: + SSP0CR0tmp = BIT0 | BIT1 | BIT3; + break; + + case 13: + SSP0CR0tmp = BIT2 | BIT3; + break; + + case 14: + SSP0CR0tmp = BIT0 | BIT2 | BIT3; + break; + + case 15: + SSP0CR0tmp = BIT1 | BIT2 | BIT3; + break; + + case 16: + SSP0CR0tmp = BIT0 | BIT1 | BIT2 | BIT3; + break; + + default: + return 0; + } + + if (cpol) { + SSP0CR0tmp |= BIT6; + } + + if (cpha) { + SSP0CR0tmp |= BIT7; + } + + SSP0CR1 = 0x00; //SSP0 disabled + + /* Setting xx-Bit Datasize, CPOL and CPHA*/ + SSP0CR0 = SSP0CR0tmp; + + // Clock Setup + uint32_t pclksel; + uint32_t cpsr; + lpc2387_pclk_scale(F_CPU / 1000, freq, &pclksel, &cpsr); + PCLKSEL1 &= ~(BIT10 | BIT11); // CCLK to PCLK divider ??? + PCLKSEL1 |= pclksel << 10; + SSP0CPSR = cpsr; + + // Enable + SSP0CR1 |= BIT1; //SSP0 enabled + + uint32_t Dummy; + + for (uint32_t i = 0; i < FIFOSIZE; i++) { + Dummy = SSP0DR; // clear the RxFIFO + } + + return 1; +} + +uint8_t SSP0Unprepare(uint8_t chip) +{ + switch (chip) { + case BMA180_INTERN: + case SMB380_ACC: { + //Turn off Acceleration Sensor + PINSEL3 &= ~(BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17); + FIO1DIR |= BIT20 | BIT21 | BIT24; + FIO1DIR &= ~BIT23; //MISO as Input + FIO1SET = BIT20 | BIT24; //CLK + SSEL + MOSI GPIO as Output //TODO depends on CPOL+CPHA Settings + FIO1CLR = BIT21; + break; + } + + case BMA180_EXTERN: + case L3G_EXTERN: + case NORDIC: + case NANOPAN: + case ACAMDMS: { + //Turn off Nanopan (Pins to GPIO) + PINSEL0 &= ~(BIT30 | BIT31); //CLK to GPIO + PINSEL1 &= ~(BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5); + FIO0DIR |= BIT15 | BIT16 | BIT18; //CLK + SSEL + MOSI GPIO as Output + FIO0DIR &= ~BIT17; //MISO as Input + FIO0SET = BIT15 | BIT16; //CLK + SSEL + MOSI GPIO as Output //TODO depends on CPOL+CPHA Settings + FIO0CLR = BIT18; + break; + } + + default: { + printf("wrong CHIP selected\n"); + return 0; + } + } + + return 1; +} + +unsigned char SMB380_ssp_write(const unsigned char regAddr, const unsigned char data, unsigned char flag) +{ + + uint16_t temp = 0; + + if (flag) { + temp = (unsigned int)(((regAddr & 0xFF7F) << 8) | data); + + } + else { + temp = (((unsigned int)(regAddr | 0x80) << 8) | 0xFF); + } + + return SSP0_write(temp, SMB380_ACC); +} + +unsigned char SSP0_write(const uint16_t data, uint8_t device) +{ + unsigned char ret = 1; + + while ((SSP0SR & (SSPSR_TNF | SSPSR_BSY)) != SSPSR_TNF) + ; + + if (!USE_CS) { + switch (device) { + case BMA180_INTERN: + case SMB380_ACC: { + FIO1CLR = SSP0_SEL; + break; + } + + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: { + printf("[%s] line: %d\n", __FUNCTION__, __LINE__); + FIO0CLR = SSP0_SELN; + break; + } + + case ACAMDMS: + case NORDIC: + //Chip Select is done in Nordic driver + break; + + default: + ret = 0; + goto ret; + } + } + + SSP0DR = data; + + if (!USE_CS) { + while (SSP0SR & SSPSR_BSY) + ; + + switch (device) { + case BMA180_INTERN: + case SMB380_ACC: { + FIO1SET = SSP0_SEL; + break; + } + + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: { + FIO0SET = SSP0_SELN; + break; + } + + case ACAMDMS: + case NORDIC: + //Chip Select is done in Nordic driver + break; + + default: + ret = 0; + goto ret; + } + } + +ret: + return ret; +} + +unsigned short SSP0_read(uint8_t device) +{ + uint16_t data; + + while (!(SSP0SR & SSPSR_RNE)) + ; + + if (!USE_CS) { + switch (device) { + case BMA180_INTERN: + case SMB380_ACC: { + FIO1CLR = SSP0_SEL; + break; + } + + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: { + FIO0CLR = SSP0_SELN; + break; + } + + case NORDIC: + case ACAMDMS: + //Chip Select is done in Nordic driver + break; + + default: + data = 0xFFFF; + goto ret; + } + } + + data = SSP0DR; + + if (!USE_CS) { + switch (device) { + case BMA180_INTERN: + case SMB380_ACC: { + FIO1SET = SSP0_SEL; + break; + } + + case BMA180_EXTERN: + case L3G_EXTERN: + case NANOPAN: { + FIO0SET = SSP0_SELN; + break; + } + + case ACAMDMS: + case NORDIC: + //Chip Select is done in Nordic driver + break; + + default: + data = 0xFFFF; + goto ret; + } + } + +ret: + return data; +} + +unsigned short SMB380_ssp_read(void) +{ + return SSP0_read(SMB380_ACC); +} + +unsigned short nrf24l01_ssp_read_write(const uint8_t data) +{ + SSP0_write(data, NORDIC); + return SSP0_read(NORDIC); +} + +unsigned short acam_trx(const uint8_t data) +{ + SSP0_write(data, ACAMDMS); + return SSP0_read(ACAMDMS); +} + diff --git a/avsextrem/include/board.h b/avsextrem/include/board.h index 11da670e0e..f8960c2dac 100644 --- a/avsextrem/include/board.h +++ b/avsextrem/include/board.h @@ -1,20 +1,23 @@ -/** - * @ingroup conf - * @ingroup avsextrem - * - * @{ - */ +/* +* board.h - Definitions for the AVSEXTREM board configuration. +* Copyright (C) 2013 Heiko Will +* +* This source code is licensed under the LGPLv2 license, +* See the file LICENSE for more details. +* +*/ + /** * @file - * @brief avsextrem board configuration + * @brief avsextrem board configuration * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author baar - * @author Zakaria Kasmi + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author baar + * @author Zakaria Kasmi * @version $Revision: 1127 $ * - * @note $Id: board-conf.h 1127 2009-05-13 08:48:29Z baar $ + * @note $Id: board-conf.h 1127 2013-06-13 08:48:29Z baar $ */ @@ -23,7 +26,7 @@ #include -#define FEUERWARE_CONF_BOARD_NAME "FU Berlin AVSEXTREM BOARD" +#define FEUERWARE_CONF_BOARD_NAME "FU Berlin AVSEXTREM BOARD" #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) @@ -47,7 +50,7 @@ // if FAT is enabled this board supports files #define FEUERWARE_CONF_CORE_SUPPORTS_FILES defined(MODULE_FAT) -#ifdef MODULE_FAT +#ifdef MODULE_FAT #define CFG_CONF_MEM_SIZE 0x7FFFFFFF #define SYSLOG_CONF_NUM_INTERFACES 2 #else diff --git a/avsextrem/include/configure.h b/avsextrem/include/configure.h index f12f3e1b89..6088a0ad32 100644 --- a/avsextrem/include/configure.h +++ b/avsextrem/include/configure.h @@ -1,28 +1,23 @@ -/****************************************************************************** -Copyright 2009, Freie Universitaet Berlin (FUB). All rights reserved. +/* +* avsextrem-cc1100.c - CC100 Transceiver Driver for the AVSEXTREM-BOARD. +* Copyright (C) 2013 Heiko Will +* +* This source code is licensed under the LGPLv2 license, +* See the file LICENSE for more details. +* +*/ -These sources were developed at the Freie Universitaet Berlin, Computer Systems -and Telematics group (http://cst.mi.fu-berlin.de). -------------------------------------------------------------------------------- -This file is part of FeuerWare. - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -FeuerWare is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see http://www.gnu.org/licenses/ . --------------------------------------------------------------------------------- -For further information and questions please use the web site - http://scatterweb.mi.fu-berlin.de -and the mailinglist (subscription via web site) - scatterweb@lists.spline.inf.fu-berlin.de -*******************************************************************************/ +/** + * @file + * @brief definitions for the avsextrem board configuration + * + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author baar + * @author Zakaria Kasmi + * @version $Revision: 1127 $ + * + * @note $Id: board-conf.h 1127 2013-06-13 08:48:29Z baar $ + */ #ifndef CONFIGURE_H_ #define CONFIGURE_H_ @@ -60,11 +55,11 @@ and the mailinglist (subscription via web site) #include "cpu-conf.h" #ifdef MODULE_SYSMON - #ifndef TRACELOG_CONF_NUM_ENTRIES - #define TRACELOG_CONF_NUM_ENTRIES 10 - #endif +#ifndef TRACELOG_CONF_NUM_ENTRIES +#define TRACELOG_CONF_NUM_ENTRIES 10 +#endif #else - #undef TRACELOG_CONF_NUM_ENTRIES +#undef TRACELOG_CONF_NUM_ENTRIES #endif diff --git a/avsextrem/include/smb380-board.h b/avsextrem/include/smb380-board.h index a45e38a893..4a92cf5b53 100644 --- a/avsextrem/include/smb380-board.h +++ b/avsextrem/include/smb380-board.h @@ -1,22 +1,23 @@ /* - * msba2acc-smb380.h - header file of the Driver for the SMB380 acceleration sensor. - * Copyright (C) 2013 Freie Universität Berlin + * smb380-board.h - definitions of the Driver for the SMB380 acceleration sensor. + * Copyright (C) 2013 Freie Universität Berlin + * + * This source code is licensed under the LGPLv2 license, + * See the file LICENSE for more details. * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. */ /** * @file * @internal - * @brief SMB380 acceleration sensor definitions for the LPC2387 + * @brief SMB380 acceleration sensor definitions for the LPC2387 * - * @author Freie Universität Berlin, Computer Systems & Telematics - * @author Marco Ziegert - * @author Zakaria Kasmi + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi * @version $Revision: 3854 $ * - * @note $Id: msba2acc-smb380.h 3854 2010-01-18 15:27:01Z zkasmi $ + * @note $Id: msba2acc-smb380.h 3854 2013-06-19 17:33:01Z zkasmi $ * */ @@ -35,12 +36,12 @@ #define LPM_PREVENT_SLEEP_ACCSENSOR BIT2 -enum SMB380_MODE{ - SMB380_POLL, - SMB380_POLL_AFTER_CONTINOUS, - SMB380_CONTINOUS, - SMB380_THRESHOLD, - SMB380_FALSEALERT +enum SMB380_MODE { + SMB380_POLL, + SMB380_POLL_AFTER_CONTINOUS, + SMB380_CONTINOUS, + SMB380_THRESHOLD, + SMB380_FALSEALERT }; //volatile enum SMB380_MODE volatile enum SMB380_MODE smb380_mode;// = SMB380_POLL; @@ -165,27 +166,27 @@ volatile enum SMB380_MODE smb380_mode;// = SMB380_POLL; void SMB380_update_image(void); /* change from Header (public) to internal use (private) - * set ee_w Bit in control1 to + * set ee_w Bit in control1 to * enable read to 0x16 to 0x22 and * enable write to 0x16 to 0x3D */ void SMB380_enable_eeprom_default(void); -uint8_t SMB380_HystereseFunctionSample(int16_t* value); //Example Hysterese functon +uint8_t SMB380_HystereseFunctionSample(int16_t *value); //Example Hysterese functon // simple api for single-sample, single thread interrupt mode uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t range); -uint8_t SMB380_init(uint8_t (*func)(int16_t*)); // enables Interrupts (normally only once called) +uint8_t SMB380_init(uint8_t (*func)(int16_t *)); // enables Interrupts (normally only once called) void SMB380_setSampleRate(uint16_t rate); uint16_t SMB380_getSampleRate(void); void freeRingReadPointer(void); void actualizeRingReadPointer(void); -uint8_t readRingBuff(int16_t* value); -uint8_t writeRingBuff(int16_t* value); +uint8_t readRingBuff(int16_t *value); +uint8_t writeRingBuff(int16_t *value); void SMB380_activateDynRangeSet(uint8_t activate); -uint8_t checkRange(int16_t* value); +uint8_t checkRange(int16_t *value); void SMB380_enableEEPROM(void); void SMB380_disableEEPROM(void); @@ -231,4 +232,4 @@ void SMB380_ShowMemory(void); void SMB380_Selftest_1(void); -#endif /* SMB380_H_ */ +#endif /* SMB380_H_ */ diff --git a/avsextrem/include/ssp0-board.h b/avsextrem/include/ssp0-board.h index 4145a2f6e5..6c7b0907fe 100644 --- a/avsextrem/include/ssp0-board.h +++ b/avsextrem/include/ssp0-board.h @@ -1,22 +1,23 @@ /* * ssp0-borad.h - header file of the SPI interface for the LPC2387. - * Copyright (C) 2013 Freie Universität Berlin + * Copyright (C) 2013 Freie Universität Berlin + * + * This source code is licensed under the LGPLv2 license, + * See the file LICENSE for more details. * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. */ /** * @file * @internal - * @brief SPI interface definitions for the LPC2387 + * @brief SPI interface definitions for the LPC2387 * - * @author Freie Universität Berlin, Computer Systems & Telematics - * @author Marco Ziegert - * @author Zakaria Kasmi + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi * @version $Revision: 3854 $ * - * @note $Id: avsextrem-ssp0.c 3854 2010-01-18 15:27:01Z zkasmi $ + * @note $Id: avsextrem-ssp0.c 3854 2010-01-18 15:27:01Z zkasmi $ */ #ifndef __SSP_H__ #define __SSP_H__ @@ -94,8 +95,8 @@ #define SMB380_EXTINT_MODE 1 #define BMA180_EXTINT_MODE 1 -uint32_t SSP0Init( void ); -uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol,uint8_t cpha, uint16_t freq); +uint32_t SSP0Init(void); +uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, uint16_t freq); uint8_t SSP0Unprepare(uint8_t chip); unsigned char SSP0_write(const uint16_t data, uint8_t device); unsigned short SSP0_read(uint8_t device); diff --git a/avsextrem/include/type.h b/avsextrem/include/type.h deleted file mode 100644 index d2098f25ad..0000000000 --- a/avsextrem/include/type.h +++ /dev/null @@ -1,31 +0,0 @@ -/***************************************************************************** - * type.h: Type definition Header file for NXP LPC230x Family Microprocessors - * - * Copyright(C) 2006, NXP Semiconductor - * All rights reserved. - * - * History - * 2006.09.01 ver 1.00 Prelimnary version, first Release - * -******************************************************************************/ -#ifndef __TYPE_H__ -#define __TYPE_H__ - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef TRUE -#define TRUE (1) -#endif - -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; -typedef unsigned int BOOL; - -#endif /* __TYPE_H__ */ From 93c153a37f9b6b4f000c3d8f563c7509a98ce1ad Mon Sep 17 00:00:00 2001 From: Zakaria Kasmi Date: Thu, 19 Sep 2013 16:53:35 +0200 Subject: [PATCH 172/188] fixed encoding and coding conventions --- avsextrem/Makefile | 6 +- avsextrem/board_init.c | 84 ++++----- avsextrem/drivers/avsextrem-cc1100.c | 51 +++--- avsextrem/drivers/avsextrem-smb380.c | 263 +++++++++++++-------------- avsextrem/drivers/avsextrem-ssp0.c | 103 ++++++----- avsextrem/include/board.h | 22 +-- avsextrem/include/configure.h | 21 +-- avsextrem/include/smb380-board.h | 139 ++++++++------ avsextrem/include/ssp0-board.h | 23 ++- msba2-common/Makefile | 2 +- msba2-common/board_common_init.c | 5 +- msba2-common/board_config.c | 11 +- msba2-common/lpc2387-timer3.c | 26 +-- msba2/board_init.c | 9 +- 14 files changed, 375 insertions(+), 390 deletions(-) diff --git a/avsextrem/Makefile b/avsextrem/Makefile index 0340a2a81b..3597e18c73 100644 --- a/avsextrem/Makefile +++ b/avsextrem/Makefile @@ -10,7 +10,7 @@ INCLUDES += -I$(RIOTBASE)/cpu/arm_common/include/ INCLUDES += -I$(RIOTBASE)/cpu/lpc2387/include/ INCLUDES += -I$(RIOTBASE)/drivers/cc110x -all: $(BINDIR)$(ARCH) +all: $(BINDIR)$(ARCH) "$(MAKE)" -C ../msba2-common "$(MAKE)" -C drivers @@ -34,7 +34,5 @@ clean: rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) @if [ -d $(BINDIR) ] ; \ then rmdir $(BINDIR) ; \ - fi - - + fi diff --git a/avsextrem/board_init.c b/avsextrem/board_init.c index ce1cc57933..419198da9a 100644 --- a/avsextrem/board_init.c +++ b/avsextrem/board_init.c @@ -8,16 +8,11 @@ */ -/** - * @ingroup avsextrem - * @{ - */ - /** * @file * @brief avsextrem board initialization * - * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Freie Universität Berlin, Computer Systems & Telematics * @author Heiko Will * @author Kaspar Schleise * @author Michael Baar @@ -25,7 +20,7 @@ * @author Marco Ziegert * @author Stefan Pfeiffer * - * @note $Id: board_init.c 1071 2013-08-14 10:15:56Z hwill $ + * @note $Id: board_init.c 1071 2013-09-19 16:50:56 kasmi $ */ #include "lpc23xx.h" #include "VIC.h" @@ -51,24 +46,25 @@ void init_clks1(void) PLLCON &= ~0x0002; pllfeed(); - while (PLLSTAT & BIT25); // wait until PLL is disconnected before disabling - deadlock otherwise + while (PLLSTAT & BIT25); /* wait until PLL is disconnected before + * disabling - deadlock otherwise */ // Disable PLL PLLCON &= ~0x0001; pllfeed(); - while (PLLSTAT & BIT24); // wait until PLL is disabled + while (PLLSTAT & BIT24); // wait until PLL is disabled - SCS |= 0x10; // main OSC between 15MHz and 24MHz (more stable in tests) - SCS |= 0x20; // Enable main OSC + SCS |= 0x10; // main OSC between 15MHz and 24MHz (more stable in tests) + 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; // Setting Multiplier and Divider values - PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz + PLLCFG = 0x0008; // M=9 N=1 Fcco = 288 MHz pllfeed(); // Enabling the PLL */ @@ -76,20 +72,20 @@ void init_clks1(void) pllfeed(); /* Set clock divider to 4 (value+1) */ - CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz + CCLKCFG = CL_CPU_DIV - 1; // Fcpu = 72 MHz #if USE_USB - USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ + USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ #endif } /*---------------------------------------------------------------------------*/ void bl_init_ports(void) { - SCS |= BIT0; // Set IO Ports to fast switching mode + SCS |= BIT0; // Set IO Ports to fast switching mode /* UART0 */ - PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 + PINSEL0 |= BIT4 + BIT6; // RxD0 and TxD0 PINSEL0 &= ~(BIT5 + BIT7); //PTTU: @@ -114,29 +110,30 @@ void bl_init_ports(void) // /* Disable Resistors on LED - and Ports to output*/ - PINMODE7 |= BIT19 + BIT21; //3.25 + 3.26 - PINMODE2 |= BIT1; //1.0 + PINMODE7 |= BIT19 + BIT21; //3.25 + 3.26 + PINMODE2 |= BIT1; //1.0 FIO1DIR |= BIT0; FIO3DIR |= BIT25 + BIT26; - FIO1SET = BIT0; //all off + FIO1SET = BIT0; //all off 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; // ** + // FIO1CLR = BIT22; // PA /Shutdown + // Important: First put this Port as DA 2.0V and then turn on PA!! + // FIO0DIR |= BIT26; + // FIO0SET = BIT26; // 1.22 + 1.25 + 1.26 // Configure GPS - PINMODE3 |= BIT3 + BIT7; // No Pullup on 1.17 & 1.19 + PINMODE3 |= BIT3 + BIT7; // No Pullup on 1.17 & 1.19 PINMODE9 |= BIT27 + BIT25; // No Pullup for Uart FIO1DIR |= BIT17; - FIO1CLR = BIT17; // Turn off GPS + FIO1CLR = BIT17; // Turn off GPS FIO1DIR |= BIT19; - FIO1CLR = BIT19; // Hold in Reset + FIO1CLR = BIT19; // Hold in Reset PINSEL9 |= BIT24 + BIT25 + BIT26 + BIT27; //4.28 & 4.29 as Uart3 // Nanotron @@ -148,7 +145,7 @@ void bl_init_ports(void) FIO1DIR &= ~BIT4; // nanotron Rx/Tx as input FIO1CLR = BIT15; - FIO1CLR = BIT9; // Enable power + FIO1CLR = BIT9; // Enable power PINMODE1 |= BIT1; // No Pullup for CS FIO0DIR |= BIT16; // CS as output @@ -157,7 +154,7 @@ void bl_init_ports(void) // RFID // FIO1DIR |= BIT1; // RFID Power - // FIO1CLR = BIT1; // + // FIO1CLR = BIT1; // // FIO0DIR |= BIT1; // RFID Reset // FIO0SET = BIT1; // Hold in Reset @@ -177,7 +174,7 @@ void bl_init_ports(void) // 0.23 + 0.24 // Battery Voltage (AD) - PINMODE1 |= BIT19; //0.25 + PINMODE1 |= BIT19; //0.25 PINSEL1 &= ~BIT19; PINSEL1 |= BIT18; @@ -187,36 +184,19 @@ void bl_init_ports(void) FIO0SET = BIT7 + BIT9; //SMB380 - FIO1DIR |= BIT20 + BIT21 + BIT24; //SCK + CSB + SDI + FIO1DIR |= BIT20 + BIT21 + BIT24; //SCK + CSB + SDI FIO1SET = BIT21; FIO1SET = BIT20 + 24; //SHT11 - FIO1DIR |= BIT25; //1.25 + FIO1DIR |= BIT25; //1.25 PINSEL3 &= ~(BIT12 | BIT13 | BIT18 | BIT19); //SD - FIO0DIR &= ~(BIT19 | BIT20 | BIT21 | BIT22) ; //0.19 0.20 0.21 0.22 as input - PINMODE1 |= (BIT7) | (BIT9) | (BIT11) | (BIT13); // no resistors - FIO2DIR &= ~(BIT11 + BIT12 + BIT13); //2.11 2.12 2.13 as input - PINMODE4 |= (BIT23) | (BIT25) | (BIT27); // no resistors + FIO0DIR &= ~(BIT19 | BIT20 | BIT21 | BIT22) ; //0.19 0.20 0.21 0.22 as input + PINMODE1 |= (BIT7) | (BIT9) | (BIT11) | (BIT13); // no resistors + FIO2DIR &= ~(BIT11 + BIT12 + BIT13); //2.11 2.12 2.13 as input + PINMODE4 |= (BIT23) | (BIT25) | (BIT27); // no resistors - //Tetra - // FIO2DIR |= BIT0 + BIT7; - // 2.0 bis 2.7 - - // No Pullups on any port - // Does not work, needs more current than pull-ups - // 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/avsextrem/drivers/avsextrem-cc1100.c b/avsextrem/drivers/avsextrem-cc1100.c index da0da6aac8..ee83ebbd90 100644 --- a/avsextrem/drivers/avsextrem-cc1100.c +++ b/avsextrem/drivers/avsextrem-cc1100.c @@ -13,7 +13,7 @@ * @ingroup LPC2387 * @brief CC1100 LPC2387 dependend functions * - * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Freie Universität Berlin, Computer Systems & Telematics * @author Heiko Will * @author Thomas Hillebrandt * @author Zakaria Kasmi @@ -33,16 +33,16 @@ #include "cc1100_spi.h" #include "gpioint.h" -#define CC1100_GDO0 (FIO2PIN & BIT6) // read serial I/O (GDO0) -#define CC1100_GDO1 (FIO0PIN & BIT8) // read serial I/O (GDO1) -#define CC1100_GDO2 (FIO0PIN & BIT28) // read serial I/O (GDO2) +#define CC1100_GDO0 (FIO2PIN & BIT6) // read serial I/O (GDO0) +#define CC1100_GDO1 (FIO0PIN & BIT8) // read serial I/O (GDO1) +#define CC1100_GDO2 (FIO0PIN & BIT28) // read serial I/O (GDO2) -#define SPI_TX_EMPTY (SSP1SR & SSPSR_TFE) -#define SPI_BUSY (SSP1SR & SSPSR_BSY) -#define SPI_RX_AVAIL (SSP1SR & SSPSR_RNE) +#define SPI_TX_EMPTY (SSP1SR & SSPSR_TFE) +#define SPI_BUSY (SSP1SR & SSPSR_BSY) +#define SPI_RX_AVAIL (SSP1SR & SSPSR_RNE) -#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 +#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 //#define DEBUG @@ -73,17 +73,17 @@ static int test_time(int code) int cc1100_get_gdo0(void) { - return CC1100_GDO0; + return CC1100_GDO0; } int cc1100_get_gdo1(void) { - return CC1100_GDO1; + return CC1100_GDO1; } int cc1100_get_gdo2(void) { - return CC1100_GDO2; + return CC1100_GDO2; } void cc1100_spi_init(void) @@ -93,14 +93,14 @@ void cc1100_spi_init(void) FIO0SET = BIT6; // Power - PCONP |= PCSSP1; // Enable power for SSP1 (default is on) + PCONP |= PCSSP1; // Enable power for SSP1 (default is on) // PIN Setup - PINSEL0 |= BIT15; // Set CLK function to SSP1 + PINSEL0 |= BIT15; // Set CLK function to SSP1 PINSEL0 &= ~BIT14; - PINSEL0 |= BIT17 ; // Set MISO function to SSP1 + PINSEL0 |= BIT17 ; // Set MISO function to SSP1 PINSEL0 &= ~BIT16; - PINSEL0 |= BIT19; // Set MOSI function to SSP1 + PINSEL0 |= BIT19; // Set MOSI function to SSP1 PINSEL0 &= ~BIT18; // Interface Setup SSP1CR0 = 7; @@ -109,17 +109,17 @@ void cc1100_spi_init(void) uint32_t pclksel; uint32_t cpsr; lpc2387_pclk_scale(F_CPU / 1000, 6000, &pclksel, &cpsr); - PCLKSEL0 &= ~(BIT21 | BIT20); // CCLK to PCLK divider + PCLKSEL0 &= ~(BIT21 | BIT20); // CCLK to PCLK divider PCLKSEL0 |= pclksel << 20; SSP1CPSR = cpsr; // Enable - SSP1CR1 |= BIT1; // SSP-Enable + SSP1CR1 |= BIT1; // SSP-Enable int dummy; // Clear RxFIFO: - while (SPI_RX_AVAIL) { // while RNE (Receive FIFO Not Empty)... - dummy = SSP1DR; // read data + while (SPI_RX_AVAIL) { // while RNE (Receive FIFO Not Empty)... + dummy = SSP1DR; // read data } } @@ -173,7 +173,7 @@ cc1100_spi_select(void) volatile int retry_count = 0; volatile int abort_count; // Switch to GDO mode input - PINSEL0 &= ~(BIT17 + BIT16);// Set MISO function to GPIO + PINSEL0 &= ~(BIT17 + BIT16); // Set MISO function to GPIO FIO0DIR &= ~BIT8; cs_low: // CS to low @@ -195,8 +195,8 @@ loop: goto final; } - FIO0SET = BIT6; // CS to high - goto cs_low; // try again + FIO0SET = BIT6; // CS to high + goto cs_low; // try again } goto loop; @@ -204,7 +204,7 @@ loop: final: // Switch to SPI mode - PINSEL0 |= BIT17; // Set MISO function to SSP1 + PINSEL0 |= BIT17; // Set MISO function to SSP1 PINSEL0 &= ~BIT16; } @@ -246,9 +246,6 @@ void cc1100_gdo0_disable(void) gpioint_set(2, BIT6, GPIOINT_DISABLE, NULL); } - - - void cc1100_init_interrupts(void) { // Enable external interrupt on low edge (for GDO2) diff --git a/avsextrem/drivers/avsextrem-smb380.c b/avsextrem/drivers/avsextrem-smb380.c index 73d5a49be2..5cc084f73d 100644 --- a/avsextrem/drivers/avsextrem-smb380.c +++ b/avsextrem/drivers/avsextrem-smb380.c @@ -1,7 +1,7 @@ /* * msba2acc-smb380.c - implementation of the Driver for the SMB380 acceleration * sensor on the AVSEXTREM board. - * Copyright (C) 2013 Freie Universität Berlin + * Copyright (C) 2013 Freie Universität Berlin * * This source code is licensed under the LGPLv2 license, * See the file LICENSE for more details. @@ -11,10 +11,10 @@ /** * @file * @internal - * @brief SMB380 acceleration sensor driver for the LPC2387 on the + * @brief SMB380 acceleration sensor driver for the LPC2387 on the * AVSEXTREM board. * - * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Freie Universität Berlin, Computer Systems & Telematics * @author Marco Ziegert * @author Zakaria Kasmi * @version $Revision: 3854 $ @@ -23,7 +23,7 @@ */ -#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ +#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ #include "cpu.h" #include "lpm.h" //#include "PatrecInit.h" @@ -45,22 +45,6 @@ #include "math.h" #include "lpc2387.h" -/* program example - * - * - * - * -SMB380_init(); //Initializes SPI and the SMB380 accelerator sensor -SMB380_setRange(SMB380_RANGE_8G); -//SMB380_setBandWidth(SMB380_BAND_WIDTH_100HZ); -SMB380_enableNewDataInt(); - -while ( readRingBuff(accInt) ) { - printf("[%4i|%4i|%4i|%4i]\r\n", accInt[0], accInt[1], accInt[2], accInt[3]); - ktimer_wait(KTIMER_TICKS(1000000)); - //actualizeRingReadPointer(); //update read-pointer position to a current measurement (drop unread ones) -} -*/ uint8_t simple_pid; int16_t simple_buffer[4]; @@ -73,24 +57,30 @@ uint16_t readPointerPos[SMB380_RING_BUFF_MAX_THREADS]; u_char PointerList[SMB380_RING_BUFF_MAX_THREADS]; static msg_t wakeupmessage; -uint8_t (*smb380function)(int16_t *); //pointer to a user-defined function which is called during a writepointer action - -uint16_t sampleRateSMB380; - -bool dynRange = false; //condition if range-check should be done +/* + * pointer to a user-defined function which is called during a writepointer + * action + */ +uint8_t (*smb380function)(int16_t *); +uint16_t sampleRateSMB380; // condition if range-check should be done +bool dynRange = false; uint8_t counter_Decreasing = 0; volatile uint16_t interruptTicksSMB380; typedef struct { - u_int writePointerPos; //Writepointer position - uint8_t countRange; //check value for updated range settings (only needed for multiplication in Float-mode - uint8_t range; //current range + u_int writePointerPos; //Writepointer position + /* + * check value for updated range settings (only needed for multiplication + * in Float-mode + */ + uint8_t countRange; + uint8_t range; //current range } settingsSMB380; settingsSMB380 settings; -/* measuring temperature dependent internal sample rate of SMB380 */ +// measuring temperature dependent internal sample rate of SMB380 static volatile uint32_t tickStart = 0; static volatile uint32_t tickLastSample = 0; static volatile uint32_t tickCurrentSamples = 0; @@ -105,7 +95,8 @@ extern unsigned long ktimer_now(void); float SMB380_getSampleRatio(void) { - return ((1.0 / ((float)(tickLastSample - tickStart) / tickCurrentSamples)) * 100000) /*/ (float)(SMB380_SAMPLE_RATE_MAX / sampleRateSMB380)*/; + return ((1.0 / ((float)(tickLastSample - tickStart) / tickCurrentSamples)) * + 100000); } uint8_t smb380emptyfunction(int16_t *value) @@ -119,7 +110,7 @@ uint8_t SMB380_HystereseFunctionSample(int16_t *value) static uint8_t counter = 0; int16_t delta = abs(value[0] - x) + abs(value[1] - y) + abs(value[2] - z); - if (delta < 40) { //TODO: delta and counter are constant values, change it! + if (delta < 40) { //TODO: delta and counter are constant values, change it! counter++; } else { @@ -142,14 +133,14 @@ uint8_t SMB380_HystereseFunctionSample(int16_t *value) //SMB380_setAnyMotionLimit(100,0); SMB380_enableAnyMotionLimit(); smb380_mode = SMB380_THRESHOLD; - counter = 0; //n�tig? + counter = 0; } else if (counter == 100) { SMB380_disableNewDataInt(); //SMB380_setAnyMotionLimit(100,0); SMB380_enableAnyMotionLimit(); smb380_mode = SMB380_FALSEALERT; - counter = 0; //n�tig? + counter = 0; return 0; } @@ -179,7 +170,8 @@ static void SMB380_simple_interrupthandler(void) } // enables simple Interrupt driven Mode -uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t range) +uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t + range) { SSP0Init(); interruptTicksSMB380 = 0; @@ -215,7 +207,7 @@ uint8_t SMB380_init(uint8_t (*func)(int16_t *)) smb380function = smb380emptyfunction; } - //smb380function = SMB380_HystereseFunctionSample; //Platzhalter + //smb380function = SMB380_HystereseFunctionSample; //placeholder SMB380_softReset(); hwtimer_wait(HWTIMER_TICKS(100000)); @@ -223,7 +215,7 @@ uint8_t SMB380_init(uint8_t (*func)(int16_t *)) SMB380_disableLowerLimit(); smb380_mode = SMB380_POLL; - SMB380_setSampleRate(SMB380_SAMPLE_RATE_MAX); //set output to 3000 Hz + SMB380_setSampleRate(SMB380_SAMPLE_RATE_MAX); //set output to 3000 Hz settings.writePointerPos = 0; settings.range = 0; @@ -239,7 +231,8 @@ uint8_t SMB380_init(uint8_t (*func)(int16_t *)) ringBuff_Z = (int16_t *)malloc(SMB380_RING_BUFF_SIZE * sizeof(int16_t)); ringBuff_T = (int16_t *)malloc(SMB380_RING_BUFF_SIZE * sizeof(int16_t)); - if ((ringBuff_X == NULL) | (ringBuff_Y == NULL) | (ringBuff_Z == NULL) | (ringBuff_T == NULL)) { + if ((ringBuff_X == NULL) | (ringBuff_Y == NULL) | (ringBuff_Z == NULL) | + (ringBuff_T == NULL)) { if (ringBuff_X != NULL) { free((int16_t *)ringBuff_X); } @@ -276,8 +269,10 @@ static void SMB380_extIntHandler(void) writeRingBuff(accInt); - // printf("SMB380 acc x,y,z: [%i|%i|%i|%2.3f]\r\n", accInt[0], accInt[1], accInt[2], acc[3]); - // printf("SMB380 acc x,y,z: [%2.3f|%2.3f|%2.3f|%2.3f]\r\n\n\n", acc[0], acc[1], acc[2], acc[3]); + // printf("SMB380 acc x,y,z: [%i|%i|%i|%2.3f]\r\n", accInt[0], accInt[1], + // accInt[2], acc[3]); + // printf("SMB380 acc x,y,z: [%2.3f|%2.3f|%2.3f|%2.3f]\r\n\n\n", acc[0], + // acc[1], acc[2], acc[3]); // printf("Nach Interrupt Reset:\n"); // SMB380_ShowMemory(); } @@ -307,12 +302,13 @@ uint8_t SMB380_Unprepare(void) return SSP0Unprepare(SMB380_ACC); } -/* return the pointerNo related with the current thread */ +// return the pointerNo related with the current thread uint8_t getRingReadPointerforCurrentThread(void) { uint8_t pointerNo = 0; - while ((PointerList[pointerNo] != active_thread->pid) && (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { + while ((PointerList[pointerNo] != active_thread->pid) && + (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { pointerNo++; } @@ -321,10 +317,11 @@ uint8_t getRingReadPointerforCurrentThread(void) uint8_t initRingReadPointerforCurrentThread(void) { - //TODO make it Threadsafe + //TODO: make it Threadsafe uint8_t pointerNo = 0; - while ((PointerList[pointerNo] > 0) && (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { + while ((PointerList[pointerNo] > 0) && + (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { pointerNo++; } @@ -357,36 +354,21 @@ void actualizeRingReadPointer(void) } } -//TODO more read-pointer +//TODO: more read-pointer uint8_t readRingBuff(int16_t *value) { - // if ( inISR() ) { - // if ( readPointerPos[pointerNo] == settings.writePointerPos ) - // return 0; - // } else { - // while ( readPointerPos[pointerNo] != settings.writePointerPos ) { - // uint8_t x = 254; - //// while ( x ) - //// x--; - // } - // } - - // zugriff auf pid - // if (getRead fk_thread->pid kenn ich schon) - // { - // pointerno[pid]; - // } - // else - // { - // initRingReadPointerforCurrentThread(); - // } uint8_t pointerNo = getRingReadPointerforCurrentThread(); - // If thread is not known to read on the ringbuffer, try adding him to the list of known threads, otherwise exit with error + /* + * If thread is not known to read on the ringbuffer, try adding him to the + * list of known threads, otherwise exit with error + */ + if (pointerNo == SMB380_RING_BUFF_MAX_THREADS) { if (!initRingReadPointerforCurrentThread()) { - //printf("%sNo Readpointer left, maximum of %u is reached!\n\r", SMB380_DEBUG_MESSAGE, SMB380_RING_BUFF_MAX_THREADS); + //printf("%sNo Readpointer left, maximum of %u is reached!\n\r", + // SMB380_DEBUG_MESSAGE, SMB380_RING_BUFF_MAX_THREADS); return 0; } else { @@ -415,7 +397,7 @@ uint8_t readRingBuff(int16_t *value) return 1; } -//TODO more read-pointer +//TODO: more read-pointer uint8_t writeRingBuff(int16_t *value) { if (smb380_mode == SMB380_FALSEALERT) { @@ -423,7 +405,8 @@ uint8_t writeRingBuff(int16_t *value) return 0; } - if ((interruptTicksSMB380 >= sampleRateSMB380 - 1) || (smb380_mode == SMB380_THRESHOLD)) { + if ((interruptTicksSMB380 >= sampleRateSMB380 - 1) || + (smb380_mode == SMB380_THRESHOLD)) { interruptTicksSMB380 = 0; /* measuring temperature dependent internal sample rate of SMB380 */ @@ -583,7 +566,8 @@ void wakeUpRegisteredProcesses(void) //wake up waiting processes wakeupmessage.type = MSG_TYPE_SMB380_WAKEUP; - while ((PointerList[pointerNo] > 0) && (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { + while ((PointerList[pointerNo] > 0) && + (pointerNo < SMB380_RING_BUFF_MAX_THREADS)) { msg_send(&wakeupmessage, PointerList[pointerNo], false); pointerNo++; } @@ -819,7 +803,8 @@ void SMB380_softReset(void) unsigned char ur; unsigned long cpsr = disableIRQ(); SMB380_Prepare(); - SMB380_ssp_write(SMB380_CONTROL1, SMB380_CONTROL1_SOFT_RESET_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL1, SMB380_CONTROL1_SOFT_RESET_MASK, + SMB380_WRITE_REGISTER); ur = ((unsigned char)SMB380_ssp_read()) & SMB380_CONTROL1_SOFT_RESET_MASK; SMB380_Unprepare(); restoreIRQ(cpsr); @@ -848,9 +833,7 @@ unsigned char SMB380_getCustomerReg(void) return uReg; } -/* Selftest - * - * */ +// Selftest void SMB380_Selftest_1(void) { unsigned char uReg = 0; @@ -912,7 +895,7 @@ void SMB380_setUpperLimit(void) { unsigned long cpsr = disableIRQ(); SMB380_Prepare(); - SMB380_ssp_write(SMB380_HG_THRES, 128, SMB380_WRITE_REGISTER); //1g + SMB380_ssp_write(SMB380_HG_THRES, 128, SMB380_WRITE_REGISTER); //1g SMB380_ssp_read(); SMB380_ssp_write(SMB380_HG_DUR, 0, SMB380_WRITE_REGISTER); SMB380_ssp_read(); @@ -927,7 +910,8 @@ void SMB380_enableUpperLimit(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_HG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_HG_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); @@ -940,7 +924,8 @@ void SMB380_disableUpperLimit(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_HG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_HG_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); @@ -953,7 +938,8 @@ void SMB380_enableLowerLimit(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_LG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ENABLE_LG_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); @@ -966,7 +952,8 @@ void SMB380_disableLowerLimit(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_LG_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ENABLE_LG_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); @@ -985,7 +972,8 @@ uint8_t SMB380_setAnyMotionLimit(uint16_t mg, uint16_t gvalueint) threshold = mg / (15.6 * (SMB380_getRange() / 2)); } else if (gvalueint != 0) { - threshold = ceil(((gvalueint * 2000) / 512.0) / 15.6); //Scaling for different gRanges is not needed + /* Scaling for different gRanges is not needed */ + threshold = ceil(((gvalueint * 2000) / 512.0) / 15.6); } else { return 0; @@ -994,13 +982,12 @@ uint8_t SMB380_setAnyMotionLimit(uint16_t mg, uint16_t gvalueint) unsigned short uReg; unsigned long cpsr = disableIRQ(); SMB380_Prepare(); - SMB380_ssp_write(SMB380_ANY_MOTION_THRES, threshold, SMB380_WRITE_REGISTER); //0,3g = 300 / 15,6mg = 19 + /* 0,3g = 300 / 15,6mg = 19 */ + SMB380_ssp_write(SMB380_ANY_MOTION_THRES, threshold, SMB380_WRITE_REGISTER); SMB380_ssp_read(); //Set duration at this point SMB380_ssp_write(SMB380_ANY_MOTION_DUR_HYST, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - // SMB380_ssp_write(SMB380_ANY_MOTION_DUR_HYST, (uReg & ~SMB380_ANY_MOTION_DUR_MASK) | 0x40, SMB380_WRITE_REGISTER); - // SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); return 1; @@ -1013,11 +1000,13 @@ void SMB380_enableAnyMotionLimit(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_ENABLE_ADV_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_ENABLE_ADV_INT_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ANY_MOTION_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL2, uReg | SMB380_CONTROL2_ANY_MOTION_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); @@ -1030,11 +1019,15 @@ void SMB380_disableAnyMotionLimit(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL2, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL2, uReg & ~SMB380_CONTROL2_ANY_MOTION_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL2, + uReg & ~SMB380_CONTROL2_ANY_MOTION_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_ENABLE_ADV_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL4, + uReg & ~SMB380_CONTROL4_ENABLE_ADV_INT_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); @@ -1044,15 +1037,19 @@ void SMB380_enableNewDataInt(void) { unsigned short uReg; unsigned long cpsr = disableIRQ(); - //prevent deep sleep, reason: 400�s wake-up time is to long for 3kHz interrupts + /* + * prevent deep sleep, reason: 400 µs wake-up time is to long for 3kHz + * interrupts + */ SETBIT(lpm_prevent_sleep, LPM_PREVENT_SLEEP_ACCSENSOR); SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_NEW_DATA_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL4, uReg | SMB380_CONTROL4_NEW_DATA_INT_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); - /* measuring temperature dependent internal sample rate of SMB380 */ + // measuring temperature dependent internal sample rate of SMB380 tickStart = ktimer_now(); tickCurrentSamples = 0; restoreIRQ(cpsr); @@ -1065,10 +1062,14 @@ void SMB380_disableNewDataInt(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL4, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_NEW_DATA_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL4, uReg & ~SMB380_CONTROL4_NEW_DATA_INT_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); - //enable deep sleep, reason: 400�s wake-up time was to long for 3kHz interrupts + /* + * enable deep sleep, reason: 400 µs wake-up time was to long for 3kHz + * interrupts + */ CLRBIT(lpm_prevent_sleep, LPM_PREVENT_SLEEP_ACCSENSOR); restoreIRQ(cpsr); } @@ -1080,7 +1081,8 @@ void SMB380_resetInterruptFlags(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_RESET_INT_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_RESET_INT_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); @@ -1093,7 +1095,8 @@ void SMB380_enableEEPROM(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_EE_W_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL1, uReg | SMB380_CONTROL1_EE_W_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); @@ -1106,38 +1109,13 @@ void SMB380_disableEEPROM(void) SMB380_Prepare(); SMB380_ssp_write(SMB380_CONTROL1, 0, SMB380_READ_REGISTER); uReg = SMB380_ssp_read(); - SMB380_ssp_write(SMB380_CONTROL1, uReg & ~SMB380_CONTROL1_EE_W_MASK, SMB380_WRITE_REGISTER); + SMB380_ssp_write(SMB380_CONTROL1, uReg & ~SMB380_CONTROL1_EE_W_MASK, + SMB380_WRITE_REGISTER); SMB380_ssp_read(); SMB380_Unprepare(); restoreIRQ(cpsr); } -//void SMB380_calibrate(void){ -// unsigned short uMSB, uLSB; -// //TODO 25Hz, 2G -// -// SMB380_ssp_write(SMB380_ACC_X_MSB, 0, SMB380_READ_REGISTER); -// SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA, 0, SMB380_READ_REGISTER); -// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; -// uLSB = (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; -// -// SMB380_ssp_write(SMB380_ACC_X_MSB + SMB380_EEPROM_OFFSET, uMSB, SMB380_WRITE_REGISTER); -// SMB380_ssp_write(SMB380_ACC_X_LSB_NEWDATA + SMB380_EEPROM_OFFSET, uLSB, SMB380_WRITE_REGISTER); -// -// -// SMB380_ssp_write(SMB380_ACC_Y_MSB, 0, SMB380_READ_REGISTER); -// SMB380_ssp_write(SMB380_ACC_Y_LSB_NEWDATA, 0, SMB380_READ_REGISTER); -// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; -// uLSB |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; -// -// SMB380_ssp_write(SMB380_ACC_Z_MSB, 0, SMB380_READ_REGISTER); -// SMB380_ssp_write(SMB380_ACC_Z_LSB_NEWDATA, 0, SMB380_READ_REGISTER); -// uMSB = (SMB380_ssp_read() & SMB380_ACC_MSB_MASK) << 2; -// uLSB |= (SMB380_ssp_read() & SMB380_ACC_LSB_MASK) >> 6; -// -// -//} - /* * Return offsets from offset registers, * remove xyz afterwards because it is useless @@ -1204,8 +1182,8 @@ unsigned char SMB380_readOffsetTemp(uint16_t *offset) return true; } -/* EEPROM = 1 if data has to be written in EEPROM and not only in image - * +/* + * EEPROM = 1 if data has to be written in EEPROM and not only in image */ void SMB380_writeOffset(uint16_t *offset, uint8_t EEPROM) { @@ -1215,7 +1193,8 @@ void SMB380_writeOffset(uint16_t *offset, uint8_t EEPROM) uint16_t eeoffset = 0; if (EEPROM) { - eeoffset = SMB380_EEPROM_OFFSET; //create offset if saving to EEPROM is needed + //create offset if saving to EEPROM is needed + eeoffset = SMB380_EEPROM_OFFSET; } unsigned short uReg; @@ -1224,40 +1203,48 @@ void SMB380_writeOffset(uint16_t *offset, uint8_t EEPROM) //x-Axis uReg = (offset[0] & 0x03) << 6; //get both LSB Bits - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); //write them to image or eeprom + //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X, 0, SMB380_READ_REGISTER); uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_X + eeoffset, (uint8_t)uReg, + SMB380_WRITE_REGISTER); //write them to image or eeprom SMB380_ssp_read(); hwtimer_wait(HWTIMER_TICKS(50000)); uReg = (offset[0] & 0x3FC) >> 2; //get MSB Bits - SMB380_ssp_write(SMB380_OFFSET_MSB_X + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_MSB_X + eeoffset, (uint8_t)uReg, + SMB380_WRITE_REGISTER); //write them to image or eeprom SMB380_ssp_read(); hwtimer_wait(HWTIMER_TICKS(50000)); //y-Axis uReg = (offset[1] & 0x03) << 6; //get both LSB Bits - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y, 0, SMB380_READ_REGISTER); uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Y + eeoffset, (uint8_t)uReg, + SMB380_WRITE_REGISTER); //write them to image or eeprom SMB380_ssp_read(); hwtimer_wait(HWTIMER_TICKS(50000)); uReg = (offset[1] & 0x3FC) >> 2; //get MSB Bits - SMB380_ssp_write(SMB380_OFFSET_MSB_Y + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_MSB_Y + eeoffset, (uint8_t)uReg, + SMB380_WRITE_REGISTER); //write them to image or eeprom SMB380_ssp_read(); hwtimer_wait(HWTIMER_TICKS(50000)); //z-Axis uReg = (offset[2] & 0x03) << 6; //get both LSB Bits - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, SMB380_READ_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z, 0, + SMB380_READ_REGISTER); //write them to image or eeprom uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_Z + eeoffset, (uint8_t)uReg, + SMB380_WRITE_REGISTER); //write them to image or eeprom SMB380_ssp_read(); hwtimer_wait(HWTIMER_TICKS(50000)); uReg = (offset[2] & 0x3FC) >> 2; //get MSB Bits - SMB380_ssp_write(SMB380_OFFSET_MSB_Z + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_MSB_Z + eeoffset, (uint8_t)uReg, + SMB380_WRITE_REGISTER); //write them to image or eeprom SMB380_ssp_read(); hwtimer_wait(HWTIMER_TICKS(50000)); @@ -1275,7 +1262,8 @@ void SMB380_writeOffsetTemp(uint16_t *offset, uint8_t EEPROM) uint16_t eeoffset = 0; if (EEPROM) { - eeoffset = SMB380_EEPROM_OFFSET; //create offset if saving to EEPROM is needed + //create offset if saving to EEPROM is needed + eeoffset = SMB380_EEPROM_OFFSET; } unsigned short uReg; @@ -1284,14 +1272,17 @@ void SMB380_writeOffsetTemp(uint16_t *offset, uint8_t EEPROM) //T-Axis uReg = (offset[0] & 0x03) << 6; //get both LSB Bits - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, SMB380_READ_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T, 0, + SMB380_READ_REGISTER); //write them to image or eeprom uReg |= (SMB380_ssp_read() & 0x3F); //saves gain from same register - SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_LSB_GAIN_T + eeoffset, (uint8_t)uReg, + SMB380_WRITE_REGISTER); //write them to image or eeprom SMB380_ssp_read(); hwtimer_wait(HWTIMER_TICKS(50000)); uReg = (offset[0] & 0x3FC) >> 2; //get MSB Bits - SMB380_ssp_write(SMB380_OFFSET_MSB_T + eeoffset, (uint8_t)uReg, SMB380_WRITE_REGISTER); //write them to image or eeprom + SMB380_ssp_write(SMB380_OFFSET_MSB_T + eeoffset, (uint8_t)uReg, + SMB380_WRITE_REGISTER); //write them to image or eeprom SMB380_ssp_read(); hwtimer_wait(HWTIMER_TICKS(50000)); diff --git a/avsextrem/drivers/avsextrem-ssp0.c b/avsextrem/drivers/avsextrem-ssp0.c index 17dfa05133..e396e5dddb 100644 --- a/avsextrem/drivers/avsextrem-ssp0.c +++ b/avsextrem/drivers/avsextrem-ssp0.c @@ -1,9 +1,9 @@ /* - * avsextrem-ssp0.c - implementation of the SPI0 interface for the LPC2387, + * avsextrem-ssp0.c - implementation of the SPI0 interface for the LPC2387, * and the AVSESTREM board. - * Copyright (C) 2013 Freie Universität Berlin + * Copyright (C) 2013 Freie Universität Berlin * - * This source code is licensed under the LGPLv2 license, + * This source code is licensed under the LGPLv2 license, * See the file LICENSE for more details. */ @@ -12,7 +12,7 @@ * @internal * @brief Implements the SPI0 interface for the LPC2387 * - * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Freie Universität Berlin, Computer Systems & Telematics * @author Marco Ziegert * @author Zakaria Kasmi * @version $Revision: 3854 $ @@ -20,7 +20,7 @@ * @note $Id: avsextrem-ssp0.c 3854 2013-08-14 15:27:01Z zkasmi $ */ -#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ +#include "lpc23xx.h" /* LPC23XX/24xx Peripheral Registers */ #include "cpu.h" #include "VIC.h" #include "ssp0-board.h" @@ -36,27 +36,21 @@ // //static void MMA7455L_extIntHandler(void); -/***************************************************************************** - ** Function name: SSP0Init - ** - ** Descriptions: SSP0 port initialization routine - ** - ** parameters: None - ** Returned value: true or false, if the interrupt handler - ** can't be installed correctly, return false. - ** - *****************************************************************************/ uint32_t SSP0Init(void) { - /* enable clock to SSP0 for security reason. By default, it's enabled already */ + /* + * enable clock to SSP0 for security reason. + * By default, it's enabled already + */ PCONP |= PCSSP0; - //TODO CLK, MISO, MOSI standardm��ig als GPIOs konfigurieren + //TODO: configure CLK, MISO, MOSI by default as GPIOs. #if USE_CS - // PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; //P1.20 1.21 1.23 1.24 + // P1.20 1.21 1.23 1.24 + // PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; #else - // PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 SSEL0 nicht - + // No SSEL0 + // PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 #endif #if SSP1_INTERRUPT_MODE @@ -65,27 +59,33 @@ uint32_t SSP0Init(void) return (FALSE); } - /* Set SSPINMS registers to enable interrupts */ - /* enable all error related interrupts */ + /* + * Set SSPINMS registers to enable interrupts, + * enable all error related interrupts + */ + SSP1IMSC = SSPIMSC_RORIM | SSPIMSC_RTIM; #endif return (1); } -/* datasize (wordsize) in decimal (4-16), cpol&cpha =(0/1) and frequency divided by 1000 (e.g. 8 MHz = 8000) - * +/* + * datasize (wordsize) in decimal (4-16), cpol&cpha =(0/1) and frequency divided + * by 1000 (e.g. 8 MHz = 8000) */ -uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, uint16_t freq) +uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, + uint16_t freq) { switch (chip) { case BMA180_INTERN: case SMB380_ACC: { #if USE_CS - PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17; //P1.20 1.21 1.23 1.24 + PINSEL3 |= BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | + BIT17; //P1.20 1.21 1.23 1.24 #else - - PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; //1.20 1.23 1.24 SSEL0 nicht + // 1.20 1.23 1.24 are not configured as SSEL0 + PINSEL3 |= BIT8 | BIT9 | BIT14 | BIT15 | BIT16 | BIT17; #endif break; } @@ -96,18 +96,19 @@ uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, case ACAMDMS: { #if USE_CS PINSEL0 |= BIT31; - PINSEL1 |= BIT1 | BIT3 | BIT5; //P0.15 0.16 0.17 0.18 + PINSEL1 |= BIT1 | BIT3 | BIT5; // P0.15 0.16 0.17 0.18 #else - //Turn on NanoPAN + // Turn on NanoPAN PINSEL0 |= BIT31; - PINSEL1 |= BIT3 | BIT5; //0.15 0.17 0.18 SSEL0 nicht + // 0.15 0.17 0.18 are not configured as SSEL0 + PINSEL1 |= BIT3 | BIT5; #endif break; } case NORDIC: { PINSEL0 |= BIT31; - PINSEL1 |= BIT3 | BIT5; //0.15 0.17 0.18 SSEL0 nicht + PINSEL1 |= BIT3 | BIT5; // 0.15 0.17 0.18 SSEL0 (No) break; } @@ -184,9 +185,9 @@ uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, SSP0CR0tmp |= BIT7; } - SSP0CR1 = 0x00; //SSP0 disabled + SSP0CR1 = 0x00; // SSP0 disabled - /* Setting xx-Bit Datasize, CPOL and CPHA*/ + // Setting xx-Bit Datasize, CPOL and CPHA SSP0CR0 = SSP0CR0tmp; // Clock Setup @@ -198,7 +199,7 @@ uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, SSP0CPSR = cpsr; // Enable - SSP0CR1 |= BIT1; //SSP0 enabled + SSP0CR1 |= BIT1; // SSP0 enabled uint32_t Dummy; @@ -214,11 +215,15 @@ uint8_t SSP0Unprepare(uint8_t chip) switch (chip) { case BMA180_INTERN: case SMB380_ACC: { - //Turn off Acceleration Sensor - PINSEL3 &= ~(BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | BIT17); + // Turn off Acceleration Sensor + PINSEL3 &= ~(BIT8 | BIT9 | BIT10 | BIT11 | BIT14 | BIT15 | BIT16 | + BIT17); FIO1DIR |= BIT20 | BIT21 | BIT24; - FIO1DIR &= ~BIT23; //MISO as Input - FIO1SET = BIT20 | BIT24; //CLK + SSEL + MOSI GPIO as Output //TODO depends on CPOL+CPHA Settings + FIO1DIR &= ~BIT23; // MISO as Input + FIO1SET = BIT20 | BIT24; /* + * CLK + SSEL + MOSI GPIO as Output + * TODO: depends on CPOL+CPHA Settings + */ FIO1CLR = BIT21; break; } @@ -228,12 +233,15 @@ uint8_t SSP0Unprepare(uint8_t chip) case NORDIC: case NANOPAN: case ACAMDMS: { - //Turn off Nanopan (Pins to GPIO) + // Turn off Nanopan (Pins to GPIO) PINSEL0 &= ~(BIT30 | BIT31); //CLK to GPIO PINSEL1 &= ~(BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5); FIO0DIR |= BIT15 | BIT16 | BIT18; //CLK + SSEL + MOSI GPIO as Output - FIO0DIR &= ~BIT17; //MISO as Input - FIO0SET = BIT15 | BIT16; //CLK + SSEL + MOSI GPIO as Output //TODO depends on CPOL+CPHA Settings + FIO0DIR &= ~BIT17; // MISO as Input + FIO0SET = BIT15 | BIT16; /* + * CLK + SSEL + MOSI GPIO as Output + * TODO: depends on CPOL+CPHA Settings + */ FIO0CLR = BIT18; break; } @@ -247,7 +255,8 @@ uint8_t SSP0Unprepare(uint8_t chip) return 1; } -unsigned char SMB380_ssp_write(const unsigned char regAddr, const unsigned char data, unsigned char flag) +unsigned char SMB380_ssp_write(const unsigned char regAddr, + const unsigned char data, unsigned char flag) { uint16_t temp = 0; @@ -288,7 +297,7 @@ unsigned char SSP0_write(const uint16_t data, uint8_t device) case ACAMDMS: case NORDIC: - //Chip Select is done in Nordic driver + // Chip Select is done in Nordic driver break; default: @@ -319,7 +328,7 @@ unsigned char SSP0_write(const uint16_t data, uint8_t device) case ACAMDMS: case NORDIC: - //Chip Select is done in Nordic driver + // Chip Select is done in Nordic driver break; default: @@ -356,7 +365,7 @@ unsigned short SSP0_read(uint8_t device) case NORDIC: case ACAMDMS: - //Chip Select is done in Nordic driver + // Chip Select is done in Nordic driver break; default: @@ -384,7 +393,7 @@ unsigned short SSP0_read(uint8_t device) case ACAMDMS: case NORDIC: - //Chip Select is done in Nordic driver + // Chip Select is done in Nordic driver break; default: diff --git a/avsextrem/include/board.h b/avsextrem/include/board.h index f8960c2dac..64f8bc3205 100644 --- a/avsextrem/include/board.h +++ b/avsextrem/include/board.h @@ -1,6 +1,6 @@ /* * board.h - Definitions for the AVSEXTREM board configuration. -* Copyright (C) 2013 Heiko Will +* Copyright (C) 2013 Zakaria Kasmi * * This source code is licensed under the LGPLv2 license, * See the file LICENSE for more details. @@ -12,12 +12,12 @@ * @file * @brief avsextrem board configuration * - * @author Freie Universität Berlin, Computer Systems & Telematics - * @author baar + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Heiko Will * @author Zakaria Kasmi * @version $Revision: 1127 $ * - * @note $Id: board-conf.h 1127 2013-06-13 08:48:29Z baar $ + * @note $Id: board-conf.h 1127 2013-06-13 08:48:29Z kasmi$ */ @@ -26,7 +26,7 @@ #include -#define FEUERWARE_CONF_BOARD_NAME "FU Berlin AVSEXTREM BOARD" +#define FEUERWARE_CONF_BOARD_NAME "FU Berlin AVSEXTREM BOARD" #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) @@ -42,19 +42,19 @@ #ifdef MODULE_CC110X -#define FEUERWARE_CONF_NUM_RADIOS 1 +#define FEUERWARE_CONF_NUM_RADIOS 1 #else -#define FEUERWARE_CONF_NUM_RADIOS 0 +#define FEUERWARE_CONF_NUM_RADIOS 0 #endif // if FAT is enabled this board supports files -#define FEUERWARE_CONF_CORE_SUPPORTS_FILES defined(MODULE_FAT) +#define FEUERWARE_CONF_CORE_SUPPORTS_FILES defined(MODULE_FAT) #ifdef MODULE_FAT -#define CFG_CONF_MEM_SIZE 0x7FFFFFFF -#define SYSLOG_CONF_NUM_INTERFACES 2 +#define CFG_CONF_MEM_SIZE 0x7FFFFFFF +#define SYSLOG_CONF_NUM_INTERFACES 2 #else -#define SYSLOG_CONF_NUM_INTERFACES 1 +#define SYSLOG_CONF_NUM_INTERFACES 1 #endif void init_clks1(void); diff --git a/avsextrem/include/configure.h b/avsextrem/include/configure.h index 6088a0ad32..5ca52843a1 100644 --- a/avsextrem/include/configure.h +++ b/avsextrem/include/configure.h @@ -1,6 +1,6 @@ /* -* avsextrem-cc1100.c - CC100 Transceiver Driver for the AVSEXTREM-BOARD. -* Copyright (C) 2013 Heiko Will +* configure.h - Configuration file for the avsextrem board. +* Copyright (C) 2013 Zakaria Kasmi * * This source code is licensed under the LGPLv2 license, * See the file LICENSE for more details. @@ -11,20 +11,18 @@ * @file * @brief definitions for the avsextrem board configuration * - * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Freie Universität Berlin, Computer Systems & Telematics * @author baar * @author Zakaria Kasmi * @version $Revision: 1127 $ * - * @note $Id: board-conf.h 1127 2013-06-13 08:48:29Z baar $ + * @note $Id: board-conf.h 1127 2013-08-20 17:15:29 kasmi $ */ #ifndef CONFIGURE_H_ #define CONFIGURE_H_ /** - * @defgroup conf Offline Configuration - * @ingroup feuerware * * The offline configuration file "configure.h" is automatically * included in every file by the build system and allows to configure @@ -39,17 +37,6 @@ * @{ */ -/** - * @file - * @brief Central offline configuration - * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project - * @author baar - * @version $Revision: 3854 $ - * - * @note $Id: configure.h 3854 2011-12-06 15:27:01Z hwill $ - */ - //#include "project-conf.h" //#include "board-conf.h" #include "cpu-conf.h" diff --git a/avsextrem/include/smb380-board.h b/avsextrem/include/smb380-board.h index 4a92cf5b53..218f724f49 100644 --- a/avsextrem/include/smb380-board.h +++ b/avsextrem/include/smb380-board.h @@ -1,23 +1,23 @@ /* - * smb380-board.h - definitions of the Driver for the SMB380 acceleration sensor. - * Copyright (C) 2013 Freie Universität Berlin + * msba2acc-smb380.h - Definitions of the Driver for the SMB380 acceleration + * sensor. + * Copyright (C) 2013 Freie Universität Berlin * * This source code is licensed under the LGPLv2 license, * See the file LICENSE for more details. - * - */ + **/ /** * @file * @internal - * @brief SMB380 acceleration sensor definitions for the LPC2387 + * @brief SMB380 acceleration sensor definitions for the LPC2387 * - * @author Freie Universität Berlin, Computer Systems & Telematics - * @author Marco Ziegert - * @author Zakaria Kasmi - * @version $Revision: 3854 $ + * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Marco Ziegert + * @author Zakaria Kasmi + * @version $Revision: 3854 $ * - * @note $Id: msba2acc-smb380.h 3854 2013-06-19 17:33:01Z zkasmi $ + * @note $Id: msba2acc-smb380.h 3854 2010-01-18 15:27:01 kasmi $ * */ @@ -30,9 +30,9 @@ #define MSG_TYPE_SMB380_WAKEUP 814 -#define SMB380_X_AXIS 0 //X Axis-Name -#define SMB380_Y_AXIS 1 //Y Axis-Name -#define SMB380_Z_AXIS 2 //Z Axis-Name +#define SMB380_X_AXIS 0 //X Axis-Name +#define SMB380_Y_AXIS 1 //Y Axis-Name +#define SMB380_Z_AXIS 2 //Z Axis-Name #define LPM_PREVENT_SLEEP_ACCSENSOR BIT2 @@ -54,35 +54,41 @@ volatile enum SMB380_MODE smb380_mode;// = SMB380_POLL; */ #define SMB380_EEPROM_OFFSET 0x20 - -#define SMB380_CHIP_ID 0x00 //Chip-ID Bit0-2, default: 010b -#define SMB380_CHIP_ID_MASK 0x07 //Chip-ID mask - -#define SMB380_AL_ML_VERSION 0x01 //ml_version Bit0-3 ; al_version Bit4-7 -#define SMB380_AL_MASK 0xF0 //al_mask -#define SMB380_ML_MASK 0x0F //ml_mask - -#define SMB380_ACC_X_LSB_NEWDATA 0x02 //LSB_acc_x Bit6-7 ; new_data_x Bit0 -#define SMB380_ACC_X_MSB 0x03 //MSB_acc_x Bit0-7 -#define SMB380_ACC_Y_LSB_NEWDATA 0x04 //LSB_acc_y Bit6-7 ; new_data_y Bit0 -#define SMB380_ACC_Y_MSB 0x05 //MSB_acc_y Bit0-7 -#define SMB380_ACC_Z_LSB_NEWDATA 0x06 //LSB_acc_z Bit6-7 ; new_data_z Bit0 -#define SMB380_ACC_Z_MSB 0x07 //MSB_acc_z Bit0-7 +//Chip-ID Bit0-2, default: 010b +#define SMB380_CHIP_ID 0x00 +//Chip-ID mask +#define SMB380_CHIP_ID_MASK 0x07 +//ml_version Bit0-3 ; al_version Bit4-7 +#define SMB380_AL_ML_VERSION 0x01 +#define SMB380_AL_MASK 0xF0 +#define SMB380_ML_MASK 0x0F +//LSB_acc_x Bit6-7; new_data_x Bit0 +#define SMB380_ACC_X_LSB_NEWDATA 0x02 +//MSB_acc_x Bit0-7 +#define SMB380_ACC_X_MSB 0x03 +//LSB_acc_y Bit6-7; new_data_y Bit0 +#define SMB380_ACC_Y_LSB_NEWDATA 0x04 +//MSB_acc_y Bit0-7 +#define SMB380_ACC_Y_MSB 0x05 +//LSB_acc_z Bit6-7; new_data_z Bit0 +#define SMB380_ACC_Z_LSB_NEWDATA 0x06 +//MSB_acc_z Bit0-7 +#define SMB380_ACC_Z_MSB 0x07 #define SMB380_ACC_LSB_MASK 0xC0 #define SMB380_ACC_MSB_MASK 0xFF #define SMB380_ACC_NEWDATA_MASK 0x01 - -#define SMB380_TEMP 0x08 //Temperature Bit0-7 - -#define SMB380_STATUS 0x09 //Status register, contains six flags +//Temperature Bit0-7 +#define SMB380_TEMP 0x08 +//Status register, contains six flags +#define SMB380_STATUS 0x09 #define SMB380_STATUS_ST_RESULT_MASK 0x80 #define SMB380_STATUS_ALERT_PHASE_MASK 0x10 #define SMB380_STATUS_LG_LATCHED_MASK 0x08 #define SMB380_STATUS_HG_LATCHED_MASK 0x04 #define SMB380_STATUS_STATUS_LG_MASK 0x02 #define SMB380_STATUS_STATUS_HG_MASK 0x01 - -#define SMB380_CONTROL1 0x0A //Control register - contains seven values, default: x000 0000b +//Control register - contains seven values, default: x000 0000b +#define SMB380_CONTROL1 0x0A #define SMB380_CONTROL1_RESET_INT_MASK 0x40 #define SMB380_CONTROL1_UPDATE_MASK 0x20 #define SMB380_CONTROL1_EE_W_MASK 0x10 @@ -90,33 +96,39 @@ volatile enum SMB380_MODE smb380_mode;// = SMB380_POLL; #define SMB380_CONTROL1_SELF_TEST_0_MASK 0x04 #define SMB380_CONTROL1_SOFT_RESET_MASK 0x02 #define SMB380_CONTROL1_SLEEP_MASK 0x01 - -#define SMB380_CONTROL2 0x0B //Control register - contains six values, default: x000 0011b +//Control register - contains six values, default: x000 0011b +#define SMB380_CONTROL2 0x0B #define SMB380_CONTROL2_ALERT_MASK 0x80 #define SMB380_CONTROL2_ANY_MOTION_MASK 0x40 #define SMB380_CONTROL2_COUNTER_HG_MASK 0x30 #define SMB380_CONTROL2_COUNTER_LG_MASK 0x0C #define SMB380_CONTROL2_ENABLE_HG_MASK 0x02 #define SMB380_CONTROL2_ENABLE_LG_MASK 0x01 - -#define SMB380_LG_THRES 0x0C // , default: 20 -#define SMB380_LG_DUR 0x0D // , default: 150 -#define SMB380_HG_THRES 0x0E // , default: 160 -#define SMB380_HG_DUR 0x0F // , default: 150 -#define SMB380_ANY_MOTION_THRES 0x10 // , default: 0 -#define SMB380_ANY_MOTION_DUR_HYST 0x1 // , default: 0000 0000b +//default: 20 +#define SMB380_LG_THRES 0x0C +//default: 150 +#define SMB380_LG_DUR 0x0D +//default: 160 +#define SMB380_HG_THRES 0x0E +//default: 150 +#define SMB380_HG_DUR 0x0F +//default: 0 +#define SMB380_ANY_MOTION_THRES 0x10 +//default: 0000 0000b +#define SMB380_ANY_MOTION_DUR_HYST 0x1 #define SMB380_ANY_MOTION_DUR_MASK 0xC0 #define SMB380_ANY_MOTION_DUR_HG_HYST_MASK 0x38 #define SMB380_ANY_MOTION_DUR_LG_HYST_MASK 0x07 - -#define SMB380_CUST1 0x12 // , default: 162 -#define SMB380_CUST2 0x13 // , default: 13 - -#define SMB380_CONTROL3 0x14 // , default: xxx0 1110b +//default: 162 +#define SMB380_CUST1 0x12 +//default: 13 +#define SMB380_CUST2 0x13 +//default: xxx0 1110b +#define SMB380_CONTROL3 0x14 #define SMB380_CONTROL3_RANGE_MASK 0x18 #define SMB380_CONTROL3_BANDWITH_MASK 0x07 - -#define SMB380_CONTROL4 0x15 // , default: 1000 0000b +//default: 1000 0000b +#define SMB380_CONTROL4 0x15 #define SMB380_CONTROL4_SPI4_MASK 0x80 #define SMB380_CONTROL4_ENABLE_ADV_INT_MASK 0x40 #define SMB380_CONTROL4_NEW_DATA_INT_MASK 0x20 @@ -155,30 +167,37 @@ volatile enum SMB380_MODE smb380_mode;// = SMB380_POLL; #define SMB380_BAND_WIDTH_375HZ 0x04 #define SMB380_BAND_WIDTH_750HZ 0x05 #define SMB380_BAND_WIDTH_1500HZ 0x06 -#define SMB380_RING_BUFF_SIZE 256 //SMB380_RING_BUFF_SIZE * int16_t (2Byte) * 4 (x,y,z,Temp) = 512 Byte (for 64) +//SMB380_RING_BUFF_SIZE * int16_t (2Byte) * 4 (x,y,z,Temp) = 512 Byte (for 64) +#define SMB380_RING_BUFF_SIZE 256 //TODO chsnge size to 2048 #define SMB380_RING_BUFF_MAX_THREADS 10 #define SMB380_SAMPLE_RATE_MAX 3000 -/* change from Header (public) to internal use (private) (use it after every write to EEPROM) +/* + * change from Header (public) to internal use (private) + * (use it after every write to EEPROM). * set update_image Bit in control1 to - * copie content from EEPROM (0x2B to 0x3D) to Image (0x0B to 0x1D) */ + * copie content from EEPROM (0x2B to 0x3D) to Image (0x0B to 0x1D) + **/ void SMB380_update_image(void); -/* change from Header (public) to internal use (private) +/* + * change from Header (public) to internal use (private) * set ee_w Bit in control1 to * enable read to 0x16 to 0x22 and - * enable write to 0x16 to 0x3D */ + * enable write to 0x16 to 0x3D + **/ void SMB380_enable_eeprom_default(void); +//Example Hysterese function +uint8_t SMB380_HystereseFunctionSample(int16_t *value); -uint8_t SMB380_HystereseFunctionSample(int16_t *value); //Example Hysterese functon - -// simple api for single-sample, single thread interrupt mode -uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, uint8_t range); +//Simple api for single-sample, single thread interrupt mode +uint8_t SMB380_init_simple(uint16_t samplerate, uint8_t bandwidth, + uint8_t range); - -uint8_t SMB380_init(uint8_t (*func)(int16_t *)); // enables Interrupts (normally only once called) +//Enables Interrupts (normally only once called) +uint8_t SMB380_init(uint8_t (*func)(int16_t *)); void SMB380_setSampleRate(uint16_t rate); uint16_t SMB380_getSampleRate(void); void freeRingReadPointer(void); diff --git a/avsextrem/include/ssp0-board.h b/avsextrem/include/ssp0-board.h index 6c7b0907fe..ffcc5356ee 100644 --- a/avsextrem/include/ssp0-board.h +++ b/avsextrem/include/ssp0-board.h @@ -1,6 +1,6 @@ /* * ssp0-borad.h - header file of the SPI interface for the LPC2387. - * Copyright (C) 2013 Freie Universität Berlin + * Copyright (C) 2013 Freie Universität Berlin * * This source code is licensed under the LGPLv2 license, * See the file LICENSE for more details. @@ -12,7 +12,7 @@ * @internal * @brief SPI interface definitions for the LPC2387 * - * @author Freie Universität Berlin, Computer Systems & Telematics + * @author Freie Universität Berlin, Computer Systems & Telematics * @author Marco Ziegert * @author Zakaria Kasmi * @version $Revision: 3854 $ @@ -26,10 +26,16 @@ #define DMA_ENABLED 0 -/* if USE_CS is zero, set SSEL as GPIO that you have total control of the sequence */ +/* + * if USE_CS is zero, set SSEL as GPIO that you have total control of the + * sequence + **/ #define USE_CS 0 -/* if 1, use driver for onboard BMA180, otherwise for external BMA180 utilizing Nanopan Connector */ +/* + * if 1, use driver for onboard BMA180, otherwise for external BMA180 utilizing + * Nanopan Connector + **/ #define BMA180_ONBOARD 1 #define SMB380_ACC 0 @@ -96,18 +102,17 @@ #define BMA180_EXTINT_MODE 1 uint32_t SSP0Init(void); -uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, uint16_t freq); +uint8_t SSP0Prepare(uint8_t chip, uint8_t datasize, uint8_t cpol, uint8_t cpha, + uint16_t freq); uint8_t SSP0Unprepare(uint8_t chip); unsigned char SSP0_write(const uint16_t data, uint8_t device); unsigned short SSP0_read(uint8_t device); -unsigned char SMB380_ssp_write(const unsigned char regAddr, const unsigned char data, unsigned char flag); +unsigned char SMB380_ssp_write(const unsigned char regAddr, + const unsigned char data, unsigned char flag); unsigned short SMB380_ssp_read(void); unsigned short nrf24l01_ssp_read_write(const uint8_t data); unsigned short acam_trx(const uint8_t data); void SSP0Handler(void); #endif /* __SSP_H__ */ -/***************************************************************************** -** End Of File -******************************************************************************/ diff --git a/msba2-common/Makefile b/msba2-common/Makefile index 6e64f29bb8..29f64c8ecb 100644 --- a/msba2-common/Makefile +++ b/msba2-common/Makefile @@ -1,4 +1,4 @@ -SRC = $(wildcard *.c) +SRC = $(wildcard *.c) BINDIR = $(RIOTBOARD)/$(BOARD)/bin/ OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines DEP = $(SRC:%.c=$(BINDIR)%.d) diff --git a/msba2-common/board_common_init.c b/msba2-common/board_common_init.c index 5db84af7ab..4096caa944 100644 --- a/msba2-common/board_common_init.c +++ b/msba2-common/board_common_init.c @@ -72,9 +72,10 @@ pllfeed(void) } -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 a7207c895d..496a077961 100644 --- a/msba2-common/board_config.c +++ b/msba2-common/board_config.c @@ -3,12 +3,10 @@ #include #include -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)); } @@ -17,8 +15,7 @@ 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/lpc2387-timer3.c b/msba2-common/lpc2387-timer3.c index e070a156bc..3b404edd94 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/board_init.c b/msba2/board_init.c index a600de19d1..427d563e1b 100644 --- a/msba2/board_init.c +++ b/msba2/board_init.c @@ -2,7 +2,7 @@ * main.c - Main function of the SRF02 ultrasonic sensor project. * Copyright (C) 2013 Zakaria Kasmi * - * The source code is licensed under the LGPLv2 license, + * The source code is licensed under the LGPLv2 license, * See the file LICENSE for more details. */ @@ -15,7 +15,7 @@ * @file * @brief MSB-A2 board initialization * - * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project * @author Heiko Will * @author Kaspar Schleiser * @author Michael Baar @@ -86,7 +86,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; @@ -105,4 +106,4 @@ void init_clks1(void) #if USE_USB USBCLKCFG = USBCLKDivValue; /* usbclk = 288 MHz/6 = 48 MHz */ #endif -} \ No newline at end of file +} From 5d73fbe196039afdcdc4164eb2d6f7d0b3db62d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Roussel?= Date: Tue, 1 Oct 2013 11:07:48 +0200 Subject: [PATCH 173/188] Force Git to ignore backup files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 937bfe3459..071b01a9bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin/ *.o +*~ From 70338853563ad93b40a1ad81d202227342817676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Roussel?= Date: Tue, 1 Oct 2013 11:16:52 +0200 Subject: [PATCH 174/188] Updated the MCU frequency from 800 KHz to (a more likely) 8 MHz. --- telosb/include/board.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telosb/include/board.h b/telosb/include/board.h index d9ab4a6675..18b064d172 100644 --- a/telosb/include/board.h +++ b/telosb/include/board.h @@ -29,7 +29,7 @@ */ //MSB430 core -#define MSP430_INITIAL_CPU_SPEED 800000uL +#define MSP430_INITIAL_CPU_SPEED 8000000uL #define MSP430_HAS_DCOR 0 #define MSP430_HAS_EXTERNAL_CRYSTAL 1 From 0dd268345eae2ec91a44654166b0e48de272c80c Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Thu, 10 Oct 2013 13:54:15 +0200 Subject: [PATCH 175/188] fix Makefile.dep remove cc1100 cruft model ltc4150 dependency --- native/Makefile.dep | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/native/Makefile.dep b/native/Makefile.dep index de1d7e692c..fdd8ec4d90 100644 --- a/native/Makefile.dep +++ b/native/Makefile.dep @@ -1,6 +1,6 @@ -ifneq (,$(findstring cc110x_ng,$(USEMODULE))) - ifeq (,$(findstring cc110x_spi,$(USEMODULE))) - USEMODULE += cc110x_spi +ifneq (,$(findstring ltc4150,$(USEMODULE))) + ifeq (,$(findstring hwtimer,$(USEMODULE))) + USEMODULE += hwtimer endif endif From e1d5c8c8c62bde6efa6c94d2e48ba4daec9b959c Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Fri, 11 Oct 2013 15:07:53 +0200 Subject: [PATCH 176/188] added objcopy flags to makefiles for all platforms --- chronos/Makefile.include | 1 + msb-430-common/Makefile.include | 1 + msba2-common/Makefile.include | 1 + redbee-econotag/Makefile.include | 5 +++-- wsn430-common/Makefile.include | 4 +++- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/chronos/Makefile.include b/chronos/Makefile.include index 47ba1a079f..04b77c5d4c 100644 --- a/chronos/Makefile.include +++ b/chronos/Makefile.include @@ -19,3 +19,4 @@ ifeq ($(strip $(PORT)),) endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" +export OFLAGS = -O ihex diff --git a/msb-430-common/Makefile.include b/msb-430-common/Makefile.include index 33ce3d11eb..b7dd9ef3d9 100644 --- a/msb-430-common/Makefile.include +++ b/msb-430-common/Makefile.include @@ -24,3 +24,4 @@ export FFLAGS = -j olimex "prog $(HEXFILE)" export USEMODULE += msp430_common export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ +export OFLAGS = -O ihex diff --git a/msba2-common/Makefile.include b/msba2-common/Makefile.include index c2832ca47d..5d3ba0fb0d 100644 --- a/msba2-common/Makefile.include +++ b/msba2-common/Makefile.include @@ -24,3 +24,4 @@ export FFLAGS = $(PORT) $(PROJBINDIR)/$(PROJECT).hex include $(RIOTBOARD)/msba2-common/Makefile.dep export INCLUDES += -I$(RIOTCPU)/lpc2387/include +export OFLAGS = -O ihex diff --git a/redbee-econotag/Makefile.include b/redbee-econotag/Makefile.include index 26738a93fc..53a4eec202 100644 --- a/redbee-econotag/Makefile.include +++ b/redbee-econotag/Makefile.include @@ -19,7 +19,7 @@ export AS = $(PREFIX)as export LINK = $(PREFIX)gcc export SIZE = $(PREFIX)size export OBJCOPY = $(PREFIX)objcopy -FLASHER = lpc2k_pgm +FLASHER = mc1322x-load.pl TERM = pyterm.py LINKFLAGS = -mcpu=arm7tdmi-s -static -lgcc -nostartfiles -T$(RIOTBASE)/cpu/$(CPU)/mc1322x.lds @@ -27,4 +27,5 @@ ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 endif export HEXFILE = bin/$(PROJECT).hex -export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" +export FFLAGS = -t $(PORT) -f $(HEXFILE) -c 'bbmc -l redbee-econotag reset' +export OFLAGS = -O binary --gap-fill=0xff diff --git a/wsn430-common/Makefile.include b/wsn430-common/Makefile.include index 63cee9a3af..f1cde0aab9 100644 --- a/wsn430-common/Makefile.include +++ b/wsn430-common/Makefile.include @@ -20,4 +20,6 @@ endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" -export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ \ No newline at end of file +export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ +export OFLAGS = -O ihex + From e2ca03bcdb733ea7b3fc7b73fc7c3bb63c4a832a Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Sun, 20 Oct 2013 17:54:31 +0200 Subject: [PATCH 177/188] define radiopacket_length_t in board.h --- avsextrem/include/board.h | 2 ++ chronos/include/board.h | 2 ++ msb-430/include/board.h | 2 ++ msb-430h/include/board.h | 2 ++ msba2/include/board.h | 2 ++ native/include/board.h | 2 ++ olimex_lpc2148/include/board.h | 2 ++ pttu/include/board.h | 2 ++ telosb/include/board.h | 2 ++ wsn430-v1_3b/include/board.h | 2 ++ wsn430-v1_4/include/board.h | 2 ++ 11 files changed, 22 insertions(+) diff --git a/avsextrem/include/board.h b/avsextrem/include/board.h index 64f8bc3205..ac3cfd7717 100644 --- a/avsextrem/include/board.h +++ b/avsextrem/include/board.h @@ -59,6 +59,8 @@ void init_clks1(void); +typedef uint8_t radio_packet_length_t; + /** @} */ #endif /* BOARDCONF_H_ */ diff --git a/chronos/include/board.h b/chronos/include/board.h index 3186b63316..f4230f7a8d 100644 --- a/chronos/include/board.h +++ b/chronos/include/board.h @@ -7,4 +7,6 @@ #define MSP430_HAS_DCOR 1 #define MSP430_HAS_EXTERNAL_CRYSTAL 1 +typedef uint8_t radio_packet_length_t; + #endif // _MSB_BOARD_H diff --git a/msb-430/include/board.h b/msb-430/include/board.h index 56c24a5461..286de9fc59 100644 --- a/msb-430/include/board.h +++ b/msb-430/include/board.h @@ -66,5 +66,7 @@ and the mailinglist (subscription via web site) #include +typedef uint8_t radio_packet_length_t; + /** @} */ #endif // _MSB_BOARD_H diff --git a/msb-430h/include/board.h b/msb-430h/include/board.h index d9634d6b4d..fe8d49abb6 100644 --- a/msb-430h/include/board.h +++ b/msb-430h/include/board.h @@ -66,5 +66,7 @@ and the mailinglist (subscription via web site) #include +typedef uint8_t radio_packet_length_t; + /** @} */ #endif // _MSB_BOARD_H diff --git a/msba2/include/board.h b/msba2/include/board.h index fb64f0095e..fc16380df8 100644 --- a/msba2/include/board.h +++ b/msba2/include/board.h @@ -17,4 +17,6 @@ void init_clks1(void); +typedef uint8_t radio_packet_length_t; + #endif /* __BOARD_H */ diff --git a/native/include/board.h b/native/include/board.h index f4797f2060..9665094f37 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -27,3 +27,5 @@ void _native_LED_RED_ON(void); #define LED_RED_ON (_native_LED_RED_ON()) void _native_LED_RED_TOGGLE(void); #define LED_RED_TOGGLE (_native_LED_RED_TOGGLE()) + +typedef uint16_t radio_packet_length_t; diff --git a/olimex_lpc2148/include/board.h b/olimex_lpc2148/include/board.h index eaf536b005..c79b46b368 100644 --- a/olimex_lpc2148/include/board.h +++ b/olimex_lpc2148/include/board.h @@ -1 +1,3 @@ #include + +typedef uint8_t radio_packet_length_t; diff --git a/pttu/include/board.h b/pttu/include/board.h index 850f8d1d17..ba7b3f42bf 100644 --- a/pttu/include/board.h +++ b/pttu/include/board.h @@ -52,5 +52,7 @@ void init_clks1(void); void init_clks2(void); void bl_init_clks(void); +typedef uint8_t radio_packet_length_t; + /** @} */ #endif // __BOARD_H diff --git a/telosb/include/board.h b/telosb/include/board.h index 18b064d172..5fc3151e9c 100644 --- a/telosb/include/board.h +++ b/telosb/include/board.h @@ -54,5 +54,7 @@ #include +typedef uint8_t radio_packet_length_t; + /** @} */ #endif // _TELOSB_BOARD_H diff --git a/wsn430-v1_3b/include/board.h b/wsn430-v1_3b/include/board.h index ee09d10169..466df39adc 100644 --- a/wsn430-v1_3b/include/board.h +++ b/wsn430-v1_3b/include/board.h @@ -57,5 +57,7 @@ #include +typedef uint8_t radio_packet_length_t; + /** @} */ #endif // _WSN_BOARD_H diff --git a/wsn430-v1_4/include/board.h b/wsn430-v1_4/include/board.h index 3cb86d1366..5ffbf8049a 100644 --- a/wsn430-v1_4/include/board.h +++ b/wsn430-v1_4/include/board.h @@ -57,5 +57,7 @@ #include +typedef uint8_t radio_packet_length_t; + /** @} */ #endif // _WSN_BOARD_H From ab59944366ae97729dd8f5be8eb51c2fcff5ed3b Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Tue, 27 Aug 2013 10:04:28 +0200 Subject: [PATCH 178/188] fixes uart implementation --- redbee-econotag/Makefile.include | 2 +- redbee-econotag/board_init.c | 4 +- redbee-econotag/drivers/include/maca.h | 2 +- redbee-econotag/drivers/include/uart.h | 104 ++++++++----------------- redbee-econotag/drivers/redbee_uart.c | 87 +++++++-------------- redbee-econotag/drivers/redbee_uart1.c | 6 +- redbee-econotag/drivers/redbee_uart2.c | 6 +- redbee-econotag/include/board.h | 17 ++++ 8 files changed, 92 insertions(+), 136 deletions(-) create mode 100644 redbee-econotag/include/board.h diff --git a/redbee-econotag/Makefile.include b/redbee-econotag/Makefile.include index 53a4eec202..8208eeeb71 100644 --- a/redbee-econotag/Makefile.include +++ b/redbee-econotag/Makefile.include @@ -12,7 +12,7 @@ export CFLAGS_BASIC = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ -ffixed-r8 -ffunction-sections -ffreestanding -fno-builtin \ -nodefaultlibs -Wcast-align -Wall -Wstrict-prototypes -Wextra \ -Os -pipe -export CFLAGS += $(CFLAGS_BASIC) -mthumb +# export CFLAGS += $(CFLAGS_BASIC) -mthumb $(warning TODO add -mthumb) export AFLAGS = -Wa,-gstabs $(CFLAGS) export AS = $(PREFIX)as diff --git a/redbee-econotag/board_init.c b/redbee-econotag/board_init.c index 7cafd1a0e2..18ac6c376c 100644 --- a/redbee-econotag/board_init.c +++ b/redbee-econotag/board_init.c @@ -2,8 +2,8 @@ * board_init.c - redbee-econotag initialization code * Copyright (C) 2013 Oliver Hahm * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. */ void board_init(void) diff --git a/redbee-econotag/drivers/include/maca.h b/redbee-econotag/drivers/include/maca.h index 7c2bc8e071..bb1ca3326a 100644 --- a/redbee-econotag/drivers/include/maca.h +++ b/redbee-econotag/drivers/include/maca.h @@ -407,7 +407,7 @@ struct MACA_struct { { uint32_t TXCCADELAY :12; // Delay from end of CCA to Tx start uint32_t :20; // reserved - }RXENDbits; + }TXCCADELAYbits; }; uint32_t KEY3; // see (9.7.45) uint32_t KEY2; // see (9.7.45) diff --git a/redbee-econotag/drivers/include/uart.h b/redbee-econotag/drivers/include/uart.h index b95e6abcd1..252bca811b 100644 --- a/redbee-econotag/drivers/include/uart.h +++ b/redbee-econotag/drivers/include/uart.h @@ -2,8 +2,8 @@ * uart.h - UART driver for redbee * Copyright (C) 2013 Thomas Eichinger * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. * * This file is part of RIOT. */ @@ -11,6 +11,8 @@ #ifndef UART_H #define UART_H +#include + /*-----------------------------------------------------------------*/ /* UART */ #define UART1_BASE (0x80005000) @@ -20,73 +22,68 @@ 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; + uint32_t TXE: 1; /*< Tx Enable */ + uint32_t RXE: 1; /*< Rx Enable */ + uint32_t PEN: 1; /*< Parity Enable */ + uint32_t EP: 1; /*< Even Parity (1=Odd, 0=Even) */ + uint32_t ST2: 1; /*< Enable 2 Stop Bits */ + uint32_t SB: 1; /*< Send Break */ + uint32_t CONTX: 1; /*< Continuous Tx (Test Mode) */ + uint32_t TXOENB: 1; /*< TXD Outbut Disable */ + uint32_t : 2; /*< reserved */ + uint32_t XTIM: 1; /*< Times of Oversampling */ + uint32_t FCP: 1; /*< Flow Control Polarity */ + uint32_t FCE: 1; /*< Flow Control Enable */ + uint32_t MTXR: 1; /*< enable/disable TxRDY Interrupts */ + uint32_t MRXR: 1; /*< enable/disable RxRDY Interrupts */ + uint32_t TST: 1; /*< Test Loop-Back */ + uint32_t : 16; /*< reserved */ } CONbits; }; union { uint32_t STAT; struct UART_STAT { + uint32_t SE: 1; /*< Start Bit Error */ + uint32_t PE: 1; /*< Parity Bit Error */ + uint32_t FE: 1; /*< Frame/Stop Bit Error */ + uint32_t TOE: 1; /*< Tx FIFO Overrun Error */ + uint32_t ROE: 1; /*< Rx FIFO Overrun Error */ + uint32_t RUE: 1; /*< Rx FIFO Underrun Error */ + uint32_t RXRDY: 1; /*< Receiver is causing Interrupts */ + uint32_t TXRDY: 1; /*< Transmitter is causing Interrupts */ 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; + uint32_t : 24; } DATAbits; }; union { uint32_t RXCON; struct UART_URXCON { - uint32_t : 26; uint32_t LVL: 6; + uint32_t : 26; } RXCONbits; }; union { uint32_t TXCON; struct UART_TXCON { - uint32_t : 26; uint32_t LVL: 6; + uint32_t : 26; } TXCONbits; }; union { uint32_t CTS; struct UART_CTS { - uint32_t : 27; uint32_t LVL: 5; + uint32_t : 27; } CTSbits; }; - union { - uint32_t BR; - struct UART_BR { - uint32_t INC: 16; - uint32_t MOD: 16; - } BRbits; - }; + + uint32_t BR; /*< BR is 32bit access only */ }; static volatile struct UART_struct *const UART1 = (void *)(UART1_BASE); @@ -99,43 +96,10 @@ void uart_flow_ctl(volatile struct UART_struct *uart, uint8_t on); #define UART0_BUFSIZE (32) -/* 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 index bf467a1376..cdeb62bc98 100644 --- a/redbee-econotag/drivers/redbee_uart.c +++ b/redbee-econotag/drivers/redbee_uart.c @@ -2,8 +2,8 @@ * redbee_uart.c - UART driver for redbee * Copyright (C) 2013 Thomas Eichinger * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. * * This file is part of RIOT. */ @@ -11,7 +11,6 @@ #include "mc1322x.h" #include "uart.h" #include "gpio.h" -#include "io.h" #define MOD_ 9999 #define CLK_ 24000000 @@ -26,16 +25,16 @@ void uart_set_baudrate(volatile struct UART_struct *uart, uint32_t baudrate) /* 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; + /* add 5 and div by 10 to get a proper 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_; + /* BR register is 32bit access only */ + uart->BR = (((uint16_t) inc << 16) | MOD_); /* reenable UARTx again */ /* uart->CON.XTIM = 0 is 16x oversample (datasheet is incorrect) */ @@ -92,7 +91,6 @@ void uart_flow_ctl(volatile struct UART_struct *uart, uint8_t on) } } -// 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 */ @@ -100,9 +98,6 @@ void uart_init(volatile struct UART_struct *uart, uint32_t baudrate) 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; @@ -112,27 +107,17 @@ void uart_init(volatile struct UART_struct *uart, uint32_t baudrate) 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 + UART1->CONbits.TXE = 1; /*< enable transmit */ + UART1->CONbits.RXE = 1; /*< enable receive */ - //u1_tx_head = 0; - //u1_tx_tail = 0; + UART1->CONbits.FCE = 1; /*< enable flowcontrol */ + UART1->CONbits.MRXR = 1; /*< disable Rx interrupt */ + UART1->CTSbits.LVL = 31; /*< drop cts when tx buffer at trigger level */ + GPIO->FUNC_SEL.U1CTS = 1; /*< set GPIO 16 to UART1 CTS */ + GPIO->FUNC_SEL.U1RTS = 1; /*< set GPIO 17 to UART1 RTS */ - //enable_irq(UART1); ITC->INTENABLEbits.UART1 = 1; + } else { /* UART2 */ @@ -144,30 +129,20 @@ void uart_init(volatile struct UART_struct *uart, uint32_t baudrate) 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 + UART2->CONbits.TXE = 1; /*< enable transmit */ + UART2->CONbits.RXE = 1; /*< enable receive */ - // u2_tx_head = 0; - //u2_tx_tail = 0; + UART2->CONbits.FCE = 1; /*< enable flowcontrol */ + UART2->CONbits.MRXR = 1; /*< disable Rx interrupt */ + UART2->CTSbits.LVL = 31; /*< drop cts when tx buffer at trigger level */ + GPIO->FUNC_SEL.U2CTS = 1; /*< set GPIO 20 to UART2 CTS */ + GPIO->FUNC_SEL.U2RTS = 1; /*< set GPIO 21 to UART2 RTS */ - //enable_irq(UART2); ITC->INTENABLEbits.UART2 = 1; } uart_set_baudrate(uart, baudrate); + } static inline uint32_t uart0_puts(uint8_t *astring, uint32_t length) @@ -186,17 +161,16 @@ void stdio_flush(void) ITC->INTENABLEbits.UART1 = 0; ITC->INTENABLEbits.UART2 = 0; + while (UART1->RXCON != 0 || UART2->RXCON != 0) { + UART1->DATA; + UART2->DATA; + } + while (UART1->TXCON != 0 || UART2->TXCON != 0) { + /* wait */ + } + 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 - */ } @@ -208,5 +182,4 @@ int fw_puts(char *astring, int 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 cf7f9d0152..690d13d381 100644 --- a/redbee-econotag/drivers/redbee_uart1.c +++ b/redbee-econotag/drivers/redbee_uart1.c @@ -3,8 +3,8 @@ * Copyright (C) 2013 Oliver Hahm * 2013 Thomas Eichinger * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. * * This file is part of RIOT. */ @@ -15,6 +15,8 @@ void uart1_isr(void) { + uint32_t i = 0; + if (UART1->USTATbits.RXRDY == 1) { #ifdef MODULE_UART0 diff --git a/redbee-econotag/drivers/redbee_uart2.c b/redbee-econotag/drivers/redbee_uart2.c index a93c3f7137..013d424159 100644 --- a/redbee-econotag/drivers/redbee_uart2.c +++ b/redbee-econotag/drivers/redbee_uart2.c @@ -3,8 +3,8 @@ * Copyright (C) 2013 Oliver Hahm * 2013 Thomas Eichinger * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. * * This file is part of RIOT. */ @@ -15,7 +15,7 @@ void uart2_isr(void) { - int i = 0; + uint32_t i = 0; if (UART2->USTATbits.RXRDY == 1) { #ifdef MODULE_UART0 diff --git a/redbee-econotag/include/board.h b/redbee-econotag/include/board.h new file mode 100644 index 0000000000..bbcb2b07d3 --- /dev/null +++ b/redbee-econotag/include/board.h @@ -0,0 +1,17 @@ +/** + * board.h - redbee-econotag Board. + * Copyright (C) 2013 Thomas Eichinger + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef REDBEE_ECONOTAG_BOARD_H +#define REDBEE_ECONOTAG_BOARD_H + +#define CTUNE 0xb +#define IBIAS 0x1f +#define FTUNE 0x7 + +#endif + From 5ac8e9a2a55fca5c4e70333d273b37c0937caf29 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Thu, 17 Oct 2013 14:08:17 +0200 Subject: [PATCH 179/188] adjust objcopy flags --- redbee-econotag/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redbee-econotag/Makefile.include b/redbee-econotag/Makefile.include index 8208eeeb71..53a4eec202 100644 --- a/redbee-econotag/Makefile.include +++ b/redbee-econotag/Makefile.include @@ -12,7 +12,7 @@ export CFLAGS_BASIC = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ -ffixed-r8 -ffunction-sections -ffreestanding -fno-builtin \ -nodefaultlibs -Wcast-align -Wall -Wstrict-prototypes -Wextra \ -Os -pipe -# export CFLAGS += $(CFLAGS_BASIC) -mthumb +export CFLAGS += $(CFLAGS_BASIC) -mthumb $(warning TODO add -mthumb) export AFLAGS = -Wa,-gstabs $(CFLAGS) export AS = $(PREFIX)as From 8ae50ef8f460721c38c924204f7a6dca4516b248 Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Mon, 21 Oct 2013 13:06:26 +0200 Subject: [PATCH 180/188] fix: compilation with -mthumb flag for certain files --- redbee-econotag/Makefile | 4 ++-- redbee-econotag/Makefile.include | 4 +--- redbee-econotag/drivers/Makefile | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/redbee-econotag/Makefile b/redbee-econotag/Makefile index ae4ccfd0a7..8b1d55d8b4 100644 --- a/redbee-econotag/Makefile +++ b/redbee-econotag/Makefile @@ -21,8 +21,8 @@ $(BINDIR)$(ARCH): $(OBJ) # compile and generate dependency info $(BINDIR)%.o: %.c - $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o - $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + $(CC) $(CFLAGS) $(CFLAGS_MTHUMB) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(CFLAGS_MTHUMB) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d # remove compilation products diff --git a/redbee-econotag/Makefile.include b/redbee-econotag/Makefile.include index 53a4eec202..19179c3c2d 100644 --- a/redbee-econotag/Makefile.include +++ b/redbee-econotag/Makefile.include @@ -6,13 +6,11 @@ export PREFIX = @arm-none-eabi- export CC = @$(PREFIX)gcc export AR = @$(PREFIX)ar export CFLAGS = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ - -export CFLAGS_BASIC = -std=gnu99 -march=armv4t -mtune=arm7tdmi-s -mlong-calls \ -msoft-float -mthumb-interwork -fno-strict-aliasing -fno-common \ -ffixed-r8 -ffunction-sections -ffreestanding -fno-builtin \ -nodefaultlibs -Wcast-align -Wall -Wstrict-prototypes -Wextra \ -Os -pipe -export CFLAGS += $(CFLAGS_BASIC) -mthumb +export CFLAGS_MTHUMB ?= -mthumb $(warning TODO add -mthumb) export AFLAGS = -Wa,-gstabs $(CFLAGS) export AS = $(PREFIX)as diff --git a/redbee-econotag/drivers/Makefile b/redbee-econotag/drivers/Makefile index 0a40ae1d50..cec1080b64 100644 --- a/redbee-econotag/drivers/Makefile +++ b/redbee-econotag/drivers/Makefile @@ -15,8 +15,8 @@ $(BINDIR)redbee-econotag_common_drivers.a: $(OBJ) # compile and generate dependency info $(BINDIR)%.o: %.c - $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o - $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + $(CC) $(CFLAGS) $(CFLAGS_MTHUMB) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(CFLAGS_MTHUMB) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d @printf "$(BINDIR)" | cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d # remove compilation products From 3362fe1de066df8c6910f687b815e632e98c7ca4 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Sat, 26 Oct 2013 14:45:51 +0200 Subject: [PATCH 181/188] switch thread instead of exiting context lpm_sleep is always being called from within a thread context, not from an isr context, therefore it should use thread_yield instead of cpu_switch_context_exit. --- native/drivers/native-uart0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/drivers/native-uart0.c b/native/drivers/native-uart0.c index 9f77a72d0c..70d545a36b 100644 --- a/native/drivers/native-uart0.c +++ b/native/drivers/native-uart0.c @@ -66,7 +66,7 @@ void _native_handle_uart0_input() uart0_notify_thread(); _native_in_isr = 0; - cpu_switch_context_exit(); + thread_yield(); } int _native_set_uart_fds(void) From 1e19ca247a4507f2895eace9f1dd76cea8e97b2c Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Sat, 26 Oct 2013 20:06:35 +0200 Subject: [PATCH 182/188] handle stdin EOF --- native/drivers/native-uart0.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/native/drivers/native-uart0.c b/native/drivers/native-uart0.c index 70d545a36b..b9d8b041d3 100644 --- a/native/drivers/native-uart0.c +++ b/native/drivers/native-uart0.c @@ -60,6 +60,14 @@ void _native_handle_uart0_input() if (nread == -1) { err(1, "_native_handle_uart0_input(): read()"); } + else if (nread == 0) { + /* XXX: + * preliminary resolution for this situation, will be coped + * with properly in #161 */ + close(_native_uart_in); + _native_uart_in = -1; + warnx("stdin closed"); + } for(int pos = 0; pos < nread; pos++) { uart0_handle_incoming(buf[pos]); } From ec3234a8f77f7f107f057aed802d3fd31239d961 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 28 Oct 2013 23:01:45 +0100 Subject: [PATCH 183/188] fixed missing stdint includes for all platforms * plus some minor include and prototype fixes for wsn430 --- avsextrem/include/board.h | 2 +- chronos/include/board.h | 1 + msb-430-common/include/board-conf.h | 2 ++ msb-430/Makefile.include | 1 + msb-430/include/board.h | 2 ++ msb-430h/include/board.h | 1 + msba2-common/include/msba2_common.h | 3 ++- msba2/include/board.h | 4 ++-- native/include/board.h | 2 ++ olimex_lpc2148/include/board.h | 3 ++- telosb/include/board.h | 1 + wsn430-common/Makefile.include | 2 +- wsn430-common/board_init.c | 2 ++ wsn430-common/include/board-conf.h | 2 ++ wsn430-v1_3b/Makefile.include | 3 ++- wsn430-v1_3b/include/board.h | 2 ++ wsn430-v1_4/Makefile | 1 - wsn430-v1_4/Makefile.include | 3 ++- wsn430-v1_4/include/board.h | 2 ++ 19 files changed, 30 insertions(+), 9 deletions(-) diff --git a/avsextrem/include/board.h b/avsextrem/include/board.h index ac3cfd7717..59d321d2f6 100644 --- a/avsextrem/include/board.h +++ b/avsextrem/include/board.h @@ -24,7 +24,7 @@ #ifndef BOARDCONF_H_ #define BOARDCONF_H_ #include - +#include "msba2-common.h" #define FEUERWARE_CONF_BOARD_NAME "FU Berlin AVSEXTREM BOARD" diff --git a/chronos/include/board.h b/chronos/include/board.h index f4230f7a8d..c07dd4f00e 100644 --- a/chronos/include/board.h +++ b/chronos/include/board.h @@ -1,6 +1,7 @@ #ifndef _MSB_BOARD_H #define _MSB_BOARD_H +#include #include #define MSP430_INITIAL_CPU_SPEED 7372800uL diff --git a/msb-430-common/include/board-conf.h b/msb-430-common/include/board-conf.h index 9db51d9454..5a9d5b1dd0 100644 --- a/msb-430-common/include/board-conf.h +++ b/msb-430-common/include/board-conf.h @@ -1,6 +1,8 @@ #ifndef BOARD_CONF_H #define BOARD_CONF_H +#include + #define INFOMEM (0x1000) #endif /* BOARD-CONF_H */ diff --git a/msb-430/Makefile.include b/msb-430/Makefile.include index c42b46b063..e2a5fb3e39 100644 --- a/msb-430/Makefile.include +++ b/msb-430/Makefile.include @@ -1 +1,2 @@ +export INCLUDES += -I$(RIOTBOARD)/msb-430h/include -I$(RIOTBOARD)/msb-430-common/include include $(RIOTBOARD)/msb-430-common/Makefile.include diff --git a/msb-430/include/board.h b/msb-430/include/board.h index 286de9fc59..e7968f4499 100644 --- a/msb-430/include/board.h +++ b/msb-430/include/board.h @@ -48,6 +48,8 @@ and the mailinglist (subscription via web site) * @note $Id$ */ +#include "board-conf.h" + //MSB430 core #define MSP430_INITIAL_CPU_SPEED 2457600uL #define MSP430_HAS_DCOR 1 diff --git a/msb-430h/include/board.h b/msb-430h/include/board.h index fe8d49abb6..fc086d53cb 100644 --- a/msb-430h/include/board.h +++ b/msb-430h/include/board.h @@ -65,6 +65,7 @@ and the mailinglist (subscription via web site) #define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED #include +#include "board-conf.h" typedef uint8_t radio_packet_length_t; diff --git a/msba2-common/include/msba2_common.h b/msba2-common/include/msba2_common.h index fff12f965d..4e56c82ab7 100644 --- a/msba2-common/include/msba2_common.h +++ b/msba2-common/include/msba2_common.h @@ -43,7 +43,8 @@ and the mailinglist (subscription via web site) * @note $Id$ */ -#include +#include +#include "lpc2387.h" #define VICIntEnClear VICIntEnClr diff --git a/msba2/include/board.h b/msba2/include/board.h index fc16380df8..829715b3c2 100644 --- a/msba2/include/board.h +++ b/msba2/include/board.h @@ -1,8 +1,8 @@ #ifndef __BOARD_H #define __BOARD_H -#include -#include +#include "msba2_common.h" +#include "bitarithm.h" #define LED_RED_PIN (BIT25) #define LED_GREEN_PIN (BIT26) diff --git a/native/include/board.h b/native/include/board.h index 9665094f37..349c17cfdb 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -15,6 +15,8 @@ * @} */ +#include + void _native_LED_GREEN_OFF(void); #define LED_GREEN_OFF (_native_LED_GREEN_OFF()) void _native_LED_GREEN_ON(void); diff --git a/olimex_lpc2148/include/board.h b/olimex_lpc2148/include/board.h index c79b46b368..ff961ea366 100644 --- a/olimex_lpc2148/include/board.h +++ b/olimex_lpc2148/include/board.h @@ -1,3 +1,4 @@ -#include +#include +#include "lpc2148.h" typedef uint8_t radio_packet_length_t; diff --git a/telosb/include/board.h b/telosb/include/board.h index 5fc3151e9c..55fd2a35b4 100644 --- a/telosb/include/board.h +++ b/telosb/include/board.h @@ -52,6 +52,7 @@ #define LED_BLUE_OFF LEDS_PxOUT |= LEDS_CONF_BLUE #define LED_BLUE_TOGGLE LEDS_PxOUT ^= LEDS_CONF_BLUE +#include #include typedef uint8_t radio_packet_length_t; diff --git a/wsn430-common/Makefile.include b/wsn430-common/Makefile.include index f1cde0aab9..8a16ab54a0 100644 --- a/wsn430-common/Makefile.include +++ b/wsn430-common/Makefile.include @@ -20,6 +20,6 @@ endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" -export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ +export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ -I$(RIOTBASE)/sys/net/ieee802154/include/ export OFLAGS = -O ihex diff --git a/wsn430-common/board_init.c b/wsn430-common/board_init.c index 986a8ed10f..9b84c699bc 100644 --- a/wsn430-common/board_init.c +++ b/wsn430-common/board_init.c @@ -14,6 +14,8 @@ volatile static uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; +void msp430_init_dco(void); + typedef enum { MCLK_2MHZ_SCLK_1MHZ = 1000002uL, MCLK_4MHZ_SCLK_1MHZ = 1000004uL, diff --git a/wsn430-common/include/board-conf.h b/wsn430-common/include/board-conf.h index 7ebf0e03e6..e54b3d58eb 100644 --- a/wsn430-common/include/board-conf.h +++ b/wsn430-common/include/board-conf.h @@ -8,6 +8,8 @@ #ifndef BOARD_CONF_H #define BOARD_CONF_H +#include + #define INFOMEM (0x1000) #endif /* BOARD-CONF_H */ diff --git a/wsn430-v1_3b/Makefile.include b/wsn430-v1_3b/Makefile.include index 366d6cbcc8..267a2fb9cd 100644 --- a/wsn430-v1_3b/Makefile.include +++ b/wsn430-v1_3b/Makefile.include @@ -1,3 +1,4 @@ +export INCLUDES += -I$(RIOTBOARD)/wsn430-common/include include $(RIOTBOARD)/$(BOARD)/Makefile.dep -include $(RIOTBOARD)/wsn430-common/Makefile.include \ No newline at end of file +include $(RIOTBOARD)/wsn430-common/Makefile.include diff --git a/wsn430-v1_3b/include/board.h b/wsn430-v1_3b/include/board.h index 466df39adc..9a23fdf8d7 100644 --- a/wsn430-v1_3b/include/board.h +++ b/wsn430-v1_3b/include/board.h @@ -31,6 +31,8 @@ * @note $Id$ */ +#include "board-conf.h" + //MSB430 core #define MSP430_INITIAL_CPU_SPEED 800000uL #define MSP430_HAS_DCOR 0 diff --git a/wsn430-v1_4/Makefile b/wsn430-v1_4/Makefile index d6b578d59f..5e426ffbd9 100644 --- a/wsn430-v1_4/Makefile +++ b/wsn430-v1_4/Makefile @@ -9,7 +9,6 @@ INCLUDES += -I${RIOTBASE}/core/include/ INCLUDES += -Iinclude/ -I$(RIOTBOARD)/wsn430-common/include/ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include -INCLUDES += -I$(RIOTBASE)/sys/net/ all: $(BINDIR)$(ARCH) $(MAKE) -C ../wsn430-common diff --git a/wsn430-v1_4/Makefile.include b/wsn430-v1_4/Makefile.include index 366d6cbcc8..267a2fb9cd 100644 --- a/wsn430-v1_4/Makefile.include +++ b/wsn430-v1_4/Makefile.include @@ -1,3 +1,4 @@ +export INCLUDES += -I$(RIOTBOARD)/wsn430-common/include include $(RIOTBOARD)/$(BOARD)/Makefile.dep -include $(RIOTBOARD)/wsn430-common/Makefile.include \ No newline at end of file +include $(RIOTBOARD)/wsn430-common/Makefile.include diff --git a/wsn430-v1_4/include/board.h b/wsn430-v1_4/include/board.h index 5ffbf8049a..092bc76998 100644 --- a/wsn430-v1_4/include/board.h +++ b/wsn430-v1_4/include/board.h @@ -31,6 +31,8 @@ * @note $Id$ */ +#include "board-conf.h" + //MSB430 core #define MSP430_INITIAL_CPU_SPEED 800000uL #define MSP430_HAS_DCOR 0 From 6d109e984935c0a928cb63dc5710fd13ebc68d17 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 29 Oct 2013 16:34:59 +0100 Subject: [PATCH 184/188] added missing header guard to native board.h --- native/include/board.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/native/include/board.h b/native/include/board.h index 349c17cfdb..f1dca63e6a 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -1,3 +1,6 @@ +#ifndef BOARD_H +#define BOARD_H + /** * Native Board interface * @@ -31,3 +34,4 @@ void _native_LED_RED_TOGGLE(void); #define LED_RED_TOGGLE (_native_LED_RED_TOGGLE()) typedef uint16_t radio_packet_length_t; +#endif /* BOARD_H */ From 745fb5e52fb086309e649e79c2a5c890eb263365 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 1 Nov 2013 11:11:21 +0100 Subject: [PATCH 185/188] Fixed typo in avsextre/include/board.h include --- avsextrem/include/board.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avsextrem/include/board.h b/avsextrem/include/board.h index 59d321d2f6..4370382942 100644 --- a/avsextrem/include/board.h +++ b/avsextrem/include/board.h @@ -24,7 +24,7 @@ #ifndef BOARDCONF_H_ #define BOARDCONF_H_ #include -#include "msba2-common.h" +#include "msba2_common.h" #define FEUERWARE_CONF_BOARD_NAME "FU Berlin AVSEXTREM BOARD" From a5b42fe14a38ee7bf3220eeb4612bb94f5dfc093 Mon Sep 17 00:00:00 2001 From: authmillenon Date: Sun, 3 Nov 2013 16:08:55 +0100 Subject: [PATCH 186/188] Changes according PR #282 --- telosb/Makefile | 2 +- wsn430-common/Makefile.include | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/telosb/Makefile b/telosb/Makefile index 4f9b220a4a..c5eb97b3bc 100644 --- a/telosb/Makefile +++ b/telosb/Makefile @@ -9,7 +9,7 @@ INCLUDES += -I${RIOTBOARD}/${BOARD}/include/ INCLUDES += -I${RIOTBASE}/core/include/ INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include -INCLUDES += -I$(RIOTBASE)/sys/net/ +INCLUDES += -I$(RIOTBASE)/sys/net/include all: $(BINDIR)$(ARCH) diff --git a/wsn430-common/Makefile.include b/wsn430-common/Makefile.include index 8a16ab54a0..346044a309 100644 --- a/wsn430-common/Makefile.include +++ b/wsn430-common/Makefile.include @@ -20,6 +20,6 @@ endif export HEXFILE = bin/$(PROJECT).hex export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" -export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ -I$(RIOTBASE)/sys/net/ieee802154/include/ +export INCLUDES += -I $(RIOTCPU)/msp430-common/include/ -I$(RIOTBASE)/sys/net/include/ export OFLAGS = -O ihex From f0477062172f949aa76f0202b29e66784cbd94ed Mon Sep 17 00:00:00 2001 From: Thomas Eichinger Date: Wed, 6 Nov 2013 12:42:39 +0100 Subject: [PATCH 187/188] mc1322x moved radio implementation --- redbee-econotag/drivers/include/maca.h | 531 -------- redbee-econotag/drivers/include/maca_packet.h | 44 - redbee-econotag/drivers/maca.c | 1064 ----------------- 3 files changed, 1639 deletions(-) delete mode 100644 redbee-econotag/drivers/include/maca.h delete mode 100644 redbee-econotag/drivers/include/maca_packet.h delete mode 100644 redbee-econotag/drivers/maca.c diff --git a/redbee-econotag/drivers/include/maca.h b/redbee-econotag/drivers/include/maca.h deleted file mode 100644 index bb1ca3326a..0000000000 --- a/redbee-econotag/drivers/include/maca.h +++ /dev/null @@ -1,531 +0,0 @@ -/* - * maca.h - The MACA driver for the Redbee EconoTag - * Copyright (C) 2013 Thomas Eichinger - * - * 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 MACA_H_ -#define MACA_H_ - -#include "maca_packet.h" -#include - -/*********************************************************/ -/* function definitions */ -/*********************************************************/ - -/* functions for the initialization and turning on and off of the MACA */ -void maca_init ( void ); -void maca_on ( void ); -void maca_off ( void ); - -/* function to check if MACA is running right */ -void maca_check ( void ); - -/* functions to configure MACA */ -void maca_set_power ( uint8_t power ); -void maca_set_channel ( uint8_t channel ); -uint16_t maca_set_address ( uint16_t addr ); -uint16_t maca_get_address ( void ); - -/* get Link Quality Indicator */ -extern uint8_t (*get_lqi) ( void ); - - -/* interface to configure demodulator */ -#define MACA_DEMOD_DCD 1 /* -96dBm, 22.2mA */ -#define MACA_DEMOD_NCD 0 /* -100dBm, 24.2mA */ -void set_demodulator_type ( uint8_t type ); - -/* macro for setting checksum filtering */ -extern volatile uint8_t fcs_mode; -#define MACA_SET_FCS_MODE(x) fcs_mode = (x) - -/* MACA_SET_PRM_MODE(PROMISC) to disable address filtering */ -/* MACA_SET_PRM_MODE(AUTOACK) to enable address filtering AND autoack */ -extern volatile uint8_t prm_mode; -#define MACA_SET_PRM_MODE(x) prm_mode = (x) - -/* functions working on maca_packet_t */ -void maca_set_tx_packet ( volatile maca_packet_t *packet ); -volatile maca_packet_t* maca_get_rx_packet ( void ); -volatile maca_packet_t* maca_get_free_packet ( void ); -void maca_free_packet ( volatile maca_packet_t *packet ); -void maca_free_all_packets ( void ); - -extern volatile maca_packet_t *maca_rx_head, *maca_tx_head; -extern volatile uint32_t maca_entry; - -extern void maca_rx_callback ( volatile maca_packet_t *packet ) __attribute__((weak)); -extern void maca_tx_callback ( volatile maca_packet_t *packet ) __attribute__((weak)); - -/* internal lowlevel MACA functions */ -void _maca_reset ( void ); -void _maca_init_phy ( void ); -void _maca_flyback_init ( void ); -void _maca_resume_maca_sync ( void ); -void _maca_radio_init ( void ); -uint32_t _maca_init_from_flash ( uint32_t address ); - -#define MACA_MAX_PACKET_SIZE (MACA_MAX_PAYLOAD_SIZE + 2) /* +2 for checksum */ - -/*********************************************************/ -/* register definitions */ -/*********************************************************/ - -#define MACA_BASE_ADDRESS (0x80004000) - -struct MACA_struct { - union { - // Reset the MACA Module - uint32_t RESET; - struct MACA_RESET { - uint32_t RST:1; // MACA Reset - uint32_t CLK_ON:1; // MACA Clk on/off - uint32_t :30; - } RESETbits; - }; - union { - // Write: random generator seed - // Read: get random data - uint32_t RANDOM; - struct MACA_RANDOM { - uint32_t :32; - } RANDOMbits; - }; - union { - // Control register of the MACA - uint32_t CONTROL; - struct MACA_CONTROL { - uint32_t SEQUENCE :3; // set new mode of operation (see MACA_CONTROL_SEQUENCE_*) - uint32_t MODE :2; // transmission access mode (see MACA_CONTROL_MODE_*) - uint32_t TM :1; // test mode (see MACA_CONTROL_TM_*) - uint32_t :1; // LFSR reserved - uint32_t AUTO :1; // restart Rx automatically (see MACA_CONTROL_AUTO_*) - uint32_t BCN :1; // filter beacon only (see MACA_CONTROL_BCN_*) - uint32_t ASAP :1; // start action sequence ASAP (see MACA_CONTROL_ASAP_*) - uint32_t REL :1; // clk selector (see MACA_CONTROL_REL_*) - uint32_t PRM :1; // promiscuous mode (see MACA_CONTROL_PRM_*) - uint32_t NOFC :1; // no frame check (see MACA_CONTROL_NOFC_*) - uint32_t ROLE :1; // current role - uint32_t :1; // reserved - uint32_t RSTO :1; // reset slot offset (see MACA_CONTROL_RSTO_*) - uint32_t PRE_COUNT :4; // preamble repeat counter (btween 0-15) - uint32_t ISM :1; // ISM reserved - uint32_t :11; - } CONTROLbits; - }; - union { - uint32_t STATUS; - struct - { - uint32_t COMPLETE_CODE :4; // complete code (see MACA_STATUS_COMPLETECODE_*) - uint32_t :8; // reserved - uint32_t OVR :1; // Rx buffer overrun (see MACA_STATUS_OVR_*) - uint32_t BUSY :1; // channel busy detection (see MACA_STATUS_BUSY_*) - uint32_t CRC :1; // checksum failed (see MACA_STATUS_CRC_*) - uint32_t TO :1; // time-out (see MACA_STATUS_TO_*) - uint32_t :16; // reserved - } STATUSbits; - }; - union { - uint32_t FRMPND; - struct - { - uint32_t PND :1; // Ack Frame Pending Status (see MACA_FRMPND_PND_*) - uint32_t :31; // reserved - }FRMPNbits; - }; - union { - uint32_t MC1322x_ID; - struct - { - uint32_t MC1322x_ID :8; // the 9bit MC1322x ID (see MACA_MC1322x_ID_*) - uint32_t :24; // reserved - }MC1322x_IDbits; - }; - union { - uint32_t TMREN; - struct - { - uint32_t STRT :1; // enable start clk circuit (see MACA_TMREN_STRT_*) - uint32_t CPL :1; // enable complete clk circuit (see MACA_TMREN_CPL_*) - uint32_t SFT :1; // enable soft complete clk circ (see MACA_TMREN_SFT_*) - uint32_t :29; // reserved - }TMRENbits; - }; - union { - uint32_t TMRDIS; - struct - { - uint32_t STRT :1; // disable start clk circuit (see MACA_TMRDIS_STRT_*) - uint32_t CPL :1; // disable complete clk circuit (see MACA_TMRDIS_CPL_*) - uint32_t SFT :1; // disable soft complete clk circ (see MACA_TMRDIS_SFT_*) - uint32_t STRT_OFF :1; // abort start clk (see MACA_TMRDIS_STRTOFF_*) - uint32_t CPL_OFF :1; // abort complete clk (see MACA_TMRDIS_CPLOFF_*) - uint32_t SFT_OFF :1; // abort soft complete clk (see MACA_TMRDIS_SFT_OFF_*) - uint32_t :26; // reserved - }TMRDISbits; - }; - uint32_t CLK; // sets a new absolute clock value - // Ensure that the timers are not active - uint32_t STARTCLK; // see (9.7.10) - uint32_t CPLCLK; // see (9.7.11) - uint32_t SFTCLK; // see (9.7.12) - uint32_t CLKOFFSET; // see (9.7.13) - uint32_t RELCLK; // see (9.7.14) - uint32_t CPLTIM; // see (9.7.15) - union { - uint32_t SLOTOFFSET; // see (9.7.16) - struct - { - uint32_t TX_SLOT_OFFSET :12; - uint32_t :4; - uint32_t RX_SLOT_OFFSEt :12; - uint32_t :4; - }SLOTOFFSETbits; - }; - uint32_t TIMESTAMP; // see (9.7.17) - uint32_t DMARX; // see (9.7.18) - uint32_t DMATX; // see (9.7.19) - uint32_t DMAPOLL; // see (9.7.20) - union { - uint32_t TXLEN; // see (9.7.21) - struct - { - uint32_t TX_LEN :15; // Tx payload length - uint32_t :17; // reserved - }TXLENbits; - }; - union { - uint32_t TXSEQNR; // see (9.7.22) - struct - { - uint32_t TXSEQN :8; // Tx sequ. number - uint32_t :24; // reserved - }TXSEQNRbits; - }; - union { - uint32_t SETRXLVL; // see (9.7.23) - struct - { - uint32_t FIFO_LVL :16; // FIFO level - uint32_t :16; // reserved - }SETRXLVLbits; - }; - union { - uint32_t GETRXLVL; // see (9.7.24) - struct - { - uint32_t RECVBYTES :16; // received bytes - uint32_t :16; // reserved - }GETRXLVLbits; - }; - union { - uint32_t IRQ; // read only see (9.7.25) - struct - { - uint32_t ACPL :1; // Action Complete Interrupt - uint32_t POLL :1; // Poll Indication Interrupt - uint32_t DI :1; // Data Indication Interrupt - uint32_t :6; // reserved - uint32_t LVL :1; // FIFO Level Interrupt - uint32_t SFT :1; // Soft Complete Clk Interrupt - uint32_t FLT :1; // Filter Failed Interrupt - uint32_t CRC :1; // Checksum Failed Interrupt - uint32_t CM :1; // Complete Clock Interrupt - uint32_t SYNC :1; // Sync Detected Interrupt - uint32_t STRT :1; // Action Started Interrupt - uint32_t :16; // reserved - }IRQbits; - }; - union { - uint32_t CLRIRQ; // write only see (9.7.26) - // write 1 to clear - struct - { - uint32_t ACPL :1; // Clear Action Complete Interrupt - uint32_t POLL :1; // Clear Poll Indication Interrupt - uint32_t DI :1; // Clear Data Indication Interrupt - uint32_t :6; // reserved - uint32_t LVL :1; // Clear FIFO Level Interrupt - uint32_t SFT :1; // Clear Soft Complete Clk Interrupt - uint32_t FLT :1; // Clear Filter Failed Interrupt - uint32_t CRC :1; // Clear Checksum Failed Interrupt - uint32_t CM :1; // Clear Complete Clock Interrupt - uint32_t SYNC :1; // Clear Sync Detected Interrupt - uint32_t STRT :1; // Clear Action Started Interrupt - uint32_t :16; // reserved - }CLRIRQbits; - }; - union { - uint32_t SETIRQ; // write only see (9.7.27) - // write 1 to set IRQ - struct - { - uint32_t ACPL :1; // Trigger Action Complete Interrupt - uint32_t POLL :1; // Trigger Poll Indication Interrupt - uint32_t DI :1; // Trigger Data Indication Interrupt - uint32_t :6; // reserved - uint32_t LVL :1; // Trigger FIFO Level Interrupt - uint32_t SFT :1; // Trigger Soft Complete Clk Interrupt - uint32_t FLT :1; // Trigger Filter Failed Interrupt - uint32_t CRC :1; // Trigger Checksum Failed Interrupt - uint32_t CM :1; // Trigger Complete Clock Interrupt - uint32_t SYNC :1; // Trigger Sync Detected Interrupt - uint32_t STRT :1; // Trigger Action Started Interrupt - uint32_t :16; // reserved - }SETIRQbits; - }; - union { - uint32_t MASKIRQ; // write only see (9.7.28) - // write 1 to enable IRQ - struct - { - uint32_t ACPL :1; // Enable Action Complete Interrupt - uint32_t POLL :1; // Enable Poll Indication Interrupt - uint32_t DI :1; // Enable Data Indication Interrupt - uint32_t WU :1; // reserved but needed?? - uint32_t RST :1; // reserved but needed?? - uint32_t :4; // reserved - uint32_t LVL :1; // Enable FIFO Level Interrupt - uint32_t SFT :1; // Enable Soft Complete Clk Interrupt - uint32_t FLT :1; // Enable Filter Failed Interrupt - uint32_t CRC :1; // Enable Checksum Failed Interrupt - uint32_t CM :1; // Enable Complete Clock Interrupt - uint32_t SYNC :1; // Enable Sync Detected Interrupt - uint32_t STRT :1; // Enable Action Started Interrupt - uint32_t :16; // reserved - }MASKIRQbits; - }; - union { - uint32_t MACPANID; // see (9.7.29) - struct - { - uint32_t PANID :16; // MAC PAN ID for the 802.15.4 std network - } MACPANIDbits; - }; - union { - uint32_t MAC16ADDR; // see (9.7.30) - struct - { - uint32_t ADDR :16; // reflects the MAC short address - } MAC16ADDRbits; - }; - uint32_t MAC64HI; // see (9.7.31) - uint32_t MAC64LO; // see (9.7.32) - union { - uint32_t FLTREJ; // see (9.7.33) - struct - { - uint32_t BCN :1; // Reject Beacon packets - uint32_t DATA :1; // Reject Data packets - uint32_t ACK :1; // Reject ACK packets - uint32_t CMD :1; // Reject MAC CMD packets - uint32_t :4; // reserved - uint32_t POLL :1; // Accept POLL packets - uint32_t :7; // reserved - uint32_t FC_MASK :16; // Frame Control Mask - }FLTREJbits; - }; - union { - uint32_t CLKDIV; // see (9.7.34) - struct - { - uint32_t Divider :16; // prescale value for the MACA transmit clk - uint32_t :16; // reserved - }CLKDIVbits; - }; - union { - uint32_t WARMUP; // see (9.7.35) - struct - { - uint32_t Rx_WARMUP :12; // receiver warmup time - uint32_t :4; // reserved - uint32_t Tx_WARMUP :12; // transmitter warmuptime - uint32_t :4; // reserved - }WARMUPbits; - }; - uint32_t PREAMBLE; // see (9.7.36) - uint32_t FRAMESYNC0; // see (9.7.37) - uint32_t FRAMESYNC1; // see (9.7.38) - union { - uint32_t TXACKDELAY; // see (9.7.39) - struct - { - uint32_t TXACKDELAY :12; // Tx Acknowledgement Delay - uint32_t :4; // reserved - uint32_t TXPOLLDELAY :12; // Tx Poll Delay - uint32_t :4; // reserved - }TXACKDELAYbits; - }; - union { - uint32_t RXACKDELAY; // see (9.7.40) - struct - { - uint32_t RXACKDELAY :12; // Rx Acknowledgement Delay - uint32_t :4; // reserved - uint32_t RXAUTODELAY :12; // time to disable receiver before restarting - uint32_t :4; // reserved - }RXACKDELAYbits; - }; - union { - uint32_t EOFDELAY; // see (9.7.41) - struct - { - uint32_t EOFDELAY :12; // End Of Frame Delay - uint32_t :20; // reserved - }EOFDELAYbits; - }; - union { - uint32_t CCADELAY; // see (9.7.42) - struct - { - uint32_t CCADELAY :12; // CCA Delay - uint32_t :4; // reserved - uint32_t CCALENGTH :12; // Length of time to perform CCA - uint32_t :4; // reserved - }CCADELAYbits; - }; - union { - uint32_t RXEND; // see (9.7.43) - struct - { - uint32_t RXACK_END :12; // Rx Acknowledgement Window End in Normal Mode - uint32_t :4; // reserved - uint32_t RXSLOTTED_END :12; // Rx Acknowledgement Window End in slotted CSMA-CA mode - uint32_t :4; // reserved - }RXENDbits; - }; - union { - uint32_t TXCCADELAY; // see (9.7.44) - struct - { - uint32_t TXCCADELAY :12; // Delay from end of CCA to Tx start - uint32_t :20; // reserved - }TXCCADELAYbits; - }; - uint32_t KEY3; // see (9.7.45) - uint32_t KEY2; // see (9.7.45) - uint32_t KEY1; // see (9.7.45) - uint32_t KEY0; // see (9.7.45) - union { - uint32_t OPTIONS; // see (9.7.46) - struct - { - uint32_t POLL :1; // enables writing to DMAPOLL - uint32_t PLL_TX :1; // responde to PLL unlock only while transmition - uint32_t PLL_IGNORE :1; // ignore PLL unlock signal - uint32_t SEED_KEY :1; // generation can be seeded - uint32_t :28; // reserved - }OPTIONSbits; - }; - -}; - -static volatile struct MACA_struct * const MACA = (void *) (MACA_BASE_ADDRESS + 0x04); // +4 because base + 0x00 is reserved - -#define MACA_CONTROL_SEQUENCE_NOP 0 -#define MACA_CONTROL_SEQUENCE_ABORT 1 -#define MACA_CONTROL_SEQUENCE_WAIT 2 -#define MACA_CONTROL_SEQUENCE_TX 3 -#define MACA_CONTROL_SEQUENCE_RX 4 -#define MACA_CONTROL_SEQUENCE_TXPOLL 5 -#define MACA_CONTROL_SEQUENCE_CCA 6 -#define MACA_CONTROL_SEQUENCE_ED 7 - -#define MACA_CONTROL_MODE_NOCCA 0 -#define MACA_CONTROL_MODE_NONSLOTTED_CSMACA 1 -#define MACA_CONTROL_MODE_SLOTTED_CSMACA 2 -#define MACA_CONTROL_MODE_RESERVED 3 - -#define MACA_CONTROL_TM_NORMAL 0 -#define MACA_CONTROL_TM_TM 1 - -#define MACA_CONTROL_AUTO_OFF 0 -#define MACA_CONTROL_AUTO_ON 1 - -#define MACA_CONTROL_BCN_OFF 0 -#define MACA_CONTROL_BCN_ON 1 - -#define MACA_CONTROL_ASAP_OFF 0 -#define MACA_CONTROL_ASAP_ON 1 - -#define MACA_CONTROL_REL_ABSOLUTE 0 -#define MACA_CONTROL_REL_RELATIVE 1 - -#define MACA_CONTROL_PRM_OFF 0 -#define MACA_CONTROL_PRM_ON 1 - -#define MACA_CONTROL_NOFC_OFF 0 -#define MACA_CONTROL_USE_FCS 0 -#define MACA_CONTROL_NOFC_ON 1 -#define MACA_CONTROL_NO_FCS 1 - -#define MACA_CONTROL_ROLE_NOPAN 0 -#define MACA_CONTROL_ROLE_PAN 1 - -#define MACA_CONTROL_RSTO_DONOT_RST 0 -#define MACA_CONTROL_RSTO_DO_RST 1 - -#define MACA_STATUS_COMPLETECODE_SUCCESS 0 -#define MACA_STATUS_COMPLETECODE_TIMEOUT 1 -#define MACA_STATUS_COMPLETECODE_CHANBUSY 2 -#define MACA_STATUS_COMPLETECODE_CRC_FAIL 3 -#define MACA_STATUS_COMPLETECODE_ABORTED 4 -#define MACA_STATUS_COMPLETECODE_NOACK 5 -#define MACA_STATUS_COMPLETECODE_NODATA 6 -#define MACA_STATUS_COMPLETECODE_LATESTART 7 -#define MACA_STATUS_COMPLETECODE_EXTTIMEOUT 8 -#define MACA_STATUS_COMPLETECODE_EXTPNDTIMEOUT 9 -#define MACA_STATUS_COMPLETECODE_PLLUNLOCK 12 -#define MACA_STATUS_COMPLETECODE_EXTABORT 13 -#define MACA_STATUS_COMPLETECODE_NOTCOMPLETE 14 -#define MACA_STATUS_COMPLETECODE_DMABUSERROR 15 - -#define MACA_STATUS_OVR_FALSE 0 -#define MACA_STATUS_OVR_TRUE 1 - -#define MACA_STATUS_BUSY_FALSE 0 -#define MACA_STATUS_BUSY_TRUE 1 - -#define MACA_STATUS_CRC_OK 0 -#define MACA_STATUS_CRC_ERROR 1 - -#define MACA_STATUS_TO_FALSE 0 -#define MACA_STATUS_TO_TRUE 1 - -#define MACA_FRMPND_PND_NODATA 0 -#define MACA_FRMPND_PND_DATAAVAIL 1 - -#define MACA_MC1322x_ID_ENGINEERING 0 -#define MACA_MC1322x_ID_MC13224_1 1 -#define MACA_MC1322x_ID_MC13224_2 9 -#define MACA_MC1322x_ID_MC13226 17 - - -#define MACA_TMREN_STRT_ENABLE 1 - -#define MACA_TMREN_CPL_ENABLE 1 - -#define MACA_TMREN_SFT_ENABLE 1 - -#define MACA_TMRDIS_STRT_DISABLE 1 - -#define MACA_TMRDIS_CPL_DISABLE 1 - -#define MACA_TMRDIS_SFT_DISABLE 1 - -#define MACA_TMRDIS_STRTOFF_ABORT 1 - -#define MACA_TMRDIS_CPLOFF_ABORT 1 - -#define MACA_TMRDIS_SFTOFF_ABORT 1 - - - -#endif // MACA_H_ \ No newline at end of file diff --git a/redbee-econotag/drivers/include/maca_packet.h b/redbee-econotag/drivers/include/maca_packet.h deleted file mode 100644 index 11c4c1b0f7..0000000000 --- a/redbee-econotag/drivers/include/maca_packet.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * maca_packet.h - defines a rxtx packet for the MACA driver - * Copyright (C) 2013 Thomas Eichinger - * - * 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 PACKET_H -#define PACKET_H - -#include - -/* does not include 2 byte FCS checksum */ -#ifndef MACA_MAX_PAYLOAD_SIZE -#define MACA_MAX_PAYLOAD_SIZE 125 -#endif - -#define PACKET_STATS 0 - -struct packet { - uint8_t length; /*< does not include FCS checksum */ - volatile struct packet * left; - volatile struct packet * right; - /* offset into data for first byte of the packet payload */ - /* On TX this should be 0 */ - /* On RX this should be 1 since the maca puts the length as the first byte*/ - uint8_t offset; - uint8_t lqi; - uint8_t status; - uint32_t rx_time; - #if PACKET_STATS - uint8_t seen; - uint8_t post_tx; - uint8_t get_free; - uint8_t rxd; - #endif - uint8_t data[MACA_MAX_PAYLOAD_SIZE+2+1]; /* +2 for FCS; + 1 since maca returns the length as the first byte */ -}; -typedef struct packet maca_packet_t; - -#endif \ No newline at end of file diff --git a/redbee-econotag/drivers/maca.c b/redbee-econotag/drivers/maca.c deleted file mode 100644 index befbc3c7fa..0000000000 --- a/redbee-econotag/drivers/maca.c +++ /dev/null @@ -1,1064 +0,0 @@ -/* - * maca.c - The MACA driver for the Redbee EconoTag - * Copyright (C) 2013 Thomas Eichinger - * - * 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 "maca.h" -#include "maca_packet.h" -#include "nvm.h" -#include "mc1322x.h" -#include - -// number of packets in the maca_packet_pool -#ifndef MACA_NUM_PACKETS -#define MACA_NUM_PACKETS 32 -#endif - -/* for 250kHz clock */ -#define MACA_CLOCK_DIV 95 -/* (32 chips/sym) * (sym/4bits) * (8bits/byte) = (64 chips/byte) */ -/* (8 chips/clk) * (byte/64 chips) = byte/8clks */ -#define CLK_PER_BYTE 8 - -#ifndef RECV_SOFTIMEOUT -#define RECV_SOFTIMEOUT (1024*128*CLK_PER_BYTE) -#endif - -#ifndef CPL_TIMEOUT -#define CPL_TIMEOUT (2*128*CLK_PER_BYTE) -#endif - - - -static volatile maca_packet_t maca_packet_pool[MACA_NUM_PACKETS]; - -static volatile maca_packet_t *maca_free_head; -static volatile maca_packet_t *maca_rx_end; -static volatile maca_packet_t *maca_tx_end; -static volatile maca_packet_t *maca_dma_tx; -static volatile maca_packet_t *maca_dma_rx; - -volatile maca_packet_t *maca_rx_head; -volatile maca_packet_t *maca_tx_head; - -static volatile maca_packet_t maca_dummy_ack; - -uint8_t (*get_lqi)(void) = (void *) 0x0000e04d; - -#define MACA_NO_POST 0 -#define MACA_TX_POST 1 -#define MACA_RX_POST 2 -#define MACA_MAX_POST 3 -static volatile uint8_t maca_last_post = MACA_NO_POST; - -void maca_init ( void ) { - _maca_reset(); - _maca_radio_init(); - _maca_flyback_init(); - _maca_init_phy(); - maca_set_channel ( 0 ); - maca_set_power ( 0 ); - - maca_free_head = 0; - maca_tx_head = 0; - maca_rx_head = 0; - maca_rx_end = 0; - maca_tx_end = 0; - maca_dma_rx = 0; - maca_dma_tx = 0; - - maca_free_all_packets(); - - // promiscuous, no CCA - MACA->CONTROLbits.PRM = MACA_CONTROL_PRM_ON; - MACA->CONTROLbits.MODE = MACA_CONTROL_MODE_NOCCA; - - enable_irq ( INT_NUM_MACA ); - ITC->INTFRCbits.MACA = 1; -} - -void _maca_reset ( void ) { - volatile uint32_t c; - - MACA->RESETbits.RST = 1; - - for ( c = 0; c < 100; c++ ) { - continue; - } - - MACA->RESETbits.CLK_ON = 1; - MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_NOP; - - for ( c = 0; c < 400000; c++ ) { - continue; - } - - // clear all interrupts - MACA->CLRIRQ = 0xffff; -} - -void maca_on ( void ) { - - // turn on the radio regulators - CRM->VREG_CNTLbits.BUCK_EN = 0x0; - CRM->VREG_CNTLbits.BUCK_SYNC_REC_EN = 0x0; - CRM->VREG_CNTLbits.BUCK_BYPASS_EN = 0x0; - CRM->VREG_CNTLbits.VREG_1P5V_EN = 0x3; - CRM->VREG_CNTLbits.VREG_1P5V_SEL = 0x3; - CRM->VREG_CNTLbits.VREG_1P8V_EN = 0x0; - CRM->VREG_CNTLbits.BUCK_CLKDIV = 0xf; - - // reinitialize phy - _maca_reset(); - _maca_init_phy(); - - enable_irq ( INT_NUM_MACA ); - ITC->INTFRCbits.MACA = 0x1; -} - -void maca_off ( void ) { - disable_irq ( INT_NUM_MACA ); - - // turn off radio regulators - CRM->VREG_CNTL = 0x00000f00; - - MACA->RESETbits.RST = 0x1; -} - -void maca_free_all_packets ( void ) { - volatile uint32_t i; - safe_irq_disable ( INT_NUM_MACA ); - - maca_free_head = 0; - - for ( i = 0; i < MACA_NUM_PACKETS; i++ ) { - maca_free_packet ( ( volatile maca_packet_t * ) & ( maca_packet_pool[i] ) ); - } - - maca_rx_head = 0; - maca_rx_end = 0; - maca_tx_head = 0; - maca_tx_end = 0; - - irq_restore(); - - // force MACA interrupt if there are pending irqs - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 0x1; - } -} - -void _maca_bound_check ( volatile maca_packet_t *packet ) { - volatile uint32_t i; - - if ( !packet || packet == &maca_dummy_ack ) { - return; - } - - for ( i = 0; i < MACA_NUM_PACKETS; i++ ) { - if ( packet == &maca_packet_pool[i] ) { - return; - } - } - - // bad packet bounds! next, nirvana... - printf ( "bad packet bounds! Halting... \n" ); - - while ( 1 ) { - continue; - } -} - -void maca_free_packet ( volatile maca_packet_t *packet ) { - safe_irq_disable ( INT_NUM_MACA ); - - // _maca_bound_check( packet ); - - if ( !packet || packet == &maca_dummy_ack ) { - return; - } - - // _maca_bound_check( maca_free_head ); - - packet->length = 0; - packet->offset = 0; - packet->left = maca_free_head; - packet->right = 0; - - maca_free_head = packet; - - // _maca_bound_check( maca_free_head ); - - irq_restore(); - - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 0x1; - } -} - -volatile maca_packet_t *maca_get_free_packet ( void ) { - volatile maca_packet_t *packet; - - safe_irq_disable ( INT_NUM_MACA ); - // _maca_bound_check( maca_free_head ); - - packet = maca_free_head; - - if ( packet ) { - maca_free_head = packet->left; - maca_free_head->right = 0; - } - - // _maca_bound_check( maca_free_head ); - - irq_restore(); - - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 0x1; - } - - return packet; -} - -volatile maca_packet_t *maca_get_rx_packet ( void ) { - volatile maca_packet_t *packet; - safe_irq_disable ( INT_NUM_MACA ); - - // maca_bound_check ( maca_rx_head ); - - packet = maca_rx_head; - - if ( packet ) { - maca_rx_head = packet->left; - maca_rx_head->right = 0; - } - - irq_restore (); - - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 0x1; - } - - return packet; -} - -void maca_set_tx_packet ( volatile maca_packet_t *packet ) { - safe_irq_disable ( INT_NUM_MACA ); - - // maca_bound_check ( packet ); - - if ( !packet ) { - return; - } - - if ( !maca_tx_head ) { - // start a new queue - maca_tx_end = packet; - maca_tx_end->left = 0; - maca_tx_end->right = 0; - maca_tx_head = maca_tx_end; - } - else { - // add packet to the end of the queue - maca_tx_end->left = packet; - packet->right = maca_tx_end; - // move the queue - maca_tx_end = packet; - maca_tx_end->left = 0; - } - - irq_restore (); - - if ( ITC->NIPENDbits.MACA || maca_last_post == MACA_NO_POST ) { - ITC->INTFRCbits.MACA = 0x1; - } - - if ( maca_last_post == MACA_RX_POST ) { - MACA->SFTCLK = MACA->CLK + CLK_PER_BYTE; - } - - return; -} - -void _maca_post_receive ( void ) { - maca_last_post = MACA_RX_POST; - - // from the libmc1322x implementation: - // "this sets the rxlen field - // this is undocumented but very important - // you will not receive anything without setting it" - MACA->TXLEN = ( MACA_MAX_PACKET_SIZE<<16 ); - - if ( !maca_dma_rx ) { - maca_dma_rx = maca_get_free_packet (); - - if ( !maca_dma_rx ) { - MACA->SFTCLK = MACA->CLK + RECV_SOFTIMEOUT; - MACA->TMRENbits.SFT = 0x1; - - // no free buffers, so don't start reception - enable_irq ( INT_NUM_MACA ); - return; - } - } - - // maca_bound_check ( maca_dma_rx ); - // maca_bound_check ( maca_dma_tx ); - - // load starting addess - MACA->DMARX = ( uint32_t ) & ( maca_dma_rx->data[0] ); - // wind up a timer for timeout - MACA->SFTCLK = MACA->CLK + RECV_SOFTIMEOUT; - // enable the soft complete clk circuit - MACA->TMRENbits.SFT = 0x1; - // start the receive sequence - MACA->CONTROLbits.ASAP = MACA_CONTROL_ASAP_ON; - MACA->CONTROLbits.PRE_COUNT = 0x4; - MACA->CONTROLbits.NOFC = MACA_CONTROL_NOFC_OFF; // aka use FCS - MACA->CONTROLbits.PRM = MACA_CONTROL_PRM_ON; - MACA->CONTROLbits.AUTO = MACA_CONTROL_AUTO_ON; - MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_RX; -} - -void _maca_post_transmit ( void ) { - safe_irq_disable ( INT_NUM_MACA ); - - maca_last_post = MACA_TX_POST; - maca_dma_tx = maca_tx_head; - - MACA->TXSEQNRbits.TXSEQN = maca_dma_tx->data[2]; - MACA->TXLENbits.TX_LEN = ( uint16_t ) ( ( maca_dma_tx->length ) + 2 ); - // set rx length to ACK length - MACA->TXLEN = ( uint32_t ) ( 3<<16 ); - // load data starting address - MACA->DMATX = ( uint32_t ) & ( maca_dma_tx->data[0 + maca_dma_tx->offset] ); - - if ( !maca_dma_rx ) { - maca_dma_rx = maca_get_free_packet(); - - if ( !maca_dma_rx ) { - printf ( "tried to fill MACA->DMARX in maca_post_tx but there are no packet buffers left" ); - maca_dma_rx = &maca_dummy_ack; - } - } - - // maca_bound_check ( maca_dma_rx ); - // maca_bound_check ( maca_dma_tx ); - - MACA->DMARX = ( uint32_t ) & ( maca_dma_rx->data[0] ); - - // disable soft timeout clk and start clk - MACA->TMRDISbits.SFT = MACA_TMRDIS_SFT_DISABLE; - MACA->TMRDISbits.CPL = MACA_TMRDIS_CPL_DISABLE; - - // set cpl clk to a long range and enable it - // for the case MACA locks - MACA->CPLCLK = MACA->CLK + CPL_TIMEOUT; - MACA->TMRENbits.CPL = 0x1; - - irq_restore (); - - MACA->CONTROLbits.ASAP = MACA_CONTROL_ASAP_ON; - MACA->CONTROLbits.PRE_COUNT = 0x4; - MACA->CONTROLbits.PRM = MACA_CONTROL_PRM_ON; - MACA->CONTROLbits.MODE = MACA_CONTROL_MODE_NOCCA; - MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_TX; - -} - -void _maca_free_tx_head ( void ) { - volatile maca_packet_t *packet; - safe_irq_disable ( INT_NUM_MACA ); - - packet = maca_tx_head; - maca_tx_head = maca_tx_head->left; - - if ( maca_tx_head == 0 ) { - maca_tx_end = 0; - } - - maca_free_packet ( packet ); - - irq_restore (); - - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 1; - } - - return; -} - -void _maca_add_to_rx ( volatile maca_packet_t *packet ) { - safe_irq_disable ( INT_NUM_MACA ); - - if ( !packet ) { - printf ( "packet null passed to _maca_add_to_rx\n" ); - return; - } - - packet->offset = 1; // first byte is the length - - if ( maca_rx_head == 0 ) { - // start a new queue - maca_rx_end = packet; - maca_rx_end->left = 0; - maca_rx_end->right = 0; - maca_rx_head = maca_rx_end; - } - else { - // enqueue packet - maca_rx_end->left = packet; - packet->right = maca_rx_end; - maca_rx_end = packet; - maca_rx_end->left = 0; - } - - irq_restore(); - - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 1; - } - - return; -} - -void _maca_decode_status ( void ) { - volatile uint32_t code; - - code = MACA->STATUSbits.COMPLETE_CODE; - - switch ( code ) { - case MACA_STATUS_COMPLETECODE_ABORTED: { - printf ( "maca: aborted\n" ); - _maca_resume_maca_sync (); - break; - } - - case MACA_STATUS_COMPLETECODE_NOTCOMPLETE: { - printf ( "maca: not completed\n" ); - _maca_resume_maca_sync (); - break; - } - - case MACA_STATUS_COMPLETECODE_TIMEOUT: { - printf ( "maca: timeout\n" ); - _maca_resume_maca_sync (); - break; - } - - case MACA_STATUS_COMPLETECODE_NOACK: { - printf ( "maca: no ack\n" ); - _maca_resume_maca_sync (); - break; - } - - case MACA_STATUS_COMPLETECODE_EXTTIMEOUT: { - printf ( "maca: ext timeout\n" ); - _maca_resume_maca_sync (); - break; - } - - case MACA_STATUS_COMPLETECODE_EXTPNDTIMEOUT: { - printf ( "maca: ext pnd timeout\n" ); - _maca_resume_maca_sync (); - break; - } - case MACA_STATUS_COMPLETECODE_SUCCESS: { - printf ( "maca: success\n" ); - _maca_resume_maca_sync (); - break; - } - - default: { - printf ( "maca status: %x", MACA->STATUSbits.COMPLETE_CODE ); - _maca_resume_maca_sync (); - } - } -} - -void maca_isr ( void ) { - //maca_entry++; - - if ( MACA->STATUSbits.OVR ) { - printf ( "maca overrun\n" ); - } - - if ( MACA->STATUSbits.BUSY ) { - printf ( "maca busy\n" ); - } - - if ( MACA->STATUSbits.CRC ) { - printf ( "maca crc error\n" ); - } - - if ( MACA->STATUSbits.TO ) { - printf ( "maca timeout\n" ); - } - - if ( MACA->IRQbits.DI ) { - MACA->CLRIRQbits.DI = 0x1; - maca_dma_rx->length = MACA->GETRXLVLbits.RECVBYTES - 2; // packet length doesn't include length - maca_dma_rx->lqi = get_lqi(); - maca_dma_rx->rx_time = MACA->TIMESTAMP; - - // does the packet need an ACK? - if ( MACA->CONTROLbits.PRM == MACA_CONTROL_PRM_OFF && - ( maca_dma_rx->data[1] & 0x20 ) ) { - volatile uint32_t wait_clk; - wait_clk = MACA->CLK + 200; - - while ( MACA->CLK < wait_clk ) { - continue; - } - } - - if ( maca_rx_callback != 0 ) { - maca_rx_callback ( maca_dma_rx ); - } - - _maca_add_to_rx ( maca_dma_rx ); - maca_dma_rx = 0; - } - - // filter faild - if ( MACA->IRQbits.FLT ) { - printf ( "maca filter faild\n" ); - _maca_resume_maca_sync (); - MACA->CLRIRQbits.FLT = 0x1; - } - - // CRC checksum faild - if ( MACA->IRQbits.CRC ) { - printf ( "maca crc checksum faild\n" ); - _maca_resume_maca_sync (); - MACA->CLRIRQbits.CRC = 0x1; - } - - // softclock interrupt - if ( MACA->IRQbits.SFT ) { - MACA->CLRIRQbits.SFT = 0x1; - } - - // poll interrupt - if ( MACA->IRQbits.POLL ) { - MACA->CLRIRQbits.POLL = 0x1; - } - - // action complete interrupt - if ( MACA->IRQbits.ACPL ) { - if ( maca_last_post == MACA_TX_POST ) { - maca_tx_head->status = MACA->STATUSbits.COMPLETE_CODE; - - if ( maca_tx_callback != 0 ) { - maca_tx_callback ( maca_tx_head ); - } - - maca_dma_tx = 0x0; - _maca_free_tx_head (); - maca_last_post = MACA_NO_POST; - } - - _maca_resume_maca_sync (); - MACA->CLRIRQbits.ACPL = 0x1; - } - - _maca_decode_status (); - - // this should never happen ... - if ( MACA->IRQ != 0 ) { - printf ( "MACA->IRQ is %x", (unsigned int) MACA->IRQ ); - } - - if ( maca_tx_head != 0 ) { - _maca_post_transmit (); - } - else { - _maca_post_receive (); - } -} - -void _maca_init_phy ( void ) { - MACA->CLKDIV = MACA_CLOCK_DIV; - MACA->WARMUP = 0x00180012; - MACA->EOFDELAY = 0x00000004; - MACA->CCADELAY = 0x001a0022; - MACA->TXCCADELAY = 0x00000025; - MACA->FRAMESYNC0 = 0x000000a7; - MACA->CLK = 0x00000008; - MACA->RXACKDELAY = 0x0000001e; - MACA->RXEND = 0x000000b4; - MACA->TXACKDELAY = 0x00000044; - MACA->MASKIRQbits.ACPL = 0x1; - MACA->MASKIRQbits.CM = 0x1; - MACA->MASKIRQbits.FLT = 0x1; - MACA->MASKIRQbits.CRC = 0x1; - MACA->MASKIRQbits.DI = 0x1; - MACA->MASKIRQbits.SFT = 0x1; - MACA->MASKIRQbits.RST = 0x1; - MACA->SLOTOFFSET = 0x00350000; -} - -#define MTOC_BASE 0x80009a00 //Modem Tracking Oscillator Controller -void _maca_flyback_init ( void ) { - uint32_t val8, tmp; - - val8 = * ( volatile uint32_t * ) ( MTOC_BASE+8 ); - tmp = val8 | 0x0000f7df; - * ( volatile uint32_t * ) ( MTOC_BASE+8 ) = tmp; - * ( volatile uint32_t * ) ( MTOC_BASE+12 ) = 0x00ffffff; - * ( volatile uint32_t * ) ( MTOC_BASE+16 ) = ( ( ( uint32_t ) 0x00ffffff ) >>12 ); - * ( volatile uint32_t * ) ( MTOC_BASE ) = 16; -} - -#define MACA_MAX_SEQ_1 2 -const uint32_t maca_addr_seq_1[MACA_MAX_SEQ_1] = { - 0x80003048, - 0x8000304c, -}; - -const uint32_t maca_data_seq_1[MACA_MAX_SEQ_1] = { - 0x00000f78, - 0x00607707, -}; - - -#define MACA_MAX_SEQ_2 2 -const uint32_t maca_addr_seq_2[MACA_MAX_SEQ_2] = { - 0x8000a050, - 0x8000a054, -}; - -const uint32_t maca_data_seq_2[MACA_MAX_SEQ_2] = { - 0x0000047b, - 0x0000007b, -}; - -#define MACA_MAX_CAL3_SEQ_1 3 -const uint32_t maca_addr_cal3_seq_1[MACA_MAX_CAL3_SEQ_1] = { 0x80009400,0x80009a04,0x80009a00, }; -const uint32_t maca_data_cal3_seq_1[MACA_MAX_CAL3_SEQ_1] = {0x00020017,0x8185a0a4,0x8c900025, }; - -#define MACA_MAX_CAL3_SEQ_2 2 -const uint32_t maca_addr_cal3_seq_2[MACA_MAX_CAL3_SEQ_2] = { 0x80009a00,0x80009a00,}; -const uint32_t maca_data_cal3_seq_2[MACA_MAX_CAL3_SEQ_2] = { 0x8c900021,0x8c900027,}; - -#define MACA_MAX_CAL3_SEQ_3 1 -const uint32_t maca_addr_cal3_seq_3[MACA_MAX_CAL3_SEQ_3] = { 0x80009a00 }; -const uint32_t maca_data_cal3_seq_3[MACA_MAX_CAL3_SEQ_3] = { 0x8c900000 }; - -#define MACA_MAX_CAL5 4 -const uint32_t maca_addr_cal5[MACA_MAX_CAL5] = { - 0x80009400, - 0x8000a050, - 0x8000a054, - 0x80003048, -}; -const uint32_t maca_data_cal5[MACA_MAX_CAL5] = { - 0x00000017, - 0x00000000, - 0x00000000, - 0x00000f00, -}; - -#define MACA_MAX_DATA 43 -const uint32_t maca_addr_reg_rep[MACA_MAX_DATA] = { - 0x80004118,0x80009204,0x80009208,0x8000920c, - 0x80009210,0x80009300,0x80009304,0x80009308, - 0x8000930c,0x80009310,0x80009314,0x80009318, - 0x80009380,0x80009384,0x80009388,0x8000938c, - 0x80009390,0x80009394,0x8000a008,0x8000a018, - 0x8000a01c,0x80009424,0x80009434,0x80009438, - 0x8000943c,0x80009440,0x80009444,0x80009448, - 0x8000944c,0x80009450,0x80009460,0x80009464, - 0x8000947c,0x800094e0,0x800094e4,0x800094e8, - 0x800094ec,0x800094f0,0x800094f4,0x800094f8, - 0x80009470,0x8000981c,0x80009828 -}; - -const uint32_t maca_data_reg_rep[MACA_MAX_DATA] = { - 0x00180012,0x00000605,0x00000504,0x00001111, - 0x0fc40000,0x20046000,0x4005580c,0x40075801, - 0x4005d801,0x5a45d800,0x4a45d800,0x40044000, - 0x00106000,0x00083806,0x00093807,0x0009b804, - 0x000db800,0x00093802,0x00000015,0x00000002, - 0x0000000f,0x0000aaa0,0x01002020,0x016800fe, - 0x8e578248,0x000000dd,0x00000946,0x0000035a, - 0x00100010,0x00000515,0x00397feb,0x00180358, - 0x00000455,0x00000001,0x00020003,0x00040014, - 0x00240034,0x00440144,0x02440344,0x04440544, - 0x0ee7fc00,0x00000082,0x0000002a -}; - -uint8_t ctov[16] = { - 0x0b,0x0b,0x0b,0x0a, - 0x0d,0x0d,0x0c,0x0c, - 0x0f,0x0e,0x0e,0x0e, - 0x11,0x10,0x10,0x0f -}; - -#define _INIT_CTOV_WORD_1 0x00dfbe77 -#define _INIT_CTOV_WORD_2 0x023126e9 -uint8_t get_ctov ( uint32_t r0, uint32_t r1 ) { - r0 = r0 * _INIT_CTOV_WORD_1; - r0 += ( r1 << 22 ); - r0 += _INIT_CTOV_WORD_2; - - r0 = ( uint32_t ) ( ( ( int32_t ) r0 ) >>25 ); - return ( uint8_t ) r0; -} - -static uint8_t _ram_values[4]; - -void _maca_radio_init ( void ) { - volatile uint32_t c; - - // sequence 1 - for ( c = 0; c < MACA_MAX_SEQ_1; c++ ) { - if ( ( uint32_t ) maca_addr_seq_1[c] != CRM->VREG_CNTL ) { - * ( ( volatile uint32_t * ) ( maca_addr_seq_1[c] ) ) = maca_data_seq_1[c]; - } - } - - // sequence 1 delay - for ( c = 0; c < 0x161a8; c++ ) { - continue; - } - - // sequence 2 - for ( c = 0; c < MACA_MAX_SEQ_2; c++ ) { - * ( ( volatile uint32_t * ) ( maca_addr_seq_2[c] ) ) = maca_data_seq_2[c]; - } - - // modem value - * ( ( volatile uint32_t * ) 0x80009000 ) = 0x80050100; - - // cal 3 seq 1 - for ( c = 0; c < MACA_MAX_CAL3_SEQ_1; c++ ) { - * ( ( volatile uint32_t * ) ( maca_addr_cal3_seq_1[c] ) ) = maca_data_cal3_seq_1[c]; - } - - // cal 3 delay - for ( c = 0; c < 0x11194; c++ ) { - continue; - } - - // cal 3 seq 2 - for ( c = 0; c < MACA_MAX_CAL3_SEQ_2; c++ ) { - * ( ( volatile uint32_t * ) ( maca_addr_cal3_seq_2[c] ) ) = maca_data_cal3_seq_2[c]; - } - - // cal 3 delay - for ( c = 0; c < 0x11194; c++ ) { - continue; - } - - // cal 3 seq 3 - for ( c = 0; c < MACA_MAX_CAL3_SEQ_3; c++ ) { - * ( ( volatile uint32_t * ) ( maca_addr_cal3_seq_3[c] ) ) = maca_data_cal3_seq_3[c]; - } - - // cal 5 - for ( c = 0; c < MACA_MAX_CAL5; c++ ) { - if ( ( uint32_t ) maca_addr_cal5[c] != CRM->VREG_CNTL ) { - * ( ( volatile uint32_t * ) ( maca_addr_cal5[c] ) ) = maca_data_cal5[c]; - } - } - - /*reg replacment */ - for ( c = 0; c < MACA_MAX_DATA; c++ ) { - * ( ( volatile uint32_t * ) ( maca_addr_reg_rep[c] ) ) = maca_data_reg_rep[c]; - } - - _maca_init_from_flash ( 0x1f000 ); - - for ( c=0; c<4; c++ ) { - printf ( " 0x%02x\n\r", _ram_values[c] ); - } - - for ( c=0; c<16; c++ ) { - ctov[c] = get_ctov ( c, _ram_values[3] ); - } -} - -const uint32_t PSMVAL[19] = { - 0x0000080f, 0x0000080f, 0x0000080f, - 0x0000080f, 0x0000081f, 0x0000081f, - 0x0000081f, 0x0000080f, 0x0000080f, - 0x0000080f, 0x0000001f, 0x0000000f, - 0x0000000f, 0x00000816, 0x0000001b, - 0x0000000b, 0x00000802, 0x00000817, - 0x00000003, -}; - -const uint32_t PAVAL[19] = { - 0x000022c0, 0x000022c0, 0x000022c0, - 0x00002280, 0x00002303, 0x000023c0, - 0x00002880, 0x000029f0, 0x000029f0, - 0x000029f0, 0x000029c0, 0x00002bf0, - 0x000029f0, 0x000028a0, 0x00002800, - 0x00002ac0, 0x00002880, 0x00002a00, - 0x00002b00, -}; - -const uint32_t AIMVAL[19] = { - 0x000123a0, 0x000163a0, 0x0001a3a0, - 0x0001e3a0, 0x000223a0, 0x000263a0, - 0x0002a3a0, 0x0002e3a0, 0x000323a0, - 0x000363a0, 0x0003a3a0, 0x0003a3a0, - 0x0003e3a0, 0x000423a0, 0x000523a0, - 0x000423a0, 0x0004e3a0, 0x0004e3a0, - 0x0004e3a0, -}; - -// #define MRRF_BASE 0x80009400 // Modem Radio Receiver Functions -// void _set_demodulator_type ( uint8_t demod ) { -// uint32_t val = *(uint32_t*)(MRRF_BASE); -// if ( demod == MACA_DEMOD_NCD ) { -// val = (val & ~1); -// } else { -// val = (val | 1); -// } -// *(uint32_t*)(MRRF_BASE) = val; -// } - -#define ADDR_POW1 0x8000a014 -#define ADDR_POW2 (ADDR_POW1 + 12) -#define ADDR_POW3 (ADDR_POW1 + 64) - -void maca_set_power ( uint8_t power ) { - safe_irq_disable ( INT_NUM_MACA ); - - * ( ( uint32_t * ) ( ADDR_POW1 ) ) = PSMVAL[power]; - -#ifdef USE_PA - * ( ( uint32_t * ) ( ADDR_POW2 ) ) = 0xffffdfff & PAVAL[power]; /* single port */ -#else - * ( ( uint32_t * ) ( ADDR_POW2 ) ) = 0x00002000 | PAVAL[power]; /* dual port */ -#endif - - * ( ( uint32_t * ) ( ADDR_POW3 ) ) = AIMVAL[power]; - irq_restore(); - - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 1; - } -} - -const uint8_t VCODivI[16] = { - 0x2f, 0x2f, 0x2f, 0x2f, - 0x2f, 0x2f, 0x2f, 0x2f, - 0x2f, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, -}; - -const uint32_t VCODivF[16] = { - 0x00355555, 0x006aaaaa, 0x00a00000, 0x00d55555, - 0x010aaaaa, 0x01400000, 0x01755555, 0x01aaaaaa, - 0x01e00000, 0x00155555, 0x004aaaaa, 0x00800000, - 0x00b55555, 0x00eaaaaa, 0x01200000, 0x01555555, -}; - -#define ADDR_CHAN1 0x80009800 -#define ADDR_CHAN2 (ADDR_CHAN1+12) -#define ADDR_CHAN3 (ADDR_CHAN1+16) -#define ADDR_CHAN4 (ADDR_CHAN1+48) - -void maca_set_channel ( uint8_t chan ) { - volatile uint32_t tmp; - safe_irq_disable ( INT_NUM_MACA ); - - tmp = * ( uint32_t * ) ( ADDR_CHAN1 ); - tmp = tmp & 0xbfffffff; - * ( ( uint32_t * ) ( ADDR_CHAN1 ) ) = tmp; - - * ( ( uint32_t * ) ( ADDR_CHAN2 ) ) = VCODivI[chan]; - * ( ( uint32_t * ) ( ADDR_CHAN3 ) ) = VCODivF[chan]; - - tmp = * ( ( uint32_t * ) ( ADDR_CHAN4 ) ); - tmp = tmp | 2; - * ( ( uint32_t * ) ( ADDR_CHAN4 ) ) = tmp; - - tmp = * ( ( uint32_t * ) ( ADDR_CHAN4 ) ); - tmp = tmp | 4; - * ( ( uint32_t * ) ( ADDR_CHAN4 ) ) = tmp; - - tmp = tmp & 0xffffe0ff; - tmp = tmp | ( ( ( ctov[chan] ) <<8 ) &0x1f00 ); - * ( ( uint32_t * ) ( ADDR_CHAN4 ) ) = tmp; - - irq_restore(); - - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 1; - } -} - -uint16_t maca_set_address ( uint16_t addr ) { - safe_irq_disable ( INT_NUM_MACA ); - - MACA->MAC16ADDR = addr; - - irq_restore(); - - if ( ITC->NIPENDbits.MACA ) { - ITC->INTFRCbits.MACA = 1; - } - return MACA->MAC16ADDR; -} - -uint16_t maca_get_address ( void ) { - return MACA->MAC16ADDR; -} - -#define MACA_ROM_END 0x0013ffff -#define MACA_ENTRY_EOF 0x00000e0f -uint32_t _exec_init_entry ( volatile uint32_t *entries, uint8_t *value_buffer ) { - volatile uint32_t i; - - if ( entries[0] <= MACA_ROM_END ) { - if ( entries[0] == 0 ) { - /* do delay */ - printf ( "init_entry: delay 0x%08x\n", (unsigned int) entries[1] ); - - for ( i=0; i < entries[1]; i++ ) { - continue; - } - - return 2; - } - else if ( entries[0] == 1 ) { - /* do bit set/clear */ - printf ( "init_entry: bit set/clear 0x%08x 0x%08x 0x%08x\n", (unsigned int) entries[1], - (unsigned int) entries[2], - (unsigned int) entries[3] ); - * ( uint32_t * ) ( entries[2] ) = ( * ( uint32_t * ) ( entries[2] ) & entries[1] ) | ( entries[3] & entries[1] ); - return 4; - } - else if ( entries[0] >= 16 && entries[0] < 0xfff1 ) { - /* store bytes in value_buffer */ - printf ( "init_entry: store in value_buffer 0x%02x position %d\n", (unsigned int) entries[1], - (unsigned int) ( entries[0]>>4 ) - 1 ); - value_buffer[ ( entries[0]>>4 )-1] = entries[1]; - return 2; - } - else if ( entries[0] == MACA_ENTRY_EOF ) { - printf ( "init_entry: EOF \n" ); - return 0; - } - else { - /* invalid */ - printf ( "init_entry: invalid code 0x%08x\n", (unsigned int) entries[0] ); - return 0; - } - } - else { - /* address not in ROM */ - /* store value in address command */ - printf ( "init_entry: address value pair - *0x%08x = 0x%08x\n", (unsigned int) entries[0], - (unsigned int) entries[1] ); - - if ( entries[0] != CRM->VREG_CNTL ) { - * ( uint32_t * ) ( entries[0] ) = entries[1]; - } - else { - printf ( "skipping CRM->VREG_CNTL\n" ); - } - - return 2; - } -} - -#define MACA_FLASH_INIT_MAGIC 0x00000abc -uint32_t _maca_init_from_flash ( uint32_t addr ) { - nvm_type_t type = 0; - nvm_err_t err; - - volatile uint32_t buffer[8]; - volatile uint32_t length; - volatile uint32_t i = 0; - volatile uint32_t j = 0; - - err = nvm_detect ( g_nvm_internal_interface_c, &type ); - printf ( "nvm_detect returned type 0x%08x err 0x%02x\n", type, err ); - - nvm_setsvar ( 0 ); - err = nvm_read ( g_nvm_internal_interface_c, type, ( uint8_t * ) buffer, addr, 8 ); - i += 8; - printf ( "nvm_read returned: 0x%02x\n", err ); - - for ( j = 0; j < 4; j++ ) { - printf ( "0x%08x\n", (unsigned int) buffer[j] ); - } - - if ( buffer[0] == MACA_FLASH_INIT_MAGIC ) { - length = buffer[1] & 0x0000ffff; - - while ( i < ( length-4 ) ) { - err = nvm_read ( g_nvm_internal_interface_c, type, ( uint8_t * ) buffer, addr+i, 32 ); - i += 4 * _exec_init_entry ( buffer, _ram_values ); - } - } - else { - i = 0; - } - - nvm_setsvar ( 1 ); - return i; -} - -void _maca_resume_maca_sync ( void ) { - volatile uint32_t clk; - volatile uint32_t tsm_rx_steps; - volatile uint32_t last_warmup_step; - volatile uint32_t last_warmup_data; - volatile uint32_t last_warmdown_step; - volatile uint32_t last_warmdown_data; - volatile uint32_t i; - - safe_irq_disable ( INT_NUM_MACA ); - - /* manual TSM modem shutdown */ - /* read TSM_RX_STEPS */ - tsm_rx_steps = * ( volatile uint32_t * ) ( 0x80009204 ); - /* isolate the RX_WU_STEPS */ - /* shift left to align with 32-bit addressing */ - last_warmup_step = ( tsm_rx_steps & 0x1f ) << 2; - /* Read "current" TSM step and save this value for later */ - last_warmup_data = ( * ( ( volatile uint32_t * ) ( 0x80009300 + last_warmup_step ) ) ); - - /* isolate the RX_WD_STEPS */ - /* right-shift bits down to bit 0 position */ - /* left-shift to align with 32-bit addressing */ - last_warmdown_step = ( ( tsm_rx_steps & 0x1f00 ) >> 8 ) << 2; - /* write "last warmdown data" to current TSM step to shutdown rx */ - last_warmdown_data = ( * ( ( volatile uint32_t * ) ( 0x80009300 + last_warmdown_step ) ) ); - ( * ( ( volatile uint32_t * ) ( 0x80009300 + last_warmup_step ) ) ) = last_warmdown_data; - - /* Abort */ - MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_ABORT; - - /* Wait ~8us */ - for ( clk = MACA->CLK, i = 0; MACA->CLK - clk < 3 && i < 300; i++ ) { - continue; - } - - /* NOP */ - MACA->CONTROLbits.SEQUENCE = MACA_CONTROL_SEQUENCE_NOP; - - /* Wait ~8us */ - for ( clk = MACA->CLK, i = 0; MACA->CLK - clk < 3 && i < 300; i++ ) { - continue; - } - - /* restore original "last warmup step" data to TSM (VERY IMPORTANT!!!) */ - ( * ( ( volatile uint32_t * ) ( 0x80009300 + last_warmup_step ) ) ) = last_warmup_data; - - /* Clear all MACA interrupts - we should have gotten the ABORT IRQ */ - MACA->CLRIRQ = 0xffff; - - irq_restore(); -} From 232e2051374bac305882f2458925c55e895c01d9 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Wed, 6 Nov 2013 10:11:57 -0800 Subject: [PATCH 188/188] moved boards into subdirectory --- LICENSE => boards/LICENSE | 0 Makefile => boards/Makefile | 0 Makefile.base => boards/Makefile.base | 0 README.md => boards/README.md | 0 {avsextrem => boards/avsextrem}/Makefile | 0 {avsextrem => boards/avsextrem}/Makefile.include | 0 {avsextrem => boards/avsextrem}/board_init.c | 0 {avsextrem => boards/avsextrem}/drivers/Makefile | 0 {avsextrem => boards/avsextrem}/drivers/avsextrem-cc1100.c | 0 {avsextrem => boards/avsextrem}/drivers/avsextrem-smb380.c | 0 {avsextrem => boards/avsextrem}/drivers/avsextrem-ssp0.c | 0 {avsextrem => boards/avsextrem}/include/board.h | 0 {avsextrem => boards/avsextrem}/include/configure.h | 0 {avsextrem => boards/avsextrem}/include/smb380-board.h | 0 {avsextrem => boards/avsextrem}/include/ssp0-board.h | 0 {chronos => boards/chronos}/Makefile | 0 {chronos => boards/chronos}/Makefile.include | 0 {chronos => boards/chronos}/board_init.c | 0 {chronos => boards/chronos}/drivers/Makefile | 0 {chronos => boards/chronos}/drivers/battery.c | 0 {chronos => boards/chronos}/drivers/buzzer.c | 0 {chronos => boards/chronos}/drivers/cc430-cc110x.c | 0 {chronos => boards/chronos}/drivers/display.c | 0 {chronos => boards/chronos}/drivers/display1.c | 0 {chronos => boards/chronos}/drivers/display_putchar.c | 0 {chronos => boards/chronos}/drivers/include/battery.h | 0 {chronos => boards/chronos}/drivers/include/buzzer.h | 0 {chronos => boards/chronos}/drivers/include/display.h | 0 {chronos => boards/chronos}/drivers/include/display_putchar.h | 0 {chronos => boards/chronos}/include/board.h | 0 {chronos => boards/chronos}/include/buttons.h | 0 {chronos => boards/chronos}/putchar.c | 0 {msb-430-common => boards/msb-430-common}/Makefile | 0 {msb-430-common => boards/msb-430-common}/Makefile.include | 0 {msb-430-common => boards/msb-430-common}/board_config.c | 0 {msb-430-common => boards/msb-430-common}/board_init.c | 0 {msb-430-common => boards/msb-430-common}/drivers/Makefile | 0 .../msb-430-common}/drivers/include/sht11-board.h | 0 {msb-430-common => boards/msb-430-common}/include/board-conf.h | 0 {msb-430-common => boards/msb-430-common}/uart1.c | 0 {msb-430 => boards/msb-430}/Makefile | 0 {msb-430 => boards/msb-430}/Makefile.include | 0 {msb-430 => boards/msb-430}/include/board.h | 0 {msb-430h => boards/msb-430h}/Makefile | 0 {msb-430h => boards/msb-430h}/Makefile.dep | 0 {msb-430h => boards/msb-430h}/Makefile.include | 0 {msb-430h => boards/msb-430h}/driver_cc110x.c | 0 {msb-430h => boards/msb-430h}/include/board.h | 0 {msba2-common => boards/msba2-common}/Makefile | 0 {msba2-common => boards/msba2-common}/Makefile.dep | 0 {msba2-common => boards/msba2-common}/Makefile.include | 0 {msba2-common => boards/msba2-common}/board_common_init.c | 0 {msba2-common => boards/msba2-common}/board_config.c | 0 {msba2-common => boards/msba2-common}/drivers/Makefile | 0 .../msba2-common}/drivers/include/sht11-board.h | 0 {msba2-common => boards/msba2-common}/drivers/include/uart0.h | 0 {msba2-common => boards/msba2-common}/drivers/msba2-cc110x.c | 0 {msba2-common => boards/msba2-common}/drivers/msba2-ltc4150.c | 0 {msba2-common => boards/msba2-common}/drivers/msba2-uart0.c | 0 {msba2-common => boards/msba2-common}/include/msba2_common.h | 0 {msba2-common => boards/msba2-common}/lpc2387-timer3.c | 0 {msba2-common => boards/msba2-common}/tools/CHANGES | 0 {msba2-common => boards/msba2-common}/tools/COPYING | 0 {msba2-common => boards/msba2-common}/tools/Makefile | 0 {msba2-common => boards/msba2-common}/tools/README.txt | 0 {msba2-common => boards/msba2-common}/tools/armtools.txt | 0 {msba2-common => boards/msba2-common}/tools/flash.cmd | 0 {msba2-common => boards/msba2-common}/tools/flashutil.sh | 0 {msba2-common => boards/msba2-common}/tools/mkbootc | 0 {msba2-common => boards/msba2-common}/tools/mkstaticlist | 0 {msba2-common => boards/msba2-common}/tools/obj/boot_23xx.d | 0 {msba2-common => boards/msba2-common}/tools/obj/boot_2xxx.d | 0 {msba2-common => boards/msba2-common}/tools/obj/chipinfo.d | 0 {msba2-common => boards/msba2-common}/tools/obj/control_2xxx.d | 0 {msba2-common => boards/msba2-common}/tools/obj/download.d | 0 {msba2-common => boards/msba2-common}/tools/obj/ihex.d | 0 {msba2-common => boards/msba2-common}/tools/obj/lpc2k_pgm.d | 0 {msba2-common => boards/msba2-common}/tools/obj/pseudoterm.d | 0 {msba2-common => boards/msba2-common}/tools/obj/serial.d | 0 {msba2-common => boards/msba2-common}/tools/obj/uuencode.d | 0 {msba2-common => boards/msba2-common}/tools/src/boot.h | 0 {msba2-common => boards/msba2-common}/tools/src/boot_23xx.armasm | 0 {msba2-common => boards/msba2-common}/tools/src/boot_23xx.c | 0 {msba2-common => boards/msba2-common}/tools/src/boot_23xx.h | 0 {msba2-common => boards/msba2-common}/tools/src/boot_2xxx.armasm | 0 {msba2-common => boards/msba2-common}/tools/src/boot_2xxx.c | 0 {msba2-common => boards/msba2-common}/tools/src/boot_2xxx.h | 0 {msba2-common => boards/msba2-common}/tools/src/chipinfo.c | 0 {msba2-common => boards/msba2-common}/tools/src/chipinfo.h | 0 {msba2-common => boards/msba2-common}/tools/src/cksum_test.c | 0 {msba2-common => boards/msba2-common}/tools/src/control_2xxx.c | 0 {msba2-common => boards/msba2-common}/tools/src/control_2xxx.h | 0 {msba2-common => boards/msba2-common}/tools/src/download.c | 0 {msba2-common => boards/msba2-common}/tools/src/download.h | 0 {msba2-common => boards/msba2-common}/tools/src/gui.c | 0 {msba2-common => boards/msba2-common}/tools/src/gui.h | 0 {msba2-common => boards/msba2-common}/tools/src/ihex.c | 0 {msba2-common => boards/msba2-common}/tools/src/ihex.h | 0 {msba2-common => boards/msba2-common}/tools/src/lpc2k_pgm.c | 0 {msba2-common => boards/msba2-common}/tools/src/lpc2k_pgm.h | 0 {msba2-common => boards/msba2-common}/tools/src/pseudoterm.c | 0 {msba2-common => boards/msba2-common}/tools/src/serial.c | 0 {msba2-common => boards/msba2-common}/tools/src/serial.h | 0 {msba2-common => boards/msba2-common}/tools/src/settings.c | 0 {msba2-common => boards/msba2-common}/tools/src/settings.h | 0 {msba2-common => boards/msba2-common}/tools/src/uuencode.c | 0 {msba2-common => boards/msba2-common}/tools/src/uuencode.h | 0 {msba2-common => boards/msba2-common}/tools/termctrl.sh | 0 {msba2 => boards/msba2}/Makefile | 0 {msba2 => boards/msba2}/Makefile.include | 0 {msba2 => boards/msba2}/board_init.c | 0 {msba2 => boards/msba2}/include/board.h | 0 {native => boards/native}/Makefile | 0 {native => boards/native}/Makefile.dep | 0 {native => boards/native}/Makefile.include | 0 {native => boards/native}/board_config.c | 0 {native => boards/native}/board_init.c | 0 {native => boards/native}/drivers/Makefile | 0 {native => boards/native}/drivers/native-led.c | 0 {native => boards/native}/drivers/native-ltc4150.c | 0 {native => boards/native}/drivers/native-uart0.c | 0 {native => boards/native}/include/board.h | 0 {native => boards/native}/include/board_internal.h | 0 {olimex_lpc2148 => boards/olimex_lpc2148}/board_init.c | 0 {olimex_lpc2148 => boards/olimex_lpc2148}/debug_uart.c | 0 {olimex_lpc2148 => boards/olimex_lpc2148}/include/board.h | 0 {olimex_lpc2148 => boards/olimex_lpc2148}/include/rs232.h | 0 {olimex_lpc2148 => boards/olimex_lpc2148}/rs232.c | 0 {olimex_lpc2148 => boards/olimex_lpc2148}/tick.c | 0 {olimex_lpc2148 => boards/olimex_lpc2148}/tools/lpc2148_flash.gdb | 0 {pttu => boards/pttu}/board_init.c | 0 {pttu => boards/pttu}/include/board.h | 0 {pttu => boards/pttu}/tools/jtag.txt | 0 {pttu => boards/pttu}/tools/olimex-arm-usb-ocd.cfg | 0 {pttu => boards/pttu}/tools/openocd-pttu.cfg | 0 {pttu => boards/pttu}/tools/openocd-pttu.sh | 0 {pttu => boards/pttu}/tools/pttu_debug.gdb | 0 {redbee-econotag => boards/redbee-econotag}/Makefile | 0 {redbee-econotag => boards/redbee-econotag}/Makefile.dep | 0 {redbee-econotag => boards/redbee-econotag}/Makefile.include | 0 {redbee-econotag => boards/redbee-econotag}/README | 0 {redbee-econotag => boards/redbee-econotag}/board_init.c | 0 {redbee-econotag => boards/redbee-econotag}/drivers/Makefile | 0 {redbee-econotag => boards/redbee-econotag}/drivers/include/nvm.h | 0 .../redbee-econotag}/drivers/include/uart.h | 0 {redbee-econotag => boards/redbee-econotag}/drivers/nvm.c | 0 {redbee-econotag => boards/redbee-econotag}/drivers/redbee_uart.c | 0 .../redbee-econotag}/drivers/redbee_uart1.c | 0 .../redbee-econotag}/drivers/redbee_uart2.c | 0 {redbee-econotag => boards/redbee-econotag}/include/board.h | 0 .../redbee-econotag}/tools/ftditools/Makefile | 0 .../redbee-econotag}/tools/ftditools/bbmc.c | 0 {redbee-econotag => boards/redbee-econotag}/tools/mc1322x-load.c | 0 {redbee-econotag => boards/redbee-econotag}/tools/mc1322x-load.pl | 0 {telosb => boards/telosb}/Makefile | 0 {telosb => boards/telosb}/Makefile.dep | 0 {telosb => boards/telosb}/Makefile.include | 0 {telosb => boards/telosb}/board.c | 0 {telosb => boards/telosb}/driver_cc2420.c | 0 {telosb => boards/telosb}/include/board-conf.h | 0 {telosb => boards/telosb}/include/board.h | 0 {telosb => boards/telosb}/uart.c | 0 {wsn430-common => boards/wsn430-common}/Makefile | 0 {wsn430-common => boards/wsn430-common}/Makefile.include | 0 {wsn430-common => boards/wsn430-common}/board_config.c | 0 {wsn430-common => boards/wsn430-common}/board_init.c | 0 {wsn430-common => boards/wsn430-common}/drivers/Makefile | 0 {wsn430-common => boards/wsn430-common}/include/board-conf.h | 0 {wsn430-common => boards/wsn430-common}/uart0.c | 0 {wsn430-v1_3b => boards/wsn430-v1_3b}/Makefile | 0 {wsn430-v1_3b => boards/wsn430-v1_3b}/Makefile.dep | 0 {wsn430-v1_3b => boards/wsn430-v1_3b}/Makefile.include | 0 {wsn430-v1_3b => boards/wsn430-v1_3b}/driver_cc110x.c | 0 {wsn430-v1_3b => boards/wsn430-v1_3b}/include/board.h | 0 {wsn430-v1_4 => boards/wsn430-v1_4}/Makefile | 0 {wsn430-v1_4 => boards/wsn430-v1_4}/Makefile.dep | 0 {wsn430-v1_4 => boards/wsn430-v1_4}/Makefile.include | 0 {wsn430-v1_4 => boards/wsn430-v1_4}/driver_cc2420.c | 0 {wsn430-v1_4 => boards/wsn430-v1_4}/include/board.h | 0 179 files changed, 0 insertions(+), 0 deletions(-) rename LICENSE => boards/LICENSE (100%) rename Makefile => boards/Makefile (100%) rename Makefile.base => boards/Makefile.base (100%) rename README.md => boards/README.md (100%) rename {avsextrem => boards/avsextrem}/Makefile (100%) rename {avsextrem => boards/avsextrem}/Makefile.include (100%) rename {avsextrem => boards/avsextrem}/board_init.c (100%) rename {avsextrem => boards/avsextrem}/drivers/Makefile (100%) rename {avsextrem => boards/avsextrem}/drivers/avsextrem-cc1100.c (100%) rename {avsextrem => boards/avsextrem}/drivers/avsextrem-smb380.c (100%) rename {avsextrem => boards/avsextrem}/drivers/avsextrem-ssp0.c (100%) rename {avsextrem => boards/avsextrem}/include/board.h (100%) rename {avsextrem => boards/avsextrem}/include/configure.h (100%) rename {avsextrem => boards/avsextrem}/include/smb380-board.h (100%) rename {avsextrem => boards/avsextrem}/include/ssp0-board.h (100%) rename {chronos => boards/chronos}/Makefile (100%) rename {chronos => boards/chronos}/Makefile.include (100%) rename {chronos => boards/chronos}/board_init.c (100%) rename {chronos => boards/chronos}/drivers/Makefile (100%) rename {chronos => boards/chronos}/drivers/battery.c (100%) rename {chronos => boards/chronos}/drivers/buzzer.c (100%) rename {chronos => boards/chronos}/drivers/cc430-cc110x.c (100%) rename {chronos => boards/chronos}/drivers/display.c (100%) rename {chronos => boards/chronos}/drivers/display1.c (100%) rename {chronos => boards/chronos}/drivers/display_putchar.c (100%) rename {chronos => boards/chronos}/drivers/include/battery.h (100%) rename {chronos => boards/chronos}/drivers/include/buzzer.h (100%) rename {chronos => boards/chronos}/drivers/include/display.h (100%) rename {chronos => boards/chronos}/drivers/include/display_putchar.h (100%) rename {chronos => boards/chronos}/include/board.h (100%) rename {chronos => boards/chronos}/include/buttons.h (100%) rename {chronos => boards/chronos}/putchar.c (100%) rename {msb-430-common => boards/msb-430-common}/Makefile (100%) rename {msb-430-common => boards/msb-430-common}/Makefile.include (100%) rename {msb-430-common => boards/msb-430-common}/board_config.c (100%) rename {msb-430-common => boards/msb-430-common}/board_init.c (100%) rename {msb-430-common => boards/msb-430-common}/drivers/Makefile (100%) rename {msb-430-common => boards/msb-430-common}/drivers/include/sht11-board.h (100%) rename {msb-430-common => boards/msb-430-common}/include/board-conf.h (100%) rename {msb-430-common => boards/msb-430-common}/uart1.c (100%) rename {msb-430 => boards/msb-430}/Makefile (100%) rename {msb-430 => boards/msb-430}/Makefile.include (100%) rename {msb-430 => boards/msb-430}/include/board.h (100%) rename {msb-430h => boards/msb-430h}/Makefile (100%) rename {msb-430h => boards/msb-430h}/Makefile.dep (100%) rename {msb-430h => boards/msb-430h}/Makefile.include (100%) rename {msb-430h => boards/msb-430h}/driver_cc110x.c (100%) rename {msb-430h => boards/msb-430h}/include/board.h (100%) rename {msba2-common => boards/msba2-common}/Makefile (100%) rename {msba2-common => boards/msba2-common}/Makefile.dep (100%) rename {msba2-common => boards/msba2-common}/Makefile.include (100%) rename {msba2-common => boards/msba2-common}/board_common_init.c (100%) rename {msba2-common => boards/msba2-common}/board_config.c (100%) rename {msba2-common => boards/msba2-common}/drivers/Makefile (100%) rename {msba2-common => boards/msba2-common}/drivers/include/sht11-board.h (100%) rename {msba2-common => boards/msba2-common}/drivers/include/uart0.h (100%) rename {msba2-common => boards/msba2-common}/drivers/msba2-cc110x.c (100%) rename {msba2-common => boards/msba2-common}/drivers/msba2-ltc4150.c (100%) rename {msba2-common => boards/msba2-common}/drivers/msba2-uart0.c (100%) rename {msba2-common => boards/msba2-common}/include/msba2_common.h (100%) rename {msba2-common => boards/msba2-common}/lpc2387-timer3.c (100%) rename {msba2-common => boards/msba2-common}/tools/CHANGES (100%) rename {msba2-common => boards/msba2-common}/tools/COPYING (100%) rename {msba2-common => boards/msba2-common}/tools/Makefile (100%) rename {msba2-common => boards/msba2-common}/tools/README.txt (100%) rename {msba2-common => boards/msba2-common}/tools/armtools.txt (100%) rename {msba2-common => boards/msba2-common}/tools/flash.cmd (100%) rename {msba2-common => boards/msba2-common}/tools/flashutil.sh (100%) rename {msba2-common => boards/msba2-common}/tools/mkbootc (100%) rename {msba2-common => boards/msba2-common}/tools/mkstaticlist (100%) rename {msba2-common => boards/msba2-common}/tools/obj/boot_23xx.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/boot_2xxx.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/chipinfo.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/control_2xxx.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/download.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/ihex.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/lpc2k_pgm.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/pseudoterm.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/serial.d (100%) rename {msba2-common => boards/msba2-common}/tools/obj/uuencode.d (100%) rename {msba2-common => boards/msba2-common}/tools/src/boot.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/boot_23xx.armasm (100%) rename {msba2-common => boards/msba2-common}/tools/src/boot_23xx.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/boot_23xx.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/boot_2xxx.armasm (100%) rename {msba2-common => boards/msba2-common}/tools/src/boot_2xxx.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/boot_2xxx.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/chipinfo.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/chipinfo.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/cksum_test.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/control_2xxx.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/control_2xxx.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/download.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/download.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/gui.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/gui.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/ihex.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/ihex.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/lpc2k_pgm.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/lpc2k_pgm.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/pseudoterm.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/serial.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/serial.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/settings.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/settings.h (100%) rename {msba2-common => boards/msba2-common}/tools/src/uuencode.c (100%) rename {msba2-common => boards/msba2-common}/tools/src/uuencode.h (100%) rename {msba2-common => boards/msba2-common}/tools/termctrl.sh (100%) rename {msba2 => boards/msba2}/Makefile (100%) rename {msba2 => boards/msba2}/Makefile.include (100%) rename {msba2 => boards/msba2}/board_init.c (100%) rename {msba2 => boards/msba2}/include/board.h (100%) rename {native => boards/native}/Makefile (100%) rename {native => boards/native}/Makefile.dep (100%) rename {native => boards/native}/Makefile.include (100%) rename {native => boards/native}/board_config.c (100%) rename {native => boards/native}/board_init.c (100%) rename {native => boards/native}/drivers/Makefile (100%) rename {native => boards/native}/drivers/native-led.c (100%) rename {native => boards/native}/drivers/native-ltc4150.c (100%) rename {native => boards/native}/drivers/native-uart0.c (100%) rename {native => boards/native}/include/board.h (100%) rename {native => boards/native}/include/board_internal.h (100%) rename {olimex_lpc2148 => boards/olimex_lpc2148}/board_init.c (100%) rename {olimex_lpc2148 => boards/olimex_lpc2148}/debug_uart.c (100%) rename {olimex_lpc2148 => boards/olimex_lpc2148}/include/board.h (100%) rename {olimex_lpc2148 => boards/olimex_lpc2148}/include/rs232.h (100%) rename {olimex_lpc2148 => boards/olimex_lpc2148}/rs232.c (100%) rename {olimex_lpc2148 => boards/olimex_lpc2148}/tick.c (100%) rename {olimex_lpc2148 => boards/olimex_lpc2148}/tools/lpc2148_flash.gdb (100%) rename {pttu => boards/pttu}/board_init.c (100%) rename {pttu => boards/pttu}/include/board.h (100%) rename {pttu => boards/pttu}/tools/jtag.txt (100%) rename {pttu => boards/pttu}/tools/olimex-arm-usb-ocd.cfg (100%) rename {pttu => boards/pttu}/tools/openocd-pttu.cfg (100%) rename {pttu => boards/pttu}/tools/openocd-pttu.sh (100%) rename {pttu => boards/pttu}/tools/pttu_debug.gdb (100%) rename {redbee-econotag => boards/redbee-econotag}/Makefile (100%) rename {redbee-econotag => boards/redbee-econotag}/Makefile.dep (100%) rename {redbee-econotag => boards/redbee-econotag}/Makefile.include (100%) rename {redbee-econotag => boards/redbee-econotag}/README (100%) rename {redbee-econotag => boards/redbee-econotag}/board_init.c (100%) rename {redbee-econotag => boards/redbee-econotag}/drivers/Makefile (100%) rename {redbee-econotag => boards/redbee-econotag}/drivers/include/nvm.h (100%) rename {redbee-econotag => boards/redbee-econotag}/drivers/include/uart.h (100%) rename {redbee-econotag => boards/redbee-econotag}/drivers/nvm.c (100%) rename {redbee-econotag => boards/redbee-econotag}/drivers/redbee_uart.c (100%) rename {redbee-econotag => boards/redbee-econotag}/drivers/redbee_uart1.c (100%) rename {redbee-econotag => boards/redbee-econotag}/drivers/redbee_uart2.c (100%) rename {redbee-econotag => boards/redbee-econotag}/include/board.h (100%) rename {redbee-econotag => boards/redbee-econotag}/tools/ftditools/Makefile (100%) rename {redbee-econotag => boards/redbee-econotag}/tools/ftditools/bbmc.c (100%) rename {redbee-econotag => boards/redbee-econotag}/tools/mc1322x-load.c (100%) rename {redbee-econotag => boards/redbee-econotag}/tools/mc1322x-load.pl (100%) rename {telosb => boards/telosb}/Makefile (100%) rename {telosb => boards/telosb}/Makefile.dep (100%) rename {telosb => boards/telosb}/Makefile.include (100%) rename {telosb => boards/telosb}/board.c (100%) rename {telosb => boards/telosb}/driver_cc2420.c (100%) rename {telosb => boards/telosb}/include/board-conf.h (100%) rename {telosb => boards/telosb}/include/board.h (100%) rename {telosb => boards/telosb}/uart.c (100%) rename {wsn430-common => boards/wsn430-common}/Makefile (100%) rename {wsn430-common => boards/wsn430-common}/Makefile.include (100%) rename {wsn430-common => boards/wsn430-common}/board_config.c (100%) rename {wsn430-common => boards/wsn430-common}/board_init.c (100%) rename {wsn430-common => boards/wsn430-common}/drivers/Makefile (100%) rename {wsn430-common => boards/wsn430-common}/include/board-conf.h (100%) rename {wsn430-common => boards/wsn430-common}/uart0.c (100%) rename {wsn430-v1_3b => boards/wsn430-v1_3b}/Makefile (100%) rename {wsn430-v1_3b => boards/wsn430-v1_3b}/Makefile.dep (100%) rename {wsn430-v1_3b => boards/wsn430-v1_3b}/Makefile.include (100%) rename {wsn430-v1_3b => boards/wsn430-v1_3b}/driver_cc110x.c (100%) rename {wsn430-v1_3b => boards/wsn430-v1_3b}/include/board.h (100%) rename {wsn430-v1_4 => boards/wsn430-v1_4}/Makefile (100%) rename {wsn430-v1_4 => boards/wsn430-v1_4}/Makefile.dep (100%) rename {wsn430-v1_4 => boards/wsn430-v1_4}/Makefile.include (100%) rename {wsn430-v1_4 => boards/wsn430-v1_4}/driver_cc2420.c (100%) rename {wsn430-v1_4 => boards/wsn430-v1_4}/include/board.h (100%) diff --git a/LICENSE b/boards/LICENSE similarity index 100% rename from LICENSE rename to boards/LICENSE diff --git a/Makefile b/boards/Makefile similarity index 100% rename from Makefile rename to boards/Makefile diff --git a/Makefile.base b/boards/Makefile.base similarity index 100% rename from Makefile.base rename to boards/Makefile.base diff --git a/README.md b/boards/README.md similarity index 100% rename from README.md rename to boards/README.md diff --git a/avsextrem/Makefile b/boards/avsextrem/Makefile similarity index 100% rename from avsextrem/Makefile rename to boards/avsextrem/Makefile diff --git a/avsextrem/Makefile.include b/boards/avsextrem/Makefile.include similarity index 100% rename from avsextrem/Makefile.include rename to boards/avsextrem/Makefile.include diff --git a/avsextrem/board_init.c b/boards/avsextrem/board_init.c similarity index 100% rename from avsextrem/board_init.c rename to boards/avsextrem/board_init.c diff --git a/avsextrem/drivers/Makefile b/boards/avsextrem/drivers/Makefile similarity index 100% rename from avsextrem/drivers/Makefile rename to boards/avsextrem/drivers/Makefile diff --git a/avsextrem/drivers/avsextrem-cc1100.c b/boards/avsextrem/drivers/avsextrem-cc1100.c similarity index 100% rename from avsextrem/drivers/avsextrem-cc1100.c rename to boards/avsextrem/drivers/avsextrem-cc1100.c diff --git a/avsextrem/drivers/avsextrem-smb380.c b/boards/avsextrem/drivers/avsextrem-smb380.c similarity index 100% rename from avsextrem/drivers/avsextrem-smb380.c rename to boards/avsextrem/drivers/avsextrem-smb380.c diff --git a/avsextrem/drivers/avsextrem-ssp0.c b/boards/avsextrem/drivers/avsextrem-ssp0.c similarity index 100% rename from avsextrem/drivers/avsextrem-ssp0.c rename to boards/avsextrem/drivers/avsextrem-ssp0.c diff --git a/avsextrem/include/board.h b/boards/avsextrem/include/board.h similarity index 100% rename from avsextrem/include/board.h rename to boards/avsextrem/include/board.h diff --git a/avsextrem/include/configure.h b/boards/avsextrem/include/configure.h similarity index 100% rename from avsextrem/include/configure.h rename to boards/avsextrem/include/configure.h diff --git a/avsextrem/include/smb380-board.h b/boards/avsextrem/include/smb380-board.h similarity index 100% rename from avsextrem/include/smb380-board.h rename to boards/avsextrem/include/smb380-board.h diff --git a/avsextrem/include/ssp0-board.h b/boards/avsextrem/include/ssp0-board.h similarity index 100% rename from avsextrem/include/ssp0-board.h rename to boards/avsextrem/include/ssp0-board.h diff --git a/chronos/Makefile b/boards/chronos/Makefile similarity index 100% rename from chronos/Makefile rename to boards/chronos/Makefile diff --git a/chronos/Makefile.include b/boards/chronos/Makefile.include similarity index 100% rename from chronos/Makefile.include rename to boards/chronos/Makefile.include diff --git a/chronos/board_init.c b/boards/chronos/board_init.c similarity index 100% rename from chronos/board_init.c rename to boards/chronos/board_init.c diff --git a/chronos/drivers/Makefile b/boards/chronos/drivers/Makefile similarity index 100% rename from chronos/drivers/Makefile rename to boards/chronos/drivers/Makefile diff --git a/chronos/drivers/battery.c b/boards/chronos/drivers/battery.c similarity index 100% rename from chronos/drivers/battery.c rename to boards/chronos/drivers/battery.c diff --git a/chronos/drivers/buzzer.c b/boards/chronos/drivers/buzzer.c similarity index 100% rename from chronos/drivers/buzzer.c rename to boards/chronos/drivers/buzzer.c diff --git a/chronos/drivers/cc430-cc110x.c b/boards/chronos/drivers/cc430-cc110x.c similarity index 100% rename from chronos/drivers/cc430-cc110x.c rename to boards/chronos/drivers/cc430-cc110x.c diff --git a/chronos/drivers/display.c b/boards/chronos/drivers/display.c similarity index 100% rename from chronos/drivers/display.c rename to boards/chronos/drivers/display.c diff --git a/chronos/drivers/display1.c b/boards/chronos/drivers/display1.c similarity index 100% rename from chronos/drivers/display1.c rename to boards/chronos/drivers/display1.c diff --git a/chronos/drivers/display_putchar.c b/boards/chronos/drivers/display_putchar.c similarity index 100% rename from chronos/drivers/display_putchar.c rename to boards/chronos/drivers/display_putchar.c diff --git a/chronos/drivers/include/battery.h b/boards/chronos/drivers/include/battery.h similarity index 100% rename from chronos/drivers/include/battery.h rename to boards/chronos/drivers/include/battery.h diff --git a/chronos/drivers/include/buzzer.h b/boards/chronos/drivers/include/buzzer.h similarity index 100% rename from chronos/drivers/include/buzzer.h rename to boards/chronos/drivers/include/buzzer.h diff --git a/chronos/drivers/include/display.h b/boards/chronos/drivers/include/display.h similarity index 100% rename from chronos/drivers/include/display.h rename to boards/chronos/drivers/include/display.h diff --git a/chronos/drivers/include/display_putchar.h b/boards/chronos/drivers/include/display_putchar.h similarity index 100% rename from chronos/drivers/include/display_putchar.h rename to boards/chronos/drivers/include/display_putchar.h diff --git a/chronos/include/board.h b/boards/chronos/include/board.h similarity index 100% rename from chronos/include/board.h rename to boards/chronos/include/board.h diff --git a/chronos/include/buttons.h b/boards/chronos/include/buttons.h similarity index 100% rename from chronos/include/buttons.h rename to boards/chronos/include/buttons.h diff --git a/chronos/putchar.c b/boards/chronos/putchar.c similarity index 100% rename from chronos/putchar.c rename to boards/chronos/putchar.c diff --git a/msb-430-common/Makefile b/boards/msb-430-common/Makefile similarity index 100% rename from msb-430-common/Makefile rename to boards/msb-430-common/Makefile diff --git a/msb-430-common/Makefile.include b/boards/msb-430-common/Makefile.include similarity index 100% rename from msb-430-common/Makefile.include rename to boards/msb-430-common/Makefile.include diff --git a/msb-430-common/board_config.c b/boards/msb-430-common/board_config.c similarity index 100% rename from msb-430-common/board_config.c rename to boards/msb-430-common/board_config.c diff --git a/msb-430-common/board_init.c b/boards/msb-430-common/board_init.c similarity index 100% rename from msb-430-common/board_init.c rename to boards/msb-430-common/board_init.c diff --git a/msb-430-common/drivers/Makefile b/boards/msb-430-common/drivers/Makefile similarity index 100% rename from msb-430-common/drivers/Makefile rename to boards/msb-430-common/drivers/Makefile diff --git a/msb-430-common/drivers/include/sht11-board.h b/boards/msb-430-common/drivers/include/sht11-board.h similarity index 100% rename from msb-430-common/drivers/include/sht11-board.h rename to boards/msb-430-common/drivers/include/sht11-board.h diff --git a/msb-430-common/include/board-conf.h b/boards/msb-430-common/include/board-conf.h similarity index 100% rename from msb-430-common/include/board-conf.h rename to boards/msb-430-common/include/board-conf.h diff --git a/msb-430-common/uart1.c b/boards/msb-430-common/uart1.c similarity index 100% rename from msb-430-common/uart1.c rename to boards/msb-430-common/uart1.c diff --git a/msb-430/Makefile b/boards/msb-430/Makefile similarity index 100% rename from msb-430/Makefile rename to boards/msb-430/Makefile diff --git a/msb-430/Makefile.include b/boards/msb-430/Makefile.include similarity index 100% rename from msb-430/Makefile.include rename to boards/msb-430/Makefile.include diff --git a/msb-430/include/board.h b/boards/msb-430/include/board.h similarity index 100% rename from msb-430/include/board.h rename to boards/msb-430/include/board.h diff --git a/msb-430h/Makefile b/boards/msb-430h/Makefile similarity index 100% rename from msb-430h/Makefile rename to boards/msb-430h/Makefile diff --git a/msb-430h/Makefile.dep b/boards/msb-430h/Makefile.dep similarity index 100% rename from msb-430h/Makefile.dep rename to boards/msb-430h/Makefile.dep diff --git a/msb-430h/Makefile.include b/boards/msb-430h/Makefile.include similarity index 100% rename from msb-430h/Makefile.include rename to boards/msb-430h/Makefile.include diff --git a/msb-430h/driver_cc110x.c b/boards/msb-430h/driver_cc110x.c similarity index 100% rename from msb-430h/driver_cc110x.c rename to boards/msb-430h/driver_cc110x.c diff --git a/msb-430h/include/board.h b/boards/msb-430h/include/board.h similarity index 100% rename from msb-430h/include/board.h rename to boards/msb-430h/include/board.h diff --git a/msba2-common/Makefile b/boards/msba2-common/Makefile similarity index 100% rename from msba2-common/Makefile rename to boards/msba2-common/Makefile diff --git a/msba2-common/Makefile.dep b/boards/msba2-common/Makefile.dep similarity index 100% rename from msba2-common/Makefile.dep rename to boards/msba2-common/Makefile.dep diff --git a/msba2-common/Makefile.include b/boards/msba2-common/Makefile.include similarity index 100% rename from msba2-common/Makefile.include rename to boards/msba2-common/Makefile.include diff --git a/msba2-common/board_common_init.c b/boards/msba2-common/board_common_init.c similarity index 100% rename from msba2-common/board_common_init.c rename to boards/msba2-common/board_common_init.c diff --git a/msba2-common/board_config.c b/boards/msba2-common/board_config.c similarity index 100% rename from msba2-common/board_config.c rename to boards/msba2-common/board_config.c diff --git a/msba2-common/drivers/Makefile b/boards/msba2-common/drivers/Makefile similarity index 100% rename from msba2-common/drivers/Makefile rename to boards/msba2-common/drivers/Makefile diff --git a/msba2-common/drivers/include/sht11-board.h b/boards/msba2-common/drivers/include/sht11-board.h similarity index 100% rename from msba2-common/drivers/include/sht11-board.h rename to boards/msba2-common/drivers/include/sht11-board.h diff --git a/msba2-common/drivers/include/uart0.h b/boards/msba2-common/drivers/include/uart0.h similarity index 100% rename from msba2-common/drivers/include/uart0.h rename to boards/msba2-common/drivers/include/uart0.h diff --git a/msba2-common/drivers/msba2-cc110x.c b/boards/msba2-common/drivers/msba2-cc110x.c similarity index 100% rename from msba2-common/drivers/msba2-cc110x.c rename to boards/msba2-common/drivers/msba2-cc110x.c diff --git a/msba2-common/drivers/msba2-ltc4150.c b/boards/msba2-common/drivers/msba2-ltc4150.c similarity index 100% rename from msba2-common/drivers/msba2-ltc4150.c rename to boards/msba2-common/drivers/msba2-ltc4150.c diff --git a/msba2-common/drivers/msba2-uart0.c b/boards/msba2-common/drivers/msba2-uart0.c similarity index 100% rename from msba2-common/drivers/msba2-uart0.c rename to boards/msba2-common/drivers/msba2-uart0.c diff --git a/msba2-common/include/msba2_common.h b/boards/msba2-common/include/msba2_common.h similarity index 100% rename from msba2-common/include/msba2_common.h rename to boards/msba2-common/include/msba2_common.h diff --git a/msba2-common/lpc2387-timer3.c b/boards/msba2-common/lpc2387-timer3.c similarity index 100% rename from msba2-common/lpc2387-timer3.c rename to boards/msba2-common/lpc2387-timer3.c diff --git a/msba2-common/tools/CHANGES b/boards/msba2-common/tools/CHANGES similarity index 100% rename from msba2-common/tools/CHANGES rename to boards/msba2-common/tools/CHANGES diff --git a/msba2-common/tools/COPYING b/boards/msba2-common/tools/COPYING similarity index 100% rename from msba2-common/tools/COPYING rename to boards/msba2-common/tools/COPYING diff --git a/msba2-common/tools/Makefile b/boards/msba2-common/tools/Makefile similarity index 100% rename from msba2-common/tools/Makefile rename to boards/msba2-common/tools/Makefile diff --git a/msba2-common/tools/README.txt b/boards/msba2-common/tools/README.txt similarity index 100% rename from msba2-common/tools/README.txt rename to boards/msba2-common/tools/README.txt diff --git a/msba2-common/tools/armtools.txt b/boards/msba2-common/tools/armtools.txt similarity index 100% rename from msba2-common/tools/armtools.txt rename to boards/msba2-common/tools/armtools.txt diff --git a/msba2-common/tools/flash.cmd b/boards/msba2-common/tools/flash.cmd similarity index 100% rename from msba2-common/tools/flash.cmd rename to boards/msba2-common/tools/flash.cmd diff --git a/msba2-common/tools/flashutil.sh b/boards/msba2-common/tools/flashutil.sh similarity index 100% rename from msba2-common/tools/flashutil.sh rename to boards/msba2-common/tools/flashutil.sh diff --git a/msba2-common/tools/mkbootc b/boards/msba2-common/tools/mkbootc similarity index 100% rename from msba2-common/tools/mkbootc rename to boards/msba2-common/tools/mkbootc diff --git a/msba2-common/tools/mkstaticlist b/boards/msba2-common/tools/mkstaticlist similarity index 100% rename from msba2-common/tools/mkstaticlist rename to boards/msba2-common/tools/mkstaticlist diff --git a/msba2-common/tools/obj/boot_23xx.d b/boards/msba2-common/tools/obj/boot_23xx.d similarity index 100% rename from msba2-common/tools/obj/boot_23xx.d rename to boards/msba2-common/tools/obj/boot_23xx.d diff --git a/msba2-common/tools/obj/boot_2xxx.d b/boards/msba2-common/tools/obj/boot_2xxx.d similarity index 100% rename from msba2-common/tools/obj/boot_2xxx.d rename to boards/msba2-common/tools/obj/boot_2xxx.d diff --git a/msba2-common/tools/obj/chipinfo.d b/boards/msba2-common/tools/obj/chipinfo.d similarity index 100% rename from msba2-common/tools/obj/chipinfo.d rename to boards/msba2-common/tools/obj/chipinfo.d diff --git a/msba2-common/tools/obj/control_2xxx.d b/boards/msba2-common/tools/obj/control_2xxx.d similarity index 100% rename from msba2-common/tools/obj/control_2xxx.d rename to boards/msba2-common/tools/obj/control_2xxx.d diff --git a/msba2-common/tools/obj/download.d b/boards/msba2-common/tools/obj/download.d similarity index 100% rename from msba2-common/tools/obj/download.d rename to boards/msba2-common/tools/obj/download.d diff --git a/msba2-common/tools/obj/ihex.d b/boards/msba2-common/tools/obj/ihex.d similarity index 100% rename from msba2-common/tools/obj/ihex.d rename to boards/msba2-common/tools/obj/ihex.d diff --git a/msba2-common/tools/obj/lpc2k_pgm.d b/boards/msba2-common/tools/obj/lpc2k_pgm.d similarity index 100% rename from msba2-common/tools/obj/lpc2k_pgm.d rename to boards/msba2-common/tools/obj/lpc2k_pgm.d diff --git a/msba2-common/tools/obj/pseudoterm.d b/boards/msba2-common/tools/obj/pseudoterm.d similarity index 100% rename from msba2-common/tools/obj/pseudoterm.d rename to boards/msba2-common/tools/obj/pseudoterm.d diff --git a/msba2-common/tools/obj/serial.d b/boards/msba2-common/tools/obj/serial.d similarity index 100% rename from msba2-common/tools/obj/serial.d rename to boards/msba2-common/tools/obj/serial.d diff --git a/msba2-common/tools/obj/uuencode.d b/boards/msba2-common/tools/obj/uuencode.d similarity index 100% rename from msba2-common/tools/obj/uuencode.d rename to boards/msba2-common/tools/obj/uuencode.d diff --git a/msba2-common/tools/src/boot.h b/boards/msba2-common/tools/src/boot.h similarity index 100% rename from msba2-common/tools/src/boot.h rename to boards/msba2-common/tools/src/boot.h diff --git a/msba2-common/tools/src/boot_23xx.armasm b/boards/msba2-common/tools/src/boot_23xx.armasm similarity index 100% rename from msba2-common/tools/src/boot_23xx.armasm rename to boards/msba2-common/tools/src/boot_23xx.armasm diff --git a/msba2-common/tools/src/boot_23xx.c b/boards/msba2-common/tools/src/boot_23xx.c similarity index 100% rename from msba2-common/tools/src/boot_23xx.c rename to boards/msba2-common/tools/src/boot_23xx.c diff --git a/msba2-common/tools/src/boot_23xx.h b/boards/msba2-common/tools/src/boot_23xx.h similarity index 100% rename from msba2-common/tools/src/boot_23xx.h rename to boards/msba2-common/tools/src/boot_23xx.h diff --git a/msba2-common/tools/src/boot_2xxx.armasm b/boards/msba2-common/tools/src/boot_2xxx.armasm similarity index 100% rename from msba2-common/tools/src/boot_2xxx.armasm rename to boards/msba2-common/tools/src/boot_2xxx.armasm diff --git a/msba2-common/tools/src/boot_2xxx.c b/boards/msba2-common/tools/src/boot_2xxx.c similarity index 100% rename from msba2-common/tools/src/boot_2xxx.c rename to boards/msba2-common/tools/src/boot_2xxx.c diff --git a/msba2-common/tools/src/boot_2xxx.h b/boards/msba2-common/tools/src/boot_2xxx.h similarity index 100% rename from msba2-common/tools/src/boot_2xxx.h rename to boards/msba2-common/tools/src/boot_2xxx.h diff --git a/msba2-common/tools/src/chipinfo.c b/boards/msba2-common/tools/src/chipinfo.c similarity index 100% rename from msba2-common/tools/src/chipinfo.c rename to boards/msba2-common/tools/src/chipinfo.c diff --git a/msba2-common/tools/src/chipinfo.h b/boards/msba2-common/tools/src/chipinfo.h similarity index 100% rename from msba2-common/tools/src/chipinfo.h rename to boards/msba2-common/tools/src/chipinfo.h diff --git a/msba2-common/tools/src/cksum_test.c b/boards/msba2-common/tools/src/cksum_test.c similarity index 100% rename from msba2-common/tools/src/cksum_test.c rename to boards/msba2-common/tools/src/cksum_test.c diff --git a/msba2-common/tools/src/control_2xxx.c b/boards/msba2-common/tools/src/control_2xxx.c similarity index 100% rename from msba2-common/tools/src/control_2xxx.c rename to boards/msba2-common/tools/src/control_2xxx.c diff --git a/msba2-common/tools/src/control_2xxx.h b/boards/msba2-common/tools/src/control_2xxx.h similarity index 100% rename from msba2-common/tools/src/control_2xxx.h rename to boards/msba2-common/tools/src/control_2xxx.h diff --git a/msba2-common/tools/src/download.c b/boards/msba2-common/tools/src/download.c similarity index 100% rename from msba2-common/tools/src/download.c rename to boards/msba2-common/tools/src/download.c diff --git a/msba2-common/tools/src/download.h b/boards/msba2-common/tools/src/download.h similarity index 100% rename from msba2-common/tools/src/download.h rename to boards/msba2-common/tools/src/download.h diff --git a/msba2-common/tools/src/gui.c b/boards/msba2-common/tools/src/gui.c similarity index 100% rename from msba2-common/tools/src/gui.c rename to boards/msba2-common/tools/src/gui.c diff --git a/msba2-common/tools/src/gui.h b/boards/msba2-common/tools/src/gui.h similarity index 100% rename from msba2-common/tools/src/gui.h rename to boards/msba2-common/tools/src/gui.h diff --git a/msba2-common/tools/src/ihex.c b/boards/msba2-common/tools/src/ihex.c similarity index 100% rename from msba2-common/tools/src/ihex.c rename to boards/msba2-common/tools/src/ihex.c diff --git a/msba2-common/tools/src/ihex.h b/boards/msba2-common/tools/src/ihex.h similarity index 100% rename from msba2-common/tools/src/ihex.h rename to boards/msba2-common/tools/src/ihex.h diff --git a/msba2-common/tools/src/lpc2k_pgm.c b/boards/msba2-common/tools/src/lpc2k_pgm.c similarity index 100% rename from msba2-common/tools/src/lpc2k_pgm.c rename to boards/msba2-common/tools/src/lpc2k_pgm.c diff --git a/msba2-common/tools/src/lpc2k_pgm.h b/boards/msba2-common/tools/src/lpc2k_pgm.h similarity index 100% rename from msba2-common/tools/src/lpc2k_pgm.h rename to boards/msba2-common/tools/src/lpc2k_pgm.h diff --git a/msba2-common/tools/src/pseudoterm.c b/boards/msba2-common/tools/src/pseudoterm.c similarity index 100% rename from msba2-common/tools/src/pseudoterm.c rename to boards/msba2-common/tools/src/pseudoterm.c diff --git a/msba2-common/tools/src/serial.c b/boards/msba2-common/tools/src/serial.c similarity index 100% rename from msba2-common/tools/src/serial.c rename to boards/msba2-common/tools/src/serial.c diff --git a/msba2-common/tools/src/serial.h b/boards/msba2-common/tools/src/serial.h similarity index 100% rename from msba2-common/tools/src/serial.h rename to boards/msba2-common/tools/src/serial.h diff --git a/msba2-common/tools/src/settings.c b/boards/msba2-common/tools/src/settings.c similarity index 100% rename from msba2-common/tools/src/settings.c rename to boards/msba2-common/tools/src/settings.c diff --git a/msba2-common/tools/src/settings.h b/boards/msba2-common/tools/src/settings.h similarity index 100% rename from msba2-common/tools/src/settings.h rename to boards/msba2-common/tools/src/settings.h diff --git a/msba2-common/tools/src/uuencode.c b/boards/msba2-common/tools/src/uuencode.c similarity index 100% rename from msba2-common/tools/src/uuencode.c rename to boards/msba2-common/tools/src/uuencode.c diff --git a/msba2-common/tools/src/uuencode.h b/boards/msba2-common/tools/src/uuencode.h similarity index 100% rename from msba2-common/tools/src/uuencode.h rename to boards/msba2-common/tools/src/uuencode.h diff --git a/msba2-common/tools/termctrl.sh b/boards/msba2-common/tools/termctrl.sh similarity index 100% rename from msba2-common/tools/termctrl.sh rename to boards/msba2-common/tools/termctrl.sh diff --git a/msba2/Makefile b/boards/msba2/Makefile similarity index 100% rename from msba2/Makefile rename to boards/msba2/Makefile diff --git a/msba2/Makefile.include b/boards/msba2/Makefile.include similarity index 100% rename from msba2/Makefile.include rename to boards/msba2/Makefile.include diff --git a/msba2/board_init.c b/boards/msba2/board_init.c similarity index 100% rename from msba2/board_init.c rename to boards/msba2/board_init.c diff --git a/msba2/include/board.h b/boards/msba2/include/board.h similarity index 100% rename from msba2/include/board.h rename to boards/msba2/include/board.h diff --git a/native/Makefile b/boards/native/Makefile similarity index 100% rename from native/Makefile rename to boards/native/Makefile diff --git a/native/Makefile.dep b/boards/native/Makefile.dep similarity index 100% rename from native/Makefile.dep rename to boards/native/Makefile.dep diff --git a/native/Makefile.include b/boards/native/Makefile.include similarity index 100% rename from native/Makefile.include rename to boards/native/Makefile.include diff --git a/native/board_config.c b/boards/native/board_config.c similarity index 100% rename from native/board_config.c rename to boards/native/board_config.c diff --git a/native/board_init.c b/boards/native/board_init.c similarity index 100% rename from native/board_init.c rename to boards/native/board_init.c diff --git a/native/drivers/Makefile b/boards/native/drivers/Makefile similarity index 100% rename from native/drivers/Makefile rename to boards/native/drivers/Makefile diff --git a/native/drivers/native-led.c b/boards/native/drivers/native-led.c similarity index 100% rename from native/drivers/native-led.c rename to boards/native/drivers/native-led.c diff --git a/native/drivers/native-ltc4150.c b/boards/native/drivers/native-ltc4150.c similarity index 100% rename from native/drivers/native-ltc4150.c rename to boards/native/drivers/native-ltc4150.c diff --git a/native/drivers/native-uart0.c b/boards/native/drivers/native-uart0.c similarity index 100% rename from native/drivers/native-uart0.c rename to boards/native/drivers/native-uart0.c diff --git a/native/include/board.h b/boards/native/include/board.h similarity index 100% rename from native/include/board.h rename to boards/native/include/board.h diff --git a/native/include/board_internal.h b/boards/native/include/board_internal.h similarity index 100% rename from native/include/board_internal.h rename to boards/native/include/board_internal.h diff --git a/olimex_lpc2148/board_init.c b/boards/olimex_lpc2148/board_init.c similarity index 100% rename from olimex_lpc2148/board_init.c rename to boards/olimex_lpc2148/board_init.c diff --git a/olimex_lpc2148/debug_uart.c b/boards/olimex_lpc2148/debug_uart.c similarity index 100% rename from olimex_lpc2148/debug_uart.c rename to boards/olimex_lpc2148/debug_uart.c diff --git a/olimex_lpc2148/include/board.h b/boards/olimex_lpc2148/include/board.h similarity index 100% rename from olimex_lpc2148/include/board.h rename to boards/olimex_lpc2148/include/board.h diff --git a/olimex_lpc2148/include/rs232.h b/boards/olimex_lpc2148/include/rs232.h similarity index 100% rename from olimex_lpc2148/include/rs232.h rename to boards/olimex_lpc2148/include/rs232.h diff --git a/olimex_lpc2148/rs232.c b/boards/olimex_lpc2148/rs232.c similarity index 100% rename from olimex_lpc2148/rs232.c rename to boards/olimex_lpc2148/rs232.c diff --git a/olimex_lpc2148/tick.c b/boards/olimex_lpc2148/tick.c similarity index 100% rename from olimex_lpc2148/tick.c rename to boards/olimex_lpc2148/tick.c diff --git a/olimex_lpc2148/tools/lpc2148_flash.gdb b/boards/olimex_lpc2148/tools/lpc2148_flash.gdb similarity index 100% rename from olimex_lpc2148/tools/lpc2148_flash.gdb rename to boards/olimex_lpc2148/tools/lpc2148_flash.gdb diff --git a/pttu/board_init.c b/boards/pttu/board_init.c similarity index 100% rename from pttu/board_init.c rename to boards/pttu/board_init.c diff --git a/pttu/include/board.h b/boards/pttu/include/board.h similarity index 100% rename from pttu/include/board.h rename to boards/pttu/include/board.h diff --git a/pttu/tools/jtag.txt b/boards/pttu/tools/jtag.txt similarity index 100% rename from pttu/tools/jtag.txt rename to boards/pttu/tools/jtag.txt diff --git a/pttu/tools/olimex-arm-usb-ocd.cfg b/boards/pttu/tools/olimex-arm-usb-ocd.cfg similarity index 100% rename from pttu/tools/olimex-arm-usb-ocd.cfg rename to boards/pttu/tools/olimex-arm-usb-ocd.cfg diff --git a/pttu/tools/openocd-pttu.cfg b/boards/pttu/tools/openocd-pttu.cfg similarity index 100% rename from pttu/tools/openocd-pttu.cfg rename to boards/pttu/tools/openocd-pttu.cfg diff --git a/pttu/tools/openocd-pttu.sh b/boards/pttu/tools/openocd-pttu.sh similarity index 100% rename from pttu/tools/openocd-pttu.sh rename to boards/pttu/tools/openocd-pttu.sh diff --git a/pttu/tools/pttu_debug.gdb b/boards/pttu/tools/pttu_debug.gdb similarity index 100% rename from pttu/tools/pttu_debug.gdb rename to boards/pttu/tools/pttu_debug.gdb diff --git a/redbee-econotag/Makefile b/boards/redbee-econotag/Makefile similarity index 100% rename from redbee-econotag/Makefile rename to boards/redbee-econotag/Makefile diff --git a/redbee-econotag/Makefile.dep b/boards/redbee-econotag/Makefile.dep similarity index 100% rename from redbee-econotag/Makefile.dep rename to boards/redbee-econotag/Makefile.dep diff --git a/redbee-econotag/Makefile.include b/boards/redbee-econotag/Makefile.include similarity index 100% rename from redbee-econotag/Makefile.include rename to boards/redbee-econotag/Makefile.include diff --git a/redbee-econotag/README b/boards/redbee-econotag/README similarity index 100% rename from redbee-econotag/README rename to boards/redbee-econotag/README diff --git a/redbee-econotag/board_init.c b/boards/redbee-econotag/board_init.c similarity index 100% rename from redbee-econotag/board_init.c rename to boards/redbee-econotag/board_init.c diff --git a/redbee-econotag/drivers/Makefile b/boards/redbee-econotag/drivers/Makefile similarity index 100% rename from redbee-econotag/drivers/Makefile rename to boards/redbee-econotag/drivers/Makefile diff --git a/redbee-econotag/drivers/include/nvm.h b/boards/redbee-econotag/drivers/include/nvm.h similarity index 100% rename from redbee-econotag/drivers/include/nvm.h rename to boards/redbee-econotag/drivers/include/nvm.h diff --git a/redbee-econotag/drivers/include/uart.h b/boards/redbee-econotag/drivers/include/uart.h similarity index 100% rename from redbee-econotag/drivers/include/uart.h rename to boards/redbee-econotag/drivers/include/uart.h diff --git a/redbee-econotag/drivers/nvm.c b/boards/redbee-econotag/drivers/nvm.c similarity index 100% rename from redbee-econotag/drivers/nvm.c rename to boards/redbee-econotag/drivers/nvm.c diff --git a/redbee-econotag/drivers/redbee_uart.c b/boards/redbee-econotag/drivers/redbee_uart.c similarity index 100% rename from redbee-econotag/drivers/redbee_uart.c rename to boards/redbee-econotag/drivers/redbee_uart.c diff --git a/redbee-econotag/drivers/redbee_uart1.c b/boards/redbee-econotag/drivers/redbee_uart1.c similarity index 100% rename from redbee-econotag/drivers/redbee_uart1.c rename to boards/redbee-econotag/drivers/redbee_uart1.c diff --git a/redbee-econotag/drivers/redbee_uart2.c b/boards/redbee-econotag/drivers/redbee_uart2.c similarity index 100% rename from redbee-econotag/drivers/redbee_uart2.c rename to boards/redbee-econotag/drivers/redbee_uart2.c diff --git a/redbee-econotag/include/board.h b/boards/redbee-econotag/include/board.h similarity index 100% rename from redbee-econotag/include/board.h rename to boards/redbee-econotag/include/board.h diff --git a/redbee-econotag/tools/ftditools/Makefile b/boards/redbee-econotag/tools/ftditools/Makefile similarity index 100% rename from redbee-econotag/tools/ftditools/Makefile rename to boards/redbee-econotag/tools/ftditools/Makefile diff --git a/redbee-econotag/tools/ftditools/bbmc.c b/boards/redbee-econotag/tools/ftditools/bbmc.c similarity index 100% rename from redbee-econotag/tools/ftditools/bbmc.c rename to boards/redbee-econotag/tools/ftditools/bbmc.c diff --git a/redbee-econotag/tools/mc1322x-load.c b/boards/redbee-econotag/tools/mc1322x-load.c similarity index 100% rename from redbee-econotag/tools/mc1322x-load.c rename to boards/redbee-econotag/tools/mc1322x-load.c diff --git a/redbee-econotag/tools/mc1322x-load.pl b/boards/redbee-econotag/tools/mc1322x-load.pl similarity index 100% rename from redbee-econotag/tools/mc1322x-load.pl rename to boards/redbee-econotag/tools/mc1322x-load.pl diff --git a/telosb/Makefile b/boards/telosb/Makefile similarity index 100% rename from telosb/Makefile rename to boards/telosb/Makefile diff --git a/telosb/Makefile.dep b/boards/telosb/Makefile.dep similarity index 100% rename from telosb/Makefile.dep rename to boards/telosb/Makefile.dep diff --git a/telosb/Makefile.include b/boards/telosb/Makefile.include similarity index 100% rename from telosb/Makefile.include rename to boards/telosb/Makefile.include diff --git a/telosb/board.c b/boards/telosb/board.c similarity index 100% rename from telosb/board.c rename to boards/telosb/board.c diff --git a/telosb/driver_cc2420.c b/boards/telosb/driver_cc2420.c similarity index 100% rename from telosb/driver_cc2420.c rename to boards/telosb/driver_cc2420.c diff --git a/telosb/include/board-conf.h b/boards/telosb/include/board-conf.h similarity index 100% rename from telosb/include/board-conf.h rename to boards/telosb/include/board-conf.h diff --git a/telosb/include/board.h b/boards/telosb/include/board.h similarity index 100% rename from telosb/include/board.h rename to boards/telosb/include/board.h diff --git a/telosb/uart.c b/boards/telosb/uart.c similarity index 100% rename from telosb/uart.c rename to boards/telosb/uart.c diff --git a/wsn430-common/Makefile b/boards/wsn430-common/Makefile similarity index 100% rename from wsn430-common/Makefile rename to boards/wsn430-common/Makefile diff --git a/wsn430-common/Makefile.include b/boards/wsn430-common/Makefile.include similarity index 100% rename from wsn430-common/Makefile.include rename to boards/wsn430-common/Makefile.include diff --git a/wsn430-common/board_config.c b/boards/wsn430-common/board_config.c similarity index 100% rename from wsn430-common/board_config.c rename to boards/wsn430-common/board_config.c diff --git a/wsn430-common/board_init.c b/boards/wsn430-common/board_init.c similarity index 100% rename from wsn430-common/board_init.c rename to boards/wsn430-common/board_init.c diff --git a/wsn430-common/drivers/Makefile b/boards/wsn430-common/drivers/Makefile similarity index 100% rename from wsn430-common/drivers/Makefile rename to boards/wsn430-common/drivers/Makefile diff --git a/wsn430-common/include/board-conf.h b/boards/wsn430-common/include/board-conf.h similarity index 100% rename from wsn430-common/include/board-conf.h rename to boards/wsn430-common/include/board-conf.h diff --git a/wsn430-common/uart0.c b/boards/wsn430-common/uart0.c similarity index 100% rename from wsn430-common/uart0.c rename to boards/wsn430-common/uart0.c diff --git a/wsn430-v1_3b/Makefile b/boards/wsn430-v1_3b/Makefile similarity index 100% rename from wsn430-v1_3b/Makefile rename to boards/wsn430-v1_3b/Makefile diff --git a/wsn430-v1_3b/Makefile.dep b/boards/wsn430-v1_3b/Makefile.dep similarity index 100% rename from wsn430-v1_3b/Makefile.dep rename to boards/wsn430-v1_3b/Makefile.dep diff --git a/wsn430-v1_3b/Makefile.include b/boards/wsn430-v1_3b/Makefile.include similarity index 100% rename from wsn430-v1_3b/Makefile.include rename to boards/wsn430-v1_3b/Makefile.include diff --git a/wsn430-v1_3b/driver_cc110x.c b/boards/wsn430-v1_3b/driver_cc110x.c similarity index 100% rename from wsn430-v1_3b/driver_cc110x.c rename to boards/wsn430-v1_3b/driver_cc110x.c diff --git a/wsn430-v1_3b/include/board.h b/boards/wsn430-v1_3b/include/board.h similarity index 100% rename from wsn430-v1_3b/include/board.h rename to boards/wsn430-v1_3b/include/board.h diff --git a/wsn430-v1_4/Makefile b/boards/wsn430-v1_4/Makefile similarity index 100% rename from wsn430-v1_4/Makefile rename to boards/wsn430-v1_4/Makefile diff --git a/wsn430-v1_4/Makefile.dep b/boards/wsn430-v1_4/Makefile.dep similarity index 100% rename from wsn430-v1_4/Makefile.dep rename to boards/wsn430-v1_4/Makefile.dep diff --git a/wsn430-v1_4/Makefile.include b/boards/wsn430-v1_4/Makefile.include similarity index 100% rename from wsn430-v1_4/Makefile.include rename to boards/wsn430-v1_4/Makefile.include diff --git a/wsn430-v1_4/driver_cc2420.c b/boards/wsn430-v1_4/driver_cc2420.c similarity index 100% rename from wsn430-v1_4/driver_cc2420.c rename to boards/wsn430-v1_4/driver_cc2420.c diff --git a/wsn430-v1_4/include/board.h b/boards/wsn430-v1_4/include/board.h similarity index 100% rename from wsn430-v1_4/include/board.h rename to boards/wsn430-v1_4/include/board.h